create-nx-workspace 22.3.0-canary.20251216-71bfc21 → 22.3.0
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 +95 -9
- package/package.json +1 -1
- package/src/create-workspace.d.ts.map +1 -1
- package/src/create-workspace.js +8 -6
- package/src/internal-utils/prompts.d.ts.map +1 -1
- package/src/internal-utils/prompts.js +4 -0
- package/src/utils/git/git.d.ts +5 -0
- package/src/utils/git/git.d.ts.map +1 -1
- package/src/utils/git/git.js +15 -0
- package/src/utils/nx/ab-testing.d.ts +13 -4
- package/src/utils/nx/ab-testing.d.ts.map +1 -1
- package/src/utils/nx/nx-cloud.d.ts.map +1 -1
- package/src/utils/package-manager.d.ts +4 -1
- package/src/utils/package-manager.d.ts.map +1 -1
- package/src/utils/package-manager.js +73 -32
- package/src/utils/template/clone-template.js +1 -1
|
@@ -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":"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"}
|
|
@@ -37,6 +37,8 @@ let chosenTemplate;
|
|
|
37
37
|
let chosenPreset;
|
|
38
38
|
// Track whether user opted into cloud or not for SIGINT handler.
|
|
39
39
|
let useCloud;
|
|
40
|
+
// For stats
|
|
41
|
+
let packageManager;
|
|
40
42
|
exports.commandsObject = yargs
|
|
41
43
|
.wrap(yargs.terminalWidth())
|
|
42
44
|
.parserConfiguration({
|
|
@@ -167,7 +169,11 @@ exports.commandsObject = yargs
|
|
|
167
169
|
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
168
170
|
errorCode,
|
|
169
171
|
errorMessage,
|
|
170
|
-
errorFile,
|
|
172
|
+
errorFile: errorFile ?? '',
|
|
173
|
+
template: chosenTemplate ?? '',
|
|
174
|
+
preset: chosenPreset ?? '',
|
|
175
|
+
nodeVersion: process.versions.node ?? '',
|
|
176
|
+
packageManager: packageManager ?? '',
|
|
171
177
|
},
|
|
172
178
|
});
|
|
173
179
|
if (error instanceof error_utils_1.CnwError) {
|
|
@@ -240,6 +246,8 @@ async function main(parsedArgs) {
|
|
|
240
246
|
template: chosenTemplate ?? '',
|
|
241
247
|
preset: chosenPreset ?? '',
|
|
242
248
|
connectUrl: workspaceInfo.connectUrl ?? '',
|
|
249
|
+
nodeVersion: process.versions.node,
|
|
250
|
+
packageManager: packageManager ?? '',
|
|
243
251
|
},
|
|
244
252
|
});
|
|
245
253
|
if (parsedArgs.nxCloud && workspaceInfo.nxCloudInfo) {
|
|
@@ -273,6 +281,7 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
273
281
|
meta: {
|
|
274
282
|
type: 'start',
|
|
275
283
|
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
284
|
+
nodeVersion: process.versions.node,
|
|
276
285
|
},
|
|
277
286
|
});
|
|
278
287
|
try {
|
|
@@ -280,21 +289,35 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
280
289
|
const template = await (0, prompts_1.determineTemplate)(argv);
|
|
281
290
|
chosenTemplate = template;
|
|
282
291
|
if (template !== 'custom') {
|
|
283
|
-
// Template flow - uses detected package manager (from invoking command)
|
|
292
|
+
// Template flow - respects CLI arg, otherwise uses detected package manager (from invoking command)
|
|
284
293
|
argv.template = template;
|
|
285
294
|
const aiAgents = await (0, prompts_1.determineAiAgents)(argv);
|
|
286
295
|
const nxCloud = argv.skipGit === true ? 'skip' : await (0, prompts_1.determineNxCloudV2)(argv);
|
|
287
296
|
const completionMessageKey = nxCloud === 'skip'
|
|
288
297
|
? undefined
|
|
289
298
|
: ab_testing_1.messages.completionMessageOfSelectedPrompt('setupNxCloudV2');
|
|
299
|
+
packageManager = argv.packageManager ?? (0, package_manager_1.detectInvokedPackageManager)();
|
|
290
300
|
Object.assign(argv, {
|
|
291
301
|
nxCloud,
|
|
292
302
|
useGitHub: nxCloud !== 'skip',
|
|
293
303
|
completionMessageKey,
|
|
294
|
-
packageManager
|
|
304
|
+
packageManager,
|
|
295
305
|
defaultBase: 'main',
|
|
296
306
|
aiAgents,
|
|
297
307
|
});
|
|
308
|
+
await (0, ab_testing_1.recordStat)({
|
|
309
|
+
nxVersion: nx_version_1.nxVersion,
|
|
310
|
+
command: 'create-nx-workspace',
|
|
311
|
+
useCloud: nxCloud !== 'skip',
|
|
312
|
+
meta: {
|
|
313
|
+
type: 'precreate',
|
|
314
|
+
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
315
|
+
template: chosenTemplate,
|
|
316
|
+
preset: '',
|
|
317
|
+
nodeVersion: process.versions.node ?? '',
|
|
318
|
+
packageManager,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
298
321
|
}
|
|
299
322
|
else {
|
|
300
323
|
// Preset flow - existing behavior
|
|
@@ -312,21 +335,57 @@ async function normalizeArgsMiddleware(argv) {
|
|
|
312
335
|
throw new error_utils_1.CnwError('INVALID_PRESET', `Could not find preset "${argv.preset}": ${message}`);
|
|
313
336
|
}
|
|
314
337
|
}
|
|
315
|
-
|
|
338
|
+
packageManager = await (0, prompts_1.determinePackageManager)(argv);
|
|
316
339
|
const aiAgents = await (0, prompts_1.determineAiAgents)(argv);
|
|
317
340
|
const defaultBase = await (0, prompts_1.determineDefaultBase)(argv);
|
|
318
|
-
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
341
|
+
// Check if CLI arg was provided (use rawArgs to check original input)
|
|
342
|
+
const cliNxCloudArgProvided = rawArgs.nxCloud !== undefined;
|
|
343
|
+
let nxCloud;
|
|
344
|
+
let useGitHub;
|
|
345
|
+
let completionMessageKey;
|
|
346
|
+
if (argv.skipGit === true) {
|
|
347
|
+
nxCloud = 'skip';
|
|
348
|
+
useGitHub = undefined;
|
|
349
|
+
}
|
|
350
|
+
else if (cliNxCloudArgProvided) {
|
|
351
|
+
// CLI arg provided: use existing flow (CI provider selection if needed)
|
|
352
|
+
nxCloud = await (0, prompts_1.determineNxCloud)(argv);
|
|
353
|
+
useGitHub =
|
|
354
|
+
nxCloud === 'skip'
|
|
355
|
+
? undefined
|
|
356
|
+
: nxCloud === 'github' || (await (0, prompts_1.determineIfGitHubWillBeUsed)(argv));
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
// No CLI arg: use simplified prompt (same as template flow)
|
|
360
|
+
nxCloud = await (0, prompts_1.determineNxCloudV2)(argv);
|
|
361
|
+
useGitHub = nxCloud !== 'skip';
|
|
362
|
+
completionMessageKey =
|
|
363
|
+
nxCloud === 'skip'
|
|
364
|
+
? undefined
|
|
365
|
+
: ab_testing_1.messages.completionMessageOfSelectedPrompt('setupNxCloudV2');
|
|
366
|
+
}
|
|
322
367
|
Object.assign(argv, {
|
|
323
368
|
nxCloud,
|
|
324
369
|
useGitHub,
|
|
370
|
+
completionMessageKey,
|
|
325
371
|
packageManager,
|
|
326
372
|
defaultBase,
|
|
327
373
|
aiAgents,
|
|
328
374
|
});
|
|
329
375
|
chosenPreset = argv.preset;
|
|
376
|
+
await (0, ab_testing_1.recordStat)({
|
|
377
|
+
nxVersion: nx_version_1.nxVersion,
|
|
378
|
+
command: 'create-nx-workspace',
|
|
379
|
+
useCloud: nxCloud !== 'skip',
|
|
380
|
+
meta: {
|
|
381
|
+
type: 'precreate',
|
|
382
|
+
flowVariant: (0, ab_testing_1.getFlowVariant)(),
|
|
383
|
+
template: '',
|
|
384
|
+
preset: chosenPreset ?? '',
|
|
385
|
+
nodeVersion: process.versions.node ?? '',
|
|
386
|
+
packageManager,
|
|
387
|
+
},
|
|
388
|
+
});
|
|
330
389
|
}
|
|
331
390
|
}
|
|
332
391
|
catch (e) {
|
|
@@ -362,8 +421,22 @@ async function determineFolder(parsedArgs) {
|
|
|
362
421
|
: parsedArgs.name;
|
|
363
422
|
if (folderName) {
|
|
364
423
|
validateWorkspaceName(folderName);
|
|
424
|
+
// If directory exists, either re-prompt (interactive) or error (non-interactive)
|
|
425
|
+
if ((0, fs_1.existsSync)(folderName)) {
|
|
426
|
+
if (parsedArgs.interactive && !(0, is_ci_1.isCI)()) {
|
|
427
|
+
output_1.output.warn({
|
|
428
|
+
title: `Directory ${folderName} already exists.`,
|
|
429
|
+
});
|
|
430
|
+
// Re-prompt for a new folder name
|
|
431
|
+
return promptForFolder(parsedArgs);
|
|
432
|
+
}
|
|
433
|
+
throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${folderName}' already exists. Choose a different name or remove the existing directory.`);
|
|
434
|
+
}
|
|
365
435
|
return folderName;
|
|
366
436
|
}
|
|
437
|
+
return promptForFolder(parsedArgs);
|
|
438
|
+
}
|
|
439
|
+
async function promptForFolder(parsedArgs) {
|
|
367
440
|
const reply = await enquirer.prompt([
|
|
368
441
|
{
|
|
369
442
|
name: 'folderName',
|
|
@@ -371,11 +444,24 @@ async function determineFolder(parsedArgs) {
|
|
|
371
444
|
initial: 'org',
|
|
372
445
|
type: 'input',
|
|
373
446
|
skip: !parsedArgs.interactive || (0, is_ci_1.isCI)(),
|
|
447
|
+
validate: (value) => {
|
|
448
|
+
if (!value) {
|
|
449
|
+
return 'Folder name cannot be empty';
|
|
450
|
+
}
|
|
451
|
+
if (!/^[a-zA-Z]/.test(value)) {
|
|
452
|
+
return 'Workspace name must start with a letter';
|
|
453
|
+
}
|
|
454
|
+
if ((0, fs_1.existsSync)(value)) {
|
|
455
|
+
return `The directory '${value}' already exists`;
|
|
456
|
+
}
|
|
457
|
+
return true;
|
|
458
|
+
},
|
|
374
459
|
},
|
|
375
460
|
]);
|
|
461
|
+
// Fallback invariants in case validate is bypassed (e.g., in CI or non-interactive mode)
|
|
376
462
|
invariant(reply.folderName, 'INVALID_FOLDER_NAME', 'Folder name cannot be empty');
|
|
377
463
|
validateWorkspaceName(reply.folderName);
|
|
378
|
-
invariant(!(0, fs_1.existsSync)(reply.folderName), 'DIRECTORY_EXISTS', `The
|
|
464
|
+
invariant(!(0, fs_1.existsSync)(reply.folderName), 'DIRECTORY_EXISTS', `The directory '${reply.folderName}' already exists. Choose a different name or remove the existing directory.`);
|
|
379
465
|
return reply.folderName;
|
|
380
466
|
}
|
|
381
467
|
async function determineStack(parsedArgs) {
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
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;;;;;
|
|
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;;;;;GAgLZ;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAI7D"}
|
package/src/create-workspace.js
CHANGED
|
@@ -87,20 +87,22 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
89
|
const isTemplate = !!options.template;
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
// Generate CI for preset flow (not template)
|
|
91
|
+
// When nxCloud === 'yes' (from simplified prompt), use GitHub as the CI provider
|
|
92
|
+
if (nxCloud !== 'skip' && !isTemplate) {
|
|
93
|
+
const ciProvider = nxCloud === 'yes' ? 'github' : nxCloud;
|
|
94
|
+
await (0, setup_ci_1.setupCI)(directory, ciProvider, packageManager);
|
|
93
95
|
}
|
|
94
96
|
let pushedToVcs = git_1.VcsPushStatus.SkippedGit;
|
|
95
97
|
if (!skipGit) {
|
|
96
98
|
try {
|
|
97
99
|
await (0, git_1.initializeGitRepo)(directory, { defaultBase, commit });
|
|
98
100
|
// Push to GitHub if commit was made, GitHub push is not skipped, and:
|
|
99
|
-
// - CI provider is GitHub (preset flow), OR
|
|
100
|
-
// -
|
|
101
|
+
// - CI provider is GitHub (preset flow with CLI arg), OR
|
|
102
|
+
// - Nx Cloud enabled via simplified prompt (nxCloud === 'yes')
|
|
101
103
|
if (commit &&
|
|
102
104
|
!skipGitHubPush &&
|
|
103
|
-
(nxCloud === 'github' ||
|
|
105
|
+
(nxCloud === 'github' || nxCloud === 'yes')) {
|
|
104
106
|
pushedToVcs = await (0, git_1.pushToGitHub)(directory, {
|
|
105
107
|
skipGitHubPush,
|
|
106
108
|
name,
|
|
@@ -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;AAW/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,CA4C5B;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"}
|
|
@@ -11,6 +11,7 @@ const enquirer = require("enquirer");
|
|
|
11
11
|
const chalk = require("chalk");
|
|
12
12
|
const ab_testing_1 = require("../utils/nx/ab-testing");
|
|
13
13
|
const default_base_1 = require("../utils/git/default-base");
|
|
14
|
+
const git_1 = require("../utils/git/git");
|
|
14
15
|
const package_manager_1 = require("../utils/package-manager");
|
|
15
16
|
const string_utils_1 = require("../utils/string-utils");
|
|
16
17
|
const is_ci_1 = require("../utils/ci/is-ci");
|
|
@@ -105,6 +106,9 @@ async function determineTemplate(parsedArgs) {
|
|
|
105
106
|
// A/B test: shouldUseTemplateFlow() determines if user sees template or preset flow
|
|
106
107
|
if (!(0, ab_testing_1.shouldUseTemplateFlow)())
|
|
107
108
|
return 'custom';
|
|
109
|
+
// Template flow requires git for cloning - fall back to custom preset if git is not available
|
|
110
|
+
if (!(0, git_1.isGitAvailable)())
|
|
111
|
+
return 'custom';
|
|
108
112
|
const { template } = await enquirer.prompt([
|
|
109
113
|
{
|
|
110
114
|
name: 'template',
|
package/src/utils/git/git.d.ts
CHANGED
|
@@ -9,6 +9,11 @@ export declare class GitHubPushSkippedError extends Error {
|
|
|
9
9
|
constructor(message: string);
|
|
10
10
|
}
|
|
11
11
|
export declare function checkGitVersion(): Promise<string | null | undefined>;
|
|
12
|
+
/**
|
|
13
|
+
* Synchronously checks if git is available on the system.
|
|
14
|
+
* Returns true if git command can be executed, false otherwise.
|
|
15
|
+
*/
|
|
16
|
+
export declare function isGitAvailable(): boolean;
|
|
12
17
|
export declare function initializeGitRepo(directory: string, options: {
|
|
13
18
|
defaultBase: string;
|
|
14
19
|
commit?: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/git/git.ts"],"names":[],"mappings":"AAMA,oBAAY,aAAa;IACvB,WAAW,gBAAgB;IAC3B,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,UAAU,eAAe;CAC1B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAgB,KAAK,yBAAyB;gBAElC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAQ1E;AA0ED,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,iBAsDF;AAED,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,OAAO,CAAC,aAAa,CAAC,CAuHxB"}
|
|
1
|
+
{"version":3,"file":"git.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/git/git.ts"],"names":[],"mappings":"AAMA,oBAAY,aAAa;IACvB,WAAW,gBAAgB;IAC3B,sBAAsB,2BAA2B;IACjD,iBAAiB,sBAAsB;IACvC,UAAU,eAAe;CAC1B;AAED,qBAAa,sBAAuB,SAAQ,KAAK;IAC/C,SAAgB,KAAK,yBAAyB;gBAElC,OAAO,EAAE,MAAM;CAI5B;AAED,wBAAsB,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,CAQ1E;AAED;;;GAGG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAOxC;AA0ED,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,iBAsDF;AAED,wBAAsB,YAAY,CAChC,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE;IACP,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,GACA,OAAO,CAAC,aAAa,CAAC,CAuHxB"}
|
package/src/utils/git/git.js
CHANGED
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GitHubPushSkippedError = exports.VcsPushStatus = void 0;
|
|
4
4
|
exports.checkGitVersion = checkGitVersion;
|
|
5
|
+
exports.isGitAvailable = isGitAvailable;
|
|
5
6
|
exports.initializeGitRepo = initializeGitRepo;
|
|
6
7
|
exports.pushToGitHub = pushToGitHub;
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
7
9
|
const default_base_1 = require("./default-base");
|
|
8
10
|
const output_1 = require("../output");
|
|
9
11
|
const child_process_utils_1 = require("../child-process-utils");
|
|
@@ -33,6 +35,19 @@ async function checkGitVersion() {
|
|
|
33
35
|
return null;
|
|
34
36
|
}
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Synchronously checks if git is available on the system.
|
|
40
|
+
* Returns true if git command can be executed, false otherwise.
|
|
41
|
+
*/
|
|
42
|
+
function isGitAvailable() {
|
|
43
|
+
try {
|
|
44
|
+
(0, child_process_1.execSync)('git --version', { stdio: 'ignore' });
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
36
51
|
async function getGitHubUsername(directory) {
|
|
37
52
|
const result = await (0, child_process_utils_1.execAndWait)('gh api user --jq .login', directory);
|
|
38
53
|
const username = result.stdout.trim();
|
|
@@ -51,15 +51,24 @@ export interface RecordStatMetaComplete {
|
|
|
51
51
|
export interface RecordStatMetaError {
|
|
52
52
|
type: 'error';
|
|
53
53
|
errorCode: string;
|
|
54
|
-
flowVariant
|
|
55
|
-
errorMessage
|
|
56
|
-
errorFile
|
|
54
|
+
flowVariant: string;
|
|
55
|
+
errorMessage: string;
|
|
56
|
+
errorFile: string;
|
|
57
|
+
[key: string]: string;
|
|
57
58
|
}
|
|
58
59
|
export interface RecordStatMetaCancel {
|
|
59
60
|
type: 'cancel';
|
|
60
61
|
flowVariant?: string;
|
|
61
62
|
}
|
|
62
|
-
export
|
|
63
|
+
export interface RecordStatMetaPrecreate {
|
|
64
|
+
type: 'precreate';
|
|
65
|
+
flowVariant: string;
|
|
66
|
+
template: string;
|
|
67
|
+
preset: string;
|
|
68
|
+
nodeVersion: string;
|
|
69
|
+
packageManager: string;
|
|
70
|
+
}
|
|
71
|
+
export type RecordStatMeta = RecordStatMetaStart | RecordStatMetaComplete | RecordStatMetaError | RecordStatMetaCancel | RecordStatMetaPrecreate;
|
|
63
72
|
/**
|
|
64
73
|
* We are incrementing a counter to track how often create-nx-workspace is used in CI
|
|
65
74
|
* vs dev environments. No personal information is collected.
|
|
@@ -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,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;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,WAAW,
|
|
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,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,UAAU,CAAA;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,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,QAAQ,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,WAAW,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,cAAc,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,cAAc,GACtB,mBAAmB,GACnB,sBAAsB,GACtB,mBAAmB,GACnB,oBAAoB,GACpB,uBAAuB,CAAC;AAE5B;;;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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-cloud.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/nx/nx-cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAGL,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAIpB,MAAM,MAAM,OAAO,GACf,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,qBAAqB,GACrB,UAAU,GACV,MAAM,CAAC;AAEX,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM,EAC1B,SAAS,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"nx-cloud.d.ts","sourceRoot":"","sources":["../../../../../../packages/create-nx-workspace/src/utils/nx/nx-cloud.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE3C,OAAO,EAGL,oBAAoB,EACrB,MAAM,YAAY,CAAC;AAIpB,MAAM,MAAM,OAAO,GACf,KAAK,GACL,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,qBAAqB,GACrB,UAAU,GACV,MAAM,CAAC;AAEX,wBAAsB,2BAA2B,CAC/C,SAAS,EAAE,MAAM,EACjB,kBAAkB,EAAE,MAAM,EAC1B,SAAS,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CA+BxB;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,UAgBjD;AAED,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,SAAS,CAAC,EAAE,OAAO,GAClB,OAAO,CAAC,MAAM,CAAC,CAwCjB;AAED,wBAAsB,cAAc,CAClC,eAAe,EAAE,MAAM,EACvB,WAAW,EAAE,aAAa,EAC1B,oBAAoB,CAAC,EAAE,oBAAoB,mBAU5C;AAED,wBAAgB,qBAAqB,WAIpC"}
|
|
@@ -26,8 +26,11 @@ export declare function generatePackageManagerFiles(root: string, packageManager
|
|
|
26
26
|
*/
|
|
27
27
|
export declare function workspacesToPnpmYaml(workspaces: string[]): string;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Converts "*" dependencies to "workspace:*" in all workspace package.json files.
|
|
30
|
+
* This is needed for pnpm, yarn, and bun to properly symlink workspace packages.
|
|
30
31
|
*/
|
|
32
|
+
export declare function convertStarToWorkspaceProtocol(root: string): void;
|
|
33
|
+
export declare function findAllWorkspacePackageJsons(root: string, maxDepth?: number): string[];
|
|
31
34
|
export declare function findWorkspacePackages(root: string): string[];
|
|
32
35
|
export declare function getPackageManagerVersion(packageManager: PackageManager, cwd?: string): string;
|
|
33
36
|
/**
|
|
@@ -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,QAyBxD;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAEjE;AAwBD;;;GAGG;AACH,wBAAgB,8BAA8B,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAuBjE;AAED,wBAAgB,4BAA4B,CAC1C,IAAI,EAAE,MAAM,EACZ,QAAQ,GAAE,MAAU,GACnB,MAAM,EAAE,CAWV;AAsCD,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAgB5D;AAID,wBAAgB,wBAAwB,CACtC,cAAc,EAAE,cAAc,EAC9B,GAAG,SAAgB,GAClB,MAAM,CAWR;AAED;;;;;;;;;GASG;AACH,wBAAgB,2BAA2B,IAAI,cAAc,CAiB5D"}
|
|
@@ -5,6 +5,8 @@ exports.detectPackageManager = detectPackageManager;
|
|
|
5
5
|
exports.getPackageManagerCommand = getPackageManagerCommand;
|
|
6
6
|
exports.generatePackageManagerFiles = generatePackageManagerFiles;
|
|
7
7
|
exports.workspacesToPnpmYaml = workspacesToPnpmYaml;
|
|
8
|
+
exports.convertStarToWorkspaceProtocol = convertStarToWorkspaceProtocol;
|
|
9
|
+
exports.findAllWorkspacePackageJsons = findAllWorkspacePackageJsons;
|
|
8
10
|
exports.findWorkspacePackages = findWorkspacePackages;
|
|
9
11
|
exports.getPackageManagerVersion = getPackageManagerVersion;
|
|
10
12
|
exports.detectInvokedPackageManager = detectInvokedPackageManager;
|
|
@@ -87,8 +89,9 @@ function generatePackageManagerFiles(root, packageManager = detectPackageManager
|
|
|
87
89
|
const [pmMajor] = getPackageManagerVersion(packageManager).split('.');
|
|
88
90
|
switch (packageManager) {
|
|
89
91
|
case 'pnpm':
|
|
90
|
-
// pnpm doesn't support "workspaces" in package.json
|
|
92
|
+
// pnpm doesn't support "workspaces" in package.json
|
|
91
93
|
convertToWorkspaceYaml(root);
|
|
94
|
+
convertStarToWorkspaceProtocol(root);
|
|
92
95
|
break;
|
|
93
96
|
case 'yarn':
|
|
94
97
|
if (+pmMajor >= 2) {
|
|
@@ -96,7 +99,12 @@ function generatePackageManagerFiles(root, packageManager = detectPackageManager
|
|
|
96
99
|
// avoids errors when using nested yarn projects
|
|
97
100
|
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(root, 'yarn.lock'), '');
|
|
98
101
|
}
|
|
102
|
+
convertStarToWorkspaceProtocol(root);
|
|
99
103
|
break;
|
|
104
|
+
case 'bun':
|
|
105
|
+
convertStarToWorkspaceProtocol(root);
|
|
106
|
+
break;
|
|
107
|
+
// npm handles "*" natively, no conversion needed
|
|
100
108
|
}
|
|
101
109
|
}
|
|
102
110
|
/**
|
|
@@ -105,12 +113,6 @@ function generatePackageManagerFiles(root, packageManager = detectPackageManager
|
|
|
105
113
|
function workspacesToPnpmYaml(workspaces) {
|
|
106
114
|
return `packages:\n${workspaces.map((p) => ` - '${p}'`).join('\n')}\n`;
|
|
107
115
|
}
|
|
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
116
|
function convertToWorkspaceYaml(root) {
|
|
115
117
|
const packageJsonPath = (0, node_path_1.join)(root, 'package.json');
|
|
116
118
|
if (!(0, node_fs_1.existsSync)(packageJsonPath)) {
|
|
@@ -122,45 +124,84 @@ function convertToWorkspaceYaml(root) {
|
|
|
122
124
|
return;
|
|
123
125
|
}
|
|
124
126
|
(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
127
|
delete packageJson.workspaces;
|
|
135
128
|
(0, node_fs_1.writeFileSync)(packageJsonPath, JSON.stringify(packageJson, null, 2) + '\n');
|
|
136
129
|
}
|
|
137
130
|
/**
|
|
138
|
-
*
|
|
131
|
+
* Converts "*" dependencies to "workspace:*" in all workspace package.json files.
|
|
132
|
+
* This is needed for pnpm, yarn, and bun to properly symlink workspace packages.
|
|
139
133
|
*/
|
|
140
|
-
function
|
|
141
|
-
const
|
|
134
|
+
function convertStarToWorkspaceProtocol(root) {
|
|
135
|
+
for (const pkgJsonPath of findAllWorkspacePackageJsons(root)) {
|
|
136
|
+
try {
|
|
137
|
+
const pkgJson = JSON.parse((0, node_fs_1.readFileSync)(pkgJsonPath, 'utf-8'));
|
|
138
|
+
let updated = false;
|
|
139
|
+
for (const deps of [pkgJson.dependencies, pkgJson.devDependencies]) {
|
|
140
|
+
if (!deps)
|
|
141
|
+
continue;
|
|
142
|
+
for (const [dep, version] of Object.entries(deps)) {
|
|
143
|
+
if (version === '*') {
|
|
144
|
+
deps[dep] = 'workspace:*';
|
|
145
|
+
updated = true;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (updated) {
|
|
150
|
+
(0, node_fs_1.writeFileSync)(pkgJsonPath, JSON.stringify(pkgJson, null, 2) + '\n');
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
catch {
|
|
154
|
+
// Skip invalid package.json files
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function findAllWorkspacePackageJsons(root, maxDepth = 2) {
|
|
159
|
+
const results = [];
|
|
142
160
|
for (const dir of ['packages', 'libs', 'apps']) {
|
|
143
161
|
const fullPath = (0, node_path_1.join)(root, dir);
|
|
144
|
-
if (
|
|
145
|
-
|
|
146
|
-
|
|
162
|
+
if ((0, node_fs_1.existsSync)(fullPath)) {
|
|
163
|
+
findPackageJsonsRecursive(fullPath, 1, maxDepth, results);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return results;
|
|
167
|
+
}
|
|
168
|
+
function findPackageJsonsRecursive(dir, currentDepth, maxDepth, results) {
|
|
169
|
+
if (currentDepth > maxDepth) {
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const entries = (0, node_fs_1.readdirSync)(dir, { withFileTypes: true });
|
|
147
174
|
for (const entry of entries) {
|
|
148
175
|
if (!entry.isDirectory())
|
|
149
176
|
continue;
|
|
150
|
-
const
|
|
177
|
+
const entryPath = (0, node_path_1.join)(dir, entry.name);
|
|
178
|
+
const pkgJsonPath = (0, node_path_1.join)(entryPath, 'package.json');
|
|
151
179
|
if ((0, node_fs_1.existsSync)(pkgJsonPath)) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch {
|
|
159
|
-
// Skip invalid package.json files
|
|
160
|
-
}
|
|
180
|
+
results.push(pkgJsonPath);
|
|
181
|
+
}
|
|
182
|
+
if (currentDepth < maxDepth) {
|
|
183
|
+
findPackageJsonsRecursive(entryPath, currentDepth + 1, maxDepth, results);
|
|
161
184
|
}
|
|
162
185
|
}
|
|
163
186
|
}
|
|
187
|
+
catch {
|
|
188
|
+
// Skip unreadable directories
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function findWorkspacePackages(root) {
|
|
192
|
+
const packages = [];
|
|
193
|
+
const packageJsonPaths = findAllWorkspacePackageJsons(root);
|
|
194
|
+
for (const pkgJsonPath of packageJsonPaths) {
|
|
195
|
+
try {
|
|
196
|
+
const pkgJson = JSON.parse((0, node_fs_1.readFileSync)(pkgJsonPath, 'utf-8'));
|
|
197
|
+
if (pkgJson.name) {
|
|
198
|
+
packages.push(pkgJson.name);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
catch {
|
|
202
|
+
// Skip invalid package.json files
|
|
203
|
+
}
|
|
204
|
+
}
|
|
164
205
|
return packages.sort();
|
|
165
206
|
}
|
|
166
207
|
const pmVersionCache = new Map();
|
|
@@ -8,7 +8,7 @@ const path_1 = require("path");
|
|
|
8
8
|
const error_utils_1 = require("../error-utils");
|
|
9
9
|
async function cloneTemplate(templateUrl, targetDirectory) {
|
|
10
10
|
if ((0, fs_1.existsSync)(targetDirectory)) {
|
|
11
|
-
throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${targetDirectory}' already exists
|
|
11
|
+
throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${targetDirectory}' already exists. Choose a different name or remove the existing directory.`);
|
|
12
12
|
}
|
|
13
13
|
try {
|
|
14
14
|
await (0, child_process_utils_1.execAndWait)(`git clone --depth 1 "${templateUrl}" "${targetDirectory}"`, process.cwd());
|