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

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

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.

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

Comment thread src/jsonpath.js Outdated
Comment thread src/jsonpath.js
@brettz9 brettz9 changed the title Updates TypeScript-as-JSDoc and updates Jul 30, 2026
@brettz9
brettz9 force-pushed the updates branch 4 times, most recently from 57a858a to 3c5dc94 Compare July 30, 2026 12:55
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.

Typescript comilation failes when using the sandbox setting

2 participants