@nestjs/cli 12.0.0-alpha.1 → 12.0.0-alpha.4

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/bin/nest.js CHANGED
File without changes
@@ -1,16 +1,18 @@
1
- import { createRequire } from 'module';
1
+ import { builtinModules, createRequire } from 'module';
2
2
  import { join } from 'path';
3
3
  import { defaultTsconfigFilename } from '../../configuration/defaults.js';
4
4
  import { appendTsExtension } from '../helpers/append-extension.js';
5
5
  const require = createRequire(import.meta.url);
6
6
  function loadRspackDeps() {
7
7
  try {
8
+ const rspack = require('@rspack/core');
8
9
  const externals = require('webpack-node-externals');
9
10
  const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin');
10
- return { nodeExternals: externals, TsconfigPathsPlugin };
11
+ return { nodeExternals: externals, TsconfigPathsPlugin, rspack };
11
12
  }
12
13
  catch (e) {
13
- const pkg = e?.message?.match?.(/Cannot find.*'([^']+)'/)?.[1] ?? 'webpack-node-externals';
14
+ const pkg = e?.message?.match?.(/Cannot find.*'([^']+)'/)?.[1] ??
15
+ 'webpack-node-externals';
14
16
  throw new Error(`The "${pkg}" package is required when using the rspack compiler but could not be found. ` +
15
17
  `Please install it:\n\n npm install --save-dev @rspack/core webpack-node-externals tsconfig-paths-webpack-plugin\n`);
16
18
  }
@@ -28,16 +30,32 @@ export const rspackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilen
28
30
  module: true,
29
31
  library: { type: 'module' },
30
32
  chunkFormat: 'module',
33
+ chunkLoading: 'import',
31
34
  }),
32
35
  },
33
36
  ...(isEsm && {
34
- experiments: { outputModule: true },
37
+ experiments: { outputModule: true, topLevelAwait: true },
35
38
  }),
36
39
  ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
37
40
  externals: [
38
41
  externals(isEsm ? { importType: 'module' } : {}),
42
+ ...(isEsm
43
+ ? [
44
+ ({ request }, callback) => {
45
+ if (!request)
46
+ return callback();
47
+ const bare = request.startsWith('node:')
48
+ ? request.slice(5)
49
+ : request;
50
+ if (builtinModules.includes(bare)) {
51
+ return callback(null, `module ${request}`);
52
+ }
53
+ callback();
54
+ },
55
+ ]
56
+ : []),
39
57
  ],
40
- externalsPresets: { node: true },
58
+ externalsPresets: { node: !isEsm },
41
59
  module: {
42
60
  rules: [
43
61
  {
@@ -62,11 +80,18 @@ export const rspackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilen
62
80
  },
63
81
  ],
64
82
  exclude: /node_modules/,
83
+ ...(isEsm && { type: 'javascript/esm' }),
65
84
  },
66
85
  ],
67
86
  },
