@openmrs/webpack-config 11.0.1-pre.6090 → 11.0.1-pre.6106

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 (3) hide show
  1. package/dist/index.js +27 -11
  2. package/package.json +2 -2
  3. package/src/index.ts +35 -12
package/dist/index.js CHANGED
@@ -242,26 +242,40 @@ function slugify(name) {
242
242
  function fileExistsSync(name) {
243
243
  return (0, fs_1.existsSync)(name) && (0, fs_1.statSync)(name).isFile();
244
244
  }
245
+ /** Where the builds configured in this process write their output. */
246
+ const outputDirs = new Set();
247
+ /** True for anything in `node_modules` or in a build's output, where the type checker has no source files to find. */
248
+ function isOutsideSources(path) {
249
+ return (/[\\/]node_modules(?:[\\/]|$)/.test(path) ||
250
+ [...outputDirs].some((outputDir) => path === outputDir || path.startsWith(outputDir + path_1.sep)));
251
+ }
245
252
  /**
246
- * fork-ts-checker-webpack-plugin 9 passes Chokidar 4 `interval: undefined` and `binaryInterval: undefined`
247
- * whenever webpack polls without a numeric `poll`, which is `poll: true` or `CHOKIDAR_USEPOLLING` on its own.
248
- * Chokidar 4 spreads those over its defaults, so the watch process crashes with `ERR_INVALID_ARG_TYPE` as soon
249
- * as polling starts. Chokidar 3 ignored undefined options; dropping them before they reach the plugin's copy of
250
- * Chokidar restores that, along with Chokidar's own intervals.
253
+ * fork-ts-checker-webpack-plugin 9 watches for new source files with its own copy of Chokidar 4, which crashes
254
+ * a watching build in two ways that Chokidar 3 didn't. `watch` on that copy is wrapped to avoid both:
255
+ *
256
+ * - The plugin passes `interval: undefined` and `binaryInterval: undefined` whenever webpack polls without a
257
+ * numeric `poll`, which is `poll: true` or `CHOKIDAR_USEPOLLING` on its own. Chokidar 4 spreads those over
258
+ * its defaults, so the watch process crashes with `ERR_INVALID_ARG_TYPE` as soon as polling starts. Chokidar 3
259
+ * ignored undefined options; dropping them restores that, along with Chokidar's own intervals.
260
+ * - Chokidar 4 has no FSEvents backend and opens a handle per file. The plugin watches every directory the
261
+ * tsconfig includes, which is the whole app when it has no `include`, and on macOS the dev server then dies
262
+ * with EMFILE on reaching `node_modules`. So `node_modules` is left out, and so is the build's output: the
263
+ * dev server writes it to disk, and the plugin takes every file emitted there for a new source file and
264
+ * rebuilds, without end.
251
265
  */
252
- function keepChokidarPollingDefaults() {
266
+ function adaptTypeCheckerChokidar() {
253
267
  const pluginDir = (0, path_1.dirname)(require.resolve('fork-ts-checker-webpack-plugin'));
254
268
  // eslint-disable-next-line @typescript-eslint/no-require-imports
255
269
  const chokidarModule = require(require.resolve('chokidar', { paths: [pluginDir] }));
256
270
  // The plugin calls `chokidar.default.watch`, through TypeScript's `__importDefault`.
257
271
  const chokidar = chokidarModule.__esModule ? chokidarModule.default : chokidarModule;
258
272
  const watch = chokidar === null || chokidar === void 0 ? void 0 : chokidar.watch;
259
- if (typeof watch !== 'function' || watch.keepsPollingDefaults) {
273
+ if (typeof watch !== 'function' || watch.adaptedForTypeChecker) {
260
274
  return;
261
275
  }
262
- chokidar.watch = Object.assign((paths, options) => watch(paths, options && Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))), { keepsPollingDefaults: true });
276
+ chokidar.watch = Object.assign((paths, options = {}) => watch(paths, Object.assign(Object.assign({}, Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))), { ignored: [options.ignored, isOutsideSources].filter(Boolean) })), { adaptedForTypeChecker: true });
263
277
  }
