@nestjs/cli 9.4.2 → 10.0.0-next.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 (44) hide show
  1. package/.circleci/config.yml +2 -2
  2. package/actions/build.action.d.ts +4 -7
  3. package/actions/build.action.js +43 -21
  4. package/actions/new.action.js +1 -2
  5. package/commands/build.command.js +23 -1
  6. package/commands/start.command.js +23 -1
  7. package/lib/compiler/base-compiler.d.ts +9 -0
  8. package/lib/compiler/base-compiler.js +26 -0
  9. package/lib/compiler/compiler.d.ts +4 -4
  10. package/lib/compiler/compiler.js +6 -7
  11. package/lib/compiler/defaults/swc-defaults.d.ts +31 -0
  12. package/lib/compiler/defaults/swc-defaults.js +47 -0
  13. package/lib/compiler/defaults/webpack-defaults.d.ts +1 -1
  14. package/lib/compiler/helpers/get-value-or-default.d.ts +1 -1
  15. package/lib/compiler/helpers/is-compilable-extension.d.ts +1 -0
  16. package/lib/compiler/helpers/is-compilable-extension.js +9 -0
  17. package/lib/compiler/hooks/tsconfig-paths.hook.js +2 -9
  18. package/lib/compiler/interfaces/readonly-visitor.interface.d.ts +9 -0
  19. package/lib/compiler/interfaces/readonly-visitor.interface.js +2 -0
  20. package/lib/compiler/plugins/plugin-metadata-generator.d.ts +15 -0
  21. package/lib/compiler/plugins/plugin-metadata-generator.js +39 -0
  22. package/lib/compiler/plugins/plugin-metadata-printer.d.ts +5 -0
  23. package/lib/compiler/plugins/plugin-metadata-printer.js +30 -0
  24. package/lib/compiler/plugins/plugins-loader.d.ts +30 -0
  25. package/lib/compiler/plugins/plugins-loader.js +66 -0
  26. package/lib/compiler/swc/constants.d.ts +9 -0
  27. package/lib/compiler/swc/constants.js +14 -0
  28. package/lib/compiler/swc/forked-type-checker.d.ts +1 -0
  29. package/lib/compiler/swc/forked-type-checker.js +72 -0
  30. package/lib/compiler/swc/swc-compiler.d.ts +20 -0
  31. package/lib/compiler/swc/swc-compiler.js +171 -0
  32. package/lib/compiler/swc/type-checker-host.d.ts +13 -0
  33. package/lib/compiler/swc/type-checker-host.js +85 -0
  34. package/lib/compiler/watch-compiler.d.ts +9 -5
  35. package/lib/compiler/watch-compiler.js +23 -15
  36. package/lib/compiler/webpack-compiler.d.ts +13 -5
  37. package/lib/compiler/webpack-compiler.js +30 -30
  38. package/lib/configuration/configuration.d.ts +1 -0
  39. package/lib/configuration/defaults.js +1 -0
  40. package/lib/package-managers/package-manager.factory.js +17 -19
  41. package/lib/readers/file-system.reader.js +3 -24
  42. package/package.json +22 -13
  43. package/lib/compiler/plugins-loader.d.ts +0 -21
  44. package/lib/compiler/plugins-loader.js +0 -54
@@ -4,53 +4,63 @@ exports.WebpackCompiler = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const ui_1 = require("../ui");
7
+ const base_compiler_1 = require("./base-compiler");
7
8
  const webpack_defaults_1 = require("./defaults/webpack-defaults");
8
9
  const get_value_or_default_1 = require("./helpers/get-value-or-default");
9
10
  const webpack = require("webpack");
