@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.
Files changed (182) hide show
  1. package/actions/abstract.action.d.ts +1 -2
  2. package/actions/abstract.action.js +1 -5
  3. package/actions/add.action.d.ts +3 -4
  4. package/actions/add.action.js +38 -52
  5. package/actions/build.action.d.ts +11 -10
  6. package/actions/build.action.js +85 -72
  7. package/actions/generate.action.d.ts +3 -3
  8. package/actions/generate.action.js +56 -59
  9. package/actions/index.d.ts +7 -7
  10. package/actions/index.js +7 -23
  11. package/actions/info.action.d.ts +12 -28
  12. package/actions/info.action.js +47 -55
  13. package/actions/new.action.d.ts +3 -3
  14. package/actions/new.action.js +75 -105
  15. package/actions/start.action.d.ts +4 -7
  16. package/actions/start.action.js +36 -46
  17. package/bin/nest.js +14 -10
  18. package/commands/abstract.command.d.ts +3 -3
  19. package/commands/abstract.command.js +2 -5
  20. package/commands/add.command.d.ts +3 -3
  21. package/commands/add.command.js +13 -20
  22. package/commands/build.command.d.ts +3 -3
  23. package/commands/build.command.js +25 -54
  24. package/commands/command.input.js +1 -2
  25. package/commands/command.loader.d.ts +2 -2
  26. package/commands/command.loader.js +18 -22
  27. package/commands/context/add.context.d.ts +7 -0
  28. package/commands/context/add.context.js +1 -0
  29. package/commands/context/build.context.d.ts +13 -0
  30. package/commands/context/build.context.js +1 -0
  31. package/commands/context/generate.context.d.ts +15 -0
  32. package/commands/context/generate.context.js +1 -0
  33. package/commands/context/index.d.ts +5 -0
  34. package/commands/context/index.js +5 -0
  35. package/commands/context/new.context.d.ts +11 -0
  36. package/commands/context/new.context.js +1 -0
  37. package/commands/context/start.context.d.ts +19 -0
  38. package/commands/context/start.context.js +1 -0
  39. package/commands/generate.command.d.ts +3 -3
  40. package/commands/generate.command.js +26 -54
  41. package/commands/index.d.ts +3 -2
  42. package/commands/index.js +3 -18
  43. package/commands/info.command.d.ts +3 -3
  44. package/commands/info.command.js +2 -6
  45. package/commands/new.command.d.ts +3 -3
  46. package/commands/new.command.js +24 -33
  47. package/commands/start.command.d.ts +3 -3
  48. package/commands/start.command.js +34 -71
  49. package/lib/compiler/assets-manager.d.ts +1 -1
  50. package/lib/compiler/assets-manager.js +27 -33
  51. package/lib/compiler/base-compiler.d.ts +5 -5
  52. package/lib/compiler/base-compiler.js +10 -13
  53. package/lib/compiler/compiler.d.ts +6 -6
  54. package/lib/compiler/compiler.js +7 -9
  55. package/lib/compiler/defaults/rspack-defaults.d.ts +2 -0
  56. package/lib/compiler/defaults/rspack-defaults.js +117 -0
  57. package/lib/compiler/defaults/swc-defaults.d.ts +1 -1
  58. package/lib/compiler/defaults/swc-defaults.js +1 -5
  59. package/lib/compiler/defaults/webpack-defaults.d.ts +2 -2
  60. package/lib/compiler/defaults/webpack-defaults.js +13 -16
  61. package/lib/compiler/helpers/append-extension.js +3 -6
  62. package/lib/compiler/helpers/copy-path-resolve.js +2 -5
  63. package/lib/compiler/helpers/delete-out-dir.d.ts +1 -1
  64. package/lib/compiler/helpers/delete-out-dir.js +5 -8
  65. package/lib/compiler/helpers/get-builder.d.ts +9 -7
  66. package/lib/compiler/helpers/get-builder.js +3 -6
  67. package/lib/compiler/helpers/get-rspack-config-path.d.ts +9 -0
  68. package/lib/compiler/helpers/get-rspack-config-path.js +15 -0
  69. package/lib/compiler/helpers/get-tsc-config.path.d.ts +2 -3
  70. package/lib/compiler/helpers/get-tsc-config.path.js +6 -9
  71. package/lib/compiler/helpers/get-value-or-default.d.ts +2 -3
  72. package/lib/compiler/helpers/get-value-or-default.js +3 -8
  73. package/lib/compiler/helpers/get-webpack-config-path.d.ts +2 -3
  74. package/lib/compiler/helpers/get-webpack-config-path.js +4 -7
  75. package/lib/compiler/helpers/manual-restart.js +4 -8
  76. package/lib/compiler/helpers/tsconfig-provider.d.ts +1 -1
  77. package/lib/compiler/helpers/tsconfig-provider.js +8 -11
  78. package/lib/compiler/hooks/tsconfig-paths.hook.js +13 -13
  79. package/lib/compiler/interfaces/readonly-visitor.interface.js +1 -2
  80. package/lib/compiler/plugins/plugin-metadata-generator.d.ts +1 -1
  81. package/lib/compiler/plugins/plugin-metadata-generator.js +10 -13
  82. package/lib/compiler/plugins/plugin-metadata-printer.d.ts +1 -1
  83. package/lib/compiler/plugins/plugin-metadata-printer.js +5 -9
  84. package/lib/compiler/plugins/plugins-loader.d.ts +2 -2
  85. package/lib/compiler/plugins/plugins-loader.js +13 -13
  86. package/lib/compiler/rspack-compiler.d.ts +19 -0
  87. package/lib/compiler/rspack-compiler.js +97 -0
  88. package/lib/compiler/swc/constants.d.ts +0 -1
  89. package/lib/compiler/swc/constants.js +9 -13
  90. package/lib/compiler/swc/forked-type-checker.js +13 -18
  91. package/lib/compiler/swc/swc-compiler.d.ts +4 -4
  92. package/lib/compiler/swc/swc-compiler.js +41 -39
  93. package/lib/compiler/swc/type-checker-host.js +12 -18
  94. package/lib/compiler/typescript-loader.js +5 -7
  95. package/lib/compiler/watch-compiler.d.ts +5 -5
  96. package/lib/compiler/watch-compiler.js +14 -18
  97. package/lib/compiler/webpack-compiler.d.ts +6 -7
  98. package/lib/compiler/webpack-compiler.js +14 -18
  99. package/lib/configuration/configuration.d.ts +9 -4
  100. package/lib/configuration/configuration.js +1 -2
  101. package/lib/configuration/configuration.loader.d.ts +1 -1
  102. package/lib/configuration/configuration.loader.js +1 -2
  103. package/lib/configuration/defaults.d.ts +2 -1
  104. package/lib/configuration/defaults.js +8 -10
  105. package/lib/configuration/index.d.ts +3 -3
  106. package/lib/configuration/index.js +3 -19
  107. package/lib/configuration/nest-configuration.loader.d.ts +3 -3
  108. package/lib/configuration/nest-configuration.loader.js +11 -20
  109. package/lib/package-managers/abstract.package-manager.d.ts +4 -4
  110. package/lib/package-managers/abstract.package-manager.js +19 -30
  111. package/lib/package-managers/index.d.ts +8 -8
  112. package/lib/package-managers/index.js +8 -24
  113. package/lib/package-managers/npm.package-manager.d.ts +2 -2
  114. package/lib/package-managers/npm.package-manager.js +6 -10
  115. package/lib/package-managers/package-manager-commands.js +1 -2
  116. package/lib/package-managers/package-manager.factory.d.ts +2 -2
  117. package/lib/package-managers/package-manager.factory.js +16 -20
  118. package/lib/package-managers/package-manager.js +2 -5
  119. package/lib/package-managers/pnpm.package-manager.d.ts +2 -2
  120. package/lib/package-managers/pnpm.package-manager.js +6 -10
  121. package/lib/package-managers/project.dependency.js +1 -2
  122. package/lib/package-managers/yarn.package-manager.d.ts +2 -2
  123. package/lib/package-managers/yarn.package-manager.js +6 -10
  124. package/lib/questions/questions.d.ts +5 -1
  125. package/lib/questions/questions.js +2 -7
  126. package/lib/readers/file-system.reader.d.ts +1 -1
  127. package/lib/readers/file-system.reader.js +6 -9
  128. package/lib/readers/index.d.ts +2 -2
  129. package/lib/readers/index.js +2 -18
  130. package/lib/readers/reader.js +3 -5
  131. package/lib/runners/abstract.runner.js +10 -12
  132. package/lib/runners/git.runner.d.ts +1 -1
  133. package/lib/runners/git.runner.js +2 -6
  134. package/lib/runners/index.d.ts +3 -3
  135. package/lib/runners/index.js +3 -19
  136. package/lib/runners/npm.runner.d.ts +1 -1
  137. package/lib/runners/npm.runner.js +2 -6
  138. package/lib/runners/pnpm.runner.d.ts +1 -1
  139. package/lib/runners/pnpm.runner.js +2 -6
  140. package/lib/runners/runner.factory.d.ts +6 -6
  141. package/lib/runners/runner.factory.js +15 -20
  142. package/lib/runners/runner.js +2 -5
  143. package/lib/runners/schematic.runner.d.ts +1 -1
  144. package/lib/runners/schematic.runner.js +5 -7
  145. package/lib/runners/yarn.runner.d.ts +1 -1
  146. package/lib/runners/yarn.runner.js +2 -6
  147. package/lib/schematics/abstract.collection.d.ts +3 -3
  148. package/lib/schematics/abstract.collection.js +3 -5
  149. package/lib/schematics/collection.factory.d.ts +2 -2
  150. package/lib/schematics/collection.factory.js +9 -13
  151. package/lib/schematics/collection.js +2 -5
  152. package/lib/schematics/custom.collection.d.ts +2 -2
  153. package/lib/schematics/custom.collection.js +4 -8
  154. package/lib/schematics/index.d.ts +4 -4
  155. package/lib/schematics/index.js +4 -20
  156. package/lib/schematics/nest.collection.d.ts +3 -3
  157. package/lib/schematics/nest.collection.js +104 -108
  158. package/lib/schematics/schematic.option.js +7 -9
  159. package/lib/ui/banner.js +1 -4
  160. package/lib/ui/emojis.d.ts +17 -17
  161. package/lib/ui/emojis.js +19 -22
  162. package/lib/ui/errors.js +1 -5
  163. package/lib/ui/index.d.ts +5 -5
  164. package/lib/ui/index.js +5 -21
  165. package/lib/ui/messages.js +15 -19
  166. package/lib/ui/prefixes.js +3 -6
  167. package/lib/utils/formatting.js +1 -4
  168. package/lib/utils/get-default-tsconfig-path.js +4 -7
  169. package/lib/utils/gracefully-exit-on-prompt-error.js +1 -4
  170. package/lib/utils/is-module-available.js +3 -4
  171. package/lib/utils/load-configuration.d.ts +1 -1
  172. package/lib/utils/load-configuration.js +4 -7
  173. package/lib/utils/local-binaries.d.ts +1 -1
  174. package/lib/utils/local-binaries.js +8 -11
  175. package/lib/utils/os-info.utils.js +1 -4
  176. package/lib/utils/project-utils.d.ts +1 -3
  177. package/lib/utils/project-utils.js +16 -28
  178. package/lib/utils/remaining-flags.d.ts +2 -2
  179. package/lib/utils/remaining-flags.js +2 -5
  180. package/lib/utils/tree-kill.js +7 -10
  181. package/lib/utils/type-assertions.js +1 -4
  182. package/package.json +31 -33
