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

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.
@@ -1,4 +1,4 @@
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';
@@ -28,16 +28,32 @@ export const rspackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilen
28
28
  module: true,
29
29
  library: { type: 'module' },
30
30
  chunkFormat: 'module',
31
+ chunkLoading: 'import',
31
32
  }),
32
33
  },
33
34
  ...(isEsm && {
34
- experiments: { outputModule: true },
35
+ experiments: { outputModule: true, topLevelAwait: true },
35
36
  }),
36
37
  ignoreWarnings: [/^(?!CriticalDependenciesWarning$)/],
37
38
  externals: [
38
39
  externals(isEsm ? { importType: 'module' } : {}),
40
+ ...(isEsm
41
+ ? [
42
+ ({ request }, callback) => {
43
+ if (!request)
44
+ return callback();
45
+ const bare = request.startsWith('node:')
46
+ ? request.slice(5)
47
+ : request;
48
+ if (builtinModules.includes(bare)) {
49
+ return callback(null, `module ${request}`);
50
+ }
51
+ callback();
52
+ },
53
+ ]
54
+ : []),
39
55
  ],
40
- externalsPresets: { node: true },
56
+ externalsPresets: { node: !isEsm },
41
57
  module: {
42
58
  rules: [
43
59
  {
@@ -62,11 +78,18 @@ export const rspackDefaultsFactory = (sourceRoot, relativeSourceRoot, entryFilen
62
78
  },
63
79
  ],
64
80
  exclude: /node_modules/,
81
+ ...(isEsm && { type: 'javascript/esm' }),
65
82
  },
66
83
  ],
67
84
  },
68
85
  resolve: {
69
86
  extensions: ['.tsx', '.ts', '.js'],
87
+ ...(isEsm && {
88
+ extensionAlias: {
89
+ '.js': ['.ts', '.js'],
90
+ '.mjs': ['.mts', '.mjs'],
91
+ },
92
+ }),
70
93
  tsConfig: tsConfigFile,
71
94
  plugins: [
72
95
  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.2",
4
4
  "type": "module",
5
5
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
6
6
  "publishConfig": {
@@ -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"