Repository navigation
fix: typing, build and packaging issues shared with project template - #283
Merged
Merged
Conversation
The require export condition reused ES module declarations, so CommonJS consumers with node16/nodenext module resolution failed with TS1479. Declarations are now copied to .d.cts at build time, with relative .js specifiers rewritten to .cjs, and referenced via separate types under import and require conditions. Refs #269
Grammar was declared as function without construct signature, so `new Grammar()` (as documented) failed with TS7009 under --strict. Refs #269
testJSONPointer and testReferenceToken used type predicates targeting aliases of string, which narrowed invalid input to never in the false branch. testArrayLocation, testArrayIndex and testArrayDash keep their predicates, as they narrow to literal types. Refs #269
Error classes derived their names from this.constructor.name, which Terser mangles in dist/*.min.js (e.g. JSONPointerKeyError became Z). Names are now defined explicitly on the error classes. Refs #269
webpack's default globalObject for web target is self, which is not defined in Node.js, so requiring the bundles threw ReferenceError. The bundles now use self or this as global object. Adds smoke test of built artifacts (npm run test:artifacts). Refs #269
The CommonJS build rewrote apg-lite imports relative to the current working directory and used raw path.relative() output, producing wrong paths when run from another directory, backslashes on Windows and bare specifiers for files directly under src/. Refs #269
inferExpectations collected failed terminals from offsets earlier than the furthest one and considered TLS terminals only, so e.g. "/a~" reported "0", "1", "/". Failed TLS, TBS and TRG terminals are now recorded with their offsets and only those at the furthest offset are reported, or none when the parser matched past them. Refs #269
The npm-watch pattern {src,test}/*.js matched top-level files only, so
editing e.g. src/parse/index.js did not re-run tests.
Refs #269
The CommonJS build bundles apg-lite (cjs/apg-lite.cjs) and src/grammar.js is generated by apg-js. The BSD-2-Clause license requires reproducing the copyright notice and license in binary distributions. Refs #269
Runs the artifact smoke test and type checks after the build, verifies the tarball contains the generated declarations, and installs it into a new project on every Node.js version from engines up. Refs #269
char0n
force-pushed
the
fix/issue-269
branch
from
November 26, 2026 10:08
9d7f27f to
318413e
Compare
Member
Author
|
🎉 This PR is included in version 3.0.3 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
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.
Fixes all items of #269, one commit per item, following the fixes in swaggerexpert/media-types.
./evaluate/realms/jsonand./evaluate/realms/map-setas reported in the commentfix(types): provide CommonJS declarations for all entry pointsnew Grammar()(TS7009)fix(types): declare Grammar as class with construct signaturetestJSONPointer/testReferenceTokenfix(types): return boolean from JSON Pointer and token test functionsfix(errors): keep error names in minified browser bundlerequirefix(build): make UMD bundles loadable via requirefix(build): resolve apg-lite path independently of cwd and platformTrace.inferExpectations()wrong expectationsfix(parse): infer expectations at furthest offset onlytest(parse): cover escaping of XML special characterstest:watchignores nested fileschore(scripts): watch nested files in test:watchdocs(NOTICE): add apg-lite copyright and licenseci: test built artifacts, typings and installed tarballDifferences from the media-types fixes
scripts/build-types.cjsgenerates a.d.ctsfor every.d.ts(not onlyindex.d.ts), rewriting relative.jsimports to.cjs, so the realm declarations reference the CommonJS index declarations.@arethetypeswrong/clion the packed tarball: 🟢 for node16 (CJS and ESM) and bundler on all entry points (was 👺 Masquerading as ESM).testArrayLocation,testArrayIndexandtestArrayDashkeep their predicates, as they narrow to literal types and are sound.unescapedincludes%x00-2E), so the\u0000sentinel would be consumed. It is also not needed: every failing JSON Pointer ends with a failed terminal at the furthest offset (/at start,0/1after~).parse('/a~')now expects"0", "1"(was"0", "1", "/").& < > " 'intoXml()(and replaces characters invalid in XML with U+FFFD, as its caveat comment says). This PR only adds a regression test.Review follow-ups
fix(parse): infer no expectations after successful parse:parse('/a', { trace: true }).trace.inferExpectations()returned"\x00-."(regression of item 7,mainreturned[]);"/\are escaped and code points above 0xFF use\u{...}fix(build): rewrite all relative specifiers in CommonJS declarations: alsoimport()types,require(), side-effect imports; the build fails on extensionless relative specifiers and removes stale.d.ctsdocs(NOTICE): mention apg-lite bundled in UMD browser bundlestest(artifacts): require UMD bundles on Node.js >= 14.6 only: bundles use private class methodsci: verify tarball contains generated declarations: the.d.ctsfiles anddist/package.jsonare gitignoredNot addressed:
node10resolution of the realm subpaths (pre-existing, same in 3.0.2) anddist/not being inexports(bundles are meant for CDNs / loading by path).Verification
npm test: 310 passingnpm run test:artifacts: CommonJS, ES module, realms, UMD viarequireand browser global; fails before the fix withReferenceError: self is not definednpm run test:types:tsc --strictfor.cts/.mtsconsumers (node16) and bundler; reproduces TS1479 / TS7009 / never-narrowing before the fixesCloses #269