@@ -1,4 +1,3 @@
1
- import { Input } from '../commands';
2
1
  export declare abstract class AbstractAction {
3
- abstract handle(inputs?: Input[], options?: Input[], extraFlags?: string[]): Promise<void>;
2
+ abstract handle(context?: any): Promise<void>;
4
3
  }
@@ -1,6 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AbstractAction = void 0;
4
- class AbstractAction {
1
+ export class AbstractAction {
5
2
  }
6
- exports.AbstractAction = AbstractAction;
@@ -1,11 +1,10 @@
1
- import { Input } from '../commands';
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(inputs: Input[], options: Input[], extraFlags: string[]): Promise<void>;
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;
@@ -1,42 +1,36 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddAction = void 0;
4
- const ansis_1 = require("ansis");
5
- const get_value_or_default_1 = require("../lib/compiler/helpers/get-value-or-default");
6
- const package_managers_1 = require("../lib/package-managers");
7
- const schematics_1 = require("../lib/schematics");
8
- const ui_1 = require("../lib/ui");
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 abstract_action_1.AbstractAction {
14
- async handle(inputs, options, extraFlags) {
15
- const libraryName = this.getLibraryName(inputs);
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 skipInstall = (0, project_utils_1.hasValidOptionFlag)('skip-install', options);
20
- const packageInstallSuccess = skipInstall || (await this.installPackage(collectionName, tagName));
16
+ const packageInstallSuccess = context.skipInstall ||
17
+ (await this.installPackage(collectionName, tagName));
21
18
  if (packageInstallSuccess) {
22
- const sourceRootOption = await this.getSourceRoot(inputs.concat(options));
23
- options.push(sourceRootOption);
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((0, ansis_1.red)(ui_1.MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName)));
28
- throw new Error(ui_1.MESSAGES.LIBRARY_INSTALLATION_FAILED_BAD_PACKAGE(libraryName));
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(inputs) {
32
- const configuration = await (0, load_configuration_1.loadConfiguration)();
27
+ async getSourceRoot(project) {
28
+ const configuration = await loadConfiguration();
33
29
  const configurationProjects = configuration.projects;
34
- const appName = inputs.find((option) => option.name === 'project')
35
- .value;
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 = (0, project_utils_1.shouldAskForProject)(schematicName, configurationProjects, appName);
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 = (0, project_utils_1.moveDefaultProjectToStart)(configuration, defaultProjectName, defaultLabel);
51
- const selectedProject = (await (0, project_utils_1.askForProjectName)(ui_1.MESSAGES.LIBRARY_PROJECT_SELECTION_QUESTION, projects));
52
- const project = selectedProject.replace(defaultLabel, '');
53
- if (project !== configuration.sourceRoot) {
54
- sourceRoot = configurationProjects[project].sourceRoot;
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 { name: 'sourceRoot', value: sourceRoot };
51
+ return sourceRoot;
58
52
  }
59
53
  async installPackage(collectionName, tagName) {
60
- const manager = await package_managers_1.PackageManagerFactory.find();
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 && error.message) {
68
- console.error((0, ansis_1.red)(error.message));
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, options, extraFlags) {
74
- console.info(ui_1.MESSAGES.LIBRARY_INSTALLATION_STARTS);
67
+ async addLibrary(collectionName, sourceRoot, extraFlags) {
68
+ console.info(MESSAGES.LIBRARY_INSTALLATION_STARTS);
75
69
  const schematicOptions = [];
76
- schematicOptions.push(new schematics_1.SchematicOption('sourceRoot', options.find((option) => option.name === 'sourceRoot').value));
70
+ schematicOptions.push(new SchematicOption('sourceRoot', sourceRoot));
77
71
  const extraFlagsString = extraFlags ? extraFlags.join(' ') : undefined;
78
72
  try {
79
- const collection = schematics_1.CollectionFactory.create(collectionName);
73
+ const collection = CollectionFactory.create(collectionName);
80
74
  await collection.execute(schematicName, schematicOptions, extraFlagsString);
81
75
  }
82
76
  catch (error) {
83
- if (error && error.message) {
84
- console.error((0, ansis_1.red)(error.message));
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 { Input } from '../commands';
2
- import { AssetsManager } from '../lib/compiler/assets-manager';
3
- import { TsConfigProvider } from '../lib/compiler/helpers/tsconfig-provider';
4
- import { PluginsLoader } from '../lib/compiler/plugins/plugins-loader';
5
- import { TypeScriptBinaryLoader } from '../lib/compiler/typescript-loader';
6
- import { ConfigurationLoader } from '../lib/configuration';
7
- import { FileSystemReader } from '../lib/readers';
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(commandInputs: Input[], commandOptions: Input[]): Promise<void>;
17
- runBuild(commandInputs: Input[], commandOptions: Input[], watchMode: boolean, watchAssetsMode: boolean, isDebugEnabled?: boolean, onSuccess?: () => void): Promise<void>;
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
  }
@@ -1,118 +1,110 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BuildAction = void 0;
4
- const ansis_1 = require("ansis");
5
- const path_1 = require("path");
6
- const assets_manager_1 = require("../lib/compiler/assets-manager");
7
- const delete_out_dir_1 = require("../lib/compiler/helpers/delete-out-dir");
8
- const get_builder_1 = require("../lib/compiler/helpers/get-builder");
9
- const get_tsc_config_path_1 = require("../lib/compiler/helpers/get-tsc-config.path");
10
- const get_value_or_default_1 = require("../lib/compiler/helpers/get-value-or-default");
11
- const get_webpack_config_path_1 = require("../lib/compiler/helpers/get-webpack-config-path");
12
- const tsconfig_provider_1 = require("../lib/compiler/helpers/tsconfig-provider");
13
- const plugins_loader_1 = require("../lib/compiler/plugins/plugins-loader");
14
- const typescript_loader_1 = require("../lib/compiler/typescript-loader");
15
- const configuration_1 = require("../lib/configuration");
16
- const defaults_1 = require("../lib/configuration/defaults");
17
- const readers_1 = require("../lib/readers");
18
- const ui_1 = require("../lib/ui");
19
- const is_module_available_1 = require("../lib/utils/is-module-available");
20
- const abstract_action_1 = require("./abstract.action");
21
- class BuildAction extends abstract_action_1.AbstractAction {
22
- constructor() {
23
- super(...arguments);
24
- this.pluginsLoader = new plugins_loader_1.PluginsLoader();
25
- this.tsLoader = new typescript_loader_1.TypeScriptBinaryLoader();
26
- this.tsConfigProvider = new tsconfig_provider_1.TsConfigProvider(this.tsLoader);
27
- this.fileSystemReader = new readers_1.FileSystemReader(process.cwd());
28
- this.loader = new configuration_1.NestConfigurationLoader(this.fileSystemReader);
29
- this.assetsManager = new assets_manager_1.AssetsManager();
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
- const watchModeOption = commandOptions.find((option) => option.name === 'watch');
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.log(`\n${ui_1.ERROR_PREFIX} ${err.message}\n`);
35
+ console.error(`\n${ERROR_PREFIX} ${err.message}\n`);
42
36
  }
43
37
  else {
44
- console.error(`\n${(0, ansis_1.red)(err)}\n`);
38
+ console.error(`\n${red(err)}\n`);
45
39
  }
46
40
  process.exit(1);
47
41
  }
48
42
  }
49
- async runBuild(commandInputs, commandOptions, watchMode, watchAssetsMode, isDebugEnabled = false, onSuccess) {
50
- const configFileName = commandOptions.find((option) => option.name === 'config').value;
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 (buildAll) {
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 = commandInputs
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 = (0, get_tsc_config_path_1.getTscConfigPath)(configuration, commandOptions, appName);
60
+ const pathToTsconfig = getTscConfigPath(configuration, options, appName);
72
61
  const { options: tsOptions } = this.tsConfigProvider.getByConfigFilename(pathToTsconfig);
73
- const outDir = tsOptions.outDir || defaults_1.defaultOutDir;
74
- const isWebpackEnabled = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.webpack', appName, 'webpack', commandOptions);
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
- : (0, get_builder_1.getBuilder)(configuration, commandOptions, appName);
78
- await (0, delete_out_dir_1.deleteOutDirIfEnabled)(configuration, appName, outDir);
66
+ : getBuilder(configuration, options, appName);
67
+ await deleteOutDirIfEnabled(configuration, appName, outDir);
79
68
  this.assetsManager.copyAssets(configuration, appName, outDir, watchAssetsMode);
80
- const typeCheck = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', commandOptions);
69
+ const typeCheck = getValueOrDefault(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options);
81
70
  if (typeCheck && builder.type !== 'swc') {
82
- console.warn(ui_1.INFO_PREFIX +
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, commandOptions, configuration, pathToTsconfig, appName, onSuccess);
76
+ await this.runTsc(watchMode, options, configuration, pathToTsconfig, appName, onSuccess);
88
77
  break;
89
78
  case 'webpack':
90
- await this.runWebpack(configuration, appName, commandOptions, pathToTsconfig, isDebugEnabled, watchMode, onSuccess);
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, commandOptions, tsOptions, onSuccess);
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 Promise.resolve().then(() => require('../lib/compiler/swc/swc-compiler'));
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: (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.typeCheck', appName, 'typeCheck', options),
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, commandOptions, pathToTsconfig, debug, watchMode, onSuccess) {
109
- const { WebpackCompiler } = await Promise.resolve().then(() => require('../lib/compiler/webpack-compiler'));
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 = (0, get_webpack_config_path_1.getWebpackConfigPath)(configuration, commandOptions, appName) ??
112
- defaults_1.defaultWebpackConfigFilename;
113
- const webpackConfigFactoryOrConfig = this.getWebpackConfigFactoryByPath(webpackPath, defaults_1.defaultWebpackConfigFilename);
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
- inputs: commandOptions,
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 Promise.resolve().then(() => require('../lib/compiler/watch-compiler'));
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.find((option) => option.name === 'preserveWatchOutput' && option.value === true)?.value;
118
+ const isPreserveWatchOutputEnabled = !!options.preserveWatchOutput;
127
119
  watchCompiler.run(configuration, pathToTsconfig, appName, { preserveWatchOutput: isPreserveWatchOutputEnabled }, onSuccess);
128
120
  }
129
121
  else {
130
- const { Compiler } = await Promise.resolve().then(() => require('../lib/compiler/compiler'));
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 = (0, path_1.join)(process.cwd(), webpackPath);
138
- const isWebpackFileAvailable = (0, is_module_available_1.isModuleAvailable)(pathToWebpackFile);
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 { Input } from '../commands';
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(inputs: Input[], options: Input[]): Promise<void>;
4
+ handle(context: GenerateCommandContext): Promise<void>;
5
5
  }
@@ -1,48 +1,39 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GenerateAction = void 0;
4
- const ansis_1 = require("ansis");
5
- const path = require("path");
6
- const get_value_or_default_1 = require("../lib/compiler/helpers/get-value-or-default");
7
- const schematics_1 = require("../lib/schematics");
8
- const ui_1 = require("../lib/ui");
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");
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
- exports.GenerateAction = GenerateAction;
19
- const generateFiles = async (inputs) => {
20
- const configuration = await (0, load_configuration_1.loadConfiguration)();
21
- const collectionOption = inputs.find((option) => option.name === 'collection').value;
22
- const schematic = inputs.find((option) => option.name === 'schematic')
23
- .value;
24
- const appName = inputs.find((option) => option.name === 'project')
25
- .value;
26
- const spec = inputs.find((option) => option.name === 'spec');
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
- ? (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName)
25
+ ? getValueOrDefault(configuration, 'sourceRoot', appName)
35
26
  : configuration.sourceRoot;
36
- const specValue = spec.value;
37
- const flatValue = !!flat?.value;
38
- const specFileSuffixValue = specFileSuffix.value;
39
- const specOptions = spec.options;
40
- let generateSpec = (0, project_utils_1.shouldGenerateSpec)(configuration, schematic, appName, specValue, specOptions.passedAsInput);
41
- let generateFlat = (0, project_utils_1.shouldGenerateFlat)(configuration, appName, flatValue);
42
- let generateSpecFileSuffix = (0, project_utils_1.getSpecFileSuffix)(configuration, appName, specFileSuffixValue);
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 ((0, project_utils_1.shouldAskForProject)(schematic, configurationProjects, appName)) {
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 = (0, project_utils_1.moveDefaultProjectToStart)(configuration, defaultProjectName, defaultLabel);
55
- const selectedProjectName = (await (0, project_utils_1.askForProjectName)(ui_1.MESSAGES.PROJECT_SELECTION_QUESTION, projects));
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 = (0, project_utils_1.shouldGenerateSpec)(configuration, schematic, selectedProjectName, specValue, specOptions.passedAsInput);
63
- generateFlat = (0, project_utils_1.shouldGenerateFlat)(configuration, selectedProjectName, flatValue);
64
- generateSpecFileSuffix = (0, project_utils_1.getSpecFileSuffix)(configuration, appName, specFileSuffixValue);
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 schematics_1.SchematicOption('sourceRoot', sourceRoot));
71
- schematicOptions.push(new schematics_1.SchematicOption('spec', generateSpec));
72
- schematicOptions.push(new schematics_1.SchematicOption('flat', generateFlat));
73
- schematicOptions.push(new schematics_1.SchematicOption('specFileSuffix', generateSpecFileSuffix));
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
- const schematicInput = inputs.find((input) => input.name === 'schematic');
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(schematicInput.value, schematicOptions);
69
+ await collection.execute(schematic, schematicOptions);
80
70
  }
81
71
  catch (error) {
82
72
  if (error && error.message) {
83
- console.error((0, ansis_1.red)(error.message));
73
+ console.error(red(error.message));
84
74
  }
85
75
  }
86
76
  };
87
- const mapSchematicOptions = (inputs) => {
88
- const excludedInputNames = ['schematic', 'spec', 'flat', 'specFileSuffix'];
77
+ const mapContextToSchematicOptions = (context) => {
89
78
  const options = [];
90
- inputs.forEach((input) => {
91
- if (!excludedInputNames.includes(input.name) && input.value !== undefined) {
92
- (0, type_assertions_1.assertNonArray)(input.value);
93
- options.push(new schematics_1.SchematicOption(input.name, input.value));
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
  };
@@ -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';