10
- class WebpackCompiler {
11
+ class WebpackCompiler extends base_compiler_1.BaseCompiler {
11
12
  constructor(pluginsLoader) {
12
- this.pluginsLoader = pluginsLoader;
13
+ super(pluginsLoader);
13
14
  }
14
- run(configuration, options, webpackConfigFactoryOrConfig, tsConfigPath, appName, isDebugEnabled = false, watchMode = false, assetsManager, onSuccess) {
15
+ run(configuration, tsConfigPath, appName, extras, onSuccess) {
16
+ var _a, _b;
15
17
  const cwd = process.cwd();
16
18
  const configPath = (0, path_1.join)(cwd, tsConfigPath);
17
19
  if (!(0, fs_1.existsSync)(configPath)) {
18
20
  throw new Error(`Could not find TypeScript configuration file "${tsConfigPath}".`);
19
21
  }
20
- const pluginsConfig = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.plugins', appName);
21
- const plugins = this.pluginsLoader.load(pluginsConfig);
22
- const relativeRootPath = (0, path_1.dirname)((0, path_1.relative)(cwd, configPath));
23
- const sourceRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'sourceRoot', appName, 'sourceRoot', options);
24
- const pathToSource = (0, path_1.normalize)(sourceRoot).indexOf((0, path_1.normalize)(relativeRootPath)) >= 0
25
- ? (0, path_1.join)(cwd, sourceRoot)
26
- : (0, path_1.join)(cwd, relativeRootPath, sourceRoot);
27
- const entryFile = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'entryFile', appName, 'entryFile', options);
22
+ const plugins = this.loadPlugins(configuration, tsConfigPath, appName);
23
+ const pathToSource = this.getPathToSource(configuration, tsConfigPath, appName);
24
+ const entryFile = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'entryFile', appName, 'entryFile', extras.inputs);
28
25
  const entryFileRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'root', appName) || '';
29
- const defaultOptions = (0, webpack_defaults_1.webpackDefaultsFactory)(pathToSource, entryFileRoot, entryFile, isDebugEnabled, tsConfigPath, plugins);
26
+ const defaultOptions = (0, webpack_defaults_1.webpackDefaultsFactory)(pathToSource, entryFileRoot, entryFile, (_a = extras.debug) !== null && _a !== void 0 ? _a : false, tsConfigPath, plugins);
30
27
  let compiler;
31
28
  let watchOptions;
32
29
  let watch;
33
- if (Array.isArray(webpackConfigFactoryOrConfig)) {
34
- const webpackConfigurations = webpackConfigFactoryOrConfig.map((configOrFactory) => {
30
+ if (Array.isArray(extras.webpackConfigFactoryOrConfig)) {
31
+ const webpackConfigurations = extras.webpackConfigFactoryOrConfig.map((configOrFactory) => {
35
32
  const unwrappedConfig = typeof configOrFactory !== 'function'
36
33
  ? configOrFactory
37
34
  : configOrFactory(defaultOptions, webpack);
38
- return Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: watchMode ? 'development' : defaultOptions.mode }), unwrappedConfig);
35
+ return Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: extras.watchMode ? 'development' : defaultOptions.mode }), unwrappedConfig);
39
36
  });
40
37
  compiler = webpack(webpackConfigurations);
41
38
  watchOptions = webpackConfigurations.map((config) => config.watchOptions || {});
42
39
  watch = webpackConfigurations.some((config) => config.watch);
43
40
  }
44
41
  else {
45
- const projectWebpackOptions = typeof webpackConfigFactoryOrConfig !== 'function'
46
- ? webpackConfigFactoryOrConfig
47
- : webpackConfigFactoryOrConfig(defaultOptions, webpack);
48
- const webpackConfiguration = Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: watchMode ? 'development' : defaultOptions.mode }), projectWebpackOptions);
42
+ const projectWebpackOptions = typeof extras.webpackConfigFactoryOrConfig !== 'function'
43
+ ? extras.webpackConfigFactoryOrConfig
44
+ : extras.webpackConfigFactoryOrConfig(defaultOptions, webpack);
45
+ const webpackConfiguration = Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: extras.watchMode ? 'development' : defaultOptions.mode }), projectWebpackOptions);
49
46
  compiler = webpack(webpackConfiguration);
