@nestjs/cli 9.1.7 → 9.1.9-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.
@@ -88,6 +88,7 @@ class BuildAction extends abstract_action_1.AbstractAction {
88
88
  }
89
89
  else {
90
90
  this.compiler.run(configuration, pathToTsconfig, appName, onSuccess);
91
+ this.assetsManager.closeWatchers();
91
92
  }
92
93
  });
93
94
  }
@@ -2,6 +2,13 @@ import { Configuration } from '../configuration';
2
2
  export declare class AssetsManager {
3
3
  private watchAssetsKeyValue;
4
4
  private watchers;
5
+ private actionInProgress;
6
+ /**
7
+ * Using on `nest build` to close file watch or the build process will not end
8
+ * Interval like process
9
+ * If no action has been taken recently close watchers
10
+ * If action has been taken recently flag and try again
11
+ */
5
12
  closeWatchers(): void;
6
13
  copyAssets(configuration: Required<Configuration>, appName: string, outDir: string, watchAssetsMode: boolean): void;
7
14
  private actionOnFile;
@@ -10,9 +10,27 @@ class AssetsManager {
10
10
  constructor() {
11
11
  this.watchAssetsKeyValue = {};
12
12
  this.watchers = [];
13
+ this.actionInProgress = false;
13
14
  }
15
+ /**
16
+ * Using on `nest build` to close file watch or the build process will not end
17
+ * Interval like process
18
+ * If no action has been taken recently close watchers
19
+ * If action has been taken recently flag and try again
20
+ */
14
21
  closeWatchers() {
15
- this.watchers.forEach((watcher) => watcher.close());
22
+ // Consider adjusting this for larger files
23
+ const timeoutMs = 500;
24
+ const closeFn = () => {
25
+ if (this.actionInProgress) {
26
+ this.actionInProgress = false;
27
+ setTimeout(closeFn, timeoutMs);
28
+ }
29
+ else {
30
+ this.watchers.forEach((watcher) => watcher.close());
31
+ }
32
+ };
33
+ setTimeout(closeFn, timeoutMs);
16
34
  }
17
35
  copyAssets(configuration, appName, outDir, watchAssetsMode) {
18
36
  const assets = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'compilerOptions.assets', appName) || [];
@@ -52,9 +70,6 @@ class AssetsManager {
52
70
  .on('add', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
53
71
  .on('change', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'change' })))
54
72
  .on('unlink', (path) => this.actionOnFile(Object.assign(Object.assign({}, option), { path, action: 'unlink' })));
55
- if (!isWatchEnabled) {
56
- watcher.on('ready', () => watcher.close());
57
- }
58
73
  this.watchers.push(watcher);
59
74
  }
60
75
  }
@@ -71,6 +86,8 @@ class AssetsManager {
71
86
  }
72
87
  // Set path value to true for watching the first time
73
88
  this.watchAssetsKeyValue[path] = true;
89
+ // Set action to true to avoid watches getting cutoff
90
+ this.actionInProgress = true;
74
91
  const dest = (0, copy_path_resolve_1.copyPathResolve)(path, item.outDir, sourceRoot.split(path_1.sep).length);
75
92
  // Copy to output dir if file is changed or added
