@nx/js 16.6.0-beta.0 → 16.6.0-beta.2

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.6.0-beta.0",
3
+ "version": "16.6.0-beta.2",
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.6.0-beta.0",
43
- "@nx/devkit": "16.6.0-beta.0",
44
- "@nx/workspace": "16.6.0-beta.0",
42
+ "@nrwl/js": "16.6.0-beta.2",
43
+ "@nx/devkit": "16.6.0-beta.2",
44
+ "@nx/workspace": "16.6.0-beta.2",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -55,6 +55,8 @@
55
55
  "minimatch": "3.0.5",
56
56
  "semver": "7.5.3",
57
57
  "source-map-support": "0.5.19",
58
+ "ts-node": "10.9.1",
59
+ "tsconfig-paths": "^4.1.2",
58
60
  "tslib": "^2.3.0"
59
61
  },
60
62
  "peerDependencies": {
@@ -69,5 +71,5 @@
69
71
  "access": "public"
70
72
  },
71
73
  "types": "./src/index.d.ts",
72
- "gitHead": "5a7ffb93c9e84bffbf52f6ae9c6c1e3b8edb9d35"
74
+ "gitHead": "c3d31711b71d648cedeff688fce9334d393b586b"
73
75
  }
@@ -69,13 +69,15 @@
69
69
  "updateBuildableProjectDepsInPackageJson": {
70
70
  "type": "boolean",
71
71
  "description": "Whether to update the buildable project dependencies in the build output package.json.",
72
- "default": false
72
+ "default": false,
73
+ "x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
73
74
  },
74
75
  "buildableProjectDepsInPackageJsonType": {
75
76
  "type": "string",
76
77
  "description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
77
78
  "enum": ["dependencies", "peerDependencies"],
78
- "default": "peerDependencies"
79
+ "default": "peerDependencies",
80
+ "x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
79
81
  },
80
82
  "external": {
81
83
  "description": "A list projects to be treated as external. This feature is experimental",
@@ -57,13 +57,15 @@
57
57
  "updateBuildableProjectDepsInPackageJson": {
58
58
  "type": "boolean",
59
59
  "description": "Whether to update the buildable project dependencies in the build output package.json.",
60
- "default": false
60
+ "default": false,
61
+ "x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
61
62
  },
62
63
  "buildableProjectDepsInPackageJsonType": {
63
64
  "type": "string",
64
65
  "description": "When `updateBuildableProjectDepsInPackageJson` is `true`, this adds dependencies to either `peerDependencies` or `dependencies`.",
65
66
  "enum": ["dependencies", "peerDependencies"],
66
- "default": "peerDependencies"
67
+ "default": "peerDependencies",
68
+ "x-deprecated": "Configure the project to use the '@nx/dependency-checks' ESLint rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks). It will be removed in v17."
67
69
  },
68
70
  "external": {
69
71
  "description": "A list projects to be treated as external. This feature is experimental",
@@ -43,20 +43,21 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
43
43
  }
44
44
  },
45
45
  };
46
+ const processTaskPostCompilation = (tsConfig) => {
47
+ if (tsConfigTaskInfoMap[tsConfig]) {
48
+ const taskInfo = tsConfigTaskInfoMap[tsConfig];
49
+ taskInfo.assetsHandler.processAllAssetsOnceSync();
50
+ (0, update_package_json_1.updatePackageJson)(taskInfo.options, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
51
+ taskInfo.endTime = Date.now();
52
+ }
53
+ };
46
54
  const typescriptCompilation = (0, lib_1.compileTypescriptSolution)(tsCompilationContext, shouldWatch, logger, {
47
55
  beforeProjectCompilationCallback: (tsConfig) => {
48
56
  if (tsConfigTaskInfoMap[tsConfig]) {
49
57
  tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
50
58
  }
51
59
  },
52
- afterProjectCompilationCallback: (tsConfig) => {
53
- if (tsConfigTaskInfoMap[tsConfig]) {
54
- const taskInfo = tsConfigTaskInfoMap[tsConfig];
55
- taskInfo.assetsHandler.processAllAssetsOnceSync();
56
- (0, update_package_json_1.updatePackageJson)(taskInfo.options, taskInfo.context, taskInfo.projectGraphNode, taskInfo.buildableProjectNodeDependencies);
57
- taskInfo.endTime = Date.now();
58
- }
59
- },
60
+ afterProjectCompilationCallback: processTaskPostCompilation,
60
61
  });
61
62
  if (shouldWatch) {
62
63
  const taskInfos = Object.values(tsConfigTaskInfoMap);
@@ -79,21 +80,54 @@ function tscBatchExecutor(taskGraph, inputs, overrides, context) {
79
80
  return { value: undefined, done: true };
80
81
  }))))));
