diff --git a/package.json b/package.json index f1321e7..a120ccd 100644 --- a/package.json +++ b/package.json @@ -44,6 +44,10 @@ "import": "./dist/emitter.mjs", "require": "./dist/emitter.cjs" }, + "./parse": { + "import": "./dist/parse.mjs", + "require": "./dist/parse.cjs" + }, "./runtime": { "import": "./dist/runtime.mjs", "require": "./dist/runtime.cjs" diff --git a/src/parse.ts b/src/parse.ts new file mode 100644 index 0000000..3de4b33 --- /dev/null +++ b/src/parse.ts @@ -0,0 +1,6 @@ +// Wraps the vendored parser's own parse() as public library surface. Consumers that need to run cddl.js's own generation pipeline themselves (parse a .cddl file, then emitModule() the result) -- rather than shelling out to src/cli.ts -- need this to get a parsed AST at all; emitModule alone only accepts one, it doesn't produce one. Typed unknown at this boundary, not the vendored parser's own Assignment[] type, matching emitModule/mergeRules's existing unknown-typed input -- the vendored AST shape is an implementation detail, not part of cddl.js's own public contract. +import { parse as vendorParse } from "../vendor/cddl/dist/index.js"; + +export function parse(filePath: string): unknown { + return vendorParse(filePath); +} diff --git a/tsconfig.json b/tsconfig.json index da80642..4ee6f4f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ "skipLibCheck": true, "types": ["node"] }, - "include": ["src/emitter.ts", "src/runtime.ts"] + "include": ["src/emitter.ts", "src/runtime.ts", "src/parse.ts"] } diff --git a/tsdown.config.ts b/tsdown.config.ts index fe31364..56e3540 100644 --- a/tsdown.config.ts +++ b/tsdown.config.ts @@ -1,8 +1,8 @@ import { defineConfig } from "tsdown"; -// src/emitter.ts (emitModule/mergeRules) and src/runtime.ts (cborDecodesAs) are the library's public surface, built directly as separate entries rather than through a re-exporting index.ts -- the project's barrel-policy lint rule requires importing straight from the module that owns each export. Each is built dual ESM/CJS with declarations so it resolves correctly under every module system; attw verifies that claim directly rather than trusting it. src/cli.ts (a script, not library surface) and vendor/cddl (compiled separately, via its own tsc step -- see package.json's _vendor:build) are deliberately not part of this build. +// src/emitter.ts (emitModule/mergeRules), src/runtime.ts (cborDecodesAs), and src/parse.ts (parse, re-exported from the vendored parser) are the library's public surface, built directly as separate entries rather than through a re-exporting index.ts -- the project's barrel-policy lint rule requires importing straight from the module that owns each export. Each is built dual ESM/CJS with declarations so it resolves correctly under every module system; attw verifies that claim directly rather than trusting it. src/cli.ts (a script, not library surface) is deliberately not part of this build; vendor/cddl is compiled separately via its own tsc step (see package.json's _vendor:build), which src/parse.ts's own bundling depends on. export default defineConfig({ - entry: ["src/emitter.ts", "src/runtime.ts"], + entry: ["src/emitter.ts", "src/runtime.ts", "src/parse.ts"], format: ["esm", "cjs"], dts: true, exports: true, diff --git a/turbo.json b/turbo.json index a27d34e..e8efd0c 100644 --- a/turbo.json +++ b/turbo.json @@ -8,7 +8,8 @@ "outputs": ["vendor/cddl/dist/**"] }, "_build": { - "inputs": ["src/index.ts", "src/emitter.ts", "src/runtime.ts", "tsdown.config.ts", "tsconfig.json"], + "dependsOn": ["_vendor:build"], + "inputs": ["src/emitter.ts", "src/runtime.ts", "src/parse.ts", "tsdown.config.ts", "tsconfig.json"], "outputs": ["dist/**"] }, "_generate": {