Skip to content

Commit e67ddb6

Browse files
chore: classify experimental bindings
1 parent e445cda commit e67ddb6

8 files changed

Lines changed: 115 additions & 8 deletions

File tree

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { execFileSync } from "node:child_process";
2+
import { readFile } from "node:fs/promises";
3+
import { dirname, relative } from "node:path";
4+
import { fileURLToPath } from "node:url";
5+
6+
const bindingKind = (pkg) => {
7+
if (pkg.name.endsWith("-napi")) {
8+
return "napi";
9+
}
10+
11+
if (pkg.name.endsWith("-wasm")) {
12+
return "wasm";
13+
}
14+
15+
return null;
16+
};
17+
18+
const cargoPublishIsDisabled = (pkg) => Array.isArray(pkg.publish) && pkg.publish.length === 0;
19+
20+
const releaseSteps = (workflow) => workflow.split(/\n {6}- name:/);
21+
22+
const hasReleasePath = (pkg, workflow, rootPath) => {
23+
const kind = bindingKind(pkg);
24+
const packagePath = relative(rootPath, dirname(pkg.manifest_path)).replaceAll("\\", "/");
25+
const buildCommand = kind === "napi" ? "napi build" : "wasm-pack build";
26+
27+
return releaseSteps(workflow).some(
28+
(step) =>
29+
step.includes(buildCommand) &&
30+
(step.includes(`cd ${packagePath}`) || step.includes(`working-directory: ${packagePath}`)),
31+
);
32+
};
33+
34+
export const findUnclassifiedBindings = ({ packages, releaseWorkflow, rootPath }) =>
35+
packages
36+
.filter((pkg) => bindingKind(pkg) !== null)
37+
.filter((pkg) => !cargoPublishIsDisabled(pkg))
38+
.filter((pkg) => !hasReleasePath(pkg, releaseWorkflow, rootPath))
39+
.map((pkg) => pkg.name)
40+
.sort();
41+
42+
export const loadBindingPolicyInputs = async (rootUrl) => {
43+
const rootPath = fileURLToPath(rootUrl);
44+
const metadata = JSON.parse(
45+
execFileSync("cargo", ["metadata", "--format-version", "1", "--no-deps"], {
46+
cwd: rootPath,
47+
encoding: "utf8",
48+
}),
49+
);
50+
const workspaceMembers = new Set(metadata.workspace_members);
51+
const releaseWorkflow = await readFile(new URL(".github/workflows/release.yml", rootUrl), "utf8");
52+
53+
return {
54+
packages: metadata.packages.filter((pkg) => workspaceMembers.has(pkg.id)),
55+
releaseWorkflow,
56+
rootPath,
57+
};
58+
};
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import assert from "node:assert/strict";
2+
import { describe, it } from "node:test";
3+
4+
import { findUnclassifiedBindings, loadBindingPolicyInputs } from "./binding-manifest-policy.mjs";
5+
6+
const ROOT_URL = new URL("../../", import.meta.url);
7+
const EXPERIMENTAL_BINDINGS = [
8+
"srcmap-generator-napi",
9+
"srcmap-remapping-napi",
10+
"srcmap-scopes-wasm",
11+
];
12+
13+
describe("Rust binding manifest policy", () => {
14+
it("classifies every workspace binding crate", async () => {
15+
const inputs = await loadBindingPolicyInputs(ROOT_URL);
16+
17+
assert.deepEqual(findUnclassifiedBindings(inputs), []);
18+
});
19+
20+
it("identifies experimental bindings when publish protection is removed", async () => {
21+
const inputs = await loadBindingPolicyInputs(ROOT_URL);
22+
const packages = inputs.packages.map((pkg) =>
23+
EXPERIMENTAL_BINDINGS.includes(pkg.name) ? { ...pkg, publish: null } : pkg,
24+
);
25+
26+
assert.deepEqual(findUnclassifiedBindings({ ...inputs, packages }), EXPERIMENTAL_BINDINGS);
27+
});
28+
29+
it("recognizes release paths for published bindings", async () => {
30+
const inputs = await loadBindingPolicyInputs(ROOT_URL);
31+
const packages = inputs.packages.map((pkg) =>
32+
pkg.name.endsWith("-napi") || pkg.name.endsWith("-wasm") ? { ...pkg, publish: null } : pkg,
33+
);
34+
35+
assert.deepEqual(findUnclassifiedBindings({ ...inputs, packages }), EXPERIMENTAL_BINDINGS);
36+
});
37+
});