81
82
  }
83
+ const toBatchExecutorTaskResult = (tsConfig, success) => ({
84
+ task: tsConfigTaskInfoMap[tsConfig].task,
85
+ result: {
86
+ success: success,
87
+ terminalOutput: tsConfigTaskInfoMap[tsConfig].terminalOutput,
88
+ startTime: tsConfigTaskInfoMap[tsConfig].startTime,
89
+ endTime: tsConfigTaskInfoMap[tsConfig].endTime,
90
+ },
91
+ });
92
+ let isCompilationDone = false;
93
+ const taskTsConfigsToReport = new Set(Object.keys(taskGraph.tasks).map((t) => taskInMemoryTsConfigMap[t].path));
94
+ let tasksToReportIterator;
95
+ const processSkippedTasks = () => {
96
+ const { value: tsConfig, done } = tasksToReportIterator.next();
97
+ if (done) {
98
+ return { value: undefined, done: true };
99
+ }
100
+ tsConfigTaskInfoMap[tsConfig].startTime = Date.now();
101
+ processTaskPostCompilation(tsConfig);
102
+ return { value: toBatchExecutorTaskResult(tsConfig, true), done: false };
103
+ };
82
104
  return yield tslib_1.__await(yield tslib_1.__await(yield* tslib_1.__asyncDelegator(tslib_1.__asyncValues(mapAsyncIterable(typescriptCompilation, (iterator) => tslib_1.__awaiter(this, void 0, void 0, function* () {
105
+ if (isCompilationDone) {
106
+ return processSkippedTasks();
107
+ }
83
108
  const { value, done } = yield iterator.next();
84
109
  if (done) {
85
- return { value, done: true };
110
+ if (taskTsConfigsToReport.size > 0) {
111
+ /**
112
+ * TS compilation is done but we still have tasks to report. This can
113
+ * happen if, for example, a project is identified as affected, but
114
+ * no file in the TS project is actually changed or if running a
115
+ * task with `--skip-nx-cache` and the outputs are already there. There
116
+ * can still be changes to assets or other files we need to process.
117
+ *
118
+ * Switch to handle the iterator for the tasks we still need to report.
119
+ */
120
+ isCompilationDone = true;
121
+ tasksToReportIterator = taskTsConfigsToReport.values();
122
+ return processSkippedTasks();
123
+ }
124
+ return { value: undefined, done: true };
86
125
  }
87
- const taskResult = {
88
- task: tsConfigTaskInfoMap[value.tsConfig].task,
89
- result: {
90
- success: value.success,
91
- terminalOutput: tsConfigTaskInfoMap[value.tsConfig].terminalOutput,
92
- startTime: tsConfigTaskInfoMap[value.tsConfig].startTime,
93
- endTime: tsConfigTaskInfoMap[value.tsConfig].endTime,
94
- },
126
+ taskTsConfigsToReport.delete(value.tsConfig);
127
+ return {
128
+ value: toBatchExecutorTaskResult(value.tsConfig, value.success),
129
+ done: false,
95
130
  };
96
- return { value: taskResult, done: false };
97
131
  }))))));
98
132
  });
