-
-
Notifications
You must be signed in to change notification settings - Fork 980
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: publish and pack support package.{json5,yaml}
- Loading branch information
Showing
13 changed files
with
215 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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() | ||
|
||
let _status!: number | ||
await fakeRegularManifest(prefix, async () => { | ||
const { status } = await runNpm(['publish', ...opts.argv.original.slice(1)]) | ||
_status = status | ||
}) | ||
if (_status !== 0) { | ||
process.exit(_status) | ||
} | ||
} | ||
|
||
export async function pack ( | ||
args: string[], | ||
opts: PnpmOptions, | ||
command: string, | ||
) { | ||
let _status!: number | ||
await fakeRegularManifest(opts.prefix, async () => { | ||
const { status } = await runNpm(['pack', ...opts.argv.original.slice(1)]) | ||
_status = status | ||
}) | ||
if (_status !== 0) { | ||
process.exit(_status) | ||
} | ||
} | ||
|
||
async function fakeRegularManifest (prefix: string, fn: () => Promise<void>) { | ||
const { fileName, manifest, writeImporterManifest } = await readImporterManifest(prefix) | ||
const exoticManifestFormat = fileName !== 'package.json' | ||
if (exoticManifestFormat) { | ||
await rimraf(path.join(prefix, fileName)) | ||
await writeJsonFile(path.join(prefix, 'package.json'), manifest) | ||
} | ||
await fn() | ||
if (exoticManifestFormat) { | ||
await rimraf(path.join(prefix, 'package.json')) | ||
await writeImporterManifest(manifest, true) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
import { sync as runScriptSync } from '../runScript' | ||
|
||
export default function runNpm (args: string[]) { | ||
const result = runScriptSync('npm', args, { | ||
return runScriptSync('npm', args, { | ||
cwd: process.cwd(), | ||
stdio: 'inherit', | ||
userAgent: undefined, | ||
}) | ||
process.exit(result.status) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import prepare, { | ||
prepareWithYamlManifest, | ||
prepareWithJson5Manifest, | ||
} from '@pnpm/prepare' | ||
import exists = require('path-exists') | ||
import tape = require('tape') | ||
import promisifyTape from 'tape-promise' | ||
import { execPnpm } from './utils' | ||
|
||
const test = promisifyTape(tape) | ||
const testOnly = promisifyTape(tape.only) | ||
|
||
test('pack: package with package.json', async (t: tape.Test) => { | ||
prepare(t, { | ||
name: 'test-publish-package.json', | ||
version: '0.0.0', | ||
}) | ||
|
||
await execPnpm('pack') | ||
|
||
t.ok(await exists('test-publish-package.json-0.0.0.tgz')) | ||
t.ok(await exists('package.json')) | ||
}) | ||
|
||
test('pack: package with package.yaml', async (t: tape.Test) => { | ||
prepareWithYamlManifest(t, { | ||
name: 'test-publish-package.yaml', | ||
version: '0.0.0', | ||
}) | ||
|
||
await execPnpm('pack') | ||
|
||
t.ok(await exists('test-publish-package.yaml-0.0.0.tgz')) | ||
t.ok(await exists('package.yaml')) | ||
t.notOk(await exists('package.json')) | ||
}) | ||
|
||
test('pack: package with package.json5', async (t: tape.Test) => { | ||
prepareWithJson5Manifest(t, { | ||
name: 'test-publish-package.json5', | ||
version: '0.0.0', | ||
}) | ||
|
||
await execPnpm('pack') | ||
|
||
t.ok(await exists('test-publish-package.json5-0.0.0.tgz')) | ||
t.ok(await exists('package.json5')) | ||
t.notOk(await exists('package.json')) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import prepare, { | ||
prepareWithYamlManifest, | ||
prepareWithJson5Manifest, | ||
} from '@pnpm/prepare' | ||
import exists = require('path-exists') | ||
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) => { | ||
prepare(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) | ||
|
||
t.ok(await exists('package.yaml')) | ||
t.notOk(await exists('package.json')) | ||
}) | ||
|
||
test('publish: package with package.json5', async (t: tape.Test) => { | ||
prepareWithJson5Manifest(t, { | ||
name: 'test-publish-package.json5', | ||
version: '0.0.0', | ||
}) | ||
|
||
await execPnpm('publish', ...CREDENTIALS) | ||
|
||
t.ok(await exists('package.json5')) | ||
t.notOk(await exists('package.json')) | ||
}) | ||
|
||
test('publish: package with package.json5 running publish from different folder', async (t: tape.Test) => { | ||
prepareWithJson5Manifest(t, { | ||
name: 'test-publish-package.json5', | ||
version: '0.0.1', | ||
}) | ||
|
||
process.chdir('..') | ||
|
||
await execPnpm('publish', 'project', ...CREDENTIALS) | ||
|
||
t.ok(await exists('project/package.json5')) | ||
t.notOk(await exists('project/package.json')) | ||
}) |
Oops, something went wrong.