TypeScript-as-JSDoc and updates - #269
Conversation
There was a problem hiding this comment.
Pull request overview
This PR modernizes the project’s TypeScript typing story (via TypeScript-as-JSDoc + generated declaration files) while refactoring the runtime to expose a JSONPathClass for monkey-patching, alongside dependency/tooling updates and corresponding test adjustments.
Changes:
- Refactor core runtime to use a
JSONPathClassimplementation (and update Node/browser adapters and tests accordingly). - Adopt TS checking for JS (
allowJs/checkJs) and switch from a hand-writtensrc/jsonpath.d.tsto generateddist/*.d.ts(including*.d.ctsfor CJS typing). - Update lint/build config and dev dependencies; refresh/expand tests to align with stricter typings.
Reviewed changes
Copilot reviewed 29 out of 47 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| tsconfig.json | Enables JS type-checking and declaration generation settings for the repo. |
| tsconfig-prod.json | Adds a production TS config to emit declaration files. |
| test/test.type-operators.js | Updates tests to use imported callback types and tighter JSDoc annotations. |
| test/test.toPath.js | Uses Chai lengthOf assertion style for array length checks. |
| test/test.safe-eval.js | Adds JSDoc imports/types and TS-expect-error markers for VM/security tests. |
| test/test.performance.js | Refactors test data setup and adds JSDoc types to satisfy checkJs. |
| test/test.path_expressions.js | Updates reference URL to HTTPS. |
| test/test.intermixed.arr.js | Adds type casts for spread use under checkJs. |
| test/test.examples.js | Updates reference URL, refactors expected building, and adds JSDoc typing. |
| test/test.eval.js | Updates VM access to JSONPathClass.prototype.* and adds JSDoc imports/types. |
| test/test.errors.js | Adds TS-expect-error for intentionally invalid argument test. |
| test/test.cli.js | Adds cast for stderr typing under checkJs. |
| test/test.callback.js | Tightens callback param typing and result typing for checkJs. |
| test/test.at_and_dollar.js | Avoids implicit globals by typing globalThis usage for tests. |
| test/test.api.js | Adds many new regression tests and types jsonpath() results as JSONPathClass. |
| test/test.all.js | Re-formats expected objects (likely lint/style driven). |
| test-helpers/node-env.js | Exposes JSONPathClass on globalThis for tests. |
| test-helpers/checkVM.js | Introduces VmType typedef and type annotations for VM iteration. |
| src/Safe-Script.js | Adds JSDoc typing throughout safe-eval implementation and improves error construction. |
| src/jsonpath.js | Major refactor: introduces JSONPathClass, moves methods, tightens types, and changes monkey-patching surface. |
| src/jsonpath.d.ts | Removes the old hand-authored declaration file in favor of generated typings. |
| src/jsonpath-node.js | Moves vm monkey-patching target to JSONPathClass.prototype and adds typedef re-exports. |
| src/jsonpath-node.cts | Adds CJS typing entry for Node build. |
| src/jsonpath-browser.js | Moves browser Script monkey-patching to JSONPathClass.prototype and adds typedef re-exports. |
| rollup.config.js | Updates JSDoc typing for Rollup config and TS checking compatibility. |
| pnpm-workspace.yaml | Adds minimumReleaseAgeExclude exceptions for specific packages. |
| package.json | Updates exports/types mapping to generated dist typings; updates devDeps; adds build/attw scripts. |
| eslint.config.js | Updates config typing, import plugin rule names (import-x/*), and test globals. |
| dist/Safe-Script.d.ts | Adds generated declaration output for Safe-Script. |
| dist/jsonpath.d.ts | Adds generated declaration output for the main entry. |
| dist/jsonpath-node.d.ts | Adds generated declaration output for the Node entry. |
| dist/jsonpath-node.d.cts | Adds generated CJS declaration entry for Node. |
| dist/jsonpath-browser.d.ts | Adds generated declaration output for the browser entry. |
| dist/index-browser-umd.min.cjs | Updates built/minified UMD bundle output. |
| dist/index-browser-esm.min.js | Updates built/minified ESM bundle output. |
| demo/tsconfig.json | Adds demo-specific TS config (DOM libs) for checkJs friendliness. |
| demo/index.js | Tightens DOM element typing and adjusts URL/history usage for type checking. |
| bin/jsonpath-cli.js | Switches CLI to import the Node implementation from src/ and adds JSONValue typing. |
| badges/tests-badge.svg | Updates test badge counts. |
| .ncurc.cjs | Adds npm-check-updates configuration. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
57a858a to
3c5dc94
Compare
|
@80avin : If you need more time to review that's fine, but I think it'd really be a good idea to get this merged before there is too much diff noise from any other PRs that come our way. |
|
Hey @brettz9 , sorry for delaying it this much. I've been in some events for the last few weeks, got free around 2 days back only. The PR looks good overall but I haven't had a thorough look. I'll review it by tomorrow. |
|
Also, if you don't mind, here are some more issues found by AI. I've verified them, but would accept it if you want to deprioritise any.
|
Also: - fix: drop need for assertions - chore: rebuild
Also: - refactor: drop need for NewError using `new.target`
|
I think the AI-inspired issues should now all be fixed... |
PR description
@80avin : If you could take a look, I figure with you maintaining now, that I should get your approval first. There is a lot of diff noise, but I think it is worth adopting.
BREAKING CHANGES:
anytounknownto ensure type safety (by forcing type casts of the results on the user).Other changes:
Fixes #114 ; closes #113 ; closes #115 .
Checklist
npm test, ensuring linting passes