@nx/webpack 16.8.0-beta.2 → 16.8.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nx/webpack",
3
- "version": "16.8.0-beta.2",
3
+ "version": "16.8.0-beta.4",
4
4
  "private": false,
5
5
  "description": "The Nx Plugin for Webpack contains executors and generators that support building applications using Webpack.",
6
6
  "repository": {
@@ -30,19 +30,17 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@babel/core": "^7.22.9",
33
- "@nrwl/webpack": "16.8.0-beta.2",
34
- "@nx/devkit": "16.8.0-beta.2",
35
- "@nx/js": "16.8.0-beta.2",
33
+ "@nrwl/webpack": "16.8.0-beta.4",
34
+ "@nx/devkit": "16.8.0-beta.4",
35
+ "@nx/js": "16.8.0-beta.4",
36
36
  "autoprefixer": "^10.4.9",
37
37
  "babel-loader": "^9.1.2",
38
38
  "browserslist": "^4.21.4",
39
39
  "chalk": "^4.1.0",
40
- "chokidar": "^3.5.1",
41
40
  "copy-webpack-plugin": "^10.2.4",
42
41
  "css-loader": "^6.4.0",
43
42
  "css-minimizer-webpack-plugin": "^5.0.0",
44
43
  "fork-ts-checker-webpack-plugin": "7.2.13",
45
- "ignore": "^5.0.4",
46
44
  "less": "4.1.3",
47
45
  "less-loader": "11.1.0",
48
46
  "license-webpack-plugin": "^4.0.2",
@@ -72,5 +70,5 @@
72
70
  "access": "public"
73
71
  },
74
72
  "type": "commonjs",
75
- "gitHead": "9bcc04742f9e1516d8c1ddbfb1907770c347876f"
73
+ "gitHead": "c9aad2dc8c2b34531cf61549bff872e68c481e4e"
76
74
  }
@@ -51,7 +51,7 @@ function default_1(tree) {
51
51
  // Note: This was added by an Nx migration.
52
52
  // You should consider inlining the logic into this file.
53
53
  // For more information on webpack config and Nx see:
54
- // https://nx.dev/packages/webpack/documents/webpack-config-setup
54
+ // https://nx.dev/recipes/webpack/webpack-config-setup
55
55
  return require('./${justTheFileName}')(config, context);
56
56
  });
57
57
  `);
@@ -64,7 +64,7 @@ function default_1(tree) {
64
64
  You should consider inlining the logic from ${oldName} into ${options.webpackConfig}.
65
65
  You can read our guide on how to do this here:
66
66
 
67
- https://nx.dev/packages/webpack/documents/webpack-config-setup
67
+ https://nx.dev/recipes/webpack/webpack-config-setup
68
68
  `);
69
69
  }
70
70
  else {
@@ -82,7 +82,7 @@ function default_1(tree) {
82
82
  // Update the webpack config as needed here.
83
83
  // e.g. config.plugins.push(new MyPlugin())
84
84
  // For more information on webpack config and Nx see:
85
- // https://nx.dev/packages/webpack/documents/webpack-config-setup
85
+ // https://nx.dev/recipes/webpack/webpack-config-setup
86
86
  return config;
87
87
  });
