@nestjs/cli 11.0.16 → 12.0.0-alpha.1

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 (184) 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 +138 -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 +3 -3
  60. package/lib/compiler/defaults/webpack-defaults.js +36 -18
  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 +105 -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 +30 -22
  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-esm-project.d.ts +5 -0
  171. package/lib/utils/is-esm-project.js +16 -0
  172. package/lib/utils/is-module-available.js +3 -4
  173. package/lib/utils/load-configuration.d.ts +1 -1
  174. package/lib/utils/load-configuration.js +4 -7
  175. package/lib/utils/local-binaries.d.ts +1 -1
  176. package/lib/utils/local-binaries.js +8 -11
  177. package/lib/utils/os-info.utils.js +1 -4
  178. package/lib/utils/project-utils.d.ts +1 -3
  179. package/lib/utils/project-utils.js +16 -28
  180. package/lib/utils/remaining-flags.d.ts +2 -2
  181. package/lib/utils/remaining-flags.js +2 -5
  182. package/lib/utils/tree-kill.js +7 -10
  183. package/lib/utils/type-assertions.js +1 -4
  184. package/package.json +59 -38
@@ -1,12 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.tsconfigPathsBeforeHookFactory = tsconfigPathsBeforeHookFactory;
4
- const os = require("os");
5
- const path_1 = require("path");
6
- const typescript_loader_1 = require("../typescript-loader");
7
- const tsPaths = require("tsconfig-paths");
8
- function tsconfigPathsBeforeHookFactory(compilerOptions) {
9
- const tsBinary = new typescript_loader_1.TypeScriptBinaryLoader().load();
1
+ import { createRequire } from 'module';
2
+ import { dirname, posix } from 'path';
3
+ import * as tsPaths from 'tsconfig-paths';
4
+ import { TypeScriptBinaryLoader } from '../typescript-loader.js';
5
+ const require = createRequire(import.meta.url);
6
+ export function tsconfigPathsBeforeHookFactory(compilerOptions) {
7
+ const tsBinary = new TypeScriptBinaryLoader().load();
10
8
  const { paths = {}, baseUrl = './' } = compilerOptions;
11
9
  const matcher = tsPaths.createMatchPath(baseUrl, paths, ['main']);
12
10
  return (ctx) => {
@@ -57,20 +55,22 @@ function getNotAliasedPath(sf, matcher, text) {
57
55
  if (!result) {
58
56
  return;
59
57
  }
60
- if (os.platform() === 'win32') {
58
+ if (process.platform === 'win32') {
61
59
  result = result.replace(/\\/g, '/');
62
60
  }
63
61
  try {
64
62
  // Installed packages (node modules) should take precedence over root files with the same name.
65
63
  // Ref: https://github.com/nestjs/nest-cli/issues/838
66
64
  const packagePath = require.resolve(text, {
67
- paths: [process.cwd(), ...module.paths],
65
+ paths: [process.cwd(), ...(require.resolve.paths(text) ?? [])],
68
66
  });
69
67
  if (packagePath) {
70
68
  return text;
71
69
  }
72
70
  }
73
- catch { }
74
- const resolvedPath = path_1.posix.relative((0, path_1.dirname)(sf.fileName), result) || './';
71
+ catch {
72
+ // package resolution failed, fall through to relative path
73
+ }
74
+ const resolvedPath = posix.relative(dirname(sf.fileName), result) || './';
75
75
  return resolvedPath[0] === '.' ? resolvedPath : './' + resolvedPath;
76
76
  }
@@ -1,2 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
1
+ export {};
@@ -1,5 +1,5 @@
1
1
  import * as ts from 'typescript';
2
- import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
2
+ import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface.js';
3
3
  export interface PluginMetadataGenerateOptions {
4
4
  /**
5
5
  * The visitors to use to generate the metadata.
@@ -1,10 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginMetadataGenerator = void 0;
4
- const constants_1 = require("../swc/constants");
5
- const type_checker_host_1 = require("../swc/type-checker-host");
6
- const typescript_loader_1 = require("../typescript-loader");
7
- const plugin_metadata_printer_1 = require("./plugin-metadata-printer");
1
+ import { FOUND_NO_ISSUES_GENERATING_METADATA } from '../swc/constants.js';
2
+ import { TypeCheckerHost } from '../swc/type-checker-host.js';
3
+ import { TypeScriptBinaryLoader } from '../typescript-loader.js';
4
+ import { PluginMetadataPrinter } from './plugin-metadata-printer.js';
8
5
  /**
9
6
  * Generates plugins metadata by traversing the AST of the project.
10
7
  * @example
@@ -20,11 +17,12 @@ const plugin_metadata_printer_1 = require("./plugin-metadata-printer");
20
17
  * });
21
18
  * ```
22
19
  */
23
- class PluginMetadataGenerator {
20
+ export class PluginMetadataGenerator {
21
+ pluginMetadataPrinter = new PluginMetadataPrinter();
22
+ typeCheckerHost = new TypeCheckerHost();
23
+ typescriptLoader = new TypeScriptBinaryLoader();
24
+ tsBinary;
24
25
  constructor() {
25
- this.pluginMetadataPrinter = new plugin_metadata_printer_1.PluginMetadataPrinter();
26
- this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
27
- this.typescriptLoader = new typescript_loader_1.TypeScriptBinaryLoader();
28
26
  this.tsBinary = this.typescriptLoader.load();
29
27
  }
30
28
  generate(options) {
@@ -50,7 +48,7 @@ class PluginMetadataGenerator {
50
48
  console.log(tsBinary.formatDiagnosticsWithColorAndContext(diagnostics, formatDiagnosticsHost));
51
49
  }
52
50
  else {
53
- console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
51
+ console.log(FOUND_NO_ISSUES_GENERATING_METADATA);
54
52
  }
55
53
  }
56
54
  };
@@ -81,4 +79,3 @@ class PluginMetadataGenerator {
81
79
  }, this.tsBinary);
82
80
  }
83
81
  }
84
- exports.PluginMetadataGenerator = PluginMetadataGenerator;
@@ -1,5 +1,5 @@
1
1
  import * as ts from 'typescript';
2
- import { DeepPluginMeta } from '../interfaces/readonly-visitor.interface';
2
+ import { DeepPluginMeta } from '../interfaces/readonly-visitor.interface.js';
3
3
  export interface PluginMetadataPrintOptions {
4
4
  outputDir: string;
5
5
  filename?: string;
@@ -1,14 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginMetadataPrinter = void 0;
4
- const fs_1 = require("fs");
5
- const path_1 = require("path");
1
+ import { writeFileSync } from 'fs';
2
+ import { join } from 'path';
6
3
  const SERIALIZED_METADATA_FILENAME = 'metadata.ts';
7
4
  const TYPE_IMPORT_VARIABLE_NAME = 't';
8
5
  /**
9
6
  * Prints the metadata to a file.
10
7
  */
11
- class PluginMetadataPrinter {
8
+ export class PluginMetadataPrinter {
12
9
  print(metadata, typeImports, options, tsBinary) {
13
10
  const objectLiteralExpr = tsBinary.factory.createObjectLiteralExpression(Object.keys(metadata).map((key) => this.recursivelyCreatePropertyAssignment(key, metadata[key], tsBinary)));
14
11
  const exportAssignment = tsBinary.factory.createExportAssignment(undefined, undefined, tsBinary.factory.createArrowFunction([tsBinary.factory.createToken(tsBinary.SyntaxKind.AsyncKeyword)], undefined, [], undefined, tsBinary.factory.createToken(tsBinary.SyntaxKind.EqualsGreaterThanToken), tsBinary.factory.createBlock([
@@ -20,9 +17,9 @@ class PluginMetadataPrinter {
20
17
  });
21
18
  const resultFile = tsBinary.createSourceFile('file.ts', '', tsBinary.ScriptTarget.Latest,
22
19
  /*setParentNodes*/ false, tsBinary.ScriptKind.TS);
23
- const filename = (0, path_1.join)(options.outputDir, options.filename ?? SERIALIZED_METADATA_FILENAME);
20
+ const filename = join(options.outputDir, options.filename ?? SERIALIZED_METADATA_FILENAME);
24
21
  const eslintPrefix = `/* eslint-disable */\n`;
25
- (0, fs_1.writeFileSync)(filename, eslintPrefix +
22
+ writeFileSync(filename, eslintPrefix +
26
23
  printer.printNode(tsBinary.EmitHint.Unspecified, exportAssignment, resultFile));
27
24
  }
28
25
  recursivelyCreatePropertyAssignment(identifier, meta, tsBinary) {
@@ -48,4 +45,3 @@ class PluginMetadataPrinter {
48
45
  return tsBinary.factory.createPropertyAssignment(tsBinary.factory.createComputedPropertyName(tsBinary.factory.createStringLiteral(identifier)), tsBinary.factory.createIdentifier(target));
49
46
  }
50
47
  }
51
- exports.PluginMetadataPrinter = PluginMetadataPrinter;
@@ -1,10 +1,10 @@
1
1
  import * as ts from 'typescript';
2
- import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface';
2
+ import { ReadonlyVisitor } from '../interfaces/readonly-visitor.interface.js';
3
3
  type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
4
4
  type PluginEntry = string | PluginAndOptions;
5
5
  type PluginOptions = Record<string, any>;
6
6
  interface PluginAndOptions {
7
- name: 'string';
7
+ name: string;
8
8
  options: PluginOptions;
9
9
  }
10
10
  export interface NestCompilerPlugin {
@@ -1,10 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginsLoader = void 0;
4
- const path_1 = require("path");
5
- const ui_1 = require("../../ui");
1
+ import { createRequire } from 'module';
2
+ import { join } from 'path';
3
+ import { CLI_ERRORS } from '../../ui/index.js';
4
+ const require = createRequire(import.meta.url);
6
5
  const PLUGIN_ENTRY_FILENAME = 'plugin';
7
- class PluginsLoader {
6
+ export class PluginsLoader {
8
7
  load(plugins = [], extras = {}) {
9
8
  const pluginNames = plugins.map((entry) => typeof entry === 'object'
10
9
  ? entry.name
@@ -18,7 +17,7 @@ class PluginsLoader {
18
17
  };
19
18
  pluginRefs.forEach((plugin, index) => {
20
19
  if (!plugin.before && !plugin.after && !plugin.afterDeclarations) {
21
- throw new Error(ui_1.CLI_ERRORS.WRONG_PLUGIN(pluginNames[index]));
20
+ throw new Error(CLI_ERRORS.WRONG_PLUGIN(pluginNames[index]));
22
21
  }
23
22
  const options = typeof plugins[index] === 'object'
24
23
  ? plugins[index].options || {}
@@ -46,25 +45,26 @@ class PluginsLoader {
46
45
  }
47
46
  resolvePluginReferences(pluginNames) {
48
47
  const nodeModulePaths = [
49
- (0, path_1.join)(process.cwd(), 'node_modules'),
50
- ...module.paths,
48
+ join(process.cwd(), 'node_modules'),
49
+ ...(require.resolve.paths('typescript') ?? []),
51
50
  ];
52
51
  return pluginNames.map((item) => {
53
52
  try {
54
53
  try {
55
- const binaryPath = require.resolve((0, path_1.join)(item, PLUGIN_ENTRY_FILENAME), {
54
+ const binaryPath = require.resolve(join(item, PLUGIN_ENTRY_FILENAME), {
56
55
  paths: nodeModulePaths,
57
56
  });
58
57
  return require(binaryPath);
59
58
  }
60
- catch { }
59
+ catch {
60
+ // entry-point resolution failed, try bare module resolve
61
+ }
61
62
  const binaryPath = require.resolve(item, { paths: nodeModulePaths });
62
63
  return require(binaryPath);
63
64
  }
64
65
  catch (e) {
65
- throw new Error(`"${item}" plugin is not installed.`);
66
+ throw new Error(`"${item}" plugin is not installed.`, { cause: e });
66
67
  }
67
68
  });
68
69
  }
69
70
  }
70
- exports.PluginsLoader = PluginsLoader;
@@ -0,0 +1,19 @@
1
+ import { Configuration } from '../configuration/index.js';
2
+ import { AssetsManager } from './assets-manager.js';
3
+ import { BaseCompiler } from './base-compiler.js';
4
+ import { PluginsLoader } from './plugins/plugins-loader.js';
5
+ type RspackConfigFactory = (config: Record<string, any>, rspackRef: any) => Record<string, any>;
6
+ type RspackConfigFactoryOrConfig = RspackConfigFactory | Record<string, any>;
7
+ type RspackCompilerExtras = {
8
+ options: Record<string, any>;
9
+ assetsManager: AssetsManager;
10
+ rspackConfigFactoryOrConfig: RspackConfigFactoryOrConfig | RspackConfigFactoryOrConfig[];
11
+ debug?: boolean;
12
+ watchMode?: boolean;
13
+ };
14
+ export declare class RspackCompiler extends BaseCompiler<RspackCompilerExtras> {
15
+ constructor(pluginsLoader: PluginsLoader);
16
+ run(configuration: Required<Configuration>, tsConfigPath: string, appName: string | undefined, extras: RspackCompilerExtras, onSuccess?: () => void): void;
17
+ private createAfterCallback;
18
+ }
19
+ export {};
@@ -0,0 +1,105 @@
1
+ import { existsSync } from 'fs';
2
+ import { createRequire } from 'module';
3
+ import { join } from 'path';
4
+ import { INFO_PREFIX } from '../ui/index.js';
5
+ import { isEsmProject } from '../utils/is-esm-project.js';
6
+ import { BaseCompiler } from './base-compiler.js';
7
+ import { rspackDefaultsFactory } from './defaults/rspack-defaults.js';
8
+ import { getValueOrDefault } from './helpers/get-value-or-default.js';
9
+ const require = createRequire(import.meta.url);
10
+ export class RspackCompiler extends BaseCompiler {
11
+ constructor(pluginsLoader) {
12
+ super(pluginsLoader);
13
+ }
14
+ run(configuration, tsConfigPath, appName, extras, onSuccess) {
15
+ const cwd = process.cwd();
16
+ const configPath = join(cwd, tsConfigPath);
17
+ if (!existsSync(configPath)) {
18
+ throw new Error(`Could not find TypeScript configuration file "${tsConfigPath}".`);
19
+ }
20
+ const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
21
+ const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
22
+ const entryFile = getValueOrDefault(configuration, 'entryFile', appName, 'entryFile', extras.options);
23
+ const entryFileRoot = getValueOrDefault(configuration, 'root', appName) || '';
24
+ const defaultOptions = rspackDefaultsFactory(pathToSource, entryFileRoot, entryFile, extras.debug ?? false, tsConfigPath, plugins, isEsmProject());
25
+ let rspack;
26
+ try {
27
+ rspack = require('@rspack/core');
28
+ }
29
+ catch {
30
+ throw new Error('@rspack/core is not installed. To use the rspack compiler, install the required packages:\n\n' +
31
+ ' npm install --save-dev @rspack/core webpack-node-externals tsconfig-paths-webpack-plugin\n');
32
+ }
33
+ let compiler;
34
+ let watchOptions;
35
+ let watch;
36
+ if (Array.isArray(extras.rspackConfigFactoryOrConfig)) {
37
+ const rspackConfigurations = extras.rspackConfigFactoryOrConfig.map((configOrFactory) => {
38
+ const unwrappedConfig = typeof configOrFactory !== 'function'
39
+ ? configOrFactory
40
+ : configOrFactory(defaultOptions, rspack);
41
+ return {
42
+ ...defaultOptions,
43
+ mode: extras.watchMode ? 'development' : defaultOptions.mode,
44
+ ...unwrappedConfig,
45
+ };
46
+ });
47
+ compiler = rspack.rspack(rspackConfigurations);
48
+ watchOptions = rspackConfigurations.map((config) => config.watchOptions || {});
49
+ watch = rspackConfigurations.some((config) => config.watch);
50
+ }
51
+ else {
52
+ const projectRspackOptions = typeof extras.rspackConfigFactoryOrConfig !== 'function'
53
+ ? extras.rspackConfigFactoryOrConfig
54
+ : extras.rspackConfigFactoryOrConfig(defaultOptions, rspack);
55
+ const rspackConfiguration = {
56
+ ...defaultOptions,
57
+ mode: extras.watchMode ? 'development' : defaultOptions.mode,
58
+ ...projectRspackOptions,
59
+ };
60
+ compiler = rspack.rspack(rspackConfiguration);
61
+ watchOptions = rspackConfiguration.watchOptions;
62
+ watch = rspackConfiguration.watch;
63
+ }
64
+ const afterCallback = this.createAfterCallback(onSuccess, extras.assetsManager, extras.watchMode ?? false, watch);
65
+ if (extras.watchMode || watch) {
66
+ compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
67
+ console.log(`\n${INFO_PREFIX} Rspack is building your sources...\n`);
68
+ callback();
69
+ });
70
+ compiler.watch(watchOptions || {}, afterCallback);
71
+ }
72
+ else {
73
+ compiler.run(afterCallback);
74
+ }
75
+ }
76
+ createAfterCallback(onSuccess, assetsManager, watchMode, watch) {
77
+ return (err, stats) => {
78
+ if (err && stats === undefined) {
79
+ // Could not complete the compilation
80
+ // The error caught is most likely thrown by underlying tasks
81
+ console.log(err);
82
+ return process.exit(1);
83
+ }
84
+ const statsOutput = stats.toString({
85
+ chunks: false,
86
+ colors: true,
87
+ modules: false,
88
+ assets: false,
89
+ });
90
+ if (!err && !stats.hasErrors()) {
91
+ if (!onSuccess) {
92
+ assetsManager.closeWatchers();
93
+ }
94
+ else {
95
+ onSuccess();
96
+ }
97
+ }
98
+ else if (!watchMode && !watch) {
99
+ console.log(statsOutput);
100
+ return process.exit(1);
101
+ }
102
+ console.log(statsOutput);
103
+ };
104
+ }
105
+ }
@@ -1,5 +1,4 @@
1
1
  export declare const TSC_NO_ERRORS_MESSAGE = "Found 0 errors. Watching for file changes.";
2
- export declare const TSC_COMPILATION_STARTED_MESSAGE = "Starting compilation in watch mode...";
3
2
  export declare const SWC_LOG_PREFIX: string;
4
3
  export declare const TSC_LOG_PREFIX: string;
5
4
  export declare const TSC_LOG_ERROR_PREFIX: string;
@@ -1,13 +1,9 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FOUND_NO_ISSUES_GENERATING_METADATA = exports.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = exports.INITIALIZING_TYPE_CHECKER = exports.TSC_LOG_SUCCESS_PREFIX = exports.TSC_LOG_ERROR_PREFIX = exports.TSC_LOG_PREFIX = exports.SWC_LOG_PREFIX = exports.TSC_COMPILATION_STARTED_MESSAGE = exports.TSC_NO_ERRORS_MESSAGE = void 0;
4
- const ansis_1 = require("ansis");
5
- exports.TSC_NO_ERRORS_MESSAGE = 'Found 0 errors. Watching for file changes.';
6
- exports.TSC_COMPILATION_STARTED_MESSAGE = 'Starting compilation in watch mode...';
7
- exports.SWC_LOG_PREFIX = (0, ansis_1.cyan)('> ') + ansis_1.bgCyan.bold(' SWC ');
8
- exports.TSC_LOG_PREFIX = (0, ansis_1.cyan)('> ') + ansis_1.bgCyan.bold(' TSC ');
9
- exports.TSC_LOG_ERROR_PREFIX = (0, ansis_1.red)('> ') + ansis_1.bgRed.bold(' TSC ');
10
- exports.TSC_LOG_SUCCESS_PREFIX = (0, ansis_1.green)('> ') + ansis_1.bgGreen.bold(' TSC ');
11
- exports.INITIALIZING_TYPE_CHECKER = ansis_1.bgCyan.bold(' TSC ') + (0, ansis_1.cyan)(' Initializing type checker...');
12
- exports.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = exports.TSC_LOG_SUCCESS_PREFIX + (0, ansis_1.green)(' Found 0 issues.');
13
- exports.FOUND_NO_ISSUES_GENERATING_METADATA = exports.TSC_LOG_SUCCESS_PREFIX + (0, ansis_1.green)(' Found 0 issues. Generating metadata...');
1
+ import { bgCyan, bgGreen, bgRed, cyan, green, red } from 'ansis';
2
+ export const TSC_NO_ERRORS_MESSAGE = 'Found 0 errors. Watching for file changes.';
3
+ export const SWC_LOG_PREFIX = cyan('> ') + bgCyan.bold(' SWC ');
4
+ export const TSC_LOG_PREFIX = cyan('> ') + bgCyan.bold(' TSC ');
5
+ export const TSC_LOG_ERROR_PREFIX = red('> ') + bgRed.bold(' TSC ');
6
+ export const TSC_LOG_SUCCESS_PREFIX = green('> ') + bgGreen.bold(' TSC ');
7
+ export const INITIALIZING_TYPE_CHECKER = bgCyan.bold(' TSC ') + cyan(' Initializing type checker...');
8
+ export const FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED = TSC_LOG_SUCCESS_PREFIX + green(' Found 0 issues.');
9
+ export const FOUND_NO_ISSUES_GENERATING_METADATA = TSC_LOG_SUCCESS_PREFIX + green(' Found 0 issues. Generating metadata...');
@@ -1,25 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const ui_1 = require("../../ui");
4
- const base_compiler_1 = require("../base-compiler");
5
- const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
6
- const plugins_loader_1 = require("../plugins/plugins-loader");
7
- const constants_1 = require("./constants");
8
- const type_checker_host_1 = require("./type-checker-host");
1
+ import { ERROR_PREFIX } from '../../ui/index.js';
2
+ import { BaseCompiler } from '../base-compiler.js';
3
+ import { PluginMetadataGenerator } from '../plugins/plugin-metadata-generator.js';
4
+ import { PluginsLoader } from '../plugins/plugins-loader.js';
5
+ import { FOUND_NO_ISSUES_GENERATING_METADATA, FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED, } from './constants.js';
6
+ import { TypeCheckerHost } from './type-checker-host.js';
9
7
  const [tsConfigPath, appName, sourceRoot, plugins] = process.argv.slice(2);
10
- class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
11
- constructor() {
12
- super(...arguments);
13
- this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
14
- this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
15
- }
8
+ class ForkedTypeChecker extends BaseCompiler {
9
+ pluginMetadataGenerator = new PluginMetadataGenerator();
10
+ typeCheckerHost = new TypeCheckerHost();
16
11
  async run(configuration, tsConfigPath, appName, extras) {
17
12
  const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
18
13
  const outputDir = this.getPathToSource(configuration, tsConfigPath, appName);
19
14
  try {
20
15
  const onTypeCheckOrProgramInit = (program) => {
21
16
  if (readonlyVisitors.length > 0) {
22
- console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA);
17
+ console.log(FOUND_NO_ISSUES_GENERATING_METADATA);
23
18
  this.pluginMetadataGenerator.generate({
24
19
  outputDir,
25
20
  visitors: readonlyVisitors,
@@ -27,7 +22,7 @@ class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
27
22
  });
28
23
  }
29
24
  else {
30
- console.log(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED);
25
+ console.log(FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED);
31
26
  }
32
27
  };
33
28
  this.typeCheckerHost.run(tsConfigPath, {
@@ -37,11 +32,11 @@ class ForkedTypeChecker extends base_compiler_1.BaseCompiler {
37
32
  });
38
33
  }
39
34
  catch (err) {
40
- console.log(ui_1.ERROR_PREFIX, err.message);
35
+ console.error(ERROR_PREFIX, err.message);
41
36
  }
42
37
  }
43
38
  }
44
- const pluginsLoader = new plugins_loader_1.PluginsLoader();
39
+ const pluginsLoader = new PluginsLoader();
45
40
  const forkedTypeChecker = new ForkedTypeChecker(pluginsLoader);
46
41
  const applicationName = appName === 'undefined' ? '' : appName;
47
42
  const options = {
@@ -1,8 +1,8 @@
1
1
  import * as ts from 'typescript';
2
- import { Configuration } from '../../configuration';
3
- import { AssetsManager } from '../assets-manager';
4
- import { BaseCompiler } from '../base-compiler';
5
- import { PluginsLoader } from '../plugins/plugins-loader';
2
+ import { Configuration } from '../../configuration/index.js';
3
+ import { AssetsManager } from '../assets-manager.js';
4
+ import { BaseCompiler } from '../base-compiler.js';
5
+ import { PluginsLoader } from '../plugins/plugins-loader.js';
6
6
  export type SwcCompilerExtras = {
7
7
  watch: boolean;
8
8
  typeCheck: boolean;
@@ -1,30 +1,33 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SwcCompiler = void 0;
4
- const ansis_1 = require("ansis");
5
- const child_process_1 = require("child_process");
6
- const chokidar = require("chokidar");
7
- const fs_1 = require("fs");
8
- const promises_1 = require("fs/promises");
9
- const path = require("path");
10
- const path_1 = require("path");
11
- const ui_1 = require("../../ui");
12
- const tree_kill_1 = require("../../utils/tree-kill");
13
- const base_compiler_1 = require("../base-compiler");
14
- const swc_defaults_1 = require("../defaults/swc-defaults");
15
- const get_value_or_default_1 = require("../helpers/get-value-or-default");
16
- const plugin_metadata_generator_1 = require("../plugins/plugin-metadata-generator");
17
- const constants_1 = require("./constants");
18
- const type_checker_host_1 = require("./type-checker-host");
19
- class SwcCompiler extends base_compiler_1.BaseCompiler {
1
+ import { cyan } from 'ansis';
2
+ import { fork } from 'child_process';
3
+ import * as chokidar from 'chokidar';
4
+ import { readFileSync } from 'fs';
5
+ import { stat } from 'fs/promises';
6
+ import { createRequire } from 'module';
7
+ import * as path from 'path';
8
+ import { isAbsolute, join } from 'path';
9
+ import { fileURLToPath } from 'url';
10
+ import { dirname } from 'path';
11
+ import { ERROR_PREFIX } from '../../ui/index.js';
12
+ import { treeKillSync } from '../../utils/tree-kill.js';
13
+ import { BaseCompiler } from '../base-compiler.js';
14
+ import { swcDefaultsFactory } from '../defaults/swc-defaults.js';
15
+ import { getValueOrDefault } from '../helpers/get-value-or-default.js';
16
+ import { PluginMetadataGenerator } from '../plugins/plugin-metadata-generator.js';
17
+ import { FOUND_NO_ISSUES_GENERATING_METADATA, FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED, SWC_LOG_PREFIX, } from './constants.js';
18
+ import { TypeCheckerHost } from './type-checker-host.js';
19
+ const __filename = fileURLToPath(import.meta.url);
20
+ const __dirname = dirname(__filename);
21
+ const require = createRequire(import.meta.url);
22
+ export class SwcCompiler extends BaseCompiler {
23
+ pluginMetadataGenerator = new PluginMetadataGenerator();
24
+ typeCheckerHost = new TypeCheckerHost();
20
25
  constructor(pluginsLoader) {
21
26
  super(pluginsLoader);
22
- this.pluginMetadataGenerator = new plugin_metadata_generator_1.PluginMetadataGenerator();
23
- this.typeCheckerHost = new type_checker_host_1.TypeCheckerHost();
24
27
  }
25
28
  async run(configuration, tsConfigPath, appName, extras, onSuccess) {
26
- const swcOptions = (0, swc_defaults_1.swcDefaultsFactory)(extras.tsOptions, configuration);
27
- const swcrcFilePath = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.builder.options.swcrcPath', appName);
29
+ const swcOptions = swcDefaultsFactory(extras.tsOptions, configuration);
30
+ const swcrcFilePath = getValueOrDefault(configuration, 'compilerOptions.builder.options.swcrcPath', appName);
28
31
  if (extras.watch) {
29
32
  if (extras.typeCheck) {
30
33
  this.runTypeChecker(configuration, tsConfigPath, appName, extras);
@@ -56,10 +59,10 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
56
59
  configuration.sourceRoot ?? 'src',
57
60
  JSON.stringify(configuration.compilerOptions.plugins ?? []),
58
61
  ];
59
- const childProcessRef = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'forked-type-checker.js'), args, {
62
+ const childProcessRef = fork(join(__dirname, 'forked-type-checker.js'), args, {
60
63
  cwd: process.cwd(),
61
64
  });
62
- process.on('exit', () => childProcessRef && (0, tree_kill_1.treeKillSync)(childProcessRef.pid));
65
+ process.on('exit', () => childProcessRef && treeKillSync(childProcessRef.pid));
63
66
  }
64
67
  else {
65
68
  const { readonlyVisitors } = this.loadPlugins(configuration, tsConfigPath, appName);
@@ -75,7 +78,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
75
78
  resolve();
76
79
  }
77
80
  if (readonlyVisitors.length > 0) {
78
- process.nextTick(() => console.log(constants_1.FOUND_NO_ISSUES_GENERATING_METADATA));
81
+ process.nextTick(() => console.log(FOUND_NO_ISSUES_GENERATING_METADATA));
79
82
  this.pluginMetadataGenerator.generate({
80
83
  outputDir,
81
84
  visitors: readonlyVisitors,
@@ -83,7 +86,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
83
86
  });
84
87
  }
85
88
  else {
86
- process.nextTick(() => console.log(constants_1.FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED));
89
+ process.nextTick(() => console.log(FOUND_NO_ISSUES_METADATA_GENERATION_SKIPPED));
87
90
  }
88
91
  },
89
92
  });
@@ -98,11 +101,11 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
98
101
  }
99
102
  }
100
103
  async runSwc(options, extras, swcrcFilePath) {
101
- process.nextTick(() => console.log(constants_1.SWC_LOG_PREFIX, (0, ansis_1.cyan)('Running...')));
104
+ process.nextTick(() => console.log(SWC_LOG_PREFIX, cyan('Running...')));
102
105
  const swcCli = this.loadSwcCliBinary();
103
106
  const swcRcFile = await this.getSwcRcFileContentIfExists(swcrcFilePath);
104
107
  const swcOptions = this.deepMerge(options.swcOptions, swcRcFile);
105
- if (swcOptions?.jsc?.baseUrl && !(0, path_1.isAbsolute)(swcOptions?.jsc?.baseUrl)) {
108
+ if (swcOptions?.jsc?.baseUrl && !isAbsolute(swcOptions?.jsc?.baseUrl)) {
106
109
  // jsc.baseUrl should be resolved by the caller, if it's passed as an object.
107
110
  // https://github.com/swc-project/swc/pull/7827
108
111
  const rootDir = process.cwd();
@@ -136,19 +139,19 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
136
139
  try {
137
140
  return require('@swc/cli/lib/swc/dir');
138
141
  }
139
- catch (err) {
140
- console.error(ui_1.ERROR_PREFIX +
142
+ catch {
143
+ console.error(ERROR_PREFIX +
141
144
  ' Failed to load "@swc/cli" and/or "@swc/core" required packages. Please, make sure to install them as development dependencies.');
142
145
  process.exit(1);
143
146
  }
144
147
  }
145
148
  getSwcRcFileContentIfExists(swcrcFilePath) {
146
149
  try {
147
- return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(process.cwd(), swcrcFilePath ?? '.swcrc'), 'utf8'));
150
+ return JSON.parse(readFileSync(join(process.cwd(), swcrcFilePath ?? '.swcrc'), 'utf8'));
148
151
  }
149
- catch (err) {
152
+ catch {
150
153
  if (swcrcFilePath !== undefined) {
151
- console.error(ui_1.ERROR_PREFIX +
154
+ console.error(ERROR_PREFIX +
152
155
  ` Failed to load "${swcrcFilePath}". Please, check if the file exists and is valid JSON.`);
153
156
  process.exit(1);
154
157
  }
@@ -170,7 +173,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
170
173
  }
171
174
  const merged = { ...target };
172
175
  for (const key in source) {
173
- if (source.hasOwnProperty(key)) {
176
+ if (Object.hasOwn(source, key)) {
174
177
  if (key in target) {
175
178
  merged[key] = this.deepMerge(target[key], source[key]);
176
179
  }
@@ -190,7 +193,7 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
190
193
  }
191
194
  async watchFilesInSrcDir(options, onFileAdded) {
192
195
  const srcDir = options.cliOptions?.filenames?.[0];
193
- const isDirectory = await (0, promises_1.stat)(srcDir)
196
+ const isDirectory = await stat(srcDir)
194
197
  .then((stats) => stats.isDirectory())
195
198
  .catch(() => false);
196
199
  if (!srcDir || !isDirectory) {
@@ -211,9 +214,9 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
211
214
  watcher.on('add', async (file) => onFileAdded(file));
212
215
  }
213
216
  watchFilesInOutDir(options, onChange) {
214
- const dir = (0, path_1.isAbsolute)(options.cliOptions.outDir)
217
+ const dir = isAbsolute(options.cliOptions.outDir)
215
218
  ? options.cliOptions.outDir
216
- : (0, path_1.join)(process.cwd(), options.cliOptions.outDir);
219
+ : join(process.cwd(), options.cliOptions.outDir);
217
220
  const watcher = chokidar.watch(dir, {
218
221
  ignored: (file, stats) => (stats?.isFile() &&
219
222
  !(file.endsWith('.js') || file.endsWith('.mjs'))),
@@ -228,4 +231,3 @@ class SwcCompiler extends base_compiler_1.BaseCompiler {
228
231
  }
229
232
  }
230
233
  }
231
- exports.SwcCompiler = SwcCompiler;