Files
scriptc/tests/library-mode/contract-npm/lib.ts
T
Chris Tate f9cbff164f Library mode takes the static-or-refuse npm posture: eligible packages compile, SC4013 refuses the rest
- compileLibrary runs the --npm-static eligibility bar automatically over every bare specifier the graph exposes (opted-in packages' own import and top-level require edges included, iterated to a fixpoint) — an eligible package compiles statically into the library graph, and every fallback the shared frontend records refuses as SC4013 naming the package, the specific failed bar, and the vendor-or-drop remedy (with the profile's SC4013 teaching riding the hint), never SC1010/SC2013's executable-lane teachings.
- requireInitStmt now emits the guarded %init call for a bare require naming another opted-in package: the dep's module body never ran before (NULL-closure crash at first use), a latent npm-static gap on both lanes that the library fixpoint hits immediately; the executable lane never exercised an inter-package require.
- Contract facts exclude statically-compiled npm files (their .d.ts is dropped by construction, so no npm declaration can name a wire-contract type) while their bytes keep joining source_hash/build_id through moduleOrder; the sidecar stays byte-deterministic and a package-file edit flips both identity hashes.
- Builtins keep their story under the npm posture: async_free builtin imports compile alongside npm code, event-loop surfaces still refuse SC4005, no new fence.
- New fixtures npm-static, npm-refuse, and contract-npm vendor fake packages per the tests/fixtures/npm precedent; the K12 suites assert the compile and refusal sides on both emissions and the contract suite covers the identity-hash implications.
2026-07-23 20:06:31 -05:00

29 lines
855 B
TypeScript

// Contract-sidecar fixture with a statically-compiled npm module in the
// graph: the package's bytes join source_hash/build_id (the identity
// hashes cover the WHOLE compiled module graph — the suite proves a
// package-file edit flips both), while the contract's TYPE vocabulary
// stays authored program surface (the opted-in package's .d.ts is dropped
// by construction, so no npm declaration can name a wire type).
import { add } from "adderkit";
export interface Model {
total: number;
}
export type Msg =
| { kind: "bump"; by: number }
| { kind: "reset" };
export function init(): Model {
return { total: add(1, 2) };
}
export function update(m: Model, msg: Msg): Model {
if (msg.kind === "bump") return { total: add(m.total, msg.by) };
return { total: 0 };
}
export function apply(x: number): number {
return add(x, 10);
}