@nx/js 16.6.0-beta.4 → 16.6.0-beta.5

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.4",
3
+ "version": "16.6.0-beta.5",
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": {
@@ -32,16 +32,16 @@
32
32
  "executors": "./executors.json",
33
33
  "builders": "./executors.json",
34
34
  "dependencies": {
35
- "@babel/core": "^7.15.0",
36
- "@babel/plugin-proposal-class-properties": "^7.14.5",
37
- "@babel/plugin-proposal-decorators": "^7.14.5",
38
- "@babel/plugin-transform-runtime": "^7.15.0",
39
- "@babel/preset-env": "^7.15.0",
40
- "@babel/preset-typescript": "^7.15.0",
41
- "@babel/runtime": "^7.14.8",
42
- "@nrwl/js": "16.6.0-beta.4",
43
- "@nx/devkit": "16.6.0-beta.4",
44
- "@nx/workspace": "16.6.0-beta.4",
35
+ "@babel/core": "^7.22.9",
36
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
37
+ "@babel/plugin-proposal-decorators": "^7.22.7",
38
+ "@babel/plugin-transform-runtime": "^7.22.9",
39
+ "@babel/preset-env": "^7.22.9",
40
+ "@babel/preset-typescript": "^7.22.5",
41
+ "@babel/runtime": "^7.22.6",
42
+ "@nrwl/js": "16.6.0-beta.5",
43
+ "@nx/devkit": "16.6.0-beta.5",
44
+ "@nx/workspace": "16.6.0-beta.5",
45
45
  "@phenomnomnominal/tsquery": "~5.0.1",
46
46
  "babel-plugin-const-enum": "^1.0.1",
47
47
  "babel-plugin-macros": "^2.8.0",
@@ -71,5 +71,5 @@
71
71
  "access": "public"
72
72
  },
73
73
  "types": "./src/index.d.ts",
74
- "gitHead": "b1a9ae7ce76697019b26ec9a172005840cca8da6"
74
+ "gitHead": "aab868aa0c30949832fe2c4b9cb109c204442e39"
75
75
  }
@@ -229,7 +229,7 @@ function getExecArgv(options) {
229
229
  }
230
230
  function calculateResolveMappings(context, options) {
231
231
  const parsed = (0, devkit_1.parseTargetString)(options.buildTarget, context.projectGraph);
232
- const { dependencies } = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph, context.root, parsed.project, parsed.target, parsed.configuration);
232
+ const { dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, parsed.project, parsed.target, parsed.configuration);
233
233
  return dependencies.reduce((m, c) => {
234
234
  if (c.node.type !== 'npm' && c.outputs[0] != null) {
235
235
  m[c.name] = (0, devkit_1.joinPathFragments)(context.root, c.outputs[0]);
@@ -45,7 +45,7 @@ function createTaskInfo(taskName, taskOptions, context, tsConfig) {
45
45
  outputDir: taskOptions.outputPath,
46
46
  assets: taskOptions.assets,
47
47
  });
48
- const { target: projectGraphNode, dependencies: buildableProjectNodeDependencies, } = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph, context.root, context.taskGraph.tasks[taskName].target.project, context.taskGraph.tasks[taskName].target.target, context.taskGraph.tasks[taskName].target.configuration);
48
+ const { target: projectGraphNode, dependencies: buildableProjectNodeDependencies, } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.taskGraph.tasks[taskName].target.project, context.taskGraph.tasks[taskName].target.target, context.taskGraph.tasks[taskName].target.configuration);
49
49
  return {
50
50
  task: taskName,
51
51
  options: taskOptions,
@@ -77,6 +77,9 @@ function projectGenerator(tree, schema, destinationDir, filesDir) {
77
77
  (0, devkit_1.joinPathFragments)(options.projectRoot, './src', 'index.' + (options.js ? 'js' : 'ts')),
78
78
  ]);
79
79
  }
80
+ if (options.bundler !== 'none') {
81
+ addBundlerDependencies(tree, options);
82
+ }
80
83
  if (!options.skipFormat) {
81
84
  yield (0, devkit_1.formatFiles)(tree);
82
85
  }
