Repository navigation
Built-in extractors ignore a byte order mark in every JSON manifest - #412
Open
agorischek wants to merge 3 commits into
Open
agorischek wants to merge 3 commits into
agorischek wants to merge 3 commits into
Conversation
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>
There was a problem hiding this comment.
🟢 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
On a repository holding a
package.jsonthat starts with a UTF-8 byte order mark (for example vite'splayground/resolve/utf8-bom-package/package.jsontest fixture),typescript-public-apifailed on every revision withInvalid package manifest `…/package.json`: SyntaxError: Unexpected token '\uFEFF', even withexecution.scopeset. npm, pnpm and Node'srequireall accept the BOM.typescript-public-api
ts.sys.readFiledoes.readJsonand the installed-toolchain manifest read do the same, through onewithoutBomhelper besideparseJson.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
package.jsonreads already ignored a BOM (Extractor failures say what the tool said; JSON reads ignore a byte order mark #308, through the SDK'sread_json). Its lockfiles (package-lock.json,bun.lock) andpnpm-workspace.yamlwent throughread_sourceand didn't. They now drop a BOM too.Shared helper and explore
without_bom. workspace-dependencies uses it, and so doprojections explore's TypeScript proposals forpackage.jsonand tsconfig files. Before, explore silently skipped a BOM-prefixed package.docs/reference/extractor-sdk.mdgets the new entry; CI's docs check confirms it matches the generator.Evidence
npm run tools -- check --fast: passed. Typecheck and lint were skipped becausepackages/engine/jsisn't built in this sandbox, so I ran them directly:npx tsc -p packages/extractors/typescript-support/tsconfig.json --noEmit(after buildingpackages/schemas): passed.npx eslint packages/extractors/typescript-support/src: passed.npm run tools -- test projections-extractor-workspace-dependencies: passed, 26/26, including the newlockfiles_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 newmanifests_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 warningsandcargo 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.tswith the freshly built helper and a stub in place of the engine'snormalize/canonicalize/compare. Every test passed except the 9 that depend on the stubbed comparison or canonicalization. The new testa byte order mark before a manifest is ignored, and only the API packages' manifests are parsedpasses, and on the old source it fails with the reportedInvalid package manifesterror. CI runs the real suite.I wrote the new
docs/reference/extractor-sdk.mdentry in the generator's format because the pinned nightly isn't installed here. CI'snpm 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>.mddescribes whatusers will notice, or the PR has the
no changeloglabel (seechangelog.d/README.md).
No credentials, private source or machine-specific paths are included.