88
88
  `);
@@ -39,7 +39,8 @@ class GeneratePackageJsonPlugin {
39
39
  });
40
40
  packageJson.main = (_a = packageJson.main) !== null && _a !== void 0 ? _a : this.options.outputFileName;
41
41
  compilation.emitAsset('package.json', new webpack_1.sources.RawSource((0, devkit_1.serializeJson)(packageJson)));
42
- compilation.emitAsset((0, js_2.getLockFileName)(), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson)));
42
+ const packageManager = (0, devkit_1.detectPackageManager)(this.context.root);
43
+ compilation.emitAsset((0, js_2.getLockFileName)(packageManager), new webpack_1.sources.RawSource((0, js_1.createLockFile)(packageJson, this.projectGraph, packageManager)));
43
44
  });
44
45
  });
45
46
  }
@@ -2,8 +2,10 @@ import type { Compiler } from 'webpack';
2
2
  export declare class WebpackNxBuildCoordinationPlugin {
3
3
  private readonly buildCmd;
4
4
  private currentlyRunning;
5
+ private buildCmdProcess;
5
6
  constructor(buildCmd: string, skipInitialBuild?: boolean);
6
7
  apply(compiler: Compiler): void;
7
- startWatchingBuildableLibs(): void;
8
+ startWatchingBuildableLibs(): Promise<void>;
8
9
  buildChangedProjects(): Promise<void>;
10
+ private createFileWatcher;
9
11
  }
@@ -2,16 +2,15 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WebpackNxBuildCoordinationPlugin = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const chokidar_1 = require("chokidar");
6
5
  const child_process_1 = require("child_process");
7
- const devkit_1 = require("@nx/devkit");
8
- const devkit_2 = require("@nx/devkit");
9
- const ignore_1 = require("ignore");
10
- const fs_1 = require("fs");
6
+ const client_1 = require("nx/src/daemon/client/client");
7
+ const watch_1 = require("nx/src/command-line/watch");
8
+ const output_1 = require("nx/src/utils/output");
11
9
  class WebpackNxBuildCoordinationPlugin {
12
10
  constructor(buildCmd, skipInitialBuild) {
13
11
  this.buildCmd = buildCmd;
14
12
  this.currentlyRunning = 'none';
13
+ this.buildCmdProcess = null;
15
14
  if (!skipInitialBuild) {
16
15
  this.buildChangedProjects();
17
16
  }
@@ -29,8 +28,11 @@ class WebpackNxBuildCoordinationPlugin {
29
28
  }));
30
29
  }
31
30
  startWatchingBuildableLibs() {
32
- createFileWatcher(process.cwd(), () => {
33
- this.buildChangedProjects();
31
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
32
+ const unregisterFileWatcher = yield this.createFileWatcher();
33
+ process.on('exit', () => {
34
+ unregisterFileWatcher();
35
+ });
34
36
  });
35
37
  }
36
38
  buildChangedProjects() {
@@ -40,11 +42,45 @@ class WebpackNxBuildCoordinationPlugin {
40
42
  }
41
43
  this.currentlyRunning = 'nx-build';
42
44
  try {
43
- (0, child_process_1.execSync)(this.buildCmd, { stdio: [0, 1, 2] });
44
- // eslint-disable-next-line no-empty
45
+ return yield new Promise((res) => {
46
+ this.buildCmdProcess = (0, child_process_1.exec)(this.buildCmd);
47
+ this.buildCmdProcess.stdout.pipe(process.stdout);
48
+ this.buildCmdProcess.stderr.pipe(process.stderr);
49
+ this.buildCmdProcess.on('exit', () => {
50
+ res();
51
+ });
52
+ this.buildCmdProcess.on('error', () => {
53
+ res();
54
+ });
55
+ });
45
56
  }
46
- catch (e) { }
47
- this.currentlyRunning = 'none';
57
+ finally {
58
+ this.currentlyRunning = 'none';
59
+ this.buildCmdProcess = null;
60
+ }
61
+ });
62
+ }
63
+ createFileWatcher() {
64
+ const runner = new watch_1.BatchFunctionRunner(() => this.buildChangedProjects());
65
+ return client_1.daemonClient.registerFileWatcher({
66
+ watchProjects: 'all',
67
+ }, (err, { changedProjects, changedFiles }) => {
68
+ if (err === 'closed') {
69
+ output_1.output.error({
70
+ title: 'Watch connection closed',
71
+ bodyLines: [
72
+ 'The daemon has closed the connection to this watch process.',
73
+ 'Please restart your watch command.',
74
+ ],
75
+ });
76
+ process.exit(1);
77
+ }
78
+ if (this.buildCmdProcess) {
79
+ this.buildCmdProcess.kill(2);
80
+ this.buildCmdProcess = null;
81
+ }
82
+ // Queue a build
83
+ runner.enqueue(changedProjects, changedFiles);
48
84
  });
49
85
  }
50
86
  }
@@ -52,32 +88,3 @@ exports.WebpackNxBuildCoordinationPlugin = WebpackNxBuildCoordinationPlugin;
52
88
  function sleep(time) {
53
89
  return new Promise((resolve) => setTimeout(resolve, time));
54
90
  }
55
- function getIgnoredGlobs(root) {
56
- const ig = (0, ignore_1.default)();
57
- try {
58
- ig.add((0, fs_1.readFileSync)(`${root}/.gitignore`, 'utf-8'));
59
- }
60
- catch (_a) { }
61
- try {
62
- ig.add((0, fs_1.readFileSync)(`${root}/.nxignore`, 'utf-8'));
63
- }
64
- catch (_b) { }
65
- return ig;
66
- }
67
- function createFileWatcher(root, changeHandler) {
68
- const ignoredGlobs = getIgnoredGlobs(root);
69
- const layout = (0, devkit_1.workspaceLayout)();
70
- const watcher = (0, chokidar_1.watch)([
71
- (0, devkit_2.joinPathFragments)(layout.appsDir, '**'),
72
- (0, devkit_2.joinPathFragments)(layout.libsDir, '**'),
73
- ], {
74
- cwd: root,
75
- ignoreInitial: true,
76
- });
77
- watcher.on('all', (_event, path) => {
78
- if (ignoredGlobs.ignores(path))
79
- return;
80
- changeHandler();
81
- });
82
- return { close: () => watcher.close() };
83
- }