Skip to content

Commit e00bbcb

Browse files
authored
Merge pull request #26 from reilem/fix-for-bundler-resolution
Fix usage with bundler module resolution
2 parents 129dec5 + a4657ba commit e00bbcb

File tree

6 files changed

+127
-2
lines changed

6 files changed

+127
-2
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zod-geojson",
3-
"version": "1.6.1",
3+
"version": "1.6.2",
44
"description": "Zod schemas for GeoJSON",
55
"repository": {
66
"type": "git",
@@ -36,6 +36,7 @@
3636
"test": "jest && pnpm test:esm && pnpm test:cjs",
3737
"test:esm": "pnpm -C tests/esm-testing i --frozen-lockfile && pnpm -C tests/esm-testing start",
3838
"test:cjs": "pnpm -C tests/cjs-testing i --frozen-lockfile && pnpm -C tests/cjs-testing start",
39+
"test:bundled": "pnpm -C tests/bundled-testing i --frozen-lockfile && pnpm -C tests/bundled-testing start",
3940
"clean": "rimraf lib",
4041
"build": "pnpm clean && pnpm zshy",
4142
"typecheck": "tsc",

tests/bundled-testing/package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "zod-geojson-bundled-testing",
3+
"type": "module",
4+
"scripts": {
5+
"start": "pnpm tsc && node lib/index.js"
6+
},
7+
"devDependencies": {
8+
"@types/node": "^24.3.1",
9+
"typescript": "~5.9.2"
10+
},
11+
"dependencies": {
12+
"zod": "~4.1.8",
13+
"zod-geojson": "link:../.."
14+
}
15+
}

tests/bundled-testing/pnpm-lock.yaml

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

tests/bundled-testing/src/index.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { GeoJSONSchema } from "zod-geojson";
2+
3+
function main() {
4+
const badResult = GeoJSONSchema.safeParse({
5+
type: "Feature",
6+
geometry: {
7+
type: "LineString",
8+
coordinates: [[0, 0], [1, 0], [1, 2], []],
9+
},
10+
properties: null,
11+
});
12+
if (badResult.error != null) {
13+
console.log("[PASS] Detects bad GeoJSON");
14+
} else {
15+
console.error("[FAIL] Failed to detect bad GeoJSON");
16+
process.exit(1);
17+
}
18+
19+
const goodResult = GeoJSONSchema.safeParse({
20+
type: "Point",
21+
coordinates: [0.0, 1.0],
22+
});
23+
if (goodResult.error == null) {
24+
console.log("[PASS] Parses good GeoJSON");
25+
} else {
26+
console.error("[FAIL] Failed to parse good GeoJSON");
27+
process.exit(1);
28+
}
29+
}
30+
31+
main();
32+
33+
// TYPES TESTING
34+
35+
// @ts-expect-error -- SHOULD FAIL
36+
if ("anything" in GeoJSONSchema) GeoJSONSchema.anything();
37+
38+
const goodResult = GeoJSONSchema.parse({
39+
type: "Point",
40+
coordinates: [0.0, 1.0],
41+
});
42+
43+
if (goodResult.type === "Point") {
44+
// @ts-expect-error -- SHOULD FAIL
45+
goodResult.geometries = [4, 5];
46+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"compilerOptions": {
3+
"module": "preserve",
4+
"moduleResolution": "bundler",
5+
"strict": true,
6+
"skipLibCheck": true,
7+
"outDir": "lib"
8+
},
9+
"include": ["src"],
10+
"exclude": ["node_modules"]
11+
}

tsconfig.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
{
22
"compilerOptions": {
33
"target": "es2019",
4-
"moduleResolution": "node",
4+
"module": "nodenext",
5+
"moduleResolution": "nodenext",
56
"outDir": "lib",
67
"noEmit": true,
78
"esModuleInterop": true,

0 commit comments

Comments
 (0)