Skip to content

Commit 35afd8f

Browse files
authored
build: fix cli build / modernize (#74)
<!-- ps-id: d669b3d0-e0e6-4462-8e45-666751095542 -->
1 parent 3956d25 commit 35afd8f

File tree

10 files changed

+868
-680
lines changed

10 files changed

+868
-680
lines changed

.github/workflows/publish.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ jobs:
3939
- run: npm run build
4040
- name: 🔍 Validate build artifacts
4141
run: |
42-
test -f dist/jmespath.umd.js || (echo "Missing UMD bundle" && exit 1)
43-
test -f dist/jmespath.esm.js || (echo "Missing ESM bundle" && exit 1)
44-
test -f dist/types/index.d.ts || (echo "Missing TypeScript declarations" && exit 1)
45-
test -f dist/lib/bin/jp.js || (echo "Missing CLI binary" && exit 1)
46-
head -1 dist/lib/bin/jp.js | grep -q "^#!" || (echo "CLI binary missing shebang" && exit 1)
42+
test -f dist/index.umd.js || (echo "Missing UMD bundle" && exit 1)
43+
test -f dist/index.umd.min.js || (echo "Missing minified UMD bundle" && exit 1)
44+
test -f dist/index.esm.js || (echo "Missing browser ESM bundle" && exit 1)
45+
test -f dist/index.esm.min.js || (echo "Missing minified browser ESM bundle" && exit 1)
46+
test -f dist/index.cjs || (echo "Missing Node.js CommonJS bundle" && exit 1)
47+
test -f dist/index.mjs || (echo "Missing Node.js ESM bundle" && exit 1)
48+
test -f dist/index.d.ts || (echo "Missing TypeScript declarations" && exit 1)
49+
test -f dist/cli.mjs || (echo "Missing CLI binary" && exit 1)
50+
head -1 dist/cli.mjs | grep -q "^#!" || (echo "CLI binary missing shebang" && exit 1)
4751
echo "✅ All build artifacts validated"
4852
- name: 🧪 Test build artifacts
4953
run: npm test -- test/build-artifacts.spec.ts

package-lock.json

Lines changed: 572 additions & 489 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,33 @@
77
"email": "[email protected]",
88
"url": "https://jmespath.site"
99
},
10-
"main": "dist/jmespath.umd.js",
10+
"type": "module",
1111
"bin": {
12-
"jp": "dist/lib/bin/jp.js"
12+
"jp": "./dist/cli.mjs"
1313
},
14-
"module": "dist/jmespath.esm.js",
15-
"typings": "dist/types/index.d.ts",
16-
"types": "dist/types/index.d.ts",
14+
"main": "./dist/index.cjs",
15+
"module": "./dist/index.mjs",
16+
"browser": "./dist/index.umd.js",
17+
"types": "./dist/index.d.ts",
1718
"exports": {
1819
".": {
19-
"types": "./dist/types/index.d.ts",
20-
"import": "./dist/jmespath.esm.js",
21-
"require": "./dist/jmespath.umd.js"
20+
"types": "./dist/index.d.ts",
21+
"browser": {
22+
"import": "./dist/index.esm.js",
23+
"require": "./dist/index.umd.js",
24+
"default": "./dist/index.umd.js"
25+
},
26+
"node": {
27+
"import": "./dist/index.mjs",
28+
"require": "./dist/index.cjs"
29+
},
30+
"import": "./dist/index.mjs",
31+
"require": "./dist/index.cjs"
32+
},
33+
"./cli": {
34+
"types": "./dist/cli.d.ts",
35+
"import": "./dist/cli.mjs",
36+
"require": "./dist/cli.cjs"
2237
}
2338
},
2439
"files": [
@@ -51,9 +66,10 @@
5166
"lint:fix": "biome check --write",
5267
"lint:ci": "biome check --diagnostic-level=error",
5368
"prebuild": "npx rimraf dist",
54-
"build": "npx tsc --outDir dist/lib -d --module commonjs && npx tsc --project tsconfig.bin.json && npx rollup -c rollup.config.ts",
69+
"build": "tsup",
70+
"dev": "ts-node src/cli.ts",
5571
"perf": "node --expose-gc scripts/perf.js",
56-
"start": "npx rollup -c rollup.config.ts -w",
72+
"start": "tsup --watch",
5773
"test": "vitest --run",
5874
"test:watch": "vitest",
5975
"test:prod": "npm run lint && npm run test && npm test -- test/build-artifacts.spec.ts",
@@ -66,21 +82,16 @@
6682
},
6783
"devDependencies": {
6884
"@biomejs/biome": "2.0.6",
69-
"@rollup/plugin-json": "^4.1.0",
70-
"@rollup/plugin-node-resolve": "^13.0.0",
71-
"@rollup/plugin-terser": "^0.4.0",
72-
"@rollup/plugin-typescript": "^8.2.1",
7385
"@vitest/coverage-v8": "^3.2.4",
7486
"clean-publish": "^3.4.5",
7587
"coveralls-next": "^4.2.0",
7688
"husky": "^6.0.0",
7789
"lint-staged": "^11.0.0",
7890
"rimraf": "^3.0.2",
79-
"rollup": "^2.50.5",
80-
"rollup-plugin-typescript2": "^0.36.0",
8191
"shelljs": "^0.8.4",
8292
"tinybench": "^2.5.1",
8393
"ts-node": "^10.9.2",
94+
"tsup": "^8.5.0",
8495
"typescript": "^5.8.3",
8596
"vitest": "^3.2.4"
8697
}

rollup.config.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

bin/jp.ts renamed to src/cli.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
#! /usr/bin/env node
2-
31
'use strict';
42

53
import { ParseArgsConfig, parseArgs } from 'node:util';
64
import * as fs from 'fs';
75
import pkg from '../package.json';
8-
import jmespath, { JSONValue } from '../src';
6+
import jmespath, { JSONValue } from './index';
97

108
const args = getArgs();
119

src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,6 @@ export const jmespath = {
124124
TYPE_STRING,
125125
};
126126

127-
export default jmespath;
127+
// Export as default for backward compatibility
128+
// Supports both: import jmespath from '...' and import { jmespath } from '...'
129+
export { jmespath as default };

0 commit comments

Comments
 (0)