264
- keepChokidarPollingDefaults();
278
+ adaptTypeCheckerChokidar();
265
279
  /**
266
280
  * This object will be merged into the webpack config.
267
281
  * Array values will be concatenated with the existing array.
@@ -315,7 +329,7 @@ exports.watchConfig = {};
315
329
  */
316
330
  exports.optimizationConfig = {};
317
331
  exports.default = (env, argv = {}) => {
318
- var _a;
332
+ var _a, _b, _c;
319
333
  const root = process.cwd();
320
334
  // eslint-disable-next-line @typescript-eslint/no-require-imports
321
335
  const { name, version, peerDependencies, browser, main, types } = require((0, path_1.resolve)(root, 'package.json'));
@@ -543,11 +557,13 @@ exports.default = (env, argv = {}) => {
543
557
  },
544
558
  } }, exports.overrides);
545
559
  const config = (0, lodash_1.mergeWith)(baseConfig, exports.additionalConfig, mergeFunction);
560
+ // Read from the merged config, since `overrides` and `additionalConfig` can both move the output.
561
+ outputDirs.add((0, path_1.resolve)(root, (_b = (_a = config.output) === null || _a === void 0 ? void 0 : _a.path) !== null && _b !== void 0 ? _b : outDir));
546
562
  // Appended after the merge rather than listed above. `overrides` is spread over the config object, so
547
563
  // an app setting `overrides.plugins` replaces the whole array — not a lodash merge, which would keep
548
564
  // the entries — and would drop the guard without noticing. Same reasoning as the `ExternalsPlugin`
549
565
  // block above, which avoids `externals` for the same reason.
550
566
  // Production only: under `style-loader` there are no `.css` assets to check.
551
- config.plugins = [...((_a = config.plugins) !== null && _a !== void 0 ? _a : []), ...(isProd ? [new carbon_css_guard_1.CarbonCssGuardPlugin(name)] : [])];
567
+ config.plugins = [...((_c = config.plugins) !== null && _c !== void 0 ? _c : []), ...(isProd ? [new carbon_css_guard_1.CarbonCssGuardPlugin(name)] : [])];
552
568
  return config;
553
569
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openmrs/webpack-config",
3
- "version": "11.0.1-pre.6090",
3
+ "version": "11.0.1-pre.6106",
4
4
  "license": "MPL-2.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "homepage": "https://github.com/openmrs/openmrs-esm-core#readme",
