Skip to content

Commit

Permalink
feat: "pnpm publish" supports package.{json5,yaml}
Browse files Browse the repository at this point in the history
ref #1803
  • Loading branch information
zkochan committed May 4, 2019
1 parent bb3fd53 commit c695e99
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 28 deletions.
4 changes: 2 additions & 2 deletions packages/pnpm/package.json
Expand Up @@ -84,7 +84,8 @@
"text-table": "0.2.0",
"tree-kill": "1.2.1",
"update-notifier": "2.5.0",
"version-selector-type": "2.0.1"
"version-selector-type": "2.0.1",
"write-json-file": "3.2.0"
},
"devDependencies": {
"@pnpm/assert-project": "link:../../privatePackages/assert-project",
Expand Down Expand Up @@ -127,7 +128,6 @@
"ts-node": "8.1.0",
"tslint": "5.16.0",
"typescript": "3.4.5",
"write-json-file": "3.2.0",
"write-pkg": "4.0.0",
"write-yaml-file": "2.0.0"
},
Expand Down
1 change: 0 additions & 1 deletion packages/pnpm/src/bin/pnpm.ts
Expand Up @@ -41,7 +41,6 @@ if (argv.includes('--help') || argv.includes('-h') || argv.includes('--h')) {
case 'ping':
case 'prefix':
case 'profile':
case 'publish':
case 'repo':
case 's':
case 'se':
Expand Down
8 changes: 8 additions & 0 deletions packages/pnpm/src/cmd/help.ts
Expand Up @@ -215,6 +215,13 @@ function getHelpText (command: string) {
Removes extraneous packages
`

case 'publish':
return stripIndent`
pnpm publish [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>]
Publishes a package to the npm registry.
`

case 'install-test':
return stripIndent`
pnpm install-test
Expand Down Expand Up @@ -474,6 +481,7 @@ function getHelpText (command: string) {
- list
- outdated
- prune
- publish
- rebuild
- restart
- root
Expand Down
2 changes: 2 additions & 0 deletions packages/pnpm/src/cmd/index.ts
Expand Up @@ -6,6 +6,7 @@ import link from './link'
import list from './list'
import outdated from './outdated'
import prune from './prune'
import publish from './publish'
import rebuild from './rebuild'
import recursive from './recursive'
import root from './root'
Expand All @@ -25,6 +26,7 @@ export default {
list,
outdated,
prune,
publish,
rebuild,
recursive,
restart,
Expand Down
27 changes: 27 additions & 0 deletions packages/pnpm/src/cmd/publish.ts
@@ -0,0 +1,27 @@
import readImporterManifest from '@pnpm/read-importer-manifest'
import path = require('path')
import rimraf = require('rimraf-then')
import writeJsonFile = require('write-json-file')
import { PnpmOptions } from '../types'
import runNpm from './runNpm'

export default async function (
args: string[],
opts: PnpmOptions,
command: string,
) {
if (args.length && args[0].endsWith('.tgz')) {
await runNpm(['publish', ...args])
return
}
const prefix = args.length && args[0] || process.cwd()
const { fileName, manifest, writeImporterManifest } = await readImporterManifest(prefix)
if (fileName !== 'package.json') {
await writeJsonFile(path.join(prefix, 'package.json'), manifest)
}
await runNpm(['publish', ...args])
if (fileName !== 'package.json') {
await rimraf(path.join(prefix, 'package.json'))
await writeImporterManifest(manifest)
}
}
2 changes: 2 additions & 0 deletions packages/pnpm/src/main.ts
Expand Up @@ -38,6 +38,7 @@ type CANONICAL_COMMAND_NAMES = 'help'
| 'list'
| 'outdated'
| 'prune'
| 'publish'
| 'rebuild'
| 'recursive'
| 'restart'
Expand All @@ -60,6 +61,7 @@ const supportedCmds = new Set<CANONICAL_COMMAND_NAMES>([
'update',
'link',
'prune',
'publish',
'install-test',
'restart',
'server',
Expand Down
24 changes: 0 additions & 24 deletions packages/pnpm/src/readImporterManifest.ts

This file was deleted.

1 change: 1 addition & 0 deletions packages/pnpm/test/index.ts
Expand Up @@ -7,6 +7,7 @@ import './list'
import './monorepo'
import './outdated'
import './prune'
import './publish'
import './rebuild'
import './recursive'
import './root'
Expand Down
53 changes: 53 additions & 0 deletions packages/pnpm/test/publish.ts
@@ -0,0 +1,53 @@
import {
prepareWithYamlManifest,
} from '@pnpm/prepare'
import tape = require('tape')
import promisifyTape from 'tape-promise'
import { execPnpm } from './utils'

const test = promisifyTape(tape)
const testOnly = promisifyTape(tape.only)

const CREDENTIALS = [
'--//localhost:4873/:username=username',
`--//localhost:4873/:_password=${Buffer.from('password').toString('base64')}`,
'--//localhost:4873/:email=foo@bar.net',
]

test('publish: package with package.json', async (t: tape.Test) => {
prepareWithYamlManifest(t, {
name: 'test-publish-package.json',
version: '0.0.0',
})

await execPnpm('publish', ...CREDENTIALS)
})

test('publish: package with package.yaml', async (t: tape.Test) => {
prepareWithYamlManifest(t, {
name: 'test-publish-package.yaml',
version: '0.0.0',
})

await execPnpm('publish', ...CREDENTIALS)
})

test('publish: package with package.json5', async (t: tape.Test) => {
prepareWithYamlManifest(t, {
name: 'test-publish-package.json5',
version: '0.0.0',
})

await execPnpm('publish', ...CREDENTIALS)
})

test('publish: package with package.json5 running publish from different folder', async (t: tape.Test) => {
prepareWithYamlManifest(t, {
name: 'test-publish-package.json5',
version: '0.0.1',
})

process.chdir('..')

await execPnpm('publish', 'project', ...CREDENTIALS)
})
7 changes: 7 additions & 0 deletions packages/read-importer-manifest/src/index.ts
Expand Up @@ -15,12 +15,14 @@ import {
const stat = promisify(fs.stat)

export default async function readImporterManifest (importerDir: string): Promise<{
fileName: string,
manifest: ImporterManifest
writeImporterManifest: (manifest: ImporterManifest) => Promise<void>
}> {
const result = await tryReadImporterManifest(importerDir)
if (result.manifest !== null) {
return result as {
fileName: string,
manifest: ImporterManifest
writeImporterManifest: (manifest: ImporterManifest) => Promise<void>
}
Expand All @@ -36,6 +38,7 @@ export async function readImporterManifestOnly (importerDir: string): Promise<Im
}

export async function tryReadImporterManifest (importerDir: string): Promise<{
fileName: string,
manifest: ImporterManifest | null
writeImporterManifest: (manifest: ImporterManifest) => Promise<void>
}> {
Expand All @@ -44,6 +47,7 @@ export async function tryReadImporterManifest (importerDir: string): Promise<{
const { data, text } = await readJsonFile(manifestPath)
const { indent } = detectIndent(text)
return {
fileName: 'package.json',
manifest: data,
writeImporterManifest: createManifestWriter({
indent,
Expand All @@ -59,6 +63,7 @@ export async function tryReadImporterManifest (importerDir: string): Promise<{
const { data, text } = await readJson5File(manifestPath)
const { indent } = detectIndent(text)
return {
fileName: 'package.json5',
manifest: data,
writeImporterManifest: createManifestWriter({
indent,
Expand All @@ -73,6 +78,7 @@ export async function tryReadImporterManifest (importerDir: string): Promise<{
const manifestPath = path.join(importerDir, 'package.yaml')
const manifest = await readPackageYaml(manifestPath)
return {
fileName: 'package.yaml',
manifest,
writeImporterManifest: createManifestWriter({ initialManifest: manifest, manifestPath }),
}
Expand All @@ -95,6 +101,7 @@ export async function tryReadImporterManifest (importerDir: string): Promise<{
}
const filePath = path.join(importerDir, 'package.json')
return {
fileName: 'package.json',
manifest: null,
writeImporterManifest: writeImporterManifest.bind(null, filePath),
}
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c695e99

Please sign in to comment.