@smoothbricks/nx-plugin 0.3.9 → 0.3.10
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 +7 -0
- package/dist/cross-check-policy.d.ts +65 -0
- package/dist/cross-check-policy.d.ts.map +1 -0
- package/dist/cross-check-policy.js +64 -0
- package/dist/executors/napi-cross-toolchain/executor.d.ts +42 -0
- package/dist/executors/napi-cross-toolchain/executor.d.ts.map +1 -0
- package/dist/executors/napi-cross-toolchain/executor.js +118 -0
- package/dist/executors/napi-cross-toolchain/schema.d.ts +4 -0
- package/dist/executors/napi-cross-toolchain/schema.d.ts.map +1 -0
- package/dist/executors/napi-cross-toolchain/schema.js +1 -0
- package/dist/generators/create-package/generator.d.ts.map +1 -1
- package/dist/generators/create-package/generator.js +77 -5
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +122 -12
- package/dist/typecheck-test-policy.d.ts.map +1 -1
- package/dist/typecheck-test-policy.js +22 -2
- package/dist/workspace-config-policy.js +14 -0
- package/executors.json +5 -0
- package/generators.json +1 -1
- package/package.json +6 -1
- package/src/cross-check-policy.test.ts +81 -0
- package/src/cross-check-policy.ts +70 -0
- package/src/executors/napi-cross-toolchain/executor.test.ts +112 -0
- package/src/executors/napi-cross-toolchain/executor.ts +157 -0
- package/src/executors/napi-cross-toolchain/schema.json +15 -0
- package/src/executors/napi-cross-toolchain/schema.ts +3 -0
- package/src/generators/create-package/generator.test.ts +49 -0
- package/src/generators/create-package/generator.ts +88 -6
- package/src/generators/create-package/schema.d.ts +2 -1
- package/src/generators/create-package/schema.json +7 -2
- package/src/index.test.ts +92 -14
- package/src/index.ts +136 -12
- package/src/typecheck-test-policy.ts +24 -2
- package/src/workspace-config-policy.ts +14 -0
package/README.md
CHANGED
|
@@ -36,6 +36,13 @@ Concrete targets come from concrete files:
|
|
|
36
36
|
triple. Linux `--use-napi-cross` targets compile C/C++ dependencies with Clang; the NAPI CLI supplies its downloaded
|
|
37
37
|
GNU sysroot and toolchain flags. This avoids the bundled GCC's unsupported diagnostics-color flag without disabling
|
|
38
38
|
the workspace's sccache wrapper.
|
|
39
|
+
- Each `--use-napi-cross` triple also gets a `napi-toolchain-<arch>-linux` prerequisite that extracts the pinned
|
|
40
|
+
`@napi-rs/cross-toolchain-<host>-target-<arch>` archive into `~/.napi-rs`, where the NAPI CLI probes for it. Every
|
|
41
|
+
cross build of that triple — the inferred `napi-<arch>-linux` and any package-local `cli-<arch>-linux` — depends on
|
|
42
|
+
it, so the CLI's own downloader never runs. That downloader `npm pack`s into its own package directory, which under
|
|
43
|
+
Bun's isolated global store is a shared (in CI host-wide) cache: two concurrent cross builds of one triple would
|
|
44
|
+
otherwise pack the same file into the same directory and one would die on the other's cleanup. The prerequisite
|
|
45
|
+
produces no artifact, so it stays out of the aggregate `build` and out of collected platform outputs.
|
|
39
46
|
- `build` is inferred only when the project has at least one concrete build target to run, such as inferred `tsc-js`, a
|
|
40
47
|
package-local target like `tsdown-js`, or `cargo-wasm` from this plugin. It depends on output-family wildcard targets:
|
|
41
48
|
`*-js`, `*-web`, `*-html`, `*-css`, `*-ios`, `*-android`, `*-native`, `*-napi`, `*-bun`, and `*-wasm`.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Linux compile gate, in one place.
|
|
3
|
+
*
|
|
4
|
+
* CI validates on Linux, so Rust behind a `cfg(target_os)` arm that only Linux
|
|
5
|
+
* compiles is invisible to every check a macOS host can run: a full local lint
|
|
6
|
+
* passes and CI still goes red on unused imports, unresolved names and dead code
|
|
7
|
+
* inside the `not(target_os = "macos")` branch. Closing that needs three pieces
|
|
8
|
+
* to agree — a devenv profile carrying the cross C toolchain, an Nx target per
|
|
9
|
+
* Cargo workspace that asks for the triple, and a root script that runs the
|
|
10
|
+
* second inside the first. They live here together because the plugin infers the
|
|
11
|
+
* target while the CLI installs the script and reports a project missing it; kept
|
|
12
|
+
* apart, the three spellings drift and the gate silently stops gating.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The triple CI's Linux job compiles, and the one a macOS host can cross-check.
|
|
16
|
+
* `languages.rust.targets` in the managed devenv module installs its rust-std.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CARGO_LINUX_TRIPLE = "x86_64-unknown-linux-gnu";
|
|
19
|
+
/**
|
|
20
|
+
* The devenv profile carrying the cross C compiler, defined in the managed
|
|
21
|
+
* `tooling/direnv/devenv.smoo.nix`. Opt-in because its closure is 0.4 GiB and
|
|
22
|
+
* nothing on Darwin links a Linux object.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DEVENV_CROSS_PROFILE = "linux-cross";
|
|
25
|
+
/**
|
|
26
|
+
* Nx target name. No colons, per the repo's target-naming rule.
|
|
27
|
+
*
|
|
28
|
+
* Deliberately NOT suffixed `-linux`: that suffix is the reserved platform
|
|
29
|
+
* family `LINUX_PLATFORM_TARGET_GLOBS`, which the publish workflow fans out over
|
|
30
|
+
* to build release ARTIFACTS on a Linux runner, which `platformTargetFamily`
|
|
31
|
+
* classifies by, and which flags a project as platform-bearing. A validation
|
|
32
|
+
* target that emits nothing must not be swept into artifact machinery, so it
|
|
33
|
+
* carries the neutral `-cross` qualifier — also outside the `-js`/`-napi`/`-wasm`
|
|
34
|
+
* build-output families, so no aggregate `build` picks it up either.
|
|
35
|
+
*/
|
|
36
|
+
export declare const CARGO_CROSS_LINT_TARGET = "cargo-lint-cross";
|
|
37
|
+
/**
|
|
38
|
+
* Clippy rather than `cargo check`, and `-D warnings`, because that is exactly
|
|
39
|
+
* what CI's `lint` runs; a weaker local command would pass where CI fails.
|
|
40
|
+
*
|
|
41
|
+
* `--all-targets` is what answers "what does test mean when cross-compiling": it
|
|
42
|
+
* type-checks bins, tests, benches and examples for the target, so test CODE is
|
|
43
|
+
* verified for Linux while nothing is executed — nothing can be, since an x86_64
|
|
44
|
+
* Linux binary does not run on Apple Silicon. There is deliberately no separate
|
|
45
|
+
* cross test target; it could only recompile these crates to produce a harness it
|
|
46
|
+
* must then refuse to launch.
|
|
47
|
+
*
|
|
48
|
+
* `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
|
|
49
|
+
* by the profile, so running this outside the cross shell fails loudly on a
|
|
50
|
+
* missing tool instead of quietly linting the host and reporting green.
|
|
51
|
+
*
|
|
52
|
+
* `cargo fmt` is absent on purpose: formatting is target-independent and already
|
|
53
|
+
* covered by `cargo-lint`, so repeating it here would only cost time.
|
|
54
|
+
*/
|
|
55
|
+
export declare const CARGO_CROSS_LINT_COMMAND = "cargo clippy --workspace --all-targets --target x86_64-unknown-linux-gnu -- -D warnings";
|
|
56
|
+
/** Root `package.json` script name, in the repo's `verb:qualifier` style. */
|
|
57
|
+
export declare const CROSS_CHECK_SCRIPT_NAME = "check:linux";
|
|
58
|
+
/**
|
|
59
|
+
* The developer entry point: one command on macOS that reports what CI's Linux
|
|
60
|
+
* job would. `tooling/devenv` is the managed wrapper, so this resolves the
|
|
61
|
+
* repository's devenv config from any repo in the fleet without naming its path,
|
|
62
|
+
* and `--quiet` keeps the output to Nx's own.
|
|
63
|
+
*/
|
|
64
|
+
export declare const CROSS_CHECK_SCRIPT_COMMAND = "tooling/devenv --quiet -P linux-cross shell -- nx run-many -t cargo-lint-cross";
|
|
65
|
+
//# sourceMappingURL=cross-check-policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-check-policy.d.ts","sourceRoot":"","sources":["../src/cross-check-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH;;;GAGG;AACH,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAE7D;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uBAAuB,qBAAqB,CAAC;AAE1D;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,wBAAwB,4FAAyF,CAAC;AAE/H,6EAA6E;AAC7E,eAAO,MAAM,uBAAuB,gBAAgB,CAAC;AAErD;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,mFAAyG,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Linux compile gate, in one place.
|
|
3
|
+
*
|
|
4
|
+
* CI validates on Linux, so Rust behind a `cfg(target_os)` arm that only Linux
|
|
5
|
+
* compiles is invisible to every check a macOS host can run: a full local lint
|
|
6
|
+
* passes and CI still goes red on unused imports, unresolved names and dead code
|
|
7
|
+
* inside the `not(target_os = "macos")` branch. Closing that needs three pieces
|
|
8
|
+
* to agree — a devenv profile carrying the cross C toolchain, an Nx target per
|
|
9
|
+
* Cargo workspace that asks for the triple, and a root script that runs the
|
|
10
|
+
* second inside the first. They live here together because the plugin infers the
|
|
11
|
+
* target while the CLI installs the script and reports a project missing it; kept
|
|
12
|
+
* apart, the three spellings drift and the gate silently stops gating.
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* The triple CI's Linux job compiles, and the one a macOS host can cross-check.
|
|
16
|
+
* `languages.rust.targets` in the managed devenv module installs its rust-std.
|
|
17
|
+
*/
|
|
18
|
+
export const CARGO_LINUX_TRIPLE = 'x86_64-unknown-linux-gnu';
|
|
19
|
+
/**
|
|
20
|
+
* The devenv profile carrying the cross C compiler, defined in the managed
|
|
21
|
+
* `tooling/direnv/devenv.smoo.nix`. Opt-in because its closure is 0.4 GiB and
|
|
22
|
+
* nothing on Darwin links a Linux object.
|
|
23
|
+
*/
|
|
24
|
+
export const DEVENV_CROSS_PROFILE = 'linux-cross';
|
|
25
|
+
/**
|
|
26
|
+
* Nx target name. No colons, per the repo's target-naming rule.
|
|
27
|
+
*
|
|
28
|
+
* Deliberately NOT suffixed `-linux`: that suffix is the reserved platform
|
|
29
|
+
* family `LINUX_PLATFORM_TARGET_GLOBS`, which the publish workflow fans out over
|
|
30
|
+
* to build release ARTIFACTS on a Linux runner, which `platformTargetFamily`
|
|
31
|
+
* classifies by, and which flags a project as platform-bearing. A validation
|
|
32
|
+
* target that emits nothing must not be swept into artifact machinery, so it
|
|
33
|
+
* carries the neutral `-cross` qualifier — also outside the `-js`/`-napi`/`-wasm`
|
|
34
|
+
* build-output families, so no aggregate `build` picks it up either.
|
|
35
|
+
*/
|
|
36
|
+
export const CARGO_CROSS_LINT_TARGET = 'cargo-lint-cross';
|
|
37
|
+
/**
|
|
38
|
+
* Clippy rather than `cargo check`, and `-D warnings`, because that is exactly
|
|
39
|
+
* what CI's `lint` runs; a weaker local command would pass where CI fails.
|
|
40
|
+
*
|
|
41
|
+
* `--all-targets` is what answers "what does test mean when cross-compiling": it
|
|
42
|
+
* type-checks bins, tests, benches and examples for the target, so test CODE is
|
|
43
|
+
* verified for Linux while nothing is executed — nothing can be, since an x86_64
|
|
44
|
+
* Linux binary does not run on Apple Silicon. There is deliberately no separate
|
|
45
|
+
* cross test target; it could only recompile these crates to produce a harness it
|
|
46
|
+
* must then refuse to launch.
|
|
47
|
+
*
|
|
48
|
+
* `--target` is explicit rather than inherited from a CARGO_BUILD_TARGET exported
|
|
49
|
+
* by the profile, so running this outside the cross shell fails loudly on a
|
|
50
|
+
* missing tool instead of quietly linting the host and reporting green.
|
|
51
|
+
*
|
|
52
|
+
* `cargo fmt` is absent on purpose: formatting is target-independent and already
|
|
53
|
+
* covered by `cargo-lint`, so repeating it here would only cost time.
|
|
54
|
+
*/
|
|
55
|
+
export const CARGO_CROSS_LINT_COMMAND = `cargo clippy --workspace --all-targets --target ${CARGO_LINUX_TRIPLE} -- -D warnings`;
|
|
56
|
+
/** Root `package.json` script name, in the repo's `verb:qualifier` style. */
|
|
57
|
+
export const CROSS_CHECK_SCRIPT_NAME = 'check:linux';
|
|
58
|
+
/**
|
|
59
|
+
* The developer entry point: one command on macOS that reports what CI's Linux
|
|
60
|
+
* job would. `tooling/devenv` is the managed wrapper, so this resolves the
|
|
61
|
+
* repository's devenv config from any repo in the fleet without naming its path,
|
|
62
|
+
* and `--quiet` keeps the output to Nx's own.
|
|
63
|
+
*/
|
|
64
|
+
export const CROSS_CHECK_SCRIPT_COMMAND = `tooling/devenv --quiet -P ${DEVENV_CROSS_PROFILE} shell -- nx run-many -t ${CARGO_CROSS_LINT_TARGET}`;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { NapiCrossToolchainOptions } from './schema.js';
|
|
2
|
+
interface NapiCrossToolchainContext {
|
|
3
|
+
root: string;
|
|
4
|
+
projectName?: string;
|
|
5
|
+
projectsConfigurations?: {
|
|
6
|
+
projects: Record<string, {
|
|
7
|
+
root?: string;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
export type PrewarmOutcome = 'ready' | 'extracted' | 'unsupported-host';
|
|
12
|
+
export default function napiCrossToolchainExecutor(options: NapiCrossToolchainOptions, context: NapiCrossToolchainContext): Promise<{
|
|
13
|
+
success: boolean;
|
|
14
|
+
}>;
|
|
15
|
+
/**
|
|
16
|
+
* Extract the pinned cross toolchain into the directory
|
|
17
|
+
* `napi build --use-napi-cross` probes, so its own download never runs.
|
|
18
|
+
*
|
|
19
|
+
* WHY this exists: `@napi-rs/cross-toolchain@1.0.3`'s `download()` uses its own
|
|
20
|
+
* package directory as scratch space — `npm pack` there, unpack, then a
|
|
21
|
+
* non-`force` `rmSync` of the tarball. Under `linker = "isolated"` with
|
|
22
|
+
* `globalStore = true` that directory is the shared Bun store (in CI a
|
|
23
|
+
* host-wide mutable bind mount), so two concurrent `--use-napi-cross` builds of
|
|
24
|
+
* one triple pack the same filename into the same directory and the loser dies
|
|
25
|
+
* with `ENOENT ... lstat '<tarball>'`. Nx runs `cli-x64-linux` and
|
|
26
|
+
* `napi-x64-linux` in one wave, which is exactly that race.
|
|
27
|
+
*
|
|
28
|
+
* Extraction stages into a private sibling directory and lands with `rename`,
|
|
29
|
+
* so racing callers — and repeated runs after a crash — cannot corrupt the
|
|
30
|
+
* result: `rename` replaces an empty directory (napi itself creates one before
|
|
31
|
+
* probing) and fails with ENOTEMPTY against a populated one, which means
|
|
32
|
+
* another caller already won.
|
|
33
|
+
*/
|
|
34
|
+
export declare function prewarmCrossToolchain(options: {
|
|
35
|
+
projectRoot: string;
|
|
36
|
+
triple: string;
|
|
37
|
+
platform?: string;
|
|
38
|
+
hostArch?: string;
|
|
39
|
+
home?: string;
|
|
40
|
+
}): PrewarmOutcome;
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/executors/napi-cross-toolchain/executor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAE7D,UAAU,yBAAyB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sBAAsB,CAAC,EAAE;QACvB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE;YAAE,IAAI,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KAC7C,CAAC;CACH;AAaD,MAAM,MAAM,cAAc,GAAG,OAAO,GAAG,WAAW,GAAG,kBAAkB,CAAC;AAExE,wBAA8B,0BAA0B,CACtD,OAAO,EAAE,yBAAyB,EAClC,OAAO,EAAE,yBAAyB,GACjC,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC,CAe/B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE;IAC7C,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,GAAG,cAAc,CAiEjB"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { execFileSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, renameSync, rmSync } from 'node:fs';
|
|
3
|
+
import { createRequire } from 'node:module';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
/** Package-name arch segment of `@napi-rs/cross-toolchain-<host>-target-<arch>`. */
|
|
7
|
+
const TARGET_PACKAGE_ARCH = {
|
|
8
|
+
'aarch64-unknown-linux-gnu': 'aarch64',
|
|
9
|
+
'x86_64-unknown-linux-gnu': 'x86_64',
|
|
10
|
+
};
|
|
11
|
+
const HOST_PACKAGE_ARCH = {
|
|
12
|
+
arm64: 'arm64',
|
|
13
|
+
x64: 'x64',
|
|
14
|
+
};
|
|
15
|
+
export default async function napiCrossToolchainExecutor(options, context) {
|
|
16
|
+
const projectName = context.projectName;
|
|
17
|
+
if (!projectName) {
|
|
18
|
+
throw new Error('@smoothbricks/nx-plugin:napi-cross-toolchain requires a project context.');
|
|
19
|
+
}
|
|
20
|
+
const project = context.projectsConfigurations?.projects[projectName];
|
|
21
|
+
if (!project) {
|
|
22
|
+
throw new Error(`Project ${projectName} was not found in the Nx project graph.`);
|
|
23
|
+
}
|
|
24
|
+
const projectRoot = path.resolve(context.root, project.root ?? '.');
|
|
25
|
+
const triple = options.triple;
|
|
26
|
+
console.log(`${triple}: ${prewarmCrossToolchain({ projectRoot, triple })}`);
|
|
27
|
+
return { success: true };
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Extract the pinned cross toolchain into the directory
|
|
31
|
+
* `napi build --use-napi-cross` probes, so its own download never runs.
|
|
32
|
+
*
|
|
33
|
+
* WHY this exists: `@napi-rs/cross-toolchain@1.0.3`'s `download()` uses its own
|
|
34
|
+
* package directory as scratch space — `npm pack` there, unpack, then a
|
|
35
|
+
* non-`force` `rmSync` of the tarball. Under `linker = "isolated"` with
|
|
36
|
+
* `globalStore = true` that directory is the shared Bun store (in CI a
|
|
37
|
+
* host-wide mutable bind mount), so two concurrent `--use-napi-cross` builds of
|
|
38
|
+
* one triple pack the same filename into the same directory and the loser dies
|
|
39
|
+
* with `ENOENT ... lstat '<tarball>'`. Nx runs `cli-x64-linux` and
|
|
40
|
+
* `napi-x64-linux` in one wave, which is exactly that race.
|
|
41
|
+
*
|
|
42
|
+
* Extraction stages into a private sibling directory and lands with `rename`,
|
|
43
|
+
* so racing callers — and repeated runs after a crash — cannot corrupt the
|
|
44
|
+
* result: `rename` replaces an empty directory (napi itself creates one before
|
|
45
|
+
* probing) and fails with ENOTEMPTY against a populated one, which means
|
|
46
|
+
* another caller already won.
|
|
47
|
+
*/
|
|
48
|
+
export function prewarmCrossToolchain(options) {
|
|
49
|
+
const { projectRoot, triple } = options;
|
|
50
|
+
const targetArch = TARGET_PACKAGE_ARCH[triple];
|
|
51
|
+
if (!targetArch) {
|
|
52
|
+
throw new Error(`Unsupported --use-napi-cross triple ${triple}. Supported: ${Object.keys(TARGET_PACKAGE_ARCH).join(', ')}.`);
|
|
53
|
+
}
|
|
54
|
+
const hostArch = HOST_PACKAGE_ARCH[options.hostArch ?? process.arch];
|
|
55
|
+
// napi-rs ships these toolchains for Linux x64 and Linux arm64 hosts only,
|
|
56
|
+
// and refuses `--use-napi-cross` anywhere else. Extracting on a host that can
|
|
57
|
+
// never use the result would only demand pins nothing needs, so leave the
|
|
58
|
+
// unsupported-host diagnostic to the build itself.
|
|
59
|
+
if (!hostArch || (options.platform ?? process.platform) !== 'linux') {
|
|
60
|
+
return 'unsupported-host';
|
|
61
|
+
}
|
|
62
|
+
const requireFromProject = createRequire(path.join(projectRoot, 'package.json'));
|
|
63
|
+
const targetPackage = `@napi-rs/cross-toolchain-${hostArch}-target-${targetArch}`;
|
|
64
|
+
let targetModule;
|
|
65
|
+
try {
|
|
66
|
+
targetModule = requireFromProject(targetPackage);
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
throw new Error(`${targetPackage} is not installed for ${projectRoot}. Add it to optionalDependencies so ${triple} ` +
|
|
70
|
+
'builds extract the pinned toolchain instead of downloading into the shared Bun store.', { cause: error });
|
|
71
|
+
}
|
|
72
|
+
if (typeof targetModule !== 'object' ||
|
|
73
|
+
targetModule === null ||
|
|
74
|
+
!('toolchainPath' in targetModule) ||
|
|
75
|
+
typeof targetModule.toolchainPath !== 'string') {
|
|
76
|
+
throw new Error(`${targetPackage} no longer exports a toolchainPath string.`);
|
|
77
|
+
}
|
|
78
|
+
const tarball = targetModule.toolchainPath;
|
|
79
|
+
const home = options.home ?? homedir();
|
|
80
|
+
const destination = path.join(home, '.napi-rs', 'cross-toolchain', crossToolchainVersion(requireFromProject), triple);
|
|
81
|
+
const marker = path.join(destination, 'package.json');
|
|
82
|
+
if (existsSync(marker)) {
|
|
83
|
+
return 'ready';
|
|
84
|
+
}
|
|
85
|
+
mkdirSync(path.dirname(destination), { recursive: true });
|
|
86
|
+
const staging = mkdtempSync(`${destination}.staging-`);
|
|
87
|
+
try {
|
|
88
|
+
execFileSync('tar', ['-xJf', tarball, '-C', staging], { stdio: 'inherit' });
|
|
89
|
+
if (!existsSync(path.join(staging, 'package.json'))) {
|
|
90
|
+
throw new Error(`${tarball} did not contain the package.json marker napi probes; the toolchain archive layout changed.`);
|
|
91
|
+
}
|
|
92
|
+
renameSync(staging, destination);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
rmSync(staging, { force: true, recursive: true });
|
|
96
|
+
const code = error instanceof Error && 'code' in error ? error.code : undefined;
|
|
97
|
+
if ((code === 'ENOTEMPTY' || code === 'EEXIST') && existsSync(marker)) {
|
|
98
|
+
return 'ready';
|
|
99
|
+
}
|
|
100
|
+
throw error;
|
|
101
|
+
}
|
|
102
|
+
return 'extracted';
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `napi` derives the extraction directory from `@napi-rs/cross-toolchain`'s own
|
|
106
|
+
* version, so read it from the package the CLI resolves — not from the
|
|
107
|
+
* per-target package, whose version only happens to match today.
|
|
108
|
+
*/
|
|
109
|
+
function crossToolchainVersion(requireFromProject) {
|
|
110
|
+
const cliRequire = createRequire(requireFromProject.resolve('@napi-rs/cli/package.json'));
|
|
111
|
+
const indexPath = cliRequire.resolve('@napi-rs/cross-toolchain');
|
|
112
|
+
const manifest = JSON.parse(readFileSync(path.join(path.dirname(indexPath), 'package.json'), 'utf-8'));
|
|
113
|
+
const version = typeof manifest === 'object' && manifest !== null && 'version' in manifest ? manifest.version : undefined;
|
|
114
|
+
if (typeof version !== 'string' || version.length === 0) {
|
|
115
|
+
throw new Error(`@napi-rs/cross-toolchain resolved at ${indexPath} has no version.`);
|
|
116
|
+
}
|
|
117
|
+
return version;
|
|
118
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/executors/napi-cross-toolchain/schema.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,yBAAyB;IACxC,MAAM,EAAE,MAAM,CAAC;CAChB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"generator.d.ts","sourceRoot":"","sources":["../../../src/generators/create-package/generator.ts"],"names":[],"mappings":"AAEA,OAAO,EAAY,KAAK,IAAI,EAAa,MAAM,0BAA0B,CAAC;AAE1E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAEhE,wBAA8B,SAAS,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,IAAI,CAAC,CAkBvG"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Scaffold
|
|
1
|
+
// Scaffold TypeScript libraries and Rust workspaces through one convention-owned generator.
|
|
2
2
|
// CLI wiring: packages/cli/src/generate/index.ts (variant registry)
|
|
3
3
|
import { readJson, writeJson } from 'nx/src/devkit-exports.js';
|
|
4
4
|
export default async function generator(tree, schema) {
|
|
@@ -9,7 +9,15 @@ export default async function generator(tree, schema) {
|
|
|
9
9
|
if (tree.exists(`${projectRoot}/package.json`)) {
|
|
10
10
|
throw new Error(`Package already exists at ${projectRoot}`);
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
if (schema.variant === 'ts-lib' && schema.wasm) {
|
|
13
|
+
throw new Error('wasm output metadata is only available for rust-crate');
|
|
14
|
+
}
|
|
15
|
+
if (schema.variant === 'rust-crate') {
|
|
16
|
+
writeRustFiles(tree, schema, packageName, projectRoot, rootPkg);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
writeTypeScriptFiles(tree, schema, packageName, projectRoot, rootPkg);
|
|
20
|
+
}
|
|
13
21
|
}
|
|
14
22
|
function extractScope(name) {
|
|
15
23
|
if (!name)
|
|
@@ -17,8 +25,8 @@ function extractScope(name) {
|
|
|
17
25
|
const match = /^(@[^/]+)\//.exec(name);
|
|
18
26
|
return match?.[1] ?? null;
|
|
19
27
|
}
|
|
20
|
-
function
|
|
21
|
-
const packageJson =
|
|
28
|
+
function writeTypeScriptFiles(tree, schema, packageName, projectRoot, rootPkg) {
|
|
29
|
+
const packageJson = buildTypeScriptPackageJson(schema, packageName, projectRoot, rootPkg);
|
|
22
30
|
writeJson(tree, `${projectRoot}/package.json`, packageJson);
|
|
23
31
|
writeJson(tree, `${projectRoot}/tsconfig.json`, {
|
|
24
32
|
extends: '../../tsconfig.base.json',
|
|
@@ -61,7 +69,7 @@ function writeCommonFiles(tree, schema, packageName, projectRoot, rootPkg) {
|
|
|
61
69
|
tree.write(`${projectRoot}/bunfig.toml`, '[test]\ntimeout = 30000\npreload = ["@smoothbricks/validation/bun/preload"]\n');
|
|
62
70
|
tree.write(`${projectRoot}/src/index.ts`, '');
|
|
63
71
|
}
|
|
64
|
-
function
|
|
72
|
+
function buildTypeScriptPackageJson(schema, packageName, projectRoot, rootPkg) {
|
|
65
73
|
const packageJson = {
|
|
66
74
|
name: packageName,
|
|
67
75
|
version: '0.0.0',
|
|
@@ -127,6 +135,70 @@ function buildPackageJson(schema, packageName, projectRoot, rootPkg) {
|
|
|
127
135
|
}
|
|
128
136
|
return packageJson;
|
|
129
137
|
}
|
|
138
|
+
function writeRustFiles(tree, schema, packageName, projectRoot, rootPkg) {
|
|
139
|
+
if (schema.public) {
|
|
140
|
+
throw new Error('rust-crate does not use npm publication metadata; publish Rust crates through Cargo policy');
|
|
141
|
+
}
|
|
142
|
+
const crateName = schema.name;
|
|
143
|
+
const crateRoot = `${projectRoot}/crates/${crateName}`;
|
|
144
|
+
writeJson(tree, `${projectRoot}/package.json`, {
|
|
145
|
+
name: packageName,
|
|
146
|
+
version: '0.0.0',
|
|
147
|
+
private: true,
|
|
148
|
+
scripts: {
|
|
149
|
+
test: `nx run ${schema.name}:test --outputStyle=stream`,
|
|
150
|
+
},
|
|
151
|
+
nx: {
|
|
152
|
+
name: schema.name,
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const repository = repositoryUrl(rootPkg.repository);
|
|
156
|
+
const workspacePackage = [
|
|
157
|
+
'[workspace]',
|
|
158
|
+
'resolver = "3"',
|
|
159
|
+
`members = ["crates/${crateName}"]`,
|
|
160
|
+
'',
|
|
161
|
+
'[workspace.package]',
|
|
162
|
+
'version = "0.0.0"',
|
|
163
|
+
'edition = "2024"',
|
|
164
|
+
`license = ${JSON.stringify(rootPkg.license ?? 'UNLICENSED')}`,
|
|
165
|
+
'publish = false',
|
|
166
|
+
...(repository === null ? [] : [`repository = ${JSON.stringify(repository)}`]),
|
|
167
|
+
'',
|
|
168
|
+
];
|
|
169
|
+
tree.write(`${projectRoot}/Cargo.toml`, workspacePackage.join('\n'));
|
|
170
|
+
const crateManifest = [
|
|
171
|
+
'[package]',
|
|
172
|
+
`name = ${JSON.stringify(crateName)}`,
|
|
173
|
+
'version.workspace = true',
|
|
174
|
+
'edition.workspace = true',
|
|
175
|
+
'license.workspace = true',
|
|
176
|
+
'publish.workspace = true',
|
|
177
|
+
...(schema.wasm
|
|
178
|
+
? [
|
|
179
|
+
'',
|
|
180
|
+
'[lib]',
|
|
181
|
+
'crate-type = ["cdylib", "rlib"]',
|
|
182
|
+
'',
|
|
183
|
+
'[package.metadata.smoothbricks.wasm-bindgen]',
|
|
184
|
+
'targets = ["web", "nodejs"]',
|
|
185
|
+
'out-dir = "dist-wasm"',
|
|
186
|
+
]
|
|
187
|
+
: []),
|
|
188
|
+
'',
|
|
189
|
+
];
|
|
190
|
+
tree.write(`${crateRoot}/Cargo.toml`, crateManifest.join('\n'));
|
|
191
|
+
tree.write(`${crateRoot}/src/lib.rs`, '#![forbid(unsafe_code)]\n');
|
|
192
|
+
}
|
|
193
|
+
function repositoryUrl(repository) {
|
|
194
|
+
if (typeof repository === 'string') {
|
|
195
|
+
return repository;
|
|
196
|
+
}
|
|
197
|
+
if (!isRecord(repository)) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
return typeof repository.url === 'string' ? repository.url : null;
|
|
201
|
+
}
|
|
130
202
|
function isRecord(value) {
|
|
131
203
|
return value !== null && typeof value === 'object' && !Array.isArray(value);
|
|
132
204
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { type CreateNodesV2 } from 'nx/src/devkit-exports.js';
|
|
2
|
+
export declare function hostPlatformTargetNames(targetNames: Iterable<string>): string[];
|
|
3
|
+
interface NapiTargetConvention {
|
|
4
|
+
architecture: string;
|
|
5
|
+
outputName: string;
|
|
6
|
+
targetFamily: 'linux' | 'macos';
|
|
7
|
+
useNapiCross: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Prerequisite target that extracts the cross toolchain one triple needs. The
|
|
11
|
+
* platform suffix keeps it inside its own platform family, so it can be a
|
|
12
|
+
* dependency of `napi-<arch>-linux` and package-local `cli-<arch>-linux`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function napiToolchainTargetName(convention: NapiTargetConvention): string;
|
|
2
15
|
export declare const createNodesV2: CreateNodesV2;
|
|
3
16
|
declare const _default: {
|
|
4
17
|
createNodesV2: CreateNodesV2;
|
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,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAEL,KAAK,aAAa,EAGnB,MAAM,0BAA0B,CAAC;AA2BlC,wBAAgB,uBAAuB,CAAC,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,GAAG,MAAM,EAAE,CAU/E;AAyBD,UAAU,oBAAoB;IAC5B,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC;IAChC,YAAY,EAAE,OAAO,CAAC;CACvB;AA+BD;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,oBAAoB,GAAG,MAAM,CAEhF;AA2CD,eAAO,MAAM,aAAa,EAAE,aA4B3B,CAAC"}
|