The forge's bundle met "Could not resolve blakejs" in the SDK's seal code. blakejs and tweetnacl are declared dependencies already. The build now runs a check after tsc: every bare import in dist/**/*.js must be a Node built-in, the package itself, or a declared dependency or peerDependency. The builder runs npm run build before npm pack, so a package that breaks this is never published. The check lives under src because the builder's workspace holds only the artifact's paths. Builds: design 47 H2 H-A-491
32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { mkdtempSync, mkdirSync, writeFileSync, rmSync } from "node:fs";
|
|
import { tmpdir } from "node:os";
|
|
import { join } from "node:path";
|
|
|
|
import { undeclared } from "../src/declared-imports.mjs";
|
|
|
|
// The package's built files import only what it declares (design 47 H2, H-A-491): the SDK itself passes, and a built
|
|
// file importing a package package.json leaves out is named, as the forge's bundle met blakejs.
|
|
test("every bare import of the built files is a declared dependency or a built-in", () => {
|
|
assert.deepEqual(undeclared(join(import.meta.dirname, "..")), []);
|
|
|
|
const root = mkdtempSync(join(tmpdir(), "declared-"));
|
|
try {
|
|
mkdirSync(join(root, "dist", "seal"), { recursive: true });
|
|
writeFileSync(join(root, "package.json"), JSON.stringify({ name: "@novox/x", dependencies: { tweetnacl: "1.0.3" }, devDependencies: { blakejs: "1.2.1" } }));
|
|
writeFileSync(join(root, "dist", "seal", "index.js"), [
|
|
'import nacl from "tweetnacl";',
|
|
'import blakejs from "blakejs";',
|
|
'import { createHash } from "node:crypto";',
|
|
'import fs from "fs/promises";',
|
|
'export * from "./other.js";',
|
|
'export { a } from "@novox/x/tools";',
|
|
'const m = await import("@scope/lazy/sub");',
|
|
].join("\n"));
|
|
assert.deepEqual(undeclared(root), ["dist/seal/index.js: blakejs", "dist/seal/index.js: @scope/lazy/sub"]);
|
|
} finally {
|
|
rmSync(root, { recursive: true, force: true });
|
|
}
|
|
});
|