50
47
  watchOptions = webpackConfiguration.watchOptions;
51
48
  watch = webpackConfiguration.watch;
52
49
  }
53
- const afterCallback = (err, stats) => {
50
+ const afterCallback = this.createAfterCallback(onSuccess, extras.assetsManager, (_b = extras.watchMode) !== null && _b !== void 0 ? _b : false, watch);
51
+ if (extras.watchMode || watch) {
52
+ compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
53
+ console.log(`\n${ui_1.INFO_PREFIX} Webpack is building your sources...\n`);
54
+ callback();
55
+ });
56
+ compiler.watch(watchOptions || {}, afterCallback);
57
+ }
58
+ else {
59
+ compiler.run(afterCallback);
60
+ }
61
+ }
62
+ createAfterCallback(onSuccess, assetsManager, watchMode, watch) {
63
+ return (err, stats) => {
54
64
  if (err && stats === undefined) {
55
65
  // Could not complete the compilation
56
66
  // The error caught is most likely thrown by underlying tasks
@@ -77,16 +87,6 @@ class WebpackCompiler {
77
87
  }
78
88
  console.log(statsOutput);
79
89
  };
80
- if (watchMode || watch) {
81
- compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
82
- console.log(`\n${ui_1.INFO_PREFIX} Webpack is building your sources...\n`);
83
- callback();
84
- });
85
- compiler.watch(watchOptions || {}, afterCallback);
86
- }
87
- else {
88
- compiler.run(afterCallback);
89
- }
90
90
  }
91
91
  }
92
92
  exports.WebpackCompiler = WebpackCompiler;
@@ -21,6 +21,7 @@ interface CompilerOptions {
21
21
  plugins?: string[] | PluginOptions[];
22
22
  assets?: string[];
23
23
  deleteOutDir?: boolean;
24
+ manualRestart?: boolean;
24
25
  }
25
26
  interface PluginOptions {
26
27
  name: string;
@@ -16,6 +16,7 @@ exports.defaultConfiguration = {
16
16
  webpackConfigPath: 'webpack.config.js',
17
17
  plugins: [],
18
18
  assets: [],
19
+ manualRestart: false,
19
20
  },
20
21
  generateOptions: {},
21
22
  };
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.PackageManagerFactory = void 0;
13
- const fs_1 = require("fs");
13
+ const fs = require("fs");
14
14
  const npm_package_manager_1 = require("./npm.package-manager");
15
15
  const package_manager_1 = require("./package-manager");
16
16
  const yarn_package_manager_1 = require("./yarn.package-manager");
@@ -30,24 +30,22 @@ class PackageManagerFactory {
30
30
  }
31
31
  static find() {
32
32
  return __awaiter(this, void 0, void 0, function* () {
33
- return new Promise((resolve) => {
34
- (0, fs_1.readdir)(process.cwd(), (error, files) => {
35
- if (error) {
36
- resolve(this.create(package_manager_1.PackageManager.NPM));
37
- }
38
- else {
39
- if (files.findIndex((filename) => filename === 'yarn.lock') > -1) {
40
- resolve(this.create(package_manager_1.PackageManager.YARN));
41
- }
42
- else if (files.findIndex((filename) => filename === 'pnpm-lock.yaml') > -1) {
43
- resolve(this.create(package_manager_1.PackageManager.PNPM));
44
- }
45
- else {
46
- resolve(this.create(package_manager_1.PackageManager.NPM));
47
- }
48
- }
49
- });
50
- });
33
+ const DEFAULT_PACKAGE_MANAGER = package_manager_1.PackageManager.NPM;
34
+ try {
35
+ const files = yield fs.promises.readdir(process.cwd());
36
+ const hasYarnLockFile = files.includes('yarn.lock');
37
+ if (hasYarnLockFile) {
38
+ return this.create(package_manager_1.PackageManager.YARN);
39
+ }
40
+ const hasPnpmLockFile = files.includes('pnpm-lock.yaml');
41
+ if (hasPnpmLockFile) {
42
+ return this.create(package_manager_1.PackageManager.PNPM);
43
+ }
44
+ return this.create(DEFAULT_PACKAGE_MANAGER);
45
+ }
46
+ catch (error) {
47
+ return this.create(DEFAULT_PACKAGE_MANAGER);
48
+ }
51
49
  });
52
50
  }