76
93
  if (action === 'change') {
@@ -2,8 +2,11 @@ import { Configuration } from '../configuration';
2
2
  import { AssetsManager } from './assets-manager';
3
3
  import { PluginsLoader } from './plugins-loader';
4
4
  import webpack = require('webpack');
5
+ declare type WebpackConfigFactory = (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration;
6
+ declare type WebpackConfigFactoryOrConfig = WebpackConfigFactory | webpack.Configuration;
5
7
  export declare class WebpackCompiler {
6
8
  private readonly pluginsLoader;
7
9
  constructor(pluginsLoader: PluginsLoader);
8
- run(configuration: Required<Configuration>, webpackConfigFactoryOrConfig: (config: webpack.Configuration, webpackRef: typeof webpack) => webpack.Configuration, tsConfigPath: string, appName: string, isDebugEnabled: boolean | undefined, watchMode: boolean | undefined, assetsManager: AssetsManager, onSuccess?: () => void): void;
10
+ run(configuration: Required<Configuration>, webpackConfigFactoryOrConfig: WebpackConfigFactoryOrConfig | WebpackConfigFactoryOrConfig[], tsConfigPath: string, appName: string, isDebugEnabled: boolean | undefined, watchMode: boolean | undefined, assetsManager: AssetsManager, onSuccess?: () => void): void;
9
11
  }
12
+ export {};
@@ -27,11 +27,29 @@ class WebpackCompiler {
27
27
  const entryFile = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'entryFile', appName);
28
28
  const entryFileRoot = (0, get_value_or_default_1.getValueOrDefault)(configuration, 'root', appName) || '';
29
29
  const defaultOptions = (0, webpack_defaults_1.webpackDefaultsFactory)(pathToSource, entryFileRoot, entryFile, isDebugEnabled, tsConfigPath, plugins);
30
- const projectWebpackOptions = typeof webpackConfigFactoryOrConfig !== 'function'
31
- ? webpackConfigFactoryOrConfig
32
- : webpackConfigFactoryOrConfig(defaultOptions, webpack);
33
- const webpackConfiguration = Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: watchMode ? 'development' : defaultOptions.mode }), projectWebpackOptions);
34
- const compiler = webpack(webpackConfiguration);
30
+ let compiler;
31
+ let watchOptions;
32
+ let watch;
33
+ if (Array.isArray(webpackConfigFactoryOrConfig)) {
34
+ const webpackConfigurations = webpackConfigFactoryOrConfig.map((configOrFactory) => {
35
+ const unwrappedConfig = typeof configOrFactory !== 'function'
36
+ ? configOrFactory
37
+ : configOrFactory(defaultOptions, webpack);
38
+ return Object.assign(Object.assign(Object.assign({}, defaultOptions), { mode: watchMode ? 'development' : defaultOptions.mode }), unwrappedConfig);
39
+ });
40
+ compiler = webpack(webpackConfigurations);
41
+ watchOptions = webpackConfigurations.map((config) => config.watchOptions || {});
42
+ watch = webpackConfigurations.some((config) => config.watch);
43
+ }
44
+ 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);
49
+ compiler = webpack(webpackConfiguration);
50
+ watchOptions = webpackConfiguration.watchOptions;
51
+ watch = webpackConfiguration.watch;
52
+ }
35
53
  const afterCallback = (err, stats) => {
36
54
  if (err && stats === undefined) {
37
55
  // Could not complete the compilation
@@ -53,18 +71,18 @@ class WebpackCompiler {
53
71
  onSuccess();
54
72
  }
55
73
  }
56
- else if (!watchMode && !webpackConfiguration.watch) {
74
+ else if (!watchMode && !watch) {
57
75
  console.log(statsOutput);
58
76
  return process.exit(1);
59
77
  }
60
78
  console.log(statsOutput);
61
79
  };
62
- if (watchMode || webpackConfiguration.watch) {
80
+ if (watchMode || watch) {
63
81
  compiler.hooks.watchRun.tapAsync('Rebuild info', (params, callback) => {
64
82
  console.log(`\n${ui_1.INFO_PREFIX} Webpack is building your sources...\n`);
65
83
  callback();
66
84
  });
67
- compiler.watch(webpackConfiguration.watchOptions || {}, afterCallback);
85
+ compiler.watch(watchOptions || {}, afterCallback);
68
86
  }
69
87
  else {
70
88
  compiler.run(afterCallback);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs/cli",
3
- "version": "9.1.7",
3
+ "version": "9.1.9-next.1",
4
4
  "description": "Nest - modern, fast, powerful node.js web framework (@cli)",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -62,11 +62,11 @@
62
62
  "webpack-node-externals": "3.0.0"
63
63
  },
64
64
  "devDependencies": {
65
- "@commitlint/cli": "17.3.0",
66
- "@commitlint/config-angular": "17.3.0",
65
+ "@commitlint/cli": "17.4.2",
66
+ "@commitlint/config-angular": "17.4.2",
67
67
  "@types/copyfiles": "2.4.1",
68
68
  "@types/inquirer": "8.2.5",
69
- "@types/jest": "29.2.4",
69
+ "@types/jest": "29.2.6",
70
70
  "@types/node": "18.11.18",
71
71
  "@types/node-emoji": "1.8.2",
72
72
  "@types/ora": "3.2.0",
@@ -74,20 +74,20 @@
74
74
  "@types/rimraf": "3.0.2",
75
75
  "@types/shelljs": "0.8.11",
76
76
  "@types/webpack-node-externals": "2.5.3",
77
- "@typescript-eslint/eslint-plugin": "5.47.1",
78
- "@typescript-eslint/parser": "5.47.1",
77
+ "@typescript-eslint/eslint-plugin": "5.49.0",
78
+ "@typescript-eslint/parser": "5.49.0",
79
79
  "delete-empty": "3.0.0",
80
- "eslint": "8.30.0",
81
- "eslint-config-prettier": "8.5.0",
82
- "eslint-plugin-import": "2.26.0",
80
+ "eslint": "8.32.0",
81
+ "eslint-config-prettier": "8.6.0",
82
+ "eslint-plugin-import": "2.27.5",
83
83
  "gulp": "4.0.2",
84
84
  "gulp-clean": "0.4.0",
85
- "husky": "8.0.2",
85
+ "husky": "8.0.3",
86
86
  "jest": "29.3.1",
87
87
  "lint-staged": "13.1.0",
88
- "prettier": "2.8.1",
89
- "release-it": "15.5.1",
90
- "ts-jest": "29.0.3",
88
+ "prettier": "2.8.3",
89
+ "release-it": "15.6.0",
90
+ "ts-jest": "29.0.5",
91
91
  "ts-loader": "9.4.2",
92
92
  "ts-node": "10.9.1"
93
93
  },