@depup/nestjs__cli 11.0.24-depup.8 → 12.0.0-depup.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/README.md +6 -14
- package/actions/abstract.action.d.ts +1 -2
- package/actions/abstract.action.js +1 -5
- package/actions/add.action.d.ts +3 -4
- package/actions/add.action.js +44 -53
- package/actions/build.action.d.ts +18 -11
- package/actions/build.action.js +172 -79
- package/actions/deploy.action.d.ts +6 -0
- package/actions/deploy.action.js +51 -0
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +61 -59
- package/actions/index.d.ts +9 -7
- package/actions/index.js +9 -23
- package/actions/info.action.d.ts +18 -28
- package/actions/info.action.js +80 -60
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +108 -104
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +40 -47
- package/actions/upgrade.action.d.ts +6 -0
- package/actions/upgrade.action.js +53 -0
- package/bin/nest.js +11 -10
- package/changes.json +6 -38
- package/commands/abstract.command.d.ts +3 -3
- package/commands/abstract.command.js +2 -5
- package/commands/add.command.d.ts +3 -3
- package/commands/add.command.js +17 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +52 -56
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +29 -22
- package/commands/context/add.context.d.ts +7 -0
- package/commands/context/add.context.js +1 -0
- package/commands/context/build.context.d.ts +17 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/deploy.context.d.ts +7 -0
- package/commands/context/deploy.context.js +1 -0
- package/commands/context/generate.context.d.ts +18 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +7 -0
- package/commands/context/index.js +7 -0
- package/commands/context/new.context.d.ts +19 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +22 -0
- package/commands/context/start.context.js +1 -0
- package/commands/context/upgrade.context.d.ts +11 -0
- package/commands/context/upgrade.context.js +1 -0
- package/commands/deploy.command.d.ts +5 -0
- package/commands/deploy.command.js +22 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +35 -66
- package/commands/index.d.ts +3 -2
- package/commands/index.js +3 -18
- package/commands/info.command.d.ts +3 -3
- package/commands/info.command.js +4 -8
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +34 -36
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +48 -73
- package/commands/upgrade.command.d.ts +5 -0
- package/commands/upgrade.command.js +32 -0
- package/lib/compiler/assets-manager.d.ts +20 -8
- package/lib/compiler/assets-manager.js +199 -63
- package/lib/compiler/base-compiler.d.ts +5 -5
- package/lib/compiler/base-compiler.js +10 -13
- package/lib/compiler/compiler.d.ts +6 -6
- package/lib/compiler/compiler.js +7 -9
- package/lib/compiler/defaults/rspack-defaults.d.ts +3 -0
- package/lib/compiler/defaults/rspack-defaults.js +179 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +5 -2
- package/lib/compiler/defaults/swc-defaults.js +22 -6
- package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
- package/lib/compiler/defaults/webpack-defaults.js +59 -19
- package/lib/compiler/helpers/append-extension.js +3 -6
- package/lib/compiler/helpers/copy-path-resolve.js +2 -5
- package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
- package/lib/compiler/helpers/delete-out-dir.js +45 -10
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-effective-root-dir.d.ts +16 -0
- package/lib/compiler/helpers/get-effective-root-dir.js +56 -0
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +10 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +19 -0
- package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
- package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
- package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
- package/lib/compiler/helpers/get-value-or-default.js +3 -8
- package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
- package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
- package/lib/compiler/helpers/glob.d.ts +19 -0
- package/lib/compiler/helpers/glob.js +185 -0
- package/lib/compiler/helpers/manual-restart.js +4 -8
- package/lib/compiler/helpers/path-confinement.d.ts +33 -0
- package/lib/compiler/helpers/path-confinement.js +63 -0
- package/lib/compiler/helpers/tsconfig-provider.d.ts +7 -6
- package/lib/compiler/helpers/tsconfig-provider.js +32 -13
- package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
- package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
- package/lib/compiler/plugins/plugin-metadata-generator.d.ts +37 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +113 -13
- package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
- package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
- package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
- package/lib/compiler/plugins/plugins-loader.js +12 -12
- package/lib/compiler/rspack-compiler.d.ts +21 -0
- package/lib/compiler/rspack-compiler.js +111 -0
- package/lib/compiler/swc/constants.d.ts +0 -1
- package/lib/compiler/swc/constants.js +9 -13
- package/lib/compiler/swc/forked-type-checker.js +13 -18
- package/lib/compiler/swc/swc-compiler.d.ts +13 -6
- package/lib/compiler/swc/swc-compiler.js +116 -70
- package/lib/compiler/swc/type-checker-host.js +31 -24
- package/lib/compiler/typescript-loader.js +7 -9
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +13 -15
- package/lib/compiler/watchers/recursive-directory-watcher.d.ts +37 -0
- package/lib/compiler/watchers/recursive-directory-watcher.js +334 -0
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +46 -23
- package/lib/configuration/configuration.d.ts +16 -3
- package/lib/configuration/configuration.js +1 -2
- package/lib/configuration/configuration.loader.d.ts +1 -1
- package/lib/configuration/configuration.loader.js +1 -2
- package/lib/configuration/defaults.d.ts +2 -1
- package/lib/configuration/defaults.js +8 -10
- package/lib/configuration/index.d.ts +3 -3
- package/lib/configuration/index.js +3 -19
- package/lib/configuration/nest-configuration.loader.d.ts +3 -3
- package/lib/configuration/nest-configuration.loader.js +28 -29
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +21 -32
- package/lib/package-managers/bun.package-manager.d.ts +7 -0
- package/lib/package-managers/bun.package-manager.js +22 -0
- package/lib/package-managers/index.d.ts +9 -8
- package/lib/package-managers/index.js +9 -24
- package/lib/package-managers/npm.package-manager.d.ts +2 -2
- package/lib/package-managers/npm.package-manager.js +6 -10
- package/lib/package-managers/package-manager-commands.js +1 -2
- package/lib/package-managers/package-manager.d.ts +2 -1
- package/lib/package-managers/package-manager.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +23 -20
- package/lib/package-managers/package-manager.js +3 -5
- package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
- package/lib/package-managers/pnpm.package-manager.js +6 -10
- package/lib/package-managers/project.dependency.js +1 -2
- package/lib/package-managers/yarn.package-manager.d.ts +2 -2
- package/lib/package-managers/yarn.package-manager.js +6 -10
- package/lib/questions/questions.d.ts +5 -1
- package/lib/questions/questions.js +2 -7
- package/lib/readers/file-system.reader.d.ts +1 -1
- package/lib/readers/file-system.reader.js +6 -9
- package/lib/readers/index.d.ts +2 -2
- package/lib/readers/index.js +2 -18
- package/lib/readers/reader.js +3 -5
- package/lib/runners/abstract.runner.js +40 -21
- package/lib/runners/bun.runner.d.ts +4 -0
- package/lib/runners/bun.runner.js +6 -0
- package/lib/runners/git.runner.d.ts +1 -1
- package/lib/runners/git.runner.js +2 -6
- package/lib/runners/index.d.ts +3 -3
- package/lib/runners/index.js +3 -19
- package/lib/runners/mau.runner.d.ts +8 -0
- package/lib/runners/mau.runner.js +10 -0
- package/lib/runners/npm.runner.d.ts +1 -1
- package/lib/runners/npm.runner.js +2 -6
- package/lib/runners/pnpm.runner.d.ts +1 -1
- package/lib/runners/pnpm.runner.js +2 -6
- package/lib/runners/runner.d.ts +2 -1
- package/lib/runners/runner.factory.d.ts +7 -6
- package/lib/runners/runner.factory.js +18 -20
- package/lib/runners/runner.js +3 -5
- package/lib/runners/schematic.runner.d.ts +1 -1
- package/lib/runners/schematic.runner.js +5 -7
- package/lib/runners/yarn.runner.d.ts +1 -1
- package/lib/runners/yarn.runner.js +2 -6
- package/lib/schematics/abstract.collection.d.ts +3 -3
- package/lib/schematics/abstract.collection.js +3 -5
- package/lib/schematics/collection.factory.d.ts +2 -2
- package/lib/schematics/collection.factory.js +9 -13
- package/lib/schematics/collection.js +2 -5
- package/lib/schematics/custom.collection.d.ts +2 -2
- package/lib/schematics/custom.collection.js +4 -8
- package/lib/schematics/index.d.ts +4 -4
- package/lib/schematics/index.js +4 -20
- package/lib/schematics/nest.collection.d.ts +3 -3
- package/lib/schematics/nest.collection.js +113 -109
- package/lib/schematics/schematic.option.js +10 -9
- package/lib/ui/banner.js +1 -4
- package/lib/ui/emojis.d.ts +17 -17
- package/lib/ui/emojis.js +19 -22
- package/lib/ui/errors.js +1 -4
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.d.ts +8 -0
- package/lib/ui/messages.js +23 -18
- package/lib/ui/prefixes.js +3 -6
- package/lib/utils/extra-args-warning.js +3 -6
- package/lib/utils/formatting.js +1 -4
- package/lib/utils/get-default-tsconfig-path.js +4 -7
- package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
- package/lib/utils/is-esm-project.d.ts +5 -0
- package/lib/utils/is-esm-project.js +16 -0
- package/lib/utils/is-interactive.d.ts +8 -0
- package/lib/utils/is-interactive.js +10 -0
- package/lib/utils/is-module-available.js +3 -4
- package/lib/utils/load-configuration.d.ts +1 -1
- package/lib/utils/load-configuration.js +4 -7
- package/lib/utils/local-binaries.d.ts +2 -2
- package/lib/utils/local-binaries.js +8 -11
- package/lib/utils/mau.d.ts +14 -0
- package/lib/utils/mau.js +46 -0
- package/lib/utils/os-info.utils.js +1 -4
- package/lib/utils/project-utils.d.ts +1 -3
- package/lib/utils/project-utils.js +16 -28
- package/lib/utils/remaining-flags.d.ts +2 -2
- package/lib/utils/remaining-flags.js +13 -8
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +64 -77
package/actions/new.action.js
CHANGED
|
@@ -1,36 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const isDryRunEnabled = dryRunOption && dryRunOption.value;
|
|
24
|
-
await askForMissingInformation(inputs, options);
|
|
25
|
-
await generateApplicationFiles(inputs, options).catch(exports.exit);
|
|
26
|
-
const shouldSkipInstall = options.some((option) => option.name === 'skip-install' && option.value === true);
|
|
27
|
-
const shouldSkipGit = options.some((option) => option.name === 'skip-git' && option.value === true);
|
|
28
|
-
const projectDirectory = getProjectDirectory(getApplicationNameInput(inputs), directoryOption);
|
|
29
|
-
if (!shouldSkipInstall) {
|
|
30
|
-
await installPackages(options, isDryRunEnabled, projectDirectory);
|
|
1
|
+
import { confirm, input, select } from '@inquirer/prompts';
|
|
2
|
+
import ansis from 'ansis';
|
|
3
|
+
import { execSync } from 'child_process';
|
|
4
|
+
import * as fs from 'fs';
|
|
5
|
+
import { join } from 'path';
|
|
6
|
+
import { defaultGitIgnore } from '../lib/configuration/defaults.js';
|
|
7
|
+
import { PackageManager, PackageManagerFactory, } from '../lib/package-managers/index.js';
|
|
8
|
+
import { generateInput, generateSelect } from '../lib/questions/questions.js';
|
|
9
|
+
import { GitRunner } from '../lib/runners/git.runner.js';
|
|
10
|
+
import { Collection, CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
11
|
+
import { EMOJIS, MESSAGES } from '../lib/ui/index.js';
|
|
12
|
+
import { normalizeToKebabOrSnakeCase } from '../lib/utils/formatting.js';
|
|
13
|
+
import { gracefullyExitOnPromptError } from '../lib/utils/gracefully-exit-on-prompt-error.js';
|
|
14
|
+
import { isInteractive } from '../lib/utils/is-interactive.js';
|
|
15
|
+
import { AbstractAction } from './abstract.action.js';
|
|
16
|
+
export class NewAction extends AbstractAction {
|
|
17
|
+
async handle(context) {
|
|
18
|
+
await askForMissingInformation(context);
|
|
19
|
+
await generateApplicationFiles(context).catch(exit);
|
|
20
|
+
const projectDirectory = getProjectDirectory(context);
|
|
21
|
+
if (!context.skipInstall) {
|
|
22
|
+
await installPackages(context, projectDirectory);
|
|
31
23
|
}
|
|
32
|
-
if (!
|
|
33
|
-
if (!
|
|
24
|
+
if (!context.dryRun) {
|
|
25
|
+
if (!context.skipGit) {
|
|
34
26
|
await initializeGitRepository(projectDirectory);
|
|
35
27
|
await createGitIgnoreFile(projectDirectory);
|
|
36
28
|
}
|
|
@@ -39,81 +31,98 @@ class NewAction extends abstract_action_1.AbstractAction {
|
|
|
39
31
|
process.exit(0);
|
|
40
32
|
}
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const getPackageManagerInput = (inputs) => inputs.find((options) => options.name === 'packageManager');
|
|
45
|
-
const getProjectDirectory = (applicationName, directoryOption) => {
|
|
46
|
-
return ((directoryOption && directoryOption.value) ||
|
|
47
|
-
(0, formatting_1.normalizeToKebabOrSnakeCase)(applicationName.value));
|
|
34
|
+
const getProjectDirectory = (context) => {
|
|
35
|
+
return (context.directory || normalizeToKebabOrSnakeCase(context.name));
|
|
48
36
|
};
|
|
49
|
-
const askForMissingInformation = async (
|
|
50
|
-
console.info(
|
|
37
|
+
const askForMissingInformation = async (context) => {
|
|
38
|
+
console.info(MESSAGES.PROJECT_INFORMATION_START);
|
|
51
39
|
console.info();
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
const answer = await (0, prompts_1.input)(question).catch(gracefully_exit_on_prompt_error_1.gracefullyExitOnPromptError);
|
|
57
|
-
replaceInputMissingInformation(inputs, { name: 'name', value: answer });
|
|
40
|
+
if (!context.name) {
|
|
41
|
+
const message = MESSAGES.PROJECT_NAME_QUESTION;
|
|
42
|
+
const question = generateInput('name', message)('nest-app');
|
|
43
|
+
context.name = (await input(question).catch(gracefullyExitOnPromptError));
|
|
58
44
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
const answer = await askForPackageManager();
|
|
62
|
-
replaceInputMissingInformation(options, {
|
|
63
|
-
name: 'packageManager',
|
|
64
|
-
value: answer,
|
|
65
|
-
});
|
|
45
|
+
if (!context.packageManager) {
|
|
46
|
+
context.packageManager = (await askForPackageManager());
|
|
66
47
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const input = inputs.find((input) => input.name === answer.name);
|
|
70
|
-
if (input) {
|
|
71
|
-
input.value = input.value !== undefined ? input.value : answer.value;
|
|
48
|
+
if (context.observe === undefined) {
|
|
49
|
+
context.observe = await askForObservability();
|
|
72
50
|
}
|
|
73
51
|
};
|
|
74
|
-
const generateApplicationFiles = async (
|
|
75
|
-
const
|
|
76
|
-
const
|
|
77
|
-
const schematicOptions = mapSchematicOptions(args.concat(options));
|
|
52
|
+
const generateApplicationFiles = async (context) => {
|
|
53
|
+
const collection = CollectionFactory.create(context.collection || Collection.NESTJS);
|
|
54
|
+
const schematicOptions = mapContextToSchematicOptions(context);
|
|
78
55
|
await collection.execute('application', schematicOptions);
|
|
79
56
|
console.info();
|
|
80
57
|
};
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
58
|
+
const mapContextToSchematicOptions = (context) => {
|
|
59
|
+
const options = [];
|
|
60
|
+
if (context.name !== undefined)
|
|
61
|
+
options.push(new SchematicOption('name', context.name));
|
|
62
|
+
if (context.directory !== undefined)
|
|
63
|
+
options.push(new SchematicOption('directory', context.directory));
|
|
64
|
+
if (context.dryRun)
|
|
65
|
+
options.push(new SchematicOption('dry-run', true));
|
|
66
|
+
options.push(new SchematicOption('skip-git', context.skipGit));
|
|
67
|
+
options.push(new SchematicOption('strict', context.strict));
|
|
68
|
+
if (context.skipTests) {
|
|
69
|
+
options.push(new SchematicOption('spec', false));
|
|
70
|
+
}
|
|
71
|
+
if (context.packageManager !== undefined)
|
|
72
|
+
options.push(new SchematicOption('packageManager', context.packageManager));
|
|
73
|
+
if (context.collection !== undefined)
|
|
74
|
+
options.push(new SchematicOption('collection', context.collection));
|
|
75
|
+
options.push(new SchematicOption('language', context.language));
|
|
76
|
+
options.push(new SchematicOption('format', context.format));
|
|
77
|
+
if (context.observe) {
|
|
78
|
+
options.push(new SchematicOption('observe', true));
|
|
79
|
+
}
|
|
80
|
+
// note: skip-install is intentionally excluded — not sent to schematics
|
|
81
|
+
return options;
|
|
89
82
|
};
|
|
90
|
-
const installPackages = async (
|
|
91
|
-
const inputPackageManager =
|
|
83
|
+
const installPackages = async (context, installDirectory) => {
|
|
84
|
+
const inputPackageManager = context.packageManager;
|
|
92
85
|
let packageManager;
|
|
93
|
-
if (
|
|
86
|
+
if (context.dryRun) {
|
|
94
87
|
console.info();
|
|
95
|
-
console.info(ansis.green(
|
|
88
|
+
console.info(ansis.green(MESSAGES.DRY_RUN_MODE));
|
|
96
89
|
console.info();
|
|
97
90
|
return;
|
|
98
91
|
}
|
|
99
92
|
try {
|
|
100
|
-
packageManager =
|
|
93
|
+
packageManager = PackageManagerFactory.create(inputPackageManager);
|
|
101
94
|
await packageManager.install(installDirectory, inputPackageManager);
|
|
102
95
|
}
|
|
103
96
|
catch (error) {
|
|
104
|
-
if (error
|
|
97
|
+
if (error instanceof Error) {
|
|
105
98
|
console.error(ansis.red(error.message));
|
|
106
99
|
}
|
|
107
100
|
}
|
|
108
101
|
};
|
|
102
|
+
const askForObservability = async () => {
|
|
103
|
+
// Without a TTY (CI, piped input, `execSync`) there is nobody to answer, so
|
|
104
|
+
// fall back to the opt-out default instead of blocking the scaffold.
|
|
105
|
+
if (!isInteractive()) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
return (await confirm({
|
|
109
|
+
message: MESSAGES.OBSERVABILITY_QUESTION,
|
|
110
|
+
default: false,
|
|
111
|
+
}).catch(gracefullyExitOnPromptError));
|
|
112
|
+
};
|
|
109
113
|
const askForPackageManager = async () => {
|
|
110
|
-
const question =
|
|
111
|
-
|
|
114
|
+
const question = generateSelect('packageManager')(MESSAGES.PACKAGE_MANAGER_QUESTION)([
|
|
115
|
+
PackageManager.NPM,
|
|
116
|
+
PackageManager.YARN,
|
|
117
|
+
PackageManager.PNPM,
|
|
118
|
+
PackageManager.BUN,
|
|
119
|
+
]);
|
|
120
|
+
return select(question).catch(gracefullyExitOnPromptError);
|
|
112
121
|
};
|
|
113
122
|
const initializeGitRepository = async (dir) => {
|
|
114
|
-
const runner = new
|
|
115
|
-
await runner.run('init', true,
|
|
116
|
-
console.error(ansis.red(
|
|
123
|
+
const runner = new GitRunner();
|
|
124
|
+
await runner.run('init', true, join(process.cwd(), dir)).catch(() => {
|
|
125
|
+
console.error(ansis.red(MESSAGES.GIT_INITIALIZATION_ERROR));
|
|
117
126
|
});
|
|
118
127
|
};
|
|
119
128
|
/**
|
|
@@ -127,8 +136,8 @@ const initializeGitRepository = async (dir) => {
|
|
|
127
136
|
* @return Resolves when succeeds, or rejects with any error from `fn.writeFile`.
|
|
128
137
|
*/
|
|
129
138
|
const createGitIgnoreFile = (dir, content) => {
|
|
130
|
-
const fileContent = content ||
|
|
131
|
-
const filePath =
|
|
139
|
+
const fileContent = content || defaultGitIgnore;
|
|
140
|
+
const filePath = join(process.cwd(), dir, '.gitignore');
|
|
132
141
|
if (fileExists(filePath)) {
|
|
133
142
|
return;
|
|
134
143
|
}
|
|
@@ -139,17 +148,18 @@ const printCollective = () => {
|
|
|
139
148
|
const yellow = print('yellow');
|
|
140
149
|
const emptyLine = print();
|
|
141
150
|
emptyLine();
|
|
142
|
-
yellow(`Thanks for installing Nest ${
|
|
151
|
+
yellow(`Thanks for installing Nest ${EMOJIS.PRAY}`);
|
|
143
152
|
dim('Please consider donating to our open collective');
|
|
144
153
|
dim('to help us maintain this package.');
|
|
145
154
|
emptyLine();
|
|
146
155
|
emptyLine();
|
|
147
|
-
print()(`${ansis.bold `${
|
|
156
|
+
print()(`${ansis.bold `${EMOJIS.WINE} Donate:`} ${ansis.underline('https://opencollective.com/nest')}`);
|
|
148
157
|
emptyLine();
|
|
149
158
|
};
|
|
150
159
|
const print = (color = null) => (str = '') => {
|
|
151
|
-
const terminalCols =
|
|
152
|
-
|
|
160
|
+
const terminalCols = retrieveCols();
|
|
161
|
+
// eslint-disable-next-line no-control-regex
|
|
162
|
+
const strLength = str.replace(/\x1b\[[0-9]+m/g, '').length;
|
|
153
163
|
const leftPaddingLength = Math.floor((terminalCols - strLength) / 2);
|
|
154
164
|
const leftPadding = ' '.repeat(Math.max(leftPaddingLength, 0));
|
|
155
165
|
if (color) {
|
|
@@ -157,10 +167,17 @@ const print = (color = null) => (str = '') => {
|
|
|
157
167
|
}
|
|
158
168
|
console.log(leftPadding, str);
|
|
159
169
|
};
|
|
160
|
-
const retrieveCols = () => {
|
|
170
|
+
export const retrieveCols = () => {
|
|
161
171
|
const defaultCols = 80;
|
|
172
|
+
// Prefer process.stdout.columns: it works on every platform (including
|
|
173
|
+
// Windows, where `tput` is not available by default) and reflects the
|
|
174
|
+
// actual terminal size instead of always falling back to the default.
|
|
175
|
+
const stdoutCols = process.stdout.columns;
|
|
176
|
+
if (typeof stdoutCols === 'number' && stdoutCols > 0) {
|
|
177
|
+
return stdoutCols;
|
|
178
|
+
}
|
|
162
179
|
try {
|
|
163
|
-
const terminalCols =
|
|
180
|
+
const terminalCols = execSync('tput cols', {
|
|
164
181
|
stdio: ['pipe', 'pipe', 'ignore'],
|
|
165
182
|
});
|
|
166
183
|
return parseInt(terminalCols.toString(), 10) || defaultCols;
|
|
@@ -169,18 +186,5 @@ const retrieveCols = () => {
|
|
|
169
186
|
return defaultCols;
|
|
170
187
|
}
|
|
171
188
|
};
|
|
172
|
-
|
|
173
|
-
const
|
|
174
|
-
try {
|
|
175
|
-
fs.accessSync(path);
|
|
176
|
-
return true;
|
|
177
|
-
}
|
|
178
|
-
catch (err) {
|
|
179
|
-
if (err.code === 'ENOENT') {
|
|
180
|
-
return false;
|
|
181
|
-
}
|
|
182
|
-
throw err;
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
const exit = () => process.exit(1);
|
|
186
|
-
exports.exit = exit;
|
|
189
|
+
const fileExists = (path) => fs.existsSync(path);
|
|
190
|
+
export const exit = () => process.exit(1);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { BuildAction } from './build.action';
|
|
1
|
+
import { StartCommandContext } from '../commands/index.js';
|
|
2
|
+
import { BuildAction } from './build.action.js';
|
|
3
3
|
export declare class StartAction extends BuildAction {
|
|
4
|
-
handle(
|
|
5
|
-
createOnSuccessHook
|
|
6
|
-
shell: boolean;
|
|
7
|
-
envFile?: string[];
|
|
8
|
-
}): () => void;
|
|
4
|
+
handle(context: StartCommandContext): Promise<void>;
|
|
5
|
+
private createOnSuccessHook;
|
|
9
6
|
private spawnChildProcess;
|
|
10
7
|
}
|
package/actions/start.action.js
CHANGED
|
@@ -1,60 +1,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const build_action_1 = require("./build.action");
|
|
15
|
-
class StartAction extends build_action_1.BuildAction {
|
|
16
|
-
async handle(commandInputs, commandOptions) {
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import { spawn } from 'child_process';
|
|
3
|
+
import * as fs from 'fs';
|
|
4
|
+
import { join } from 'path';
|
|
5
|
+
import { getTscConfigPath } from '../lib/compiler/helpers/get-tsc-config.path.js';
|
|
6
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
7
|
+
import { defaultConfiguration, defaultOutDir, } from '../lib/configuration/defaults.js';
|
|
8
|
+
import { ERROR_PREFIX } from '../lib/ui/index.js';
|
|
9
|
+
import { treeKillSync as killProcessSync } from '../lib/utils/tree-kill.js';
|
|
10
|
+
import { assertNonArray } from '../lib/utils/type-assertions.js';
|
|
11
|
+
import { BuildAction } from './build.action.js';
|
|
12
|
+
export class StartAction extends BuildAction {
|
|
13
|
+
async handle(context) {
|
|
17
14
|
try {
|
|
18
|
-
const configFileName =
|
|
15
|
+
const configFileName = context.config;
|
|
19
16
|
const configuration = await this.loader.load(configFileName);
|
|
20
|
-
const appName =
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
const isWatchAssetsEnabled = !!(watchAssetsModeOption && watchAssetsModeOption.value);
|
|
28
|
-
const debugFlag = debugModeOption && debugModeOption.value;
|
|
29
|
-
(0, type_assertions_1.assertNonArray)(debugFlag);
|
|
30
|
-
const binaryToRun = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'exec', appName, 'exec', commandOptions, defaults_1.defaultConfiguration.exec);
|
|
17
|
+
const appName = context.app;
|
|
18
|
+
const pathToTsconfig = getTscConfigPath(configuration, context, appName);
|
|
19
|
+
const isWatchEnabled = !!context.watch;
|
|
20
|
+
const isWatchAssetsEnabled = !!context.watchAssets;
|
|
21
|
+
const debugFlag = context.debug;
|
|
22
|
+
assertNonArray(debugFlag);
|
|
23
|
+
const binaryToRun = getValueOrDefault(configuration, 'exec', appName, 'exec', context, defaultConfiguration.exec);
|
|
31
24
|
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
|
|
32
|
-
const outDir = tsOptions.outDir ||
|
|
33
|
-
const entryFile =
|
|
34
|
-
const sourceRoot =
|
|
35
|
-
const
|
|
36
|
-
const
|
|
37
|
-
const envFileOption = commandOptions.find((option) => option.name === 'envFile');
|
|
38
|
-
const envFile = (envFileOption?.value ?? []);
|
|
25
|
+
const outDir = tsOptions.outDir || defaultOutDir;
|
|
26
|
+
const entryFile = getValueOrDefault(configuration, 'entryFile', appName, 'entryFile', context, defaultConfiguration.entryFile);
|
|
27
|
+
const sourceRoot = getValueOrDefault(configuration, 'sourceRoot', appName, 'sourceRoot', context, defaultConfiguration.sourceRoot);
|
|
28
|
+
const useShell = !!context.shell;
|
|
29
|
+
const envFile = context.envFile ?? [];
|
|
39
30
|
const onSuccess = this.createOnSuccessHook(entryFile, sourceRoot, debugFlag, outDir, binaryToRun, {
|
|
40
31
|
shell: useShell,
|
|
41
32
|
envFile,
|
|
42
33
|
});
|
|
43
|
-
await this.runBuild(
|
|
34
|
+
await this.runBuild(appName ? [appName] : [], context, isWatchEnabled, isWatchAssetsEnabled, !!debugFlag, onSuccess);
|
|
44
35
|
}
|
|
45
36
|
catch (err) {
|
|
46
37
|
if (err instanceof Error) {
|
|
47
|
-
console.
|
|
38
|
+
console.error(`\n${ERROR_PREFIX} ${err.message}\n`);
|
|
48
39
|
}
|
|
49
40
|
else {
|
|
50
|
-
console.error(`\n${
|
|
41
|
+
console.error(`\n${red(err)}\n`);
|
|
51
42
|
}
|
|
43
|
+
// A failed build (e.g. SWC type-check errors, which now reject instead of
|
|
44
|
+
// exiting the process themselves) must not report success to the caller.
|
|
45
|
+
process.exit(1);
|
|
52
46
|
}
|
|
53
47
|
}
|
|
54
48
|
createOnSuccessHook(entryFile, sourceRoot, debugFlag, outDirName, binaryToRun, options) {
|
|
55
49
|
let childProcessRef;
|
|
56
50
|
let shuttingDown = false;
|
|
57
|
-
process.on('exit', () => childProcessRef && (
|
|
51
|
+
process.on('exit', () => childProcessRef && killProcessSync(childProcessRef.pid));
|
|
58
52
|
const signalHandler = (signal) => {
|
|
59
53
|
shuttingDown = true;
|
|
60
54
|
if (childProcessRef) {
|
|
@@ -88,8 +82,8 @@ class StartAction extends build_action_1.BuildAction {
|
|
|
88
82
|
}
|
|
89
83
|
});
|
|
90
84
|
});
|
|
91
|
-
childProcessRef.stdin
|
|
92
|
-
(
|
|
85
|
+
childProcessRef.stdin?.pause?.();
|
|
86
|
+
killProcessSync(childProcessRef.pid);
|
|
93
87
|
}
|
|
94
88
|
else {
|
|
95
89
|
childProcessRef = this.spawnChildProcess(entryFile, sourceRoot, debugFlag, outDirName, binaryToRun, {
|
|
@@ -110,9 +104,9 @@ class StartAction extends build_action_1.BuildAction {
|
|
|
110
104
|
};
|
|
111
105
|
}
|
|
112
106
|
spawnChildProcess(entryFile, sourceRoot, debug, outDirName, binaryToRun, options) {
|
|
113
|
-
let outputFilePath =
|
|
107
|
+
let outputFilePath = join(outDirName, sourceRoot, entryFile);
|
|
114
108
|
if (!fs.existsSync(outputFilePath + '.js')) {
|
|
115
|
-
outputFilePath =
|
|
109
|
+
outputFilePath = join(outDirName, entryFile);
|
|
116
110
|
}
|
|
117
111
|
let childProcessArgs = [];
|
|
118
112
|
const argsStartIndex = process.argv.indexOf('--');
|
|
@@ -135,7 +129,7 @@ class StartAction extends build_action_1.BuildAction {
|
|
|
135
129
|
}
|
|
136
130
|
if (options.envFile && options.envFile.length > 0) {
|
|
137
131
|
const envFileNodeArgs = options.envFile.map((envFilePath) => `--env-file=${envFilePath}`);
|
|
138
|
-
processArgs.unshift(envFileNodeArgs
|
|
132
|
+
processArgs.unshift(...envFileNodeArgs);
|
|
139
133
|
}
|
|
140
134
|
processArgs.unshift('--enable-source-maps');
|
|
141
135
|
const spawnOptions = {
|
|
@@ -144,9 +138,8 @@ class StartAction extends build_action_1.BuildAction {
|
|
|
144
138
|
};
|
|
145
139
|
if (options.shell) {
|
|
146
140
|
const command = [binaryToRun, ...processArgs].join(' ');
|
|
147
|
-
return
|
|
141
|
+
return spawn(command, spawnOptions);
|
|
148
142
|
}
|
|
149
|
-
return
|
|
143
|
+
return spawn(binaryToRun, processArgs, spawnOptions);
|
|
150
144
|
}
|
|
151
145
|
}
|
|
152
|
-
exports.StartAction = StartAction;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { UpgradeCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
|
+
export declare class UpgradeAction extends AbstractAction {
|
|
4
|
+
handle(context: UpgradeCommandContext): Promise<void>;
|
|
5
|
+
private mapSchematicOptions;
|
|
6
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { green, red } from 'ansis';
|
|
2
|
+
import { Collection, CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
3
|
+
import { INFO_PREFIX, MESSAGES } from '../lib/ui/index.js';
|
|
4
|
+
import { isInteractive } from '../lib/utils/is-interactive.js';
|
|
5
|
+
import { loadConfiguration } from '../lib/utils/load-configuration.js';
|
|
6
|
+
import { AbstractAction } from './abstract.action.js';
|
|
7
|
+
const schematicName = 'upgrade';
|
|
8
|
+
export class UpgradeAction extends AbstractAction {
|
|
9
|
+
async handle(context) {
|
|
10
|
+
const configuration = await loadConfiguration();
|
|
11
|
+
const collectionName = context.collection || configuration.collection || Collection.NESTJS;
|
|
12
|
+
const schematicOptions = this.mapSchematicOptions(context);
|
|
13
|
+
console.info(MESSAGES.UPGRADE_IN_PROGRESS);
|
|
14
|
+
try {
|
|
15
|
+
const collection = CollectionFactory.create(collectionName);
|
|
16
|
+
await collection.execute(schematicName, schematicOptions);
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (error instanceof Error) {
|
|
20
|
+
console.error(red(error.message));
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
if (context.dryRun) {
|
|
25
|
+
console.info();
|
|
26
|
+
console.info(green(MESSAGES.DRY_RUN_MODE));
|
|
27
|
+
console.info();
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
// The schematic only bumps the project's local @nestjs/cli.
|
|
31
|
+
console.info(`\n${INFO_PREFIX} ${MESSAGES.UPGRADE_GLOBAL_CLI_HINT}\n`);
|
|
32
|
+
}
|
|
33
|
+
mapSchematicOptions(context) {
|
|
34
|
+
const options = [];
|
|
35
|
+
if (context.dryRun)
|
|
36
|
+
options.push(new SchematicOption('dry-run', true));
|
|
37
|
+
if (context.skipInstall) {
|
|
38
|
+
options.push(new SchematicOption('skip-install', true));
|
|
39
|
+
}
|
|
40
|
+
if (context.tag !== undefined) {
|
|
41
|
+
options.push(new SchematicOption('tag', context.tag));
|
|
42
|
+
}
|
|
43
|
+
if (context.observe !== undefined) {
|
|
44
|
+
options.push(new SchematicOption('observe', context.observe));
|
|
45
|
+
}
|
|
46
|
+
else if (!isInteractive()) {
|
|
47
|
+
// The schematic's `x-prompt` would block forever without a TTY (CI,
|
|
48
|
+
// pipes), so answer it up front and leave prompting to TTY sessions.
|
|
49
|
+
options.push(new SchematicOption('observe', false));
|
|
50
|
+
}
|
|
51
|
+
return options;
|
|
52
|
+
}
|
|
53
|
+
}
|
package/bin/nest.js
CHANGED
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
2
|
+
import { Command } from 'commander';
|
|
3
|
+
import { createRequire } from 'module';
|
|
4
|
+
import { CommandLoader } from '../commands/index.js';
|
|
5
|
+
import { loadLocalBinCommandLoader, localBinExists, } from '../lib/utils/local-binaries.js';
|
|
6
|
+
const require = createRequire(import.meta.url);
|
|
7
7
|
const bootstrap = async () => {
|
|
8
|
-
const program =
|
|
8
|
+
const program = new Command();
|
|
9
|
+
program.__nestCliEsm = true;
|
|
9
10
|
program
|
|
10
11
|
.version(require('../package.json').version, '-v, --version', 'Output the current version.')
|
|
11
12
|
.usage('<command> [options]')
|
|
12
13
|
.helpOption('-h, --help', 'Output usage information.');
|
|
13
|
-
if (
|
|
14
|
-
const localCommandLoader =
|
|
14
|
+
if (localBinExists()) {
|
|
15
|
+
const localCommandLoader = await loadLocalBinCommandLoader();
|
|
15
16
|
await localCommandLoader.load(program);
|
|
16
17
|
}
|
|
17
18
|
else {
|
|
18
|
-
await
|
|
19
|
+
await CommandLoader.load(program);
|
|
19
20
|
}
|
|
20
|
-
await
|
|
21
|
+
await program.parseAsync(process.argv);
|
|
21
22
|
if (!process.argv.slice(2).length) {
|
|
22
23
|
program.outputHelp();
|
|
23
24
|
}
|
package/changes.json
CHANGED
|
@@ -1,54 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bumped": {
|
|
3
3
|
"@angular-devkit/core": {
|
|
4
|
-
"from": "
|
|
4
|
+
"from": "22.1.5",
|
|
5
5
|
"to": "^22.1.6"
|
|
6
6
|
},
|
|
7
7
|
"@angular-devkit/schematics": {
|
|
8
|
-
"from": "
|
|
8
|
+
"from": "22.1.5",
|
|
9
9
|
"to": "^22.1.6"
|
|
10
10
|
},
|
|
11
11
|
"@angular-devkit/schematics-cli": {
|
|
12
|
-
"from": "
|
|
12
|
+
"from": "22.1.5",
|
|
13
13
|
"to": "^22.1.6"
|
|
14
14
|
},
|
|
15
|
-
"@inquirer/prompts": {
|
|
16
|
-
"from": "7.10.1",
|
|
17
|
-
"to": "^8.7.0"
|
|
18
|
-
},
|
|
19
|
-
"@nestjs/schematics": {
|
|
20
|
-
"from": "^11.0.1",
|
|
21
|
-
"to": "^11.1.0"
|
|
22
|
-
},
|
|
23
|
-
"ansis": {
|
|
24
|
-
"from": "4.2.0",
|
|
25
|
-
"to": "^4.3.1"
|
|
26
|
-
},
|
|
27
|
-
"chokidar": {
|
|
28
|
-
"from": "4.0.3",
|
|
29
|
-
"to": "^5.0.0"
|
|
30
|
-
},
|
|
31
|
-
"commander": {
|
|
32
|
-
"from": "4.1.1",
|
|
33
|
-
"to": "^15.0.0"
|
|
34
|
-
},
|
|
35
|
-
"node-emoji": {
|
|
36
|
-
"from": "1.11.0",
|
|
37
|
-
"to": "^2.2.0"
|
|
38
|
-
},
|
|
39
|
-
"ora": {
|
|
40
|
-
"from": "5.4.1",
|
|
41
|
-
"to": "^9.4.1"
|
|
42
|
-
},
|
|
43
15
|
"typescript": {
|
|
44
|
-
"from": "
|
|
16
|
+
"from": "~6.0.2",
|
|
45
17
|
"to": "^7.0.2"
|
|
46
|
-
},
|
|
47
|
-
"webpack": {
|
|
48
|
-
"from": "5.106.2",
|
|
49
|
-
"to": "^5.109.2"
|
|
50
18
|
}
|
|
51
19
|
},
|
|
52
|
-
"timestamp": "2026-08-
|
|
53
|
-
"totalUpdated":
|
|
20
|
+
"timestamp": "2026-08-27T11:23:37.886Z",
|
|
21
|
+
"totalUpdated": 4
|
|
54
22
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from '../actions/abstract.action';
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { AbstractAction } from '../actions/abstract.action.js';
|
|
3
3
|
export declare abstract class AbstractCommand {
|
|
4
4
|
protected action: AbstractAction;
|
|
5
5
|
constructor(action: AbstractAction);
|
|
6
|
-
abstract load(program:
|
|
6
|
+
abstract load(program: Command): void;
|
|
7
7
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.AbstractCommand = void 0;
|
|
4
|
-
class AbstractCommand {
|
|
1
|
+
export class AbstractCommand {
|
|
2
|
+
action;
|
|
5
3
|
constructor(action) {
|
|
6
4
|
this.action = action;
|
|
7
5
|
}
|
|
8
6
|
}
|
|
9
|
-
exports.AbstractCommand = AbstractCommand;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractCommand } from './abstract.command';
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import { AbstractCommand } from './abstract.command.js';
|
|
3
3
|
export declare class AddCommand extends AbstractCommand {
|
|
4
|
-
load(program:
|
|
4
|
+
load(program: Command): void;
|
|
5
5
|
}
|