33
33
  "dependencies": {
34
34
  "@module-federation/enhanced": "2.9.3",
35
- "@openmrs/carbon-css-guard": "11.0.1-pre.6090",
35
+ "@openmrs/carbon-css-guard": "11.0.1-pre.6106",
36
36
  "@swc/core": "1.16.22",
37
37
  "browserslist": "4.29.5",
38
38
  "browserslist-config-openmrs": "^1.0.1",
package/src/index.ts CHANGED
@@ -37,7 +37,7 @@
37
37
  * from `/d/e/`, then it *might* in *some cases* try to import `/d/e/c`.
38
38
  */
39
39
  import { existsSync, statSync } from 'fs';
40
- import { basename, dirname, resolve } from 'path';
40
+ import { basename, dirname, resolve, sep } from 'path';
41
41
  import browserslist from 'browserslist';
42
42
  import { loadQueries } from 'browserslist/node';
43
43
  import defaultBrowserslistQueries from 'browserslist-config-openmrs';
@@ -300,32 +300,53 @@ function fileExistsSync(name: string) {
300
300
  return existsSync(name) && statSync(name).isFile();
301
301
  }
302
302
 
303
+ /** Where the builds configured in this process write their output. */
304
+ const outputDirs = new Set<string>();
305
+
306
+ /** True for anything in `node_modules` or in a build's output, where the type checker has no source files to find. */
307
+ function isOutsideSources(path: string) {
308
+ return (
309
+ /[\\/]node_modules(?:[\\/]|$)/.test(path) ||
310
+ [...outputDirs].some((outputDir) => path === outputDir || path.startsWith(outputDir + sep))
311
+ );
312
+ }
313
+
303
314
  /**
304
- * fork-ts-checker-webpack-plugin 9 passes Chokidar 4 `interval: undefined` and `binaryInterval: undefined`
305
- * whenever webpack polls without a numeric `poll`, which is `poll: true` or `CHOKIDAR_USEPOLLING` on its own.
306
- * Chokidar 4 spreads those over its defaults, so the watch process crashes with `ERR_INVALID_ARG_TYPE` as soon
307
- * as polling starts. Chokidar 3 ignored undefined options; dropping them before they reach the plugin's copy of
308
- * Chokidar restores that, along with Chokidar's own intervals.
315
+ * fork-ts-checker-webpack-plugin 9 watches for new source files with its own copy of Chokidar 4, which crashes
316
+ * a watching build in two ways that Chokidar 3 didn't. `watch` on that copy is wrapped to avoid both:
317
+ *
318
+ * - The plugin passes `interval: undefined` and `binaryInterval: undefined` whenever webpack polls without a
319
+ * numeric `poll`, which is `poll: true` or `CHOKIDAR_USEPOLLING` on its own. Chokidar 4 spreads those over
320
+ * its defaults, so the watch process crashes with `ERR_INVALID_ARG_TYPE` as soon as polling starts. Chokidar 3
321
+ * ignored undefined options; dropping them restores that, along with Chokidar's own intervals.
322
+ * - Chokidar 4 has no FSEvents backend and opens a handle per file. The plugin watches every directory the
323
+ * tsconfig includes, which is the whole app when it has no `include`, and on macOS the dev server then dies
324
+ * with EMFILE on reaching `node_modules`. So `node_modules` is left out, and so is the build's output: the
325
+ * dev server writes it to disk, and the plugin takes every file emitted there for a new source file and
326
+ * rebuilds, without end.
309
327
  */
310
- function keepChokidarPollingDefaults() {
328
+ function adaptTypeCheckerChokidar() {
311
329
  const pluginDir = dirname(require.resolve('fork-ts-checker-webpack-plugin'));
312
330
  // eslint-disable-next-line @typescript-eslint/no-require-imports
313
331
  const chokidarModule = require(require.resolve('chokidar', { paths: [pluginDir] }));
314
332
  // The plugin calls `chokidar.default.watch`, through TypeScript's `__importDefault`.
315
333
  const chokidar = chokidarModule.__esModule ? chokidarModule.default : chokidarModule;
316
334
  const watch = chokidar?.watch;
317
- if (typeof watch !== 'function' || watch.keepsPollingDefaults) {
335
+ if (typeof watch !== 'function' || watch.adaptedForTypeChecker) {
318
336
  return;
319
337
  }
320
338
 
321
339
  chokidar.watch = Object.assign(
322
- (paths: unknown, options?: Record<string, unknown>) =>
323
- watch(paths, options && Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined))),
324
- { keepsPollingDefaults: true },
340
+ (paths: unknown, options: Record<string, unknown> = {}) =>
341
+ watch(paths, {
342
+ ...Object.fromEntries(Object.entries(options).filter(([, value]) => value !== undefined)),
343
+ ignored: [options.ignored, isOutsideSources].filter(Boolean),
344
+ }),
345
+ { adaptedForTypeChecker: true },
325
346
  );
326
347
  }
327
348
 
328
- keepChokidarPollingDefaults();
349
+ adaptTypeCheckerChokidar();
329
350
 
330
351
  /**
331
352
  * This object will be merged into the webpack config.
@@ -661,6 +682,8 @@ export default (env: Record<string, string>, argv: Record<string, string> = {})
661
682
  ...overrides,
662
683
  };
663
684
  const config = mergeWith(baseConfig, additionalConfig, mergeFunction);
685
+ // Read from the merged config, since `overrides` and `additionalConfig` can both move the output.
686
+ outputDirs.add(resolve(root, config.output?.path ?? outDir));
664
687
 
665
688
  // Appended after the merge rather than listed above. `overrides` is spread over the config object, so
666
689
  // an app setting `overrides.plugins` replaces the whole array — not a lodash merge, which would keep