@smoothbricks/nx-plugin 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31 -22
- package/dist/package-target-policy.d.ts +3 -2
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +63 -20
- package/dist/workspace-config-policy.d.ts +4 -1
- package/dist/workspace-config-policy.d.ts.map +1 -1
- package/dist/workspace-config-policy.js +3 -1
- package/package.json +1 -1
- package/src/index.test.ts +34 -13
- package/src/index.ts +34 -23
- package/src/package-target-policy.test.ts +62 -0
- package/src/package-target-policy.ts +85 -23
- package/src/workspace-config-policy.test.ts +23 -0
- package/src/workspace-config-policy.ts +5 -2
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAuB,aAAa,EAAuB,MAAM,0BAA0B,CAAC;AAyDxG,eAAO,MAAM,aAAa,EAAE,aAsB3B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -2,11 +2,14 @@ import { existsSync } from 'node:fs';
|
|
|
2
2
|
import { readFile } from 'node:fs/promises';
|
|
3
3
|
import { dirname, join } from 'node:path';
|
|
4
4
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
5
|
-
import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
|
|
5
|
+
import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
6
6
|
const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
|
|
7
7
|
const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
|
|
8
8
|
const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
|
|
9
|
-
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|
|
|
9
|
+
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
10
|
+
const ZIG_WASM_OUTPUTS = ['{projectRoot}/dist/**/*.wasm'];
|
|
11
|
+
const ZIG_NATIVE_OUTPUTS = ['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}'];
|
|
12
|
+
const ZIG_GENERIC_OUTPUTS = ['{projectRoot}/dist/**/*.{wasm,node,dylib,so,dll,a}'];
|
|
10
13
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
11
14
|
'{workspaceRoot}/package.json',
|
|
12
15
|
'{workspaceRoot}/bun.lock',
|
|
@@ -76,7 +79,9 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
76
79
|
const targets = {};
|
|
77
80
|
const validationTargets = [];
|
|
78
81
|
const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
|
|
79
|
-
|
|
82
|
+
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
83
|
+
let hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
|
|
84
|
+
let hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
80
85
|
if (hasLibTsconfig) {
|
|
81
86
|
// Official Nx target inference is disabled because its compiler surface only
|
|
82
87
|
// supports tsc/tsgo. Smoo owns the complete transformer-aware ttsc targets.
|
|
@@ -84,10 +89,7 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
84
89
|
executor: 'nx:run-commands',
|
|
85
90
|
cache: true,
|
|
86
91
|
inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
|
|
87
|
-
outputs: [
|
|
88
|
-
'{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
|
|
89
|
-
'{projectRoot}/dist/.build.tsbuildinfo',
|
|
90
|
-
],
|
|
92
|
+
outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
|
|
91
93
|
dependsOn: ['^tsc-js'],
|
|
92
94
|
options: {
|
|
93
95
|
command: 'ttsc -p tsconfig.lib.json --emit',
|
|
@@ -206,7 +208,8 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
206
208
|
},
|
|
207
209
|
},
|
|
208
210
|
};
|
|
209
|
-
|
|
211
|
+
hasOrdinaryBuildOutputTarget = true;
|
|
212
|
+
hasAnyBuildOutputTarget = true;
|
|
210
213
|
}
|
|
211
214
|
}
|
|
212
215
|
const zigSteps = await readZigSteps(absoluteProjectRoot, projectRoot);
|
|
@@ -216,27 +219,23 @@ async function createProjectTargets(packageJsonPath, workspaceRoot) {
|
|
|
216
219
|
executor: 'nx:run-commands',
|
|
217
220
|
cache: true,
|
|
218
221
|
inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
|
|
219
|
-
outputs:
|
|
220
|
-
'{projectRoot}/dist/**/*.wasm',
|
|
221
|
-
'{projectRoot}/dist/**/*.node',
|
|
222
|
-
'{projectRoot}/dist/**/*.dylib',
|
|
223
|
-
'{projectRoot}/dist/**/*.so',
|
|
224
|
-
'{projectRoot}/dist/**/*.dll',
|
|
225
|
-
'{projectRoot}/dist/**/*.a',
|
|
226
|
-
],
|
|
222
|
+
outputs: zigOutputsForStep(step),
|
|
227
223
|
options: {
|
|
228
224
|
command: `zig build ${step}`,
|
|
229
225
|
cwd: projectRoot,
|
|
230
226
|
},
|
|
231
227
|
};
|
|
232
|
-
|
|
228
|
+
hasOrdinaryBuildOutputTarget = true;
|
|
229
|
+
hasAnyBuildOutputTarget = true;
|
|
233
230
|
}
|
|
234
|
-
if (
|
|
231
|
+
if (hasOrdinaryBuildOutputTarget) {
|
|
235
232
|
targets.build = {
|
|
236
233
|
executor: 'nx:noop',
|
|
237
234
|
cache: true,
|
|
238
235
|
dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
|
|
239
236
|
};
|
|
237
|
+
}
|
|
238
|
+
if (hasAnyBuildOutputTarget) {
|
|
240
239
|
targets.clean = {
|
|
241
240
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
242
241
|
cache: false,
|
|
@@ -326,12 +325,22 @@ function parseEnvPrefixedCommand(command) {
|
|
|
326
325
|
function isRecord(value) {
|
|
327
326
|
return value !== null && typeof value === 'object';
|
|
328
327
|
}
|
|
329
|
-
function
|
|
328
|
+
function classifyPackageLocalBuildOutputs(packageJson) {
|
|
330
329
|
const targets = packageJson.nx?.targets;
|
|
331
|
-
|
|
332
|
-
|
|
330
|
+
const targetNames = isRecord(targets) ? Object.keys(targets) : [];
|
|
331
|
+
return {
|
|
332
|
+
ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
|
|
333
|
+
platform: targetNames.some((targetName) => PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))),
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
function zigOutputsForStep(step) {
|
|
337
|
+
if (step.endsWith('wasm')) {
|
|
338
|
+
return ZIG_WASM_OUTPUTS;
|
|
339
|
+
}
|
|
340
|
+
if (step.endsWith('native')) {
|
|
341
|
+
return ZIG_NATIVE_OUTPUTS;
|
|
333
342
|
}
|
|
334
|
-
return
|
|
343
|
+
return ZIG_GENERIC_OUTPUTS;
|
|
335
344
|
}
|
|
336
345
|
async function readCargoWorkspace(absoluteProjectRoot) {
|
|
337
346
|
const cargoTomlPath = join(absoluteProjectRoot, 'Cargo.toml');
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import { type Tree } from 'nx/src/devkit-exports.js';
|
|
2
|
-
import type
|
|
2
|
+
import { type NxPolicyIssue } from './workspace-config-policy.js';
|
|
3
|
+
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
3
4
|
export type { NxPolicyIssue };
|
|
4
5
|
export interface ResolvedProjectTargets {
|
|
5
6
|
targets: ReadonlySet<string>;
|
|
6
7
|
buildDependsOn?: readonly string[];
|
|
8
|
+
targetDependencies?: ReadonlyMap<string, readonly string[]>;
|
|
7
9
|
targetExecutors?: ReadonlyMap<string, string>;
|
|
8
10
|
targetScripts?: ReadonlyMap<string, string>;
|
|
9
11
|
}
|
|
10
12
|
export interface PackageTargetPolicyOptions {
|
|
11
13
|
resolvedTargetsByProject?: ReadonlyMap<string, ReadonlySet<string> | ResolvedProjectTargets>;
|
|
12
14
|
}
|
|
13
|
-
export declare const BUILD_OUTPUT_DEPENDENCIES: string[];
|
|
14
15
|
export declare function packageNxProjectName(pkg: Record<string, unknown>): string | null;
|
|
15
16
|
export declare function nxRunAlias(projectName: string, targetName: string, continuous: boolean, command?: string | null): string;
|
|
16
17
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAGxF,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"package-target-policy.d.ts","sourceRoot":"","sources":["../src/package-target-policy.ts"],"names":[],"mappings":"AAGA,OAAO,EAAyB,KAAK,IAAI,EAAc,MAAM,0BAA0B,CAAC;AAGxF,OAAO,EAIL,KAAK,aAAa,EACnB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAChG,YAAY,EAAE,aAAa,EAAE,CAAC;AAE9B,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC7B,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACnC,kBAAkB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC;IAC5D,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,wBAAwB,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,sBAAsB,CAAC,CAAC;CAC9F;AA0HD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,IAAI,CAGhF;AA2JD,wBAAgB,UAAU,CACxB,WAAW,EAAE,MAAM,EACnB,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,OAAO,EACnB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACtB,MAAM,CAMR;AAupBD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAqBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA4B1G;AAoJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACpC,aAAa,EAAE,CAEjB;AAED,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,EACnC,OAAO,GAAE;IAAE,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GACtD,OAAO,CAMT;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAoBhH;AAED,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA6BxG"}
|
|
@@ -2,18 +2,8 @@ import { existsSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { getProjects, readJson, updateJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
'*-web',
|
|
8
|
-
'*-html',
|
|
9
|
-
'*-css',
|
|
10
|
-
'*-ios',
|
|
11
|
-
'*-android',
|
|
12
|
-
'*-native',
|
|
13
|
-
'*-napi',
|
|
14
|
-
'*-bun',
|
|
15
|
-
'*-wasm',
|
|
16
|
-
];
|
|
5
|
+
import { BUILD_OUTPUT_DEPENDENCIES, LINUX_PLATFORM_TARGET_GLOBS, MACOS_PLATFORM_TARGET_GLOBS, } from './workspace-config-policy.js';
|
|
6
|
+
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
17
7
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
18
8
|
function isRecord(value) {
|
|
19
9
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
@@ -154,7 +144,7 @@ function targetExistsInResolvedProject(targetName, resolvedTargets) {
|
|
|
154
144
|
return resolvedProjectTargetNames(resolvedTargets)?.has(targetName) === true;
|
|
155
145
|
}
|
|
156
146
|
function isBuildOutputDependencyPattern(dependency) {
|
|
157
|
-
return BUILD_OUTPUT_DEPENDENCIES.
|
|
147
|
+
return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
|
|
158
148
|
}
|
|
159
149
|
function expectedTargetDependencies(targetName) {
|
|
160
150
|
return targetName === 'preview' ? ['build'] : ['^build'];
|
|
@@ -460,13 +450,13 @@ function validateBuildZigPolicy(root, packagePath) {
|
|
|
460
450
|
{ path: join(root, packagePath), message: `${packagePath}/build.zig must define at least one b.step(...) target` },
|
|
461
451
|
];
|
|
462
452
|
}
|
|
463
|
-
function validateExplicitNxTargets(pkg, packagePath,
|
|
453
|
+
function validateExplicitNxTargets(pkg, packagePath, resolvedProject) {
|
|
454
|
+
const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
|
|
464
455
|
const nx = recordProperty(pkg, 'nx');
|
|
465
456
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
466
457
|
if (!targets) {
|
|
467
|
-
return
|
|
458
|
+
return issues;
|
|
468
459
|
}
|
|
469
|
-
const issues = [];
|
|
470
460
|
for (const [targetName, rawTarget] of Object.entries(targets)) {
|
|
471
461
|
if (targetName.includes(':')) {
|
|
472
462
|
issues.push({
|
|
@@ -478,7 +468,61 @@ function validateExplicitNxTargets(pkg, packagePath, resolvedTargets) {
|
|
|
478
468
|
if (!isRecord(rawTarget)) {
|
|
479
469
|
continue;
|
|
480
470
|
}
|
|
481
|
-
issues.push(...validateTargetDependencies(rawTarget, `${packagePath}: nx.targets.${targetName}`,
|
|
471
|
+
issues.push(...validateTargetDependencies(rawTarget, `${packagePath}: nx.targets.${targetName}`, resolvedProjectTargetNames(resolvedProject)));
|
|
472
|
+
}
|
|
473
|
+
return issues;
|
|
474
|
+
}
|
|
475
|
+
function platformTargetFamily(targetName) {
|
|
476
|
+
if (MACOS_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
477
|
+
return 'macos';
|
|
478
|
+
}
|
|
479
|
+
if (LINUX_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
480
|
+
return 'linux';
|
|
481
|
+
}
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
function matchingResolvedTargets(dependency, targets) {
|
|
485
|
+
if (!dependency.startsWith('*')) {
|
|
486
|
+
return targets.has(dependency) ? [dependency] : [];
|
|
487
|
+
}
|
|
488
|
+
const suffix = dependency.slice(1);
|
|
489
|
+
return [...targets].filter((targetName) => targetName.endsWith(suffix));
|
|
490
|
+
}
|
|
491
|
+
function validatePlatformTargetDependencies(packagePath, resolvedProject) {
|
|
492
|
+
if (!isResolvedProjectTargets(resolvedProject) || !resolvedProject.targetDependencies) {
|
|
493
|
+
return [];
|
|
494
|
+
}
|
|
495
|
+
const issues = [];
|
|
496
|
+
for (const platformTarget of resolvedProject.targets) {
|
|
497
|
+
const family = platformTargetFamily(platformTarget);
|
|
498
|
+
if (!family) {
|
|
499
|
+
continue;
|
|
500
|
+
}
|
|
501
|
+
const visited = new Set();
|
|
502
|
+
const pending = [platformTarget];
|
|
503
|
+
while (pending.length > 0) {
|
|
504
|
+
const targetName = pending.pop();
|
|
505
|
+
if (!targetName || visited.has(targetName)) {
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
visited.add(targetName);
|
|
509
|
+
for (const dependency of resolvedProject.targetDependencies.get(targetName) ?? []) {
|
|
510
|
+
if (dependency.startsWith('^')) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
for (const resolvedDependency of matchingResolvedTargets(dependency, resolvedProject.targets)) {
|
|
514
|
+
if (platformTargetFamily(resolvedDependency) !== family) {
|
|
515
|
+
issues.push({
|
|
516
|
+
path: packagePath,
|
|
517
|
+
message: `${packagePath}: platform target ${platformTarget} dependency closure references ` +
|
|
518
|
+
`non-${family} sibling target ${resolvedDependency} via ${targetName}`,
|
|
519
|
+
});
|
|
520
|
+
continue;
|
|
521
|
+
}
|
|
522
|
+
pending.push(resolvedDependency);
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
482
526
|
}
|
|
483
527
|
return issues;
|
|
484
528
|
}
|
|
@@ -749,7 +793,7 @@ export function checkPackageTargetPolicyTree(tree, options = {}) {
|
|
|
749
793
|
const packagePath = config.root;
|
|
750
794
|
const resolvedProject = options.resolvedTargetsByProject?.get(projectName);
|
|
751
795
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
752
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath,
|
|
796
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
753
797
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
754
798
|
issues.push(...validateBuildZigPolicyTree(tree, packagePath));
|
|
755
799
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
@@ -933,8 +977,7 @@ export function checkPackageTargetPolicy(root, options = {}) {
|
|
|
933
977
|
const packagePath = packagePathFromJsonPath(root, packageJsonPath);
|
|
934
978
|
const projectName = packageNxProjectName(pkg);
|
|
935
979
|
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
936
|
-
|
|
937
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedTargets));
|
|
980
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
938
981
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
939
982
|
issues.push(...validateBuildZigPolicy(root, packagePath));
|
|
940
983
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
@@ -3,7 +3,10 @@ export interface NxPolicyIssue {
|
|
|
3
3
|
path: string;
|
|
4
4
|
message: string;
|
|
5
5
|
}
|
|
6
|
-
export declare const BUILD_OUTPUT_DEPENDENCIES:
|
|
6
|
+
export declare const BUILD_OUTPUT_DEPENDENCIES: readonly ['*-js', '*-web', '*-html', '*-css', '*-android', '*-native', '*-napi', '*-bun', '*-wasm'];
|
|
7
|
+
export declare const MACOS_PLATFORM_TARGET_GLOBS: readonly ['*-macos', '*-ios'];
|
|
8
|
+
export declare const LINUX_PLATFORM_TARGET_GLOBS: readonly ['*-linux'];
|
|
9
|
+
export declare const PLATFORM_TARGET_GLOBS: readonly ["*-macos", "*-ios", "*-linux"];
|
|
7
10
|
/**
|
|
8
11
|
* Check workspace config policy on an in-memory nx.json object.
|
|
9
12
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,
|
|
1
|
+
{"version":3,"file":"workspace-config-policy.d.ts","sourceRoot":"","sources":["../src/workspace-config-policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,yBAAyB,YACpC,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,WAAW,EACX,UAAU,EACV,QAAQ,EACR,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,eAAO,MAAM,2BAA2B,YAAI,SAAS,EAAE,OAAO,CAAU,CAAC;AACzE,eAAO,MAAM,2BAA2B,YAAI,SAAS,CAAU,CAAC;AAChE,eAAO,MAAM,qBAAqB,0CAA4E,CAAC;AAe/G;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,aAAa,EAAE,CA+CrF;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAa7E;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,EAAE,CAKpE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAU5D;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,EAAE,CAYxE;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAWhE"}
|
|
@@ -6,13 +6,15 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
|
6
6
|
'*-web',
|
|
7
7
|
'*-html',
|
|
8
8
|
'*-css',
|
|
9
|
-
'*-ios',
|
|
10
9
|
'*-android',
|
|
11
10
|
'*-native',
|
|
12
11
|
'*-napi',
|
|
13
12
|
'*-bun',
|
|
14
13
|
'*-wasm',
|
|
15
14
|
];
|
|
15
|
+
export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'];
|
|
16
|
+
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'];
|
|
17
|
+
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS];
|
|
16
18
|
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
17
19
|
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|
|
18
20
|
const cleanOutputsExecutor = '@smoothbricks/nx-plugin:clean-outputs';
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -5,21 +5,10 @@ import { dirname, join } from 'node:path';
|
|
|
5
5
|
|
|
6
6
|
import type { CreateNodesContextV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
7
7
|
import { createNodesV2 } from './index.js';
|
|
8
|
+
import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
|
|
8
9
|
|
|
9
10
|
const [, inferTargets] = createNodesV2;
|
|
10
|
-
const buildOutputDependencies = [
|
|
11
|
-
'^build',
|
|
12
|
-
'*-js',
|
|
13
|
-
'*-web',
|
|
14
|
-
'*-html',
|
|
15
|
-
'*-css',
|
|
16
|
-
'*-ios',
|
|
17
|
-
'*-android',
|
|
18
|
-
'*-native',
|
|
19
|
-
'*-napi',
|
|
20
|
-
'*-bun',
|
|
21
|
-
'*-wasm',
|
|
22
|
-
];
|
|
11
|
+
const buildOutputDependencies = ['^build', ...BUILD_OUTPUT_DEPENDENCIES];
|
|
23
12
|
|
|
24
13
|
describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
25
14
|
it('names standalone package projects from package metadata', async () => {
|
|
@@ -71,6 +60,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
71
60
|
...toolchainInputs,
|
|
72
61
|
'{projectRoot}/tsconfig.lib.json',
|
|
73
62
|
]);
|
|
63
|
+
expect(targets['tsc-js']?.outputs).toEqual(['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}']);
|
|
74
64
|
expect(targets.typecheck?.options).toMatchObject({
|
|
75
65
|
command: 'ttsc -p tsconfig.lib.json --noEmit',
|
|
76
66
|
cwd: 'packages/example',
|
|
@@ -171,6 +161,8 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
171
161
|
expect(targets.build?.cache).toBe(true);
|
|
172
162
|
expect(targets['zig-wasm']?.cache).toBe(true);
|
|
173
163
|
expect(targets['zig-native']?.cache).toBe(true);
|
|
164
|
+
expect(targets['zig-wasm']?.outputs).toEqual(['{projectRoot}/dist/**/*.wasm']);
|
|
165
|
+
expect(targets['zig-native']?.outputs).toEqual(['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}']);
|
|
174
166
|
expect(targets['zig-wasm']?.options).toEqual({
|
|
175
167
|
command: 'zig build wasm',
|
|
176
168
|
cwd: 'packages/ziggy',
|
|
@@ -204,6 +196,35 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
204
196
|
}
|
|
205
197
|
});
|
|
206
198
|
|
|
199
|
+
it('keeps platform-only output families out of the ordinary aggregate build', async () => {
|
|
200
|
+
const workspace = await createWorkspace();
|
|
201
|
+
try {
|
|
202
|
+
await workspace.write(
|
|
203
|
+
'packages/platform/package.json',
|
|
204
|
+
JSON.stringify({
|
|
205
|
+
name: 'platform',
|
|
206
|
+
nx: {
|
|
207
|
+
targets: {
|
|
208
|
+
'bundle-ios': { executor: 'nx:run-commands' },
|
|
209
|
+
'bundle-macos': { executor: 'nx:run-commands' },
|
|
210
|
+
'bundle-linux': { executor: 'nx:run-commands' },
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
}),
|
|
214
|
+
);
|
|
215
|
+
|
|
216
|
+
const targets = await inferProjectTargets(workspace, 'packages/platform/package.json');
|
|
217
|
+
|
|
218
|
+
expect(targets.build).toBeUndefined();
|
|
219
|
+
expect(targets.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
220
|
+
expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-ios');
|
|
221
|
+
expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-macos');
|
|
222
|
+
expect(BUILD_OUTPUT_DEPENDENCIES).not.toContain('*-linux');
|
|
223
|
+
} finally {
|
|
224
|
+
await workspace.cleanup();
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
|
|
207
228
|
it('infers cargo workspace targets including explicitly named wasm crate builds', async () => {
|
|
208
229
|
const workspace = await createWorkspace();
|
|
209
230
|
try {
|
package/src/index.ts
CHANGED
|
@@ -5,12 +5,15 @@ import { dirname, join } from 'node:path';
|
|
|
5
5
|
import type { CreateNodesResultV2, CreateNodesV2, TargetConfiguration } from 'nx/src/devkit-exports.js';
|
|
6
6
|
import { AggregateCreateNodesError } from 'nx/src/project-graph/error-types.js';
|
|
7
7
|
|
|
8
|
-
import { BUILD_OUTPUT_DEPENDENCIES } from './workspace-config-policy.js';
|
|
8
|
+
import { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
9
9
|
|
|
10
10
|
const RESERVED_ZIG_STEPS = new Set(['all', 'clean', 'install', 'test']);
|
|
11
11
|
const ZIG_STEP_PATTERN = /\bb\.step\(\s*["']([^"']+)["']\s*,/g;
|
|
12
12
|
const VALID_ZIG_STEP_NAME = /^[A-Za-z0-9_-]+$/;
|
|
13
|
-
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|
|
|
13
|
+
const BUILD_OUTPUT_TARGET_PATTERN = /-(?:js|web|html|css|android|native|napi|bun|wasm)$/;
|
|
14
|
+
const ZIG_WASM_OUTPUTS = ['{projectRoot}/dist/**/*.wasm'];
|
|
15
|
+
const ZIG_NATIVE_OUTPUTS = ['{projectRoot}/dist/**/*.{node,dylib,so,dll,a}'];
|
|
16
|
+
const ZIG_GENERIC_OUTPUTS = ['{projectRoot}/dist/**/*.{wasm,node,dylib,so,dll,a}'];
|
|
14
17
|
const TYPESCRIPT_TOOLCHAIN_INPUTS = [
|
|
15
18
|
'{workspaceRoot}/package.json',
|
|
16
19
|
'{workspaceRoot}/bun.lock',
|
|
@@ -98,7 +101,9 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
|
|
|
98
101
|
const targets: Record<string, TargetConfiguration> = {};
|
|
99
102
|
const validationTargets: string[] = [];
|
|
100
103
|
const hasLibTsconfig = existsSync(join(absoluteProjectRoot, 'tsconfig.lib.json'));
|
|
101
|
-
|
|
104
|
+
const packageLocalBuildOutputs = classifyPackageLocalBuildOutputs(packageJson);
|
|
105
|
+
let hasOrdinaryBuildOutputTarget = hasLibTsconfig || packageLocalBuildOutputs.ordinary;
|
|
106
|
+
let hasAnyBuildOutputTarget = hasOrdinaryBuildOutputTarget || packageLocalBuildOutputs.platform;
|
|
102
107
|
|
|
103
108
|
if (hasLibTsconfig) {
|
|
104
109
|
// Official Nx target inference is disabled because its compiler surface only
|
|
@@ -107,10 +112,7 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
|
|
|
107
112
|
executor: 'nx:run-commands',
|
|
108
113
|
cache: true,
|
|
109
114
|
inputs: ['production', '^production', ...TYPESCRIPT_TOOLCHAIN_INPUTS, '{projectRoot}/tsconfig.lib.json'],
|
|
110
|
-
outputs: [
|
|
111
|
-
'{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}',
|
|
112
|
-
'{projectRoot}/dist/.build.tsbuildinfo',
|
|
113
|
-
],
|
|
115
|
+
outputs: ['{projectRoot}/dist/**/*.{js,cjs,mjs,jsx,d.ts,d.cts,d.mts}{,.map}'],
|
|
114
116
|
dependsOn: ['^tsc-js'],
|
|
115
117
|
options: {
|
|
116
118
|
command: 'ttsc -p tsconfig.lib.json --emit',
|
|
@@ -230,7 +232,8 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
|
|
|
230
232
|
},
|
|
231
233
|
},
|
|
232
234
|
};
|
|
233
|
-
|
|
235
|
+
hasOrdinaryBuildOutputTarget = true;
|
|
236
|
+
hasAnyBuildOutputTarget = true;
|
|
234
237
|
}
|
|
235
238
|
}
|
|
236
239
|
|
|
@@ -241,28 +244,24 @@ async function createProjectTargets(packageJsonPath: string, workspaceRoot: stri
|
|
|
241
244
|
executor: 'nx:run-commands',
|
|
242
245
|
cache: true,
|
|
243
246
|
inputs: ['{projectRoot}/src/**/*.zig', '{projectRoot}/build.zig', '{projectRoot}/build.zig.zon'],
|
|
244
|
-
outputs:
|
|
245
|
-
'{projectRoot}/dist/**/*.wasm',
|
|
246
|
-
'{projectRoot}/dist/**/*.node',
|
|
247
|
-
'{projectRoot}/dist/**/*.dylib',
|
|
248
|
-
'{projectRoot}/dist/**/*.so',
|
|
249
|
-
'{projectRoot}/dist/**/*.dll',
|
|
250
|
-
'{projectRoot}/dist/**/*.a',
|
|
251
|
-
],
|
|
247
|
+
outputs: zigOutputsForStep(step),
|
|
252
248
|
options: {
|
|
253
249
|
command: `zig build ${step}`,
|
|
254
250
|
cwd: projectRoot,
|
|
255
251
|
},
|
|
256
252
|
};
|
|
257
|
-
|
|
253
|
+
hasOrdinaryBuildOutputTarget = true;
|
|
254
|
+
hasAnyBuildOutputTarget = true;
|
|
258
255
|
}
|
|
259
256
|
|
|
260
|
-
if (
|
|
257
|
+
if (hasOrdinaryBuildOutputTarget) {
|
|
261
258
|
targets.build = {
|
|
262
259
|
executor: 'nx:noop',
|
|
263
260
|
cache: true,
|
|
264
261
|
dependsOn: ['^build', ...BUILD_OUTPUT_DEPENDENCIES],
|
|
265
262
|
};
|
|
263
|
+
}
|
|
264
|
+
if (hasAnyBuildOutputTarget) {
|
|
266
265
|
targets.clean = {
|
|
267
266
|
executor: '@smoothbricks/nx-plugin:clean-outputs',
|
|
268
267
|
cache: false,
|
|
@@ -367,13 +366,25 @@ function isRecord(value: unknown): value is Record<string, unknown> {
|
|
|
367
366
|
return value !== null && typeof value === 'object';
|
|
368
367
|
}
|
|
369
368
|
|
|
370
|
-
function
|
|
369
|
+
function classifyPackageLocalBuildOutputs(packageJson: PackageJson): { ordinary: boolean; platform: boolean } {
|
|
371
370
|
const targets = packageJson.nx?.targets;
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
371
|
+
const targetNames = isRecord(targets) ? Object.keys(targets) : [];
|
|
372
|
+
return {
|
|
373
|
+
ordinary: targetNames.some((targetName) => BUILD_OUTPUT_TARGET_PATTERN.test(targetName)),
|
|
374
|
+
platform: targetNames.some((targetName) =>
|
|
375
|
+
PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1))),
|
|
376
|
+
),
|
|
377
|
+
};
|
|
378
|
+
}
|
|
375
379
|
|
|
376
|
-
|
|
380
|
+
function zigOutputsForStep(step: string): string[] {
|
|
381
|
+
if (step.endsWith('wasm')) {
|
|
382
|
+
return ZIG_WASM_OUTPUTS;
|
|
383
|
+
}
|
|
384
|
+
if (step.endsWith('native')) {
|
|
385
|
+
return ZIG_NATIVE_OUTPUTS;
|
|
386
|
+
}
|
|
387
|
+
return ZIG_GENERIC_OUTPUTS;
|
|
377
388
|
}
|
|
378
389
|
|
|
379
390
|
interface CargoWorkspace {
|
|
@@ -708,6 +708,68 @@ describe('checkPackageTargetPolicyTree', () => {
|
|
|
708
708
|
expect(buildIssues).toEqual([]);
|
|
709
709
|
});
|
|
710
710
|
|
|
711
|
+
it('accepts platform-only target families without an ordinary build aggregate', () => {
|
|
712
|
+
addProject(tree, 'native', 'packages/native');
|
|
713
|
+
writeJsonFile(tree, 'packages/native/package.json', {
|
|
714
|
+
name: '@scope/native',
|
|
715
|
+
nx: { name: 'native' },
|
|
716
|
+
});
|
|
717
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
718
|
+
[
|
|
719
|
+
'native',
|
|
720
|
+
{
|
|
721
|
+
targets: new Set(['bundle-ios', 'prepare-macos', 'bundle-linux']),
|
|
722
|
+
targetDependencies: new Map([
|
|
723
|
+
['bundle-ios', ['prepare-macos', '^build']],
|
|
724
|
+
['prepare-macos', []],
|
|
725
|
+
['bundle-linux', ['^build']],
|
|
726
|
+
]),
|
|
727
|
+
},
|
|
728
|
+
],
|
|
729
|
+
]);
|
|
730
|
+
|
|
731
|
+
expect(checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject })).toEqual([]);
|
|
732
|
+
});
|
|
733
|
+
|
|
734
|
+
it('rejects cross-family dependencies in resolved platform target closures', () => {
|
|
735
|
+
addProject(tree, 'native', 'packages/native');
|
|
736
|
+
writeJsonFile(tree, 'packages/native/package.json', {
|
|
737
|
+
name: '@scope/native',
|
|
738
|
+
nx: { name: 'native' },
|
|
739
|
+
});
|
|
740
|
+
const resolvedTargetsByProject = new Map<string, ResolvedProjectTargets>([
|
|
741
|
+
[
|
|
742
|
+
'native',
|
|
743
|
+
{
|
|
744
|
+
targets: new Set(['bundle-ios', 'prepare-macos', 'compile-js', 'bundle-linux']),
|
|
745
|
+
targetDependencies: new Map([
|
|
746
|
+
['bundle-ios', ['prepare-macos', '^build']],
|
|
747
|
+
['prepare-macos', ['compile-js']],
|
|
748
|
+
['bundle-linux', ['bundle-ios']],
|
|
749
|
+
]),
|
|
750
|
+
},
|
|
751
|
+
],
|
|
752
|
+
]);
|
|
753
|
+
|
|
754
|
+
const issues = checkPackageTargetPolicyTree(tree, { resolvedTargetsByProject });
|
|
755
|
+
|
|
756
|
+
expect(
|
|
757
|
+
issues.some(
|
|
758
|
+
(issue) =>
|
|
759
|
+
issue.message.includes('platform target bundle-ios dependency closure') &&
|
|
760
|
+
issue.message.includes('non-macos sibling target compile-js'),
|
|
761
|
+
),
|
|
762
|
+
).toBe(true);
|
|
763
|
+
expect(
|
|
764
|
+
issues.some(
|
|
765
|
+
(issue) =>
|
|
766
|
+
issue.message.includes('platform target bundle-linux dependency closure') &&
|
|
767
|
+
issue.message.includes('non-linux sibling target bundle-ios'),
|
|
768
|
+
),
|
|
769
|
+
).toBe(true);
|
|
770
|
+
expect(issues.some((issue) => issue.message.includes('non-macos sibling target prepare-macos'))).toBe(false);
|
|
771
|
+
});
|
|
772
|
+
|
|
711
773
|
it('rejects recursive script commands', () => {
|
|
712
774
|
addProject(tree, 'app', 'packages/app');
|
|
713
775
|
addProject(tree, 'lib', 'packages/lib');
|
|
@@ -4,13 +4,20 @@ import { join } from 'node:path';
|
|
|
4
4
|
import { getProjects, readJson, type Tree, updateJson } from 'nx/src/devkit-exports.js';
|
|
5
5
|
|
|
6
6
|
import { boundedTestScriptAlias } from './bounded-test-policy.js';
|
|
7
|
-
import
|
|
8
|
-
|
|
7
|
+
import {
|
|
8
|
+
BUILD_OUTPUT_DEPENDENCIES,
|
|
9
|
+
LINUX_PLATFORM_TARGET_GLOBS,
|
|
10
|
+
MACOS_PLATFORM_TARGET_GLOBS,
|
|
11
|
+
type NxPolicyIssue,
|
|
12
|
+
} from './workspace-config-policy.js';
|
|
13
|
+
|
|
14
|
+
export { BUILD_OUTPUT_DEPENDENCIES, PLATFORM_TARGET_GLOBS } from './workspace-config-policy.js';
|
|
9
15
|
export type { NxPolicyIssue };
|
|
10
16
|
|
|
11
17
|
export interface ResolvedProjectTargets {
|
|
12
18
|
targets: ReadonlySet<string>;
|
|
13
19
|
buildDependsOn?: readonly string[];
|
|
20
|
+
targetDependencies?: ReadonlyMap<string, readonly string[]>;
|
|
14
21
|
targetExecutors?: ReadonlyMap<string, string>;
|
|
15
22
|
targetScripts?: ReadonlyMap<string, string>;
|
|
16
23
|
}
|
|
@@ -19,19 +26,6 @@ export interface PackageTargetPolicyOptions {
|
|
|
19
26
|
resolvedTargetsByProject?: ReadonlyMap<string, ReadonlySet<string> | ResolvedProjectTargets>;
|
|
20
27
|
}
|
|
21
28
|
|
|
22
|
-
export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
23
|
-
'*-js',
|
|
24
|
-
'*-web',
|
|
25
|
-
'*-html',
|
|
26
|
-
'*-css',
|
|
27
|
-
'*-ios',
|
|
28
|
-
'*-android',
|
|
29
|
-
'*-native',
|
|
30
|
-
'*-napi',
|
|
31
|
-
'*-bun',
|
|
32
|
-
'*-wasm',
|
|
33
|
-
];
|
|
34
|
-
|
|
35
29
|
const workspaceDependencyFields = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies'];
|
|
36
30
|
|
|
37
31
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
@@ -230,7 +224,7 @@ function targetExistsInResolvedProject(
|
|
|
230
224
|
}
|
|
231
225
|
|
|
232
226
|
function isBuildOutputDependencyPattern(dependency: string): boolean {
|
|
233
|
-
return BUILD_OUTPUT_DEPENDENCIES.
|
|
227
|
+
return BUILD_OUTPUT_DEPENDENCIES.some((pattern) => pattern === dependency);
|
|
234
228
|
}
|
|
235
229
|
|
|
236
230
|
function expectedTargetDependencies(targetName: string): string[] {
|
|
@@ -606,14 +600,14 @@ function validateBuildZigPolicy(root: string, packagePath: string): NxPolicyIssu
|
|
|
606
600
|
function validateExplicitNxTargets(
|
|
607
601
|
pkg: Record<string, unknown>,
|
|
608
602
|
packagePath: string,
|
|
609
|
-
|
|
603
|
+
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
610
604
|
): NxPolicyIssue[] {
|
|
605
|
+
const issues = validatePlatformTargetDependencies(packagePath, resolvedProject);
|
|
611
606
|
const nx = recordProperty(pkg, 'nx');
|
|
612
607
|
const targets = nx ? recordProperty(nx, 'targets') : null;
|
|
613
608
|
if (!targets) {
|
|
614
|
-
return
|
|
609
|
+
return issues;
|
|
615
610
|
}
|
|
616
|
-
const issues: NxPolicyIssue[] = [];
|
|
617
611
|
for (const [targetName, rawTarget] of Object.entries(targets)) {
|
|
618
612
|
if (targetName.includes(':')) {
|
|
619
613
|
issues.push({
|
|
@@ -626,7 +620,76 @@ function validateExplicitNxTargets(
|
|
|
626
620
|
if (!isRecord(rawTarget)) {
|
|
627
621
|
continue;
|
|
628
622
|
}
|
|
629
|
-
issues.push(
|
|
623
|
+
issues.push(
|
|
624
|
+
...validateTargetDependencies(
|
|
625
|
+
rawTarget,
|
|
626
|
+
`${packagePath}: nx.targets.${targetName}`,
|
|
627
|
+
resolvedProjectTargetNames(resolvedProject),
|
|
628
|
+
),
|
|
629
|
+
);
|
|
630
|
+
}
|
|
631
|
+
return issues;
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
type PlatformTargetFamily = 'macos' | 'linux';
|
|
635
|
+
|
|
636
|
+
function platformTargetFamily(targetName: string): PlatformTargetFamily | null {
|
|
637
|
+
if (MACOS_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
638
|
+
return 'macos';
|
|
639
|
+
}
|
|
640
|
+
if (LINUX_PLATFORM_TARGET_GLOBS.some((glob) => targetName.endsWith(glob.slice(1)))) {
|
|
641
|
+
return 'linux';
|
|
642
|
+
}
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
function matchingResolvedTargets(dependency: string, targets: ReadonlySet<string>): string[] {
|
|
647
|
+
if (!dependency.startsWith('*')) {
|
|
648
|
+
return targets.has(dependency) ? [dependency] : [];
|
|
649
|
+
}
|
|
650
|
+
const suffix = dependency.slice(1);
|
|
651
|
+
return [...targets].filter((targetName) => targetName.endsWith(suffix));
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
function validatePlatformTargetDependencies(
|
|
655
|
+
packagePath: string,
|
|
656
|
+
resolvedProject?: ReadonlySet<string> | ResolvedProjectTargets,
|
|
657
|
+
): NxPolicyIssue[] {
|
|
658
|
+
if (!isResolvedProjectTargets(resolvedProject) || !resolvedProject.targetDependencies) {
|
|
659
|
+
return [];
|
|
660
|
+
}
|
|
661
|
+
const issues: NxPolicyIssue[] = [];
|
|
662
|
+
for (const platformTarget of resolvedProject.targets) {
|
|
663
|
+
const family = platformTargetFamily(platformTarget);
|
|
664
|
+
if (!family) {
|
|
665
|
+
continue;
|
|
666
|
+
}
|
|
667
|
+
const visited = new Set<string>();
|
|
668
|
+
const pending = [platformTarget];
|
|
669
|
+
while (pending.length > 0) {
|
|
670
|
+
const targetName = pending.pop();
|
|
671
|
+
if (!targetName || visited.has(targetName)) {
|
|
672
|
+
continue;
|
|
673
|
+
}
|
|
674
|
+
visited.add(targetName);
|
|
675
|
+
for (const dependency of resolvedProject.targetDependencies.get(targetName) ?? []) {
|
|
676
|
+
if (dependency.startsWith('^')) {
|
|
677
|
+
continue;
|
|
678
|
+
}
|
|
679
|
+
for (const resolvedDependency of matchingResolvedTargets(dependency, resolvedProject.targets)) {
|
|
680
|
+
if (platformTargetFamily(resolvedDependency) !== family) {
|
|
681
|
+
issues.push({
|
|
682
|
+
path: packagePath,
|
|
683
|
+
message:
|
|
684
|
+
`${packagePath}: platform target ${platformTarget} dependency closure references ` +
|
|
685
|
+
`non-${family} sibling target ${resolvedDependency} via ${targetName}`,
|
|
686
|
+
});
|
|
687
|
+
continue;
|
|
688
|
+
}
|
|
689
|
+
pending.push(resolvedDependency);
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
}
|
|
630
693
|
}
|
|
631
694
|
return issues;
|
|
632
695
|
}
|
|
@@ -933,7 +996,7 @@ export function checkPackageTargetPolicyTree(tree: Tree, options: PackageTargetP
|
|
|
933
996
|
const resolvedProject = options.resolvedTargetsByProject?.get(projectName);
|
|
934
997
|
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
935
998
|
|
|
936
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath,
|
|
999
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
937
1000
|
issues.push(...validateTestEntrypointPresenceTree(tree, packagePath, pkg));
|
|
938
1001
|
issues.push(...validateBuildZigPolicyTree(tree, packagePath));
|
|
939
1002
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets }));
|
|
@@ -1156,9 +1219,8 @@ export function checkPackageTargetPolicy(root: string, options: PackageTargetPol
|
|
|
1156
1219
|
const packagePath = packagePathFromJsonPath(root, packageJsonPath);
|
|
1157
1220
|
const projectName = packageNxProjectName(pkg);
|
|
1158
1221
|
const resolvedProject = projectName ? options.resolvedTargetsByProject?.get(projectName) : undefined;
|
|
1159
|
-
const resolvedTargets = resolvedProjectTargetNames(resolvedProject);
|
|
1160
1222
|
|
|
1161
|
-
issues.push(...validateExplicitNxTargets(pkg, packagePath,
|
|
1223
|
+
issues.push(...validateExplicitNxTargets(pkg, packagePath, resolvedProject));
|
|
1162
1224
|
issues.push(...validateTestEntrypointPresence(root, packagePath, pkg));
|
|
1163
1225
|
issues.push(...validateBuildZigPolicy(root, packagePath));
|
|
1164
1226
|
issues.push(...validatePackageScriptPolicy(pkg, packagePath, workspaceNames, { resolvedTargets: resolvedProject }));
|
|
@@ -10,9 +10,13 @@ import {
|
|
|
10
10
|
applyWorkspaceConfig,
|
|
11
11
|
applyWorkspaceConfigPolicy,
|
|
12
12
|
applyWorkspaceConfigTree,
|
|
13
|
+
BUILD_OUTPUT_DEPENDENCIES,
|
|
13
14
|
checkWorkspaceConfig,
|
|
14
15
|
checkWorkspaceConfigPolicy,
|
|
15
16
|
checkWorkspaceConfigTree,
|
|
17
|
+
LINUX_PLATFORM_TARGET_GLOBS,
|
|
18
|
+
MACOS_PLATFORM_TARGET_GLOBS,
|
|
19
|
+
PLATFORM_TARGET_GLOBS,
|
|
16
20
|
} from './workspace-config-policy.js';
|
|
17
21
|
|
|
18
22
|
// ---------------------------------------------------------------------------
|
|
@@ -56,6 +60,25 @@ function validPlugins(): unknown[] {
|
|
|
56
60
|
// Layer 1: Pure core function tests
|
|
57
61
|
// ---------------------------------------------------------------------------
|
|
58
62
|
|
|
63
|
+
describe('target family conventions', () => {
|
|
64
|
+
it('separates platform-only families from ordinary build outputs', () => {
|
|
65
|
+
expect(MACOS_PLATFORM_TARGET_GLOBS).toEqual(['*-macos', '*-ios']);
|
|
66
|
+
expect(LINUX_PLATFORM_TARGET_GLOBS).toEqual(['*-linux']);
|
|
67
|
+
expect(PLATFORM_TARGET_GLOBS).toEqual(['*-macos', '*-ios', '*-linux']);
|
|
68
|
+
expect(BUILD_OUTPUT_DEPENDENCIES).toEqual([
|
|
69
|
+
'*-js',
|
|
70
|
+
'*-web',
|
|
71
|
+
'*-html',
|
|
72
|
+
'*-css',
|
|
73
|
+
'*-android',
|
|
74
|
+
'*-native',
|
|
75
|
+
'*-napi',
|
|
76
|
+
'*-bun',
|
|
77
|
+
'*-wasm',
|
|
78
|
+
]);
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
59
82
|
describe('pure core: checkWorkspaceConfig', () => {
|
|
60
83
|
it('returns no issues for valid config', () => {
|
|
61
84
|
const issues = checkWorkspaceConfig(validNxJson());
|
|
@@ -13,13 +13,16 @@ export const BUILD_OUTPUT_DEPENDENCIES = [
|
|
|
13
13
|
'*-web',
|
|
14
14
|
'*-html',
|
|
15
15
|
'*-css',
|
|
16
|
-
'*-ios',
|
|
17
16
|
'*-android',
|
|
18
17
|
'*-native',
|
|
19
18
|
'*-napi',
|
|
20
19
|
'*-bun',
|
|
21
20
|
'*-wasm',
|
|
22
|
-
];
|
|
21
|
+
] as const;
|
|
22
|
+
|
|
23
|
+
export const MACOS_PLATFORM_TARGET_GLOBS = ['*-macos', '*-ios'] as const;
|
|
24
|
+
export const LINUX_PLATFORM_TARGET_GLOBS = ['*-linux'] as const;
|
|
25
|
+
export const PLATFORM_TARGET_GLOBS = [...MACOS_PLATFORM_TARGET_GLOBS, ...LINUX_PLATFORM_TARGET_GLOBS] as const;
|
|
23
26
|
|
|
24
27
|
const nxJsTypescriptPlugin = '@nx/js/typescript';
|
|
25
28
|
const smoothBricksNxPlugin = '@smoothbricks/nx-plugin';
|