Skip to content

Built-in extractors ignore a byte order mark in every JSON manifest - #412

Open
agorischek wants to merge 3 commits into
mainfrom
agorischek-friendly-succotash
Open

agorischek wants to merge 3 commits into
mainfrom
agorischek-friendly-succotash

Conversation

@agorischek

@agorischek agorischek commented Dec 5, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

On a repository holding a package.json that starts with a UTF-8 byte order mark (for example vite's playground/resolve/utf8-bom-package/package.json test fixture), typescript-public-api failed on every revision with Invalid package manifest `…/package.json`: SyntaxError: Unexpected token '\uFEFF', even with execution.scope set. npm, pnpm and Node's require all accept the BOM.

typescript-public-api

  • The texts the extractor loads (manifests, tsconfig files and sources) drop a leading BOM, as the compiler's own ts.sys.readFile does. readJson and the installed-toolchain manifest read do the same, through one withoutBom helper beside parseJson.
  • It no longer parses every tracked package.json. Finding which package owns a root file only needs the manifest's directory, so only the API packages' manifests (the packages being extracted) are parsed now. An unrelated fixture's invalid manifest can't fail the extraction, and the extracted package's own invalid manifest is still an error.

workspace-dependencies

Shared helper and explore

  • The SDK now exports its existing without_bom. workspace-dependencies uses it, and so do projections explore's TypeScript proposals for package.json and tsconfig files. Before, explore silently skipped a BOM-prefixed package. docs/reference/extractor-sdk.md gets the new entry; CI's docs check confirms it matches the generator.

Evidence

  • npm run tools -- check --fast: passed. Typecheck and lint were skipped because packages/engine/js isn't built in this sandbox, so I ran them directly:

    • npx tsc -p packages/extractors/typescript-support/tsconfig.json --noEmit (after building packages/schemas): passed.
    • npx eslint packages/extractors/typescript-support/src: passed.
  • npm run tools -- test projections-extractor-workspace-dependencies: passed, 26/26, including the new lockfiles_and_workspace_files_with_a_byte_order_mark_read_as_their_managers_read_them.

  • cargo test --locked -p projections-cli --lib explore::typescript: passed, 24/24, including the new manifests_and_tsconfigs_with_a_byte_order_mark_read_as_node_reads_them.

  • cargo clippy -p projections-extractor-workspace-dependencies -p projections-extractor-sdk --all-targets -- -D warnings and cargo clippy -p projections-cli --lib -- -D warnings: passed.

  • typescript-support tests: disk space was too tight to build the native engine, so I ran node --test test/collectors-typescript.test.ts test/toolchain.test.ts test/nestjs.test.ts with the freshly built helper and a stub in place of the engine's normalize/canonicalize/compare. Every test passed except the 9 that depend on the stubbed comparison or canonicalization. The new test a byte order mark before a manifest is ignored, and only the API packages' manifests are parsed passes, and on the old source it fails with the reported Invalid package manifest error. CI runs the real suite.

  • I wrote the new docs/reference/extractor-sdk.md entry in the generator's format because the pinned nightly isn't installed here. CI's npm run docs:check (public-product, ubuntu Node) reports "82 generated reference pages are up to date".

  • Documentation that this change affects is updated, and generated reference
    pages are regenerated (npm run docs:generate).

  • Fixes include a regression test.

  • A changelog fragment at changelog.d/<this PR's number>.md describes what
    users will notice, or the PR has the no changelog label (see
    changelog.d/README.md).

  • No credentials, private source or machine-specific paths are included.

agorischek and others added 2 commits December 5, 2026 02:20
typescript-public-api failed on any repository holding a package.json that
starts with a UTF-8 byte order mark (such as vite's
playground/resolve/utf8-bom-package fixture), since it parsed every tracked
manifest with JSON.parse. Its loaded texts now drop a leading BOM, as the
compiler's own sys.readFile does, and only the API packages' manifests are
parsed: an unrelated fixture's invalid manifest no longer fails the
extraction, while the extracted package's own still does.

workspace-dependencies already read package.json through the SDK's
BOM-aware read_json; its lockfiles and pnpm-workspace.yaml now drop a BOM
too. The SDK exports without_bom for that, and explore's TypeScript
proposals use it for manifests and tsconfig files, which it skipped.

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for the BOM-handling and manifest-selection changes.

No open issues 🎉

What changed in this PR

Extends the BOM handling introduced in #308 across TypeScript extraction, workspace files, and projections explore, while preventing unrelated invalid manifests from blocking API extraction.

Changes:

  • Strip leading byte order marks through shared helpers.
  • Parse only manifests belonging to selected API packages.
  • Add regression tests, SDK documentation, and a changelog entry.
File Description
packages/​extractors/​workspace-dependencies/​tests/​managers.rs Tests BOM-prefixed lockfiles and workspace files.
packages/​extractors/​workspace-dependencies/​src/​lib.rs Strips BOMs from workspace text inputs.
packages/​extractors/​typescript-support/​test/​collectors-typescript.test.ts Tests BOM handling and unrelated invalid manifests.
packages/​extractors/​typescript-support/​src/​typescript/​packages.ts Parses only selected API package manifests.
packages/​extractors/​typescript-support/​src/​typescript/​files.ts Strips BOMs when loading compiler inputs.
packages/​extractors/​typescript-support/​src/​toolchain.ts Handles BOM-prefixed installed manifests.
packages/​extractors/​typescript-support/​src/​shared.ts Removes BOMs before JSON parsing.
packages/​extractors/​typescript-support/​src/​json/​parse.ts Adds the shared TypeScript BOM helper.
packages/​extractors/​sdk/​src/​paths.rs Makes the Rust BOM helper public.
packages/​extractors/​sdk/​src/​lib.rs Exports the BOM helper.
packages/​cli/​src/​explore/​typescript/​tsconfig.rs Uses BOM-aware tsconfig reads.
packages/​cli/​src/​explore/​typescript.rs Adds BOM-aware discovery reads and regression coverage.
docs/​reference/​extractor-sdk.md Documents the exported helper.
changelog.d/​412.md Describes the user-visible fixes.

Review effort: Balanced

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants