@smoothbricks/nx-plugin 0.4.0 → 0.4.1
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.js +13 -4
- package/dist/package-target-policy.d.ts.map +1 -1
- package/dist/package-target-policy.js +2 -1
- package/package.json +1 -1
- package/src/index.test.ts +6 -6
- package/src/index.ts +13 -4
- package/src/package-target-policy.test.ts +13 -0
- package/src/package-target-policy.ts +2 -1
package/dist/index.js
CHANGED
|
@@ -964,9 +964,18 @@ function resolveNapiConfig(packageJson, packageJsonPath, absoluteProjectRoot, is
|
|
|
964
964
|
return { binaryName, cargoPackage, manifestPath, targets };
|
|
965
965
|
}
|
|
966
966
|
function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
|
|
967
|
-
|
|
967
|
+
// napi derives the addon filename ([name]) from the nearest package.json `napi`
|
|
968
|
+
// field starting at the invocation cwd. A repository-root invocation runs where
|
|
969
|
+
// no such field exists, so without an explicit path every repo-rooted build
|
|
970
|
+
// emits index.*.node while the loader resolves binaryName.*.node — a mismatch
|
|
971
|
+
// that stale local artifacts can mask for months.
|
|
972
|
+
const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
|
|
973
|
+
const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
|
|
968
974
|
const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
|
|
969
975
|
const cargoCwd = repoRooted ? '.' : projectRoot;
|
|
976
|
+
// A repository-root Cargo invocation runs outside the owning npm package, so
|
|
977
|
+
// Nx's root-only PATH cannot resolve that package's napi CLI.
|
|
978
|
+
const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
|
|
970
979
|
const outputPath = (projectOutput) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
|
|
971
980
|
const hostPlatformTargetName = hostPlatform === null ? null : `napi-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
|
|
972
981
|
let nativeHostTargetName = null;
|
|
@@ -997,7 +1006,7 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
|
|
|
997
1006
|
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
998
1007
|
options: {
|
|
999
1008
|
cwd: cargoCwd,
|
|
1000
|
-
command:
|
|
1009
|
+
command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
|
|
1001
1010
|
...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
|
|
1002
1011
|
},
|
|
1003
1012
|
};
|
|
@@ -1014,7 +1023,7 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
|
|
|
1014
1023
|
outputs: ['{projectRoot}/dist/native/host'],
|
|
1015
1024
|
options: {
|
|
1016
1025
|
cwd: cargoCwd,
|
|
1017
|
-
command:
|
|
1026
|
+
command: `${napiCommand} build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`,
|
|
1018
1027
|
...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
|
|
1019
1028
|
},
|
|
1020
1029
|
};
|
|
@@ -1056,7 +1065,7 @@ function createNapiTargets(projectRoot, config, hostPlatform, repoRooted) {
|
|
|
1056
1065
|
outputs: [`{projectRoot}/${outputDirectory}`],
|
|
1057
1066
|
options: {
|
|
1058
1067
|
cwd: cargoCwd,
|
|
1059
|
-
command:
|
|
1068
|
+
command: `${napiCommand} build --release --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`,
|
|
1060
1069
|
// Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
|
|
1061
1070
|
// GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
|
|
1062
1071
|
// scripts resolve the host libc headers instead.
|
|
@@ -1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AE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,aAAa,EAAE,CAsBlH;AAED;;;;GAIG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,GAAE,0BAA+B,GAAG,OAAO,CA8B1G;AAwJD,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,WAAW,EAAE,MAAM,EACnB,eAAe,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,EACrC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,GACjC,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,CAAC;IAAC,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,CAAC,CAAA;CAAO,GAC1F,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,CA8BxG"}
|
|
@@ -551,7 +551,8 @@ function validateTargetDependencies(target, label, resolvedTargets, projectNames
|
|
|
551
551
|
if (typeof dependency !== 'string') {
|
|
552
552
|
continue;
|
|
553
553
|
}
|
|
554
|
-
|
|
554
|
+
// Nx expands "..." to the inferred target's existing dependencies before merging explicit entries.
|
|
555
|
+
if (dependency === '...' || isCrossProjectTargetDependency(dependency, projectNames)) {
|
|
555
556
|
continue;
|
|
556
557
|
}
|
|
557
558
|
if (dependency.includes(':')) {
|
package/package.json
CHANGED
package/src/index.test.ts
CHANGED
|
@@ -491,12 +491,12 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
491
491
|
expect(native['napi-debug']?.options).toMatchObject({
|
|
492
492
|
cwd: '.',
|
|
493
493
|
command:
|
|
494
|
-
'napi build --platform --no-js --dts native.napi.d.ts --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --output-dir packages/native/.cache/native-debug',
|
|
494
|
+
'packages/native/node_modules/.bin/napi build --platform --no-js --dts native.napi.d.ts --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/.cache/native-debug',
|
|
495
495
|
});
|
|
496
496
|
expect(native['napi-arm64-macos']?.options).toMatchObject({
|
|
497
497
|
cwd: '.',
|
|
498
498
|
command:
|
|
499
|
-
'napi build --release --platform --no-js --dts native.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --output-dir packages/native/dist/native/darwin-arm64',
|
|
499
|
+
'packages/native/node_modules/.bin/napi build --release --platform --no-js --dts native.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path packages/native/crates/native-napi/Cargo.toml --package native-napi --package-json-path packages/native/package.json --output-dir packages/native/dist/native/darwin-arm64',
|
|
500
500
|
});
|
|
501
501
|
expect(native.build?.dependsOn).toContainEqual(rootCompile);
|
|
502
502
|
expect(native.clean?.executor).toBe('@smoothbricks/nx-plugin:clean-outputs');
|
|
@@ -679,14 +679,14 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
679
679
|
options: {
|
|
680
680
|
cwd: 'packages/cowshed',
|
|
681
681
|
command:
|
|
682
|
-
'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/host',
|
|
682
|
+
'napi build --release --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/host',
|
|
683
683
|
},
|
|
684
684
|
});
|
|
685
685
|
expect(unservedHostTargets.build?.dependsOn).toEqual(['^build', 'cargo-test-compile', 'cargo-napi', 'tsc-js']);
|
|
686
686
|
expect(targets['napi-arm64-macos']?.outputs).toEqual(['{projectRoot}/dist/native/darwin-arm64']);
|
|
687
687
|
expect(targets['napi-arm64-macos']?.options).toMatchObject({
|
|
688
688
|
command:
|
|
689
|
-
'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/darwin-arm64',
|
|
689
|
+
'napi build --release --platform --no-js --dts cowshed.darwin-arm64.d.ts --target aarch64-apple-darwin --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/darwin-arm64',
|
|
690
690
|
});
|
|
691
691
|
expect(targets['napi-arm64-macos']?.options?.env).toBeUndefined();
|
|
692
692
|
// No cargo-test-compile edge here, on ANY host: a platform target's
|
|
@@ -747,7 +747,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
747
747
|
expect(darwinArm64Targets['napi-arm64-linux']?.dependsOn).toEqual(['napi-toolchain-arm64-linux']);
|
|
748
748
|
expect(darwinArm64Targets['napi-x64-linux']?.outputs).toEqual(['{projectRoot}/dist/native/linux-x64-gnu']);
|
|
749
749
|
expect(darwinArm64Targets['napi-x64-linux']?.options?.command).toBe(
|
|
750
|
-
'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir dist/native/linux-x64-gnu',
|
|
750
|
+
'napi build --release --platform --no-js --dts cowshed.linux-x64-gnu.d.ts --target x86_64-unknown-linux-gnu --use-napi-cross --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir dist/native/linux-x64-gnu',
|
|
751
751
|
);
|
|
752
752
|
|
|
753
753
|
// The whole rule, stated once per forced host: a triple gets a cross
|
|
@@ -817,7 +817,7 @@ describe('@smoothbricks/nx-plugin inferred targets', () => {
|
|
|
817
817
|
options: {
|
|
818
818
|
cwd: 'packages/cowshed',
|
|
819
819
|
command:
|
|
820
|
-
'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --output-dir .cache/native-debug',
|
|
820
|
+
'napi build --platform --no-js --dts cowshed.napi.d.ts --manifest-path crates/cowshed-napi/Cargo.toml --package cowshed-napi --package-json-path package.json --output-dir .cache/native-debug',
|
|
821
821
|
},
|
|
822
822
|
});
|
|
823
823
|
expect(targets['cargo-test']?.dependsOn).toEqual(['cargo-test-cowshed-napi']);
|
package/src/index.ts
CHANGED
|
@@ -1183,9 +1183,18 @@ function createNapiTargets(
|
|
|
1183
1183
|
hostPlatform: NapiPlatform | null,
|
|
1184
1184
|
repoRooted: boolean,
|
|
1185
1185
|
): Record<string, TargetConfiguration> {
|
|
1186
|
-
|
|
1186
|
+
// napi derives the addon filename ([name]) from the nearest package.json `napi`
|
|
1187
|
+
// field starting at the invocation cwd. A repository-root invocation runs where
|
|
1188
|
+
// no such field exists, so without an explicit path every repo-rooted build
|
|
1189
|
+
// emits index.*.node while the loader resolves binaryName.*.node — a mismatch
|
|
1190
|
+
// that stale local artifacts can mask for months.
|
|
1191
|
+
const packageJsonPath = repoRooted ? posix.join(projectRoot, 'package.json') : 'package.json';
|
|
1192
|
+
const commonCommand = `--manifest-path ${config.manifestPath} --package ${config.cargoPackage} --package-json-path ${packageJsonPath}`;
|
|
1187
1193
|
const cargoInputs = repoRooted ? REPO_ROOT_CARGO_OUTPUT_INPUTS : NAPI_INPUTS;
|
|
1188
1194
|
const cargoCwd = repoRooted ? '.' : projectRoot;
|
|
1195
|
+
// A repository-root Cargo invocation runs outside the owning npm package, so
|
|
1196
|
+
// Nx's root-only PATH cannot resolve that package's napi CLI.
|
|
1197
|
+
const napiCommand = repoRooted ? posix.join(projectRoot, 'node_modules/.bin/napi') : 'napi';
|
|
1189
1198
|
const outputPath = (projectOutput: string) => (repoRooted ? posix.join(projectRoot, projectOutput) : projectOutput);
|
|
1190
1199
|
const hostPlatformTargetName =
|
|
1191
1200
|
hostPlatform === null ? null : `napi-${hostPlatform.architecture}-${hostPlatform.targetFamily}`;
|
|
@@ -1218,7 +1227,7 @@ function createNapiTargets(
|
|
|
1218
1227
|
outputs: ['{projectRoot}/.cache/native-debug'],
|
|
1219
1228
|
options: {
|
|
1220
1229
|
cwd: cargoCwd,
|
|
1221
|
-
command:
|
|
1230
|
+
command: `${napiCommand} build --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('.cache/native-debug')}`,
|
|
1222
1231
|
...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
|
|
1223
1232
|
},
|
|
1224
1233
|
};
|
|
@@ -1236,7 +1245,7 @@ function createNapiTargets(
|
|
|
1236
1245
|
outputs: ['{projectRoot}/dist/native/host'],
|
|
1237
1246
|
options: {
|
|
1238
1247
|
cwd: cargoCwd,
|
|
1239
|
-
command:
|
|
1248
|
+
command: `${napiCommand} build --release --platform --no-js --dts ${config.binaryName}.napi.d.ts ${commonCommand} --output-dir ${outputPath('dist/native/host')}`,
|
|
1240
1249
|
...(hostCompilerEnv ? { env: hostCompilerEnv } : {}),
|
|
1241
1250
|
},
|
|
1242
1251
|
};
|
|
@@ -1280,7 +1289,7 @@ function createNapiTargets(
|
|
|
1280
1289
|
outputs: [`{projectRoot}/${outputDirectory}`],
|
|
1281
1290
|
options: {
|
|
1282
1291
|
cwd: cargoCwd,
|
|
1283
|
-
command:
|
|
1292
|
+
command: `${napiCommand} build --release --platform --no-js --dts ${config.binaryName}.${convention.outputName}.d.ts --target ${triple}${crossFlag} ${commonCommand} --output-dir ${outputPath(outputDirectory)}`,
|
|
1284
1293
|
// Genuine Linux cross-compiles use Clang plus napi-rs's downloaded
|
|
1285
1294
|
// GNU sysroot. A native Linux target uses Nix's cc wrapper so C build
|
|
1286
1295
|
// scripts resolve the host libc headers instead.
|
|
@@ -546,6 +546,19 @@ describe('per-package checkPackageTargets', () => {
|
|
|
546
546
|
const issues = checkPackageTargets(pkg, 'packages/lib');
|
|
547
547
|
expect(issues.some((i) => i.message.includes('build:ts') && i.message.includes('colon'))).toBe(true);
|
|
548
548
|
});
|
|
549
|
+
|
|
550
|
+
it('accepts the Nx inferred-target merge marker', () => {
|
|
551
|
+
const pkg = {
|
|
552
|
+
nx: {
|
|
553
|
+
name: 'lib',
|
|
554
|
+
targets: {
|
|
555
|
+
build: { dependsOn: ['...', 'rust-dist'] },
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
};
|
|
559
|
+
|
|
560
|
+
expect(checkPackageTargets(pkg, 'packages/lib', new Set(['build', 'rust-dist']))).toEqual([]);
|
|
561
|
+
});
|
|
549
562
|
});
|
|
550
563
|
|
|
551
564
|
describe('per-package applyPackageTargets', () => {
|
|
@@ -728,7 +728,8 @@ function validateTargetDependencies(
|
|
|
728
728
|
if (typeof dependency !== 'string') {
|
|
729
729
|
continue;
|
|
730
730
|
}
|
|
731
|
-
|
|
731
|
+
// Nx expands "..." to the inferred target's existing dependencies before merging explicit entries.
|
|
732
|
+
if (dependency === '...' || isCrossProjectTargetDependency(dependency, projectNames)) {
|
|
732
733
|
continue;
|
|
733
734
|
}
|
|
734
735
|
if (dependency.includes(':')) {
|