Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ jobs:
- name: Execute tests
run: npm test

- name: Test artifacts
run: npm run test:artifacts

- name: Test typings
run: npm run test:types

- name: Semantic Release
env:
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,58 @@ jobs:
run: npm ci
- name: Execute tests
run: npm test
- name: Build artifacts
run: npm run build
- name: Test artifacts
run: npm run test:artifacts
- name: Test typings
run: npm run test:types
- name: Pack tarball
run: |
mkdir -p pack
npm pack --pack-destination ./pack
- name: Verify tarball contains generated declarations
run: |
# generated files are gitignored, so make sure they are published
contents="$(tar -tzf pack/*.tgz)"
for file in types/index.d.cts types/evaluate/realms/json.d.cts types/evaluate/realms/map-set.d.cts; do
echo "$contents" | grep -qx "package/$file" || { echo "missing $file"; exit 1; }
done
- name: Upload tarball
uses: actions/upload-artifact@v7
with:
name: tarball
path: |
pack/*.tgz
test/artifacts/smoke.cjs

compatibility:
needs: test
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
# oldest supported version (engines in package.json) and maintained versions
node-version: [ 12.20.0, 14, 16, 18, 20, 22, 24, 26 ]

steps:
- name: Download tarball
uses: actions/download-artifact@v8
with:
name: tarball
- name: Use Node.js
uses: actions/setup-node@v7
with:
node-version: ${{ matrix.node-version }}
- name: Install tarball into a new project
run: |
mkdir consumer
cd consumer
npm init -y
npm install ../pack/*.tgz
# the package is resolved relative to the script, so the script must be inside the project
cp ../test/artifacts/smoke.cjs .
- name: Test installed package
working-directory: consumer
run: node smoke.cjs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ node_modules/
/es
/dist
/swaggerexpert-json-pointer-*.tgz
/types/**/*.d.cts
/pack
6 changes: 4 additions & 2 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ npm run grammar:compile # Compile ABNF grammar to parser (src/grammar.bnf → s
npm test # Run all tests with Mocha
npm test -- --grep "pattern" # Run specific tests matching pattern
npm test -- test/parse/index.js # Run a single test file
npm run test:artifacts # Smoke test built artifacts (es/, cjs/, dist/), run after npm run build
npm run test:types # Type check typings as CommonJS and ES module consumers, run after npm run build
```

## Architecture
Expand Down Expand Up @@ -57,7 +59,7 @@ Located in `src/parse/translators/`:

### Error Hierarchy

All errors extend `JSONPointerError`:
All errors extend `JSONPointerError`. Error classes define their `name` explicitly, as minifiers mangle class names:
- `JSONPointerParseError` - Invalid pointer syntax
- `JSONPointerCompileError` - Invalid reference tokens during compilation
- `JSONPointerEvaluateError` - Base for evaluation errors
Expand All @@ -72,4 +74,4 @@ The build produces three formats:
- `cjs/` - CommonJS (.cjs)
- `dist/` - UMD browser bundles (json-pointer.browser.js, json-pointer.browser.min.js)

TypeScript types are in `types/index.d.ts`.
TypeScript types are in `types/`; the build generates gitignored `.d.cts` copies for the `require` export conditions.
27 changes: 27 additions & 0 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,30 @@ https://datatracker.ietf.org/doc/html/rfc6901
Majority of ABNF grammar (grammar.bnf) and certain texts within the README.md file
are licensed under Revised BSD License - https://spdx.org/licenses/BSD-3-Clause.html.

apg-lite
Copyright (c) 2023 Lowell D. Thomas
https://github.com/ldthomas/apg-lite
The CommonJS build (cjs/apg-lite.cjs) and the UMD browser bundles (dist/) bundle apg-lite,
and src/grammar.js is generated by apg-js.
apg-lite is licensed under 2-Clause BSD License - https://spdx.org/licenses/BSD-2-Clause.html:

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 changes: 24 additions & 13 deletions babel.config.cjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
const path = require('node:path');

/**
* apg-lite is an ES module, so the CommonJS build (kept for backward compatibility)
* bundles its own copy at cjs/apg-lite.cjs. Imports of apg-lite are rewritten to a relative path
* to that copy, mirroring src/ layout in the output directory, independent of the current working
* directory and platform path separators.
*/
const resolveApgLite = (extension) => [
'module-resolver',
{
resolvePath(sourcePath, currentFile) {
if (sourcePath !== 'apg-lite') return sourcePath;

const apgLite = path.join(__dirname, 'src', `apg-lite.${extension}`);
const relativePath = path
.relative(path.dirname(currentFile), apgLite)
.split(path.sep)
.join('/');

return relativePath.startsWith('.') ? relativePath : `./${relativePath}`;
},
},
];

module.exports = {
env: {
cjs: {
Expand All @@ -21,19 +44,7 @@ module.exports = {
path.join(__dirname, './scripts/babel-plugin-add-import-extension.cjs'),
{ extension: 'cjs' },
],
[
'module-resolver',
{
resolvePath(sourcePath, currentFile) {
if (sourcePath === 'apg-lite') {
const apgLiteCJS = path.resolve('./src/apg-lite.cjs');
const currentDir = path.dirname(currentFile);
return path.relative(currentDir, apgLiteCJS);
}
return sourcePath;
},
},
],
resolveApgLite('cjs'),
],
},
es: {
Expand Down
4 changes: 4 additions & 0 deletions config/webpack/browser.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const browser = {
filename: 'json-pointer.browser.js',
libraryTarget: 'umd',
library: 'JSONPointer',
// works in browsers, web workers and CommonJS (where self is not defined)
globalObject: "typeof self !== 'undefined' ? self : this",
},
resolve: {
extensions: ['.js'],
Expand Down Expand Up @@ -40,6 +42,8 @@ const browserMin = {
filename: 'json-pointer.browser.min.js',
libraryTarget: 'umd',
library: 'JSONPointer',
// works in browsers, web workers and CommonJS (where self is not defined)
globalObject: "typeof self !== 'undefined' ? self : this",
},
resolve: {
extensions: ['.js'],
Expand Down
Loading
Loading