99
133
  }
@@ -238,8 +238,8 @@ function createFiles(tree, options, filesDir) {
238
238
  }
239
239
  function addJest(tree, options) {
240
240
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
241
- const { jestProjectGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
242
- return yield jestProjectGenerator(tree, Object.assign(Object.assign({}, options), { project: options.name, setupFile: 'none', supportTsx: false, skipSerializers: true, testEnvironment: options.testEnvironment, skipFormat: true, compiler: options.bundler === 'swc' || options.bundler === 'tsc'
241
+ const { configurationGenerator } = (0, devkit_1.ensurePackage)('@nx/jest', versions_1.nxVersion);
242
+ return yield configurationGenerator(tree, Object.assign(Object.assign({}, options), { project: options.name, setupFile: 'none', supportTsx: false, skipSerializers: true, testEnvironment: options.testEnvironment, skipFormat: true, compiler: options.bundler === 'swc' || options.bundler === 'tsc'
243
243
  ? options.bundler
244
244
  : options.bundler === 'rollup'
245
245
  ? 'swc'
@@ -9,26 +9,29 @@ const executors = new Set([
9
9
  '@nrwl/js:tsc',
10
10
  ]);
11
11
  function default_1(tree) {
12
+ var _a;
13
+ var _b;
12
14
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
13
- const projects = (0, devkit_1.getProjects)(tree);
14
- for (const [projectName, project] of projects) {
15
- if (project.projectType !== 'library') {
15
+ // use project graph to get the expanded target configurations
16
+ const projectGraph = yield (0, devkit_1.createProjectGraphAsync)();
17
+ for (const [projectName, { data: projectData }] of Object.entries(projectGraph.nodes)) {
18
+ if (projectData.projectType !== 'library') {
16
19
  continue;
17
20
  }
18
- let updated = false;
19
- for (const [, target] of Object.entries(project.targets || {})) {
21
+ for (const [targetName, target] of Object.entries(projectData.targets || {})) {
20
22
  if (!executors.has(target.executor)) {
21
23
  continue;
22
24
  }
23
- if (target.options &&
25
+ if (!target.options ||
24
26
  target.options.updateBuildableProjectDepsInPackageJson === undefined) {
25
- target.options.updateBuildableProjectDepsInPackageJson = true;
26
- updated = true;
27
+ // read the project configuration to write the explicit project configuration
28
+ // and avoid writing the expanded target configuration
29
+ const project = (0, devkit_1.readProjectConfiguration)(tree, projectName);
30
+ (_a = (_b = project.targets[targetName]).options) !== null && _a !== void 0 ? _a : (_b.options = {});
31
+ project.targets[targetName].options.updateBuildableProjectDepsInPackageJson = true;
32
+ (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
27
33
  }
28
34
  }
29
- if (updated) {
30
- (0, devkit_1.updateProjectConfiguration)(tree, projectName, project);
31
- }
32
35
  }
33
36
  yield (0, devkit_1.formatFiles)(tree);
34
37
  });
@@ -0,0 +1,7 @@
1
+ import { type ProjectGraph, type ProjectGraphProjectNode, type ProjectFileMap } from '@nx/devkit';
2
+ /**
3
+ * Finds all npm dependencies and their expected versions for a given project.
4
+ */
5
+ export declare function findNpmDependencies(workspaceRoot: string, sourceProject: ProjectGraphProjectNode, projectGraph: ProjectGraph, projectFileMap: ProjectFileMap, buildTarget: string, options?: {
6
+ includeTransitiveDependencies?: boolean;
7
+ }): Record<string, string>;
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.findNpmDependencies = void 0;
4
+ const path_1 = require("path");
5
+ const file_utils_1 = require("nx/src/project-graph/file-utils");
6
+ const task_hasher_1 = require("nx/src/hasher/task-hasher");
7
+ const devkit_1 = require("@nx/devkit");
8
+ const fileutils_1 = require("nx/src/utils/fileutils");
9
+ const project_graph_1 = require("nx/src/config/project-graph");
10
+ const ts_config_1 = require("./typescript/ts-config");
11
+ /**
12
+ * Finds all npm dependencies and their expected versions for a given project.
13
+ */
14
+ function findNpmDependencies(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, options = {}) {
15
+ let seen = null;
16
+ if (options.includeTransitiveDependencies) {
17
+ seen = new Set();
18
+ }
19
+ const results = {};
20
+ function collectAll(currentProject, collectedDeps) {
21
+ if (seen === null || seen === void 0 ? void 0 : seen.has(currentProject.name))
22
+ return;
23
+ collectDependenciesFromFileMap(workspaceRoot, currentProject, projectGraph, projectFileMap, buildTarget, collectedDeps);
24
+ collectHelperDependencies(workspaceRoot, currentProject, projectGraph, buildTarget, collectedDeps);
25
+ if (options.includeTransitiveDependencies) {
26
+ const projectDeps = projectGraph.dependencies[currentProject.name];
27
+ for (const dep of projectDeps) {
28
+ const projectDep = projectGraph.nodes[dep.target];
29
+ if (projectDep)
30
+ collectAll(projectDep, collectedDeps);
31
+ }
32
+ }
33
+ }
34
+ collectAll(sourceProject, results);
35
+ return results;
36
+ }
37
+ exports.findNpmDependencies = findNpmDependencies;
38
+ // Keep track of workspace libs we already read package.json for so we don't read from disk again.
39
+ const seenWorkspaceDeps = {};
40
+ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGraph, projectFileMap, buildTarget, npmDeps) {
41
+ const rawFiles = projectFileMap[sourceProject.name];
42
+ if (!rawFiles)
43
+ return;
44
+ // Cannot read inputs if the target does not exist on the project.
45
+ if (!sourceProject.data.targets[buildTarget])
46
+ return;
47
+ const inputs = (0, task_hasher_1.getTargetInputs)((0, file_utils_1.readNxJson)(), sourceProject, buildTarget).selfInputs;
48
+ const files = (0, task_hasher_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
49
+ for (const fileData of files) {
50
+ if (!fileData.deps ||
51
+ fileData.file ===
52
+ (0, devkit_1.joinPathFragments)(sourceProject.data.root, 'package.json')) {
53
+ continue;
54
+ }
55
+ for (const dep of fileData.deps) {
56
+ const target = (0, project_graph_1.fileDataDepTarget)(dep);
57
+ // If the node is external, then read package info from `data`.
58
+ const externalDep = projectGraph.externalNodes[target];
59
+ if ((externalDep === null || externalDep === void 0 ? void 0 : externalDep.type) === 'npm') {
60
+ npmDeps[externalDep.data.packageName] = externalDep.data.version;
61
+ continue;
62
+ }
63
+ // If node is internal, then try reading package info from `package.json` (which must exist for this to work).
64
+ const workspaceDep = projectGraph.nodes[target];
65
+ if (!workspaceDep)
66
+ continue;
67
+ const cached = seenWorkspaceDeps[workspaceDep.name];
68
+ if (cached) {
69
+ npmDeps[cached.name] = cached.version;
70
+ }
71
+ else {
72
+ const packageJson = readPackageJson(workspaceDep, workspaceRoot);
73
+ if (packageJson) {
74
+ // This is a workspace lib so we can't reliably read in a specific version since it depends on how the workspace is set up.
75
+ // ASSUMPTION: Most users will use '*' for workspace lib versions. Otherwise, they can manually update it.
76
+ npmDeps[packageJson.name] = '*';
77
+ seenWorkspaceDeps[workspaceDep.name] = {
78
+ name: packageJson.name,
79
+ version: '*',
80
+ };
81
+ }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ function readPackageJson(project, workspaceRoot) {
87
+ const packageJsonPath = (0, path_1.join)(workspaceRoot, project.data.root, 'package.json');
88
+ if ((0, fileutils_1.fileExists)(packageJsonPath))
89
+ return (0, devkit_1.readJsonFile)(packageJsonPath);
90
+ return null;
91
+ }
92
+ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, buildTarget, npmDeps) {
93
+ var _a, _b, _c, _d;
94
+ const target = sourceProject.data.targets[buildTarget];
95
+ if (!target)
96
+ return;
97
+ if (target.executor === '@nx/js:tsc' && ((_a = target.options) === null || _a === void 0 ? void 0 : _a.tsConfig)) {
98
+ const tsConfig = (0, ts_config_1.readTsConfig)((0, path_1.join)(workspaceRoot, target.options.tsConfig));
99
+ if (tsConfig === null || tsConfig === void 0 ? void 0 : tsConfig.options['importHelpers']) {
100
+ npmDeps['tslib'] = (_b = projectGraph.externalNodes['npm:tslib']) === null || _b === void 0 ? void 0 : _b.data.version;
101
+ }
102
+ }
103
+ if (target.executor === '@nx/js:swc') {
104
+ const swcConfigPath = target.options.swcrc
105
+ ? (0, path_1.join)(workspaceRoot, target.options.swcrc)
106
+ : (0, path_1.join)(workspaceRoot, sourceProject.data.root, '.swcrc');
107
+ const swcConfig = (0, fileutils_1.fileExists)(swcConfigPath)
108
+ ? (0, devkit_1.readJsonFile)(swcConfigPath)
109
+ : {};
110
+ if ((_c = swcConfig === null || swcConfig === void 0 ? void 0 : swcConfig.jsc) === null || _c === void 0 ? void 0 : _c.externalHelpers) {
111
+ npmDeps['@swc/helpers'] =
112
+ (_d = projectGraph.externalNodes['npm:@swc/helpers']) === null || _d === void 0 ? void 0 : _d.data.version;
113
+ }
114
+ }
115
+ }
@@ -42,7 +42,17 @@ export interface ExecutorOptions {
42
42
  watch: boolean;
43
43
  clean?: boolean;
44
44
  transformers: TransformerEntry[];
45
+ /**
46
+ * @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
47
+ * rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
48
+ * It will be removed in v17.
49
+ */
45
50
  updateBuildableProjectDepsInPackageJson?: boolean;
51
+ /**
52
+ * @deprecated Configure the project to use the `@nx/dependency-checks` ESLint
53
+ * rule instead (https://nx.dev/packages/eslint-plugin/documents/dependency-checks).
54
+ * It will be removed in v17.
55
+ */
46
56
  buildableProjectDepsInPackageJsonType?: 'dependencies' | 'peerDependencies';
47
57
  external?: 'all' | 'none' | string[];
48
58
  externalBuildTargets?: string[];
@@ -0,0 +1 @@
1
+ export declare function tsNodeRegister(file: string, tsConfig?: string): void;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.tsNodeRegister = void 0;
4
+ function tsNodeRegister(file, tsConfig) {
5
+ if (!(file === null || file === void 0 ? void 0 : file.endsWith('.ts')))
6
+ return;
7
+ // Register TS compiler lazily
8
+ require('ts-node').register({
9
+ project: tsConfig,
10
+ compilerOptions: {
11
+ module: 'CommonJS',
12
+ types: ['node'],
13
+ },
14
+ });
15
+ if (!tsConfig)
16
+ return;
17
+ // Register paths in tsConfig
18
+ const tsconfigPaths = require('tsconfig-paths');
19
+ const { absoluteBaseUrl: baseUrl, paths } = tsconfigPaths.loadConfig(tsConfig);
20
+ if (baseUrl && paths) {
21
+ tsconfigPaths.register({ baseUrl, paths });
22
+ }
23
+ }
24
+ exports.tsNodeRegister = tsNodeRegister;