CONTRIBUTING.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,19 @@ packages/
5757
sourcemap-wasm/ WASM bindings for sourcemap
5858
generator-wasm/ WASM bindings for generator
5959
remapping-wasm/ WASM bindings for remapping
60-
scopes-wasm/ WASM bindings for scopes
60+
scopes-wasm/ Experimental WASM bindings for scopes (unpublished)
6161
symbolicate-wasm/ WASM bindings for symbolicate
6262
codec/ NAPI bindings for codec
6363
sourcemap/ NAPI bindings for sourcemap
64-
generator/ NAPI bindings for generator
65-
remapping/ NAPI bindings for remapping
64+
generator/ Experimental NAPI bindings for generator (unpublished)
65+
remapping/ JavaScript remapping wrapper plus experimental NAPI bindings
6666
trace-mapping/ Drop-in @jridgewell/trace-mapping replacement
6767
6868
benchmarks/ JS benchmarks comparing against existing libraries
6969
```
7070

71+
The experimental `generator`, `remapping` NAPI, and `scopes-wasm` binding crates remain workspace members so they compile with the rest of the repository. They use `publish = false` and are not released as npm packages. The published `@srcmap/remapping` JavaScript wrapper shares the `packages/remapping` directory but does not publish the experimental NAPI binary.
72+
7173
## Development workflow
7274

7375
### Building

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ const pos = originalPositionFor(map, { line: 43, column: 10 })
231231
map.free() // Release WASM memory (or use `using` with Symbol.dispose)
232232
```
233233

234-
### All packages
234+
### Published npm packages
235235

