@nx/js 16.5.0-beta.2 → 16.5.0

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": "16.5.0-beta.2",
3
+ "version": "16.5.0",
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": {
@@ -39,9 +39,9 @@
39
39
  "@babel/preset-env": "^7.15.0",
40
40
  "@babel/preset-typescript": "^7.15.0",
41
41
  "@babel/runtime": "^7.14.8",
42
- "@nrwl/js": "16.5.0-beta.2",
43
- "@nx/devkit": "16.5.0-beta.2",
44
- "@nx/workspace": "16.5.0-beta.2",
42
+ "@nrwl/js": "16.5.0",
43
+ "@nx/devkit": "16.5.0",
44
+ "@nx/workspace": "16.5.0",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -69,5 +69,5 @@
69
69
  "access": "public"
70
70
  },
71
71
  "types": "./src/index.d.ts",
72
- "gitHead": "efdf140459e453c50f06cf287906c4bb3ac49d3d"
72
+ "gitHead": "eaebcc34f92db2200dab0bde2e2e1dde107a47bf"
73
73
  }
@@ -5,14 +5,15 @@ const tslib_1 = require("tslib");
5
5
  const chalk = require("chalk");
6
6
  const child_process_1 = require("child_process");
7
7
  const devkit_1 = require("@nx/devkit");
8
+ const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
8
9
  const client_1 = require("nx/src/daemon/client/client");
9
10
  const crypto_1 = require("crypto");
10
11
  const path = require("path");
11
12
  const path_1 = require("path");
12
- const async_iterable_1 = require("@nx/devkit/src/utils/async-iterable");
13
13
  const buildable_libs_utils_1 = require("../../utils/buildable-libs-utils");
14
14
  const kill_tree_1 = require("./lib/kill-tree");
15
15
  const fileutils_1 = require("nx/src/utils/fileutils");
