@nx/js 22.6.0-rc.1 → 22.6.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/generators.json +0 -6
- package/package.json +4 -4
- package/src/plugins/typescript/plugin.js +2 -2
- package/src/generators/deps-sync/deps-sync.d.ts +0 -5
- package/src/generators/deps-sync/deps-sync.d.ts.map +0 -1
- package/src/generators/deps-sync/deps-sync.js +0 -124
- package/src/generators/deps-sync/schema.json +0 -8
package/generators.json
CHANGED
|
@@ -43,12 +43,6 @@
|
|
|
43
43
|
"alias": ["sync"],
|
|
44
44
|
"hidden": true
|
|
45
45
|
},
|
|
46
|
-
"deps-sync": {
|
|
47
|
-
"factory": "./src/generators/deps-sync/deps-sync",
|
|
48
|
-
"schema": "./src/generators/deps-sync/schema.json",
|
|
49
|
-
"description": "Synchronize package.json dependencies for internal packages based on the project graph.",
|
|
50
|
-
"hidden": true
|
|
51
|
-
},
|
|
52
46
|
"setup-prettier": {
|
|
53
47
|
"factory": "./src/generators/setup-prettier/generator",
|
|
54
48
|
"schema": "./src/generators/setup-prettier/schema.json",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nx/js",
|
|
3
|
-
"version": "22.6.0
|
|
3
|
+
"version": "22.6.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,8 +39,8 @@
|
|
|
39
39
|
"@babel/preset-env": "^7.23.2",
|
|
40
40
|
"@babel/preset-typescript": "^7.22.5",
|
|
41
41
|
"@babel/runtime": "^7.22.6",
|
|
42
|
-
"@nx/devkit": "22.6.0
|
|
43
|
-
"@nx/workspace": "22.6.0
|
|
42
|
+
"@nx/devkit": "22.6.0",
|
|
43
|
+
"@nx/workspace": "22.6.0",
|
|
44
44
|
"@zkochan/js-yaml": "0.0.7",
|
|
45
45
|
"babel-plugin-const-enum": "^1.0.1",
|
|
46
46
|
"babel-plugin-macros": "^3.1.0",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"tslib": "^2.3.0"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"nx": "22.6.0
|
|
63
|
+
"nx": "22.6.0"
|
|
64
64
|
},
|
|
65
65
|
"peerDependencies": {
|
|
66
66
|
"verdaccio": "^6.0.5"
|
|
@@ -286,7 +286,7 @@ function buildTscTargets(config, options, context, configFiles, cache) {
|
|
|
286
286
|
inputs: getInputs(namedInputs, config, tsConfig, internalProjectReferences, context.workspaceRoot, cache),
|
|
287
287
|
outputs: getOutputs(config, tsConfig, internalProjectReferences, context.workspaceRoot,
|
|
288
288
|
/* emitDeclarationOnly */ true),
|
|
289
|
-
syncGenerators: ['@nx/js:typescript-sync'
|
|
289
|
+
syncGenerators: ['@nx/js:typescript-sync'],
|
|
290
290
|
metadata: {
|
|
291
291
|
technologies: ['typescript'],
|
|
292
292
|
description: 'Runs type-checking for the project.',
|
|
@@ -317,7 +317,7 @@ function buildTscTargets(config, options, context, configFiles, cache) {
|
|
|
317
317
|
outputs: getOutputs(config, tsConfig, internalProjectReferences, context.workspaceRoot,
|
|
318
318
|
// should be false for build target, but providing it just in case is set to true
|
|
319
319
|
tsConfig.options.emitDeclarationOnly),
|
|
320
|
-
syncGenerators: ['@nx/js:typescript-sync'
|
|
320
|
+
syncGenerators: ['@nx/js:typescript-sync'],
|
|
321
321
|
metadata: {
|
|
322
322
|
technologies: ['typescript'],
|
|
323
323
|
description: 'Builds the project with `tsc`.',
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"deps-sync.d.ts","sourceRoot":"","sources":["../../../../../../packages/js/src/generators/deps-sync/deps-sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AAaxE,wBAAsB,aAAa,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAoJ5E;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.syncGenerator = syncGenerator;
|
|
4
|
-
const devkit_1 = require("@nx/devkit");
|
|
5
|
-
const jsonc_parser_1 = require("jsonc-parser");
|
|
6
|
-
async function syncGenerator(tree) {
|
|
7
|
-
const projectGraph = await (0, devkit_1.createProjectGraphAsync)();
|
|
8
|
-
const pm = (0, devkit_1.detectPackageManager)(tree.root);
|
|
9
|
-
const versionString = pm === 'npm' ? '*' : 'workspace:*';
|
|
10
|
-
// Build a set of all internal package names
|
|
11
|
-
const internalPackageNames = new Set();
|
|
12
|
-
const projectToPackageName = new Map();
|
|
13
|
-
for (const node of Object.values(projectGraph.nodes)) {
|
|
14
|
-
const packageName = node.data.metadata?.js?.packageName;
|
|
15
|
-
if (packageName) {
|
|
16
|
-
internalPackageNames.add(packageName);
|
|
17
|
-
projectToPackageName.set(node.name, packageName);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
const changedFiles = new Map();
|
|
21
|
-
for (const projectName of Object.keys(projectGraph.nodes)) {
|
|
22
|
-
const sourceNode = projectGraph.nodes[projectName];
|
|
23
|
-
if (sourceNode.data.root === '.') {
|
|
24
|
-
continue;
|
|
25
|
-
}
|
|
26
|
-
// The consumer must itself have a package name (i.e. a package.json with name)
|
|
27
|
-
const sourcePackageName = projectToPackageName.get(projectName);
|
|
28
|
-
if (!sourcePackageName) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
const packageJsonPath = (0, devkit_1.joinPathFragments)(sourceNode.data.root, 'package.json');
|
|
32
|
-
if (!tree.exists(packageJsonPath)) {
|
|
33
|
-
continue;
|
|
34
|
-
}
|
|
35
|
-
// Collect the expected set of internal dependency package names
|
|
36
|
-
const expectedInternalDeps = new Set();
|
|
37
|
-
for (const dep of projectGraph.dependencies[projectName] || []) {
|
|
38
|
-
const targetNode = projectGraph.nodes[dep.target];
|
|
39
|
-
if (!targetNode || dep.type === 'implicit') {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const depPackageName = projectToPackageName.get(dep.target);
|
|
43
|
-
if (depPackageName) {
|
|
44
|
-
expectedInternalDeps.add(depPackageName);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
// Read current package.json
|
|
48
|
-
const rawContents = tree.read(packageJsonPath, 'utf-8');
|
|
49
|
-
const packageJson = (0, devkit_1.parseJson)(rawContents);
|
|
50
|
-
const currentDevDeps = packageJson.devDependencies ?? {};
|
|
51
|
-
let hasChanges = false;
|
|
52
|
-
let updatedContents = rawContents;
|
|
53
|
-
// Add missing internal devDependencies
|
|
54
|
-
for (const depName of expectedInternalDeps) {
|
|
55
|
-
if (currentDevDeps[depName] === versionString ||
|
|
56
|
-
packageJson.dependencies?.[depName]) {
|
|
57
|
-
continue;
|
|
58
|
-
}
|
|
59
|
-
if (currentDevDeps[depName] !== undefined) {
|
|
60
|
-
// Present but wrong version string — update it
|
|
61
|
-
if (process.env.NX_VERBOSE_LOGGING === 'true') {
|
|
62
|
-
devkit_1.logger.info(`Updating devDependency "${depName}" version to "${versionString}" in ${packageJsonPath}.`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const edits = (0, jsonc_parser_1.modify)(updatedContents, ['devDependencies', depName], versionString, {
|
|
66
|
-
formattingOptions: {
|
|
67
|
-
keepLines: true,
|
|
68
|
-
insertSpaces: true,
|
|
69
|
-
tabSize: 2,
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
updatedContents = (0, jsonc_parser_1.applyEdits)(updatedContents, edits);
|
|
73
|
-
hasChanges = true;
|
|
74
|
-
addChange(changedFiles, packageJsonPath, depName, 'added');
|
|
75
|
-
}
|
|
76
|
-
// Remove stale internal devDependencies (internal packages no longer
|
|
77
|
-
// depended on according to the project graph)
|
|
78
|
-
for (const depName of Object.keys(currentDevDeps)) {
|
|
79
|
-
if (internalPackageNames.has(depName) &&
|
|
80
|
-
!expectedInternalDeps.has(depName)) {
|
|
81
|
-
const edits = (0, jsonc_parser_1.modify)(updatedContents, ['devDependencies', depName], undefined, {
|
|
82
|
-
formattingOptions: {
|
|
83
|
-
keepLines: true,
|
|
84
|
-
insertSpaces: true,
|
|
85
|
-
tabSize: 2,
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
updatedContents = (0, jsonc_parser_1.applyEdits)(updatedContents, edits);
|
|
89
|
-
hasChanges = true;
|
|
90
|
-
addChange(changedFiles, packageJsonPath, depName, 'removed');
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
if (hasChanges) {
|
|
94
|
-
tree.write(packageJsonPath, updatedContents);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
if (changedFiles.size > 0) {
|
|
98
|
-
await (0, devkit_1.formatFiles)(tree);
|
|
99
|
-
const outOfSyncDetails = [];
|
|
100
|
-
for (const [filePath, details] of changedFiles) {
|
|
101
|
-
outOfSyncDetails.push(`${filePath}:`);
|
|
102
|
-
if (details.added.size > 0) {
|
|
103
|
-
outOfSyncDetails.push(` - Missing devDependencies: ${Array.from(details.added).join(', ')}`);
|
|
104
|
-
}
|
|
105
|
-
if (details.removed.size > 0) {
|
|
106
|
-
outOfSyncDetails.push(` - Stale devDependencies: ${Array.from(details.removed).join(', ')}`);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return {
|
|
110
|
-
outOfSyncMessage: 'Some package.json files are missing devDependencies to internal packages they depend on or contain stale devDependencies to internal packages they no longer depend on.',
|
|
111
|
-
outOfSyncDetails,
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
exports.default = syncGenerator;
|
|
116
|
-
function addChange(changedFiles, filePath, depName, type) {
|
|
117
|
-
if (!changedFiles.has(filePath)) {
|
|
118
|
-
changedFiles.set(filePath, {
|
|
119
|
-
added: new Set(),
|
|
120
|
-
removed: new Set(),
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
changedFiles.get(filePath)[type].add(depName);
|
|
124
|
-
}
|