236236
| Package | Description |
237237
|---|---|
@@ -246,6 +246,16 @@ map.free() // Release WASM memory (or use `using` with Symbol.dispose)
246246
| [`@srcmap/sourcemap`](https://www.npmjs.com/package/@srcmap/sourcemap) | Parser + consumer (NAPI) |
247247
| [`@srcmap/codec`](https://www.npmjs.com/package/@srcmap/codec) | VLQ codec (NAPI) |
248248

249+
### Experimental bindings
250+
251+
The Rust workspace also contains the following experimental binding crates. They are kept in the workspace for development and validation, but are not published as npm packages:
252+
253+
| Workspace crate | Status |
254+
|---|---|
255+
| `srcmap-generator-napi` in `packages/generator` | Experimental NAPI binding, unpublished |
256+
| `srcmap-remapping-napi` in `packages/remapping` | Experimental NAPI binding, unpublished. The `@srcmap/remapping` JavaScript wrapper in the same directory is published separately. |
257+
| `srcmap-scopes-wasm` in `packages/scopes-wasm` | Experimental WASM binding, unpublished |
258+
249259
## CLI
250260

251261
```bash

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"typos": "typos",
3030
"deny": "cargo deny check",
3131
"test": "pnpm run test:rust && pnpm run test:js",
32-
"test:js": "node --test .github/scripts/check-napi-declarations.test.mjs .github/scripts/publish-crate-if-needed.test.mjs .github/scripts/workflow-policy.test.mjs benchmarks/workload.test.mjs packages/codec/__tests__/codec.test.mjs packages/sourcemap/__tests__/sourcemap.test.mjs packages/sourcemap-wasm/__tests__/sourcemap-wasm.test.mjs packages/sourcemap-wasm/__tests__/coverage-utils.test.mjs packages/sourcemap-wasm/__tests__/browser.test.mjs packages/generator-wasm/__tests__/generator-wasm.test.mjs packages/remapping-wasm/__tests__/remapping-wasm.test.mjs packages/symbolicate-wasm/__tests__/symbolicate-wasm.test.mjs packages/trace-mapping/__tests__/trace-mapping.test.mjs packages/trace-mapping/__tests__/compat.test.mjs packages/source-map/__tests__/source-map.test.mjs packages/gen-mapping/__tests__/gen-mapping.test.mjs packages/gen-mapping/__tests__/gen-mapping.cjs.test.cjs packages/remapping/__tests__/remapping.test.mjs packages/remapping/__tests__/remapping.cjs.test.cjs packages/remapping/__tests__/compat.test.mjs",
32+
"test:js": "node --test .github/scripts/binding-manifest-policy.test.mjs .github/scripts/check-napi-declarations.test.mjs .github/scripts/publish-crate-if-needed.test.mjs .github/scripts/workflow-policy.test.mjs benchmarks/workload.test.mjs packages/codec/__tests__/codec.test.mjs packages/sourcemap/__tests__/sourcemap.test.mjs packages/sourcemap-wasm/__tests__/sourcemap-wasm.test.mjs packages/sourcemap-wasm/__tests__/coverage-utils.test.mjs packages/sourcemap-wasm/__tests__/browser.test.mjs packages/generator-wasm/__tests__/generator-wasm.test.mjs packages/remapping-wasm/__tests__/remapping-wasm.test.mjs packages/symbolicate-wasm/__tests__/symbolicate-wasm.test.mjs packages/trace-mapping/__tests__/trace-mapping.test.mjs packages/trace-mapping/__tests__/compat.test.mjs packages/source-map/__tests__/source-map.test.mjs packages/gen-mapping/__tests__/gen-mapping.test.mjs packages/gen-mapping/__tests__/gen-mapping.cjs.test.cjs packages/remapping/__tests__/remapping.test.mjs packages/remapping/__tests__/remapping.cjs.test.cjs packages/remapping/__tests__/compat.test.mjs",
3333
"test:rust": "cargo test",
3434
"coverage": "pnpm run coverage:rust && pnpm run coverage:js",
3535
"coverage:js": "mkdir -p coverage && node --test --experimental-test-coverage --test-reporter=lcov --test-reporter-destination=coverage/js-lcov.info --test-reporter=spec --test-reporter-destination=stdout packages/codec/__tests__/codec.test.mjs packages/sourcemap/__tests__/sourcemap.test.mjs packages/sourcemap-wasm/__tests__/sourcemap-wasm.test.mjs packages/sourcemap-wasm/__tests__/coverage-utils.test.mjs packages/generator-wasm/__tests__/generator-wasm.test.mjs packages/remapping-wasm/__tests__/remapping-wasm.test.mjs packages/symbolicate-wasm/__tests__/symbolicate-wasm.test.mjs packages/trace-mapping/__tests__/trace-mapping.test.mjs packages/trace-mapping/__tests__/compat.test.mjs packages/source-map/__tests__/source-map.test.mjs packages/gen-mapping/__tests__/gen-mapping.test.mjs packages/gen-mapping/__tests__/gen-mapping.cjs.test.cjs packages/remapping/__tests__/remapping.test.mjs packages/remapping/__tests__/remapping.cjs.test.cjs packages/remapping/__tests__/compat.test.mjs",

packages/generator/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition.workspace = true
55
rust-version.workspace = true
66
license.workspace = true
77
repository.workspace = true
8-
description = "N-API bindings for srcmap-generator"
8+
description = "Experimental unpublished N-API bindings for srcmap-generator"
99
publish = false
1010

1111
[package.metadata.cargo-shear]

packages/remapping/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition.workspace = true
55
rust-version.workspace = true
66
license.workspace = true
77
repository.workspace = true
8-
description = "N-API bindings for srcmap-remapping"
8+
description = "Experimental unpublished N-API bindings for srcmap-remapping"
99
publish = false
1010

1111
[lib]

packages/scopes-wasm/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ edition.workspace = true
55
rust-version.workspace = true
66
license.workspace = true
77
repository.workspace = true
8-
description = "WebAssembly bindings for srcmap-scopes"
8+
description = "Experimental unpublished WebAssembly bindings for srcmap-scopes"
99
publish = false
1010

1111
[package.metadata.wasm-pack.profile.release]

0 commit comments

Comments
 (0)