68
87
  resolve: {
69
88
  extensions: ['.tsx', '.ts', '.js'],
89
+ ...(isEsm && {
90
+ extensionAlias: {
91
+ '.js': ['.ts', '.js'],
92
+ '.mjs': ['.mts', '.mjs'],
93
+ },
94
+ }),
70
95
  tsConfig: tsConfigFile,
71
96
  plugins: [
72
97
  new TsconfigPathsPlugin({
@@ -1,3 +1,3 @@
1
- import { MultiNestCompilerPlugins } from '../plugins/plugins-loader.js';
2
1
  import type webpack from 'webpack';
3
- export declare const webpackDefaultsFactory: (sourceRoot: string, relativeSourceRoot: string, entryFilename: string, isDebugEnabled: boolean | undefined, tsConfigFile: string | undefined, plugins: MultiNestCompilerPlugins, isEsm?: boolean) => webpack.Configuration;
2
+ import { MultiNestCompilerPlugins } from '../plugins/plugins-loader.js';
3
+ export declare const webpackDefaultsFactory: (sourceRoot: string, relativeSourceRoot: string, entryFilename: string, isDebugEnabled: boolean | undefined, tsConfigFile: string | undefined, plugins: MultiNestCompilerPlugins) => webpack.Configuration;
@@ -16,8 +16,8 @@ function loadWebpackDeps() {
16
16
  `Please install it:\n\n npm install --save-dev webpack webpack-node-externals tsconfig-paths-webpack-plugin ts-loader fork-ts-checker-webpack-plugin\n`);
17
17
  }
18
18
  }
19
- export const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, isDebugEnabled = false, tsConfigFile = defaultTsconfigFilename, plugins, isEsm = false) => {
20
- const { webpack: wp, nodeExternals: externals, TsconfigPathsPlugin } = loadWebpackDeps();
19
+ export const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilename, isDebugEnabled = false, tsConfigFile = defaultTsconfigFilename, plugins) => {
20
+ const { webpack: wp, nodeExternals: externals, TsconfigPathsPlugin, } = loadWebpackDeps();
21
21
  const isPluginRegistered = isAnyPluginRegistered(plugins);
22
22
  const webpackConfiguration = {
23
23
  entry: appendTsExtension(join(sourceRoot, entryFilename)),
@@ -25,19 +25,9 @@ export const webpackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFile
25
25
  target: 'node',
26
26
  output: {
27
27
  filename: join(relativeSourceRoot, `${entryFilename}.js`),
28
- ...(isEsm && {
29
- module: true,
30
- library: { type: 'module' },
31
- chunkFormat: 'module',
32
- }),
33
28
  },
34
- ...(isEsm && {
35
- experiments: { outputModule: true },
36
- }),
37
29
  ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
38
- externals: [
39
- externals(isEsm ? { importType: 'module' } : {}),
40
- ],
30
+ externals: [externals()],
41
31
  externalsPresets: { node: true },
42
32
  module: {
43
33
  rules: [
@@ -6,6 +6,9 @@ import { isEsmProject } from '../utils/is-esm-project.js';
6
6
  import { BaseCompiler } from './base-compiler.js';
7
7
  import { webpackDefaultsFactory } from './defaults/webpack-defaults.js';
8
8
  import { getValueOrDefault } from './helpers/get-value-or-default.js';
9
+ const WEBPACK_DEPRECATION_MSG = 'The webpack compiler is deprecated and will be removed in a future major version. ' +
10
+ 'Please migrate to rspack (--builder rspack). ' +
11
+ 'See https://docs.nestjs.com/cli/usages#build for details.';
9
12
  const require = createRequire(import.meta.url);
10
13
  function loadWebpack() {
11
14
  try {
@@ -30,7 +33,13 @@ export class WebpackCompiler extends BaseCompiler {
30
33
  const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
31
34
  const entryFile = getValueOrDefault(configuration, 'entryFile', appName, 'entryFile', extras.options);
32
35
  const entryFileRoot = getValueOrDefault(configuration, 'root', appName) || '';
33
- const defaultOptions = webpackDefaultsFactory(pathToSource, entryFileRoot, entryFile, extras.debug ?? false, tsConfigPath, plugins, isEsmProject());
36
+ if (isEsmProject()) {
37
+ throw new Error('The webpack compiler does not support ESM projects ("type": "module" in package.json). ' +
38
+ 'Please use rspack instead by setting "builder": "rspack" in your nest-cli.json compilerOptions, ' +
39
+ 'or use --builder rspack on the command line.');
40
+ }
41
+ console.warn(`\n${INFO_PREFIX} ${WEBPACK_DEPRECATION_MSG}\n`);
42
+ const defaultOptions = webpackDefaultsFactory(pathToSource, entryFileRoot, entryFile, extras.debug ?? false, tsConfigPath, plugins);
34
43
  const wp = loadWebpack();
35
44
  let compiler;
36
45
  let watchOptions;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "12.0.0-alpha.1",
3
+ "version": "12.0.0-alpha.4",
4
4
  "type": "module",
5
5
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
6
6
  "publishConfig": {
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "build": "tsc",
17
- "clean": "gulp clean:bundle",
17
+ "clean": "node tools/clean.js",
18
18
  "format": "prettier --write \"**/*.ts\"",
19
19
  "lint": "eslint 'lib/**/*.ts' 'commands/**/*.ts' 'actions/**/*.ts' --fix",
20
20
  "start": "node bin/nest.js",
@@ -58,15 +58,15 @@
58
58
  "devDependencies": {
59
59
  "@commitlint/cli": "20.4.3",
60
60
  "@commitlint/config-angular": "20.4.3",
61
+ "@eslint/js": "10.0.1",
62
+ "@rspack/core": "^1.7.7",
61
63
  "@swc/cli": "0.8.0",
62
64
  "@swc/core": "1.15.18",
63
65
  "@types/node": "24.10.13",
64
66
  "@types/webpack-node-externals": "3.0.4",
65
- "@eslint/js": "10.0.1",
66
67
  "delete-empty": "3.0.0",
67
68
  "eslint": "10.0.2",
68
69
  "eslint-config-prettier": "10.1.8",
69
- "typescript-eslint": "8.56.1",
70
70
  "fork-ts-checker-webpack-plugin": "9.1.0",
71
71
  "gulp": "5.0.1",
72
72
  "gulp-clean": "0.4.0",
@@ -76,6 +76,7 @@
76
76
  "release-it": "19.2.4",
77
77
  "ts-loader": "9.5.4",
78
78
  "tsconfig-paths-webpack-plugin": "4.2.0",
79
+ "typescript-eslint": "8.56.1",
79
80
  "vitest": "3.2.4",
80
81
  "webpack": "5.105.4",
81
82
  "webpack-node-externals": "3.0.0"