nx 24.1.0-beta.1 → 24.1.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/command-line/release/utils/repository-git-tags.js +3 -3
- package/dist/src/command-line/reset/reset.js +51 -2
- package/dist/src/daemon/client/daemon-environment.js +15 -0
- package/dist/src/devkit-internals.d.ts +3 -3
- package/dist/src/devkit-internals.js +6 -3
- package/dist/src/generators/utils/glob.js +3 -3
- package/dist/src/hasher/hash-task.d.ts +3 -1
- package/dist/src/hasher/hash-task.js +3 -2
- package/dist/src/native/index.d.ts +0 -4
- package/dist/src/native/index.js +13 -0
- package/dist/src/native/nx.wasm32-wasi.debug.wasm +0 -0
- package/dist/src/native/nx.wasm32-wasi.wasm +0 -0
- package/dist/src/plugins/js/index.js +24 -9
- package/dist/src/plugins/js/lock-file/bun-parser.d.ts +74 -2
- package/dist/src/plugins/js/lock-file/bun-parser.js +971 -139
- package/dist/src/plugins/js/lock-file/lock-file.d.ts +32 -12
- package/dist/src/plugins/js/lock-file/lock-file.js +189 -43
- package/dist/src/plugins/js/lock-file/npm-parser.d.ts +1 -0
- package/dist/src/plugins/js/lock-file/npm-parser.js +66 -2
- package/dist/src/plugins/js/lock-file/pnpm-parser.d.ts +5 -1
- package/dist/src/plugins/js/lock-file/pnpm-parser.js +107 -54
- package/dist/src/plugins/js/lock-file/pruned-output.d.ts +52 -10
- package/dist/src/plugins/js/lock-file/pruned-output.js +132 -66
- package/dist/src/plugins/js/lock-file/utils/local-path-hashes.d.ts +27 -0
- package/dist/src/plugins/js/lock-file/utils/local-path-hashes.js +155 -0
- package/dist/src/plugins/js/lock-file/utils/package-json.d.ts +1 -1
- package/dist/src/plugins/js/lock-file/utils/package-json.js +2 -1
- package/dist/src/plugins/js/package-json/create-package-json.d.ts +1 -0
- package/dist/src/plugins/js/package-json/create-package-json.js +197 -8
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.d.ts +1 -1
- package/dist/src/plugins/js/project-graph/build-dependencies/build-dependencies.js +2 -2
- package/dist/src/plugins/js/project-graph/build-dependencies/explicit-package-json-dependencies.js +16 -9
- package/dist/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.js +17 -28
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.d.ts +47 -1
- package/dist/src/plugins/js/project-graph/build-dependencies/target-project-locator.js +261 -15
- package/dist/src/project-graph/error-types.d.ts +2 -2
- package/dist/src/project-graph/error-types.js +2 -2
- package/dist/src/tasks-runner/init-tasks-runner.js +23 -17
- package/dist/src/tasks-runner/task-orchestrator.js +16 -2
- package/dist/src/tasks-runner/tasks-schedule.js +1 -1
- package/dist/src/tasks-runner/utils.d.ts +2 -1
- package/dist/src/tasks-runner/utils.js +2 -1
- package/dist/src/utils/find-matching-projects.js +7 -9
- package/dist/src/utils/handle-import.js +8 -2
- package/dist/src/utils/json.js +5 -0
- package/dist/src/utils/package-json.d.ts +7 -0
- package/dist/src/utils/package-json.js +9 -0
- package/package.json +13 -12
|
@@ -11,14 +11,23 @@ export { LOCKFILES } from './lock-file-names';
|
|
|
11
11
|
export declare const AUTO_AFFECTED_LOCK_FILES: readonly ["yarn.lock", "package-lock.json", "pnpm-lock.yaml", "pnpm-lock.yml", "bun.lockb", "bun.lock"];
|
|
12
12
|
/**
|
|
13
13
|
* Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
|
|
14
|
+
* `bunPatchFileHashes` are the patch files of a bun.lock that `lockFileHash` covers.
|
|
15
|
+
* `localPathSources` lists the workspace-relative sources of the nodes installed
|
|
16
|
+
* from the local file tree, whose contents the node hashes do not cover.
|
|
17
|
+
* `installedLocalPathNodes` names the local-path node each importer installs
|
|
18
|
+
* per dependency name, keyed by the importer's path ('.' for the root).
|
|
14
19
|
*/
|
|
15
|
-
export declare function getLockFileNodes(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateNodesContext): {
|
|
20
|
+
export declare function getLockFileNodes(packageManager: PackageManager, lockFile: string, contents: string, lockFileHash: string, context: CreateNodesContext, bunPatchFileHashes?: Map<string, string>): {
|
|
16
21
|
nodes: Record<string, ProjectGraphExternalNode>;
|
|
17
22
|
keyMap: Map<string, any>;
|
|
23
|
+
localPathSources?: Record<string, string[]>;
|
|
24
|
+
installedLocalPathNodes: Record<string, Record<string, string>>;
|
|
18
25
|
};
|
|
19
|
-
export declare function getLockFileNodesForName(lockFile: string, contents: string, lockFileHash: string, packageJson?: PackageJson): {
|
|
26
|
+
export declare function getLockFileNodesForName(lockFile: string, contents: string, lockFileHash: string, packageJson?: PackageJson, bunPatchFileHashes?: Map<string, string>): {
|
|
20
27
|
nodes: Record<string, ProjectGraphExternalNode>;
|
|
21
28
|
keyMap: Map<string, any>;
|
|
29
|
+
localPathSources?: Record<string, string[]>;
|
|
30
|
+
installedLocalPathNodes: Record<string, Record<string, string>>;
|
|
22
31
|
};
|
|
23
32
|
/**
|
|
24
33
|
* Parses the lockfile into dependencies between external nodes.
|
|
@@ -32,6 +41,7 @@ export declare function lockFileExists(packageManager: PackageManager): boolean;
|
|
|
32
41
|
*/
|
|
33
42
|
export declare function getLockFileName(packageManager: PackageManager): string;
|
|
34
43
|
export declare function getLockFilePath(packageManager: PackageManager): string;
|
|
44
|
+
export declare function hasTextBunLockfile(workspaceRootPath: string): boolean;
|
|
35
45
|
/**
|
|
36
46
|
* Create lock file based on the root level lock file and (pruned) package.json
|
|
37
47
|
*
|
|
@@ -42,13 +52,18 @@ export declare function getLockFilePath(packageManager: PackageManager): string;
|
|
|
42
52
|
* An inherited `pnpm.patchedDependencies` goes with it, since the prune scopes
|
|
43
53
|
* the lockfile's patches to the packages that survive it and rewrites their
|
|
44
54
|
* paths onto the output.
|
|
45
|
-
* The
|
|
46
|
-
*
|
|
55
|
+
* The block stays in the manifest for npm, yarn and bun, which never read it.
|
|
56
|
+
* For Bun, a dependency whose spec the pruned bun.lock replaces with its locked
|
|
57
|
+
* version takes that version too, since a frozen install rejects the pair
|
|
58
|
+
* otherwise.
|
|
59
|
+
* Since this mutates the manifest, callers must write or emit it after this
|
|
60
|
+
* returns.
|
|
47
61
|
*
|
|
48
62
|
* The lockfile alone does not make a complete pnpm output. A workspace
|
|
49
63
|
* declaring build-script approvals, patches or vendored local paths also needs
|
|
50
64
|
* the artifacts `generatePrunedDeployOutput` ships, and this warns when that is
|
|
51
|
-
* the case.
|
|
65
|
+
* the case. A Bun workspace needs its patch files and vendored local paths the
|
|
66
|
+
* same way.
|
|
52
67
|
*
|
|
53
68
|
* On a pruning error the root lockfile is returned as a fail-open fallback,
|
|
54
69
|
* with the manifest left as authored.
|
|
@@ -65,18 +80,23 @@ type PrunedDeploySink = {
|
|
|
65
80
|
};
|
|
66
81
|
/**
|
|
67
82
|
* Generates the standalone deploy output a generate-package-json flow ships
|
|
68
|
-
* alongside its manifest: the pruned lockfile and
|
|
69
|
-
*
|
|
70
|
-
* `pnpm patch` files, and the vendored non-workspace local-path
|
|
83
|
+
* alongside its manifest: the pruned lockfile and the install-time artifacts
|
|
84
|
+
* that lockfile needs. For pnpm those are the settings-only pnpm-workspace.yaml,
|
|
85
|
+
* the `pnpm patch` files, and the vendored non-workspace local-path
|
|
86
|
+
* dependencies; for Bun, the `bun patch` files and the vendored local-path
|
|
87
|
+
* dependencies.
|
|
71
88
|
* `options` carries either an `outputDirectory` to write into or an `emit` sink
|
|
72
89
|
* for a bundler's asset pipeline, never both.
|
|
73
90
|
*
|
|
74
91
|
* Mutates `packageJson` into the form the output must ship (the relocated
|
|
75
|
-
* local-path specifiers, the pnpm config strip, the pnpm <=10 build settings
|
|
76
|
-
*
|
|
92
|
+
* local-path specifiers, the pnpm config strip, the pnpm <=10 build settings,
|
|
93
|
+
* the Bun root `trustedDependencies`, pruned `patchedDependencies`, override
|
|
94
|
+
* strip and pinned versions), so write or emit the manifest after this returns.
|
|
77
95
|
*
|
|
78
|
-
* Bun
|
|
79
|
-
*
|
|
96
|
+
* A Bun workspace without the text bun.lock, on the binary bun.lockb or with no
|
|
97
|
+
* lockfile at all, gets no lockfile: it warns and ships nothing, leaving the
|
|
98
|
+
* manifest as authored. A Bun manifest without
|
|
99
|
+
* dependencies also ships no lockfile, as Bun writes none for it.
|
|
80
100
|
*/
|
|
81
101
|
export declare function generatePrunedDeployOutput(packageJson: PackageJson, graph: ProjectGraph, projectRoot: string, options: PrunedDeploySink & {
|
|
82
102
|
packageManager: PackageManager;
|
|
@@ -11,6 +11,7 @@ exports.getLockFileDependencies = getLockFileDependencies;
|
|
|
11
11
|
exports.lockFileExists = lockFileExists;
|
|
12
12
|
exports.getLockFileName = getLockFileName;
|
|
13
13
|
exports.getLockFilePath = getLockFilePath;
|
|
14
|
+
exports.hasTextBunLockfile = hasTextBunLockfile;
|
|
14
15
|
exports.createLockFile = createLockFile;
|
|
15
16
|
exports.generatePrunedDeployOutput = generatePrunedDeployOutput;
|
|
16
17
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -48,13 +49,18 @@ const BUN_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, lock
|
|
|
48
49
|
const BUN_TEXT_LOCK_PATH = (0, node_path_1.join)(workspace_root_1.workspaceRoot, lock_file_names_1.BUN_TEXT_LOCK_FILE);
|
|
49
50
|
/**
|
|
50
51
|
* Parses the lockfile into external nodes, plus the keyMap that getLockFileDependencies reads.
|
|
52
|
+
* `bunPatchFileHashes` are the patch files of a bun.lock that `lockFileHash` covers.
|
|
53
|
+
* `localPathSources` lists the workspace-relative sources of the nodes installed
|
|
54
|
+
* from the local file tree, whose contents the node hashes do not cover.
|
|
55
|
+
* `installedLocalPathNodes` names the local-path node each importer installs
|
|
56
|
+
* per dependency name, keyed by the importer's path ('.' for the root).
|
|
51
57
|
*/
|
|
52
|
-
function getLockFileNodes(packageManager, lockFile, contents, lockFileHash, context) {
|
|
58
|
+
function getLockFileNodes(packageManager, lockFile, contents, lockFileHash, context, bunPatchFileHashes) {
|
|
53
59
|
try {
|
|
54
60
|
const packageJson = packageManager === 'yarn' || packageManager === 'bun'
|
|
55
61
|
? (0, fileutils_1.readJsonFile)((0, node_path_1.join)(context.workspaceRoot, 'package.json'))
|
|
56
62
|
: undefined;
|
|
57
|
-
return getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson);
|
|
63
|
+
return getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson, bunPatchFileHashes);
|
|
58
64
|
}
|
|
59
65
|
catch (e) {
|
|
60
66
|
if (!isPostInstallProcess()) {
|
|
@@ -67,12 +73,16 @@ function getLockFileNodes(packageManager, lockFile, contents, lockFileHash, cont
|
|
|
67
73
|
}
|
|
68
74
|
throw new Error(`Unknown package manager: ${packageManager}`);
|
|
69
75
|
}
|
|
70
|
-
function getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson) {
|
|
76
|
+
function getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson, bunPatchFileHashes) {
|
|
71
77
|
if (lockFile === lock_file_names_1.YARN_LOCK_FILE || lockFile === lock_file_names_1.BUN_LOCK_FILE) {
|
|
72
78
|
// yarn-parser only reads optional fields plus an unused `name` for the
|
|
73
79
|
// synthetic root workspace node, which is identical across base/head and
|
|
74
80
|
// therefore irrelevant for affected diffing.
|
|
75
|
-
return
|
|
81
|
+
return {
|
|
82
|
+
...(0, yarn_parser_1.getYarnLockfileNodes)(contents, lockFileHash, packageJson ?? {}),
|
|
83
|
+
// No record for Yarn or bun.lockb; imports resolve by version and name
|
|
84
|
+
installedLocalPathNodes: {},
|
|
85
|
+
};
|
|
76
86
|
}
|
|
77
87
|
if (lockFile === lock_file_names_1.PNPM_LOCK_FILE || lockFile === PNPM_LOCK_FILE_LEGACY) {
|
|
78
88
|
return (0, pnpm_parser_1.getPnpmLockfileNodes)(contents, lockFileHash);
|
|
@@ -81,8 +91,13 @@ function getLockFileNodesForName(lockFile, contents, lockFileHash, packageJson)
|
|
|
81
91
|
return (0, npm_parser_1.getNpmLockfileNodes)(contents, lockFileHash);
|
|
82
92
|
}
|
|
83
93
|
if (lockFile === lock_file_names_1.BUN_TEXT_LOCK_FILE) {
|
|
84
|
-
const nodes = (0, bun_parser_1.getBunTextLockfileNodes)(contents, lockFileHash);
|
|
85
|
-
return {
|
|
94
|
+
const nodes = (0, bun_parser_1.getBunTextLockfileNodes)(contents, lockFileHash, bunPatchFileHashes);
|
|
95
|
+
return {
|
|
96
|
+
nodes,
|
|
97
|
+
keyMap: new Map(),
|
|
98
|
+
localPathSources: (0, bun_parser_1.getBunLocalPathNodeSources)(contents, lockFileHash, nodes),
|
|
99
|
+
installedLocalPathNodes: (0, bun_parser_1.getBunInstalledLocalPathNodes)(contents, lockFileHash, nodes),
|
|
100
|
+
};
|
|
86
101
|
}
|
|
87
102
|
throw new Error(`Unknown lock file: ${lockFile}`);
|
|
88
103
|
}
|
|
@@ -195,6 +210,41 @@ function getLockFilePath(packageManager) {
|
|
|
195
210
|
}
|
|
196
211
|
throw new Error(`Unknown package manager: ${packageManager}`);
|
|
197
212
|
}
|
|
213
|
+
const BUN_TEXT_LOCKFILE_HINT = 'Run `bun install --save-text-lockfile` at the workspace root to switch to bun.lock.';
|
|
214
|
+
// Only the text bun.lock can be pruned. Without it, a Bun deploy output ships
|
|
215
|
+
// the manifest alone.
|
|
216
|
+
function hasTextBunLockfile(workspaceRootPath) {
|
|
217
|
+
return (0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRootPath, lock_file_names_1.BUN_TEXT_LOCK_FILE));
|
|
218
|
+
}
|
|
219
|
+
// Same precedence as getLockFilePath, against the root the caller prunes from.
|
|
220
|
+
function usesBinaryBunLockfile(workspaceRootPath) {
|
|
221
|
+
return (!hasTextBunLockfile(workspaceRootPath) &&
|
|
222
|
+
(0, node_fs_1.existsSync)((0, node_path_1.join)(workspaceRootPath, lock_file_names_1.BUN_LOCK_FILE)));
|
|
223
|
+
}
|
|
224
|
+
// A pruned Bun lockfile is always the text bun.lock.
|
|
225
|
+
function getPrunedLockFileName(packageManager) {
|
|
226
|
+
return packageManager === 'bun'
|
|
227
|
+
? lock_file_names_1.BUN_TEXT_LOCK_FILE
|
|
228
|
+
: getLockFileName(packageManager);
|
|
229
|
+
}
|
|
230
|
+
// Bun trusts the install scripts of the packages the install root lists, and a
|
|
231
|
+
// list replaces Bun's default one, so the output carries the workspace root's.
|
|
232
|
+
function mergeRootTrustedDependencies(packageJson, workspaceRootPath) {
|
|
233
|
+
const rootPackageJsonPath = (0, node_path_1.join)(workspaceRootPath, 'package.json');
|
|
234
|
+
if (!(0, node_fs_1.existsSync)(rootPackageJsonPath)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
const { trustedDependencies } = (0, fileutils_1.readJsonFile)(rootPackageJsonPath);
|
|
238
|
+
if (!trustedDependencies) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
packageJson.trustedDependencies = [
|
|
242
|
+
...new Set([
|
|
243
|
+
...trustedDependencies,
|
|
244
|
+
...(packageJson.trustedDependencies ?? []),
|
|
245
|
+
]),
|
|
246
|
+
];
|
|
247
|
+
}
|
|
198
248
|
/**
|
|
199
249
|
* Create lock file based on the root level lock file and (pruned) package.json
|
|
200
250
|
*
|
|
@@ -205,13 +255,18 @@ function getLockFilePath(packageManager) {
|
|
|
205
255
|
* An inherited `pnpm.patchedDependencies` goes with it, since the prune scopes
|
|
206
256
|
* the lockfile's patches to the packages that survive it and rewrites their
|
|
207
257
|
* paths onto the output.
|
|
208
|
-
* The
|
|
209
|
-
*
|
|
258
|
+
* The block stays in the manifest for npm, yarn and bun, which never read it.
|
|
259
|
+
* For Bun, a dependency whose spec the pruned bun.lock replaces with its locked
|
|
260
|
+
* version takes that version too, since a frozen install rejects the pair
|
|
261
|
+
* otherwise.
|
|
262
|
+
* Since this mutates the manifest, callers must write or emit it after this
|
|
263
|
+
* returns.
|
|
210
264
|
*
|
|
211
265
|
* The lockfile alone does not make a complete pnpm output. A workspace
|
|
212
266
|
* declaring build-script approvals, patches or vendored local paths also needs
|
|
213
267
|
* the artifacts `generatePrunedDeployOutput` ships, and this warns when that is
|
|
214
|
-
* the case.
|
|
268
|
+
* the case. A Bun workspace needs its patch files and vendored local paths the
|
|
269
|
+
* same way.
|
|
215
270
|
*
|
|
216
271
|
* On a pruning error the root lockfile is returned as a fail-open fallback,
|
|
217
272
|
* with the manifest left as authored.
|
|
@@ -220,18 +275,50 @@ function getLockFilePath(packageManager) {
|
|
|
220
275
|
*/
|
|
221
276
|
function createLockFile(packageJson, graph, packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot)) {
|
|
222
277
|
let pruned = true;
|
|
278
|
+
const pinnedSpecs = [];
|
|
223
279
|
const lockFileContent = buildLockFile(packageJson, graph, packageManager, {
|
|
224
280
|
onPruneFallback: () => {
|
|
225
281
|
pruned = false;
|
|
226
282
|
},
|
|
283
|
+
onPinnedSpec: (pin) => pinnedSpecs.push(pin),
|
|
227
284
|
});
|
|
228
285
|
if (pruned && packageManager === 'pnpm') {
|
|
229
286
|
(0, pruned_output_1.stripPrunedLockfilePnpmConfig)(packageJson);
|
|
230
287
|
(0, pruned_output_1.dropInheritedPnpmPatchedDependencies)(packageJson);
|
|
231
288
|
(0, pruned_output_1.warnIncompletePrunedPnpmOutput)(lockFileContent);
|
|
232
289
|
}
|
|
290
|
+
if (pruned && packageManager === 'bun') {
|
|
291
|
+
applyPinnedSpecs(packageJson, pinnedSpecs);
|
|
292
|
+
warnIncompletePrunedBunOutput(lockFileContent);
|
|
293
|
+
}
|
|
233
294
|
return lockFileContent;
|
|
234
295
|
}
|
|
296
|
+
function applyPinnedSpecs(packageJson, pinnedSpecs) {
|
|
297
|
+
for (const { depType, name, spec } of pinnedSpecs) {
|
|
298
|
+
packageJson[depType][name] = spec;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
// The pieces a pruned bun.lock needs beside it, which only
|
|
302
|
+
// `generatePrunedDeployOutput` ships.
|
|
303
|
+
function warnIncompletePrunedBunOutput(lockFileContent) {
|
|
304
|
+
const missing = [];
|
|
305
|
+
if ((0, bun_parser_1.getBunLockfilePatchKeys)(lockFileContent).length) {
|
|
306
|
+
missing.push('the patch files and the patchedDependencies they need');
|
|
307
|
+
}
|
|
308
|
+
if ((0, bun_parser_1.getPrunedBunLocalPathTargets)(lockFileContent).length) {
|
|
309
|
+
missing.push('the vendored file:/link: dependencies it references');
|
|
310
|
+
}
|
|
311
|
+
if (!missing.length) {
|
|
312
|
+
return;
|
|
313
|
+
}
|
|
314
|
+
output_1.output.warn({
|
|
315
|
+
title: 'The pruned bun.lock needs artifacts this call does not return',
|
|
316
|
+
bodyLines: [
|
|
317
|
+
`A standalone install of the output will be missing ${missing.join(', and ')}.`,
|
|
318
|
+
'Use generatePrunedDeployOutput to ship them.',
|
|
319
|
+
],
|
|
320
|
+
});
|
|
321
|
+
}
|
|
235
322
|
/**
|
|
236
323
|
* `createLockFile` without the manifest reconciliation, for callers that own
|
|
237
324
|
* that step themselves. `options.onPruneFallback` fires just before the
|
|
@@ -239,25 +326,31 @@ function createLockFile(packageJson, graph, packageManager = (0, package_manager
|
|
|
239
326
|
* sense for an actually pruned lockfile (e.g. link-closure validation and
|
|
240
327
|
* local-path artifact shipping). Every root-relative read resolves from
|
|
241
328
|
* `options.workspaceRootPath`, so a caller passing one cannot end up with the
|
|
242
|
-
* lockfile read from one root and the catalogs resolved from another.
|
|
329
|
+
* lockfile read from one root and the catalogs resolved from another. Without
|
|
330
|
+
* `options.projectRoot`, a manifest dependency named like a workspace package
|
|
331
|
+
* is taken to be that package.
|
|
243
332
|
*/
|
|
244
333
|
function buildLockFile(packageJson, graph, packageManager = (0, package_manager_1.detectPackageManager)(workspace_root_1.workspaceRoot), options) {
|
|
245
334
|
const workspaceRootPath = options?.workspaceRootPath ?? workspace_root_1.workspaceRoot;
|
|
335
|
+
if (packageManager === 'bun' && usesBinaryBunLockfile(workspaceRootPath)) {
|
|
336
|
+
output_1.output.log({
|
|
337
|
+
title: 'Unable to create a pruned lockfile from the binary bun.lockb',
|
|
338
|
+
bodyLines: [BUN_TEXT_LOCKFILE_HINT],
|
|
339
|
+
});
|
|
340
|
+
return '';
|
|
341
|
+
}
|
|
246
342
|
const normalizedPackageJson = (0, package_json_1.normalizePackageJson)(packageJson);
|
|
247
|
-
const content = (0, node_fs_1.readFileSync)((0, node_path_1.join)(workspaceRootPath,
|
|
343
|
+
const content = (0, node_fs_1.readFileSync)((0, node_path_1.join)(workspaceRootPath, getPrunedLockFileName(packageManager)), 'utf8');
|
|
248
344
|
try {
|
|
249
345
|
if (packageManager === 'bun') {
|
|
250
|
-
|
|
251
|
-
title: "Unable to create bun lock files. Run bun install it's just as quick",
|
|
252
|
-
});
|
|
253
|
-
return '';
|
|
346
|
+
return (0, bun_parser_1.stringifyBunLockfile)(graph, content, normalizedPackageJson, workspaceRootPath, options?.projectRoot, options?.onPinnedSpec);
|
|
254
347
|
}
|
|
255
348
|
const prunedGraph = (0, project_graph_pruning_1.pruneProjectGraph)(graph, packageJson, workspaceRootPath, packageManager);
|
|
256
349
|
if (packageManager === 'yarn') {
|
|
257
350
|
return (0, yarn_parser_1.stringifyYarnLockfile)(prunedGraph, content, normalizedPackageJson);
|
|
258
351
|
}
|
|
259
352
|
if (packageManager === 'pnpm') {
|
|
260
|
-
return (0, pnpm_parser_1.stringifyPnpmLockfile)(prunedGraph, content, normalizedPackageJson, workspaceRootPath);
|
|
353
|
+
return (0, pnpm_parser_1.stringifyPnpmLockfile)(prunedGraph, content, normalizedPackageJson, workspaceRootPath, options?.projectRoot);
|
|
261
354
|
}
|
|
262
355
|
if (packageManager === 'npm') {
|
|
263
356
|
return (0, npm_parser_1.stringifyNpmLockfile)(prunedGraph, content, normalizedPackageJson);
|
|
@@ -285,12 +378,12 @@ function buildLockFile(packageJson, graph, packageManager = (0, package_manager_
|
|
|
285
378
|
}
|
|
286
379
|
/**
|
|
287
380
|
* Creates the pruned lockfile for a generate-package-json flow, running the
|
|
288
|
-
* steps such a flow needs around `createLockFile`. For pnpm, the
|
|
289
|
-
* `file:`/`link:` local-path specifiers are relocated to their
|
|
290
|
-
* first (
|
|
291
|
-
* the manifest's form), and the local-path dependency closure
|
|
292
|
-
* after pruning so a shipped `link:` target that requires an
|
|
293
|
-
* dependency fails the build instead of the deploy. After a successful prune,
|
|
381
|
+
* steps such a flow needs around `createLockFile`. For pnpm and Bun, the
|
|
382
|
+
* manifest's `file:`/`link:` local-path specifiers are relocated to their
|
|
383
|
+
* shipped location first (both re-resolve them on a non-frozen install, and the
|
|
384
|
+
* lockfile copies the manifest's form), and the local-path dependency closure
|
|
385
|
+
* is validated after pruning so a shipped `link:` target that requires an
|
|
386
|
+
* unresolvable dependency fails the build instead of the deploy. After a successful prune,
|
|
294
387
|
* the manifest's pnpm config block is stripped for every package manager:
|
|
295
388
|
* re-declaring config a pruned pnpm lockfile bakes into its snapshots trips
|
|
296
389
|
* ERR_PNPM_LOCKFILE_CONFIG_MISMATCH, and npm and yarn never read the block at
|
|
@@ -305,32 +398,47 @@ function buildLockFile(packageJson, graph, packageManager = (0, package_manager_
|
|
|
305
398
|
* the closure validation is skipped, and the remaining install-time pieces must
|
|
306
399
|
* not ship local-path artifacts for it (see `getPrunedPnpmInstallArtifacts`).
|
|
307
400
|
*
|
|
308
|
-
* Mutates `packageJson` (the pnpm
|
|
309
|
-
* strip
|
|
310
|
-
*
|
|
401
|
+
* Mutates `packageJson` (the pnpm and Bun specifier relocation, the config
|
|
402
|
+
* strip, and for Bun the `overrides`/`resolutions` strip and the locked version
|
|
403
|
+
* of each dependency an override installed outside its range or in place of
|
|
404
|
+
* its local path), so write or emit the manifest after calling this.
|
|
311
405
|
*/
|
|
312
406
|
function createPrunedLockfile(packageJson, graph, projectRoot, workspaceRootPath = workspace_root_1.workspaceRoot, packageManager = (0, package_manager_1.detectPackageManager)(workspaceRootPath)) {
|
|
313
407
|
const originalPackageJson = structuredClone(packageJson);
|
|
314
|
-
if (packageManager === 'pnpm') {
|
|
315
|
-
(0, pruned_output_1.rewritePrunedLocalPathSpecifiers)(packageJson, projectRoot, workspaceRootPath,
|
|
408
|
+
if (packageManager === 'pnpm' || packageManager === 'bun') {
|
|
409
|
+
(0, pruned_output_1.rewritePrunedLocalPathSpecifiers)(packageJson, projectRoot, workspaceRootPath, (0, get_workspace_packages_from_graph_1.getWorkspacePackagesFromGraph)(graph), packageManager);
|
|
316
410
|
}
|
|
411
|
+
if (packageManager === 'bun') {
|
|
412
|
+
// Bun reads these only from the workspace root, whose effect the pruned
|
|
413
|
+
// bun.lock already locks, so a project's own block never applied.
|
|
414
|
+
delete packageJson.overrides;
|
|
415
|
+
delete packageJson.resolutions;
|
|
416
|
+
}
|
|
417
|
+
const pinnedSpecs = [];
|
|
317
418
|
let pruneError;
|
|
318
419
|
const lockFileContent = buildLockFile(packageJson, graph, packageManager, {
|
|
319
420
|
onPruneFallback: (error) => {
|
|
320
421
|
pruneError = error;
|
|
321
422
|
},
|
|
322
423
|
workspaceRootPath,
|
|
424
|
+
projectRoot,
|
|
425
|
+
onPinnedSpec: (pin) => pinnedSpecs.push(pin),
|
|
323
426
|
});
|
|
324
427
|
const pruned = pruneError === undefined;
|
|
325
428
|
if (pruned) {
|
|
429
|
+
applyPinnedSpecs(packageJson, pinnedSpecs);
|
|
326
430
|
(0, pruned_output_1.stripPrunedLockfilePnpmConfig)(packageJson);
|
|
327
431
|
if (packageManager === 'pnpm') {
|
|
328
432
|
(0, pruned_output_1.validatePrunedLocalPathClosure)(packageJson, workspaceRootPath, lockFileContent);
|
|
329
433
|
}
|
|
434
|
+
else if (packageManager === 'bun') {
|
|
435
|
+
(0, bun_parser_1.validatePrunedBunLocalPathClosure)(packageJson, workspaceRootPath, lockFileContent);
|
|
436
|
+
}
|
|
330
437
|
}
|
|
331
438
|
else {
|
|
332
439
|
// The root lockfile matches the manifest as authored, so undo the
|
|
333
|
-
// specifier relocation and
|
|
440
|
+
// specifier relocation and the Bun override strip, and keep the pnpm
|
|
441
|
+
// config it still declares.
|
|
334
442
|
for (const key of Object.keys(packageJson)) {
|
|
335
443
|
delete packageJson[key];
|
|
336
444
|
}
|
|
@@ -342,6 +450,9 @@ function createPrunedLockfile(packageJson, graph, projectRoot, workspaceRootPath
|
|
|
342
450
|
if (packageManager === 'pnpm') {
|
|
343
451
|
bodyLines.push('The emitted package.json keeps its resolution-time pnpm config (`overrides`, `packageExtensions`), its vendored local-path specifiers point at their original workspace locations, and no local-path artifacts are shipped for it.');
|
|
344
452
|
}
|
|
453
|
+
else if (packageManager === 'bun') {
|
|
454
|
+
bodyLines.push('The vendored local-path specifiers of the emitted package.json point at their original workspace locations, and no local-path artifacts are shipped for it.');
|
|
455
|
+
}
|
|
345
456
|
bodyLines.push(packageManager === 'npm'
|
|
346
457
|
? '`npm ci` in the output will fail; run `npm install` instead.'
|
|
347
458
|
: packageManager === 'yarn'
|
|
@@ -357,42 +468,77 @@ function createPrunedLockfile(packageJson, graph, projectRoot, workspaceRootPath
|
|
|
357
468
|
}
|
|
358
469
|
/**
|
|
359
470
|
* Generates the standalone deploy output a generate-package-json flow ships
|
|
360
|
-
* alongside its manifest: the pruned lockfile and
|
|
361
|
-
*
|
|
362
|
-
* `pnpm patch` files, and the vendored non-workspace local-path
|
|
471
|
+
* alongside its manifest: the pruned lockfile and the install-time artifacts
|
|
472
|
+
* that lockfile needs. For pnpm those are the settings-only pnpm-workspace.yaml,
|
|
473
|
+
* the `pnpm patch` files, and the vendored non-workspace local-path
|
|
474
|
+
* dependencies; for Bun, the `bun patch` files and the vendored local-path
|
|
475
|
+
* dependencies.
|
|
363
476
|
* `options` carries either an `outputDirectory` to write into or an `emit` sink
|
|
364
477
|
* for a bundler's asset pipeline, never both.
|
|
365
478
|
*
|
|
366
479
|
* Mutates `packageJson` into the form the output must ship (the relocated
|
|
367
|
-
* local-path specifiers, the pnpm config strip, the pnpm <=10 build settings
|
|
368
|
-
*
|
|
480
|
+
* local-path specifiers, the pnpm config strip, the pnpm <=10 build settings,
|
|
481
|
+
* the Bun root `trustedDependencies`, pruned `patchedDependencies`, override
|
|
482
|
+
* strip and pinned versions), so write or emit the manifest after this returns.
|
|
369
483
|
*
|
|
370
|
-
* Bun
|
|
371
|
-
*
|
|
484
|
+
* A Bun workspace without the text bun.lock, on the binary bun.lockb or with no
|
|
485
|
+
* lockfile at all, gets no lockfile: it warns and ships nothing, leaving the
|
|
486
|
+
* manifest as authored. A Bun manifest without
|
|
487
|
+
* dependencies also ships no lockfile, as Bun writes none for it.
|
|
372
488
|
*/
|
|
373
489
|
function generatePrunedDeployOutput(packageJson, graph, projectRoot, options) {
|
|
374
490
|
const workspaceRootPath = options.workspaceRoot ?? workspace_root_1.workspaceRoot;
|
|
375
491
|
const { packageManager } = options;
|
|
376
|
-
if (packageManager === 'bun') {
|
|
492
|
+
if (packageManager === 'bun' && !hasTextBunLockfile(workspaceRootPath)) {
|
|
377
493
|
output_1.output.warn({
|
|
378
|
-
title: 'Bun lockfile generation
|
|
379
|
-
bodyLines:
|
|
380
|
-
|
|
381
|
-
|
|
494
|
+
title: 'Bun lockfile generation requires the text bun.lock',
|
|
495
|
+
bodyLines: usesBinaryBunLockfile(workspaceRootPath)
|
|
496
|
+
? [
|
|
497
|
+
'The workspace uses the binary bun.lockb, so only the package.json is generated.',
|
|
498
|
+
BUN_TEXT_LOCKFILE_HINT,
|
|
499
|
+
]
|
|
500
|
+
: [
|
|
501
|
+
'The workspace has no bun.lock, so only the package.json is generated.',
|
|
502
|
+
],
|
|
382
503
|
});
|
|
383
504
|
return;
|
|
384
505
|
}
|
|
506
|
+
if (packageManager === 'bun') {
|
|
507
|
+
mergeRootTrustedDependencies(packageJson, workspaceRootPath);
|
|
508
|
+
}
|
|
385
509
|
const { lockFileContent, pruned } = createPrunedLockfile(packageJson, graph, projectRoot, workspaceRootPath, packageManager);
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
510
|
+
// A pruned bun.lock is empty for a manifest without dependencies, which
|
|
511
|
+
// ships without one.
|
|
512
|
+
const shipsLockFile = !(packageManager === 'bun' && lockFileContent === '');
|
|
513
|
+
const artifacts = shipsLockFile
|
|
514
|
+
? [
|
|
515
|
+
{
|
|
516
|
+
path: getPrunedLockFileName(packageManager),
|
|
517
|
+
content: lockFileContent,
|
|
518
|
+
},
|
|
519
|
+
]
|
|
520
|
+
: [];
|
|
389
521
|
if (packageManager === 'pnpm') {
|
|
390
522
|
artifacts.push(...(0, pruned_output_1.getPrunedPnpmInstallArtifacts)(workspaceRootPath, lockFileContent, packageJson, { includeLocalPathArtifacts: pruned }));
|
|
391
523
|
}
|
|
524
|
+
if (packageManager === 'bun') {
|
|
525
|
+
artifacts.push(...(0, bun_parser_1.getPrunedBunPatchArtifacts)(workspaceRootPath, lockFileContent, packageJson));
|
|
526
|
+
// The root-lockfile fallback references the whole workspace.
|
|
527
|
+
if (pruned) {
|
|
528
|
+
artifacts.push(...(0, pruned_output_1.getLocalPathArtifacts)(workspaceRootPath, (0, bun_parser_1.getPrunedBunLocalPathTargets)(lockFileContent)));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
392
531
|
// Discriminate on the value, not key presence: options built by spread can
|
|
393
532
|
// carry an explicitly-present `outputDirectory: undefined` beside `emit`.
|
|
394
533
|
if (options.outputDirectory !== undefined) {
|
|
395
534
|
const { outputDirectory } = options;
|
|
535
|
+
// Bun rejects a frozen install when a lockfile from a prior deploy sits
|
|
536
|
+
// beside a manifest without dependencies.
|
|
537
|
+
if (!shipsLockFile) {
|
|
538
|
+
(0, node_fs_1.rmSync)((0, node_path_1.join)(outputDirectory, getPrunedLockFileName(packageManager)), {
|
|
539
|
+
force: true,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
396
542
|
// Directory trees flow through here one file at a time, so dedupe the
|
|
397
543
|
// recursive mkdir per destination directory.
|
|
398
544
|
const createdDirs = new Set();
|
|
@@ -5,6 +5,7 @@ import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
|
|
5
5
|
export declare function getNpmLockfileNodes(lockFileContent: string, lockFileHash: string): {
|
|
6
6
|
nodes: Record<string, ProjectGraphExternalNode>;
|
|
7
7
|
keyMap: Map<string, ProjectGraphExternalNode>;
|
|
8
|
+
installedLocalPathNodes: Record<string, Record<string, string>>;
|
|
8
9
|
};
|
|
9
10
|
export declare function getNpmLockfileDependencies(lockFileContent: string, lockFileHash: string, ctx: CreateDependenciesContext, keyMap: Map<string, ProjectGraphExternalNode>): RawProjectGraphDependency[];
|
|
10
11
|
export declare function stringifyNpmLockfile(graph: ProjectGraph, rootLockFileContent: string, packageJson: NormalizedPackageJson): string;
|
|
@@ -33,6 +33,7 @@ function getNpmLockfileDependencies(lockFileContent, lockFileHash, ctx, keyMap)
|
|
|
33
33
|
function getNodes(data) {
|
|
34
34
|
const keyMap = new Map();
|
|
35
35
|
const nodes = new Map();
|
|
36
|
+
const localPathPackageNames = new Set();
|
|
36
37
|
if (data.lockfileVersion > 1) {
|
|
37
38
|
Object.entries(data.packages).forEach(([path, snapshot]) => {
|
|
38
39
|
// skip workspaces and snapshots bundled into their parent package
|
|
@@ -47,6 +48,9 @@ function getNodes(data) {
|
|
|
47
48
|
// symlinked packages in workspaces do not have versions
|
|
48
49
|
if (version) {
|
|
49
50
|
createNode(packageName, version, path, nodes, keyMap, snapshot);
|
|
51
|
+
if (snapshot.resolved?.startsWith('file:')) {
|
|
52
|
+
localPathPackageNames.add(packageName);
|
|
53
|
+
}
|
|
50
54
|
}
|
|
51
55
|
});
|
|
52
56
|
}
|
|
@@ -77,7 +81,63 @@ function getNodes(data) {
|
|
|
77
81
|
results[node.name] = node;
|
|
78
82
|
});
|
|
79
83
|
}
|
|
80
|
-
return {
|
|
84
|
+
return {
|
|
85
|
+
nodes: results,
|
|
86
|
+
keyMap,
|
|
87
|
+
installedLocalPathNodes: localPathPackageNames.size
|
|
88
|
+
? getInstalledLocalPathNodes(data, keyMap, localPathPackageNames)
|
|
89
|
+
: {},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function getInstalledLocalPathNodes(data, keyMap, localPathPackageNames) {
|
|
93
|
+
const installed = Object.create(null);
|
|
94
|
+
for (const importerPath in data.packages) {
|
|
95
|
+
if (importerPath !== '' && importerPath.includes('node_modules')) {
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
const importer = data.packages[importerPath];
|
|
99
|
+
for (const deps of [
|
|
100
|
+
importer.dependencies,
|
|
101
|
+
importer.devDependencies,
|
|
102
|
+
importer.optionalDependencies,
|
|
103
|
+
importer.peerDependencies,
|
|
104
|
+
]) {
|
|
105
|
+
for (const depName of Object.keys(deps ?? {})) {
|
|
106
|
+
if (!localPathPackageNames.has(depName)) {
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
// Node loads the nearest copy, so a registry copy there wins
|
|
110
|
+
const key = findNearestNpmPackageKey(data, importerPath, depName);
|
|
111
|
+
const snapshot = key && data.packages[key];
|
|
112
|
+
if (!snapshot ||
|
|
113
|
+
snapshot.link ||
|
|
114
|
+
!snapshot.resolved?.startsWith('file:') ||
|
|
115
|
+
(snapshot.name && snapshot.name !== depName)) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const node = keyMap.get(key);
|
|
119
|
+
if (node) {
|
|
120
|
+
(installed[importerPath || '.'] ??= Object.create(null))[depName] =
|
|
121
|
+
node.name;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return installed;
|
|
127
|
+
}
|
|
128
|
+
function findNearestNpmPackageKey(data, importerPath, packageName) {
|
|
129
|
+
let dir = importerPath;
|
|
130
|
+
while (true) {
|
|
131
|
+
const key = `${dir ? `${dir}/` : ''}node_modules/${packageName}`;
|
|
132
|
+
if (data.packages[key]) {
|
|
133
|
+
return key;
|
|
134
|
+
}
|
|
135
|
+
if (!dir) {
|
|
136
|
+
return undefined;
|
|
137
|
+
}
|
|
138
|
+
const slash = dir.lastIndexOf('/');
|
|
139
|
+
dir = slash === -1 ? '' : dir.slice(0, slash);
|
|
140
|
+
}
|
|
81
141
|
}
|
|
82
142
|
function addV1Node(packageName, snapshot, path, nodes, keyMap) {
|
|
83
143
|
createNode(packageName, snapshot.version, path, nodes, keyMap, snapshot);
|
|
@@ -210,7 +270,11 @@ fallback) {
|
|
|
210
270
|
return child;
|
|
211
271
|
}
|
|
212
272
|
}
|
|
213
|
-
else if (
|
|
273
|
+
else if (
|
|
274
|
+
// A `file:` copy named by its path matches no range. Node loads the
|
|
275
|
+
// nearest copy, so it wins unless a nearer copy is already the fallback.
|
|
276
|
+
(!fallback && child.data.version.startsWith('file:')) ||
|
|
277
|
+
child.data.version === versionRange ||
|
|
214
278
|
cachedSatisfies(child.data.version, versionRange)) {
|
|
215
279
|
return child;
|
|
216
280
|
}
|
|
@@ -5,6 +5,10 @@ import { CreateDependenciesContext } from '../../../project-graph/plugins';
|
|
|
5
5
|
export declare function getPnpmLockfileNodes(lockFileContent: string, lockFileHash: string): {
|
|
6
6
|
nodes: Record<string, ProjectGraphExternalNode>;
|
|
7
7
|
keyMap: Map<string, Set<ProjectGraphExternalNode>>;
|
|
8
|
+
/** Workspace-relative local path sources per node name. */
|
|
9
|
+
localPathSources: Record<string, string[]>;
|
|
10
|
+
/** The `file:` node each importer installs, per importer path and name. */
|
|
11
|
+
installedLocalPathNodes: Record<string, Record<string, string>>;
|
|
8
12
|
};
|
|
9
13
|
export declare function getPnpmLockfileDependencies(lockFileContent: string, lockFileHash: string, ctx: CreateDependenciesContext, keyMap: Map<string, Set<ProjectGraphExternalNode>>): RawProjectGraphDependency[];
|
|
10
|
-
export declare function stringifyPnpmLockfile(graph: ProjectGraph, rootLockFileContent: string, packageJson: NormalizedPackageJson, workspaceRoot: string): string;
|
|
14
|
+
export declare function stringifyPnpmLockfile(graph: ProjectGraph, rootLockFileContent: string, packageJson: NormalizedPackageJson, workspaceRoot: string, projectRoot?: string): string;
|