create-nx-workspace 22.2.0 → 22.2.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/bin/create-nx-workspace.d.ts.map +1 -1
- package/bin/create-nx-workspace.js +79 -73
- package/package.json +1 -1
- package/src/create-empty-workspace.d.ts.map +1 -1
- package/src/create-empty-workspace.js +2 -11
- package/src/create-preset.d.ts.map +1 -1
- package/src/create-preset.js +2 -6
- package/src/create-sandbox.d.ts.map +1 -1
- package/src/create-sandbox.js +2 -11
- package/src/create-workspace.d.ts.map +1 -1
- package/src/create-workspace.js +15 -2
- package/src/internal-utils/prompts.d.ts.map +1 -1
- package/src/internal-utils/prompts.js +5 -15
- package/src/utils/ci/setup-ci.d.ts.map +1 -1
- package/src/utils/ci/setup-ci.js +2 -11
- package/src/utils/error-utils.d.ts +18 -0
- package/src/utils/error-utils.d.ts.map +1 -1
- package/src/utils/error-utils.js +21 -2
- package/src/utils/nx/ab-testing.d.ts +19 -2
- package/src/utils/nx/ab-testing.d.ts.map +1 -1
- package/src/utils/nx/ab-testing.js +1 -7
- package/src/utils/package-manager.d.ts +8 -0
- package/src/utils/package-manager.d.ts.map +1 -1
- package/src/utils/package-manager.js +70 -0
- package/src/utils/template/clone-template.d.ts.map +1 -1
- package/src/utils/template/clone-template.js +3 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-nx-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/bin/create-nx-workspace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,EACL,sBAAsB,EAEvB,MAAM,iCAAiC,CAAC;AAKzC,OAAO,EAAiB,MAAM,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"create-nx-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/bin/create-nx-workspace.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,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,12 +12,27 @@ const output_1 = require("../src/utils/output");
|
|
|
12
12
|
const nx_version_1 = require("../src/utils/nx/nx-version");
|
|
13
13
|
const decorator_1 = require("./decorator");
|
|
14
14
|
const get_third_party_preset_1 = require("../src/utils/preset/get-third-party-preset");
|
|
15
|
+
const package_manager_1 = require("../src/utils/package-manager");
|
|
15
16
|
const prompts_1 = require("../src/internal-utils/prompts");
|
|
16
17
|
const yargs_options_1 = require("../src/internal-utils/yargs-options");
|
|
17
18
|
const ab_testing_1 = require("../src/utils/nx/ab-testing");
|
|
18
19
|
const error_utils_1 = require("../src/utils/error-utils");
|
|
19
20
|
const fs_1 = require("fs");
|
|
20
21
|
const is_ci_1 = require("../src/utils/ci/is-ci");
|
|
22
|
+
function extractErrorFile(error) {
|
|
23
|
+
if (!error.stack)
|
|
24
|
+
return undefined;
|
|
25
|
+
const lines = error.stack.split('\n');
|
|
26
|
+
// Find the first line with a file path (typically line 1 after the error message)
|
|
27
|
+
const fileLine = lines.find((line) => line.includes('at ') && line.includes('/'));
|
|
28
|
+
if (!fileLine)
|
|
29
|
+
return undefined;
|
|
30
|
+
// Extract just the file path portion
|
|
31
|
+
const match = fileLine.match(/\(([^)]+)\)/) || fileLine.match(/at\s+(.+)/);
|
|
32
|
+
return match?.[1]?.trim();
|
|
33
|
+
}
|
|
34
|
+
// For template-based CNW we want to know if user picked empty vs react vs angular etc.
|
|
35
|
+
let chosenTemplate;
|
|
21
36
|
exports.commandsObject = yargs
|
|
22
37
|
.wrap(yargs.terminalWidth())
|
|
23
38
|
.parserConfiguration({
|
|
@@ -127,12 +142,35 @@ exports.commandsObject = yargs
|
|
|
127
142
|
type: 'array',
|
|
128
143
|
choices: [...create_workspace_options_1.supportedAgents],
|
|
129
144
|
}), yargs_options_1.withNxCloud, yargs_options_1.withUseGitHub, yargs_options_1.withAllPrompts, yargs_options_1.withPackageManager, yargs_options_1.withGitOptions), async function handler(argv) {
|
|
130
|
-
await main(argv).catch((error) => {
|
|
145
|
+
await main(argv).catch(async (error) => {
|
|
131
146
|
const { version } = require('../package.json');
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
147
|
+
// Record error stat for telemetry
|
|
148
|
+
const errorCode = error instanceof error_utils_1.CnwError ? error.code : 'UNKNOWN';
|
|
149
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
150
|
+
const errorFile = error instanceof Error ? extractErrorFile(error) : undefined;
|
|
151
|
+
await (0, ab_testing_1.recordStat)({
|
|
152
|
+
nxVersion: nx_version_1.nxVersion,
|
|
153
|
+
command: 'create-nx-workspace',
|
|
154
|
+
useCloud: argv.nxCloud !== 'skip',
|
|
155
|
+
meta: {
|
|
156
|
+
type: 'error',
|
|
157
|
+
errorCode,
|
|
158
|
+
errorMessage: errorCode === 'UNKNOWN' ? errorMessage : undefined,
|
|
159
|
+
errorFile: errorCode === 'UNKNOWN' ? errorFile : undefined,
|
|
160
|
+
},
|
|
135
161
|
});
|
|
162
|
+
if (error instanceof error_utils_1.CnwError) {
|
|
163
|
+
output_1.output.error({
|
|
164
|
+
title: `Failed to create workspace`,
|
|
165
|
+
bodyLines: error.message.split('\n').filter((line) => line.trim()),
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
output_1.output.error({
|
|
170
|
+
title: `Failed to create workspace (v${version})`,
|
|
171
|
+
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(error),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
136
174
|
process.exit(1);
|
|
137
175
|
});
|
|
138
176
|
}, [normalizeArgsMiddleware])
|
|
@@ -179,18 +217,17 @@ async function main(parsedArgs) {
|
|
|
179
217
|
nxVersion: nx_version_1.nxVersion,
|
|
180
218
|
command: 'create-nx-workspace',
|
|
181
219
|
useCloud: parsedArgs.nxCloud !== 'skip',
|
|
182
|
-
meta:
|
|
183
|
-
|
|
184
|
-
ab_testing_1.
|
|
185
|
-
|
|
186
|
-
ab_testing_1.messages.codeOfSelectedPromptMessage('setupNxCloudV2') ||
|
|
220
|
+
meta: {
|
|
221
|
+
type: 'complete',
|
|
222
|
+
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
223
|
+
setupCIPrompt: ab_testing_1.messages.codeOfSelectedPromptMessage('setupCI'),
|
|
224
|
+
setupCloudPrompt: ab_testing_1.messages.codeOfSelectedPromptMessage('setupNxCloudV2') ||
|
|
187
225
|
ab_testing_1.messages.codeOfSelectedPromptMessage('setupNxCloud'),
|
|
188
|
-
parsedArgs.nxCloud,
|
|
189
|
-
rawArgs.nxCloud,
|
|
190
|
-
workspaceInfo.pushedToVcs,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
directory: workspaceInfo.directory,
|
|
226
|
+
nxCloudArg: parsedArgs.nxCloud ?? '',
|
|
227
|
+
nxCloudArgRaw: rawArgs.nxCloud ?? '',
|
|
228
|
+
pushedToVcs: workspaceInfo.pushedToVcs ?? '',
|
|
229
|
+
template: chosenTemplate ?? '',
|
|
230
|
+
},
|
|
194
231
|
});
|
|
195
232
|
if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
|
|
196
233
|
process.stdout.write(workspaceInfo.nxCloudInfo);
|
|
@@ -216,22 +253,21 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
216
253
|
});
|
|
217
254
|
argv.workspaces ??= true;
|
|
218
255
|
argv.useProjectJson ??= !argv.workspaces;
|
|
256
|
+
await (0, ab_testing_1.recordStat)({
|
|
257
|
+
nxVersion: nx_version_1.nxVersion,
|
|
258
|
+
command: 'create-nx-workspace',
|
|
259
|
+
useCloud: argv.nxCloud !== 'skip',
|
|
260
|
+
meta: {
|
|
261
|
+
type: 'start',
|
|
262
|
+
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
263
|
+
},
|
|
264
|
+
});
|
|
219
265
|
try {
|
|
220
266
|
argv.name = await determineFolder(argv);
|
|
221
|
-
const workingDir = process.cwd().replace(/\\/g, '/');
|
|
222
|
-
const directory = require('path').join(workingDir, argv.name);
|
|
223
267
|
const template = await (0, prompts_1.determineTemplate)(argv);
|
|
224
|
-
|
|
225
|
-
const startPrefix = (0, ab_testing_1.getFlowVariant)() === '1' ? 'start-v2' : 'start';
|
|
226
|
-
await (0, ab_testing_1.recordStat)({
|
|
227
|
-
nxVersion: nx_version_1.nxVersion,
|
|
228
|
-
command: 'create-nx-workspace',
|
|
229
|
-
meta: [startPrefix],
|
|
230
|
-
useCloud: argv.nxCloud !== 'skip',
|
|
231
|
-
directory,
|
|
232
|
-
});
|
|
268
|
+
chosenTemplate = template;
|
|
233
269
|
if (template !== 'custom') {
|
|
234
|
-
// Template flow - uses
|
|
270
|
+
// Template flow - uses detected package manager (from invoking command) and 'main' branch by default
|
|
235
271
|
argv.template = template;
|
|
236
272
|
const aiAgents = await (0, prompts_1.determineAiAgents)(argv);
|
|
237
273
|
const nxCloud = argv.skipGit === true ? 'skip' : await (0, prompts_1.determineNxCloudV2)(argv);
|
|
@@ -242,7 +278,7 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
242
278
|
nxCloud,
|
|
243
279
|
useGitHub: nxCloud !== 'skip',
|
|
244
280
|
completionMessageKey,
|
|
245
|
-
packageManager:
|
|
281
|
+
packageManager: (0, package_manager_1.detectInvokedPackageManager)(),
|
|
246
282
|
defaultBase: 'main',
|
|
247
283
|
aiAgents,
|
|
248
284
|
});
|
|
@@ -259,16 +295,8 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
259
295
|
(0, get_third_party_preset_1.getPackageNameFromThirdPartyPreset)(argv.preset);
|
|
260
296
|
}
|
|
261
297
|
catch (e) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
title: `Could not find preset "${argv.preset}"`,
|
|
265
|
-
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
266
|
-
});
|
|
267
|
-
}
|
|
268
|
-
else {
|
|
269
|
-
console.error(e);
|
|
270
|
-
}
|
|
271
|
-
process.exit(1);
|
|
298
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
299
|
+
throw new error_utils_1.CnwError('INVALID_PRESET', `Could not find preset "${argv.preset}": ${message}`);
|
|
272
300
|
}
|
|
273
301
|
}
|
|
274
302
|
const packageManager = await (0, prompts_1.determinePackageManager)(argv);
|
|
@@ -288,14 +316,16 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
288
316
|
}
|
|
289
317
|
}
|
|
290
318
|
catch (e) {
|
|
291
|
-
|
|
292
|
-
|
|
319
|
+
if (e instanceof error_utils_1.CnwError) {
|
|
320
|
+
throw e;
|
|
321
|
+
}
|
|
322
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
323
|
+
throw new error_utils_1.CnwError('UNKNOWN', message);
|
|
293
324
|
}
|
|
294
325
|
}
|
|
295
|
-
function invariant(predicate, message) {
|
|
326
|
+
function invariant(predicate, errorCode, message) {
|
|
296
327
|
if (!predicate) {
|
|
297
|
-
|
|
298
|
-
process.exit(1);
|
|
328
|
+
throw new error_utils_1.CnwError(errorCode, message);
|
|
299
329
|
}
|
|
300
330
|
}
|
|
301
331
|
function validateWorkspaceName(name) {
|
|
@@ -329,14 +359,9 @@ async function determineFolder(parsedArgs) {
|
|
|
329
359
|
skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
|
|
330
360
|
},
|
|
331
361
|
]);
|
|
332
|
-
invariant(reply.folderName,
|
|
333
|
-
title: 'Invalid folder name',
|
|
334
|
-
bodyLines: [`Folder name cannot be empty`],
|
|
335
|
-
});
|
|
362
|
+
invariant(reply.folderName, 'INVALID_FOLDER_NAME', 'Folder name cannot be empty');
|
|
336
363
|
validateWorkspaceName(reply.folderName);
|
|
337
|
-
invariant(!(0, fs_1.existsSync)(reply.folderName), {
|
|
338
|
-
title: 'That folder is already taken',
|
|
339
|
-
});
|
|
364
|
+
invariant(!(0, fs_1.existsSync)(reply.folderName), 'DIRECTORY_EXISTS', `The folder '${reply.folderName}' already exists`);
|
|
340
365
|
return reply.folderName;
|
|
341
366
|
}
|
|
342
367
|
async function determineStack(parsedArgs) {
|
|
@@ -800,13 +825,7 @@ async function determineAngularOptions(parsedArgs) {
|
|
|
800
825
|
const htmlSelectorRegex = /^[a-zA-Z][.0-9a-zA-Z]*((:?-[0-9]+)*|(:?-[a-zA-Z][.0-9a-zA-Z]*(:?-[0-9]+)*)*)$/;
|
|
801
826
|
// validate whether component/directive selectors will be valid with the provided prefix
|
|
802
827
|
if (!htmlSelectorRegex.test(`${prefix}-placeholder`)) {
|
|
803
|
-
|
|
804
|
-
title: `Failed to create a workspace.`,
|
|
805
|
-
bodyLines: [
|
|
806
|
-
`The provided "${prefix}" prefix is invalid. It must be a valid HTML selector.`,
|
|
807
|
-
],
|
|
808
|
-
});
|
|
809
|
-
process.exit(1);
|
|
828
|
+
throw new error_utils_1.CnwError('ANGULAR_PREFIX_INVALID', `The provided "${prefix}" prefix is invalid. It must be a valid HTML selector.`);
|
|
810
829
|
}
|
|
811
830
|
}
|
|
812
831
|
if (parsedArgs.preset && parsedArgs.preset !== preset_1.Preset.Angular) {
|
|
@@ -1031,12 +1050,7 @@ async function determinePackageBasedOrIntegratedOrStandalone() {
|
|
|
1031
1050
|
],
|
|
1032
1051
|
},
|
|
1033
1052
|
]);
|
|
1034
|
-
invariant(workspaceType, {
|
|
1035
|
-
title: 'Invalid workspace type',
|
|
1036
|
-
bodyLines: [
|
|
1037
|
-
`It must be one of the following: standalone, integrated. Got ${workspaceType}`,
|
|
1038
|
-
],
|
|
1039
|
-
});
|
|
1053
|
+
invariant(workspaceType, 'INVALID_WORKSPACE_TYPE', `Invalid workspace type. It must be one of the following: standalone, integrated. Got ${workspaceType}`);
|
|
1040
1054
|
return workspaceType;
|
|
1041
1055
|
}
|
|
1042
1056
|
async function determineStandaloneOrMonorepo() {
|
|
@@ -1058,12 +1072,7 @@ async function determineStandaloneOrMonorepo() {
|
|
|
1058
1072
|
],
|
|
1059
1073
|
},
|
|
1060
1074
|
]);
|
|
1061
|
-
invariant(workspaceType, {
|
|
1062
|
-
title: 'Invalid workspace type',
|
|
1063
|
-
bodyLines: [
|
|
1064
|
-
`It must be one of the following: standalone, integrated. Got ${workspaceType}`,
|
|
1065
|
-
],
|
|
1066
|
-
});
|
|
1075
|
+
invariant(workspaceType, 'INVALID_WORKSPACE_TYPE', `Invalid workspace type. It must be one of the following: standalone, integrated. Got ${workspaceType}`);
|
|
1067
1076
|
return workspaceType;
|
|
1068
1077
|
}
|
|
1069
1078
|
async function determineAppName(parsedArgs) {
|
|
@@ -1078,10 +1087,7 @@ async function determineAppName(parsedArgs) {
|
|
|
1078
1087
|
skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
|
|
1079
1088
|
},
|
|
1080
1089
|
]);
|
|
1081
|
-
invariant(appName,
|
|
1082
|
-
title: 'Invalid name',
|
|
1083
|
-
bodyLines: [`Name cannot be empty`],
|
|
1084
|
-
});
|
|
1090
|
+
invariant(appName, 'INVALID_APP_NAME', 'App name cannot be empty');
|
|
1085
1091
|
return appName;
|
|
1086
1092
|
}
|
|
1087
1093
|
async function determineReactFramework(parsedArgs) {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-empty-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-empty-workspace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"create-empty-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-empty-workspace.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAGL,cAAc,EACf,MAAM,yBAAyB,CAAC;AAGjC;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CAAC,CAAC,SAAS,sBAAsB,EACzE,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc,EAC9B,OAAO,EAAE,CAAC,GACT,OAAO,CAAC,MAAM,CAAC,CA6DjB"}
|
|
@@ -5,7 +5,6 @@ const ora = require("ora");
|
|
|
5
5
|
const path_1 = require("path");
|
|
6
6
|
const child_process_utils_1 = require("./utils/child-process-utils");
|
|
7
7
|
const error_utils_1 = require("./utils/error-utils");
|
|
8
|
-
const output_1 = require("./utils/output");
|
|
9
8
|
const package_manager_1 = require("./utils/package-manager");
|
|
10
9
|
const unparse_1 = require("./utils/unparse");
|
|
11
10
|
/**
|
|
@@ -52,16 +51,8 @@ async function createEmptyWorkspace(tmpDir, name, packageManager, options) {
|
|
|
52
51
|
}
|
|
53
52
|
catch (e) {
|
|
54
53
|
workspaceSetupSpinner.fail();
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
title: `Failed to create a workspace.`,
|
|
58
|
-
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
59
|
-
});
|
|
60
|
-
}
|
|
61
|
-
else {
|
|
62
|
-
console.error(e);
|
|
63
|
-
}
|
|
64
|
-
process.exit(1);
|
|
54
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
55
|
+
throw new error_utils_1.CnwError('WORKSPACE_CREATION_FAILED', `Failed to create a workspace: ${message}`);
|
|
65
56
|
}
|
|
66
57
|
finally {
|
|
67
58
|
workspaceSetupSpinner.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-preset.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAGL,cAAc,EACf,MAAM,yBAAyB,CAAC;AAIjC,wBAAsB,YAAY,CAAC,CAAC,SAAS,sBAAsB,EACjE,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,CAAC,EACb,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"create-preset.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-preset.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAGL,cAAc,EACf,MAAM,yBAAyB,CAAC;AAIjC,wBAAsB,YAAY,CAAC,CAAC,SAAS,sBAAsB,EACjE,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,CAAC,EACb,cAAc,EAAE,cAAc,EAC9B,SAAS,EAAE,MAAM,GAChB,OAAO,CAAC,IAAI,CAAC,CAoDf"}
|
package/src/create-preset.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createPreset = createPreset;
|
|
4
|
-
const
|
|
4
|
+
const error_utils_1 = require("./utils/error-utils");
|
|
5
5
|
const package_manager_1 = require("./utils/package-manager");
|
|
6
6
|
const child_process_utils_1 = require("./utils/child-process-utils");
|
|
7
7
|
const unparse_1 = require("./utils/unparse");
|
|
@@ -38,10 +38,6 @@ async function createPreset(preset, parsedArgs, packageManager, directory) {
|
|
|
38
38
|
await (0, child_process_utils_1.spawnAndWait)(exec, args, directory);
|
|
39
39
|
}
|
|
40
40
|
catch (e) {
|
|
41
|
-
|
|
42
|
-
title: `Failed to apply preset: ${preset}`,
|
|
43
|
-
bodyLines: ['See above'],
|
|
44
|
-
});
|
|
45
|
-
process.exit(1);
|
|
41
|
+
throw new error_utils_1.CnwError('PRESET_FAILED', `Failed to apply preset: ${preset}`);
|
|
46
42
|
}
|
|
47
43
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-sandbox.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-sandbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,cAAc,EACf,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"create-sandbox.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-sandbox.ts"],"names":[],"mappings":"AAKA,OAAO,EAGL,cAAc,EACf,MAAM,yBAAyB,CAAC;AAKjC;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,cAAc,EAAE,cAAc,mBAwCjE"}
|
package/src/create-sandbox.js
CHANGED
|
@@ -7,7 +7,6 @@ const ora = require("ora");
|
|
|
7
7
|
const path_1 = require("path");
|
|
8
8
|
const package_manager_1 = require("./utils/package-manager");
|
|
9
9
|
const child_process_utils_1 = require("./utils/child-process-utils");
|
|
10
|
-
const output_1 = require("./utils/output");
|
|
11
10
|
const nx_version_1 = require("./utils/nx/nx-version");
|
|
12
11
|
const error_utils_1 = require("./utils/error-utils");
|
|
13
12
|
/**
|
|
@@ -36,16 +35,8 @@ async function createSandbox(packageManager) {
|
|
|
36
35
|
}
|
|
37
36
|
catch (e) {
|
|
38
37
|
installSpinner.fail();
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
title: `Failed to install dependencies`,
|
|
42
|
-
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
console.error(e);
|
|
47
|
-
}
|
|
48
|
-
process.exit(1);
|
|
38
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
39
|
+
throw new error_utils_1.CnwError('SANDBOX_FAILED', `Failed to install dependencies: ${message}`);
|
|
49
40
|
}
|
|
50
41
|
finally {
|
|
51
42
|
installSpinner.stop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-workspace.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"create-workspace.d.ts","sourceRoot":"","sources":["../../../../packages/create-nx-workspace/src/create-workspace.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAGpE,OAAO,EAGL,aAAa,EACd,MAAM,iBAAiB,CAAC;AAsBzB,wBAAgB,4BAA4B,IAAI;IAC9C,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;CAChC,CAEA;AAED,wBAAsB,eAAe,CAAC,CAAC,SAAS,sBAAsB,EACpE,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,CAAC,EACV,OAAO,CAAC,EAAE,CAAC;;;;GA6KZ;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7D"}
|
package/src/create-workspace.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getInterruptedWorkspaceState = getInterruptedWorkspaceState;
|
|
4
4
|
exports.createWorkspace = createWorkspace;
|
|
5
5
|
exports.extractConnectUrl = extractConnectUrl;
|
|
6
|
+
const node_fs_1 = require("node:fs");
|
|
6
7
|
const path_1 = require("path");
|
|
7
8
|
const create_empty_workspace_1 = require("./create-empty-workspace");
|
|
8
9
|
const create_preset_1 = require("./create-preset");
|
|
@@ -16,6 +17,7 @@ const get_third_party_preset_1 = require("./utils/preset/get-third-party-preset"
|
|
|
16
17
|
const preset_1 = require("./utils/preset/preset");
|
|
17
18
|
const clone_template_1 = require("./utils/template/clone-template");
|
|
18
19
|
const child_process_utils_1 = require("./utils/child-process-utils");
|
|
20
|
+
const package_manager_1 = require("./utils/package-manager");
|
|
19
21
|
// State for SIGINT handler - only set after workspace is fully installed
|
|
20
22
|
let workspaceDirectory;
|
|
21
23
|
let cloudConnectUrl;
|
|
@@ -38,8 +40,19 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
38
40
|
const workspaceSetupSpinner = ora(`Creating workspace from template`).start();
|
|
39
41
|
try {
|
|
40
42
|
await (0, clone_template_1.cloneTemplate)(templateUrl, name);
|
|
41
|
-
//
|
|
42
|
-
|
|
43
|
+
// Remove npm lockfile from template since we'll generate the correct one
|
|
44
|
+
const npmLockPath = (0, path_1.join)(directory, 'package-lock.json');
|
|
45
|
+
if ((0, node_fs_1.existsSync)(npmLockPath)) {
|
|
46
|
+
(0, node_fs_1.unlinkSync)(npmLockPath);
|
|
47
|
+
}
|
|
48
|
+
// Generate package manager specific files (e.g., .yarnrc.yml for Yarn Berry)
|
|
49
|
+
(0, package_manager_1.generatePackageManagerFiles)(directory, packageManager);
|
|
50
|
+
// Install dependencies with the user's package manager
|
|
51
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
|
|
52
|
+
if (pmc.preInstall) {
|
|
53
|
+
await (0, child_process_utils_1.execAndWait)(pmc.preInstall, directory);
|
|
54
|
+
}
|
|
55
|
+
await (0, child_process_utils_1.execAndWait)(pmc.install, directory);
|
|
43
56
|
// Mark workspace as ready for SIGINT handler
|
|
44
57
|
workspaceDirectory = directory;
|
|
45
58
|
workspaceSetupSpinner.succeed(`Successfully created the workspace: ${directory}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/internal-utils/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"prompts.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/internal-utils/prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAU/B,OAAO,EAEL,cAAc,EAEf,MAAM,0BAA0B,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EACL,KAAK,EAGN,MAAM,6BAA6B,CAAC;AAGrC,wBAAsB,gBAAgB,CACpC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,GAChD,OAAO,CAAC,OAAO,CAAC,CAQlB;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GACvE,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,CAiC5B;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,SAAS,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GACrE,OAAO,CAAC,OAAO,CAAC,CAelB;AA4BD,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC,GACD,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,CA2C5B;AAED,wBAAsB,iBAAiB,CACrC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,QAAQ,CAAC,EAAE,KAAK,EAAE,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC,GACzE,OAAO,CAAC,KAAK,EAAE,CAAC,CAElB;AAqBD,wBAAsB,oBAAoB,CACxC,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,WAAW,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,GACpD,OAAO,CAAC,MAAM,CAAC,CAwBjB;AAED,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC;IAAE,cAAc,EAAE,MAAM,CAAA;CAAE,CAAC,GACtD,OAAO,CAAC,cAAc,CAAC,CAiCzB"}
|
|
@@ -10,12 +10,12 @@ exports.determinePackageManager = determinePackageManager;
|
|
|
10
10
|
const enquirer = require("enquirer");
|
|
11
11
|
const chalk = require("chalk");
|
|
12
12
|
const ab_testing_1 = require("../utils/nx/ab-testing");
|
|
13
|
-
const output_1 = require("../utils/output");
|
|
14
13
|
const default_base_1 = require("../utils/git/default-base");
|
|
15
14
|
const package_manager_1 = require("../utils/package-manager");
|
|
16
15
|
const string_utils_1 = require("../utils/string-utils");
|
|
17
16
|
const is_ci_1 = require("../utils/ci/is-ci");
|
|
18
17
|
const create_workspace_options_1 = require("../create-workspace-options");
|
|
18
|
+
const error_utils_1 = require("../utils/error-utils");
|
|
19
19
|
async function determineNxCloud(parsedArgs) {
|
|
20
20
|
if (parsedArgs.nxCloud) {
|
|
21
21
|
return parsedArgs.nxCloud;
|
|
@@ -169,11 +169,7 @@ async function determineDefaultBase(parsedArgs) {
|
|
|
169
169
|
])
|
|
170
170
|
.then((a) => {
|
|
171
171
|
if (!a.DefaultBase) {
|
|
172
|
-
|
|
173
|
-
title: 'Invalid branch name',
|
|
174
|
-
bodyLines: [`Branch name cannot be empty`],
|
|
175
|
-
});
|
|
176
|
-
process.exit(1);
|
|
172
|
+
throw new error_utils_1.CnwError('INVALID_BRANCH_NAME', 'Branch name cannot be empty');
|
|
177
173
|
}
|
|
178
174
|
return a.DefaultBase;
|
|
179
175
|
});
|
|
@@ -186,15 +182,9 @@ async function determinePackageManager(parsedArgs) {
|
|
|
186
182
|
if (package_manager_1.packageManagerList.includes(packageManager)) {
|
|
187
183
|
return packageManager;
|
|
188
184
|
}
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
`Package manager must be one of ${(0, string_utils_1.stringifyCollection)([
|
|
193
|
-
...package_manager_1.packageManagerList,
|
|
194
|
-
])}`,
|
|
195
|
-
],
|
|
196
|
-
});
|
|
197
|
-
process.exit(1);
|
|
185
|
+
throw new error_utils_1.CnwError('INVALID_PACKAGE_MANAGER', `Package manager must be one of ${(0, string_utils_1.stringifyCollection)([
|
|
186
|
+
...package_manager_1.packageManagerList,
|
|
187
|
+
])}`);
|
|
198
188
|
}
|
|
199
189
|
else if (parsedArgs.allPrompts) {
|
|
200
190
|
return enquirer
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"setup-ci.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/ci/setup-ci.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"setup-ci.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/ci/setup-ci.ts"],"names":[],"mappings":"AAIA,OAAO,EAA4B,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAE9E,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,EAAE,EAAE,MAAM,EACV,cAAc,EAAE,cAAc;;;GAqB/B"}
|
package/src/utils/ci/setup-ci.js
CHANGED
|
@@ -4,7 +4,6 @@ exports.setupCI = setupCI;
|
|
|
4
4
|
const ora = require("ora");
|
|
5
5
|
const child_process_utils_1 = require("../child-process-utils");
|
|
6
6
|
const error_utils_1 = require("../error-utils");
|
|
7
|
-
const output_1 = require("../output");
|
|
8
7
|
const package_manager_1 = require("../package-manager");
|
|
9
8
|
async function setupCI(directory, ci, packageManager) {
|
|
10
9
|
const ciSpinner = ora(`Generating CI workflow`).start();
|
|
@@ -16,16 +15,8 @@ async function setupCI(directory, ci, packageManager) {
|
|
|
16
15
|
}
|
|
17
16
|
catch (e) {
|
|
18
17
|
ciSpinner.fail();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
title: `Failed to generate CI workflow`,
|
|
22
|
-
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.error(e);
|
|
27
|
-
}
|
|
28
|
-
process.exit(1);
|
|
18
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
19
|
+
throw new error_utils_1.CnwError('CI_WORKFLOW_FAILED', `Failed to generate CI workflow: ${message}`);
|
|
29
20
|
}
|
|
30
21
|
finally {
|
|
31
22
|
ciSpinner.stop();
|
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Error codes for CNW errors.
|
|
3
|
+
* These are used for telemetry and error tracking.
|
|
4
|
+
*/
|
|
5
|
+
export type CnwErrorCode = 'DIRECTORY_EXISTS' | 'INVALID_WORKSPACE_NAME' | 'INVALID_FOLDER_NAME' | 'INVALID_BRANCH_NAME' | 'INVALID_PACKAGE_MANAGER' | 'INVALID_PRESET' | 'INVALID_WORKSPACE_TYPE' | 'INVALID_APP_NAME' | 'PRESET_FAILED' | 'SANDBOX_FAILED' | 'TEMPLATE_CLONE_FAILED' | 'CI_WORKFLOW_FAILED' | 'WORKSPACE_CREATION_FAILED' | 'ANGULAR_PREFIX_INVALID' | 'UNKNOWN';
|
|
6
|
+
/**
|
|
7
|
+
* Custom error class for CNW errors.
|
|
8
|
+
* Used for structured error reporting and telemetry.
|
|
9
|
+
*/
|
|
10
|
+
export declare class CnwError extends Error {
|
|
11
|
+
readonly code: CnwErrorCode;
|
|
12
|
+
readonly logFile?: string;
|
|
13
|
+
readonly exitCode?: number;
|
|
14
|
+
constructor(code: CnwErrorCode, message: string, logFile?: string, exitCode?: number);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated Use CnwError instead
|
|
18
|
+
*/
|
|
1
19
|
export declare class CreateNxWorkspaceError extends Error {
|
|
2
20
|
logMessage: string;
|
|
3
21
|
code: number | null | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/utils/error-utils.ts"],"names":[],"mappings":"AAAA,qBAAa,sBAAuB,SAAQ,KAAK;IAEtC,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAC/B,OAAO,EAAE,MAAM;gBAFf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,OAAO,EAAE,MAAM;CAKzB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/utils/error-utils.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,MAAM,YAAY,GACpB,kBAAkB,GAClB,wBAAwB,GACxB,qBAAqB,GACrB,qBAAqB,GACrB,yBAAyB,GACzB,gBAAgB,GAChB,wBAAwB,GACxB,kBAAkB,GAClB,eAAe,GACf,gBAAgB,GAChB,uBAAuB,GACvB,oBAAoB,GACpB,2BAA2B,GAC3B,wBAAwB,GACxB,SAAS,CAAC;AAEd;;;GAGG;AACH,qBAAa,QAAS,SAAQ,KAAK;aAEf,IAAI,EAAE,YAAY;aAElB,OAAO,CAAC,EAAE,MAAM;aAChB,QAAQ,CAAC,EAAE,MAAM;gBAHjB,IAAI,EAAE,YAAY,EAClC,OAAO,EAAE,MAAM,EACC,OAAO,CAAC,EAAE,MAAM,EAChB,QAAQ,CAAC,EAAE,MAAM;CAKpC;AAED;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,KAAK;IAEtC,UAAU,EAAE,MAAM;IAClB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAC/B,OAAO,EAAE,MAAM;gBAFf,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC/B,OAAO,EAAE,MAAM;CAKzB;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAsB1D"}
|
package/src/utils/error-utils.js
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CreateNxWorkspaceError = void 0;
|
|
3
|
+
exports.CreateNxWorkspaceError = exports.CnwError = void 0;
|
|
4
4
|
exports.mapErrorToBodyLines = mapErrorToBodyLines;
|
|
5
|
+
/**
|
|
6
|
+
* Custom error class for CNW errors.
|
|
7
|
+
* Used for structured error reporting and telemetry.
|
|
8
|
+
*/
|
|
9
|
+
class CnwError extends Error {
|
|
10
|
+
constructor(code, message, logFile, exitCode) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.logFile = logFile;
|
|
14
|
+
this.exitCode = exitCode;
|
|
15
|
+
this.name = 'CnwError';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.CnwError = CnwError;
|
|
19
|
+
/**
|
|
20
|
+
* @deprecated Use CnwError instead
|
|
21
|
+
*/
|
|
5
22
|
class CreateNxWorkspaceError extends Error {
|
|
6
23
|
constructor(logMessage, code, logFile) {
|
|
7
24
|
super(logMessage);
|
|
@@ -23,7 +40,9 @@ function mapErrorToBodyLines(error) {
|
|
|
23
40
|
}
|
|
24
41
|
const lines = error instanceof CreateNxWorkspaceError
|
|
25
42
|
? [`Exit code: ${error.code}`, `Log file: ${error.logFile}`]
|
|
26
|
-
:
|
|
43
|
+
: error instanceof CnwError && error.logFile
|
|
44
|
+
? [`Log file: ${error.logFile}`]
|
|
45
|
+
: [];
|
|
27
46
|
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
28
47
|
lines.push(`Error: ${error.message}`);
|
|
29
48
|
lines.push(`Stack: ${error.stack}`);
|
|
@@ -37,6 +37,24 @@ export declare class PromptMessages {
|
|
|
37
37
|
completionMessageOfSelectedPrompt(key: MessageKey): CompletionMessageKey;
|
|
38
38
|
}
|
|
39
39
|
export declare const messages: PromptMessages;
|
|
40
|
+
/**
|
|
41
|
+
* Meta payload types for recordStat telemetry.
|
|
42
|
+
*/
|
|
43
|
+
export interface RecordStatMetaStart {
|
|
44
|
+
type: 'start';
|
|
45
|
+
[key: string]: string;
|
|
46
|
+
}
|
|
47
|
+
export interface RecordStatMetaComplete {
|
|
48
|
+
type: 'complete';
|
|
49
|
+
[key: string]: string;
|
|
50
|
+
}
|
|
51
|
+
export interface RecordStatMetaError {
|
|
52
|
+
type: 'error';
|
|
53
|
+
errorCode: string;
|
|
54
|
+
errorMessage?: string;
|
|
55
|
+
errorFile?: string;
|
|
56
|
+
}
|
|
57
|
+
export type RecordStatMeta = RecordStatMetaStart | RecordStatMetaComplete | RecordStatMetaError;
|
|
40
58
|
/**
|
|
41
59
|
* We are incrementing a counter to track how often create-nx-workspace is used in CI
|
|
42
60
|
* vs dev environments. No personal information is collected.
|
|
@@ -45,8 +63,7 @@ export declare function recordStat(opts: {
|
|
|
45
63
|
command: string;
|
|
46
64
|
nxVersion: string;
|
|
47
65
|
useCloud: boolean;
|
|
48
|
-
meta:
|
|
49
|
-
directory: string;
|
|
66
|
+
meta: RecordStatMeta;
|
|
50
67
|
}): Promise<void>;
|
|
51
68
|
export {};
|
|
52
69
|
//# sourceMappingURL=ab-testing.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ab-testing.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/nx/ab-testing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAsDvD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,IAAI,OAAO,CAO/C;AAED;;GAEG;AACH,wBAAgB,cAAc,IAAI,MAAM,CAKvC;AAED,eAAO,MAAM,cAAc,UAQ1B,CAAC;AAEF,QAAA,MAAM,cAAc,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAsGjD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,cAAc,CAAC;AACrD,UAAU,WAAW;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,C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A;KAAE,CAAC;IAC9C,iBAAiB,EAAE,oBAAoB,CAAC;CACzC;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,gBAAgB,CAAwC;IAEhE,SAAS,CAAC,GAAG,EAAE,UAAU,GAAG,WAAW;IAavC,2BAA2B,CAAC,GAAG,EAAE,UAAU,GAAG,MAAM;IAQpD,iCAAiC,CAAC,GAAG,EAAE,UAAU,GAAG,oBAAoB;CAQzE;AAED,eAAO,MAAM,QAAQ,gBAAuB,CAAC;AAS7C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,UAAU,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,mBAAmB;IAClC,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,MAAM,cAAc,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,mBAAmB,CAAC;AAExB;;;GAGG;AACH,wBAAsB,UAAU,CAAC,IAAI,EAAE;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,IAAI,EAAE,cAAc,CAAC;CACtB,iBAuBA"}
|
|
@@ -231,12 +231,6 @@ async function recordStat(opts) {
|
|
|
231
231
|
if (!shouldRecordStats()) {
|
|
232
232
|
return;
|
|
233
233
|
}
|
|
234
|
-
// nx-ignore-next-line
|
|
235
|
-
const { getCloudUrl } = require(require.resolve('nx/src/nx-cloud/utilities/get-cloud-options', {
|
|
236
|
-
paths: [opts.directory],
|
|
237
|
-
}
|
|
238
|
-
// nx-ignore-next-line
|
|
239
|
-
));
|
|
240
234
|
const axios = require('axios');
|
|
241
235
|
await (axios['default'] ?? axios)
|
|
242
236
|
.create({
|
|
@@ -247,7 +241,7 @@ async function recordStat(opts) {
|
|
|
247
241
|
command: opts.command,
|
|
248
242
|
isCI: (0, is_ci_1.isCI)(),
|
|
249
243
|
useCloud: opts.useCloud,
|
|
250
|
-
meta:
|
|
244
|
+
meta: JSON.stringify({ nxVersion: opts.nxVersion, ...opts.meta }),
|
|
251
245
|
});
|
|
252
246
|
}
|
|
253
247
|
catch (e) {
|
|
@@ -21,6 +21,14 @@ export declare function getPackageManagerCommand(packageManager?: PackageManager
|
|
|
21
21
|
getRegistryUrl?: string;
|
|
22
22
|
};
|
|
23
23
|
export declare function generatePackageManagerFiles(root: string, packageManager?: PackageManager): void;
|
|
24
|
+
/**
|
|
25
|
+
* Converts an array of workspace globs to pnpm-workspace.yaml content.
|
|
26
|
+
*/
|
|
27
|
+
export declare function workspacesToPnpmYaml(workspaces: string[]): string;
|
|
28
|
+
/**
|
|
29
|
+
* Finds all package names from packages, libs, and apps directories.
|
|
30
|
+
*/
|
|
31
|
+
export declare function findWorkspacePackages(root: string): string[];
|
|
24
32
|
export declare function getPackageManagerVersion(packageManager: PackageManager, cwd?: string): string;
|
|
25
33
|
/**
|
|
26
34
|
* Detects which package manager was used to invoke create-nx-{plugin|workspace} command
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/utils/package-manager.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,yCAA0C,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAW,GAAG,cAAc,CAQrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,GAAE,cAAuC,GACtD;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAElB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAgDA;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,cAAuC,
|
|
1
|
+
{"version":3,"file":"package-manager.d.ts","sourceRoot":"","sources":["../../../../../packages/create-nx-workspace/src/utils/package-manager.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,kBAAkB,yCAA0C,CAAC;AAE1E,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE,wBAAgB,oBAAoB,CAAC,GAAG,GAAE,MAAW,GAAG,cAAc,CAQrE;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,wBAAwB,CACtC,cAAc,GAAE,cAAuC,GACtD;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAElB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAgDA;AAED,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,MAAM,EACZ,cAAc,GAAE,cAAuC,QAmBxD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAEjE;AAwCD;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAyB5D;AAID,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,cAAc,EAC9B,GAAG,SAAgB,GAClB,MAAM,CAWR;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,IAAI,cAAc,CAiB5D"}
|
|
@@ -4,6 +4,8 @@ exports.packageManagerList = void 0;
|
|
|
4
4
|
exports.detectPackageManager = detectPackageManager;
|
|
5
5
|
exports.getPackageManagerCommand = getPackageManagerCommand;
|
|
6
6
|
exports.generatePackageManagerFiles = generatePackageManagerFiles;
|
|
7
|
+
exports.workspacesToPnpmYaml = workspacesToPnpmYaml;
|
|
8
|
+
exports.findWorkspacePackages = findWorkspacePackages;
|
|
7
9
|
exports.getPackageManagerVersion = getPackageManagerVersion;
|
|
8
10
|
exports.detectInvokedPackageManager = detectInvokedPackageManager;
|
|
9
11
|
const node_child_process_1 = require("node:child_process");
|
|
@@ -84,6 +86,10 @@ function getPackageManagerCommand(packageManager = detectPackageManager()) {
|
|
|
84
86
|
function generatePackageManagerFiles(root, packageManager = detectPackageManager()) {
|
|
85
87
|
const [pmMajor] = getPackageManagerVersion(packageManager).split('.');
|
|
86
88
|
switch (packageManager) {
|
|
89
|
+
case 'pnpm':
|
|
90
|
+
// pnpm doesn't support "workspaces" in package.json, needs pnpm-workspace.yaml
|
|
91
|
+
convertToWorkspaceYaml(root);
|
|
92
|
+
break;
|
|
87
93
|
case 'yarn':
|
|
88
94
|
if (+pmMajor >= 2) {
|
|
89
95
|
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, '.yarnrc.yml'), 'nodeLinker: node-modules\nenableScripts: false');
|
|
@@ -93,6 +99,70 @@ function generatePackageManagerFiles(root, packageManager = detectPackageManager
|
|
|
93
99
|
break;
|
|
94
100
|
}
|
|
95
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Converts an array of workspace globs to pnpm-workspace.yaml content.
|
|
104
|
+
*/
|
|
105
|
+
function workspacesToPnpmYaml(workspaces) {
|
|
106
|
+
return `packages:\n${workspaces.map((p) => ` - '${p}'`).join('\n')}\n`;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Converts package.json "workspaces" field to pnpm-workspace.yaml
|
|
110
|
+
* and removes the workspaces field from package.json.
|
|
111
|
+
* Also adds workspace packages as devDependencies since pnpm doesn't
|
|
112
|
+
* automatically symlink workspace packages like npm/yarn.
|
|
113
|
+
*/
|
|
114
|
+
function convertToWorkspaceYaml(root) {
|
|
115
|
+
const packageJsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
116
|
+
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const packageJson = JSON.parse((0, node_fs_1.readFileSync)(packageJsonPath, 'utf-8'));
|
|
120
|
+
const workspaces = packageJson.workspaces;
|
|
121
|
+
if (!workspaces || workspaces.length === 0) {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, 'pnpm-workspace.yaml'), workspacesToPnpmYaml(workspaces));
|
|
125
|
+
// Find all workspace packages and add as devDependencies
|
|
126
|
+
const workspacePackages = findWorkspacePackages(root);
|
|
127
|
+
if (workspacePackages.length > 0) {
|
|
128
|
+
packageJson.devDependencies = packageJson.devDependencies || {};
|
|
129
|
+
for (const pkg of workspacePackages) {
|
|
130
|
+
packageJson.devDependencies[pkg] = 'workspace:*';
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Remove workspaces from package.json
|
|
134
|
+
delete packageJson.workspaces;
|
|
135
|
+
(0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Finds all package names from packages, libs, and apps directories.
|
|
139
|
+
*/
|
|
140
|
+
function findWorkspacePackages(root) {
|
|
141
|
+
const packages = [];
|
|
142
|
+
for (const dir of ['packages', 'libs', 'apps']) {
|
|
143
|
+
const fullPath = (0, node_path_1.join)(root, dir);
|
|
144
|
+
if (!(0, node_fs_1.existsSync)(fullPath))
|
|
145
|
+
continue;
|
|
146
|
+
const entries = (0, node_fs_1.readdirSync)(fullPath, { withFileTypes: true });
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
if (!entry.isDirectory())
|
|
149
|
+
continue;
|
|
150
|
+
const pkgJsonPath = (0, node_path_1.join)(fullPath, entry.name, 'package.json');
|
|
151
|
+
if ((0, node_fs_1.existsSync)(pkgJsonPath)) {
|
|
152
|
+
try {
|
|
153
|
+
const pkgJson = JSON.parse((0, node_fs_1.readFileSync)(pkgJsonPath, 'utf-8'));
|
|
154
|
+
if (pkgJson.name) {
|
|
155
|
+
packages.push(pkgJson.name);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
catch {
|
|
159
|
+
// Skip invalid package.json files
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return packages.sort();
|
|
165
|
+
}
|
|
96
166
|
const pmVersionCache = new Map();
|
|
97
167
|
function getPackageManagerVersion(packageManager, cwd = process.cwd()) {
|
|
98
168
|
if (pmVersionCache.has(packageManager)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clone-template.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/template/clone-template.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clone-template.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/template/clone-template.ts"],"names":[],"mappings":"AAMA,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC,CA0Bf"}
|
|
@@ -5,11 +5,10 @@ const child_process_utils_1 = require("../child-process-utils");
|
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const promises_1 = require("fs/promises");
|
|
7
7
|
const path_1 = require("path");
|
|
8
|
-
const output_1 = require("../output");
|
|
9
8
|
const error_utils_1 = require("../error-utils");
|
|
10
9
|
async function cloneTemplate(templateUrl, targetDirectory) {
|
|
11
10
|
if ((0, fs_1.existsSync)(targetDirectory)) {
|
|
12
|
-
throw new
|
|
11
|
+
throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${targetDirectory}' already exists and is not empty. Choose a different name or remove the existing directory.`);
|
|
13
12
|
}
|
|
14
13
|
try {
|
|
15
14
|
await (0, child_process_utils_1.execAndWait)(`git clone --depth 1 "${templateUrl}" "${targetDirectory}"`, process.cwd());
|
|
@@ -20,15 +19,7 @@ async function cloneTemplate(templateUrl, targetDirectory) {
|
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
catch (e) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
title: 'Failed to create starter workspace',
|
|
26
|
-
bodyLines: (0, error_utils_1.mapErrorToBodyLines)(e),
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
console.error(e);
|
|
31
|
-
}
|
|
32
|
-
process.exit(1);
|
|
22
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
23
|
+
throw new error_utils_1.CnwError('TEMPLATE_CLONE_FAILED', `Failed to create starter workspace: ${message}`);
|
|
33
24
|
}
|
|
34
25
|
}
|