16
+ const get_main_file_dir_1 = require("../../utils/get-main-file-dir");
16
17
  function debounce(fn, wait) {
17
18
  let timeoutId;
18
19
  return () => {
@@ -27,13 +28,11 @@ function nodeExecutor(options, context) {
27
28
  (_a = (_d = process.env).NODE_ENV) !== null && _a !== void 0 ? _a : (_d.NODE_ENV = (_b = context === null || context === void 0 ? void 0 : context.configurationName) !== null && _b !== void 0 ? _b : 'development');
28
29
  const project = context.projectGraph.nodes[context.projectName];
29
30
  const buildTarget = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
30
- let buildOptions;
31
- if (project.data.targets[buildTarget.target]) {
32
- buildOptions = Object.assign(Object.assign({}, (_c = project.data.targets[buildTarget.target]) === null || _c === void 0 ? void 0 : _c.options), options.buildTargetOptions);
33
- }
34
- else {
31
+ if (!project.data.targets[buildTarget.target]) {
35
32
  throw new Error(`Cannot find build target ${chalk.bold(options.buildTarget)} for project ${chalk.bold(context.projectName)}`);
36
33
  }
34
+ const buildTargetExecutor = (_c = project.data.targets[buildTarget.target]) === null || _c === void 0 ? void 0 : _c.executor;
35
+ const buildOptions = Object.assign(Object.assign({}, (0, devkit_1.readTargetOptions)(buildTarget, context)), options.buildTargetOptions);
37
36
  if (options.waitUntilTargets && options.waitUntilTargets.length > 0) {
38
37
  const results = yield tslib_1.__await(runWaitUntilTargets(options, context));
39
38
  for (const [i, result] of results.entries()) {
@@ -44,15 +43,7 @@ function nodeExecutor(options, context) {
44
43
  }
45
44
  // Re-map buildable workspace projects to their output directory.
46
45
  const mappings = calculateResolveMappings(context, options);
47
- let outputFileName = buildOptions.outputFileName || `${path.parse(buildOptions.main).name}.js`;
48
- if (!buildOptions.outputFileName) {
49
- const matches = buildOptions.main.match(/^(?!.*src)(.*)\/([^/]*)$/); //ignore strings that contain src and split paths into [folders before main, main.ts]
50
- if (matches) {
51
- const [mainFolder, mainFileName] = matches.slice(1);
52
- outputFileName = path.join(mainFolder, `${path.parse(mainFileName).name}.js`);
53
- }
54
- }
55
- const fileToRun = (0, path_1.join)(context.root, buildOptions.outputPath, outputFileName);
46
+ const fileToRun = getFileToRun(context, project, buildOptions, buildTargetExecutor);
56
47
  const tasks = [];
57
48
  let currentTask = null;
58
49
  yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues((0, async_iterable_1.createAsyncIterable)(({ done, next, error }) => tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -229,6 +220,20 @@ function runWaitUntilTargets(options, context) {
229
220
  }));
230
221
  })));
231
222
  }
223
+ function getFileToRun(context, project, buildOptions, buildTargetExecutor) {
224
+ let outputFileName = buildOptions.outputFileName;
225
+ if (!outputFileName) {
226
+ const fileName = `${path.parse(buildOptions.main).name}.js`;
227
+ if (buildTargetExecutor === '@nx/js:tsc' ||
228
+ buildTargetExecutor === '@nx/js:swc') {
229
+ outputFileName = path.join((0, get_main_file_dir_1.getMainFileDirRelativeToProjectRoot)(buildOptions.main, project.data.root), fileName);
230
+ }
231
+ else {
232
+ outputFileName = fileName;
233
+ }
234
+ }
235
+ return (0, path_1.join)(context.root, buildOptions.outputPath, outputFileName);
236
+ }
232
237
  function fileToRunCorrectPath(fileToRun) {
233
238
  if (!(0, fileutils_1.fileExists)(fileToRun)) {
234
239
  const cjsFile = fileToRun.replace(/\.js$/, '.cjs');
@@ -0,0 +1 @@
1
+ export declare function getMainFileDirRelativeToProjectRoot(main: string, projectRoot: string): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getMainFileDirRelativeToProjectRoot = void 0;
4
+ const path_1 = require("path");
5
+ const path_2 = require("nx/src/utils/path");
6
+ function getMainFileDirRelativeToProjectRoot(main, projectRoot) {
7
+ const mainFileDir = (0, path_1.dirname)(main);
8
+ const relativeDir = (0, path_2.normalizePath)((0, path_1.relative)(projectRoot, mainFileDir));
9
+ return relativeDir === '' ? `./` : `./${relativeDir}/`;
10
+ }
11
+ exports.getMainFileDirRelativeToProjectRoot = getMainFileDirRelativeToProjectRoot;
@@ -12,11 +12,7 @@ const operators_1 = require("nx/src/project-graph/operators");
12
12
  const fileutils_1 = require("nx/src/utils/fileutils");
13
13
  const fs_1 = require("fs");
14
14
  const nx_deps_cache_1 = require("nx/src/project-graph/nx-deps-cache");
15
- function getMainFileDirRelativeToProjectRoot(main, projectRoot) {
16
- const mainFileDir = (0, path_1.dirname)(main);
17
- const relativeDir = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, mainFileDir));
18
- return relativeDir === '' ? `./` : `./${relativeDir}/`;
19
- }
15
+ const get_main_file_dir_1 = require("../get-main-file-dir");
20
16
  function updatePackageJson(options, context, target, dependencies, fileMap = null) {
21
17
  var _a;
22
18
  let packageJson;
@@ -99,7 +95,7 @@ function getUpdatedPackageJsonContent(packageJson, options) {
99
95
  const hasCjsFormat = !options.format || ((_a = options.format) === null || _a === void 0 ? void 0 : _a.includes('cjs'));
100
96
  const hasEsmFormat = (_b = options.format) === null || _b === void 0 ? void 0 : _b.includes('esm');
101
97
  const mainFile = (0, path_1.basename)(options.main).replace(/\.[tj]s$/, '');
102
- const relativeMainFileDir = getMainFileDirRelativeToProjectRoot(options.main, options.projectRoot);
98
+ const relativeMainFileDir = (0, get_main_file_dir_1.getMainFileDirRelativeToProjectRoot)(options.main, options.projectRoot);
103
99
  const typingsFile = `${relativeMainFileDir}${mainFile}.d.ts`;
104
100
  const exports = typeof packageJson.exports === 'string'
105
101
  ? packageJson.exports