Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/parse.ts
Original file line number Diff line number Diff line change
@@ -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);
}
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
4 changes: 2 additions & 2 deletions tsdown.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
3 changes: 2 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down