@smoothbricks/cli 0.2.0 → 0.3.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/README.md +27 -23
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +19 -3
- package/dist/generate/index.d.ts +20 -0
- package/dist/generate/index.d.ts.map +1 -0
- package/dist/generate/index.js +47 -0
- package/dist/lib/run.d.ts +1 -0
- package/dist/lib/run.d.ts.map +1 -1
- package/dist/lib/run.js +19 -0
- package/dist/lib/workspace.d.ts +10 -0
- package/dist/lib/workspace.d.ts.map +1 -1
- package/dist/lib/workspace.js +55 -16
- package/dist/monorepo/lockfile.d.ts.map +1 -1
- package/dist/monorepo/lockfile.js +9 -0
- package/dist/monorepo/package-policy.d.ts +6 -17
- package/dist/monorepo/package-policy.d.ts.map +1 -1
- package/dist/monorepo/package-policy.js +63 -1127
- package/dist/monorepo/publish-workflow.js +2 -3
- package/dist/nx/index.d.ts +1 -0
- package/dist/nx/index.d.ts.map +1 -1
- package/dist/nx/index.js +23 -5
- package/dist/release/candidates.js +1 -1
- package/dist/release/core.d.ts +3 -1
- package/dist/release/core.d.ts.map +1 -1
- package/dist/release/core.js +76 -9
- package/dist/release/github-release.d.ts +1 -0
- package/dist/release/github-release.d.ts.map +1 -1
- package/dist/release/github-release.js +1 -1
- package/dist/release/index.d.ts +9 -3
- package/dist/release/index.d.ts.map +1 -1
- package/dist/release/index.js +265 -39
- package/dist/release/orchestration.d.ts +10 -2
- package/dist/release/orchestration.d.ts.map +1 -1
- package/dist/release/orchestration.js +33 -3
- package/managed/templates/github/workflows/ci.yml +3 -2
- package/package.json +7 -12
- package/src/cli.ts +21 -4
- package/src/generate/index.ts +92 -0
- package/src/lib/run.ts +25 -0
- package/src/lib/workspace.ts +72 -16
- package/src/monorepo/lockfile.ts +9 -0
- package/src/monorepo/package-policy.test.ts +250 -22
- package/src/monorepo/package-policy.ts +88 -1351
- package/src/monorepo/publish-workflow.ts +2 -3
- package/src/nx/index.test.ts +9 -0
- package/src/nx/index.ts +25 -5
- package/src/release/__tests__/candidates.test.ts +53 -8
- package/src/release/__tests__/core-properties.test.ts +2 -2
- package/src/release/__tests__/core-scenarios.test.ts +12 -15
- package/src/release/__tests__/core.test.ts +50 -3
- package/src/release/__tests__/fixture-repo.test.ts +68 -18
- package/src/release/__tests__/github-release.test.ts +9 -16
- package/src/release/__tests__/orchestration.test.ts +91 -5
- package/src/release/__tests__/retag-unpublished.test.ts +9 -9
- package/src/release/__tests__/trust-publisher.test.ts +65 -33
- package/src/release/candidates.ts +1 -1
- package/src/release/core.ts +95 -10
- package/src/release/github-release.ts +1 -1
- package/src/release/index.ts +343 -49
- package/src/release/orchestration.ts +50 -5
- package/dist/nx-version-actions.cjs +0 -25
- package/dist/nx-version-actions.d.cts +0 -6
- package/dist/nx-version-actions.d.cts.map +0 -1
- package/src/nx-version-actions.cts +0 -36
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { join } from 'node:path';
|
|
2
|
+
import { applyWorkspaceBoundedTestTargetPolicy, checkWorkspaceBoundedTestTargetPolicy, } from '@smoothbricks/nx-plugin/bounded-test-policy';
|
|
3
|
+
import { applyPackageTargetPolicy, checkPackageTargetPolicy, } from '@smoothbricks/nx-plugin/package-target-policy';
|
|
4
|
+
import { applyReleaseConfigPolicy, checkReleaseConfigPolicy, SMOO_NX_RELEASE_TAG_PATTERN, SMOO_NX_VERSION_ACTIONS, } from '@smoothbricks/nx-plugin/release-config-policy';
|
|
5
|
+
import { applyTypecheckTestPolicy, checkTypecheckTestPolicy } from '@smoothbricks/nx-plugin/typecheck-test-policy';
|
|
6
|
+
import { applyWorkspaceConfigPolicy, checkWorkspaceConfigPolicy, } from '@smoothbricks/nx-plugin/workspace-config-policy';
|
|
7
|
+
import { getOrCreateRecord, hasOwnString, isRecord, readJsonObject, recordProperty, requiredJsonObject, setMissingStringProperty, setStringProperty, stringProperty, writeJsonObject, } from '../lib/json.js';
|
|
8
|
+
import { getWorkspacePackageManifests, getWorkspacePackages, listPackageJsonRecords, listPublicPackages, packageRepositoryInfo, repositoryInfo, sameRepositoryAfterNormalization, workspaceDependencyFields, } from '../lib/workspace.js';
|
|
9
|
+
export { SMOO_NX_RELEASE_TAG_PATTERN, SMOO_NX_VERSION_ACTIONS };
|
|
7
10
|
const extraCommitScopes = ['release'];
|
|
8
11
|
const rootScriptPolicy = {
|
|
9
12
|
lint: 'nx run-many -t lint',
|
|
@@ -11,17 +14,6 @@ const rootScriptPolicy = {
|
|
|
11
14
|
'format:staged': 'git-format-staged --config tooling/git-hooks/git-format-staged.yml',
|
|
12
15
|
'format:changed': 'git-format-staged --config tooling/git-hooks/git-format-staged.yml --also-unstaged',
|
|
13
16
|
};
|
|
14
|
-
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
15
|
-
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|
|
16
|
-
const expectedSharedGlobalsNamedInput = ['{workspaceRoot}/.github/workflows/ci.yml'];
|
|
17
|
-
const defaultProductionNamedInput = [
|
|
18
|
-
'{projectRoot}/src/**/*',
|
|
19
|
-
'{projectRoot}/package.json',
|
|
20
|
-
'!{projectRoot}/**/__tests__/**',
|
|
21
|
-
'!{projectRoot}/**/*.test.*',
|
|
22
|
-
'!{projectRoot}/**/*.spec.*',
|
|
23
|
-
];
|
|
24
|
-
const impreciseProductionInputs = new Set(['default', '{projectRoot}/**/*', '{projectRoot}/**']);
|
|
25
17
|
export function applyFixableMonorepoDefaults(root) {
|
|
26
18
|
applyRootScriptDefaults(root);
|
|
27
19
|
applyNxPluginDefaults(root);
|
|
@@ -53,22 +45,7 @@ export function applyRootScriptDefaults(root) {
|
|
|
53
45
|
}
|
|
54
46
|
}
|
|
55
47
|
export function applyNxPluginDefaults(root) {
|
|
56
|
-
|
|
57
|
-
const nxJson = readJsonObject(nxJsonPath);
|
|
58
|
-
if (!nxJson) {
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
let changed = removeColonTargetDefaults(nxJson);
|
|
62
|
-
changed = applyBuildTargetDefault(nxJson) || changed;
|
|
63
|
-
changed = applyNamedInputDefaults(nxJson) || changed;
|
|
64
|
-
const currentPlugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
65
|
-
const nextPlugins = upsertNxPlugin(upsertNxPlugin(currentPlugins, expectedNxJsTypescriptPlugin()), smoothBricksNxPlugin);
|
|
66
|
-
if (JSON.stringify(currentPlugins) !== JSON.stringify(nextPlugins)) {
|
|
67
|
-
nxJson.plugins = nextPlugins;
|
|
68
|
-
changed = true;
|
|
69
|
-
}
|
|
70
|
-
if (changed) {
|
|
71
|
-
writeJsonObject(nxJsonPath, nxJson);
|
|
48
|
+
if (applyWorkspaceConfigPolicy(root)) {
|
|
72
49
|
console.log('updated nx.json smoo plugin config');
|
|
73
50
|
}
|
|
74
51
|
else {
|
|
@@ -114,58 +91,33 @@ export function applyPublicPackageDefaults(root) {
|
|
|
114
91
|
export function applyWorkspaceDependencyDefaults(root, options = {}) {
|
|
115
92
|
const workspaceNames = new Set(getWorkspacePackages(root).map((pkg) => pkg.name));
|
|
116
93
|
for (const pkg of listPackageJsonRecords(root)) {
|
|
117
|
-
|
|
118
|
-
const projectName = packageNxProjectName(pkg.json);
|
|
119
|
-
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
120
|
-
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
121
|
-
changed = migratePackageColonTargets(pkg.json, resolvedTargets) || changed;
|
|
122
|
-
changed = rewriteColonTargetDependenciesInPackage(pkg.json, resolvedTargets) || changed;
|
|
123
|
-
changed = removePackageColonTargets(pkg.json) || changed;
|
|
124
|
-
changed = removeRedundantNoopBuildTarget(pkg.json, resolvedProject) || changed;
|
|
125
|
-
changed = applyPackageScriptPolicy(pkg.json, pkg.path, workspaceNames, { resolvedTargets }) || changed;
|
|
94
|
+
const changed = fixWorkspaceDependencyRanges(pkg.json, workspaceNames);
|
|
126
95
|
if (changed) {
|
|
127
96
|
writeJsonObject(pkg.packageJsonPath, pkg.json);
|
|
128
|
-
console.log(`updated ${pkg.path}/package.json workspace dependency
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
console.log(`unchanged ${pkg.path}/package.json workspace dependency policy`);
|
|
97
|
+
console.log(`updated ${pkg.path}/package.json workspace dependency ranges`);
|
|
132
98
|
}
|
|
133
|
-
applyBunTestTsconfigDefaults(root, pkg.path, pkg.json, workspaceNames);
|
|
134
|
-
applyTsconfigTestReferenceDefaults(root, pkg.path);
|
|
135
99
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const nxJsonPath = join(root, 'nx.json');
|
|
139
|
-
const nxJson = requiredJsonObject(nxJsonPath);
|
|
140
|
-
let changed = false;
|
|
141
|
-
const release = getOrCreateRecord(nxJson, 'release');
|
|
142
|
-
changed = setStringProperty(release, 'projectsRelationship', 'independent') || changed;
|
|
143
|
-
const version = getOrCreateRecord(release, 'version');
|
|
144
|
-
changed = setStringProperty(version, 'specifierSource', 'conventional-commits') || changed;
|
|
145
|
-
changed = setStringProperty(version, 'currentVersionResolver', 'git-tag') || changed;
|
|
146
|
-
changed = setStringProperty(version, 'fallbackCurrentVersionResolver', 'disk') || changed;
|
|
147
|
-
changed = setStringProperty(version, 'versionActions', SMOO_NX_VERSION_ACTIONS) || changed;
|
|
148
|
-
if (delete version.preVersionCommand) {
|
|
149
|
-
changed = true;
|
|
100
|
+
if (applyPackageTargetPolicy(root, options)) {
|
|
101
|
+
console.log('updated package Nx target policy');
|
|
150
102
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
const changelog = getOrCreateRecord(release, 'changelog');
|
|
154
|
-
changed = setBooleanProperty(changelog, 'workspaceChangelog', false) || changed;
|
|
155
|
-
const projectChangelogs = getOrCreateRecord(changelog, 'projectChangelogs');
|
|
156
|
-
changed = setBooleanProperty(projectChangelogs, 'createRelease', false) || changed;
|
|
157
|
-
changed = setBooleanProperty(projectChangelogs, 'file', false) || changed;
|
|
158
|
-
const renderOptions = getOrCreateRecord(projectChangelogs, 'renderOptions');
|
|
159
|
-
if (typeof renderOptions.authors !== 'boolean') {
|
|
160
|
-
renderOptions.authors = true;
|
|
161
|
-
changed = true;
|
|
103
|
+
else {
|
|
104
|
+
console.log('unchanged package Nx target policy');
|
|
162
105
|
}
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
changed = true;
|
|
106
|
+
if (applyTypecheckTestPolicy(root)) {
|
|
107
|
+
console.log('updated tsconfig.test.json policy');
|
|
166
108
|
}
|
|
167
|
-
|
|
168
|
-
|
|
109
|
+
else {
|
|
110
|
+
console.log('unchanged tsconfig.test.json policy');
|
|
111
|
+
}
|
|
112
|
+
if (applyWorkspaceBoundedTestTargetPolicy(root)) {
|
|
113
|
+
console.log('updated package test targets bounded execution policy');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
console.log('unchanged package test targets bounded execution policy');
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export function applyNxReleaseDefaults(root) {
|
|
120
|
+
if (applyReleaseConfigPolicy(root)) {
|
|
169
121
|
console.log('updated nx.json release config');
|
|
170
122
|
}
|
|
171
123
|
else {
|
|
@@ -178,12 +130,13 @@ export function applyNxProjectNameDefaults(root) {
|
|
|
178
130
|
if (!rootName) {
|
|
179
131
|
return;
|
|
180
132
|
}
|
|
181
|
-
for (const pkg of
|
|
133
|
+
for (const pkg of getWorkspacePackageManifests(root)) {
|
|
182
134
|
const suggestedName = suggestNxProjectName(rootName, pkg.name);
|
|
183
135
|
if (!suggestedName) {
|
|
184
136
|
continue;
|
|
185
137
|
}
|
|
186
|
-
const
|
|
138
|
+
const nx = getOrCreateRecord(pkg.json, 'nx');
|
|
139
|
+
const changed = setStringProperty(nx, 'name', suggestedName);
|
|
187
140
|
if (changed) {
|
|
188
141
|
writeJsonObject(pkg.packageJsonPath, pkg.json);
|
|
189
142
|
console.log(`updated ${pkg.path}/package.json nx.name`);
|
|
@@ -200,7 +153,7 @@ export function listNxProjectNames(root) {
|
|
|
200
153
|
const rootPackage = readJsonObject(join(root, 'package.json'));
|
|
201
154
|
const rootName = rootPackage ? stringProperty(rootPackage, 'name') : null;
|
|
202
155
|
const names = [];
|
|
203
|
-
for (const pkg of
|
|
156
|
+
for (const pkg of getWorkspacePackageManifests(root)) {
|
|
204
157
|
const nx = recordProperty(pkg.json, 'nx');
|
|
205
158
|
const configuredName = nx ? stringProperty(nx, 'name') : null;
|
|
206
159
|
const suggestedName = rootName ? suggestNxProjectName(rootName, pkg.name) : null;
|
|
@@ -253,83 +206,13 @@ export function validateRootPackagePolicy(root) {
|
|
|
253
206
|
return failures;
|
|
254
207
|
}
|
|
255
208
|
export function validateNxReleaseConfig(root) {
|
|
256
|
-
const nxJson = readJsonObject(join(root, 'nx.json'));
|
|
257
|
-
if (!nxJson) {
|
|
258
|
-
console.error('nx.json not found or invalid');
|
|
259
|
-
return 1;
|
|
260
|
-
}
|
|
261
|
-
const release = recordProperty(nxJson, 'release');
|
|
262
|
-
const version = release ? recordProperty(release, 'version') : null;
|
|
263
|
-
const releaseTag = release ? recordProperty(release, 'releaseTag') : null;
|
|
264
|
-
const changelog = release ? recordProperty(release, 'changelog') : null;
|
|
265
|
-
const projectChangelogs = changelog ? recordProperty(changelog, 'projectChangelogs') : null;
|
|
266
|
-
const renderOptions = projectChangelogs ? recordProperty(projectChangelogs, 'renderOptions') : null;
|
|
267
209
|
let failures = 0;
|
|
268
|
-
|
|
269
|
-
console.error(
|
|
210
|
+
for (const issue of checkWorkspaceConfigPolicy(root)) {
|
|
211
|
+
console.error(issue.message);
|
|
270
212
|
failures++;
|
|
271
213
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
console.error('nx.json release.projectsRelationship must be independent');
|
|
275
|
-
failures++;
|
|
276
|
-
}
|
|
277
|
-
if (!version) {
|
|
278
|
-
console.error('nx.json release.version config is missing');
|
|
279
|
-
failures++;
|
|
280
|
-
}
|
|
281
|
-
if (version && stringProperty(version, 'specifierSource') !== 'conventional-commits') {
|
|
282
|
-
console.error('nx.json release.version.specifierSource must be conventional-commits');
|
|
283
|
-
failures++;
|
|
284
|
-
}
|
|
285
|
-
// Nx requires git-tag as the primary resolver when deriving versions from
|
|
286
|
-
// conventional commits. Disk is only a fallback for initial untagged packages.
|
|
287
|
-
if (version && stringProperty(version, 'currentVersionResolver') !== 'git-tag') {
|
|
288
|
-
console.error('nx.json release.version.currentVersionResolver must be git-tag');
|
|
289
|
-
failures++;
|
|
290
|
-
}
|
|
291
|
-
if (version && stringProperty(version, 'fallbackCurrentVersionResolver') !== 'disk') {
|
|
292
|
-
console.error('nx.json release.version.fallbackCurrentVersionResolver must be disk');
|
|
293
|
-
failures++;
|
|
294
|
-
}
|
|
295
|
-
if (version && stringProperty(version, 'versionActions') !== SMOO_NX_VERSION_ACTIONS) {
|
|
296
|
-
console.error(`nx.json release.version.versionActions must be ${SMOO_NX_VERSION_ACTIONS}`);
|
|
297
|
-
failures++;
|
|
298
|
-
}
|
|
299
|
-
if (version && stringProperty(version, 'preVersionCommand')) {
|
|
300
|
-
console.error('nx.json release.version.preVersionCommand must not be defined; smoo builds npm-missing packages before publish');
|
|
301
|
-
failures++;
|
|
302
|
-
}
|
|
303
|
-
if (!releaseTag) {
|
|
304
|
-
console.error('nx.json release.releaseTag config is missing');
|
|
305
|
-
failures++;
|
|
306
|
-
}
|
|
307
|
-
if (releaseTag && stringProperty(releaseTag, 'pattern') !== SMOO_NX_RELEASE_TAG_PATTERN) {
|
|
308
|
-
console.error(`nx.json release.releaseTag.pattern must be ${SMOO_NX_RELEASE_TAG_PATTERN}`);
|
|
309
|
-
failures++;
|
|
310
|
-
}
|
|
311
|
-
if (!changelog) {
|
|
312
|
-
console.error('nx.json release.changelog config is missing');
|
|
313
|
-
failures++;
|
|
314
|
-
}
|
|
315
|
-
if (changelog && changelog.workspaceChangelog !== false) {
|
|
316
|
-
console.error('nx.json release.changelog.workspaceChangelog must be false');
|
|
317
|
-
failures++;
|
|
318
|
-
}
|
|
319
|
-
if (!projectChangelogs) {
|
|
320
|
-
console.error('nx.json release.changelog.projectChangelogs config is missing');
|
|
321
|
-
failures++;
|
|
322
|
-
}
|
|
323
|
-
if (projectChangelogs && projectChangelogs.createRelease !== false) {
|
|
324
|
-
console.error('nx.json release.changelog.projectChangelogs.createRelease must be false');
|
|
325
|
-
failures++;
|
|
326
|
-
}
|
|
327
|
-
if (projectChangelogs && projectChangelogs.file !== false) {
|
|
328
|
-
console.error('nx.json release.changelog.projectChangelogs.file must be false');
|
|
329
|
-
failures++;
|
|
330
|
-
}
|
|
331
|
-
if (!renderOptions) {
|
|
332
|
-
console.error('nx.json release.changelog.projectChangelogs.renderOptions config is missing');
|
|
214
|
+
for (const issue of checkReleaseConfigPolicy(root)) {
|
|
215
|
+
console.error(issue.message);
|
|
333
216
|
failures++;
|
|
334
217
|
}
|
|
335
218
|
return failures;
|
|
@@ -341,7 +224,7 @@ export function validateNxProjectNames(root) {
|
|
|
341
224
|
return 0;
|
|
342
225
|
}
|
|
343
226
|
let failures = 0;
|
|
344
|
-
for (const pkg of
|
|
227
|
+
for (const pkg of getWorkspacePackageManifests(root)) {
|
|
345
228
|
const suggestedName = suggestNxProjectName(rootName, pkg.name);
|
|
346
229
|
if (!suggestedName) {
|
|
347
230
|
continue;
|
|
@@ -429,16 +312,9 @@ export function validatePublicPackageMetadata(root) {
|
|
|
429
312
|
return failures;
|
|
430
313
|
}
|
|
431
314
|
export function validateWorkspaceDependencies(root, options = {}) {
|
|
432
|
-
const workspaceNames = new Set(getWorkspacePackages(root).map((pkg) => pkg.name));
|
|
433
315
|
let failures = 0;
|
|
316
|
+
const workspaceNames = new Set(getWorkspacePackages(root).map((pkg) => pkg.name));
|
|
434
317
|
for (const pkg of listPackageJsonRecords(root)) {
|
|
435
|
-
const projectName = packageNxProjectName(pkg.json);
|
|
436
|
-
const resolvedTargets = resolvedProjectTargetNames(projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined);
|
|
437
|
-
failures += validateExplicitNxTargets(pkg.json, pkg.path, resolvedTargets);
|
|
438
|
-
failures += validateBunTestTsconfigPresence(root, pkg.path, pkg.json);
|
|
439
|
-
failures += validateTsconfigTestPolicy(root, pkg.path);
|
|
440
|
-
failures += validateTsconfigTestReferencePolicy(root, pkg.path);
|
|
441
|
-
failures += validateBuildZigPolicy(root, pkg.path);
|
|
442
318
|
for (const field of workspaceDependencyFields) {
|
|
443
319
|
const dependencies = recordProperty(pkg.json, field);
|
|
444
320
|
if (!dependencies) {
|
|
@@ -451,151 +327,27 @@ export function validateWorkspaceDependencies(root, options = {}) {
|
|
|
451
327
|
}
|
|
452
328
|
}
|
|
453
329
|
}
|
|
454
|
-
failures += validatePackageScriptPolicy(pkg.json, pkg.path, workspaceNames, { resolvedTargets });
|
|
455
330
|
}
|
|
456
|
-
|
|
457
|
-
console.
|
|
458
|
-
|
|
459
|
-
return failures;
|
|
460
|
-
}
|
|
461
|
-
export function applyPackageScriptPolicy(pkg, _packagePath, workspaceNames, options = {}) {
|
|
462
|
-
if (!hasWorkspaceDependency(pkg, workspaceNames)) {
|
|
463
|
-
return false;
|
|
464
|
-
}
|
|
465
|
-
const scripts = recordProperty(pkg, 'scripts');
|
|
466
|
-
if (!scripts) {
|
|
467
|
-
return false;
|
|
468
|
-
}
|
|
469
|
-
const projectName = packageNxProjectName(pkg);
|
|
470
|
-
if (!projectName) {
|
|
471
|
-
return false;
|
|
472
|
-
}
|
|
473
|
-
const nxConfig = applyPackageNxConfig(pkg, { projectName, targets: true });
|
|
474
|
-
const targets = nxConfig.targets;
|
|
475
|
-
let changed = nxConfig.changed;
|
|
476
|
-
for (const [scriptName, rawCommand] of Object.entries(scripts)) {
|
|
477
|
-
if (typeof rawCommand !== 'string') {
|
|
478
|
-
continue;
|
|
479
|
-
}
|
|
480
|
-
const rewrite = classifyScriptRewrite(scriptName, rawCommand);
|
|
481
|
-
if (!rewrite) {
|
|
482
|
-
continue;
|
|
483
|
-
}
|
|
484
|
-
const targetName = rewrite.targetName;
|
|
485
|
-
const alias = nxRunAlias(projectName, targetName, rewrite.continuous);
|
|
486
|
-
const existingTarget = recordProperty(targets, targetName);
|
|
487
|
-
if (!existingTarget &&
|
|
488
|
-
targetName !== scriptName &&
|
|
489
|
-
targetExistsInResolvedProject(targetName, options.resolvedTargets)) {
|
|
490
|
-
if (scripts[scriptName] !== alias) {
|
|
491
|
-
scripts[scriptName] = alias;
|
|
492
|
-
changed = true;
|
|
493
|
-
}
|
|
494
|
-
continue;
|
|
495
|
-
}
|
|
496
|
-
const existingOptions = existingTarget ? recordProperty(existingTarget, 'options') : null;
|
|
497
|
-
const existingCommand = existingOptions ? stringProperty(existingOptions, 'command') : null;
|
|
498
|
-
const command = isScriptRunnerCommand(existingCommand, scriptName)
|
|
499
|
-
? rewrite.command
|
|
500
|
-
: (existingCommand ?? rewrite.command);
|
|
501
|
-
const target = existingTarget ?? {};
|
|
502
|
-
changed = setStringProperty(target, 'executor', 'nx:run-commands') || changed;
|
|
503
|
-
changed = setStringArrayProperty(target, 'dependsOn', expectedTargetDependencies(targetName)) || changed;
|
|
504
|
-
if (rewrite.continuous && target.continuous !== true) {
|
|
505
|
-
target.continuous = true;
|
|
506
|
-
changed = true;
|
|
507
|
-
}
|
|
508
|
-
const targetOptions = getOrCreateRecord(target, 'options');
|
|
509
|
-
changed = setStringProperty(targetOptions, 'command', command) || changed;
|
|
510
|
-
changed = setStringProperty(targetOptions, 'cwd', '{projectRoot}') || changed;
|
|
511
|
-
for (const [name, value] of Object.entries(rewrite.env)) {
|
|
512
|
-
const env = getOrCreateRecord(targetOptions, 'env');
|
|
513
|
-
changed = setStringProperty(env, name, value) || changed;
|
|
514
|
-
}
|
|
515
|
-
if (targets[targetName] !== target) {
|
|
516
|
-
targets[targetName] = target;
|
|
517
|
-
changed = true;
|
|
518
|
-
}
|
|
519
|
-
if (scripts[scriptName] !== alias) {
|
|
520
|
-
scripts[scriptName] = alias;
|
|
521
|
-
changed = true;
|
|
522
|
-
}
|
|
331
|
+
for (const issue of checkPackageTargetPolicy(root, options)) {
|
|
332
|
+
console.error(`${issue.path}: ${issue.message}`);
|
|
333
|
+
failures++;
|
|
523
334
|
}
|
|
524
|
-
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
if (!hasWorkspaceDependency(pkg, workspaceNames)) {
|
|
528
|
-
return 0;
|
|
335
|
+
for (const issue of checkTypecheckTestPolicy(root)) {
|
|
336
|
+
console.error(`${issue.path}: ${issue.message}`);
|
|
337
|
+
failures++;
|
|
529
338
|
}
|
|
530
|
-
const
|
|
531
|
-
|
|
532
|
-
|
|
339
|
+
for (const issue of checkWorkspaceBoundedTestTargetPolicy(root)) {
|
|
340
|
+
console.error(`${issue.path}: ${issue.message}`);
|
|
341
|
+
failures++;
|
|
533
342
|
}
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
537
|
-
let failures = 0;
|
|
538
|
-
for (const [scriptName, rawCommand] of Object.entries(scripts)) {
|
|
539
|
-
if (typeof rawCommand !== 'string') {
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
const alias = parseNxRunAlias(rawCommand);
|
|
543
|
-
const rewrite = alias
|
|
544
|
-
? { targetName: alias.targetName, continuous: isContinuousTarget(alias.targetName, '') }
|
|
545
|
-
: classifyScriptRewrite(scriptName, rawCommand);
|
|
546
|
-
if (!rewrite || (alias && projectName && alias.projectName !== projectName)) {
|
|
547
|
-
if (alias && projectName && alias.projectName !== projectName) {
|
|
548
|
-
console.error(`${packagePath}: scripts.${scriptName} must delegate to project ${projectName}`);
|
|
549
|
-
failures++;
|
|
550
|
-
}
|
|
551
|
-
continue;
|
|
552
|
-
}
|
|
553
|
-
if (!projectName) {
|
|
554
|
-
console.error(`${packagePath}: package scripts that use workspace dependencies require package.json nx.name`);
|
|
555
|
-
failures++;
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
const expectedAlias = nxRunAlias(projectName, rewrite.targetName, rewrite.continuous);
|
|
559
|
-
if (rawCommand !== expectedAlias) {
|
|
560
|
-
console.error(`${packagePath}: scripts.${scriptName} must delegate to ${expectedAlias}`);
|
|
561
|
-
failures++;
|
|
562
|
-
continue;
|
|
563
|
-
}
|
|
564
|
-
const target = targets ? recordProperty(targets, rewrite.targetName) : null;
|
|
565
|
-
if (!target &&
|
|
566
|
-
rewrite.targetName !== scriptName &&
|
|
567
|
-
targetExistsInResolvedProject(rewrite.targetName, options.resolvedTargets)) {
|
|
568
|
-
continue;
|
|
569
|
-
}
|
|
570
|
-
if (rewrite.targetName.includes(':')) {
|
|
571
|
-
continue;
|
|
572
|
-
}
|
|
573
|
-
const targetOptions = target ? recordProperty(target, 'options') : null;
|
|
574
|
-
const command = targetOptions ? stringProperty(targetOptions, 'command') : null;
|
|
575
|
-
if (!target || stringProperty(target, 'executor') !== 'nx:run-commands' || !targetOptions || !command) {
|
|
576
|
-
console.error(`${packagePath}: nx.targets.${rewrite.targetName} must use nx:run-commands with options.command`);
|
|
577
|
-
failures++;
|
|
578
|
-
continue;
|
|
579
|
-
}
|
|
580
|
-
if (stringProperty(targetOptions, 'cwd') !== '{projectRoot}') {
|
|
581
|
-
console.error(`${packagePath}: nx.targets.${rewrite.targetName}.options.cwd must be {projectRoot}`);
|
|
582
|
-
failures++;
|
|
583
|
-
}
|
|
584
|
-
if (!targetDependsOn(target, expectedTargetDependencies(rewrite.targetName))) {
|
|
585
|
-
console.error(`${packagePath}: nx.targets.${rewrite.targetName}.dependsOn must include ${expectedTargetDependencies(rewrite.targetName).join(', ')}`);
|
|
586
|
-
failures++;
|
|
587
|
-
}
|
|
588
|
-
if (rewrite.continuous && target.continuous !== true) {
|
|
589
|
-
console.error(`${packagePath}: nx.targets.${rewrite.targetName}.continuous must be true`);
|
|
590
|
-
failures++;
|
|
591
|
-
}
|
|
592
|
-
if (isScriptRunnerCommand(command, scriptName)) {
|
|
593
|
-
console.error(`${packagePath}: nx.targets.${rewrite.targetName}.options.command must not call scripts.${scriptName}`);
|
|
594
|
-
failures++;
|
|
595
|
-
}
|
|
343
|
+
if (failures === 0) {
|
|
344
|
+
console.log('Workspace dependency policy is valid.');
|
|
596
345
|
}
|
|
597
346
|
return failures;
|
|
598
347
|
}
|
|
348
|
+
// ---------------------------------------------------------------------------
|
|
349
|
+
// Helpers kept in CLI (not Nx-specific)
|
|
350
|
+
// ---------------------------------------------------------------------------
|
|
599
351
|
function fixWorkspaceDependencyRanges(pkg, workspaceNames) {
|
|
600
352
|
let changed = false;
|
|
601
353
|
for (const field of workspaceDependencyFields) {
|
|
@@ -635,804 +387,19 @@ function validateRootNxScriptInference(rootPackage) {
|
|
|
635
387
|
console.error('package.json nx.includedScripts must be [] so root scripts do not become recursive Nx targets.');
|
|
636
388
|
return 1;
|
|
637
389
|
}
|
|
638
|
-
function
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
if (targetDefaults) {
|
|
642
|
-
for (const targetName of Object.keys(targetDefaults)) {
|
|
643
|
-
if (targetName.includes(':')) {
|
|
644
|
-
console.error(`nx.json targetDefaults.${targetName} must not use colon target names. ` +
|
|
645
|
-
'Nx CLI syntax already uses project:target:configuration, so smoo Nx target names must be unambiguous tool-output names.');
|
|
646
|
-
failures++;
|
|
647
|
-
}
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
failures += validateBuildTargetDefault(nxJson);
|
|
651
|
-
failures += validateNamedInputDefaults(nxJson);
|
|
652
|
-
const plugins = Array.isArray(nxJson.plugins) ? nxJson.plugins : [];
|
|
653
|
-
const nxJsPlugin = plugins.find(isNxJsTypescriptPlugin);
|
|
654
|
-
if (!nxJsPlugin) {
|
|
655
|
-
console.error(`nx.json plugins must configure ${nxJsTypescriptPlugin}. ` +
|
|
656
|
-
'Official Nx owns TypeScript library inference; smoo configures it so tsconfig.lib.json produces tsc-js and leaves build available as an aggregate target.');
|
|
657
|
-
failures++;
|
|
658
|
-
}
|
|
659
|
-
else if (nxJsBuildTargetName(nxJsPlugin) !== 'tsc-js') {
|
|
660
|
-
console.error(`nx.json ${nxJsTypescriptPlugin} build.targetName must be tsc-js. ` +
|
|
661
|
-
'TypeScript library output is a concrete tool-output target; build is reserved for aggregate targets that depend on concrete build work.');
|
|
662
|
-
failures++;
|
|
663
|
-
}
|
|
664
|
-
if (!plugins.includes(smoothBricksNxPlugin) && !plugins.some(isSmoothBricksNxPluginRecord)) {
|
|
665
|
-
console.error(`nx.json plugins must include ${smoothBricksNxPlugin}. ` +
|
|
666
|
-
'Smoo relies on this plugin to infer convention targets that official Nx does not provide, including typecheck-tests, non-TypeScript build-tool targets, and aggregate build/lint targets.');
|
|
667
|
-
failures++;
|
|
668
|
-
}
|
|
669
|
-
return failures;
|
|
670
|
-
}
|
|
671
|
-
function validateExplicitNxTargets(pkg, packagePath, resolvedTargets) {
|
|
672
|
-
const nx = recordProperty(pkg, 'nx');
|
|
673
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
674
|
-
if (!targets) {
|
|
675
|
-
return 0;
|
|
676
|
-
}
|
|
677
|
-
let failures = 0;
|
|
678
|
-
for (const [targetName, rawTarget] of Object.entries(targets)) {
|
|
679
|
-
if (targetName.includes(':')) {
|
|
680
|
-
console.error(`${packagePath}: package.json nx.targets.${targetName} must not use colon target names. ` +
|
|
681
|
-
'Nx CLI syntax already uses project:target:configuration; use a concrete tool-output target name and keep colon names only as package-script aliases.');
|
|
682
|
-
failures++;
|
|
683
|
-
}
|
|
684
|
-
if (!isRecord(rawTarget)) {
|
|
685
|
-
continue;
|
|
686
|
-
}
|
|
687
|
-
failures += validateTargetDependencies(rawTarget, `${packagePath}: nx.targets.${targetName}`, resolvedTargets);
|
|
688
|
-
}
|
|
689
|
-
return failures;
|
|
690
|
-
}
|
|
691
|
-
function validateTargetDependencies(target, label, resolvedTargets) {
|
|
692
|
-
if (!Array.isArray(target.dependsOn)) {
|
|
693
|
-
return 0;
|
|
694
|
-
}
|
|
695
|
-
let failures = 0;
|
|
696
|
-
for (const dependency of target.dependsOn) {
|
|
697
|
-
if (typeof dependency !== 'string') {
|
|
698
|
-
continue;
|
|
699
|
-
}
|
|
700
|
-
if (dependency.includes(':')) {
|
|
701
|
-
console.error(`${label}.dependsOn must not include colon target dependency ${dependency}`);
|
|
702
|
-
failures++;
|
|
703
|
-
continue;
|
|
704
|
-
}
|
|
705
|
-
if (label.endsWith('nx.targets.build') &&
|
|
706
|
-
!dependency.startsWith('^') &&
|
|
707
|
-
!targetExistsInResolvedProject(dependency, resolvedTargets)) {
|
|
708
|
-
console.error(`${label}.dependsOn references missing target ${dependency}`);
|
|
709
|
-
failures++;
|
|
710
|
-
}
|
|
711
|
-
}
|
|
712
|
-
return failures;
|
|
713
|
-
}
|
|
714
|
-
function validateTsconfigTestPolicy(root, packagePath) {
|
|
715
|
-
const path = join(root, packagePath, 'tsconfig.test.json');
|
|
716
|
-
const tsconfig = readJsonObject(path);
|
|
717
|
-
if (!tsconfig) {
|
|
718
|
-
return 0;
|
|
719
|
-
}
|
|
720
|
-
const compilerOptions = recordProperty(tsconfig, 'compilerOptions');
|
|
721
|
-
let failures = 0;
|
|
722
|
-
if (!compilerOptions || compilerOptions.noEmit !== true) {
|
|
723
|
-
console.error(`${packagePath}/tsconfig.test.json compilerOptions.noEmit must be true`);
|
|
724
|
-
failures++;
|
|
725
|
-
}
|
|
726
|
-
if (compilerOptions?.composite === true) {
|
|
727
|
-
console.error(`${packagePath}/tsconfig.test.json must not set compilerOptions.composite = true. ` +
|
|
728
|
-
'Bun test typechecking is a no-emit validation pass, not a TypeScript build-mode project.');
|
|
729
|
-
failures++;
|
|
730
|
-
}
|
|
731
|
-
if (compilerOptions?.declaration === true) {
|
|
732
|
-
console.error(`${packagePath}/tsconfig.test.json must not set compilerOptions.declaration = true`);
|
|
733
|
-
failures++;
|
|
734
|
-
}
|
|
735
|
-
if (compilerOptions?.declarationMap === true) {
|
|
736
|
-
console.error(`${packagePath}/tsconfig.test.json must not set compilerOptions.declarationMap = true`);
|
|
737
|
-
failures++;
|
|
738
|
-
}
|
|
739
|
-
if (compilerOptions?.outDir === 'dist-test') {
|
|
740
|
-
console.error(`${packagePath}/tsconfig.test.json must not emit to dist-test`);
|
|
741
|
-
failures++;
|
|
742
|
-
}
|
|
743
|
-
if (typeof compilerOptions?.tsBuildInfoFile === 'string' && compilerOptions.tsBuildInfoFile.includes('dist-test')) {
|
|
744
|
-
console.error(`${packagePath}/tsconfig.test.json must not write tsbuildinfo under dist-test`);
|
|
745
|
-
failures++;
|
|
746
|
-
}
|
|
747
|
-
return failures;
|
|
748
|
-
}
|
|
749
|
-
function validateTsconfigTestReferencePolicy(root, packagePath) {
|
|
750
|
-
const testTsconfigPath = join(root, packagePath, 'tsconfig.test.json');
|
|
751
|
-
if (!existsSync(testTsconfigPath)) {
|
|
752
|
-
return 0;
|
|
753
|
-
}
|
|
754
|
-
const projectTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.json'));
|
|
755
|
-
if (!projectTsconfigHasTestReference(projectTsconfig)) {
|
|
756
|
-
return 0;
|
|
757
|
-
}
|
|
758
|
-
console.error(`${packagePath}/tsconfig.json must not reference ./tsconfig.test.json. ` +
|
|
759
|
-
'Test typechecking is run by the inferred typecheck-tests target with tsc --noEmit, not TypeScript build mode.');
|
|
760
|
-
return 1;
|
|
761
|
-
}
|
|
762
|
-
function validateBunTestTsconfigPresence(root, packagePath, pkg) {
|
|
763
|
-
if (!usesBunTest(pkg)) {
|
|
764
|
-
return 0;
|
|
765
|
-
}
|
|
766
|
-
const path = join(root, packagePath, 'tsconfig.test.json');
|
|
767
|
-
if (existsSync(path)) {
|
|
768
|
-
return 0;
|
|
769
|
-
}
|
|
770
|
-
console.error(`${packagePath}: bun test requires tsconfig.test.json because Bun executes tests without typechecking. ` +
|
|
771
|
-
'Run smoo monorepo validate --fix to create the no-emit test typecheck config.');
|
|
772
|
-
return 1;
|
|
773
|
-
}
|
|
774
|
-
function applyBunTestTsconfigDefaults(root, packagePath, pkg, workspaceNames) {
|
|
775
|
-
if (!usesBunTest(pkg)) {
|
|
776
|
-
return;
|
|
777
|
-
}
|
|
778
|
-
const tsconfigTestPath = join(root, packagePath, 'tsconfig.test.json');
|
|
779
|
-
const existing = readJsonObject(tsconfigTestPath);
|
|
780
|
-
const tsconfigTest = existing ?? {};
|
|
781
|
-
let changed = existing === null;
|
|
782
|
-
changed = applyTsconfigTestDefaults(root, packagePath, pkg, tsconfigTest, workspaceNames) || changed;
|
|
783
|
-
if (changed) {
|
|
784
|
-
writeJsonObject(tsconfigTestPath, tsconfigTest);
|
|
785
|
-
console.log(`updated ${packagePath}/tsconfig.test.json bun test typecheck config`);
|
|
786
|
-
}
|
|
787
|
-
else {
|
|
788
|
-
console.log(`unchanged ${packagePath}/tsconfig.test.json bun test typecheck config`);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
function applyTsconfigTestReferenceDefaults(root, packagePath) {
|
|
792
|
-
const projectTsconfigPath = join(root, packagePath, 'tsconfig.json');
|
|
793
|
-
const projectTsconfig = readJsonObject(projectTsconfigPath);
|
|
794
|
-
if (!projectTsconfig || !projectTsconfigHasTestReference(projectTsconfig)) {
|
|
795
|
-
return;
|
|
796
|
-
}
|
|
797
|
-
const references = Array.isArray(projectTsconfig.references) ? projectTsconfig.references : [];
|
|
798
|
-
projectTsconfig.references = references.filter((entry) => !isRecord(entry) || entry.path !== './tsconfig.test.json');
|
|
799
|
-
writeJsonObject(projectTsconfigPath, projectTsconfig);
|
|
800
|
-
console.log(`updated ${packagePath}/tsconfig.json removed test project reference`);
|
|
801
|
-
}
|
|
802
|
-
function applyTsconfigTestDefaults(root, packagePath, pkg, tsconfigTest, workspaceNames) {
|
|
803
|
-
let changed = setMissingStringProperty(tsconfigTest, 'extends', defaultTsconfigTestExtends(root, packagePath));
|
|
804
|
-
const compilerOptions = getOrCreateRecord(tsconfigTest, 'compilerOptions');
|
|
805
|
-
changed = copyLibCompilerOptions(root, packagePath, compilerOptions) || changed;
|
|
806
|
-
changed = setBooleanProperty(compilerOptions, 'composite', false) || changed;
|
|
807
|
-
changed = setBooleanProperty(compilerOptions, 'declaration', false) || changed;
|
|
808
|
-
changed = setBooleanProperty(compilerOptions, 'declarationMap', false) || changed;
|
|
809
|
-
changed = setBooleanProperty(compilerOptions, 'emitDeclarationOnly', false) || changed;
|
|
810
|
-
changed = setBooleanProperty(compilerOptions, 'noEmit', true) || changed;
|
|
811
|
-
changed = mergeStringListProperty(compilerOptions, 'types', ['bun']) || changed;
|
|
812
|
-
if (delete compilerOptions.outDir) {
|
|
813
|
-
changed = true;
|
|
814
|
-
}
|
|
815
|
-
if (delete compilerOptions.tsBuildInfoFile) {
|
|
816
|
-
changed = true;
|
|
817
|
-
}
|
|
818
|
-
changed =
|
|
819
|
-
mergeStringListProperty(tsconfigTest, 'include', [
|
|
820
|
-
'src/**/*.test.ts',
|
|
821
|
-
'src/**/*.spec.ts',
|
|
822
|
-
'src/**/__tests__/**/*.ts',
|
|
823
|
-
'src/**/__tests__/**/*.tsx',
|
|
824
|
-
'src/test-suite-tracer.ts',
|
|
825
|
-
]) || changed;
|
|
826
|
-
for (const referencePath of collectTsconfigTestReferencePaths(root, packagePath, pkg, workspaceNames)) {
|
|
827
|
-
changed = addTsconfigReference(tsconfigTest, referencePath) || changed;
|
|
828
|
-
}
|
|
829
|
-
return changed;
|
|
830
|
-
}
|
|
831
|
-
function defaultTsconfigTestExtends(root, packagePath) {
|
|
832
|
-
const libTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.lib.json'));
|
|
833
|
-
return stringProperty(libTsconfig ?? {}, 'extends') ?? '../../tsconfig.base.json';
|
|
834
|
-
}
|
|
835
|
-
function copyLibCompilerOptions(root, packagePath, target) {
|
|
836
|
-
const libTsconfig = readJsonObject(join(root, packagePath, 'tsconfig.lib.json'));
|
|
837
|
-
const libCompilerOptions = libTsconfig ? recordProperty(libTsconfig, 'compilerOptions') : null;
|
|
838
|
-
if (!libCompilerOptions) {
|
|
839
|
-
return false;
|
|
840
|
-
}
|
|
841
|
-
let changed = false;
|
|
842
|
-
for (const key of ['baseUrl', 'module', 'moduleResolution', 'jsx', 'lib']) {
|
|
843
|
-
if (hasOwn(libCompilerOptions, key) && target[key] !== libCompilerOptions[key]) {
|
|
844
|
-
target[key] = libCompilerOptions[key];
|
|
845
|
-
changed = true;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
return changed;
|
|
849
|
-
}
|
|
850
|
-
function collectTsconfigTestReferencePaths(root, packagePath, pkg, workspaceNames) {
|
|
851
|
-
const paths = existsSync(join(root, packagePath, 'tsconfig.lib.json')) ? ['./tsconfig.lib.json'] : [];
|
|
852
|
-
const packagesByName = new Map(getWorkspacePackages(root).map((workspacePkg) => [workspacePkg.name, workspacePkg]));
|
|
853
|
-
for (const field of workspaceDependencyFields) {
|
|
854
|
-
const dependencies = recordProperty(pkg, field);
|
|
855
|
-
if (!dependencies) {
|
|
856
|
-
continue;
|
|
857
|
-
}
|
|
858
|
-
for (const dependencyName of Object.keys(dependencies)) {
|
|
859
|
-
if (!workspaceNames.has(dependencyName)) {
|
|
860
|
-
continue;
|
|
861
|
-
}
|
|
862
|
-
const dependencyPackage = packagesByName.get(dependencyName);
|
|
863
|
-
if (!dependencyPackage) {
|
|
864
|
-
continue;
|
|
865
|
-
}
|
|
866
|
-
const dependencyTsconfig = join(root, dependencyPackage.path, 'tsconfig.lib.json');
|
|
867
|
-
if (!existsSync(dependencyTsconfig)) {
|
|
868
|
-
continue;
|
|
869
|
-
}
|
|
870
|
-
const refPath = relative(join(root, packagePath), dependencyTsconfig).replaceAll('\\', '/');
|
|
871
|
-
if (!paths.includes(refPath)) {
|
|
872
|
-
paths.push(refPath);
|
|
873
|
-
}
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
return paths;
|
|
877
|
-
}
|
|
878
|
-
function usesBunTest(pkg) {
|
|
879
|
-
const scripts = recordProperty(pkg, 'scripts');
|
|
880
|
-
if (scripts && Object.values(scripts).some((command) => typeof command === 'string' && isBunTestCommand(command))) {
|
|
881
|
-
return true;
|
|
882
|
-
}
|
|
883
|
-
const nx = recordProperty(pkg, 'nx');
|
|
884
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
885
|
-
if (!targets) {
|
|
886
|
-
return false;
|
|
887
|
-
}
|
|
888
|
-
for (const target of Object.values(targets)) {
|
|
889
|
-
if (!isRecord(target)) {
|
|
890
|
-
continue;
|
|
891
|
-
}
|
|
892
|
-
const options = recordProperty(target, 'options');
|
|
893
|
-
const command = options ? stringProperty(options, 'command') : null;
|
|
894
|
-
if (command && isBunTestCommand(command)) {
|
|
895
|
-
return true;
|
|
896
|
-
}
|
|
897
|
-
}
|
|
898
|
-
return false;
|
|
899
|
-
}
|
|
900
|
-
function isBunTestCommand(command) {
|
|
901
|
-
return /^bun\s+test(?:\s|$)/.test(parseEnvPrefixedCommand(command).command.trim());
|
|
902
|
-
}
|
|
903
|
-
function mergeStringListProperty(record, key, values) {
|
|
904
|
-
const rawCurrent = record[key];
|
|
905
|
-
const current = Array.isArray(rawCurrent)
|
|
906
|
-
? rawCurrent.filter((entry) => typeof entry === 'string')
|
|
907
|
-
: [];
|
|
908
|
-
const next = [...current];
|
|
909
|
-
for (const value of values) {
|
|
910
|
-
if (!next.includes(value)) {
|
|
911
|
-
next.push(value);
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
if (Array.isArray(rawCurrent) &&
|
|
915
|
-
next.length === rawCurrent.length &&
|
|
916
|
-
next.every((entry, index) => entry === rawCurrent[index])) {
|
|
917
|
-
return false;
|
|
918
|
-
}
|
|
919
|
-
record[key] = next;
|
|
920
|
-
return true;
|
|
921
|
-
}
|
|
922
|
-
function addTsconfigReference(tsconfig, path) {
|
|
923
|
-
const current = Array.isArray(tsconfig.references)
|
|
924
|
-
? tsconfig.references.filter((entry) => isRecord(entry))
|
|
925
|
-
: [];
|
|
926
|
-
if (current.some((entry) => entry.path === path)) {
|
|
927
|
-
return false;
|
|
928
|
-
}
|
|
929
|
-
tsconfig.references = [...current, { path }];
|
|
930
|
-
return true;
|
|
931
|
-
}
|
|
932
|
-
function projectTsconfigHasTestReference(projectTsconfig) {
|
|
933
|
-
return Boolean(projectTsconfig &&
|
|
934
|
-
Array.isArray(projectTsconfig.references) &&
|
|
935
|
-
projectTsconfig.references.some((entry) => isRecord(entry) && entry.path === './tsconfig.test.json'));
|
|
936
|
-
}
|
|
937
|
-
function validateBuildZigPolicy(root, packagePath) {
|
|
938
|
-
const path = join(root, packagePath, 'build.zig');
|
|
939
|
-
if (!existsSync(path)) {
|
|
940
|
-
return 0;
|
|
941
|
-
}
|
|
942
|
-
if (/\bb\.step\s*\(/.test(readFileSync(path, 'utf8'))) {
|
|
943
|
-
return 0;
|
|
944
|
-
}
|
|
945
|
-
console.error(`${packagePath}/build.zig must define at least one b.step(...) target`);
|
|
946
|
-
return 1;
|
|
947
|
-
}
|
|
948
|
-
function applyBuildTargetDefault(nxJson) {
|
|
949
|
-
const targetDefaults = getOrCreateRecord(nxJson, 'targetDefaults');
|
|
950
|
-
const build = getOrCreateRecord(targetDefaults, 'build');
|
|
951
|
-
let changed = setBooleanProperty(build, 'cache', true);
|
|
952
|
-
changed = setStringArrayProperty(build, 'outputs', ['{projectRoot}/dist']) || changed;
|
|
953
|
-
return changed;
|
|
954
|
-
}
|
|
955
|
-
function validateBuildTargetDefault(nxJson) {
|
|
956
|
-
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
957
|
-
const build = targetDefaults ? recordProperty(targetDefaults, 'build') : null;
|
|
958
|
-
let failures = 0;
|
|
959
|
-
if (!build || build.cache !== true) {
|
|
960
|
-
console.error('nx.json targetDefaults.build.cache must be true');
|
|
961
|
-
failures++;
|
|
962
|
-
}
|
|
963
|
-
const outputs = build?.outputs;
|
|
964
|
-
if (!Array.isArray(outputs) || outputs.length !== 1 || outputs[0] !== '{projectRoot}/dist') {
|
|
965
|
-
console.error('nx.json targetDefaults.build.outputs must be ["{projectRoot}/dist"]');
|
|
966
|
-
failures++;
|
|
967
|
-
}
|
|
968
|
-
return failures;
|
|
969
|
-
}
|
|
970
|
-
function applyNamedInputDefaults(nxJson) {
|
|
971
|
-
const namedInputs = getOrCreateRecord(nxJson, 'namedInputs');
|
|
972
|
-
let changed = false;
|
|
973
|
-
if (!Array.isArray(namedInputs.default)) {
|
|
974
|
-
namedInputs.default = ['{projectRoot}/**/*', 'sharedGlobals'];
|
|
975
|
-
changed = true;
|
|
976
|
-
}
|
|
977
|
-
changed = setStringArrayProperty(namedInputs, 'sharedGlobals', expectedSharedGlobalsNamedInput) || changed;
|
|
978
|
-
const production = namedInputs.production;
|
|
979
|
-
if (!Array.isArray(production) || !isPreciseProductionNamedInput(production)) {
|
|
980
|
-
namedInputs.production = defaultProductionNamedInput;
|
|
981
|
-
changed = true;
|
|
982
|
-
}
|
|
983
|
-
return changed;
|
|
984
|
-
}
|
|
985
|
-
function validateNamedInputDefaults(nxJson) {
|
|
986
|
-
const namedInputs = recordProperty(nxJson, 'namedInputs');
|
|
987
|
-
const production = namedInputs?.production;
|
|
988
|
-
let failures = 0;
|
|
989
|
-
if (!namedInputs) {
|
|
990
|
-
console.error('nx.json namedInputs must be configured so production builds have precise cache inputs.');
|
|
991
|
-
return 1;
|
|
992
|
-
}
|
|
993
|
-
if (!Array.isArray(namedInputs.default)) {
|
|
994
|
-
console.error('nx.json namedInputs.default must be an array; smoo allows it to remain broad for non-production tasks.');
|
|
995
|
-
failures++;
|
|
996
|
-
}
|
|
997
|
-
if (!stringArrayEquals(namedInputs.sharedGlobals, expectedSharedGlobalsNamedInput)) {
|
|
998
|
-
console.error('nx.json namedInputs.sharedGlobals must include only {workspaceRoot}/.github/workflows/ci.yml');
|
|
999
|
-
failures++;
|
|
1000
|
-
}
|
|
1001
|
-
if (!Array.isArray(production)) {
|
|
1002
|
-
console.error('nx.json namedInputs.production must be an array of precise production inputs.');
|
|
1003
|
-
return failures + 1;
|
|
1004
|
-
}
|
|
1005
|
-
if (!isPreciseProductionNamedInput(production)) {
|
|
1006
|
-
console.error('nx.json namedInputs.production must enumerate precise production inputs. Do not include default or broad {projectRoot}/** globs; use language/tool-specific paths such as {projectRoot}/src/**/*, {projectRoot}/Cargo.toml, or {projectRoot}/pyproject.toml.');
|
|
1007
|
-
failures++;
|
|
1008
|
-
}
|
|
1009
|
-
return failures;
|
|
1010
|
-
}
|
|
1011
|
-
function isPreciseProductionNamedInput(production) {
|
|
1012
|
-
let hasPositiveProjectInput = false;
|
|
1013
|
-
for (const input of production) {
|
|
1014
|
-
if (typeof input !== 'string') {
|
|
1015
|
-
return false;
|
|
1016
|
-
}
|
|
1017
|
-
const normalized = input.startsWith('!') ? input.slice(1) : input;
|
|
1018
|
-
if (impreciseProductionInputs.has(input) || impreciseProductionInputs.has(normalized)) {
|
|
1019
|
-
return false;
|
|
1020
|
-
}
|
|
1021
|
-
if (!input.startsWith('!') && normalized.startsWith('{projectRoot}/')) {
|
|
1022
|
-
hasPositiveProjectInput = true;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
return hasPositiveProjectInput;
|
|
1026
|
-
}
|
|
1027
|
-
function removeColonTargetDefaults(nxJson) {
|
|
1028
|
-
const targetDefaults = recordProperty(nxJson, 'targetDefaults');
|
|
1029
|
-
if (!targetDefaults) {
|
|
1030
|
-
return false;
|
|
1031
|
-
}
|
|
1032
|
-
let changed = false;
|
|
1033
|
-
for (const targetName of Object.keys(targetDefaults)) {
|
|
1034
|
-
if (targetName.includes(':')) {
|
|
1035
|
-
delete targetDefaults[targetName];
|
|
1036
|
-
changed = true;
|
|
1037
|
-
}
|
|
1038
|
-
}
|
|
1039
|
-
return changed;
|
|
1040
|
-
}
|
|
1041
|
-
function rewriteColonTargetDependenciesInPackage(pkg, resolvedTargets) {
|
|
1042
|
-
const nx = recordProperty(pkg, 'nx');
|
|
1043
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
1044
|
-
if (!targets) {
|
|
1045
|
-
return false;
|
|
1046
|
-
}
|
|
1047
|
-
const projectName = packageNxProjectName(pkg);
|
|
1048
|
-
const scriptTargetAliases = scriptTargetAliasesForProject(pkg, projectName);
|
|
1049
|
-
let changed = false;
|
|
1050
|
-
for (const target of Object.values(targets)) {
|
|
1051
|
-
if (!isRecord(target) || !Array.isArray(target.dependsOn)) {
|
|
1052
|
-
continue;
|
|
1053
|
-
}
|
|
1054
|
-
target.dependsOn = target.dependsOn.map((dependency) => {
|
|
1055
|
-
if (typeof dependency !== 'string' || !dependency.includes(':')) {
|
|
1056
|
-
return dependency;
|
|
1057
|
-
}
|
|
1058
|
-
const next = scriptTargetAliases.get(dependency) ?? replacementTargetName(dependency, null, resolvedTargets);
|
|
1059
|
-
if (!next) {
|
|
1060
|
-
return dependency;
|
|
1061
|
-
}
|
|
1062
|
-
changed = true;
|
|
1063
|
-
return next;
|
|
1064
|
-
});
|
|
1065
|
-
}
|
|
1066
|
-
return changed;
|
|
1067
|
-
}
|
|
1068
|
-
function scriptTargetAliasesForProject(pkg, projectName) {
|
|
1069
|
-
if (!projectName) {
|
|
1070
|
-
return new Map();
|
|
1071
|
-
}
|
|
1072
|
-
const scripts = recordProperty(pkg, 'scripts');
|
|
1073
|
-
if (!scripts) {
|
|
1074
|
-
return new Map();
|
|
1075
|
-
}
|
|
1076
|
-
const aliases = new Map();
|
|
1077
|
-
for (const [scriptName, rawCommand] of Object.entries(scripts)) {
|
|
1078
|
-
if (typeof rawCommand !== 'string' || !scriptName.includes(':')) {
|
|
1079
|
-
continue;
|
|
1080
|
-
}
|
|
1081
|
-
const alias = parseNxRunAlias(rawCommand);
|
|
1082
|
-
if (alias?.projectName === projectName && !alias.targetName.includes(':')) {
|
|
1083
|
-
aliases.set(scriptName, alias.targetName);
|
|
1084
|
-
}
|
|
1085
|
-
}
|
|
1086
|
-
return aliases;
|
|
1087
|
-
}
|
|
1088
|
-
function removePackageColonTargets(pkg) {
|
|
1089
|
-
const nx = recordProperty(pkg, 'nx');
|
|
1090
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
1091
|
-
if (!targets) {
|
|
1092
|
-
return false;
|
|
1093
|
-
}
|
|
1094
|
-
let changed = false;
|
|
1095
|
-
for (const targetName of Object.keys(targets)) {
|
|
1096
|
-
if (targetName.includes(':')) {
|
|
1097
|
-
delete targets[targetName];
|
|
1098
|
-
changed = true;
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
return changed;
|
|
1102
|
-
}
|
|
1103
|
-
function resolvedProjectTargetNames(resolvedProject) {
|
|
1104
|
-
if (!resolvedProject) {
|
|
1105
|
-
return undefined;
|
|
1106
|
-
}
|
|
1107
|
-
return isResolvedProjectTargets(resolvedProject) ? resolvedProject.targets : resolvedProject;
|
|
1108
|
-
}
|
|
1109
|
-
function resolvedProjectBuildDependsOn(resolvedProject) {
|
|
1110
|
-
if (!isResolvedProjectTargets(resolvedProject)) {
|
|
1111
|
-
return undefined;
|
|
1112
|
-
}
|
|
1113
|
-
return resolvedProject.buildDependsOn;
|
|
1114
|
-
}
|
|
1115
|
-
function isResolvedProjectTargets(value) {
|
|
1116
|
-
return isRecord(value) && value.targets instanceof Set;
|
|
1117
|
-
}
|
|
1118
|
-
function removeRedundantNoopBuildTarget(pkg, resolvedProject) {
|
|
1119
|
-
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
1120
|
-
const resolvedBuildDependsOn = resolvedProjectBuildDependsOn(resolvedProject);
|
|
1121
|
-
if (!resolvedTargets?.has('build') || !resolvedBuildDependsOn) {
|
|
1122
|
-
return false;
|
|
1123
|
-
}
|
|
1124
|
-
const nx = recordProperty(pkg, 'nx');
|
|
1125
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
1126
|
-
const build = targets ? recordProperty(targets, 'build') : null;
|
|
1127
|
-
if (!targets ||
|
|
1128
|
-
!build ||
|
|
1129
|
-
!isNoopTarget(build) ||
|
|
1130
|
-
!targetDependenciesMatchResolvedBuild(build, resolvedBuildDependsOn)) {
|
|
1131
|
-
return false;
|
|
1132
|
-
}
|
|
1133
|
-
delete targets.build;
|
|
1134
|
-
return true;
|
|
1135
|
-
}
|
|
1136
|
-
function isNoopTarget(target) {
|
|
1137
|
-
const executor = stringProperty(target, 'executor');
|
|
1138
|
-
if (executor !== null && executor !== 'nx:noop') {
|
|
1139
|
-
return false;
|
|
1140
|
-
}
|
|
1141
|
-
const options = recordProperty(target, 'options');
|
|
1142
|
-
return !options || stringProperty(options, 'command') === null;
|
|
1143
|
-
}
|
|
1144
|
-
function targetDependenciesMatchResolvedBuild(target, resolvedBuildDependsOn) {
|
|
1145
|
-
if (!Array.isArray(target.dependsOn)) {
|
|
1146
|
-
return false;
|
|
1147
|
-
}
|
|
1148
|
-
const expected = new Set(resolvedBuildDependsOn);
|
|
1149
|
-
if (target.dependsOn.length !== expected.size) {
|
|
1150
|
-
return false;
|
|
1151
|
-
}
|
|
1152
|
-
return target.dependsOn.every((dependency) => {
|
|
1153
|
-
if (typeof dependency !== 'string') {
|
|
1154
|
-
return false;
|
|
1155
|
-
}
|
|
1156
|
-
return expected.has(dependency);
|
|
1157
|
-
});
|
|
1158
|
-
}
|
|
1159
|
-
function migratePackageColonTargets(pkg, resolvedTargets) {
|
|
1160
|
-
const nx = recordProperty(pkg, 'nx');
|
|
1161
|
-
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
1162
|
-
if (!targets) {
|
|
1163
|
-
return false;
|
|
1164
|
-
}
|
|
1165
|
-
const projectName = packageNxProjectName(pkg);
|
|
1166
|
-
const scripts = recordProperty(pkg, 'scripts');
|
|
1167
|
-
let changed = false;
|
|
1168
|
-
const renamedTargets = new Map();
|
|
1169
|
-
for (const [targetName, rawTarget] of Object.entries(targets)) {
|
|
1170
|
-
if (!targetName.includes(':') || !isRecord(rawTarget)) {
|
|
1171
|
-
continue;
|
|
1172
|
-
}
|
|
1173
|
-
const nextTargetName = replacementTargetName(targetName, targetCommand(rawTarget), resolvedTargets);
|
|
1174
|
-
if (!nextTargetName || nextTargetName.includes(':')) {
|
|
1175
|
-
continue;
|
|
1176
|
-
}
|
|
1177
|
-
if (!targetExistsInResolvedProject(nextTargetName, resolvedTargets)) {
|
|
1178
|
-
targets[nextTargetName] = rawTarget;
|
|
1179
|
-
}
|
|
1180
|
-
delete targets[targetName];
|
|
1181
|
-
renamedTargets.set(targetName, nextTargetName);
|
|
1182
|
-
changed = true;
|
|
1183
|
-
}
|
|
1184
|
-
if (renamedTargets.size === 0) {
|
|
1185
|
-
return changed;
|
|
1186
|
-
}
|
|
1187
|
-
for (const target of Object.values(targets)) {
|
|
1188
|
-
if (isRecord(target)) {
|
|
1189
|
-
changed = rewriteTargetDependencies(target, renamedTargets) || changed;
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
if (scripts && projectName) {
|
|
1193
|
-
for (const [scriptName, rawCommand] of Object.entries(scripts)) {
|
|
1194
|
-
if (typeof rawCommand !== 'string') {
|
|
1195
|
-
continue;
|
|
1196
|
-
}
|
|
1197
|
-
const alias = parseNxRunAlias(rawCommand);
|
|
1198
|
-
if (!alias || alias.projectName !== projectName) {
|
|
1199
|
-
continue;
|
|
1200
|
-
}
|
|
1201
|
-
const nextTargetName = renamedTargets.get(alias.targetName);
|
|
1202
|
-
if (!nextTargetName) {
|
|
1203
|
-
continue;
|
|
1204
|
-
}
|
|
1205
|
-
scripts[scriptName] = nxRunAlias(projectName, nextTargetName, isContinuousTarget(nextTargetName, ''));
|
|
1206
|
-
changed = true;
|
|
1207
|
-
}
|
|
1208
|
-
}
|
|
1209
|
-
return changed;
|
|
1210
|
-
}
|
|
1211
|
-
function rewriteTargetDependencies(target, renamedTargets) {
|
|
1212
|
-
if (!Array.isArray(target.dependsOn)) {
|
|
1213
|
-
return false;
|
|
1214
|
-
}
|
|
1215
|
-
let changed = false;
|
|
1216
|
-
target.dependsOn = target.dependsOn.map((dependency) => {
|
|
1217
|
-
if (typeof dependency !== 'string') {
|
|
1218
|
-
return dependency;
|
|
1219
|
-
}
|
|
1220
|
-
const next = renamedTargets.get(dependency);
|
|
1221
|
-
if (!next) {
|
|
1222
|
-
return dependency;
|
|
1223
|
-
}
|
|
1224
|
-
changed = true;
|
|
1225
|
-
return next;
|
|
1226
|
-
});
|
|
1227
|
-
return changed;
|
|
1228
|
-
}
|
|
1229
|
-
function targetCommand(target) {
|
|
1230
|
-
const options = recordProperty(target, 'options');
|
|
1231
|
-
return options ? stringProperty(options, 'command') : null;
|
|
1232
|
-
}
|
|
1233
|
-
function replacementTargetName(targetName, command, resolvedTargets) {
|
|
1234
|
-
if (command) {
|
|
1235
|
-
const commandTargetName = targetNameForCommand(command);
|
|
1236
|
-
if (commandTargetName) {
|
|
1237
|
-
return commandTargetName;
|
|
1238
|
-
}
|
|
1239
|
-
}
|
|
1240
|
-
const suffix = targetName.slice(targetName.lastIndexOf(':') + 1);
|
|
1241
|
-
if (suffix && targetExistsInResolvedProject(suffix, resolvedTargets)) {
|
|
1242
|
-
return suffix;
|
|
1243
|
-
}
|
|
1244
|
-
const dashed = targetName.replaceAll(':', '-');
|
|
1245
|
-
if (targetExistsInResolvedProject(dashed, resolvedTargets)) {
|
|
1246
|
-
return dashed;
|
|
1247
|
-
}
|
|
1248
|
-
return null;
|
|
1249
|
-
}
|
|
1250
|
-
function expectedNxJsTypescriptPlugin() {
|
|
1251
|
-
return {
|
|
1252
|
-
plugin: nxJsTypescriptPlugin,
|
|
1253
|
-
options: {
|
|
1254
|
-
typecheck: { targetName: 'typecheck' },
|
|
1255
|
-
build: {
|
|
1256
|
-
targetName: 'tsc-js',
|
|
1257
|
-
configName: 'tsconfig.lib.json',
|
|
1258
|
-
buildDepsName: 'build-deps',
|
|
1259
|
-
watchDepsName: 'watch-deps',
|
|
1260
|
-
},
|
|
1261
|
-
},
|
|
1262
|
-
};
|
|
1263
|
-
}
|
|
1264
|
-
function upsertNxPlugin(plugins, plugin) {
|
|
1265
|
-
const pluginName = typeof plugin === 'string' ? plugin : stringProperty(plugin, 'plugin');
|
|
1266
|
-
const next = plugins.filter((entry) => nxPluginName(entry) !== pluginName);
|
|
1267
|
-
next.push(plugin);
|
|
1268
|
-
return next;
|
|
1269
|
-
}
|
|
1270
|
-
function nxPluginName(value) {
|
|
1271
|
-
if (typeof value === 'string') {
|
|
1272
|
-
return value;
|
|
1273
|
-
}
|
|
1274
|
-
return isRecord(value) ? stringProperty(value, 'plugin') : null;
|
|
1275
|
-
}
|
|
1276
|
-
function isNxJsTypescriptPlugin(value) {
|
|
1277
|
-
return isRecord(value) && stringProperty(value, 'plugin') === nxJsTypescriptPlugin;
|
|
1278
|
-
}
|
|
1279
|
-
function isSmoothBricksNxPluginRecord(value) {
|
|
1280
|
-
return isRecord(value) && stringProperty(value, 'plugin') === smoothBricksNxPlugin;
|
|
1281
|
-
}
|
|
1282
|
-
function nxJsBuildTargetName(plugin) {
|
|
1283
|
-
const options = recordProperty(plugin, 'options');
|
|
1284
|
-
const build = options ? recordProperty(options, 'build') : null;
|
|
1285
|
-
return build ? stringProperty(build, 'targetName') : null;
|
|
1286
|
-
}
|
|
1287
|
-
function applyPackageNxConfig(pkg, options) {
|
|
1288
|
-
const nx = getOrCreateRecord(pkg, 'nx');
|
|
1289
|
-
const changed = setStringProperty(nx, 'name', options.projectName);
|
|
1290
|
-
const targets = options.targets === true ? getOrCreateRecord(nx, 'targets') : null;
|
|
1291
|
-
return { nx, targets, changed };
|
|
1292
|
-
}
|
|
1293
|
-
function packageNxProjectName(pkg) {
|
|
1294
|
-
const nx = recordProperty(pkg, 'nx');
|
|
1295
|
-
return (nx ? stringProperty(nx, 'name') : null) ?? stringProperty(pkg, 'name');
|
|
1296
|
-
}
|
|
1297
|
-
function classifyScriptRewrite(scriptName, command) {
|
|
1298
|
-
if (isNxRunAlias(command) || isBlockedScriptCommand(scriptName, command)) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
const parsed = parseEnvPrefixedCommand(command);
|
|
1302
|
-
const targetName = rewriteTargetName(scriptName, parsed.command);
|
|
1303
|
-
if (!targetName || !isSafeNxScriptCommand(parsed.command)) {
|
|
390
|
+
function suggestNxProjectName(rootPackageName, packageName) {
|
|
391
|
+
const rootScope = npmScope(rootPackageName);
|
|
392
|
+
if (!rootScope || npmScope(packageName) !== rootScope) {
|
|
1304
393
|
return null;
|
|
1305
394
|
}
|
|
1306
|
-
return
|
|
1307
|
-
targetName,
|
|
1308
|
-
continuous: isContinuousTarget(targetName, parsed.command),
|
|
1309
|
-
command: parsed.command,
|
|
1310
|
-
env: parsed.env,
|
|
1311
|
-
};
|
|
1312
|
-
}
|
|
1313
|
-
function rewriteTargetName(scriptName, command) {
|
|
1314
|
-
return targetNameForCommand(command) ?? (scriptName.includes(':') ? null : scriptName);
|
|
1315
|
-
}
|
|
1316
|
-
function targetNameForCommand(command) {
|
|
1317
|
-
const trimmed = command.trim();
|
|
1318
|
-
if (/^tsc\s+--build\s+tsconfig\.lib\.json(?:\s|$)/.test(trimmed)) {
|
|
1319
|
-
return 'tsc-js';
|
|
1320
|
-
}
|
|
1321
|
-
const zigStep = /^zig\s+build\s+([A-Za-z0-9_-]+)(?:\s|$)/.exec(trimmed)?.[1];
|
|
1322
|
-
if (zigStep) {
|
|
1323
|
-
return `zig-${zigStep}`;
|
|
1324
|
-
}
|
|
1325
|
-
if (/^wrangler\s+build(?:\s|$)/.test(trimmed)) {
|
|
1326
|
-
return 'build';
|
|
1327
|
-
}
|
|
1328
|
-
return null;
|
|
1329
|
-
}
|
|
1330
|
-
function nxRunAlias(projectName, targetName, continuous) {
|
|
1331
|
-
const flags = continuous ? ' --tui=false --outputStyle=stream' : '';
|
|
1332
|
-
return `nx run ${projectName}:${targetName}${flags}`;
|
|
1333
|
-
}
|
|
1334
|
-
function expectedTargetDependencies(targetName) {
|
|
1335
|
-
return targetName === 'preview' ? ['build'] : ['^build'];
|
|
1336
|
-
}
|
|
1337
|
-
function targetExistsInResolvedProject(targetName, resolvedTargets) {
|
|
1338
|
-
return resolvedTargets?.has(targetName) === true;
|
|
1339
|
-
}
|
|
1340
|
-
function setStringArrayProperty(record, key, value) {
|
|
1341
|
-
const current = record[key];
|
|
1342
|
-
if (stringArrayEquals(current, value)) {
|
|
1343
|
-
return false;
|
|
1344
|
-
}
|
|
1345
|
-
record[key] = value;
|
|
1346
|
-
return true;
|
|
1347
|
-
}
|
|
1348
|
-
function stringArrayEquals(value, expected) {
|
|
1349
|
-
return (Array.isArray(value) && value.length === expected.length && value.every((entry, index) => entry === expected[index]));
|
|
1350
|
-
}
|
|
1351
|
-
function targetDependsOn(target, expected) {
|
|
1352
|
-
const dependsOn = target.dependsOn;
|
|
1353
|
-
return Array.isArray(dependsOn) && expected.every((entry) => dependsOn.includes(entry));
|
|
1354
|
-
}
|
|
1355
|
-
function hasWorkspaceDependency(pkg, workspaceNames) {
|
|
1356
|
-
for (const field of workspaceDependencyFields) {
|
|
1357
|
-
const dependencies = recordProperty(pkg, field);
|
|
1358
|
-
if (!dependencies) {
|
|
1359
|
-
continue;
|
|
1360
|
-
}
|
|
1361
|
-
for (const name of Object.keys(dependencies)) {
|
|
1362
|
-
if (workspaceNames.has(name)) {
|
|
1363
|
-
return true;
|
|
1364
|
-
}
|
|
1365
|
-
}
|
|
1366
|
-
}
|
|
1367
|
-
return false;
|
|
1368
|
-
}
|
|
1369
|
-
function isSafeNxScriptCommand(command) {
|
|
1370
|
-
const trimmed = command.trim();
|
|
1371
|
-
return (/^bun\s+test(?:\s|$)/.test(trimmed) ||
|
|
1372
|
-
/^tsc-bun-test(?:\s|$)/.test(trimmed) ||
|
|
1373
|
-
/^vitest(?:\s|$)/.test(trimmed) ||
|
|
1374
|
-
/^tsc\s+(?:--build|--noEmit)(?:\s|$)/.test(trimmed) ||
|
|
1375
|
-
/^tsdown(?:\s|$)/.test(trimmed) ||
|
|
1376
|
-
/^vite\s+(?:build|dev|preview)(?:\s|$)/.test(trimmed) ||
|
|
1377
|
-
/^astro\s+(?:build|dev|preview|check)(?:\s|$)/.test(trimmed) ||
|
|
1378
|
-
/^zig\s+build(?:\s|$)/.test(trimmed) ||
|
|
1379
|
-
/^bun\s+[./\w-]*build[\w.-]*\.ts(?:\s|$)/.test(trimmed) ||
|
|
1380
|
-
/(?:^|\s)(?:bench|benchmark)(?:\s|$)/.test(trimmed) ||
|
|
1381
|
-
/^wrangler\s+build(?:\s|$)/.test(trimmed));
|
|
1382
|
-
}
|
|
1383
|
-
function isBlockedScriptCommand(scriptName, command) {
|
|
1384
|
-
if (/^(?:deploy|db|release|sync|subtree|publish|pack)(?::|$)/.test(scriptName)) {
|
|
1385
|
-
return true;
|
|
1386
|
-
}
|
|
1387
|
-
const trimmed = parseEnvPrefixedCommand(command).command;
|
|
1388
|
-
return /^(?:deploy|db|release|sync|subtree|publish|pack)(?:\s|$)/.test(trimmed) || trimmed === 'astro';
|
|
1389
|
-
}
|
|
1390
|
-
function parseEnvPrefixedCommand(command) {
|
|
1391
|
-
const env = {};
|
|
1392
|
-
let rest = command.trimStart();
|
|
1393
|
-
while (true) {
|
|
1394
|
-
const match = /^([A-Za-z_][A-Za-z0-9_]*)=/.exec(rest);
|
|
1395
|
-
if (!match?.[1]) {
|
|
1396
|
-
return { command: rest.trim(), env };
|
|
1397
|
-
}
|
|
1398
|
-
let index = match[0].length;
|
|
1399
|
-
let value = '';
|
|
1400
|
-
const quote = rest[index];
|
|
1401
|
-
if (quote === '"' || quote === "'") {
|
|
1402
|
-
index += 1;
|
|
1403
|
-
const end = rest.indexOf(quote, index);
|
|
1404
|
-
if (end === -1) {
|
|
1405
|
-
return { command: command.trim(), env: {} };
|
|
1406
|
-
}
|
|
1407
|
-
value = rest.slice(index, end);
|
|
1408
|
-
index = end + 1;
|
|
1409
|
-
}
|
|
1410
|
-
else {
|
|
1411
|
-
const end = rest.slice(index).search(/\s/);
|
|
1412
|
-
const valueEnd = end === -1 ? rest.length : index + end;
|
|
1413
|
-
value = rest.slice(index, valueEnd);
|
|
1414
|
-
index = valueEnd;
|
|
1415
|
-
}
|
|
1416
|
-
if (index < rest.length && !/\s/.test(rest[index] ?? '')) {
|
|
1417
|
-
return { command: command.trim(), env: {} };
|
|
1418
|
-
}
|
|
1419
|
-
env[match[1]] = value;
|
|
1420
|
-
rest = rest.slice(index).trimStart();
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
function isContinuousTarget(targetName, command) {
|
|
1424
|
-
return (/(?:^|:|-)(?:dev|serve|preview|watch)(?:$|:|-)/.test(targetName) ||
|
|
1425
|
-
/(?:^|\s)(?:dev|serve|preview|--watch|-w)(?:\s|$)/.test(command));
|
|
395
|
+
return unscopedPackageName(packageName);
|
|
1426
396
|
}
|
|
1427
|
-
function
|
|
1428
|
-
|
|
397
|
+
function npmScope(packageName) {
|
|
398
|
+
const match = /^(@[^/]+)\//.exec(packageName);
|
|
399
|
+
return match?.[1] ?? null;
|
|
1429
400
|
}
|
|
1430
|
-
function
|
|
1431
|
-
|
|
1432
|
-
if (!match?.[1] || !match[2]) {
|
|
1433
|
-
return null;
|
|
1434
|
-
}
|
|
1435
|
-
return { projectName: match[1], targetName: match[2] };
|
|
401
|
+
function unscopedPackageName(packageName) {
|
|
402
|
+
return packageName.startsWith('@') ? packageName.slice(packageName.indexOf('/') + 1) : packageName;
|
|
1436
403
|
}
|
|
1437
404
|
function recordKeysAreSorted(record) {
|
|
1438
405
|
const keys = Object.keys(record);
|
|
@@ -1451,37 +418,6 @@ function sortRecordInPlace(record) {
|
|
|
1451
418
|
}
|
|
1452
419
|
return true;
|
|
1453
420
|
}
|
|
1454
|
-
function isScriptRunnerCommand(command, scriptName) {
|
|
1455
|
-
if (!command) {
|
|
1456
|
-
return false;
|
|
1457
|
-
}
|
|
1458
|
-
const escaped = escapeRegex(scriptName);
|
|
1459
|
-
return new RegExp(`^(?:bun|npm)\\s+run\\s+${escaped}(?:\\s|$)`).test(command.trim());
|
|
1460
|
-
}
|
|
1461
|
-
function escapeRegex(value) {
|
|
1462
|
-
return value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
1463
|
-
}
|
|
1464
|
-
function suggestNxProjectName(rootPackageName, packageName) {
|
|
1465
|
-
const rootScope = npmScope(rootPackageName);
|
|
1466
|
-
if (!rootScope || npmScope(packageName) !== rootScope) {
|
|
1467
|
-
return null;
|
|
1468
|
-
}
|
|
1469
|
-
return unscopedPackageName(packageName);
|
|
1470
|
-
}
|
|
1471
|
-
function npmScope(packageName) {
|
|
1472
|
-
const match = /^(@[^/]+)\//.exec(packageName);
|
|
1473
|
-
return match?.[1] ?? null;
|
|
1474
|
-
}
|
|
1475
|
-
function unscopedPackageName(packageName) {
|
|
1476
|
-
return packageName.startsWith('@') ? packageName.slice(packageName.indexOf('/') + 1) : packageName;
|
|
1477
|
-
}
|
|
1478
|
-
function setBooleanProperty(record, key, value) {
|
|
1479
|
-
if (record[key] === value) {
|
|
1480
|
-
return false;
|
|
1481
|
-
}
|
|
1482
|
-
record[key] = value;
|
|
1483
|
-
return true;
|
|
1484
|
-
}
|
|
1485
421
|
function normalizeExportConditionOrder(value) {
|
|
1486
422
|
if (!isRecord(value)) {
|
|
1487
423
|
return false;
|