@nx/js 19.6.0 → 19.7.0-canary.20240817-b91d788

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/js",
3
- "version": "19.6.0",
3
+ "version": "19.7.0-canary.20240817-b91d788",
4
4
  "private": false,
5
5
  "description": "The JS plugin for Nx contains executors and generators that provide the best experience for developing JavaScript and TypeScript projects. ",
6
6
  "repository": {
@@ -58,9 +58,9 @@
58
58
  "semver": "^7.5.3",
59
59
  "source-map-support": "0.5.19",
60
60
  "tslib": "^2.3.0",
61
- "@nx/devkit": "19.6.0",
62
- "@nx/workspace": "19.6.0",
63
- "@nrwl/js": "19.6.0"
61
+ "@nx/devkit": "19.7.0-canary.20240817-b91d788",
62
+ "@nx/workspace": "19.7.0-canary.20240817-b91d788",
63
+ "@nrwl/js": "19.7.0-canary.20240817-b91d788"
64
64
  },
65
65
  "peerDependencies": {
66
66
  "verdaccio": "^5.0.4"
@@ -1,7 +1,4 @@
1
- declare const Module: any;
2
1
  declare const url: any;
3
- declare const originalLoader: any;
2
+ declare const patchSigint: any;
3
+ declare const patchRequire: any;
4
4
  declare const dynamicImport: Function;
5
- declare const mappings: any;
6
- declare const keys: string[];
7
- declare const fileToRun: any;
@@ -1,21 +1,7 @@
1
- const Module = require('module');
2
1
  const url = require('node:url');
3
- const originalLoader = Module._load;
2
+ const { patchSigint } = require('./patch-sigint');
3
+ const { patchRequire } = require('./patch-require');
4
+ patchSigint();
5
+ patchRequire();
4
6
  const dynamicImport = new Function('specifier', 'return import(specifier)');
5
- const mappings = JSON.parse(process.env.NX_MAPPINGS);
6
- const keys = Object.keys(mappings);
7
- const fileToRun = url.pathToFileURL(process.env.NX_FILE_TO_RUN);
8
- Module._load = function (request, parent) {
9
- if (!parent)
10
- return originalLoader.apply(this, arguments);
11
- const match = keys.find((k) => request === k);
12
- if (match) {
13
- const newArguments = [...arguments];
14
- newArguments[0] = mappings[match];
15
- return originalLoader.apply(this, newArguments);
16
- }
17
- else {
18
- return originalLoader.apply(this, arguments);
19
- }
20
- };
21
- dynamicImport(fileToRun);
7
+ dynamicImport(url.pathToFileURL(process.env.NX_FILE_TO_RUN));
@@ -111,11 +111,14 @@ async function* nodeExecutor(options, context) {
111
111
  task.childProcess.stderr.on('data', handleStdErr);
112
112
  task.childProcess.once('exit', (code) => {
113
113
  task.childProcess.off('data', handleStdErr);
114
- if (options.watch && !task.killed) {
114
+ if (options.watch &&
115
+ !task.killed &&
116
+ // SIGINT should exist the process rather than watch for changes.
117
+ code !== 130) {
115
118
  devkit_1.logger.info(`NX Process exited with code ${code}, waiting for changes to restart...`);
116
119
  }
117
- if (!options.watch) {
118
- if (code !== 0) {
120
+ if (!options.watch || code === 130) {
121
+ if (code !== 0 && code !== 130) {
119
122
  error(new Error(`Process exited with code ${code}`));
120
123
  }
121
124
  else {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Overrides require calls to map buildable workspace libs to their output location.
3
+ * This is useful for running programs compiled via TSC/SWC that aren't bundled.
4
+ */
5
+ export declare function patchRequire(): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchRequire = patchRequire;
4
+ const Module = require('node:module');
5
+ const originalLoader = Module._load;
6
+ /**
7
+ * Overrides require calls to map buildable workspace libs to their output location.
8
+ * This is useful for running programs compiled via TSC/SWC that aren't bundled.
9
+ */
10
+ function patchRequire() {
11
+ const mappings = JSON.parse(process.env.NX_MAPPINGS);
12
+ const keys = Object.keys(mappings);
13
+ Module._load = function (request, parent) {
14
+ if (!parent)
15
+ return originalLoader.apply(this, arguments);
16
+ const match = keys.find((k) => request === k);
17
+ if (match) {
18
+ const newArguments = [...arguments];
19
+ newArguments[0] = mappings[match];
20
+ return originalLoader.apply(this, newArguments);
21
+ }
22
+ else {
23
+ return originalLoader.apply(this, arguments);
24
+ }
25
+ };
26
+ }
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Patches the current process so that Ctrl+C is properly handled.
3
+ * Without this patch, SIGINT or Ctrl+C does not wait for graceful shutdown and exits immediately.
4
+ */
5
+ export declare function patchSigint(): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.patchSigint = patchSigint;
4
+ const readline = require('node:readline');
5
+ /**
6
+ * Patches the current process so that Ctrl+C is properly handled.
7
+ * Without this patch, SIGINT or Ctrl+C does not wait for graceful shutdown and exits immediately.
8
+ */
9
+ function patchSigint() {
10
+ readline.emitKeypressEvents(process.stdin);
11
+ if (process.stdin.isTTY)
12
+ process.stdin.setRawMode(true);
13
+ process.stdin.on('keypress', async (chunk, key) => {
14
+ if (key && key.ctrl && key.name === 'c') {
15
+ process.stdin.setRawMode(false); // To ensure nx terminal is not stuck in raw mode
16
+ const listeners = process.listeners('SIGINT');
17
+ for (const listener of listeners) {
18
+ await listener('SIGINT');
19
+ }
20
+ process.exit(130);
21
+ }
22
+ });
23
+ console.log('To exit the process, press Ctrl+C');
24
+ }
@@ -29,11 +29,11 @@ function determineModuleFormatFromTsConfig(absolutePathToTsConfig) {
29
29
  }
30
30
  function createTypeScriptCompilationOptions(normalizedOptions, context) {
31
31
  return {
32
- outputPath: normalizedOptions.outputPath,
32
+ outputPath: (0, devkit_1.joinPathFragments)(normalizedOptions.outputPath),
33
33
  projectName: context.projectName,
34
34
  projectRoot: normalizedOptions.projectRoot,
35
- rootDir: normalizedOptions.rootDir,
36
- tsConfig: normalizedOptions.tsConfig,
35
+ rootDir: (0, devkit_1.joinPathFragments)(normalizedOptions.rootDir),
36
+ tsConfig: (0, devkit_1.joinPathFragments)(normalizedOptions.tsConfig),
37
37
  watch: normalizedOptions.watch,
38
38
  deleteOutputPath: normalizedOptions.clean,
39
39
  getCustomTransformers: (0, lib_1.getCustomTrasformersFactory)(normalizedOptions.transformers),
@@ -159,7 +159,7 @@ async function addProject(tree, options) {
159
159
  }
160
160
  }
161
161
  if (options.publishable) {
162
- const packageRoot = (0, path_1.join)(defaultOutputDirectory, '{projectRoot}');
162
+ const packageRoot = (0, devkit_1.joinPathFragments)(defaultOutputDirectory, '{projectRoot}');
163
163
  projectConfiguration.targets ??= {};
164
164
  projectConfiguration.targets['nx-release-publish'] = {
165
165
  options: {
@@ -76,7 +76,7 @@ Valid values are: ${version_1.validReleaseVersionPrefixes
76
76
  if (!packageRoot) {
77
77
  throw new Error(`The project "${projectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
78
78
  }
79
- const packageJsonPath = (0, node_path_1.join)(packageRoot, 'package.json');
79
+ const packageJsonPath = (0, devkit_1.joinPathFragments)(packageRoot, 'package.json');
80
80
  if (!tree.exists(packageJsonPath)) {
81
81
  throw new Error(`The project "${projectName}" does not have a package.json available at ${packageJsonPath}.
82
82
 
@@ -544,7 +544,7 @@ To fix this you will either need to add a package.json file at that location, or
544
544
  if (!dependencyPackageRoot) {
545
545
  throw new Error(`The project "${dependencyProjectName}" does not have a packageRoot available. Please report this issue on https://github.com/nrwl/nx`);
546
546
  }
547
- const dependencyPackageJsonPath = (0, node_path_1.join)(dependencyPackageRoot, 'package.json');
547
+ const dependencyPackageJsonPath = (0, devkit_1.joinPathFragments)(dependencyPackageRoot, 'package.json');
548
548
  const dependencyPackageJson = (0, devkit_1.readJson)(tree, dependencyPackageJsonPath);
549
549
  updateDependentProjectAndAddToVersionData({
550
550
  dependentProject: transitiveDependentProject,
@@ -283,6 +283,9 @@ function updatePaths(dependencies, paths) {
283
283
  const pathsKeys = Object.keys(paths);
284
284
  // For each registered dependency
285
285
  dependencies.forEach((dep) => {
286
+ if (dep.node.type === 'npm') {
287
+ return;
288
+ }
286
289
  // If there are outputs
287
290
  if (dep.outputs && dep.outputs.length > 0) {
288
291
  // Directly map the dependency name to the output paths (dist/packages/..., etc.)
@@ -294,14 +297,19 @@ function updatePaths(dependencies, paths) {
294
297
  // If the path points to the current dependency and is nested (/)
295
298
  if (path.startsWith(nestedName)) {
296
299
  const nestedPart = path.slice(nestedName.length);
297
- // Bind secondary endpoints for ng-packagr projects
300
+ // Bind potential secondary endpoints for ng-packagr projects
298
301
  let mappedPaths = dep.outputs.map((output) => `${output}/${nestedPart}`);
299
- // Get the dependency's package name
300
- const { root } = (dep.node?.data || {});
301
- if (root) {
302
- // Update nested mappings to point to the dependency's output paths
303
- mappedPaths = mappedPaths.concat(paths[path].flatMap((path) => dep.outputs.map((output) => path.replace(root, output))));
304
- }
302
+ const { root } = dep.node.data;
303
+ // Update nested mappings to point to the dependency's output paths
304
+ mappedPaths = mappedPaths.concat(paths[path].flatMap((p) => dep.outputs.flatMap((output) => {
305
+ const basePath = p.replace(root, output);
306
+ return [
307
+ // extension-less path to support compiled output
308
+ basePath.replace(new RegExp(`${(0, path_1.extname)(basePath)}$`, 'gi'), ''),
309
+ // original path with the root re-mapped to the output path
310
+ basePath,
311
+ ];
312
+ })));
305
313
  paths[path] = mappedPaths;
306
314
  }
307
315
  }