53
51
  }
@@ -11,37 +11,16 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.FileSystemReader = void 0;
13
13
  const fs = require("fs");
14
+ const path = require("path");
14
15
  class FileSystemReader {
15
16
  constructor(directory) {
16
17
  this.directory = directory;
17
18
  }
18
19
  list() {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- return new Promise((resolve, reject) => {
21
- fs.readdir(this.directory, (error, filenames) => {
22
- if (error) {
23
- reject(error);
24
- }
25
- else {
26
- resolve(filenames);
27
- }
28
- });
29
- });
30
- });
20
+ return fs.promises.readdir(this.directory);
31
21
  }
32
22
  read(name) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- return new Promise((resolve, reject) => {
35
- fs.readFile(`${this.directory}/${name}`, (error, data) => {
36
- if (error) {
37
- reject(error);
38
- }
39
- else {
40
- resolve(data.toString());
41
- }
42
- });
43
- });
44
- });
23
+ return fs.promises.readFile(path.join(this.directory, name), 'utf8');
45
24
  }
46
25
  readAnyOf(filenames) {
47
26
  return __awaiter(this, void 0, void 0, function* () {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "9.4.2",
3
+ "version": "10.0.0-next.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -38,9 +38,9 @@
38
38
  },
39
39
  "homepage": "https://github.com/nestjs/nest-cli#readme",
40
40
  "dependencies": {
41
- "@angular-devkit/core": "15.2.6",
42
- "@angular-devkit/schematics": "15.2.6",
43
- "@angular-devkit/schematics-cli": "15.2.6",
41
+ "@angular-devkit/core": "16.0.1",
42
+ "@angular-devkit/schematics": "16.0.1",
43
+ "@angular-devkit/schematics-cli": "16.0.1",
44
44
  "@nestjs/schematics": "^9.0.4",
45
45
  "chalk": "4.1.2",
46
46
  "chokidar": "3.5.3",
@@ -58,34 +58,43 @@
58
58
  "tsconfig-paths": "4.2.0",
59
59
  "tsconfig-paths-webpack-plugin": "4.0.1",
60
60
  "typescript": "4.9.5",
61
- "webpack": "5.80.0",
61
+ "webpack": "5.82.1",
62
62
  "webpack-node-externals": "3.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@commitlint/cli": "17.6.1",
66
- "@commitlint/config-angular": "17.6.1",
65
+ "@commitlint/cli": "17.6.3",
66
+ "@commitlint/config-angular": "17.6.3",
67
+ "@swc/cli": "0.1.62",
67
68
  "@types/inquirer": "8.2.6",
68
69
  "@types/jest": "29.5.1",
69
- "@types/node": "18.16.0",
70
+ "@types/node": "18.16.12",
70
71
  "@types/node-emoji": "1.8.2",
71
72
  "@types/shelljs": "0.8.12",
72
73
  "@types/webpack-node-externals": "3.0.0",
73
- "@typescript-eslint/eslint-plugin": "5.59.0",
74
- "@typescript-eslint/parser": "5.59.0",
74
+ "@typescript-eslint/eslint-plugin": "5.59.6",
75
+ "@typescript-eslint/parser": "5.59.6",
75
76
  "delete-empty": "3.0.0",
76
- "eslint": "8.39.0",
77
+ "eslint": "8.40.0",
77
78
  "eslint-config-prettier": "8.8.0",
78
79
  "gulp": "4.0.2",
79
80
  "gulp-clean": "0.4.0",
80
81
  "husky": "8.0.3",
81
82
  "jest": "29.5.0",
82
- "lint-staged": "13.2.1",
83
+ "lint-staged": "13.2.2",
83
84
  "prettier": "2.8.8",
84
- "release-it": "15.10.1",
85
+ "release-it": "15.10.3",
85
86
  "ts-jest": "29.1.0",
86
87
  "ts-loader": "9.4.2"
87
88
  },
88
89
  "lint-staged": {
89
90
  "**/*.{ts,json}": []
91
+ },
92
+ "peerDependencies": {
93
+ "@swc/cli": "^0.1.62"
94
+ },
95
+ "peerDependenciesMeta": {
96
+ "@swc/cli": {
97
+ "optional": true
98
+ }
90
99
  }
91
100
  }
@@ -1,21 +0,0 @@
1
- import * as ts from 'typescript';
2
- type Transformer = ts.TransformerFactory<any> | ts.CustomTransformerFactory;
3
- type PluginEntry = string | PluginAndOptions;
4
- interface PluginAndOptions {
5
- name: 'string';
6
- options: Record<string, any>;
7
- }
8
- export interface NestCompilerPlugin {
9
- before?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
10
- after?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
11
- afterDeclarations?: (options?: Record<string, any>, program?: ts.Program) => Transformer;
12
- }
13
- export interface MultiNestCompilerPlugins {
14
- beforeHooks: Array<(program?: ts.Program) => Transformer>;
15
- afterHooks: Array<(program?: ts.Program) => Transformer>;
16
- afterDeclarationsHooks: Array<(program?: ts.Program) => Transformer>;
17
- }
18
- export declare class PluginsLoader {
19
- load(plugins?: PluginEntry[]): MultiNestCompilerPlugins;
20
- }
21
- export {};
@@ -1,54 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PluginsLoader = void 0;
4
- const path_1 = require("path");
5
- const util_1 = require("util");
6
- const ui_1 = require("../ui");
7
- const PLUGIN_ENTRY_FILENAME = 'plugin';
8
- class PluginsLoader {
9
- load(plugins = []) {
10
- const pluginNames = plugins.map((entry) => (0, util_1.isObject)(entry) ? entry.name : entry);
11
- const nodeModulePaths = [
12
- (0, path_1.join)(process.cwd(), 'node_modules'),
13
- ...module.paths,
14
- ];
15
- const pluginRefs = pluginNames.map((item) => {
16
- try {
17
- try {
18
- const binaryPath = require.resolve((0, path_1.join)(item, PLUGIN_ENTRY_FILENAME), {
19
- paths: nodeModulePaths,
20
- });
21
- return require(binaryPath);
22
- }
23
- catch (_a) { }
24
- const binaryPath = require.resolve(item, { paths: nodeModulePaths });
25
- return require(binaryPath);
26
- }
27
- catch (e) {
28
- throw new Error(`"${item}" plugin could not be found!`);
29
- }
30
- });
31
- const beforeHooks = [];
32
- const afterHooks = [];
33
- const afterDeclarationsHooks = [];
34
- pluginRefs.forEach((plugin, index) => {
35
- if (!plugin.before && !plugin.after && !plugin.afterDeclarations) {
36
- throw new Error(ui_1.CLI_ERRORS.WRONG_PLUGIN(pluginNames[index]));
37
- }
38
- const options = (0, util_1.isObject)(plugins[index])
39
- ? plugins[index].options || {}
40
- : {};
41
- plugin.before &&
42
- beforeHooks.push(plugin.before.bind(plugin.before, options));
43
- plugin.after && afterHooks.push(plugin.after.bind(plugin.after, options));
44
- plugin.afterDeclarations &&
45
- afterDeclarationsHooks.push(plugin.afterDeclarations.bind(plugin.afterDeclarations, options));
46
- });
47
- return {
48
- beforeHooks,
49
- afterHooks,
50
- afterDeclarationsHooks,
51
- };
52
- }
53
- }
54
- exports.PluginsLoader = PluginsLoader;