@nestjs/cli 11.0.16 → 12.0.0-alpha.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/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 +38 -52
- package/actions/build.action.d.ts +11 -10
- package/actions/build.action.js +85 -72
- package/actions/generate.action.d.ts +3 -3
- package/actions/generate.action.js +56 -59
- package/actions/index.d.ts +7 -7
- package/actions/index.js +7 -23
- package/actions/info.action.d.ts +12 -28
- package/actions/info.action.js +47 -55
- package/actions/new.action.d.ts +3 -3
- package/actions/new.action.js +75 -105
- package/actions/start.action.d.ts +4 -7
- package/actions/start.action.js +36 -46
- package/bin/nest.js +14 -10
- 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 +13 -20
- package/commands/build.command.d.ts +3 -3
- package/commands/build.command.js +25 -54
- package/commands/command.input.js +1 -2
- package/commands/command.loader.d.ts +2 -2
- package/commands/command.loader.js +18 -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 +13 -0
- package/commands/context/build.context.js +1 -0
- package/commands/context/generate.context.d.ts +15 -0
- package/commands/context/generate.context.js +1 -0
- package/commands/context/index.d.ts +5 -0
- package/commands/context/index.js +5 -0
- package/commands/context/new.context.d.ts +11 -0
- package/commands/context/new.context.js +1 -0
- package/commands/context/start.context.d.ts +19 -0
- package/commands/context/start.context.js +1 -0
- package/commands/generate.command.d.ts +3 -3
- package/commands/generate.command.js +26 -54
- 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 +2 -6
- package/commands/new.command.d.ts +3 -3
- package/commands/new.command.js +24 -33
- package/commands/start.command.d.ts +3 -3
- package/commands/start.command.js +34 -71
- package/lib/compiler/assets-manager.d.ts +1 -1
- package/lib/compiler/assets-manager.js +27 -33
- 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 +2 -0
- package/lib/compiler/defaults/rspack-defaults.js +117 -0
- package/lib/compiler/defaults/swc-defaults.d.ts +1 -1
- package/lib/compiler/defaults/swc-defaults.js +1 -5
- package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
- package/lib/compiler/defaults/webpack-defaults.js +13 -16
- 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 +5 -8
- package/lib/compiler/helpers/get-builder.d.ts +9 -7
- package/lib/compiler/helpers/get-builder.js +3 -6
- package/lib/compiler/helpers/get-rspack-config-path.d.ts +9 -0
- package/lib/compiler/helpers/get-rspack-config-path.js +15 -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/manual-restart.js +4 -8
- package/lib/compiler/helpers/tsconfig-provider.d.ts +1 -1
- package/lib/compiler/helpers/tsconfig-provider.js +8 -11
- 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 +1 -1
- package/lib/compiler/plugins/plugin-metadata-generator.js +10 -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 +13 -13
- package/lib/compiler/rspack-compiler.d.ts +19 -0
- package/lib/compiler/rspack-compiler.js +97 -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 +4 -4
- package/lib/compiler/swc/swc-compiler.js +41 -39
- package/lib/compiler/swc/type-checker-host.js +12 -18
- package/lib/compiler/typescript-loader.js +5 -7
- package/lib/compiler/watch-compiler.d.ts +5 -5
- package/lib/compiler/watch-compiler.js +14 -18
- package/lib/compiler/webpack-compiler.d.ts +6 -7
- package/lib/compiler/webpack-compiler.js +14 -18
- package/lib/configuration/configuration.d.ts +9 -4
- 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 +11 -20
- package/lib/package-managers/abstract.package-manager.d.ts +4 -4
- package/lib/package-managers/abstract.package-manager.js +19 -30
- package/lib/package-managers/index.d.ts +8 -8
- package/lib/package-managers/index.js +8 -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.factory.d.ts +2 -2
- package/lib/package-managers/package-manager.factory.js +16 -20
- package/lib/package-managers/package-manager.js +2 -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 +10 -12
- 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/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.factory.d.ts +6 -6
- package/lib/runners/runner.factory.js +15 -20
- package/lib/runners/runner.js +2 -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 +104 -108
- package/lib/schematics/schematic.option.js +7 -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 -5
- package/lib/ui/index.d.ts +5 -5
- package/lib/ui/index.js +5 -21
- package/lib/ui/messages.js +15 -19
- package/lib/ui/prefixes.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-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 +1 -1
- package/lib/utils/local-binaries.js +8 -11
- 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 +2 -5
- package/lib/utils/tree-kill.js +7 -10
- package/lib/utils/type-assertions.js +1 -4
- package/package.json +31 -33
package/actions/add.action.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { AddCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
3
|
export declare class AddAction extends AbstractAction {
|
|
4
|
-
handle(
|
|
4
|
+
handle(context: AddCommandContext): Promise<void>;
|
|
5
5
|
private getSourceRoot;
|
|
6
6
|
private installPackage;
|
|
7
7
|
private addLibrary;
|
|
8
|
-
private getLibraryName;
|
|
9
8
|
private getPackageName;
|
|
10
9
|
private getCollectionName;
|
|
11
10
|
private getTagName;
|
package/actions/add.action.js
CHANGED
|
@@ -1,42 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const load_configuration_1 = require("../lib/utils/load-configuration");
|
|
10
|
-
const project_utils_1 = require("../lib/utils/project-utils");
|
|
11
|
-
const abstract_action_1 = require("./abstract.action");
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
3
|
+
import { PackageManagerFactory, } from '../lib/package-managers/index.js';
|
|
4
|
+
import { CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
5
|
+
import { MESSAGES } from '../lib/ui/index.js';
|
|
6
|
+
import { loadConfiguration } from '../lib/utils/load-configuration.js';
|
|
7
|
+
import { askForProjectName, moveDefaultProjectToStart, shouldAskForProject, } from '../lib/utils/project-utils.js';
|
|
8
|
+
import { AbstractAction } from './abstract.action.js';
|
|
12
9
|
const schematicName = 'nest-add';
|
|
13
|
-
class AddAction extends
|
|
14
|
-
async handle(
|
|
15
|
-
const libraryName =
|
|
10
|
+
export class AddAction extends AbstractAction {
|
|
11
|
+
async handle(context) {
|
|
12
|
+
const libraryName = context.library;
|
|
16
13
|
const packageName = this.getPackageName(libraryName);
|
|
17
14
|
const collectionName = this.getCollectionName(libraryName, packageName);
|
|
18
15
|
const tagName = this.getTagName(packageName);
|
|
19
|
-
const
|
|
20
|
-
|
|
16
|
+
const packageInstallSuccess = context.skipInstall ||
|
|
17
|
+
(await this.installPackage(collectionName, tagName));
|
|
21
18
|
if (packageInstallSuccess) {
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
await this.addLibrary(collectionName, options, extraFlags);
|
|
19
|
+
const sourceRoot = await this.getSourceRoot(context.project);
|
|
20
|
+
await this.addLibrary(collectionName, sourceRoot, context.extraFlags);
|
|
25
21
|
}
|
|
26
22
|
else {
|
|
27
|
-
console.error(
|
|
28
|
-
throw new Error(
|
|
23
|
+
console.error(red(MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName)));
|
|
24
|
+
throw new Error(MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName));
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
async getSourceRoot(
|
|
32
|
-
const configuration = await
|
|
27
|
+
async getSourceRoot(project) {
|
|
28
|
+
const configuration = await loadConfiguration();
|
|
33
29
|
const configurationProjects = configuration.projects;
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
let sourceRoot = appName
|
|
37
|
-
? (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName)
|
|
30
|
+
let sourceRoot = project
|
|
31
|
+
? getValueOrDefault(configuration, 'sourceRoot', project)
|
|
38
32
|
: configuration.sourceRoot;
|
|
39
|
-
const shouldAsk =
|
|
33
|
+
const shouldAsk = shouldAskForProject(schematicName, configurationProjects, project ?? '');
|
|
40
34
|
if (shouldAsk) {
|
|
41
35
|
const defaultLabel = ' [ Default ]';
|
|
42
36
|
let defaultProjectName = configuration.sourceRoot + defaultLabel;
|
|
@@ -47,52 +41,45 @@ class AddAction extends abstract_action_1.AbstractAction {
|
|
|
47
41
|
break;
|
|
48
42
|
}
|
|
49
43
|
}
|
|
50
|
-
const projects =
|
|
51
|
-
const selectedProject = (await
|
|
52
|
-
const
|
|
53
|
-
if (
|
|
54
|
-
sourceRoot = configurationProjects[
|
|
44
|
+
const projects = moveDefaultProjectToStart(configuration, defaultProjectName, defaultLabel);
|
|
45
|
+
const selectedProject = (await askForProjectName(MESSAGES.LIBRARY_PROJECT_SELECTION_QUESTION, projects));
|
|
46
|
+
const projectName = selectedProject.replace(defaultLabel, '');
|
|
47
|
+
if (projectName !== configuration.sourceRoot) {
|
|
48
|
+
sourceRoot = configurationProjects[projectName].sourceRoot;
|
|
55
49
|
}
|
|
56
50
|
}
|
|
57
|
-
return
|
|
51
|
+
return sourceRoot;
|
|
58
52
|
}
|
|
59
53
|
async installPackage(collectionName, tagName) {
|
|
60
|
-
const manager = await
|
|
54
|
+
const manager = await PackageManagerFactory.find();
|
|
61
55
|
tagName = tagName || 'latest';
|
|
62
56
|
let installResult = false;
|
|
63
57
|
try {
|
|
64
58
|
installResult = await manager.addProduction([collectionName], tagName);
|
|
65
59
|
}
|
|
66
60
|
catch (error) {
|
|
67
|
-
if (error
|
|
68
|
-
console.error(
|
|
61
|
+
if (error instanceof Error) {
|
|
62
|
+
console.error(red(error.message));
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
65
|
return installResult;
|
|
72
66
|
}
|
|
73
|
-
async addLibrary(collectionName,
|
|
74
|
-
console.info(
|
|
67
|
+
async addLibrary(collectionName, sourceRoot, extraFlags) {
|
|
68
|
+
console.info(MESSAGES.LIBRARY_INSTALLATION_STARTS);
|
|
75
69
|
const schematicOptions = [];
|
|
76
|
-
schematicOptions.push(new
|
|
70
|
+
schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
|
|
77
71
|
const extraFlagsString = extraFlags ? extraFlags.join(' ') : undefined;
|
|
78
72
|
try {
|
|
79
|
-
const collection =
|
|
73
|
+
const collection = CollectionFactory.create(collectionName);
|
|
80
74
|
await collection.execute(schematicName, schematicOptions, extraFlagsString);
|
|
81
75
|
}
|
|
82
76
|
catch (error) {
|
|
83
|
-
if (error
|
|
84
|
-
console.error(
|
|
85
|
-
return Promise.reject();
|
|
77
|
+
if (error instanceof Error) {
|
|
78
|
+
console.error(red(error.message));
|
|
86
79
|
}
|
|
80
|
+
throw error;
|
|
87
81
|
}
|
|
88
82
|
}
|
|
89
|
-
getLibraryName(inputs) {
|
|
90
|
-
const libraryInput = inputs.find((input) => input.name === 'library');
|
|
91
|
-
if (!libraryInput) {
|
|
92
|
-
throw new Error('No library found in command input');
|
|
93
|
-
}
|
|
94
|
-
return libraryInput.value;
|
|
95
|
-
}
|
|
96
83
|
getPackageName(library) {
|
|
97
84
|
return library.startsWith('@')
|
|
98
85
|
? library.split('/', 2).join('/')
|
|
@@ -110,4 +97,3 @@ class AddAction extends abstract_action_1.AbstractAction {
|
|
|
110
97
|
: packageName.split('@', 2)[1];
|
|
111
98
|
}
|
|
112
99
|
}
|
|
113
|
-
exports.AddAction = AddAction;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { AssetsManager } from '../lib/compiler/assets-manager.js';
|
|
2
|
+
import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider.js';
|
|
3
|
+
import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader.js';
|
|
4
|
+
import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader.js';
|
|
5
|
+
import { ConfigurationLoader } from '../lib/configuration/index.js';
|
|
6
|
+
import { FileSystemReader } from '../lib/readers/index.js';
|
|
7
|
+
import { AbstractAction } from './abstract.action.js';
|
|
9
8
|
export declare class BuildAction extends AbstractAction {
|
|
10
9
|
protected readonly pluginsLoader: PluginsLoader;
|
|
11
10
|
protected readonly tsLoader: TypeScriptBinaryLoader;
|
|
@@ -13,10 +12,12 @@ export declare class BuildAction extends AbstractAction {
|
|
|
13
12
|
protected readonly fileSystemReader: FileSystemReader;
|
|
14
13
|
protected readonly loader: ConfigurationLoader;
|
|
15
14
|
protected readonly assetsManager: AssetsManager;
|
|
16
|
-
handle(
|
|
17
|
-
runBuild(
|
|
15
|
+
handle(context: any): Promise<void>;
|
|
16
|
+
runBuild(apps: (string | undefined)[], options: Record<string, any>, watchMode: boolean, watchAssetsMode: boolean, isDebugEnabled?: boolean, onSuccess?: () => void): Promise<void>;
|
|
18
17
|
private runSwc;
|
|
19
18
|
private runWebpack;
|
|
20
19
|
private runTsc;
|
|
21
20
|
private getWebpackConfigFactoryByPath;
|
|
21
|
+
private runRspack;
|
|
22
|
+
private getRspackConfigFactoryByPath;
|
|
22
23
|
}
|
package/actions/build.action.js
CHANGED
|
@@ -1,118 +1,110 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const
|
|
21
|
-
class BuildAction extends
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
async handle(commandInputs, commandOptions) {
|
|
1
|
+
import { createRequire } from 'module';
|
|
2
|
+
import { red } from 'ansis';
|
|
3
|
+
import { join } from 'path';
|
|
4
|
+
import { AssetsManager } from '../lib/compiler/assets-manager.js';
|
|
5
|
+
import { deleteOutDirIfEnabled } from '../lib/compiler/helpers/delete-out-dir.js';
|
|
6
|
+
import { getBuilder } from '../lib/compiler/helpers/get-builder.js';
|
|
7
|
+
import { getRspackConfigPath } from '../lib/compiler/helpers/get-rspack-config-path.js';
|
|
8
|
+
import { getTscConfigPath } from '../lib/compiler/helpers/get-tsc-config.path.js';
|
|
9
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
10
|
+
import { getWebpackConfigPath } from '../lib/compiler/helpers/get-webpack-config-path.js';
|
|
11
|
+
import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider.js';
|
|
12
|
+
import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader.js';
|
|
13
|
+
import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader.js';
|
|
14
|
+
import { NestConfigurationLoader, } from '../lib/configuration/index.js';
|
|
15
|
+
import { defaultOutDir, defaultRspackConfigFilename, defaultWebpackConfigFilename, } from '../lib/configuration/defaults.js';
|
|
16
|
+
import { FileSystemReader } from '../lib/readers/index.js';
|
|
17
|
+
import { ERROR_PREFIX, INFO_PREFIX } from '../lib/ui/index.js';
|
|
18
|
+
import { isModuleAvailable } from '../lib/utils/is-module-available.js';
|
|
19
|
+
import { AbstractAction } from './abstract.action.js';
|
|
20
|
+
const require = createRequire(import.meta.url);
|
|
21
|
+
export class BuildAction extends AbstractAction {
|
|
22
|
+
pluginsLoader = new PluginsLoader();
|
|
23
|
+
tsLoader = new TypeScriptBinaryLoader();
|
|
24
|
+
tsConfigProvider = new TsConfigProvider(this.tsLoader);
|
|
25
|
+
fileSystemReader = new FileSystemReader(process.cwd());
|
|
26
|
+
loader = new NestConfigurationLoader(this.fileSystemReader);
|
|
27
|
+
assetsManager = new AssetsManager();
|
|
28
|
+
async handle(context) {
|
|
29
|
+
const { apps, watch, watchAssets } = context;
|
|
32
30
|
try {
|
|
33
|
-
|
|
34
|
-
const watchMode = !!(watchModeOption && watchModeOption.value);
|
|
35
|
-
const watchAssetsModeOption = commandOptions.find((option) => option.name === 'watchAssets');
|
|
36
|
-
const watchAssetsMode = !!(watchAssetsModeOption && watchAssetsModeOption.value);
|
|
37
|
-
await this.runBuild(commandInputs, commandOptions, watchMode, watchAssetsMode);
|
|
31
|
+
await this.runBuild(apps, context, watch, watchAssets);
|
|
38
32
|
}
|
|
39
33
|
catch (err) {
|
|
40
34
|
if (err instanceof Error) {
|
|
41
|
-
console.
|
|
35
|
+
console.error(`\n${ERROR_PREFIX} ${err.message}\n`);
|
|
42
36
|
}
|
|
43
37
|
else {
|
|
44
|
-
console.error(`\n${
|
|
38
|
+
console.error(`\n${red(err)}\n`);
|
|
45
39
|
}
|
|
46
40
|
process.exit(1);
|
|
47
41
|
}
|
|
48
42
|
}
|
|
49
|
-
async runBuild(
|
|
50
|
-
const configFileName =
|
|
43
|
+
async runBuild(apps, options, watchMode, watchAssetsMode, isDebugEnabled = false, onSuccess) {
|
|
44
|
+
const configFileName = options.config;
|
|
51
45
|
const configuration = await this.loader.load(configFileName);
|
|
52
|
-
const buildAll = commandOptions.find((opt) => opt.name === 'all')?.value;
|
|
53
46
|
let appNames;
|
|
54
|
-
if (
|
|
55
|
-
// If the "all" flag is set, we need to build all projects in a monorepo.
|
|
47
|
+
if (options.all) {
|
|
56
48
|
appNames = [];
|
|
57
49
|
if (configuration.projects) {
|
|
58
50
|
appNames.push(...Object.keys(configuration.projects));
|
|
59
51
|
}
|
|
60
52
|
}
|
|
61
53
|
else {
|
|
62
|
-
appNames =
|
|
63
|
-
.filter((input) => input.name === 'app')
|
|
64
|
-
.map((input) => input.value);
|
|
54
|
+
appNames = apps;
|
|
65
55
|
}
|
|
66
56
|
if (appNames.length === 0) {
|
|
67
|
-
// If there are no projects, use "undefined" to build the default project.
|
|
68
57
|
appNames.push(undefined);
|
|
69
58
|
}
|
|
70
59
|
for (const appName of appNames) {
|
|
71
|
-
const pathToTsconfig =
|
|
60
|
+
const pathToTsconfig = getTscConfigPath(configuration, options, appName);
|
|
72
61
|
const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
|
|
73
|
-
const outDir = tsOptions.outDir ||
|
|
74
|
-
const isWebpackEnabled =
|
|
62
|
+
const outDir = tsOptions.outDir || defaultOutDir;
|
|
63
|
+
const isWebpackEnabled = getValueOrDefault(configuration, 'compilerOptions.webpack', appName, 'webpack', options);
|
|
75
64
|
const builder = isWebpackEnabled
|
|
76
65
|
? { type: 'webpack' }
|
|
77
|
-
:
|
|
78
|
-
await
|
|
66
|
+
: getBuilder(configuration, options, appName);
|
|
67
|
+
await deleteOutDirIfEnabled(configuration, appName, outDir);
|
|
79
68
|
this.assetsManager.copyAssets(configuration, appName, outDir, watchAssetsMode);
|
|
80
|
-
const typeCheck =
|
|
69
|
+
const typeCheck = getValueOrDefault(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options);
|
|
81
70
|
if (typeCheck && builder.type !== 'swc') {
|
|
82
|
-
console.warn(
|
|
71
|
+
console.warn(INFO_PREFIX +
|
|
83
72
|
` "typeCheck" will not have any effect when "builder" is not "swc".`);
|
|
84
73
|
}
|
|
85
74
|
switch (builder.type) {
|
|
86
75
|
case 'tsc':
|
|
87
|
-
await this.runTsc(watchMode,
|
|
76
|
+
await this.runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess);
|
|
88
77
|
break;
|
|
89
78
|
case 'webpack':
|
|
90
|
-
await this.runWebpack(configuration, appName,
|
|
79
|
+
await this.runWebpack(configuration, appName, options, pathToTsconfig, isDebugEnabled, watchMode, onSuccess);
|
|
80
|
+
break;
|
|
81
|
+
case 'rspack':
|
|
82
|
+
await this.runRspack(configuration, appName, options, pathToTsconfig, isDebugEnabled, watchMode, onSuccess);
|
|
91
83
|
break;
|
|
92
84
|
case 'swc':
|
|
93
|
-
await this.runSwc(configuration, appName, pathToTsconfig, watchMode,
|
|
85
|
+
await this.runSwc(configuration, appName, pathToTsconfig, watchMode, options, tsOptions, onSuccess);
|
|
94
86
|
break;
|
|
95
87
|
}
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
90
|
async runSwc(configuration, appName, pathToTsconfig, watchMode, options, tsOptions, onSuccess) {
|
|
99
|
-
const { SwcCompiler } = await
|
|
91
|
+
const { SwcCompiler } = await import('../lib/compiler/swc/swc-compiler.js');
|
|
100
92
|
const swc = new SwcCompiler(this.pluginsLoader);
|
|
101
93
|
await swc.run(configuration, pathToTsconfig, appName, {
|
|
102
94
|
watch: watchMode,
|
|
103
|
-
typeCheck:
|
|
95
|
+
typeCheck: getValueOrDefault(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options),
|
|
104
96
|
tsOptions,
|
|
105
97
|
assetsManager: this.assetsManager,
|
|
106
98
|
}, onSuccess);
|
|
107
99
|
}
|
|
108
|
-
async runWebpack(configuration, appName,
|
|
109
|
-
const { WebpackCompiler } = await
|
|
100
|
+
async runWebpack(configuration, appName, options, pathToTsconfig, debug, watchMode, onSuccess) {
|
|
101
|
+
const { WebpackCompiler } = await import('../lib/compiler/webpack-compiler.js');
|
|
110
102
|
const webpackCompiler = new WebpackCompiler(this.pluginsLoader);
|
|
111
|
-
const webpackPath =
|
|
112
|
-
|
|
113
|
-
const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath,
|
|
103
|
+
const webpackPath = getWebpackConfigPath(configuration, options, appName) ??
|
|
104
|
+
defaultWebpackConfigFilename;
|
|
105
|
+
const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath, defaultWebpackConfigFilename);
|
|
114
106
|
return webpackCompiler.run(configuration, pathToTsconfig, appName, {
|
|
115
|
-
|
|
107
|
+
options,
|
|
116
108
|
webpackConfigFactoryOrConfig,
|
|
117
109
|
debug,
|
|
118
110
|
watchMode,
|
|
@@ -121,25 +113,46 @@ class BuildAction extends abstract_action_1.AbstractAction {
|
|
|
121
113
|
}
|
|
122
114
|
async runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess) {
|
|
123
115
|
if (watchMode) {
|
|
124
|
-
const { WatchCompiler } = await
|
|
116
|
+
const { WatchCompiler } = await import('../lib/compiler/watch-compiler.js');
|
|
125
117
|
const watchCompiler = new WatchCompiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
126
|
-
const isPreserveWatchOutputEnabled = options.
|
|
118
|
+
const isPreserveWatchOutputEnabled = !!options.preserveWatchOutput;
|
|
127
119
|
watchCompiler.run(configuration, pathToTsconfig, appName, { preserveWatchOutput: isPreserveWatchOutputEnabled }, onSuccess);
|
|
128
120
|
}
|
|
129
121
|
else {
|
|
130
|
-
const { Compiler } = await
|
|
122
|
+
const { Compiler } = await import('../lib/compiler/compiler.js');
|
|
131
123
|
const compiler = new Compiler(this.pluginsLoader, this.tsConfigProvider, this.tsLoader);
|
|
132
124
|
compiler.run(configuration, pathToTsconfig, appName, undefined, onSuccess);
|
|
133
125
|
this.assetsManager.closeWatchers();
|
|
134
126
|
}
|
|
135
127
|
}
|
|
136
128
|
getWebpackConfigFactoryByPath(webpackPath, defaultPath) {
|
|
137
|
-
const pathToWebpackFile =
|
|
138
|
-
const isWebpackFileAvailable =
|
|
129
|
+
const pathToWebpackFile = join(process.cwd(), webpackPath);
|
|
130
|
+
const isWebpackFileAvailable = isModuleAvailable(pathToWebpackFile);
|
|
139
131
|
if (!isWebpackFileAvailable && webpackPath === defaultPath) {
|
|
140
|
-
return (
|
|
132
|
+
return (_config) => ({});
|
|
141
133
|
}
|
|
142
134
|
return require(pathToWebpackFile);
|
|
143
135
|
}
|
|
136
|
+
async runRspack(configuration, appName, options, pathToTsconfig, debug, watchMode, onSuccess) {
|
|
137
|
+
const { RspackCompiler } = await import('../lib/compiler/rspack-compiler.js');
|
|
138
|
+
const rspackCompiler = new RspackCompiler(this.pluginsLoader);
|
|
139
|
+
const rspackPath = getRspackConfigPath(configuration, options, appName) ??
|
|
140
|
+
defaultRspackConfigFilename;
|
|
141
|
+
const rspackConfigFactoryOrConfig = this.getRspackConfigFactoryByPath(rspackPath, defaultRspackConfigFilename);
|
|
142
|
+
return rspackCompiler.run(configuration, pathToTsconfig, appName, {
|
|
143
|
+
options,
|
|
144
|
+
rspackConfigFactoryOrConfig,
|
|
145
|
+
debug,
|
|
146
|
+
watchMode,
|
|
147
|
+
assetsManager: this.assetsManager,
|
|
148
|
+
}, onSuccess);
|
|
149
|
+
}
|
|
150
|
+
getRspackConfigFactoryByPath(rspackPath, defaultPath) {
|
|
151
|
+
const pathToRspackFile = join(process.cwd(), rspackPath);
|
|
152
|
+
const isRspackFileAvailable = isModuleAvailable(pathToRspackFile);
|
|
153
|
+
if (!isRspackFileAvailable && rspackPath === defaultPath) {
|
|
154
|
+
return (_config) => ({});
|
|
155
|
+
}
|
|
156
|
+
return require(pathToRspackFile);
|
|
157
|
+
}
|
|
144
158
|
}
|
|
145
|
-
exports.BuildAction = BuildAction;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { AbstractAction } from './abstract.action';
|
|
1
|
+
import { GenerateCommandContext } from '../commands/index.js';
|
|
2
|
+
import { AbstractAction } from './abstract.action.js';
|
|
3
3
|
export declare class GenerateAction extends AbstractAction {
|
|
4
|
-
handle(
|
|
4
|
+
handle(context: GenerateCommandContext): Promise<void>;
|
|
5
5
|
}
|
|
@@ -1,48 +1,39 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const type_assertions_1 = require("../lib/utils/type-assertions");
|
|
13
|
-
class GenerateAction extends abstract_action_1.AbstractAction {
|
|
14
|
-
async handle(inputs, options) {
|
|
15
|
-
await generateFiles(inputs.concat(options));
|
|
1
|
+
import { red } from 'ansis';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { getValueOrDefault } from '../lib/compiler/helpers/get-value-or-default.js';
|
|
4
|
+
import { Collection, CollectionFactory, SchematicOption, } from '../lib/schematics/index.js';
|
|
5
|
+
import { MESSAGES } from '../lib/ui/index.js';
|
|
6
|
+
import { loadConfiguration } from '../lib/utils/load-configuration.js';
|
|
7
|
+
import { askForProjectName, getSpecFileSuffix, moveDefaultProjectToStart, shouldAskForProject, shouldGenerateFlat, shouldGenerateSpec, } from '../lib/utils/project-utils.js';
|
|
8
|
+
import { AbstractAction } from './abstract.action.js';
|
|
9
|
+
export class GenerateAction extends AbstractAction {
|
|
10
|
+
async handle(context) {
|
|
11
|
+
await generateFiles(context);
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const flat = inputs.find((option) => option.name === 'flat');
|
|
28
|
-
const specFileSuffix = inputs.find((option) => option.name === 'specFileSuffix');
|
|
29
|
-
const collection = schematics_1.CollectionFactory.create(collectionOption || configuration.collection || schematics_1.Collection.NESTJS);
|
|
30
|
-
const schematicOptions = mapSchematicOptions(inputs);
|
|
31
|
-
schematicOptions.push(new schematics_1.SchematicOption('language', configuration.language));
|
|
14
|
+
const generateFiles = async (context) => {
|
|
15
|
+
const configuration = await loadConfiguration();
|
|
16
|
+
const collectionOption = context.collection;
|
|
17
|
+
const schematic = context.schematic;
|
|
18
|
+
const appName = context.project ?? '';
|
|
19
|
+
const specFileSuffix = context.specFileSuffix;
|
|
20
|
+
const collection = CollectionFactory.create(collectionOption || configuration.collection || Collection.NESTJS);
|
|
21
|
+
const schematicOptions = mapContextToSchematicOptions(context);
|
|
22
|
+
schematicOptions.push(new SchematicOption('language', configuration.language));
|
|
32
23
|
const configurationProjects = configuration.projects;
|
|
33
24
|
let sourceRoot = appName
|
|
34
|
-
?
|
|
25
|
+
? getValueOrDefault(configuration, 'sourceRoot', appName)
|
|
35
26
|
: configuration.sourceRoot;
|
|
36
|
-
const specValue = spec.value;
|
|
37
|
-
const
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
let generateSpec =
|
|
41
|
-
let generateFlat =
|
|
42
|
-
let generateSpecFileSuffix =
|
|
27
|
+
const specValue = typeof context.spec === 'boolean' ? context.spec : context.spec.value;
|
|
28
|
+
const specPassedAsInput = typeof context.spec === 'boolean' ? false : context.spec.passedAsInput;
|
|
29
|
+
const flatValue = context.flat !== undefined ? !!context.flat : false;
|
|
30
|
+
const specFileSuffixValue = specFileSuffix;
|
|
31
|
+
let generateSpec = shouldGenerateSpec(configuration, schematic, appName, specValue, specPassedAsInput);
|
|
32
|
+
let generateFlat = shouldGenerateFlat(configuration, appName, flatValue);
|
|
33
|
+
let generateSpecFileSuffix = getSpecFileSuffix(configuration, appName, specFileSuffixValue);
|
|
43
34
|
// If you only add a `lib` we actually don't have monorepo: true BUT we do have "projects"
|
|
44
35
|
// Ensure we don't run for new app/libs schematics
|
|
45
|
-
if (
|
|
36
|
+
if (shouldAskForProject(schematic, configurationProjects, appName)) {
|
|
46
37
|
const defaultLabel = ' [ Default ]';
|
|
47
38
|
let defaultProjectName = configuration.sourceRoot + defaultLabel;
|
|
48
39
|
for (const property in configurationProjects) {
|
|
@@ -51,47 +42,53 @@ const generateFiles = async (inputs) => {
|
|
|
51
42
|
break;
|
|
52
43
|
}
|
|
53
44
|
}
|
|
54
|
-
const projects =
|
|
55
|
-
const selectedProjectName = (await
|
|
45
|
+
const projects = moveDefaultProjectToStart(configuration, defaultProjectName, defaultLabel);
|
|
46
|
+
const selectedProjectName = (await askForProjectName(MESSAGES.PROJECT_SELECTION_QUESTION, projects));
|
|
56
47
|
const project = selectedProjectName.replace(defaultLabel, '');
|
|
57
48
|
if (project !== configuration.sourceRoot) {
|
|
58
49
|
sourceRoot = configurationProjects[project].sourceRoot;
|
|
59
50
|
}
|
|
60
51
|
if (selectedProjectName !== defaultProjectName) {
|
|
61
52
|
// Only overwrite if the appName is not the default- as it has already been loaded above
|
|
62
|
-
generateSpec =
|
|
63
|
-
generateFlat =
|
|
64
|
-
generateSpecFileSuffix =
|
|
53
|
+
generateSpec = shouldGenerateSpec(configuration, schematic, selectedProjectName, specValue, specPassedAsInput);
|
|
54
|
+
generateFlat = shouldGenerateFlat(configuration, selectedProjectName, flatValue);
|
|
55
|
+
generateSpecFileSuffix = getSpecFileSuffix(configuration, appName, specFileSuffixValue);
|
|
65
56
|
}
|
|
66
57
|
}
|
|
67
58
|
if (configuration.generateOptions?.baseDir) {
|
|
68
59
|
sourceRoot = path.join(sourceRoot, configuration.generateOptions.baseDir);
|
|
69
60
|
}
|
|
70
|
-
schematicOptions.push(new
|
|
71
|
-
schematicOptions.push(new
|
|
72
|
-
schematicOptions.push(new
|
|
73
|
-
schematicOptions.push(new
|
|
61
|
+
schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
|
|
62
|
+
schematicOptions.push(new SchematicOption('spec', generateSpec));
|
|
63
|
+
schematicOptions.push(new SchematicOption('flat', generateFlat));
|
|
64
|
+
schematicOptions.push(new SchematicOption('specFileSuffix', generateSpecFileSuffix));
|
|
74
65
|
try {
|
|
75
|
-
|
|
76
|
-
if (!schematicInput) {
|
|
66
|
+
if (!schematic) {
|
|
77
67
|
throw new Error('Unable to find a schematic for this configuration');
|
|
78
68
|
}
|
|
79
|
-
await collection.execute(
|
|
69
|
+
await collection.execute(schematic, schematicOptions);
|
|
80
70
|
}
|
|
81
71
|
catch (error) {
|
|
82
72
|
if (error && error.message) {
|
|
83
|
-
console.error(
|
|
73
|
+
console.error(red(error.message));
|
|
84
74
|
}
|
|
85
75
|
}
|
|
86
76
|
};
|
|
87
|
-
const
|
|
88
|
-
const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix'];
|
|
77
|
+
const mapContextToSchematicOptions = (context) => {
|
|
89
78
|
const options = [];
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
79
|
+
// Only include fields that schematics expect; exclude those handled separately
|
|
80
|
+
if (context.name !== undefined)
|
|
81
|
+
options.push(new SchematicOption('name', context.name));
|
|
82
|
+
if (context.path !== undefined)
|
|
83
|
+
options.push(new SchematicOption('path', context.path));
|
|
84
|
+
if (context.dryRun)
|
|
85
|
+
options.push(new SchematicOption('dry-run', true));
|
|
86
|
+
if (context.collection !== undefined)
|
|
87
|
+
options.push(new SchematicOption('collection', context.collection));
|
|
88
|
+
if (context.project !== undefined)
|
|
89
|
+
options.push(new SchematicOption('project', context.project));
|
|
90
|
+
if (context.skipImport !== undefined)
|
|
91
|
+
options.push(new SchematicOption('skipImport', context.skipImport));
|
|
92
|
+
// 'schematic', 'spec', 'flat', 'specFileSuffix' are handled separately
|
|
96
93
|
return options;
|
|
97
94
|
};
|
package/actions/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from './abstract.action';
|
|
2
|
-
export * from './build.action';
|
|
3
|
-
export * from './generate.action';
|
|
4
|
-
export * from './info.action';
|
|
5
|
-
export * from './new.action';
|
|
6
|
-
export * from './start.action';
|
|
7
|
-
export * from './add.action';
|
|
1
|
+
export * from './abstract.action.js';
|
|
2
|
+
export * from './build.action.js';
|
|
3
|
+
export * from './generate.action.js';
|
|
4
|
+
export * from './info.action.js';
|
|
5
|
+
export * from './new.action.js';
|
|
6
|
+
export * from './start.action.js';
|
|
7
|
+
export * from './add.action.js';
|