create-nx-workspace 23.2.0-beta.7 → 23.2.0-beta.9
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/bin/create-nx-workspace.d.ts +2 -2
- package/dist/bin/create-nx-workspace.js +327 -506
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +5 -1
- package/dist/src/create-workspace.js +72 -3
- package/dist/src/internal-utils/prompt-helpers.d.ts +57 -0
- package/dist/src/internal-utils/prompt-helpers.js +105 -0
- package/dist/src/internal-utils/prompts.d.ts +6 -0
- package/dist/src/internal-utils/prompts.js +135 -139
- package/dist/src/utils/error-utils.d.ts +1 -1
- package/dist/src/utils/exit-codes.d.ts +12 -0
- package/dist/src/utils/exit-codes.js +24 -0
- package/dist/src/utils/git/git.js +29 -30
- package/dist/src/utils/nx/ab-testing.d.ts +0 -1
- package/dist/src/utils/nx/ab-testing.js +4 -2
- package/package.json +2 -2
package/dist/internal.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { determineDefaultBase, determineLinterOptions, determineNxCloud, determinePackageManager, LINTERS, } from './src/internal-utils/prompts';
|
|
2
2
|
export type { Linter } from './src/internal-utils/prompts';
|
|
3
|
+
export { selectPrompt, textPrompt, confirmationPrompt, } from './src/internal-utils/prompt-helpers';
|
|
3
4
|
export { withAllPrompts, withGitOptions, withNxCloud, withOptions, withPackageManager, } from './src/internal-utils/yargs-options';
|
|
4
5
|
export { output } from './src/utils/output';
|
|
5
6
|
export type { NxCloud } from './src/utils/nx/nx-cloud';
|
package/dist/internal.js
CHANGED
|
@@ -5,13 +5,17 @@
|
|
|
5
5
|
// internal consumers and may change without semver protection. Mirrors
|
|
6
6
|
// `@nx/devkit/internal`.
|
|
7
7
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
-
exports.recordStat = exports.messages = exports.output = exports.withPackageManager = exports.withOptions = exports.withNxCloud = exports.withGitOptions = exports.withAllPrompts = exports.LINTERS = exports.determinePackageManager = exports.determineNxCloud = exports.determineLinterOptions = exports.determineDefaultBase = void 0;
|
|
8
|
+
exports.recordStat = exports.messages = exports.output = exports.withPackageManager = exports.withOptions = exports.withNxCloud = exports.withGitOptions = exports.withAllPrompts = exports.confirmationPrompt = exports.textPrompt = exports.selectPrompt = exports.LINTERS = exports.determinePackageManager = exports.determineNxCloud = exports.determineLinterOptions = exports.determineDefaultBase = void 0;
|
|
9
9
|
var prompts_1 = require("./src/internal-utils/prompts");
|
|
10
10
|
Object.defineProperty(exports, "determineDefaultBase", { enumerable: true, get: function () { return prompts_1.determineDefaultBase; } });
|
|
11
11
|
Object.defineProperty(exports, "determineLinterOptions", { enumerable: true, get: function () { return prompts_1.determineLinterOptions; } });
|
|
12
12
|
Object.defineProperty(exports, "determineNxCloud", { enumerable: true, get: function () { return prompts_1.determineNxCloud; } });
|
|
13
13
|
Object.defineProperty(exports, "determinePackageManager", { enumerable: true, get: function () { return prompts_1.determinePackageManager; } });
|
|
14
14
|
Object.defineProperty(exports, "LINTERS", { enumerable: true, get: function () { return prompts_1.LINTERS; } });
|
|
15
|
+
var prompt_helpers_1 = require("./src/internal-utils/prompt-helpers");
|
|
16
|
+
Object.defineProperty(exports, "selectPrompt", { enumerable: true, get: function () { return prompt_helpers_1.selectPrompt; } });
|
|
17
|
+
Object.defineProperty(exports, "textPrompt", { enumerable: true, get: function () { return prompt_helpers_1.textPrompt; } });
|
|
18
|
+
Object.defineProperty(exports, "confirmationPrompt", { enumerable: true, get: function () { return prompt_helpers_1.confirmationPrompt; } });
|
|
15
19
|
var yargs_options_1 = require("./src/internal-utils/yargs-options");
|
|
16
20
|
Object.defineProperty(exports, "withAllPrompts", { enumerable: true, get: function () { return yargs_options_1.withAllPrompts; } });
|
|
17
21
|
Object.defineProperty(exports, "withGitOptions", { enumerable: true, get: function () { return yargs_options_1.withGitOptions; } });
|
|
@@ -22,7 +22,6 @@ const child_process_utils_1 = require("./utils/child-process-utils");
|
|
|
22
22
|
const package_manager_1 = require("./utils/package-manager");
|
|
23
23
|
const ai_output_1 = require("./utils/ai/ai-output");
|
|
24
24
|
const prompts_1 = require("./internal-utils/prompts");
|
|
25
|
-
const error_utils_2 = require("./utils/error-utils");
|
|
26
25
|
// State for SIGINT handler - only set after workspace is fully installed
|
|
27
26
|
let workspaceDirectory;
|
|
28
27
|
let cloudConnectUrl;
|
|
@@ -34,6 +33,12 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
34
33
|
if (cliName) {
|
|
35
34
|
output_1.output.setCliName(cliName ?? 'NX');
|
|
36
35
|
}
|
|
36
|
+
// Skip formatting during generation - the single pass at the end covers
|
|
37
|
+
// everything once dependencies are on disk. A user who set this deliberately
|
|
38
|
+
// still gets no formatting at all, so remember their value rather than
|
|
39
|
+
// silently taking it over.
|
|
40
|
+
const skipFormatRequested = process.env.NX_SKIP_FORMAT === 'true';
|
|
41
|
+
process.env.NX_SKIP_FORMAT = 'true';
|
|
37
42
|
let directory;
|
|
38
43
|
if (options.template) {
|
|
39
44
|
// Resolve shorthand template names to full GitHub org/repo format
|
|
@@ -49,7 +54,7 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
49
54
|
// Otherwise refuse to write over an existing path (the CLI already guards
|
|
50
55
|
// this in determineFolder; this protects direct createWorkspace() callers).
|
|
51
56
|
if (!options.useCurrentDir && (0, node_fs_1.existsSync)(directory)) {
|
|
52
|
-
throw new
|
|
57
|
+
throw new error_utils_1.CnwError('DIRECTORY_EXISTS', `The directory '${directory}' already exists. Choose a different name or remove the existing directory.`);
|
|
53
58
|
}
|
|
54
59
|
const aiMode = (0, ai_output_1.isAiAgent)();
|
|
55
60
|
// Use spinner for human mode, progress logs for AI mode
|
|
@@ -113,7 +118,7 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
113
118
|
if (thirdPartyPackageName) {
|
|
114
119
|
const confirmed = await (0, prompts_1.confirmThirdPartyPreset)(thirdPartyPackageName, options.interactive, options.trustThirdPartyPreset);
|
|
115
120
|
if (!confirmed) {
|
|
116
|
-
throw new
|
|
121
|
+
throw new error_utils_1.CnwError('INVALID_PRESET', `Aborted: not installing third-party preset '${thirdPartyPackageName}'.`);
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
const tmpDir = await (0, create_sandbox_1.createSandbox)(packageManager);
|
|
@@ -152,6 +157,45 @@ async function createWorkspace(preset, options, rawArgs) {
|
|
|
152
157
|
const ciProvider = nxCloud === 'yes' ? 'github' : nxCloud;
|
|
153
158
|
await (0, setup_ci_1.setupCI)(directory, ciProvider, packageManager);
|
|
154
159
|
}
|
|
160
|
+
// Only now are dependencies on disk: the passes inside `@nx/workspace:new`
|
|
161
|
+
// run before the install, when no formatter resolves yet.
|
|
162
|
+
if (skipFormatRequested) {
|
|
163
|
+
process.env.NX_SKIP_FORMAT = 'true';
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
delete process.env.NX_SKIP_FORMAT;
|
|
167
|
+
}
|
|
168
|
+
if (!skipFormatRequested && workspaceHasFormatter(directory)) {
|
|
169
|
+
try {
|
|
170
|
+
const pmc = (0, package_manager_1.getPackageManagerCommand)(packageManager);
|
|
171
|
+
// `--all` because git is not initialised yet, so there is nothing to diff
|
|
172
|
+
// changed files against.
|
|
173
|
+
await (0, child_process_utils_1.execAndWait)(`${pmc.exec} nx format --all`, directory);
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
// `execAndWait` names a log file only when there was no output at all,
|
|
177
|
+
// and that file is deleted below - so report the exit code instead.
|
|
178
|
+
const reason = e?.logFile && e?.message?.includes(e.logFile)
|
|
179
|
+
? `The command failed with exit code ${e.exitCode ?? 'unknown'} and produced no output.`
|
|
180
|
+
: e?.message;
|
|
181
|
+
output_1.output.warn({
|
|
182
|
+
title: 'Could not format the new workspace.',
|
|
183
|
+
bodyLines: [
|
|
184
|
+
'The workspace was created successfully, but its files are not formatted.',
|
|
185
|
+
...(reason ? [reason] : []),
|
|
186
|
+
'Run "nx format:write" inside the workspace to format them.',
|
|
187
|
+
],
|
|
188
|
+
});
|
|
189
|
+
// Otherwise `initializeGitRepo`'s `git add .` puts an error.log in the
|
|
190
|
+
// workspace's first commit; the .gitignore templates do not cover it.
|
|
191
|
+
if (e?.logFile && (0, node_fs_1.existsSync)(e.logFile)) {
|
|
192
|
+
try {
|
|
193
|
+
(0, node_fs_1.unlinkSync)(e.logFile);
|
|
194
|
+
}
|
|
195
|
+
catch { }
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
155
199
|
let pushedToVcs = git_1.VcsPushStatus.SkippedGit;
|
|
156
200
|
let pushFailReason;
|
|
157
201
|
if (!skipGit) {
|
|
@@ -297,3 +341,28 @@ function getWorkspaceGlobsFromPreset(preset) {
|
|
|
297
341
|
return ['packages/*'];
|
|
298
342
|
}
|
|
299
343
|
}
|
|
344
|
+
/**
|
|
345
|
+
* Asks the workspace rather than the caller. `formatter` is only populated for
|
|
346
|
+
* the known-preset stacks, so trusting it skips the pass for third-party
|
|
347
|
+
* presets and templates - which is the only formatting those flows get, since
|
|
348
|
+
* everything before the install runs under `NX_SKIP_FORMAT`.
|
|
349
|
+
*
|
|
350
|
+
* Formats when detection cannot run: an unformatted new workspace fails its own
|
|
351
|
+
* `nx format:check`, which is worse than a spawn that finds nothing to do.
|
|
352
|
+
*/
|
|
353
|
+
function workspaceHasFormatter(directory) {
|
|
354
|
+
try {
|
|
355
|
+
// nx-ignore-next-line
|
|
356
|
+
const { detectFormatter } = require(require.resolve('nx/src/devkit-internals', {
|
|
357
|
+
paths: [directory],
|
|
358
|
+
// nx-ignore-next-line
|
|
359
|
+
})
|
|
360
|
+
// Typed locally: `detectFormatter` is new in this release, so the
|
|
361
|
+
// published nx these types resolve against does not export it.
|
|
362
|
+
);
|
|
363
|
+
return detectFormatter(directory) !== null;
|
|
364
|
+
}
|
|
365
|
+
catch {
|
|
366
|
+
return true;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export interface Choice<T extends string> {
|
|
2
|
+
value: T;
|
|
3
|
+
label?: string;
|
|
4
|
+
hint?: string;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* What a cancel resolves to. Defaults to aborting workspace creation; callers
|
|
8
|
+
* pass one when cancelling means something the flow can carry on from.
|
|
9
|
+
*/
|
|
10
|
+
export type OnCancel<T> = () => T;
|
|
11
|
+
/** A bare string is a choice whose label is its value. */
|
|
12
|
+
export type ChoiceOrValue<T extends string> = T | Choice<T>;
|
|
13
|
+
interface SelectPromptOptions<T extends string> {
|
|
14
|
+
message: string;
|
|
15
|
+
choices: readonly ChoiceOrValue<T>[];
|
|
16
|
+
/**
|
|
17
|
+
* Answer without prompting. The value is the first choice unless
|
|
18
|
+
* `skippedValue` says otherwise.
|
|
19
|
+
*/
|
|
20
|
+
skip?: boolean;
|
|
21
|
+
skippedValue?: T;
|
|
22
|
+
/** Highlighted when the prompt opens. Has no bearing on `skip`. */
|
|
23
|
+
initial?: T;
|
|
24
|
+
onCancel?: OnCancel<T>;
|
|
25
|
+
}
|
|
26
|
+
export declare function selectPrompt<T extends string>(options: SelectPromptOptions<T>): Promise<T>;
|
|
27
|
+
export declare function confirmationPrompt(options: {
|
|
28
|
+
message: string;
|
|
29
|
+
skip?: boolean;
|
|
30
|
+
/** Answer used when skipped. Defaults to yes, matching a first-choice skip. */
|
|
31
|
+
skippedValue?: boolean;
|
|
32
|
+
initial?: boolean;
|
|
33
|
+
onCancel?: OnCancel<boolean>;
|
|
34
|
+
}): Promise<boolean>;
|
|
35
|
+
export declare function textPrompt(options: {
|
|
36
|
+
message: string;
|
|
37
|
+
initialValue?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Runs synchronously; clack does not await validators.
|
|
40
|
+
*
|
|
41
|
+
* Always receives a string. clack validates on Enter *before* it coerces an
|
|
42
|
+
* empty submit to `''`, so it would otherwise hand `undefined` to a prompt
|
|
43
|
+
* declaring no `initialValue`; the wrapper below normalizes that, matching
|
|
44
|
+
* what enquirer passed.
|
|
45
|
+
*/
|
|
46
|
+
validate?: (value: string) => string | undefined;
|
|
47
|
+
skip?: boolean;
|
|
48
|
+
skippedValue?: string;
|
|
49
|
+
onCancel?: OnCancel<string>;
|
|
50
|
+
}): Promise<string>;
|
|
51
|
+
export declare function multiselectPrompt<T extends string>(options: {
|
|
52
|
+
message: string;
|
|
53
|
+
choices: readonly ChoiceOrValue<T>[];
|
|
54
|
+
required?: boolean;
|
|
55
|
+
initialValues?: readonly T[];
|
|
56
|
+
}): Promise<T[]>;
|
|
57
|
+
export {};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.selectPrompt = selectPrompt;
|
|
4
|
+
exports.confirmationPrompt = confirmationPrompt;
|
|
5
|
+
exports.textPrompt = textPrompt;
|
|
6
|
+
exports.multiselectPrompt = multiselectPrompt;
|
|
7
|
+
const error_utils_1 = require("../utils/error-utils");
|
|
8
|
+
/**
|
|
9
|
+
* `@clack/prompts` is ESM-only. A static import would compile to `require()`
|
|
10
|
+
* under CommonJS emit and throw ERR_REQUIRE_ESM; `module: nodenext` preserves
|
|
11
|
+
* this dynamic form.
|
|
12
|
+
*/
|
|
13
|
+
async function prompts() {
|
|
14
|
+
return await import('@clack/prompts');
|
|
15
|
+
}
|
|
16
|
+
function toChoice(choice) {
|
|
17
|
+
return typeof choice === 'string' ? { value: choice } : choice;
|
|
18
|
+
}
|
|
19
|
+
async function selectPrompt(options) {
|
|
20
|
+
if (options.skip) {
|
|
21
|
+
return options.skippedValue ?? toChoice(options.choices[0]).value;
|
|
22
|
+
}
|
|
23
|
+
const choices = options.choices.map(toChoice);
|
|
24
|
+
const { autocomplete, isCancel } = await prompts();
|
|
25
|
+
const answer = await autocomplete({
|
|
26
|
+
message: options.message,
|
|
27
|
+
// `Option<Value>` is conditional on `Value extends Primitive`, which
|
|
28
|
+
// TypeScript cannot resolve while `T` is still generic.
|
|
29
|
+
options: choices.map((c) => ({
|
|
30
|
+
value: c.value,
|
|
31
|
+
label: c.label ?? c.value,
|
|
32
|
+
...(c.hint ? { hint: c.hint } : {}),
|
|
33
|
+
})),
|
|
34
|
+
initialValue: options.initial ?? choices[0].value,
|
|
35
|
+
// A no-match filter leaves clack with an empty selection, and Enter then
|
|
36
|
+
// submits `undefined` rather than blocking. `isCancel` does not catch
|
|
37
|
+
// that, so downstream comparisons would silently take a wrong branch.
|
|
38
|
+
validate: (value) => value === undefined ? 'Pick one of the listed options' : undefined,
|
|
39
|
+
});
|
|
40
|
+
// Ctrl+C yields a sentinel rather than throwing.
|
|
41
|
+
if (isCancel(answer)) {
|
|
42
|
+
if (options.onCancel) {
|
|
43
|
+
return options.onCancel();
|
|
44
|
+
}
|
|
45
|
+
throw new error_utils_1.CnwError('CANCELLED', 'Cancelled.');
|
|
46
|
+
}
|
|
47
|
+
return answer;
|
|
48
|
+
}
|
|
49
|
+
async function confirmationPrompt(options) {
|
|
50
|
+
const answer = await selectPrompt({
|
|
51
|
+
message: options.message,
|
|
52
|
+
choices: [{ value: 'Yes' }, { value: 'No' }],
|
|
53
|
+
skip: options.skip,
|
|
54
|
+
skippedValue: options.skippedValue === undefined
|
|
55
|
+
? undefined
|
|
56
|
+
: options.skippedValue
|
|
57
|
+
? 'Yes'
|
|
58
|
+
: 'No',
|
|
59
|
+
initial: options.initial === false ? 'No' : 'Yes',
|
|
60
|
+
onCancel: options.onCancel
|
|
61
|
+
? () => (options.onCancel() ? 'Yes' : 'No')
|
|
62
|
+
: undefined,
|
|
63
|
+
});
|
|
64
|
+
return answer === 'Yes';
|
|
65
|
+
}
|
|
66
|
+
async function textPrompt(options) {
|
|
67
|
+
if (options.skip) {
|
|
68
|
+
return options.skippedValue ?? options.initialValue ?? '';
|
|
69
|
+
}
|
|
70
|
+
const { text, isCancel } = await prompts();
|
|
71
|
+
const answer = await text({
|
|
72
|
+
message: options.message,
|
|
73
|
+
initialValue: options.initialValue,
|
|
74
|
+
validate: options.validate
|
|
75
|
+
? (value) => options.validate(value ?? '')
|
|
76
|
+
: undefined,
|
|
77
|
+
});
|
|
78
|
+
if (isCancel(answer)) {
|
|
79
|
+
if (options.onCancel) {
|
|
80
|
+
return options.onCancel();
|
|
81
|
+
}
|
|
82
|
+
throw new error_utils_1.CnwError('CANCELLED', 'Cancelled.');
|
|
83
|
+
}
|
|
84
|
+
return answer;
|
|
85
|
+
}
|
|
86
|
+
async function multiselectPrompt(options) {
|
|
87
|
+
const choices = options.choices.map(toChoice);
|
|
88
|
+
const { multiselect, isCancel } = await prompts();
|
|
89
|
+
const answer = await multiselect({
|
|
90
|
+
message: options.message,
|
|
91
|
+
options: choices.map((c) => ({
|
|
92
|
+
value: c.value,
|
|
93
|
+
label: c.label ?? c.value,
|
|
94
|
+
...(c.hint ? { hint: c.hint } : {}),
|
|
95
|
+
})),
|
|
96
|
+
required: options.required ?? false,
|
|
97
|
+
initialValues: options.initialValues
|
|
98
|
+
? [...options.initialValues]
|
|
99
|
+
: undefined,
|
|
100
|
+
});
|
|
101
|
+
if (isCancel(answer)) {
|
|
102
|
+
throw new error_utils_1.CnwError('CANCELLED', 'Cancelled.');
|
|
103
|
+
}
|
|
104
|
+
return answer;
|
|
105
|
+
}
|
|
@@ -55,3 +55,9 @@ export declare function determineLinterOptions(args: {
|
|
|
55
55
|
linter?: Linter;
|
|
56
56
|
interactive?: boolean;
|
|
57
57
|
}): Promise<Linter>;
|
|
58
|
+
export type Formatter = 'oxfmt' | 'prettier' | 'none';
|
|
59
|
+
export declare const FORMATTERS: readonly ["oxfmt", "prettier", "none"];
|
|
60
|
+
export declare function determineFormatterOptions(args: {
|
|
61
|
+
formatter?: Formatter;
|
|
62
|
+
interactive?: boolean;
|
|
63
|
+
}): Promise<Formatter>;
|