@@ -165,6 +168,17 @@ function addLint(tree, options) {
165
168
  });
166
169
  }
167
170
  exports.addLint = addLint;
171
+ function addBundlerDependencies(tree, options) {
172
+ (0, devkit_1.updateJson)(tree, `${options.projectRoot}/package.json`, (json) => {
173
+ if (options.bundler === 'tsc') {
174
+ json.dependencies = Object.assign(Object.assign({}, json.dependencies), { tslib: versions_1.tsLibVersion });
175
+ }
176
+ else if (options.bundler === 'swc') {
177
+ json.dependencies = Object.assign(Object.assign({}, json.dependencies), { '@swc/helpers': versions_1.swcHelpersVersion });
178
+ }
179
+ return json;
180
+ });
181
+ }
168
182
  function updateTsConfig(tree, options) {
169
183
  (0, devkit_1.updateJson)(tree, (0, path_1.join)(options.projectRoot, 'tsconfig.json'), (json) => {
170
184
  if (options.strict) {
@@ -1,17 +1,28 @@
1
- import type { ProjectGraph, ProjectGraphProjectNode } from '@nx/devkit';
2
- import { ProjectGraphExternalNode } from '@nx/devkit';
1
+ import type { ProjectGraph, ProjectGraphExternalNode, ProjectGraphProjectNode, TaskGraph } from '@nx/devkit';
3
2
  import type * as ts from 'typescript';
4
3
  export type DependentBuildableProjectNode = {
5
4
  name: string;
6
5
  outputs: string[];
7
6
  node: ProjectGraphProjectNode | ProjectGraphExternalNode;
8
7
  };
8
+ export declare function calculateProjectBuildableDependencies(taskGraph: TaskGraph | undefined, projGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
9
+ target: ProjectGraphProjectNode;
10
+ dependencies: DependentBuildableProjectNode[];
11
+ nonBuildableDependencies: string[];
12
+ topLevelDependencies: DependentBuildableProjectNode[];
13
+ };
9
14
  export declare function calculateProjectDependencies(projGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
10
15
  target: ProjectGraphProjectNode;
11
16
  dependencies: DependentBuildableProjectNode[];
12
17
  nonBuildableDependencies: string[];
13
18
  topLevelDependencies: DependentBuildableProjectNode[];
14
19
  };
20
+ export declare function calculateDependenciesFromTaskGraph(taskGraph: TaskGraph, projectGraph: ProjectGraph, root: string, projectName: string, targetName: string, configurationName: string, shallow?: boolean): {
21
+ target: ProjectGraphProjectNode;
22
+ dependencies: DependentBuildableProjectNode[];
23
+ nonBuildableDependencies: string[];
24
+ topLevelDependencies: DependentBuildableProjectNode[];
25
+ };
15
26
  /**
16
27
  * Util function to create tsconfig compilerOptions object with support for workspace libs paths.
17
28
  *
@@ -1,19 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateBuildableProjectPackageJsonDependencies = exports.updatePaths = exports.findMissingBuildDependencies = exports.checkDependentProjectsHaveBeenBuilt = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateProjectDependencies = void 0;
4
- const path_1 = require("path");
5
- const fileutils_1 = require("nx/src/utils/fileutils");
3
+ exports.updateBuildableProjectPackageJsonDependencies = exports.updatePaths = exports.findMissingBuildDependencies = exports.checkDependentProjectsHaveBeenBuilt = exports.createTmpTsConfig = exports.computeCompilerOptionsPaths = exports.calculateDependenciesFromTaskGraph = exports.calculateProjectDependencies = exports.calculateProjectBuildableDependencies = void 0;
6
4
  const devkit_1 = require("@nx/devkit");
7
5
  const fs_1 = require("fs");
8
- const output_1 = require("nx/src/utils/output");
9
6
  const operators_1 = require("nx/src/project-graph/operators");
7
+ const fileutils_1 = require("nx/src/utils/fileutils");
8
+ const output_1 = require("nx/src/utils/output");
9
+ const path_1 = require("path");
10
10
  const ts_config_1 = require("./typescript/ts-config");
11
- let tsModule;
12
11
  function isBuildable(target, node) {
13
12
  return (node.data.targets &&
14
13
  node.data.targets[target] &&
15
14
  node.data.targets[target].executor !== '');
16
15
  }
16
+ function calculateProjectBuildableDependencies(taskGraph, projGraph, root, projectName, targetName, configurationName, shallow) {
17
+ if (process.env.NX_BUILDABLE_LIBRARIES_TASK_GRAPH === 'true' && taskGraph) {
18
+ return calculateDependenciesFromTaskGraph(taskGraph, projGraph, root, projectName, targetName, configurationName, shallow);
19
+ }
20
+ return calculateProjectDependencies(projGraph, root, projectName, targetName, configurationName, shallow);
21
+ }
22
+ exports.calculateProjectBuildableDependencies = calculateProjectBuildableDependencies;
17
23
  function calculateProjectDependencies(projGraph, root, projectName, targetName, configurationName, shallow) {
18
24
  const target = projGraph.nodes[projectName];
19
25
  // gather the library dependencies
@@ -108,6 +114,101 @@ function readTsConfigWithRemappedPaths(tsConfig, generatedTsConfigPath, dependen
108
114
  }
109
115
  return generatedTsConfig;
110
116
  }
117
+ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, projectName, targetName, configurationName, shallow) {
118
+ var _a;
119
+ const target = projectGraph.nodes[projectName];
120
+ const nonBuildableDependencies = [];
121
+ const topLevelDependencies = [];
122
+ const dependentTasks = collectDependentTasks(projectName, `${projectName}:${targetName}${configurationName ? `:${configurationName}` : ''}`, taskGraph, projectGraph, shallow);
123
+ const npmDependencies = collectNpmDependencies(projectName, projectGraph, !shallow ? dependentTasks : undefined);
124
+ const dependencies = [];
125
+ for (const [taskName, { isTopLevel }] of dependentTasks) {
126
+ let project = null;
127
+ const depTask = taskGraph.tasks[taskName];
128
+ const depProjectNode = (_a = projectGraph.nodes) === null || _a === void 0 ? void 0 : _a[depTask.target.project];
129
+ if ((depProjectNode === null || depProjectNode === void 0 ? void 0 : depProjectNode.type) !== 'lib') {
130
+ return null;
131
+ }
132
+ let outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)(depTask, depProjectNode);
133
+ if (outputs.length === 0) {
134
+ nonBuildableDependencies.push(depTask.target.project);
135
+ continue;
136
+ }
137
+ const libPackageJsonPath = (0, path_1.join)(root, depProjectNode.data.root, 'package.json');
138
+ project = {
139
+ name: (0, fileutils_1.fileExists)(libPackageJsonPath)
140
+ ? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
141
+ : depTask.target.project,
142
+ outputs,
143
+ node: depProjectNode,
144
+ };
145
+ if (isTopLevel) {
146
+ topLevelDependencies.push(project);
147
+ }
148
+ dependencies.push(project);
149
+ }
150
+ for (const { project, isTopLevel } of npmDependencies) {
151
+ if (isTopLevel) {
152
+ topLevelDependencies.push(project);
153
+ }
154
+ dependencies.push(project);
155
+ }
156
+ dependencies.sort((a, b) => (a.name > b.name ? 1 : b.name > a.name ? -1 : 0));
157
+ return {
158
+ target,
159
+ dependencies,
160
+ nonBuildableDependencies,
161
+ topLevelDependencies,
162
+ };
163
+ }
164
+ exports.calculateDependenciesFromTaskGraph = calculateDependenciesFromTaskGraph;
165
+ function collectNpmDependencies(projectName, projectGraph, dependentTasks, collectedPackages = new Set(), isTopLevel = true) {
166
+ const dependencies = projectGraph.dependencies[projectName]
167
+ .map((dep) => {
168
+ var _a, _b, _c;
169
+ const projectNode = (_b = (_a = projectGraph.nodes) === null || _a === void 0 ? void 0 : _a[dep.target]) !== null && _b !== void 0 ? _b : (_c = projectGraph.externalNodes) === null || _c === void 0 ? void 0 : _c[dep.target];
170
+ if ((projectNode === null || projectNode === void 0 ? void 0 : projectNode.type) !== 'npm' ||
171
+ collectedPackages.has(projectNode.data.packageName)) {
172
+ return null;
173
+ }
174
+ const project = {
175
+ name: projectNode.data.packageName,
176
+ outputs: [],
177
+ node: projectNode,
178
+ };
179
+ collectedPackages.add(project.name);
180
+ return { project, isTopLevel };
181
+ })
182
+ .filter((x) => !!x);
183
+ if (dependentTasks === null || dependentTasks === void 0 ? void 0 : dependentTasks.size) {
184
+ for (const [, { project: projectName }] of dependentTasks) {
185
+ dependencies.push(...collectNpmDependencies(projectName, projectGraph, undefined, collectedPackages, false));
186
+ }
187
+ }
188
+ return dependencies;
189
+ }
190
+ function collectDependentTasks(project, task, taskGraph, projectGraph, shallow, areTopLevelDeps = true, dependentTasks = new Map()) {
191
+ var _a;
192
+ for (const depTask of (_a = taskGraph.dependencies[task]) !== null && _a !== void 0 ? _a : []) {
193
+ if (dependentTasks.has(depTask)) {
194
+ if (!dependentTasks.get(depTask).isTopLevel && areTopLevelDeps) {
195
+ dependentTasks.get(depTask).isTopLevel = true;
196
+ }
197
+ continue;
198
+ }
199
+ const { project: depTaskProject } = (0, devkit_1.parseTargetString)(depTask, projectGraph);
200
+ if (depTaskProject !== project) {
201
+ dependentTasks.set(depTask, {
202
+ project: depTaskProject,
203
+ isTopLevel: areTopLevelDeps,
204
+ });
205
+ }
206
+ if (!shallow) {
207
+ collectDependentTasks(depTaskProject, depTask, taskGraph, projectGraph, shallow, depTaskProject === project && areTopLevelDeps, dependentTasks);
208
+ }
209
+ }
210
+ return dependentTasks;
211
+ }
111
212
  /**
112
213
  * Util function to create tsconfig compilerOptions object with support for workspace libs paths.
113
214
  *
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.checkDependencies = void 0;
4
4
  const buildable_libs_utils_1 = require("./buildable-libs-utils");
5
5
  function checkDependencies(context, tsConfigPath) {
6
- const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectDependencies)(context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
6
+ const { target, dependencies } = (0, buildable_libs_utils_1.calculateProjectBuildableDependencies)(context.taskGraph, context.projectGraph, context.root, context.projectName, context.targetName, context.configurationName);
7
7
  const projectRoot = target.data.root;
8
8
  if (dependencies.length > 0) {
9
9
  return {
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findNpmDependencies = void 0;
4
4
  const path_1 = require("path");
5
- const file_utils_1 = require("nx/src/project-graph/file-utils");
5
+ const configuration_1 = require("nx/src/config/configuration");
6
6
  const task_hasher_1 = require("nx/src/hasher/task-hasher");
7
7
  const devkit_1 = require("@nx/devkit");
8
8
  const fileutils_1 = require("nx/src/utils/fileutils");
@@ -44,7 +44,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
44
44
  // Cannot read inputs if the target does not exist on the project.
45
45
  if (!sourceProject.data.targets[buildTarget])
46
46
  return;
47
- const inputs = (0, task_hasher_1.getTargetInputs)((0, file_utils_1.readNxJson)(), sourceProject, buildTarget).selfInputs;
47
+ const inputs = (0, task_hasher_1.getTargetInputs)((0, configuration_1.readNxJson)(), sourceProject, buildTarget).selfInputs;
48
48
  const files = (0, task_hasher_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
49
49
  for (const fileData of files) {
50
50
  if (!fileData.deps ||