@nx/js 23.2.0-beta.4 → 23.2.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/dist/internal.d.ts +3 -3
- package/dist/internal.js +12 -15
- package/dist/src/executors/copy-workspace-modules/copy-workspace-modules.js +4 -5
- package/dist/src/executors/node/lib/output-file.js +4 -4
- package/dist/src/executors/node/node.impl.js +9 -9
- package/dist/src/executors/prune-lockfile/prune-lockfile.d.ts +1 -1
- package/dist/src/executors/prune-lockfile/prune-lockfile.js +7 -9
- package/dist/src/executors/tsc/lib/batch/watch.js +3 -3
- package/dist/src/executors/tsc/tsc.batch-impl.d.ts +1 -1
- package/dist/src/executors/tsc/tsc.batch-impl.js +2 -2
- package/dist/src/executors/verdaccio/verdaccio.impl.js +2 -2
- package/dist/src/generators/library/utils/add-release-config.js +2 -2
- package/dist/src/generators/setup-build/generator.js +1 -2
- package/dist/src/generators/typescript-sync/typescript-sync.d.ts +1 -1
- package/dist/src/generators/typescript-sync/typescript-sync.js +2 -2
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.js +5 -7
- package/dist/src/plugins/typescript/plugin.js +14 -14
- package/dist/src/plugins/typescript/util.d.ts +1 -1
- package/dist/src/release/utils/update-lock-file.js +6 -7
- package/dist/src/release/version-actions.d.ts +7 -2
- package/dist/src/release/version-actions.js +111 -57
- package/dist/src/utils/assets/copy-assets-handler.d.ts +1 -1
- package/dist/src/utils/assets/copy-assets-handler.js +2 -2
- package/dist/src/utils/buildable-libs-utils.js +10 -13
- package/dist/src/utils/find-npm-dependencies.js +7 -10
- package/dist/src/utils/generate-globs.js +11 -14
- package/dist/src/utils/get-main-file-dir.js +2 -2
- package/dist/src/utils/npm-config.d.ts +1 -1
- package/dist/src/utils/package-json/update-package-json.d.ts +1 -1
- package/dist/src/utils/package-json/update-package-json.js +9 -11
- package/dist/src/utils/package-manager-workspaces.js +2 -2
- package/dist/src/utils/typescript/create-ts-config.d.ts +1 -1
- package/dist/src/utils/typescript/create-ts-config.js +5 -5
- package/dist/src/utils/typescript/plugin.js +2 -2
- package/dist/src/utils/typescript/run-type-check.js +2 -2
- package/dist/src/utils/typescript/ts-solution-setup.d.ts +1 -1
- package/dist/src/utils/typescript/ts-solution-setup.js +3 -3
- package/dist/src/utils/watch-for-single-file-changes.js +2 -2
- package/package.json +4 -4
|
@@ -5,6 +5,7 @@ const internal_1 = require("@nx/devkit/internal");
|
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
const node_child_process_1 = require("node:child_process");
|
|
7
7
|
const node_path_1 = require("node:path");
|
|
8
|
+
const jsonc_parser_1 = require("jsonc-parser");
|
|
8
9
|
const release_1 = require("nx/release");
|
|
9
10
|
const npm_config_1 = require("../utils/npm-config");
|
|
10
11
|
const update_lock_file_1 = require("./utils/update-lock-file");
|
|
@@ -26,6 +27,7 @@ class JsVersionActions extends release_1.VersionActions {
|
|
|
26
27
|
constructor() {
|
|
27
28
|
super(...arguments);
|
|
28
29
|
this.validManifestFilenames = ['package.json'];
|
|
30
|
+
this.excludeManifestsFromFormatting = true;
|
|
29
31
|
}
|
|
30
32
|
async readCurrentVersionFromSourceManifest(tree) {
|
|
31
33
|
const sourcePackageJsonPath = (0, node_path_1.join)(this.projectGraphNode.data.root, 'package.json');
|
|
@@ -122,10 +124,9 @@ class JsVersionActions extends release_1.VersionActions {
|
|
|
122
124
|
async updateProjectVersion(tree, newVersion) {
|
|
123
125
|
const logMessages = [];
|
|
124
126
|
for (const manifestToUpdate of this.manifestsToUpdate) {
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
});
|
|
127
|
+
this.updateManifestValues(tree, manifestToUpdate.manifestPath, [
|
|
128
|
+
{ path: ['version'], value: newVersion },
|
|
129
|
+
]);
|
|
129
130
|
logMessages.push(`✍️ New version ${newVersion} written to manifest: ${manifestToUpdate.manifestPath}`);
|
|
130
131
|
}
|
|
131
132
|
return logMessages;
|
|
@@ -139,67 +140,70 @@ class JsVersionActions extends release_1.VersionActions {
|
|
|
139
140
|
const catalogUpdates = [];
|
|
140
141
|
const catalogManager = (0, internal_1.getCatalogManager)(tree.root);
|
|
141
142
|
for (const manifestToUpdate of this.manifestsToUpdate) {
|
|
142
|
-
(0, devkit_1.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
143
|
+
const json = (0, devkit_1.readJson)(tree, manifestToUpdate.manifestPath);
|
|
144
|
+
const manifestUpdates = [];
|
|
145
|
+
const dependencyTypes = [
|
|
146
|
+
'dependencies',
|
|
147
|
+
'devDependencies',
|
|
148
|
+
'peerDependencies',
|
|
149
|
+
'optionalDependencies',
|
|
150
|
+
];
|
|
151
|
+
const preserveMatchingDependencyRanges = this.finalConfigForProject.preserveMatchingDependencyRanges === true
|
|
152
|
+
? dependencyTypes
|
|
153
|
+
: this.finalConfigForProject.preserveMatchingDependencyRanges ===
|
|
154
|
+
false
|
|
155
|
+
? []
|
|
156
|
+
: this.finalConfigForProject.preserveMatchingDependencyRanges ||
|
|
157
|
+
dependencyTypes;
|
|
158
|
+
for (const depType of dependencyTypes) {
|
|
159
|
+
if (json[depType]) {
|
|
160
|
+
for (const [dep, version] of Object.entries(dependenciesToUpdate)) {
|
|
161
|
+
// Resolve the package name from the project graph metadata, as it may not match the project name
|
|
162
|
+
const packageName = projectGraph.nodes[dep].data.metadata?.js?.packageName;
|
|
163
|
+
if (!packageName) {
|
|
164
|
+
throw new Error(`Unable to determine the package name for project "${dep}" from the project graph metadata, please ensure that the "@nx/js" plugin is installed and the project graph has been built. If the issue persists, please report this issue on https://github.com/nrwl/nx/issues`);
|
|
165
|
+
}
|
|
166
|
+
const currentVersion = json[depType][packageName];
|
|
167
|
+
if (currentVersion) {
|
|
168
|
+
if (catalogManager?.isCatalogReference(currentVersion)) {
|
|
169
|
+
// collect the catalog updates so we can update the catalog definitions later
|
|
170
|
+
const catalogRef = catalogManager.parseCatalogReference(currentVersion);
|
|
171
|
+
catalogUpdates.push({
|
|
172
|
+
packageName,
|
|
173
|
+
version,
|
|
174
|
+
catalogName: catalogRef.catalogName,
|
|
175
|
+
});
|
|
176
|
+
numDependenciesToUpdate--;
|
|
177
|
+
continue;
|
|
163
178
|
}
|
|
164
|
-
|
|
165
|
-
if (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
179
|
+
// Check if other local dependency protocols should be preserved
|
|
180
|
+
else if (manifestToUpdate.preserveLocalDependencyProtocols &&
|
|
181
|
+
this.isLocalDependencyProtocol(currentVersion)) {
|
|
182
|
+
// Reduce the count appropriately to avoid confusing user-facing logs
|
|
183
|
+
numDependenciesToUpdate--;
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
else if (preserveMatchingDependencyRanges.includes(depType) &&
|
|
187
|
+
!this.isLocalDependencyProtocol(currentVersion)) {
|
|
188
|
+
// If the dependency is specified using a range, do some additional processing to determine whether to update the version
|
|
189
|
+
if ((0, semver_1.isValidRange)(currentVersion) &&
|
|
190
|
+
!(0, semver_1.isMatchingDependencyRange)(version, currentVersion)) {
|
|
191
|
+
throw new Error(`"preserveMatchingDependencyRanges" is enabled for "${depType}" and the new version "${version}" is outside the current range for "${packageName}" in manifest "${manifestToUpdate.manifestPath}". Please update the range before releasing.`);
|
|
176
192
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.isLocalDependencyProtocol(currentVersion)) {
|
|
180
|
-
// Reduce the count appropriately to avoid confusing user-facing logs
|
|
181
|
-
numDependenciesToUpdate--;
|
|
193
|
+
else if ((0, semver_1.isValidRange)(currentVersion)) {
|
|
194
|
+
// it is a range, but it is valid
|
|
182
195
|
continue;
|
|
183
196
|
}
|
|
184
|
-
else if (preserveMatchingDependencyRanges.includes(depType) &&
|
|
185
|
-
!this.isLocalDependencyProtocol(currentVersion)) {
|
|
186
|
-
// If the dependency is specified using a range, do some additional processing to determine whether to update the version
|
|
187
|
-
if ((0, semver_1.isValidRange)(currentVersion) &&
|
|
188
|
-
!(0, semver_1.isMatchingDependencyRange)(version, currentVersion)) {
|
|
189
|
-
throw new Error(`"preserveMatchingDependencyRanges" is enabled for "${depType}" and the new version "${version}" is outside the current range for "${packageName}" in manifest "${manifestToUpdate.manifestPath}". Please update the range before releasing.`);
|
|
190
|
-
}
|
|
191
|
-
else if ((0, semver_1.isValidRange)(currentVersion)) {
|
|
192
|
-
// it is a range, but it is valid
|
|
193
|
-
continue;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
json[depType][packageName] = version;
|
|
197
197
|
}
|
|
198
|
+
manifestUpdates.push({
|
|
199
|
+
path: [depType, packageName],
|
|
200
|
+
value: version,
|
|
201
|
+
});
|
|
198
202
|
}
|
|
199
203
|
}
|
|
200
204
|
}
|
|
201
|
-
|
|
202
|
-
|
|
205
|
+
}
|
|
206
|
+
this.updateManifestValues(tree, manifestToUpdate.manifestPath, manifestUpdates);
|
|
203
207
|
// If we ignored local dependecy protocols, then we could have dynamically ended up with zero here and we should not log anything related to dependencies
|
|
204
208
|
if (numDependenciesToUpdate === 0) {
|
|
205
209
|
return [];
|
|
@@ -218,6 +222,56 @@ class JsVersionActions extends release_1.VersionActions {
|
|
|
218
222
|
}
|
|
219
223
|
return logMessages;
|
|
220
224
|
}
|
|
225
|
+
updateManifestValues(tree, manifestPath, updates) {
|
|
226
|
+
if (updates.length === 0) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
let content = this.readAndValidateManifest(tree, manifestPath);
|
|
230
|
+
const formattingOptions = this.detectFormattingOptions(content);
|
|
231
|
+
for (const update of updates) {
|
|
232
|
+
content = (0, jsonc_parser_1.applyEdits)(content, (0, jsonc_parser_1.modify)(content, update.path, update.value, { formattingOptions }));
|
|
233
|
+
}
|
|
234
|
+
this.validateManifestUpdates(content, manifestPath, updates);
|
|
235
|
+
tree.write(manifestPath, content);
|
|
236
|
+
}
|
|
237
|
+
readAndValidateManifest(tree, manifestPath) {
|
|
238
|
+
const content = tree.read(manifestPath, 'utf-8');
|
|
239
|
+
try {
|
|
240
|
+
// Match readJson's support for comments and trailing commas while
|
|
241
|
+
// retaining the original text for targeted edits.
|
|
242
|
+
(0, devkit_1.parseJson)(content);
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
throw new Error(`Cannot parse ${manifestPath}: ${error.message}`);
|
|
246
|
+
}
|
|
247
|
+
return content;
|
|
248
|
+
}
|
|
249
|
+
validateManifestUpdates(content, manifestPath, updates) {
|
|
250
|
+
const manifest = (0, devkit_1.parseJson)(content);
|
|
251
|
+
for (const update of updates) {
|
|
252
|
+
let actualValue = manifest;
|
|
253
|
+
for (const pathSegment of update.path) {
|
|
254
|
+
if (actualValue === null ||
|
|
255
|
+
typeof actualValue !== 'object' ||
|
|
256
|
+
!(pathSegment in actualValue)) {
|
|
257
|
+
actualValue = undefined;
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
actualValue = actualValue[pathSegment];
|
|
261
|
+
}
|
|
262
|
+
if (actualValue !== update.value) {
|
|
263
|
+
throw new Error(`Cannot update ${manifestPath}: "${update.path.join('.')}" resolves to ${JSON.stringify(actualValue)} instead of ${JSON.stringify(update.value)} after editing. The manifest may contain duplicate keys.`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
detectFormattingOptions(content) {
|
|
268
|
+
const indentation = content.match(/^[\t ]+(?=")/m)?.[0] ?? ' ';
|
|
269
|
+
const insertSpaces = !indentation.includes('\t');
|
|
270
|
+
return {
|
|
271
|
+
insertSpaces,
|
|
272
|
+
tabSize: insertSpaces ? indentation.length : 1,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
221
275
|
// NOTE: The TODOs were carried over from the original implementation, they are not yet implemented
|
|
222
276
|
isLocalDependencyProtocol(versionSpecifier) {
|
|
223
277
|
const localPackageProtocols = [
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AssetGlob } from './assets';
|
|
2
2
|
import { normalizeAssets, getAssetOutputPath, NormalizedAssetEntry as AssetEntry } from './normalize-assets';
|
|
3
|
-
import { ChangedFile } from 'nx/
|
|
3
|
+
import { ChangedFile } from '@nx/devkit/internal';
|
|
4
4
|
export type { AssetEntry };
|
|
5
5
|
export { normalizeAssets, getAssetOutputPath };
|
|
6
6
|
export type FileEventType = 'create' | 'update' | 'delete';
|
|
@@ -12,7 +12,7 @@ const normalize_assets_1 = require("./normalize-assets");
|
|
|
12
12
|
Object.defineProperty(exports, "normalizeAssets", { enumerable: true, get: function () { return normalize_assets_1.normalizeAssets; } });
|
|
13
13
|
Object.defineProperty(exports, "getAssetOutputPath", { enumerable: true, get: function () { return normalize_assets_1.getAssetOutputPath; } });
|
|
14
14
|
const devkit_1 = require("@nx/devkit");
|
|
15
|
-
const
|
|
15
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
16
16
|
const picocolors_1 = require("picocolors");
|
|
17
17
|
const defaultFileEventHandler = (events) => {
|
|
18
18
|
const dirs = new Set(events.map((event) => path.dirname(event.dest)));
|
|
@@ -93,7 +93,7 @@ class CopyAssetsHandler {
|
|
|
93
93
|
return ['**/node_modules/**', '**/.git/**'];
|
|
94
94
|
}
|
|
95
95
|
async watchAndProcessOnAssetChange() {
|
|
96
|
-
const unregisterFileWatcher = await
|
|
96
|
+
const unregisterFileWatcher = await internal_1.daemonClient.registerFileWatcher({
|
|
97
97
|
watchProjects: 'all',
|
|
98
98
|
includeGlobalWorkspaceFiles: true,
|
|
99
99
|
}, (err, data) => {
|
|
@@ -9,14 +9,11 @@ exports.updatePaths = updatePaths;
|
|
|
9
9
|
exports.updateBuildableProjectPackageJsonDependencies = updateBuildableProjectPackageJsonDependencies;
|
|
10
10
|
const devkit_1 = require("@nx/devkit");
|
|
11
11
|
const fs_1 = require("fs");
|
|
12
|
-
const operators_1 = require("nx/src/project-graph/operators");
|
|
13
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
14
|
-
const output_1 = require("nx/src/utils/output");
|
|
15
12
|
const path_1 = require("path");
|
|
16
13
|
const ts_config_1 = require("./typescript/ts-config");
|
|
17
14
|
const strip_glob_to_base_dir_1 = require("./strip-glob-to-base-dir");
|
|
18
15
|
const crypto_1 = require("crypto");
|
|
19
|
-
const
|
|
16
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
20
17
|
function isBuildable(target, node) {
|
|
21
18
|
return (node.data.targets &&
|
|
22
19
|
node.data.targets[target] &&
|
|
@@ -49,11 +46,11 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
49
46
|
.map(({ name: dep, isTopLevel }) => {
|
|
50
47
|
let project = null;
|
|
51
48
|
const depNode = projGraph.nodes[dep] || projGraph.externalNodes[dep];
|
|
52
|
-
if ((0,
|
|
49
|
+
if ((0, internal_1.isProjectGraphProjectNode)(depNode) && depNode.type === 'lib') {
|
|
53
50
|
if (isBuildable(targetName, depNode)) {
|
|
54
51
|
const libPackageJsonPath = (0, path_1.join)(root, depNode.data.root, 'package.json');
|
|
55
52
|
project = {
|
|
56
|
-
name: (0,
|
|
53
|
+
name: (0, internal_1.fileExists)(libPackageJsonPath)
|
|
57
54
|
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
58
55
|
: dep,
|
|
59
56
|
outputs: (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
@@ -68,7 +65,7 @@ function calculateProjectDependencies(projGraph, root, projectName, targetName,
|
|
|
68
65
|
nonBuildableDependencies.push(dep);
|
|
69
66
|
}
|
|
70
67
|
}
|
|
71
|
-
else if ((0,
|
|
68
|
+
else if ((0, internal_1.isProjectGraphExternalNode)(depNode)) {
|
|
72
69
|
project = {
|
|
73
70
|
name: depNode.data.packageName,
|
|
74
71
|
outputs: [],
|
|
@@ -130,7 +127,7 @@ function readTsConfigWithRemappedPaths(originalTsconfigPath, generatedTsconfigPa
|
|
|
130
127
|
}
|
|
131
128
|
generatedTsConfig.compilerOptions.paths = paths;
|
|
132
129
|
if (process.env.NX_VERBOSE_LOGGING_PATH_MAPPINGS === 'true') {
|
|
133
|
-
|
|
130
|
+
devkit_1.output.log({
|
|
134
131
|
title: 'TypeScript path mappings have been rewritten.',
|
|
135
132
|
});
|
|
136
133
|
console.log(JSON.stringify(generatedTsConfig.compilerOptions.paths, null, 2));
|
|
@@ -158,7 +155,7 @@ function calculateDependenciesFromTaskGraph(taskGraph, projectGraph, root, proje
|
|
|
158
155
|
}
|
|
159
156
|
const libPackageJsonPath = (0, path_1.join)(root, depProjectNode.data.root, 'package.json');
|
|
160
157
|
project = {
|
|
161
|
-
name: (0,
|
|
158
|
+
name: (0, internal_1.fileExists)(libPackageJsonPath)
|
|
162
159
|
? (0, devkit_1.readJsonFile)(libPackageJsonPath).name // i.e. @workspace/mylib
|
|
163
160
|
: depTask.target.project,
|
|
164
161
|
outputs,
|
|
@@ -264,7 +261,7 @@ function updatePaths(dependencies, paths) {
|
|
|
264
261
|
const pathsKeys = Object.keys(paths);
|
|
265
262
|
// For each registered dependency
|
|
266
263
|
dependencies
|
|
267
|
-
.filter((dep) => (0,
|
|
264
|
+
.filter((dep) => (0, internal_1.isProjectGraphProjectNode)(dep.node))
|
|
268
265
|
.forEach((dep) => {
|
|
269
266
|
// If there are outputs
|
|
270
267
|
if (dep.outputs && dep.outputs.length > 0) {
|
|
@@ -335,7 +332,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
335
332
|
packageJson.peerDependencies = packageJson.peerDependencies || {};
|
|
336
333
|
let updatePackageJson = false;
|
|
337
334
|
dependencies.forEach((entry) => {
|
|
338
|
-
const packageName = (0,
|
|
335
|
+
const packageName = (0, internal_1.isNpmProject)(entry.node)
|
|
339
336
|
? entry.node.data.packageName
|
|
340
337
|
: entry.name;
|
|
341
338
|
if (!hasDependency(packageJson, 'dependencies', packageName) &&
|
|
@@ -343,7 +340,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
343
340
|
!hasDependency(packageJson, 'peerDependencies', packageName)) {
|
|
344
341
|
try {
|
|
345
342
|
let depVersion;
|
|
346
|
-
if ((0,
|
|
343
|
+
if ((0, internal_1.isProjectGraphProjectNode)(entry.node) &&
|
|
347
344
|
entry.node.type === 'lib') {
|
|
348
345
|
const outputs = (0, devkit_1.getOutputsForTargetAndConfiguration)({
|
|
349
346
|
project: projectName,
|
|
@@ -354,7 +351,7 @@ function updateBuildableProjectPackageJsonDependencies(root, projectName, target
|
|
|
354
351
|
depVersion = (0, devkit_1.readJsonFile)(depPackageJsonPath).version;
|
|
355
352
|
packageJson[typeOfDependency][packageName] = depVersion;
|
|
356
353
|
}
|
|
357
|
-
else if ((0,
|
|
354
|
+
else if ((0, internal_1.isNpmProject)(entry.node)) {
|
|
358
355
|
// If an npm dep is part of the workspace devDependencies, do not include it the library
|
|
359
356
|
if (!!workspacePackageJson.devDependencies?.[entry.node.data.packageName]) {
|
|
360
357
|
return;
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.findNpmDependencies = findNpmDependencies;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const configuration_1 = require("nx/src/config/configuration");
|
|
6
5
|
const devkit_1 = require("@nx/devkit");
|
|
7
|
-
const fileutils_1 = require("nx/src/utils/fileutils");
|
|
8
|
-
const project_graph_1 = require("nx/src/config/project-graph");
|
|
9
6
|
const ts_config_1 = require("./typescript/ts-config");
|
|
10
|
-
const
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
11
8
|
/**
|
|
12
9
|
* Finds all npm dependencies and their expected versions for a given project.
|
|
13
10
|
*/
|
|
@@ -44,14 +41,14 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
44
41
|
// If build target does not exist in project, use all files as input.
|
|
45
42
|
// This is needed for transitive dependencies for apps -- where libs may not be buildable.
|
|
46
43
|
const inputs = sourceProject.data.targets[buildTarget]
|
|
47
|
-
? (0,
|
|
44
|
+
? (0, internal_1.getTargetInputs)((0, internal_1.readNxJsonFromDisk)(), sourceProject, buildTarget).selfInputs
|
|
48
45
|
: ['{projectRoot}/**/*'];
|
|
49
46
|
if (ignoredFiles) {
|
|
50
47
|
for (const pattern of ignoredFiles) {
|
|
51
48
|
inputs.push(`!${pattern}`);
|
|
52
49
|
}
|
|
53
50
|
}
|
|
54
|
-
const files = (0,
|
|
51
|
+
const files = (0, internal_1.filterUsingGlobPatterns)(sourceProject.data.root, projectFileMap[sourceProject.name] || [], inputs);
|
|
55
52
|
for (const fileData of files) {
|
|
56
53
|
if (!fileData.deps ||
|
|
57
54
|
fileData.file ===
|
|
@@ -59,7 +56,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
59
56
|
continue;
|
|
60
57
|
}
|
|
61
58
|
for (const dep of fileData.deps) {
|
|
62
|
-
const target = (0,
|
|
59
|
+
const target = (0, internal_1.fileDataDepTarget)(dep);
|
|
63
60
|
// If the node is external, then read package info from `data`.
|
|
64
61
|
const externalDep = projectGraph.externalNodes[target];
|
|
65
62
|
if (externalDep?.type === 'npm') {
|
|
@@ -110,7 +107,7 @@ function collectDependenciesFromFileMap(workspaceRoot, sourceProject, projectGra
|
|
|
110
107
|
}
|
|
111
108
|
function readPackageJson(project, workspaceRoot) {
|
|
112
109
|
const packageJsonPath = (0, path_1.join)(workspaceRoot, project.data.root, 'package.json');
|
|
113
|
-
if ((0,
|
|
110
|
+
if ((0, internal_1.fileExists)(packageJsonPath))
|
|
114
111
|
return (0, devkit_1.readJsonFile)(packageJsonPath);
|
|
115
112
|
return null;
|
|
116
113
|
}
|
|
@@ -139,7 +136,7 @@ function collectHelperDependencies(workspaceRoot, sourceProject, projectGraph, b
|
|
|
139
136
|
const swcConfigPath = target.options.swcrc
|
|
140
137
|
? (0, path_1.join)(workspaceRoot, target.options.swcrc)
|
|
141
138
|
: (0, path_1.join)(workspaceRoot, sourceProject.data.root, '.swcrc');
|
|
142
|
-
const swcConfig = (0,
|
|
139
|
+
const swcConfig = (0, internal_1.fileExists)(swcConfigPath)
|
|
143
140
|
? (0, devkit_1.readJsonFile)(swcConfigPath)
|
|
144
141
|
: {};
|
|
145
142
|
if (swcConfig?.jsc?.externalHelpers &&
|
|
@@ -169,7 +166,7 @@ function resolveTsConfigForRunCommandsTarget(workspaceRoot, sourceProject, targe
|
|
|
169
166
|
const resolved = (0, path_1.isAbsolute)(commandTsConfig)
|
|
170
167
|
? commandTsConfig
|
|
171
168
|
: (0, path_1.join)(cwdAbsolute, commandTsConfig);
|
|
172
|
-
if ((0,
|
|
169
|
+
if ((0, internal_1.fileExists)(resolved))
|
|
173
170
|
return resolved;
|
|
174
171
|
}
|
|
175
172
|
// Preserves prior behavior when the tsconfig can't be determined from the command.
|
|
@@ -3,16 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.createGlobPatternsForDependencies = createGlobPatternsForDependencies;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
const devkit_1 = require("@nx/devkit");
|
|
6
|
-
const workspace_root_1 = require("nx/src/utils/workspace-root");
|
|
7
6
|
const path_1 = require("path");
|
|
8
|
-
const project_graph_1 = require("nx/src/project-graph/project-graph");
|
|
9
|
-
const project_graph_utils_1 = require("nx/src/utils/project-graph-utils");
|
|
10
7
|
const fs_1 = require("fs");
|
|
11
8
|
const ignore_1 = tslib_1.__importDefault(require("ignore"));
|
|
12
|
-
const
|
|
9
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
13
10
|
function configureIgnore() {
|
|
14
11
|
let ig;
|
|
15
|
-
const pathToGitIgnore = (0, path_1.join)(
|
|
12
|
+
const pathToGitIgnore = (0, path_1.join)(devkit_1.workspaceRoot, '.gitignore');
|
|
16
13
|
if ((0, fs_1.existsSync)(pathToGitIgnore)) {
|
|
17
14
|
ig = (0, ignore_1.default)();
|
|
18
15
|
ig.add((0, fs_1.readFileSync)(pathToGitIgnore, { encoding: 'utf-8' }));
|
|
@@ -26,13 +23,13 @@ function configureIgnore() {
|
|
|
26
23
|
*/
|
|
27
24
|
function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
|
|
28
25
|
let ig = configureIgnore();
|
|
29
|
-
const filenameRelativeToWorkspaceRoot = (0, devkit_1.normalizePath)((0, path_1.relative)(
|
|
30
|
-
const projectGraph = (0,
|
|
31
|
-
const projectRootMappings = (0,
|
|
26
|
+
const filenameRelativeToWorkspaceRoot = (0, devkit_1.normalizePath)((0, path_1.relative)(devkit_1.workspaceRoot, dirPath));
|
|
27
|
+
const projectGraph = (0, devkit_1.readCachedProjectGraph)();
|
|
28
|
+
const projectRootMappings = (0, internal_1.createProjectRootMappings)(projectGraph.nodes);
|
|
32
29
|
// find the project
|
|
33
30
|
let projectName;
|
|
34
31
|
try {
|
|
35
|
-
projectName = (0,
|
|
32
|
+
projectName = (0, internal_1.findProjectForPath)(filenameRelativeToWorkspaceRoot, projectRootMappings);
|
|
36
33
|
if (!projectName) {
|
|
37
34
|
throw new Error(`createGlobPatternsForDependencies: Could not find any project containing the file "${filenameRelativeToWorkspaceRoot}" among it's project files`);
|
|
38
35
|
}
|
|
@@ -42,17 +39,17 @@ function createGlobPatternsForDependencies(dirPath, fileGlobPattern) {
|
|
|
42
39
|
}
|
|
43
40
|
// generate the glob
|
|
44
41
|
try {
|
|
45
|
-
const [projectDirs, warnings] = (0,
|
|
42
|
+
const [projectDirs, warnings] = (0, internal_1.getSourceDirOfDependentProjects)(projectName, projectGraph);
|
|
46
43
|
const dirsToUse = [];
|
|
47
44
|
const recursiveScanDirs = (dirPath) => {
|
|
48
|
-
const children = (0, fs_1.readdirSync)((0, path_1.resolve)(
|
|
45
|
+
const children = (0, fs_1.readdirSync)((0, path_1.resolve)(devkit_1.workspaceRoot, dirPath));
|
|
49
46
|
for (const child of children) {
|
|
50
47
|
const childPath = (0, path_1.join)(dirPath, child);
|
|
51
48
|
if (ig?.ignores(childPath) ||
|
|
52
|
-
!(0, fs_1.lstatSync)((0, path_1.resolve)(
|
|
49
|
+
!(0, fs_1.lstatSync)((0, path_1.resolve)(devkit_1.workspaceRoot, childPath)).isDirectory()) {
|
|
53
50
|
continue;
|
|
54
51
|
}
|
|
55
|
-
if ((0, fs_1.existsSync)((0, path_1.join)(
|
|
52
|
+
if ((0, fs_1.existsSync)((0, path_1.join)(devkit_1.workspaceRoot, childPath, 'ng-package.json'))) {
|
|
56
53
|
dirsToUse.push(childPath);
|
|
57
54
|
}
|
|
58
55
|
else {
|
|
@@ -72,7 +69,7 @@ ${warnings.join('\n- ')}\n
|
|
|
72
69
|
due to missing "sourceRoot" in the dependencies' project configuration
|
|
73
70
|
`);
|
|
74
71
|
}
|
|
75
|
-
return dirsToUse.map((sourceDir) => (0, path_1.resolve)(
|
|
72
|
+
return dirsToUse.map((sourceDir) => (0, path_1.resolve)(devkit_1.workspaceRoot, (0, devkit_1.joinPathFragments)(sourceDir, fileGlobPattern)));
|
|
76
73
|
}
|
|
77
74
|
catch (e) {
|
|
78
75
|
throw new Error(`createGlobPatternsForDependencies: Error when generating globs.\n${e?.message}`);
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getRelativeDirectoryToProjectRoot = getRelativeDirectoryToProjectRoot;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const
|
|
5
|
+
const devkit_1 = require("@nx/devkit");
|
|
6
6
|
function getRelativeDirectoryToProjectRoot(file, projectRoot) {
|
|
7
7
|
const dir = (0, path_1.dirname)(file);
|
|
8
|
-
const relativeDir = (0,
|
|
8
|
+
const relativeDir = (0, devkit_1.normalizePath)((0, path_1.relative)(projectRoot, dir));
|
|
9
9
|
return relativeDir === '' ? `./` : `./${relativeDir}/`;
|
|
10
10
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ExecutorContext, ProjectFileMap, ProjectGraphProjectNode } from '@nx/devkit';
|
|
2
2
|
import { DependentBuildableProjectNode } from '../buildable-libs-utils';
|
|
3
|
-
import type { PackageJson } from 'nx/
|
|
3
|
+
import type { PackageJson } from '@nx/devkit/internal';
|
|
4
4
|
export type SupportedFormat = 'cjs' | 'esm';
|
|
5
5
|
export interface UpdatePackageJsonOption {
|
|
6
6
|
rootDir?: string;
|
|
@@ -4,24 +4,22 @@ exports.updatePackageJson = updatePackageJson;
|
|
|
4
4
|
exports.getExports = getExports;
|
|
5
5
|
exports.getUpdatedPackageJsonContent = getUpdatedPackageJsonContent;
|
|
6
6
|
exports.getOutputDir = getOutputDir;
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
|
10
|
-
const create_package_json_1 = require("nx/src/plugins/js/package-json/create-package-json");
|
|
7
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
8
|
+
const internal_2 = require("@nx/devkit/internal");
|
|
11
9
|
const devkit_1 = require("@nx/devkit");
|
|
12
10
|
const node_fs_1 = require("node:fs");
|
|
13
11
|
const path_1 = require("path");
|
|
14
|
-
const
|
|
15
|
-
const
|
|
12
|
+
const internal_3 = require("@nx/devkit/internal");
|
|
13
|
+
const internal_4 = require("@nx/devkit/internal");
|
|
16
14
|
const get_main_file_dir_1 = require("../get-main-file-dir");
|
|
17
15
|
const strip_glob_to_base_dir_1 = require("../strip-glob-to-base-dir");
|
|
18
16
|
function updatePackageJson(options, context, target, dependencies, fileMap = null) {
|
|
19
17
|
let packageJson;
|
|
20
18
|
if (fileMap == null) {
|
|
21
|
-
fileMap = (0,
|
|
19
|
+
fileMap = (0, internal_4.readFileMapCache)()?.fileMap?.projectFileMap || {};
|
|
22
20
|
}
|
|
23
21
|
if (options.updateBuildableProjectDepsInPackageJson) {
|
|
24
|
-
packageJson = (0,
|
|
22
|
+
packageJson = (0, internal_2.createPackageJson)(context.projectName, context.projectGraph, {
|
|
25
23
|
target: context.targetName,
|
|
26
24
|
root: context.root,
|
|
27
25
|
// By default we remove devDependencies since this is a production build.
|
|
@@ -34,7 +32,7 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
34
32
|
}
|
|
35
33
|
else {
|
|
36
34
|
const pathToPackageJson = (0, path_1.join)(context.root, options.projectRoot, 'package.json');
|
|
37
|
-
packageJson = (0,
|
|
35
|
+
packageJson = (0, internal_3.fileExists)(pathToPackageJson)
|
|
38
36
|
? (0, devkit_1.readJsonFile)(pathToPackageJson)
|
|
39
37
|
: { name: context.projectName, version: '0.0.1' };
|
|
40
38
|
}
|
|
@@ -60,8 +58,8 @@ function updatePackageJson(options, context, target, dependencies, fileMap = nul
|
|
|
60
58
|
devkit_1.logger.warn(`Bun lockfile generation is unsupported. Remove "generateLockfile" option or set it to false.`);
|
|
61
59
|
}
|
|
62
60
|
else {
|
|
63
|
-
const lockFile = (0,
|
|
64
|
-
(0, node_fs_1.writeFileSync)(`${options.outputPath}/${(0,
|
|
61
|
+
const lockFile = (0, internal_1.createLockFile)(packageJson, context.projectGraph, packageManager);
|
|
62
|
+
(0, node_fs_1.writeFileSync)(`${options.outputPath}/${(0, internal_1.getLockFileName)(packageManager)}`, lockFile, {
|
|
65
63
|
encoding: 'utf-8',
|
|
66
64
|
});
|
|
67
65
|
}
|
|
@@ -8,8 +8,8 @@ exports.getProjectPackageManagerWorkspaceStateWarningTask = getProjectPackageMan
|
|
|
8
8
|
const devkit_1 = require("@nx/devkit");
|
|
9
9
|
const picomatch = require("picomatch");
|
|
10
10
|
const posix_1 = require("node:path/posix");
|
|
11
|
-
const package_json_1 = require("nx/src/plugins/package-json");
|
|
12
11
|
const semver_1 = require("semver");
|
|
12
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
13
13
|
function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
14
14
|
if (!isUsingPackageManagerWorkspaces(tree)) {
|
|
15
15
|
return 'no-workspaces';
|
|
@@ -19,7 +19,7 @@ function getProjectPackageManagerWorkspaceState(tree, projectRoot) {
|
|
|
19
19
|
return isIncluded ? 'included' : 'excluded';
|
|
20
20
|
}
|
|
21
21
|
function getPackageManagerWorkspacesPatterns(tree) {
|
|
22
|
-
return (0,
|
|
22
|
+
return (0, internal_1.getGlobPatternsFromPackageManagerWorkspaces)(tree.root, (path) => (0, devkit_1.readJson)(tree, path, { expectComments: true }), (path) => {
|
|
23
23
|
const content = tree.read(path, 'utf-8');
|
|
24
24
|
const { load } = require('@zkochan/js-yaml');
|
|
25
25
|
return load(content, { filename: path });
|
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.tsConfigBaseOptions = void 0;
|
|
4
4
|
exports.getTsConfigBaseOptions = getTsConfigBaseOptions;
|
|
5
5
|
exports.extractTsConfigBase = extractTsConfigBase;
|
|
6
|
-
const json_1 = require("nx/src/generators/utils/json");
|
|
7
6
|
const is_typescript_version_at_least_1 = require("../is-typescript-version-at-least");
|
|
7
|
+
const devkit_1 = require("@nx/devkit");
|
|
8
8
|
exports.tsConfigBaseOptions = {
|
|
9
9
|
rootDir: '.',
|
|
10
10
|
sourceMap: true,
|
|
@@ -32,7 +32,7 @@ function getTsConfigBaseOptions(tree) {
|
|
|
32
32
|
function extractTsConfigBase(host) {
|
|
33
33
|
if (host.exists('tsconfig.base.json'))
|
|
34
34
|
return;
|
|
35
|
-
const tsconfig = (0,
|
|
35
|
+
const tsconfig = (0, devkit_1.readJson)(host, 'tsconfig.json');
|
|
36
36
|
const baseCompilerOptions = {};
|
|
37
37
|
if (tsconfig.compilerOptions) {
|
|
38
38
|
for (let compilerOption of Object.keys(exports.tsConfigBaseOptions)) {
|
|
@@ -41,7 +41,7 @@ function extractTsConfigBase(host) {
|
|
|
41
41
|
delete tsconfig.compilerOptions[compilerOption];
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
(0,
|
|
44
|
+
(0, devkit_1.writeJson)(host, 'tsconfig.base.json', {
|
|
45
45
|
compileOnSave: false,
|
|
46
46
|
compilerOptions: baseCompilerOptions,
|
|
47
47
|
exclude: tsconfig.exclude,
|
|
@@ -49,10 +49,10 @@ function extractTsConfigBase(host) {
|
|
|
49
49
|
tsconfig.extends = './tsconfig.base.json';
|
|
50
50
|
delete tsconfig.compileOnSave;
|
|
51
51
|
delete tsconfig.exclude;
|
|
52
|
-
(0,
|
|
52
|
+
(0, devkit_1.writeJson)(host, 'tsconfig.json', tsconfig);
|
|
53
53
|
// special case for updating e2e tests.
|
|
54
54
|
if (host.exists('e2e/tsconfig.json')) {
|
|
55
|
-
(0,
|
|
55
|
+
(0, devkit_1.updateJson)(host, 'e2e/tsconfig.json', (json) => {
|
|
56
56
|
json.extends = '../tsconfig.base.json';
|
|
57
57
|
return json;
|
|
58
58
|
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ensureProjectIsIncludedInPluginRegistrations = ensureProjectIsIncludedInPluginRegistrations;
|
|
4
|
-
const devkit_internals_1 = require("nx/src/devkit-internals");
|
|
5
4
|
const picomatch = require("picomatch");
|
|
5
|
+
const internal_1 = require("@nx/devkit/internal");
|
|
6
6
|
function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, buildTargetName) {
|
|
7
7
|
nxJson.plugins ??= [];
|
|
8
8
|
let isIncluded = false;
|
|
@@ -32,7 +32,7 @@ function ensureProjectIsIncludedInPluginRegistrations(nxJson, projectRoot, build
|
|
|
32
32
|
// before the registration's include/exclude filters are applied.
|
|
33
33
|
const tsconfigPath = `${projectRoot}/tsconfig.json`;
|
|
34
34
|
const matchingConfigFiles = picomatch('**/tsconfig.json', { dot: true })(tsconfigPath)
|
|
35
|
-
? (0,
|
|
35
|
+
? (0, internal_1.findMatchingConfigFiles)([tsconfigPath], registration.include, registration.exclude)
|
|
36
36
|
: [];
|
|
37
37
|
if (matchingConfigFiles.length) {
|
|
38
38
|
// it's included by the plugin registration, check if the user-specified options would result
|