nx 19.1.0-canary.20240522-89fdd42 → 19.1.0-canary.20240523-261b0ff
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/package.json +17 -13
- package/schemas/nx-schema.json +1 -1
- package/src/command-line/format/format.js +47 -25
- package/src/command-line/init/implementation/react/index.js +1 -0
- package/src/core/graph/main.js +1 -1
- package/src/plugins/js/index.js +7 -2
- package/src/plugins/js/lock-file/lock-file.js +31 -1
- package/src/project-graph/utils/retrieve-workspace-files.d.ts +3 -3
- package/src/utils/ab-testing.js +5 -0
- package/src/utils/package-manager.d.ts +2 -2
- package/src/utils/package-manager.js +40 -8
package/src/plugins/js/index.js
CHANGED
@@ -14,6 +14,7 @@ const file_hasher_1 = require("../../hasher/file-hasher");
|
|
14
14
|
const package_manager_1 = require("../../utils/package-manager");
|
15
15
|
const workspace_root_1 = require("../../utils/workspace-root");
|
16
16
|
const versions_1 = require("../../utils/versions");
|
17
|
+
const child_process_1 = require("child_process");
|
17
18
|
exports.name = 'nx/js/dependencies-and-lockfile';
|
18
19
|
let parsedLockFile = {};
|
19
20
|
exports.createNodes = [
|
@@ -30,7 +31,9 @@ exports.createNodes = [
|
|
30
31
|
return {};
|
31
32
|
}
|
32
33
|
const lockFilePath = (0, path_1.join)(workspace_root_1.workspaceRoot, lockFile);
|
33
|
-
const lockFileContents =
|
34
|
+
const lockFileContents = packageManager !== 'bun'
|
35
|
+
? (0, fs_1.readFileSync)(lockFilePath).toString()
|
36
|
+
: (0, child_process_1.execSync)(`bun ${lockFilePath}`).toString();
|
34
37
|
const lockFileHash = getLockFileHash(lockFileContents);
|
35
38
|
if (!lockFileNeedsReprocessing(lockFileHash)) {
|
36
39
|
const nodes = readCachedParsedLockFile().externalNodes;
|
@@ -55,7 +58,9 @@ const createDependencies = (_, ctx) => {
|
|
55
58
|
(0, lock_file_1.lockFileExists)(packageManager) &&
|
56
59
|
parsedLockFile.externalNodes) {
|
57
60
|
const lockFilePath = (0, path_1.join)(workspace_root_1.workspaceRoot, (0, lock_file_1.getLockFileName)(packageManager));
|
58
|
-
const lockFileContents =
|
61
|
+
const lockFileContents = packageManager !== 'bun'
|
62
|
+
? (0, fs_1.readFileSync)(lockFilePath).toString()
|
63
|
+
: (0, child_process_1.execSync)(`bun ${lockFilePath}`).toString();
|
59
64
|
const lockFileHash = getLockFileHash(lockFileContents);
|
60
65
|
if (!lockFileNeedsReprocessing(lockFileHash)) {
|
61
66
|
lockfileDependencies = readCachedParsedLockFile().dependencies ?? [];
|
@@ -19,10 +19,17 @@ const fileutils_1 = require("../../../utils/fileutils");
|
|
19
19
|
const YARN_LOCK_FILE = 'yarn.lock';
|
20
20
|
const NPM_LOCK_FILE = 'package-lock.json';
|
21
21
|
const PNPM_LOCK_FILE = 'pnpm-lock.yaml';
|
22
|
-
|
22
|
+
const BUN_LOCK_FILE = 'bun.lockb';
|
23
|
+
exports.LOCKFILES = [
|
24
|
+
YARN_LOCK_FILE,
|
25
|
+
NPM_LOCK_FILE,
|
26
|
+
PNPM_LOCK_FILE,
|
27
|
+
BUN_LOCK_FILE,
|
28
|
+
];
|
23
29
|
const YARN_LOCK_PATH = (0, path_1.join)(workspace_root_1.workspaceRoot, YARN_LOCK_FILE);
|
24
30
|
const NPM_LOCK_PATH = (0, path_1.join)(workspace_root_1.workspaceRoot, NPM_LOCK_FILE);
|
25
31
|
const PNPM_LOCK_PATH = (0, path_1.join)(workspace_root_1.workspaceRoot, PNPM_LOCK_FILE);
|
32
|
+
const BUN_LOCK_PATH = (0, path_1.join)(workspace_root_1.workspaceRoot, BUN_LOCK_FILE);
|
26
33
|
/**
|
27
34
|
* Parses lock file and maps dependencies and metadata to {@link LockFileGraph}
|
28
35
|
*/
|
@@ -38,6 +45,11 @@ function getLockFileNodes(packageManager, contents, lockFileHash, context) {
|
|
38
45
|
if (packageManager === 'npm') {
|
39
46
|
return (0, npm_parser_1.getNpmLockfileNodes)(contents, lockFileHash);
|
40
47
|
}
|
48
|
+
if (packageManager === 'bun') {
|
49
|
+
// bun uses yarn v1 for the file format
|
50
|
+
const packageJson = (0, fileutils_1.readJsonFile)('package.json');
|
51
|
+
return (0, yarn_parser_1.getYarnLockfileNodes)(contents, lockFileHash, packageJson);
|
52
|
+
}
|
41
53
|
}
|
42
54
|
catch (e) {
|
43
55
|
if (!isPostInstallProcess()) {
|
@@ -65,6 +77,10 @@ function getLockFileDependencies(packageManager, contents, lockFileHash, context
|
|
65
77
|
if (packageManager === 'npm') {
|
66
78
|
return (0, npm_parser_1.getNpmLockfileDependencies)(contents, lockFileHash, context);
|
67
79
|
}
|
80
|
+
if (packageManager === 'bun') {
|
81
|
+
// bun uses yarn v1 for the file format
|
82
|
+
return (0, yarn_parser_1.getYarnLockfileDependencies)(contents, lockFileHash, context);
|
83
|
+
}
|
68
84
|
}
|
69
85
|
catch (e) {
|
70
86
|
if (!isPostInstallProcess()) {
|
@@ -88,6 +104,9 @@ function lockFileExists(packageManager) {
|
|
88
104
|
if (packageManager === 'npm') {
|
89
105
|
return (0, fs_1.existsSync)(NPM_LOCK_PATH);
|
90
106
|
}
|
107
|
+
if (packageManager === 'bun') {
|
108
|
+
return (0, fs_1.existsSync)(BUN_LOCK_PATH);
|
109
|
+
}
|
91
110
|
throw new Error(`Unknown package manager ${packageManager} or lock file missing`);
|
92
111
|
}
|
93
112
|
exports.lockFileExists = lockFileExists;
|
@@ -106,6 +125,9 @@ function getLockFileName(packageManager) {
|
|
106
125
|
if (packageManager === 'npm') {
|
107
126
|
return NPM_LOCK_FILE;
|
108
127
|
}
|
128
|
+
if (packageManager === 'bun') {
|
129
|
+
return BUN_LOCK_FILE;
|
130
|
+
}
|
109
131
|
throw new Error(`Unknown package manager: ${packageManager}`);
|
110
132
|
}
|
111
133
|
exports.getLockFileName = getLockFileName;
|
@@ -119,6 +141,9 @@ function getLockFilePath(packageManager) {
|
|
119
141
|
if (packageManager === 'npm') {
|
120
142
|
return NPM_LOCK_PATH;
|
121
143
|
}
|
144
|
+
if (packageManager === 'bun') {
|
145
|
+
return BUN_LOCK_PATH;
|
146
|
+
}
|
122
147
|
throw new Error(`Unknown package manager: ${packageManager}`);
|
123
148
|
}
|
124
149
|
/**
|
@@ -145,6 +170,11 @@ function createLockFile(packageJson, graph, packageManager = (0, package_manager
|
|
145
170
|
const prunedGraph = (0, project_graph_pruning_1.pruneProjectGraph)(graph, packageJson);
|
146
171
|
return (0, npm_parser_1.stringifyNpmLockfile)(prunedGraph, content, normalizedPackageJson);
|
147
172
|
}
|
173
|
+
if (packageManager === 'bun') {
|
174
|
+
output_1.output.log({
|
175
|
+
title: "Unable to create bun lock files. Run bun install it's just as quick",
|
176
|
+
});
|
177
|
+
}
|
148
178
|
}
|
149
179
|
catch (e) {
|
150
180
|
if (!isPostInstallProcess()) {
|
@@ -9,12 +9,12 @@ import { LoadedNxPlugin } from '../plugins/internal-api';
|
|
9
9
|
* @param nxJson
|
10
10
|
*/
|
11
11
|
export declare function retrieveWorkspaceFiles(workspaceRoot: string, projectRootMap: Record<string, string>): Promise<{
|
12
|
-
allWorkspaceFiles: import("
|
12
|
+
allWorkspaceFiles: import("../file-utils").FileData[];
|
13
13
|
fileMap: {
|
14
14
|
projectFileMap: ProjectFiles;
|
15
|
-
nonProjectFiles: import("
|
15
|
+
nonProjectFiles: import("../../native").FileData[];
|
16
16
|
};
|
17
|
-
rustReferences: import("
|
17
|
+
rustReferences: import("../../native").NxWorkspaceFilesExternals;
|
18
18
|
}>;
|
19
19
|
/**
|
20
20
|
* Walk through the workspace and return `ProjectConfigurations`. Only use this if the projectFileMap is not needed.
|
package/src/utils/ab-testing.js
CHANGED
@@ -90,6 +90,11 @@ async function recordStat(opts) {
|
|
90
90
|
exports.recordStat = recordStat;
|
91
91
|
function shouldRecordStats() {
|
92
92
|
const pmc = (0, package_manager_1.getPackageManagerCommand)();
|
93
|
+
if (!pmc.getRegistryUrl) {
|
94
|
+
// Fallback on true as Package management doesn't support reading config for registry.
|
95
|
+
// currently Bun doesn't support fetching config settings https://github.com/oven-sh/bun/issues/7140
|
96
|
+
return true;
|
97
|
+
}
|
93
98
|
try {
|
94
99
|
const stdout = (0, node_child_process_1.execSync)(pmc.getRegistryUrl, { encoding: 'utf-8' });
|
95
100
|
const url = new URL(stdout.trim());
|
@@ -1,4 +1,4 @@
|
|
1
|
-
export type PackageManager = 'yarn' | 'pnpm' | 'npm';
|
1
|
+
export type PackageManager = 'yarn' | 'pnpm' | 'npm' | 'bun';
|
2
2
|
export interface PackageManagerCommands {
|
3
3
|
preInstall?: string;
|
4
4
|
install: string;
|
@@ -11,7 +11,7 @@ export interface PackageManagerCommands {
|
|
11
11
|
dlx: string;
|
12
12
|
list: string;
|
13
13
|
run: (script: string, args?: string) => string;
|
14
|
-
getRegistryUrl
|
14
|
+
getRegistryUrl?: string;
|
15
15
|
}
|
16
16
|
/**
|
17
17
|
* Detects which package manager is used in the workspace based on the lock file.
|
@@ -20,11 +20,13 @@ const execAsync = (0, util_1.promisify)(child_process_1.exec);
|
|
20
20
|
function detectPackageManager(dir = '') {
|
21
21
|
const nxJson = (0, configuration_1.readNxJson)();
|
22
22
|
return (nxJson.cli?.packageManager ??
|
23
|
-
((0, fs_1.existsSync)((0, path_1.join)(dir, '
|
24
|
-
? '
|
25
|
-
: (0, fs_1.existsSync)((0, path_1.join)(dir, '
|
26
|
-
? '
|
27
|
-
: '
|
23
|
+
((0, fs_1.existsSync)((0, path_1.join)(dir, 'bun.lockb'))
|
24
|
+
? 'bun'
|
25
|
+
: (0, fs_1.existsSync)((0, path_1.join)(dir, 'yarn.lock'))
|
26
|
+
? 'yarn'
|
27
|
+
: (0, fs_1.existsSync)((0, path_1.join)(dir, 'pnpm-lock.yaml'))
|
28
|
+
? 'pnpm'
|
29
|
+
: 'npm'));
|
28
30
|
}
|
29
31
|
exports.detectPackageManager = detectPackageManager;
|
30
32
|
/**
|
@@ -121,6 +123,21 @@ function getPackageManagerCommand(packageManager = detectPackageManager(), root
|
|
121
123
|
getRegistryUrl: 'npm config get registry',
|
122
124
|
};
|
123
125
|
},
|
126
|
+
bun: () => {
|
127
|
+
// bun doesn't current support programatically reading config https://github.com/oven-sh/bun/issues/7140
|
128
|
+
return {
|
129
|
+
install: 'bun install',
|
130
|
+
ciInstall: 'bun install --no-cache',
|
131
|
+
updateLockFile: 'bun install --frozen-lockfile',
|
132
|
+
add: 'bun install',
|
133
|
+
addDev: 'bun install -D',
|
134
|
+
rm: 'bun rm',
|
135
|
+
exec: 'bun',
|
136
|
+
dlx: 'bunx',
|
137
|
+
run: (script, args) => `bun run ${script} -- ${args}`,
|
138
|
+
list: 'bun pm ls',
|
139
|
+
};
|
140
|
+
},
|
124
141
|
};
|
125
142
|
return commands[packageManager]();
|
126
143
|
}
|
@@ -195,7 +212,12 @@ function modifyYarnRcToFitNewDirectory(contents) {
|
|
195
212
|
}
|
196
213
|
exports.modifyYarnRcToFitNewDirectory = modifyYarnRcToFitNewDirectory;
|
197
214
|
function copyPackageManagerConfigurationFiles(root, destination) {
|
198
|
-
for (const packageManagerConfigFile of [
|
215
|
+
for (const packageManagerConfigFile of [
|
216
|
+
'.npmrc',
|
217
|
+
'.yarnrc',
|
218
|
+
'.yarnrc.yml',
|
219
|
+
'bunfig.toml',
|
220
|
+
]) {
|
199
221
|
// f is an absolute path, including the {workspaceRoot}.
|
200
222
|
const f = findFileInPackageJsonDirectory(packageManagerConfigFile, root);
|
201
223
|
if (f) {
|
@@ -218,6 +240,10 @@ function copyPackageManagerConfigurationFiles(root, destination) {
|
|
218
240
|
(0, fs_1.writeFileSync)(destinationPath, updated);
|
219
241
|
break;
|
220
242
|
}
|
243
|
+
case 'bunfig.toml': {
|
244
|
+
(0, fs_1.copyFileSync)(f, destinationPath);
|
245
|
+
break;
|
246
|
+
}
|
221
247
|
}
|
222
248
|
}
|
223
249
|
}
|
@@ -299,12 +325,16 @@ async function resolvePackageVersionUsingInstallation(packageName, version) {
|
|
299
325
|
exports.resolvePackageVersionUsingInstallation = resolvePackageVersionUsingInstallation;
|
300
326
|
async function packageRegistryView(pkg, version, args) {
|
301
327
|
let pm = detectPackageManager();
|
302
|
-
if (pm === 'yarn') {
|
328
|
+
if (pm === 'yarn' || pm === 'bun') {
|
303
329
|
/**
|
304
330
|
* yarn has `yarn info` but it behaves differently than (p)npm,
|
305
331
|
* which makes it's usage unreliable
|
306
332
|
*
|
307
333
|
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
|
334
|
+
*
|
335
|
+
* Bun has a pm ls function but it only relates to its lockfile
|
336
|
+
* and acts differently from all other package managers
|
337
|
+
* from Jarred: "it probably would be bun pm view <package-name>"
|
308
338
|
*/
|
309
339
|
pm = 'npm';
|
310
340
|
}
|
@@ -314,13 +344,15 @@ async function packageRegistryView(pkg, version, args) {
|
|
314
344
|
exports.packageRegistryView = packageRegistryView;
|
315
345
|
async function packageRegistryPack(cwd, pkg, version) {
|
316
346
|
let pm = detectPackageManager();
|
317
|
-
if (pm === 'yarn') {
|
347
|
+
if (pm === 'yarn' || pm === 'bun') {
|
318
348
|
/**
|
319
349
|
* `(p)npm pack` will download a tarball of the specified version,
|
320
350
|
* whereas `yarn` pack creates a tarball of the active workspace, so it
|
321
351
|
* does not work for getting the content of a library.
|
322
352
|
*
|
323
353
|
* @see https://github.com/nrwl/nx/pull/9667#discussion_r842553994
|
354
|
+
*
|
355
|
+
* bun doesn't currently support pack
|
324
356
|
*/
|
325
357
|
pm = 'npm';
|
326
358
|
}
|