@nx/js 16.5.1 → 16.5.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.5.1",
3
+ "version": "16.5.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.5.1",
43
- "@nx/devkit": "16.5.1",
44
- "@nx/workspace": "16.5.1",
42
+ "@nrwl/js": "16.5.2",
43
+ "@nx/devkit": "16.5.2",
44
+ "@nx/workspace": "16.5.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",
@@ -69,5 +69,5 @@
69
69
  "access": "public"
70
70
  },
71
71
  "types": "./src/index.d.ts",
72
- "gitHead": "7b7f1e7f72a34cb31cff43ea0ebb80d0eab1ac79"
72
+ "gitHead": "928273940d11aa7dea87cb625a92f2c3ec62e726"
73
73
  }
@@ -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
+ }