mirror of
https://github.com/pnpm/pnpm.git
synced 2026-05-24 16:46:06 -04:00
feat(pack): do not pass thru to npm pack (#3608)
This commit is contained in:
5
.changeset/fair-ears-argue.md
Normal file
5
.changeset/fair-ears-argue.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/plugin-commands-publishing": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
`pnpm pack` uses its own inhouse implementation. `pnpm pack` is not using `npm pack`.
|
||||||
5
.changeset/smart-panthers-roll.md
Normal file
5
.changeset/smart-panthers-roll.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/plugin-commands-publishing": minor
|
||||||
|
---
|
||||||
|
|
||||||
|
Run prepublish and prepublishOnly before packing a package.
|
||||||
5
.changeset/warm-rocks-sit.md
Normal file
5
.changeset/warm-rocks-sit.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@pnpm/plugin-commands-publishing": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Do not modify the package.json file before packing the package. Do not copy LICENSE files from the root of the workspace (the files are still packed).
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"rename-overwrite": "^4.0.0",
|
"rename-overwrite": "^4.0.0",
|
||||||
"ssri": "^8.0.1",
|
"ssri": "^8.0.1",
|
||||||
"strip-bom": "^4.0.0",
|
"strip-bom": "^4.0.0",
|
||||||
"tar-stream": "^2.1.4"
|
"tar-stream": "^2.2.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/concat-stream": "^1.6.0",
|
"@types/concat-stream": "^1.6.0",
|
||||||
|
|||||||
@@ -37,6 +37,8 @@
|
|||||||
"@pnpm/logger": "^4.0.0",
|
"@pnpm/logger": "^4.0.0",
|
||||||
"@pnpm/prepare": "workspace:0.0.25",
|
"@pnpm/prepare": "workspace:0.0.25",
|
||||||
"@types/cross-spawn": "^6.0.2",
|
"@types/cross-spawn": "^6.0.2",
|
||||||
|
"@types/gunzip-maybe": "^1.4.0",
|
||||||
|
"@types/npm-packlist": "^1.1.2",
|
||||||
"@types/proxyquire": "^1.3.28",
|
"@types/proxyquire": "^1.3.28",
|
||||||
"@types/ramda": "0.27.39",
|
"@types/ramda": "0.27.39",
|
||||||
"@types/sinon": "^9.0.11",
|
"@types/sinon": "^9.0.11",
|
||||||
@@ -62,13 +64,15 @@
|
|||||||
"@pnpm/sort-packages": "workspace:2.1.0",
|
"@pnpm/sort-packages": "workspace:2.1.0",
|
||||||
"@pnpm/types": "workspace:7.3.0",
|
"@pnpm/types": "workspace:7.3.0",
|
||||||
"@zkochan/rimraf": "^2.1.1",
|
"@zkochan/rimraf": "^2.1.1",
|
||||||
"cp-file": "^9.0.0",
|
|
||||||
"enquirer": "^2.3.6",
|
"enquirer": "^2.3.6",
|
||||||
"fast-glob": "^3.2.4",
|
"fast-glob": "^3.2.4",
|
||||||
|
"gunzip-maybe": "^1.4.2",
|
||||||
|
"npm-packlist": "^2.2.2",
|
||||||
"p-filter": "^2.1.0",
|
"p-filter": "^2.1.0",
|
||||||
"ramda": "^0.27.1",
|
"ramda": "^0.27.1",
|
||||||
"realpath-missing": "^1.1.0",
|
"realpath-missing": "^1.1.0",
|
||||||
"render-help": "^1.0.1",
|
"render-help": "^1.0.1",
|
||||||
|
"tar-stream": "^2.2.0",
|
||||||
"write-json-file": "^4.3.0"
|
"write-json-file": "^4.3.0"
|
||||||
},
|
},
|
||||||
"peerDependencies": {
|
"peerDependencies": {
|
||||||
|
|||||||
@@ -1,8 +1,20 @@
|
|||||||
import { types as allTypes, UniversalOptions } from '@pnpm/config'
|
import fs from 'fs'
|
||||||
import runNpm from '@pnpm/run-npm'
|
import path from 'path'
|
||||||
|
import { types as allTypes, UniversalOptions, Config } from '@pnpm/config'
|
||||||
|
import { readProjectManifest } from '@pnpm/cli-utils'
|
||||||
|
import exportableManifest from '@pnpm/exportable-manifest'
|
||||||
|
import fg from 'fast-glob'
|
||||||
|
import gunzip from 'gunzip-maybe'
|
||||||
import pick from 'ramda/src/pick'
|
import pick from 'ramda/src/pick'
|
||||||
|
import realpathMissing from 'realpath-missing'
|
||||||
import renderHelp from 'render-help'
|
import renderHelp from 'render-help'
|
||||||
import { fakeRegularManifest } from './publish'
|
import tar from 'tar-stream'
|
||||||
|
import packlist from 'npm-packlist'
|
||||||
|
import fromPairs from 'ramda/src/fromPairs'
|
||||||
|
import { runScriptsIfPresent } from './publish'
|
||||||
|
|
||||||
|
const LICENSE_GLOB = 'LICEN{S,C}E{,.*}'
|
||||||
|
const findLicenses = fg.bind(fg, [LICENSE_GLOB]) as (opts: { cwd: string }) => Promise<string[]>
|
||||||
|
|
||||||
export function rcOptionsTypes () {
|
export function rcOptionsTypes () {
|
||||||
return {
|
return {
|
||||||
@@ -27,25 +39,63 @@ export function help () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function handler (
|
export async function handler (
|
||||||
opts: Pick<UniversalOptions, 'dir'> & {
|
opts: Pick<UniversalOptions, 'dir'> & Pick<Config, 'ignoreScripts' | 'rawConfig'> & Partial<Pick<Config, 'extraBinPaths'>> & {
|
||||||
argv: {
|
argv: {
|
||||||
original: string[]
|
original: string[]
|
||||||
}
|
}
|
||||||
engineStrict?: boolean
|
engineStrict?: boolean
|
||||||
npmPath?: string
|
|
||||||
workspaceDir?: string
|
workspaceDir?: string
|
||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
let _status!: number
|
const { manifest } = await readProjectManifest(opts.dir, opts)
|
||||||
await fakeRegularManifest({
|
const _runScriptsIfPresent = runScriptsIfPresent.bind(null, {
|
||||||
dir: opts.dir,
|
depPath: opts.dir,
|
||||||
engineStrict: opts.engineStrict,
|
extraBinPaths: opts.extraBinPaths,
|
||||||
workspaceDir: opts.workspaceDir ?? opts.dir,
|
pkgRoot: opts.dir,
|
||||||
}, async () => {
|
rawConfig: opts.rawConfig,
|
||||||
const { status } = await runNpm(opts.npmPath, ['pack', ...opts.argv.original.slice(1)])
|
rootModulesDir: await realpathMissing(path.join(opts.dir, 'node_modules')),
|
||||||
_status = status!
|
stdio: 'inherit',
|
||||||
|
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
|
||||||
})
|
})
|
||||||
if (_status !== 0) {
|
if (!opts.ignoreScripts) {
|
||||||
process.exit(_status)
|
await _runScriptsIfPresent([
|
||||||
|
'prepublish',
|
||||||
|
'prepare',
|
||||||
|
'prepublishOnly',
|
||||||
|
'prepack',
|
||||||
|
], manifest)
|
||||||
}
|
}
|
||||||
|
const tarballName = `${manifest.name!.replace('@', '').replace('/', '-')}-${manifest.version!}.tgz`
|
||||||
|
const files = await packlist({ path: opts.dir })
|
||||||
|
const filesMap: Record<string, string> = fromPairs(files.map((file) => [`package/${file}`, path.join(opts.dir, file)]))
|
||||||
|
if (opts.workspaceDir != null && opts.dir !== opts.workspaceDir && !files.some((file) => /LICEN[CS]E(\..+)?/i.test(file))) {
|
||||||
|
const licenses = await findLicenses({ cwd: opts.workspaceDir })
|
||||||
|
for (const license of licenses) {
|
||||||
|
filesMap[`package/${license}`] = path.join(opts.workspaceDir, license)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await packPkg(path.join(opts.dir, tarballName), filesMap, opts.dir)
|
||||||
|
if (!opts.ignoreScripts) {
|
||||||
|
await _runScriptsIfPresent(['postpack'], manifest)
|
||||||
|
}
|
||||||
|
return tarballName
|
||||||
|
}
|
||||||
|
|
||||||
|
async function packPkg (destFile: string, filesMap: Record<string, string>, projectDir: string): Promise<void> {
|
||||||
|
const pack = tar.pack()
|
||||||
|
for (const [name, source] of Object.entries(filesMap)) {
|
||||||
|
if (/^package\/package\.(json|json5|yaml)/.test(name)) {
|
||||||
|
const { manifest } = await readProjectManifest(projectDir, {})
|
||||||
|
const publishManifest = await exportableManifest(projectDir, manifest)
|
||||||
|
pack.entry({ name: 'package/package.json' }, JSON.stringify(publishManifest, null, 2))
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
pack.entry({ name }, fs.readFileSync(source))
|
||||||
|
}
|
||||||
|
const tarball = fs.createWriteStream(destFile)
|
||||||
|
pack.pipe(gunzip()).pipe(tarball)
|
||||||
|
pack.finalize()
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
tarball.on('close', () => resolve()).on('error', reject)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,19 +3,15 @@ import path from 'path'
|
|||||||
import { docsUrl, readProjectManifest } from '@pnpm/cli-utils'
|
import { docsUrl, readProjectManifest } from '@pnpm/cli-utils'
|
||||||
import { Config, types as allTypes } from '@pnpm/config'
|
import { Config, types as allTypes } from '@pnpm/config'
|
||||||
import PnpmError from '@pnpm/error'
|
import PnpmError from '@pnpm/error'
|
||||||
import exportableManifest from '@pnpm/exportable-manifest'
|
|
||||||
import runLifecycleHooks, { RunLifecycleHookOptions } from '@pnpm/lifecycle'
|
import runLifecycleHooks, { RunLifecycleHookOptions } from '@pnpm/lifecycle'
|
||||||
import runNpm from '@pnpm/run-npm'
|
import runNpm from '@pnpm/run-npm'
|
||||||
import { ProjectManifest } from '@pnpm/types'
|
import { ProjectManifest } from '@pnpm/types'
|
||||||
import { prompt } from 'enquirer'
|
import { prompt } from 'enquirer'
|
||||||
import rimraf from '@zkochan/rimraf'
|
import rimraf from '@zkochan/rimraf'
|
||||||
import cpFile from 'cp-file'
|
|
||||||
import fg from 'fast-glob'
|
|
||||||
import equals from 'ramda/src/equals'
|
|
||||||
import pick from 'ramda/src/pick'
|
import pick from 'ramda/src/pick'
|
||||||
import realpathMissing from 'realpath-missing'
|
import realpathMissing from 'realpath-missing'
|
||||||
import renderHelp from 'render-help'
|
import renderHelp from 'render-help'
|
||||||
import writeJsonFile from 'write-json-file'
|
import * as pack from './pack'
|
||||||
import recursivePublish, { PublishRecursiveOpts } from './recursivePublish'
|
import recursivePublish, { PublishRecursiveOpts } from './recursivePublish'
|
||||||
import { getCurrentBranch, isGitRepo, isRemoteHistoryClean, isWorkingTreeClean } from './gitChecks'
|
import { getCurrentBranch, isGitRepo, isRemoteHistoryClean, isWorkingTreeClean } from './gitChecks'
|
||||||
|
|
||||||
@@ -159,58 +155,44 @@ Do you want to continue?`,
|
|||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
|
unsafePerm: true, // when running scripts explicitly, assume that they're trusted.
|
||||||
})
|
})
|
||||||
let _status!: number
|
|
||||||
const { manifest } = await readProjectManifest(dir, opts)
|
const { manifest } = await readProjectManifest(dir, opts)
|
||||||
// Unfortunately, we cannot support postpack at the moment
|
// Unfortunately, we cannot support postpack at the moment
|
||||||
if (!opts.ignoreScripts) {
|
let args = opts.argv.original.slice(1)
|
||||||
await _runScriptsIfPresent([
|
if (dirInParams) {
|
||||||
'prepublish',
|
args = args.filter(arg => arg !== params[0])
|
||||||
'prepare',
|
|
||||||
'prepublishOnly',
|
|
||||||
'prepack',
|
|
||||||
], manifest)
|
|
||||||
}
|
}
|
||||||
await fakeRegularManifest(
|
const index = args.indexOf('--publish-branch')
|
||||||
{
|
if (index !== -1) {
|
||||||
dir,
|
// If --publish-branch follows with another cli option, only remove this argument
|
||||||
engineStrict: opts.engineStrict,
|
// otherwise remove the following argument as well
|
||||||
workspaceDir: opts.workspaceDir ?? dir,
|
if (args[index + 1]?.startsWith('-')) {
|
||||||
},
|
args.splice(index, 1)
|
||||||
async () => {
|
} else {
|
||||||
let args = opts.argv.original.slice(1)
|
args.splice(index, 2)
|
||||||
if (dirInParams) {
|
|
||||||
args = args.filter(arg => arg !== params[0])
|
|
||||||
}
|
|
||||||
const index = args.indexOf('--publish-branch')
|
|
||||||
if (index !== -1) {
|
|
||||||
// If --publish-branch follows with another cli option, only remove this argument
|
|
||||||
// otherwise remove the following argument as well
|
|
||||||
if (args[index + 1]?.startsWith('-')) {
|
|
||||||
args.splice(index, 1)
|
|
||||||
} else {
|
|
||||||
args.splice(index, 2)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : dir
|
|
||||||
const localNpmrc = path.join(cwd, '.npmrc')
|
|
||||||
const copyNpmrc = !existsSync(localNpmrc) && opts.workspaceDir && existsSync(path.join(opts.workspaceDir, '.npmrc'))
|
|
||||||
if (copyNpmrc && opts.workspaceDir) {
|
|
||||||
await fs.copyFile(path.join(opts.workspaceDir, '.npmrc'), localNpmrc)
|
|
||||||
}
|
|
||||||
|
|
||||||
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', ...args], {
|
|
||||||
cwd,
|
|
||||||
})
|
|
||||||
if (copyNpmrc) {
|
|
||||||
await rimraf(localNpmrc)
|
|
||||||
}
|
|
||||||
|
|
||||||
_status = status!
|
|
||||||
}
|
}
|
||||||
)
|
}
|
||||||
if (_status !== 0) {
|
|
||||||
process.exit(_status)
|
const cwd = manifest.publishConfig?.directory ? path.join(dir, manifest.publishConfig.directory) : dir
|
||||||
|
const localNpmrc = path.join(cwd, '.npmrc')
|
||||||
|
const copyNpmrc = !existsSync(localNpmrc) && opts.workspaceDir && existsSync(path.join(opts.workspaceDir, '.npmrc'))
|
||||||
|
if (copyNpmrc && opts.workspaceDir) {
|
||||||
|
await fs.copyFile(path.join(opts.workspaceDir, '.npmrc'), localNpmrc)
|
||||||
|
}
|
||||||
|
|
||||||
|
const tarballName = await pack.handler({
|
||||||
|
...opts,
|
||||||
|
dir: cwd,
|
||||||
|
})
|
||||||
|
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', tarballName, ...args], {
|
||||||
|
cwd,
|
||||||
|
})
|
||||||
|
await rimraf(path.join(cwd, tarballName))
|
||||||
|
if (copyNpmrc) {
|
||||||
|
await rimraf(localNpmrc)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (status != null && status !== 0) {
|
||||||
|
process.exit(status)
|
||||||
}
|
}
|
||||||
if (!opts.ignoreScripts) {
|
if (!opts.ignoreScripts) {
|
||||||
await _runScriptsIfPresent([
|
await _runScriptsIfPresent([
|
||||||
@@ -221,7 +203,7 @@ Do you want to continue?`,
|
|||||||
return { manifest }
|
return { manifest }
|
||||||
}
|
}
|
||||||
|
|
||||||
async function runScriptsIfPresent (
|
export async function runScriptsIfPresent (
|
||||||
opts: RunLifecycleHookOptions,
|
opts: RunLifecycleHookOptions,
|
||||||
scriptNames: string[],
|
scriptNames: string[],
|
||||||
manifest: ProjectManifest
|
manifest: ProjectManifest
|
||||||
@@ -231,54 +213,3 @@ async function runScriptsIfPresent (
|
|||||||
await runLifecycleHooks(scriptName, manifest, opts)
|
await runLifecycleHooks(scriptName, manifest, opts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const LICENSE_GLOB = 'LICEN{S,C}E{,.*}'
|
|
||||||
const findLicenses = fg.bind(fg, [LICENSE_GLOB]) as (opts: { cwd: string }) => Promise<string[]>
|
|
||||||
|
|
||||||
export async function fakeRegularManifest (
|
|
||||||
opts: {
|
|
||||||
engineStrict?: boolean
|
|
||||||
dir: string
|
|
||||||
workspaceDir: string
|
|
||||||
},
|
|
||||||
fn: () => Promise<void>
|
|
||||||
) {
|
|
||||||
// If a workspace package has no License of its own,
|
|
||||||
// license files from the root of the workspace are used
|
|
||||||
const copiedLicenses: string[] = opts.dir !== opts.workspaceDir && (await findLicenses({ cwd: opts.dir })).length === 0
|
|
||||||
? await copyLicenses(opts.workspaceDir, opts.dir)
|
|
||||||
: []
|
|
||||||
|
|
||||||
const { fileName, manifest, writeProjectManifest } = await readProjectManifest(opts.dir, opts)
|
|
||||||
const publishManifest = await exportableManifest(opts.dir, manifest)
|
|
||||||
const replaceManifest = fileName !== 'package.json' || !equals(manifest, publishManifest)
|
|
||||||
if (replaceManifest) {
|
|
||||||
await rimraf(path.join(opts.dir, fileName))
|
|
||||||
await writeJsonFile(path.join(opts.dir, 'package.json'), publishManifest)
|
|
||||||
}
|
|
||||||
await fn()
|
|
||||||
if (replaceManifest) {
|
|
||||||
await rimraf(path.join(opts.dir, 'package.json'))
|
|
||||||
await writeProjectManifest(manifest, true)
|
|
||||||
}
|
|
||||||
await Promise.all(
|
|
||||||
copiedLicenses.map(async (copiedLicense) => fs.unlink(copiedLicense))
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function copyLicenses (sourceDir: string, destDir: string) {
|
|
||||||
const licenses = await findLicenses({ cwd: sourceDir })
|
|
||||||
if (licenses.length === 0) return []
|
|
||||||
|
|
||||||
const copiedLicenses: string[] = []
|
|
||||||
await Promise.all(
|
|
||||||
licenses
|
|
||||||
.map((licenseRelPath) => path.join(sourceDir, licenseRelPath))
|
|
||||||
.map((licensePath) => {
|
|
||||||
const licenseCopyDest = path.join(destDir, path.basename(licensePath))
|
|
||||||
copiedLicenses.push(licenseCopyDest)
|
|
||||||
return cpFile(licensePath, licenseCopyDest)
|
|
||||||
})
|
|
||||||
)
|
|
||||||
return copiedLicenses
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { pack } from '@pnpm/plugin-commands-publishing'
|
import { pack } from '@pnpm/plugin-commands-publishing'
|
||||||
import prepare from '@pnpm/prepare'
|
import prepare from '@pnpm/prepare'
|
||||||
import exists from 'path-exists'
|
import exists from 'path-exists'
|
||||||
|
import { DEFAULT_OPTS } from './utils'
|
||||||
|
|
||||||
test('pack: package with package.json', async () => {
|
test('pack: package with package.json', async () => {
|
||||||
prepare({
|
prepare({
|
||||||
@@ -8,7 +9,12 @@ test('pack: package with package.json', async () => {
|
|||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
})
|
})
|
||||||
|
|
||||||
await pack.handler({ argv: { original: [] }, dir: process.cwd() })
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
})
|
||||||
|
|
||||||
expect(await exists('test-publish-package.json-0.0.0.tgz')).toBeTruthy()
|
expect(await exists('test-publish-package.json-0.0.0.tgz')).toBeTruthy()
|
||||||
expect(await exists('package.json')).toBeTruthy()
|
expect(await exists('package.json')).toBeTruthy()
|
||||||
@@ -20,7 +26,12 @@ test('pack: package with package.yaml', async () => {
|
|||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
}, { manifestFormat: 'YAML' })
|
}, { manifestFormat: 'YAML' })
|
||||||
|
|
||||||
await pack.handler({ argv: { original: [] }, dir: process.cwd() })
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
})
|
||||||
|
|
||||||
expect(await exists('test-publish-package.yaml-0.0.0.tgz')).toBeTruthy()
|
expect(await exists('test-publish-package.yaml-0.0.0.tgz')).toBeTruthy()
|
||||||
expect(await exists('package.yaml')).toBeTruthy()
|
expect(await exists('package.yaml')).toBeTruthy()
|
||||||
@@ -33,9 +44,54 @@ test('pack: package with package.json5', async () => {
|
|||||||
version: '0.0.0',
|
version: '0.0.0',
|
||||||
}, { manifestFormat: 'JSON5' })
|
}, { manifestFormat: 'JSON5' })
|
||||||
|
|
||||||
await pack.handler({ argv: { original: [] }, dir: process.cwd() })
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
})
|
||||||
|
|
||||||
expect(await exists('test-publish-package.json5-0.0.0.tgz')).toBeTruthy()
|
expect(await exists('test-publish-package.json5-0.0.0.tgz')).toBeTruthy()
|
||||||
expect(await exists('package.json5')).toBeTruthy()
|
expect(await exists('package.json5')).toBeTruthy()
|
||||||
expect(await exists('package.json')).toBeFalsy()
|
expect(await exists('package.json')).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('pack a package with scoped name', async () => {
|
||||||
|
prepare({
|
||||||
|
name: '@pnpm/test-scope',
|
||||||
|
version: '0.0.0',
|
||||||
|
})
|
||||||
|
|
||||||
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await exists('pnpm-test-scope-0.0.0.tgz')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|
||||||
|
test('pack: runs prepack, prepare, and postpack', async () => {
|
||||||
|
prepare({
|
||||||
|
name: 'test-publish-package.json',
|
||||||
|
version: '0.0.0',
|
||||||
|
scripts: {
|
||||||
|
prepack: 'node -e "require(\'fs\').writeFileSync(\'prepack\', \'\')"',
|
||||||
|
prepare: 'node -e "require(\'fs\').writeFileSync(\'prepare\', \'\')"',
|
||||||
|
postpack: 'node -e "require(\'fs\').writeFileSync(\'postpack\', \'\')"',
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(await exists('test-publish-package.json-0.0.0.tgz')).toBeTruthy()
|
||||||
|
expect(await exists('prepack')).toBeTruthy()
|
||||||
|
expect(await exists('prepare')).toBeTruthy()
|
||||||
|
expect(await exists('postpack')).toBeTruthy()
|
||||||
|
})
|
||||||
|
|||||||
@@ -32,6 +32,8 @@ test('publish: package with package.json', async () => {
|
|||||||
argv: { original: ['publish', ...CREDENTIALS] },
|
argv: { original: ['publish', ...CREDENTIALS] },
|
||||||
dir: process.cwd(),
|
dir: process.cwd(),
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
expect(await exists('test-publish-package.json-0.0.0.tgz')).toBeFalsy()
|
||||||
})
|
})
|
||||||
|
|
||||||
test('publish: package with package.yaml', async () => {
|
test('publish: package with package.yaml', async () => {
|
||||||
@@ -106,10 +108,22 @@ skipOnWindowsCI('pack packages with workspace LICENSE if no own LICENSE is prese
|
|||||||
await fs.writeFile('project-2/LICENSE', 'project-2 license', 'utf8')
|
await fs.writeFile('project-2/LICENSE', 'project-2 license', 'utf8')
|
||||||
|
|
||||||
process.chdir('project-1')
|
process.chdir('project-1')
|
||||||
await pack.handler({ argv: { original: [] }, dir: process.cwd(), workspaceDir })
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
workspaceDir,
|
||||||
|
})
|
||||||
|
|
||||||
process.chdir('../project-2')
|
process.chdir('../project-2')
|
||||||
await pack.handler({ argv: { original: [] }, dir: process.cwd(), workspaceDir })
|
await pack.handler({
|
||||||
|
...DEFAULT_OPTS,
|
||||||
|
argv: { original: [] },
|
||||||
|
dir: process.cwd(),
|
||||||
|
extraBinPaths: [],
|
||||||
|
workspaceDir,
|
||||||
|
})
|
||||||
|
|
||||||
process.chdir('../target')
|
process.chdir('../target')
|
||||||
|
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ registry=http://localhost:${REGISTRY_MOCK_PORT}/
|
|||||||
//localhost:${REGISTRY_MOCK_PORT}/:email=foo@bar.net`
|
//localhost:${REGISTRY_MOCK_PORT}/:email=foo@bar.net`
|
||||||
|
|
||||||
test('recursive publish', async () => {
|
test('recursive publish', async () => {
|
||||||
|
// This suffix is added to the package name to avoid issue if Jest reruns the test
|
||||||
|
const SUFFIX = Date.now()
|
||||||
|
|
||||||
const pkg1 = {
|
const pkg1 = {
|
||||||
name: '@pnpmtest/test-recursive-publish-project-1',
|
name: `@pnpmtest/test-recursive-publish-project-1-${SUFFIX}`,
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
|
|
||||||
dependencies: {
|
dependencies: {
|
||||||
@@ -27,7 +30,7 @@ test('recursive publish', async () => {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
const pkg2 = {
|
const pkg2 = {
|
||||||
name: '@pnpmtest/test-recursive-publish-project-2',
|
name: `@pnpmtest/test-recursive-publish-project-2-${SUFFIX}`,
|
||||||
version: '1.0.0',
|
version: '1.0.0',
|
||||||
|
|
||||||
dependencies: {
|
dependencies: {
|
||||||
@@ -96,11 +99,11 @@ test('recursive publish', async () => {
|
|||||||
|
|
||||||
{
|
{
|
||||||
const { stdout } = await execa('npm', ['view', pkg1.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
|
const { stdout } = await execa('npm', ['view', pkg1.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
|
||||||
expect(JSON.parse(stdout.toString())).toStrictEqual([pkg1.version])
|
expect(JSON.parse(stdout.toString())).toStrictEqual(pkg1.version)
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const { stdout } = await execa('npm', ['view', pkg2.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
|
const { stdout } = await execa('npm', ['view', pkg2.name, 'versions', '--registry', `http://localhost:${REGISTRY_MOCK_PORT}`, '--json'])
|
||||||
expect(JSON.parse(stdout.toString())).toStrictEqual([pkg2.version])
|
expect(JSON.parse(stdout.toString())).toStrictEqual(pkg2.version)
|
||||||
}
|
}
|
||||||
|
|
||||||
await projects[pkg1.name].writePackageJson({ ...pkg1, version: '2.0.0' })
|
await projects[pkg1.name].writePackageJson({ ...pkg1, version: '2.0.0' })
|
||||||
|
|||||||
58
pnpm-lock.yaml
generated
58
pnpm-lock.yaml
generated
@@ -204,7 +204,7 @@ importers:
|
|||||||
rename-overwrite: ^4.0.0
|
rename-overwrite: ^4.0.0
|
||||||
ssri: ^8.0.1
|
ssri: ^8.0.1
|
||||||
strip-bom: ^4.0.0
|
strip-bom: ^4.0.0
|
||||||
tar-stream: ^2.1.4
|
tar-stream: ^2.2.0
|
||||||
tempy: ^1.0.0
|
tempy: ^1.0.0
|
||||||
dependencies:
|
dependencies:
|
||||||
'@pnpm/fetcher-base': link:../fetcher-base
|
'@pnpm/fetcher-base': link:../fetcher-base
|
||||||
@@ -2071,23 +2071,27 @@ importers:
|
|||||||
'@pnpm/sort-packages': workspace:2.1.0
|
'@pnpm/sort-packages': workspace:2.1.0
|
||||||
'@pnpm/types': workspace:7.3.0
|
'@pnpm/types': workspace:7.3.0
|
||||||
'@types/cross-spawn': ^6.0.2
|
'@types/cross-spawn': ^6.0.2
|
||||||
|
'@types/gunzip-maybe': ^1.4.0
|
||||||
|
'@types/npm-packlist': ^1.1.2
|
||||||
'@types/proxyquire': ^1.3.28
|
'@types/proxyquire': ^1.3.28
|
||||||
'@types/ramda': 0.27.39
|
'@types/ramda': 0.27.39
|
||||||
'@types/sinon': ^9.0.11
|
'@types/sinon': ^9.0.11
|
||||||
'@zkochan/rimraf': ^2.1.1
|
'@zkochan/rimraf': ^2.1.1
|
||||||
cp-file: ^9.0.0
|
|
||||||
cross-spawn: ^7.0.3
|
cross-spawn: ^7.0.3
|
||||||
enquirer: ^2.3.6
|
enquirer: ^2.3.6
|
||||||
execa: ^5.0.0
|
execa: ^5.0.0
|
||||||
fast-glob: ^3.2.4
|
fast-glob: ^3.2.4
|
||||||
|
gunzip-maybe: ^1.4.2
|
||||||
is-ci: ^3.0.0
|
is-ci: ^3.0.0
|
||||||
is-windows: ^1.0.2
|
is-windows: ^1.0.2
|
||||||
load-json-file: ^6.2.0
|
load-json-file: ^6.2.0
|
||||||
|
npm-packlist: ^2.2.2
|
||||||
p-filter: ^2.1.0
|
p-filter: ^2.1.0
|
||||||
path-exists: ^4.0.0
|
path-exists: ^4.0.0
|
||||||
ramda: ^0.27.1
|
ramda: ^0.27.1
|
||||||
realpath-missing: ^1.1.0
|
realpath-missing: ^1.1.0
|
||||||
render-help: ^1.0.1
|
render-help: ^1.0.1
|
||||||
|
tar-stream: ^2.2.0
|
||||||
tempy: ^1.0.0
|
tempy: ^1.0.0
|
||||||
write-json-file: ^4.3.0
|
write-json-file: ^4.3.0
|
||||||
write-yaml-file: ^4.2.0
|
write-yaml-file: ^4.2.0
|
||||||
@@ -2104,13 +2108,15 @@ importers:
|
|||||||
'@pnpm/sort-packages': link:../sort-packages
|
'@pnpm/sort-packages': link:../sort-packages
|
||||||
'@pnpm/types': link:../types
|
'@pnpm/types': link:../types
|
||||||
'@zkochan/rimraf': 2.1.1
|
'@zkochan/rimraf': 2.1.1
|
||||||
cp-file: 9.1.0
|
|
||||||
enquirer: 2.3.6
|
enquirer: 2.3.6
|
||||||
fast-glob: 3.2.7
|
fast-glob: 3.2.7
|
||||||
|
gunzip-maybe: 1.4.2
|
||||||
|
npm-packlist: 2.2.2
|
||||||
p-filter: 2.1.0
|
p-filter: 2.1.0
|
||||||
ramda: 0.27.1
|
ramda: 0.27.1
|
||||||
realpath-missing: 1.1.0
|
realpath-missing: 1.1.0
|
||||||
render-help: 1.0.2
|
render-help: 1.0.2
|
||||||
|
tar-stream: 2.2.0
|
||||||
write-json-file: 4.3.0
|
write-json-file: 4.3.0
|
||||||
devDependencies:
|
devDependencies:
|
||||||
'@pnpm/filter-workspace-packages': link:../filter-workspace-packages
|
'@pnpm/filter-workspace-packages': link:../filter-workspace-packages
|
||||||
@@ -2118,6 +2124,8 @@ importers:
|
|||||||
'@pnpm/plugin-commands-publishing': 'link:'
|
'@pnpm/plugin-commands-publishing': 'link:'
|
||||||
'@pnpm/prepare': link:../../privatePackages/prepare
|
'@pnpm/prepare': link:../../privatePackages/prepare
|
||||||
'@types/cross-spawn': 6.0.2
|
'@types/cross-spawn': 6.0.2
|
||||||
|
'@types/gunzip-maybe': 1.4.0
|
||||||
|
'@types/npm-packlist': 1.1.2
|
||||||
'@types/proxyquire': 1.3.28
|
'@types/proxyquire': 1.3.28
|
||||||
'@types/ramda': 0.27.39
|
'@types/ramda': 0.27.39
|
||||||
'@types/sinon': 9.0.11
|
'@types/sinon': 9.0.11
|
||||||
@@ -4736,6 +4744,12 @@ packages:
|
|||||||
'@types/node': 14.17.5
|
'@types/node': 14.17.5
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/@types/gunzip-maybe/1.4.0:
|
||||||
|
resolution: {integrity: sha512-dFP9GrYAR9KhsjTkWJ8q8Gsfql75YIKcg9DuQOj/IrlPzR7W+1zX+cclw1McV82UXAQ+Lpufvgk3e9bC8+HzgA==}
|
||||||
|
dependencies:
|
||||||
|
'@types/node': 16.4.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/hosted-git-info/3.0.2:
|
/@types/hosted-git-info/3.0.2:
|
||||||
resolution: {integrity: sha512-RURNTeEFUwF+ifnp7kK3WLLlTmBSlRynLNS9jeAsI6RHtSrupV0l0nO6kmpaz75EUJVexy348bR452SvmH98vQ==}
|
resolution: {integrity: sha512-RURNTeEFUwF+ifnp7kK3WLLlTmBSlRynLNS9jeAsI6RHtSrupV0l0nO6kmpaz75EUJVexy348bR452SvmH98vQ==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -4854,6 +4868,10 @@ packages:
|
|||||||
/@types/node/16.3.3:
|
/@types/node/16.3.3:
|
||||||
resolution: {integrity: sha512-8h7k1YgQKxKXWckzFCMfsIwn0Y61UK6tlD6y2lOb3hTOIMlK3t9/QwHOhc81TwU+RMf0As5fj7NPjroERCnejQ==}
|
resolution: {integrity: sha512-8h7k1YgQKxKXWckzFCMfsIwn0Y61UK6tlD6y2lOb3hTOIMlK3t9/QwHOhc81TwU+RMf0As5fj7NPjroERCnejQ==}
|
||||||
|
|
||||||
|
/@types/node/16.4.0:
|
||||||
|
resolution: {integrity: sha512-HrJuE7Mlqcjj+00JqMWpZ3tY8w7EUd+S0U3L1+PQSWiXZbOgyQDvi+ogoUxaHApPJq5diKxYBQwA3iIlNcPqOg==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/normalize-package-data/2.4.1:
|
/@types/normalize-package-data/2.4.1:
|
||||||
resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==}
|
resolution: {integrity: sha512-Gj7cI7z+98M282Tqmp2K5EIsoouUEzbBJhQQzDE3jSIRk6r9gsz0oUokqIUR4u1R3dMHo0pDHM7sNOHyhulypw==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -4861,6 +4879,10 @@ packages:
|
|||||||
/@types/normalize-path/3.0.0:
|
/@types/normalize-path/3.0.0:
|
||||||
resolution: {integrity: sha512-Nd8y/5t/7CRakPYiyPzr/IAfYusy1FkcZYFEAcoMZkwpJv2n4Wm+olW+e7xBdHEXhOnWdG9ddbar0gqZWS4x5Q==}
|
resolution: {integrity: sha512-Nd8y/5t/7CRakPYiyPzr/IAfYusy1FkcZYFEAcoMZkwpJv2n4Wm+olW+e7xBdHEXhOnWdG9ddbar0gqZWS4x5Q==}
|
||||||
|
|
||||||
|
/@types/npm-packlist/1.1.2:
|
||||||
|
resolution: {integrity: sha512-9NYoEH87t90e6dkaQOuUTY/R1xUE0a67sXzJBuAB+b+/z4FysHFD19g/O154ToGjyWqKYkezVUtuBdtfd4hyfw==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/@types/parse-json/4.0.0:
|
/@types/parse-json/4.0.0:
|
||||||
resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==}
|
resolution: {integrity: sha512-//oorEZjL6sbPcKUaCdIGlIUeH26mgzimjBB77G6XRgnDl/L5wOnpyBGRe/Mmf5CVW3PwEBE1NjiMZ/ssFh4wA==}
|
||||||
dev: true
|
dev: true
|
||||||
@@ -6820,6 +6842,7 @@ packages:
|
|||||||
make-dir: 3.1.0
|
make-dir: 3.1.0
|
||||||
nested-error-stacks: 2.1.0
|
nested-error-stacks: 2.1.0
|
||||||
p-event: 4.2.0
|
p-event: 4.2.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/cpr/3.0.1:
|
/cpr/3.0.1:
|
||||||
resolution: {integrity: sha1-uaVQOLfNgaNcF7l2GJW9hJau8eU=}
|
resolution: {integrity: sha1-uaVQOLfNgaNcF7l2GJW9hJau8eU=}
|
||||||
@@ -8832,6 +8855,12 @@ packages:
|
|||||||
/ieee754/1.2.1:
|
/ieee754/1.2.1:
|
||||||
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
resolution: {integrity: sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==}
|
||||||
|
|
||||||
|
/ignore-walk/3.0.4:
|
||||||
|
resolution: {integrity: sha512-PY6Ii8o1jMRA1z4F2hRkH/xN59ox43DavKvD3oDpfurRlOJyAHpifIwpbdv1n4jt4ov0jSpw3kQ4GhJnpBL6WQ==}
|
||||||
|
dependencies:
|
||||||
|
minimatch: 3.0.4
|
||||||
|
dev: false
|
||||||
|
|
||||||
/ignore/4.0.6:
|
/ignore/4.0.6:
|
||||||
resolution: {integrity: sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==}
|
resolution: {integrity: sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg==}
|
||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
@@ -10855,6 +10884,7 @@ packages:
|
|||||||
|
|
||||||
/nested-error-stacks/2.1.0:
|
/nested-error-stacks/2.1.0:
|
||||||
resolution: {integrity: sha512-AO81vsIO1k1sM4Zrd6Hu7regmJN1NSiAja10gc4bX3F0wd+9rQmcuHQaHVQCYIEC8iFXnE+mavh23GOt7wBgug==}
|
resolution: {integrity: sha512-AO81vsIO1k1sM4Zrd6Hu7regmJN1NSiAja10gc4bX3F0wd+9rQmcuHQaHVQCYIEC8iFXnE+mavh23GOt7wBgug==}
|
||||||
|
dev: true
|
||||||
|
|
||||||
/next-path/1.0.0:
|
/next-path/1.0.0:
|
||||||
resolution: {integrity: sha1-gixFgNer54PfGZZbeJYiyoAWA+Q=}
|
resolution: {integrity: sha1-gixFgNer54PfGZZbeJYiyoAWA+Q=}
|
||||||
@@ -11014,6 +11044,16 @@ packages:
|
|||||||
once: 1.4.0
|
once: 1.4.0
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/npm-bundled/1.1.2:
|
||||||
|
resolution: {integrity: sha512-x5DHup0SuyQcmL3s7Rx/YQ8sbw/Hzg0rj48eN0dV7hf5cmQq5PXIeioroH3raV1QC1yh3uTYuMThvEQF3iKgGQ==}
|
||||||
|
dependencies:
|
||||||
|
npm-normalize-package-bin: 1.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
|
/npm-normalize-package-bin/1.0.1:
|
||||||
|
resolution: {integrity: sha512-EPfafl6JL5/rU+ot6P3gRSCpPDW5VmIzX959Ob1+ySFUuuYHWHekXpwdUZcKP5C+DS4GEtdJluwBjnsNDl+fSA==}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/npm-package-arg/4.2.1:
|
/npm-package-arg/4.2.1:
|
||||||
resolution: {integrity: sha1-WTMD/eqF98Qid18X+et2cPaA4+w=}
|
resolution: {integrity: sha1-WTMD/eqF98Qid18X+et2cPaA4+w=}
|
||||||
dependencies:
|
dependencies:
|
||||||
@@ -11021,6 +11061,17 @@ packages:
|
|||||||
semver: 5.7.1
|
semver: 5.7.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
|
/npm-packlist/2.2.2:
|
||||||
|
resolution: {integrity: sha512-Jt01acDvJRhJGthnUJVF/w6gumWOZxO7IkpY/lsX9//zqQgnF7OJaxgQXcerd4uQOLu7W5bkb4mChL9mdfm+Zg==}
|
||||||
|
engines: {node: '>=10'}
|
||||||
|
hasBin: true
|
||||||
|
dependencies:
|
||||||
|
glob: 7.1.7
|
||||||
|
ignore-walk: 3.0.4
|
||||||
|
npm-bundled: 1.1.2
|
||||||
|
npm-normalize-package-bin: 1.0.1
|
||||||
|
dev: false
|
||||||
|
|
||||||
/npm-run-all/4.1.5:
|
/npm-run-all/4.1.5:
|
||||||
resolution: {integrity: sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==}
|
resolution: {integrity: sha512-Oo82gJDAVcaMdi3nuoKFavkIHBRVqQ1qvMb+9LHk/cF4P6B2m8aP04hGf7oL6wZ9BuGwX1onlLhpuoofSyoQDQ==}
|
||||||
engines: {node: '>= 4'}
|
engines: {node: '>= 4'}
|
||||||
@@ -11248,6 +11299,7 @@ packages:
|
|||||||
engines: {node: '>=8'}
|
engines: {node: '>=8'}
|
||||||
dependencies:
|
dependencies:
|
||||||
p-timeout: 3.2.0
|
p-timeout: 3.2.0
|
||||||
|
dev: true
|
||||||
|
|
||||||
/p-every/2.0.0:
|
/p-every/2.0.0:
|
||||||
resolution: {integrity: sha512-MCz9DqD5opPC48Zsd+BHm56O/HfhYIQQtupfDzhXoVgQdg/Ux4F8/JcdRuQ+arq7zD5fB6zP3axbH3d9Nr8dlw==}
|
resolution: {integrity: sha512-MCz9DqD5opPC48Zsd+BHm56O/HfhYIQQtupfDzhXoVgQdg/Ux4F8/JcdRuQ+arq7zD5fB6zP3axbH3d9Nr8dlw==}
|
||||||
|
|||||||
Reference in New Issue
Block a user