Skip to content

TypeScript-as-JSDoc and updates - #269

Open
brettz9 wants to merge 1 commit into
JSONPath-Plus:mainfrom
brettz9:updates
Open

TypeScript-as-JSDoc and updates#269
brettz9 wants to merge 1 commit into
JSONPath-Plus:mainfrom
brettz9:updates

Conversation

@brettz9

@brettz9brettz9 commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

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:

  • chore: various changes in types, particularly with return values changing from any to unknown to ensure type safety (by forcing type casts of the results on the user).
  • refactor: should not affect most users, but monkey-patching should now be done on the JSONPathClass export

Other changes:

  • refactor: implement TypeScript-as-JSDoc and auto-build declaration files from this (avoiding need for maintaining declaration file manually)
  • chore: update devDeps
  • chore: lint

Fixes#114 ; closes#113 ; closes#115 .

Checklist

  • - Added tests
  • - Ran npm test, ensuring linting passes
  • - Adjust README documentation if relevant

CopilotAI 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.

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 JSONPathClass implementation (and update Node/browser adapters and tests accordingly).
  • Adopt TS checking for JS (allowJs/checkJs) and switch from a hand-written src/jsonpath.d.ts to generated dist/*.d.ts (including *.d.cts for 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
FileDescription
tsconfig.jsonEnables JS type-checking and declaration generation settings for the repo.
tsconfig-prod.jsonAdds a production TS config to emit declaration files.
test/test.type-operators.jsUpdates tests to use imported callback types and tighter JSDoc annotations.
test/test.toPath.jsUses Chai lengthOf assertion style for array length checks.
test/test.safe-eval.jsAdds JSDoc imports/types and TS-expect-error markers for VM/security tests.
test/test.performance.jsRefactors test data setup and adds JSDoc types to satisfy checkJs.
test/test.path_expressions.jsUpdates reference URL to HTTPS.
test/test.intermixed.arr.jsAdds type casts for spread use under checkJs.
test/test.examples.jsUpdates reference URL, refactors expected building, and adds JSDoc typing.
test/test.eval.jsUpdates VM access to JSONPathClass.prototype.* and adds JSDoc imports/types.
test/test.errors.jsAdds TS-expect-error for intentionally invalid argument test.
test/test.cli.jsAdds cast for stderr typing under checkJs.
test/test.callback.jsTightens callback param typing and result typing for checkJs.
test/test.at_and_dollar.jsAvoids implicit globals by typing globalThis usage for tests.
test/test.api.jsAdds many new regression tests and types jsonpath() results as JSONPathClass.
test/test.all.jsRe-formats expected objects (likely lint/style driven).
test-helpers/node-env.jsExposes JSONPathClass on globalThis for tests.
test-helpers/checkVM.jsIntroduces VmType typedef and type annotations for VM iteration.
src/Safe-Script.jsAdds JSDoc typing throughout safe-eval implementation and improves error construction.
src/jsonpath.jsMajor refactor: introduces JSONPathClass, moves methods, tightens types, and changes monkey-patching surface.
src/jsonpath.d.tsRemoves the old hand-authored declaration file in favor of generated typings.
src/jsonpath-node.jsMoves vm monkey-patching target to JSONPathClass.prototype and adds typedef re-exports.
src/jsonpath-node.ctsAdds CJS typing entry for Node build.
src/jsonpath-browser.jsMoves browser Script monkey-patching to JSONPathClass.prototype and adds typedef re-exports.
rollup.config.jsUpdates JSDoc typing for Rollup config and TS checking compatibility.
pnpm-workspace.yamlAdds minimumReleaseAgeExclude exceptions for specific packages.
package.jsonUpdates exports/types mapping to generated dist typings; updates devDeps; adds build/attw scripts.
eslint.config.jsUpdates config typing, import plugin rule names (import-x/*), and test globals.
dist/Safe-Script.d.tsAdds generated declaration output for Safe-Script.
dist/jsonpath.d.tsAdds generated declaration output for the main entry.
dist/jsonpath-node.d.tsAdds generated declaration output for the Node entry.
dist/jsonpath-node.d.ctsAdds generated CJS declaration entry for Node.
dist/jsonpath-browser.d.tsAdds generated declaration output for the browser entry.
dist/index-browser-umd.min.cjsUpdates built/minified UMD bundle output.
dist/index-browser-esm.min.jsUpdates built/minified ESM bundle output.
demo/tsconfig.jsonAdds demo-specific TS config (DOM libs) for checkJs friendliness.
demo/index.jsTightens DOM element typing and adjusts URL/history usage for type checking.
bin/jsonpath-cli.jsSwitches CLI to import the Node implementation from src/ and adds JSONValue typing.
badges/tests-badge.svgUpdates test badge counts.
.ncurc.cjsAdds npm-check-updates configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment threadsrc/jsonpath.js Outdated
Comment threadsrc/jsonpath.js
@brettz9brettz9 changed the title UpdatesTypeScript-as-JSDoc and updatesJul 30, 2026
@brettz9
brettz9force-pushed the updates branch 4 times, most recently from 57a858a to 3c5dc94CompareJuly 30, 2026 12:55
@brettz9

Copy link
Copy Markdown
CollaboratorAuthor

@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.

@80avin

Copy link
Copy Markdown
Collaborator

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.

Sign up for freeto 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.

Typescript comilation failes when using the sandbox setting

3 participants

@brettz9@80avin