Skip to content

Commit d2e236b

Browse files
committed
Fix ESM output for native Node.js usage
1 parent 0d395fc commit d2e236b

File tree

10 files changed

+33
-21
lines changed

10 files changed

+33
-21
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export NODE_OPTIONS := --experimental-vm-modules --redirect-warnings=artifacts/node-warnings
2+
13
JS_SIZE_LIMIT_REQ += artifacts/dist
24

35
################################################################################

jest.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import config from "@snout/jest-config";
33
export default {
44
...config,
55
transform: {
6-
"\\.tsx?$": ["ts-jest", { tsconfig: "test/tsconfig.json" }],
6+
"^.+\\.tsx?$": [
7+
"ts-jest",
8+
{
9+
useESM: true,
10+
tsconfig: "test/tsconfig.json",
11+
},
12+
],
713
},
814
};

package.json

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@
2020
"main": "artifacts/dist/index.js",
2121
"types": "artifacts/dist/index.d.ts",
2222
"exports": {
23-
".": "./artifacts/dist/index.js"
23+
".": {
24+
"types": "./artifacts/dist/index.d.ts",
25+
"import": "./artifacts/dist/index.js",
26+
"default": "./artifacts/dist/index.js"
27+
}
2428
},
2529
"sideEffects": false,
2630
"files": [
@@ -35,20 +39,20 @@
3539
"size-limit-clean": "rm -rf artifacts/dist"
3640
},
3741
"dependencies": {
38-
"@snout/regexp": "^0.3.0"
42+
"@snout/regexp": "^0.3.2"
3943
},
4044
"peerDependencies": {
4145
"@snout/router-path": "^0.6.0"
4246
},
4347
"devDependencies": {
4448
"@size-limit/preset-small-lib": "^8.0.0",
4549
"@snout/eslint-config": "^3.2.2",
46-
"@snout/jest-config": "^2.1.0",
50+
"@snout/jest-config": "^3.0.0",
4751
"@snout/router-path": "^0.7.2",
48-
"@snout/tsconfig": "^2.0.0",
52+
"@snout/tsconfig": "^3.0.0",
4953
"prettier": "^2.7.1",
5054
"prettier-plugin-organize-imports": "^3.0.0",
5155
"size-limit": "^8.0.0",
52-
"typescript": "^4.4.3"
56+
"typescript": "^4.8.4"
5357
}
5458
}

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { int } from "./coercion";
2-
export { optional } from "./optional";
3-
export { any, some } from "./repeating";
4-
export { createSlash, slash } from "./slash";
1+
export { int } from "./coercion.js";
2+
export { optional } from "./optional.js";
3+
export { any, some } from "./repeating.js";
4+
export { createSlash, slash } from "./slash.js";

test/unit/any.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { path } from "@snout/router-path";
2-
import { any } from "../../src/repeating";
2+
import { any } from "../../src/repeating.js";
33

44
describe("any()", () => {
55
it("should allow building from an array", () => {

test/unit/index.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { int } from "../../src/coercion";
2-
import * as index from "../../src/index";
3-
import { optional } from "../../src/optional";
4-
import { any, some } from "../../src/repeating";
5-
import { createSlash, slash } from "../../src/slash";
1+
import { int } from "../../src/coercion.js";
2+
import * as index from "../../src/index.js";
3+
import { optional } from "../../src/optional.js";
4+
import { any, some } from "../../src/repeating.js";
5+
import { createSlash, slash } from "../../src/slash.js";
66

77
describe("module index", () => {
88
it("should provide access to int()", () => {

test/unit/int.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { path } from "@snout/router-path";
2-
import { int } from "../../src/coercion";
2+
import { int } from "../../src/coercion.js";
33

44
describe("int()", () => {
55
it("should allow building from a number", () => {

test/unit/optional.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { normalizeParam, path } from "@snout/router-path";
2-
import { int } from "../../src/coercion";
3-
import { optional } from "../../src/optional";
2+
import { int } from "../../src/coercion.js";
3+
import { optional } from "../../src/optional.js";
44

55
describe("optional()", () => {
66
it("should allow building with or without a defined arg", () => {

test/unit/slash.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { path } from "@snout/router-path";
2-
import { createSlash, slash } from "../../src/slash";
2+
import { createSlash, slash } from "../../src/slash.js";
33

44
describe("createSlash()", () => {
55
it("should allow building with a boolean indicating whether to include the slash", () => {

test/unit/some.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { path } from "@snout/router-path";
2-
import { some } from "../../src/repeating";
2+
import { some } from "../../src/repeating.js";
33

44
describe("some()", () => {
55
it("should allow building from an array", () => {

0 commit comments

Comments
 (0)