Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/five-teams-find.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-publishing": minor
"pnpm": minor
---

Added support for `--dry-run` to the `pack` command [#10301](https://github.com/pnpm/pnpm/issues/10301).
6 changes: 6 additions & 0 deletions .changeset/pink-parks-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@pnpm/plugin-commands-deploy": patch
"pnpm": patch
---

Remove the `injectWorkspacePackages` setting from the lockfile on the `deploy` command [#10294](https://github.com/pnpm/pnpm/pull/10294).
4 changes: 4 additions & 0 deletions releasing/plugin-commands-deploy/src/createDeployFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@ export function createDeployFiles ({
overrides: undefined, // the effects of the overrides should already be part of the package snapshots
packageExtensionsChecksum: undefined, // the effects of the package extensions should already be part of the package snapshots
pnpmfileChecksum: undefined, // the effects of the pnpmfile should already be part of the package snapshots
settings: {
...lockfile.settings,
injectWorkspacePackages: undefined, // the effects of injecting workspace packages should already be part of the lockfile
},
importers: {
['.' as ProjectId]: targetSnapshot,
},
Expand Down
1 change: 1 addition & 0 deletions releasing/plugin-commands-deploy/src/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ async function deployFromSharedLockfile (
modulesDir: undefined,
confirmModulesPurge: false,
frozenLockfile: true,
injectWorkspacePackages: undefined, // the effects of injecting workspace packages should already be part of the package snapshots
overrides: undefined, // the effects of the overrides should already be part of the package snapshots
hooks: {
...opts.hooks,
Expand Down
49 changes: 49 additions & 0 deletions releasing/plugin-commands-deploy/test/deploy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { preparePackages } from '@pnpm/prepare'
import { filterPackagesFromDir } from '@pnpm/workspace.filter-packages-from-dir'
import { jest } from '@jest/globals'
import { DEFAULT_OPTS } from './utils/index.js'
import { install } from '@pnpm/plugin-commands-installation'

const original = await import('@pnpm/logger')
const warn = jest.fn()
Expand Down Expand Up @@ -498,3 +499,51 @@ test('deploy works when workspace packages use catalog protocol', async () => {
// Make sure the is-positive cataloged dependency was actually installed.
expect(fs.existsSync('deploy/node_modules/.pnpm/project-3@file+project-3/node_modules/is-positive')).toBeTruthy()
})

test('deploy does not preserve the inject workspace packages settings in the lockfile', async () => {
preparePackages([
{
location: '.',
package: {
name: 'root',
version: '1.0.0',
private: true,
},
},
{
name: 'project',
version: '1.0.0',
},
])

const { allProjects, selectedProjectsGraph } = await filterPackagesFromDir(process.cwd(), [{ namePattern: 'project' }])

await install.handler({
...DEFAULT_OPTS,
allProjects,
dir: process.cwd(),
dev: true,
production: true,
lockfileOnly: true,
sharedWorkspaceLockfile: true,
lockfileDir: process.cwd(),
workspaceDir: process.cwd(),
})

await deploy.handler({
...DEFAULT_OPTS,
allProjects,
dir: process.cwd(),
dev: false,
production: true,
recursive: true,
selectedProjectsGraph,
sharedWorkspaceLockfile: true,
lockfileDir: process.cwd(),
workspaceDir: process.cwd(),
}, ['dist'])

const project = assertProject(path.resolve('dist'))
const lockfile = project.readLockfile()
expect(lockfile.settings).not.toHaveProperty('injectWorkspacePackages')
})
38 changes: 23 additions & 15 deletions releasing/plugin-commands-publishing/src/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function cliOptionsTypes (): Record<string, unknown> {
out: String,
recursive: Boolean,
...pick([
'dry-run',
'pack-destination',
'pack-gzip-level',
'json',
Expand All @@ -57,6 +58,10 @@ export function help (): string {
title: 'Options',

list: [
{
description: 'Does everything `pnpm pack` would do except actually writing the tarball to disk.',
name: '--dry-run',
},
{
description: 'Directory in which `pnpm pack` will save tarballs. The default is the current working directory.',
name: '--pack-destination <dir>',
Expand Down Expand Up @@ -101,6 +106,7 @@ export type PackOptions = Pick<UniversalOptions, 'dir'> & Pick<Config, 'catalogs
argv: {
original: string[]
}
dryRun?: boolean
engineStrict?: boolean
packDestination?: string
out?: string
Expand Down Expand Up @@ -250,21 +256,23 @@ export async function api (opts: PackOptions): Promise<PackResult> {
const destDir = packDestination
? (path.isAbsolute(packDestination) ? packDestination : path.join(dir, packDestination ?? '.'))
: dir
await fs.promises.mkdir(destDir, { recursive: true })
await packPkg({
destFile: path.join(destDir, tarballName),
filesMap,
modulesDir: path.join(opts.dir, 'node_modules'),
packGzipLevel: opts.packGzipLevel,
manifest: publishManifest,
bins: [
...(await getBinsFromPackageManifest(publishManifest as DependencyManifest, dir)).map(({ path }) => path),
...(manifest.publishConfig?.executableFiles ?? [])
.map((executableFile) => path.join(dir, executableFile)),
],
})
if (!opts.ignoreScripts) {
await _runScriptsIfPresent(['postpack'], entryManifest)
if (!opts.dryRun) {
await fs.promises.mkdir(destDir, { recursive: true })
await packPkg({
destFile: path.join(destDir, tarballName),
filesMap,
modulesDir: path.join(opts.dir, 'node_modules'),
packGzipLevel: opts.packGzipLevel,
manifest: publishManifest,
bins: [
...(await getBinsFromPackageManifest(publishManifest as DependencyManifest, dir)).map(({ path }) => path),
...(manifest.publishConfig?.executableFiles ?? [])
.map((executableFile) => path.join(dir, executableFile)),
],
})
if (!opts.ignoreScripts) {
await _runScriptsIfPresent(['postpack'], entryManifest)
}
}
let packedTarballPath
if (opts.dir !== destDir) {
Expand Down
1 change: 1 addition & 0 deletions releasing/plugin-commands-publishing/src/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ Do you want to continue?`,
...opts,
dir,
packDestination,
dryRun: false,
})
await copyNpmrc({ dir, workspaceDir: opts.workspaceDir, packDestination })
const { status } = runNpm(opts.npmPath, ['publish', '--ignore-scripts', path.basename(tarballPath), ...args], {
Expand Down
18 changes: 18 additions & 0 deletions releasing/plugin-commands-publishing/test/pack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,24 @@ test('pack a package with scoped name', async () => {
expect(fs.existsSync('pnpm-test-scope-0.0.0.tgz')).toBeTruthy()
})

test('pack: with dry-run', async () => {
prepare({
name: 'test-publish-package.json',
version: '0.0.0',
})

await pack.handler({
...DEFAULT_OPTS,
argv: { original: [] },
dir: process.cwd(),
extraBinPaths: [],
dryRun: true,
})

expect(fs.existsSync('test-publish-package.json-0.0.0.tgz')).toBeFalsy()
expect(fs.existsSync('package.json')).toBeTruthy()
})

test('pack when there is bundledDependencies but without node-linker=hoisted', async () => {
prepare({
name: 'bundled-deps-without-node-linker-hoisted',
Expand Down