From d2e236bfdf88a6bbb1c56e934ed3b47bcd0501fc Mon Sep 17 00:00:00 2001 From: Erin Millard Date: Sat, 29 Oct 2022 10:30:46 +1000 Subject: [PATCH] Fix ESM output for native Node.js usage --- Makefile | 2 ++ jest.config.js | 8 +++++++- package.json | 14 +++++++++----- src/index.ts | 8 ++++---- test/unit/any.spec.ts | 2 +- test/unit/index.spec.ts | 10 +++++----- test/unit/int.spec.ts | 2 +- test/unit/optional.spec.ts | 4 ++-- test/unit/slash.spec.ts | 2 +- test/unit/some.spec.ts | 2 +- 10 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 3521cb1..205a465 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +export NODE_OPTIONS := --experimental-vm-modules --redirect-warnings=artifacts/node-warnings + JS_SIZE_LIMIT_REQ += artifacts/dist ################################################################################ diff --git a/jest.config.js b/jest.config.js index 1d1333f..8f877ff 100644 --- a/jest.config.js +++ b/jest.config.js @@ -3,6 +3,12 @@ import config from "@snout/jest-config"; export default { ...config, transform: { - "\\.tsx?$": ["ts-jest", { tsconfig: "test/tsconfig.json" }], + "^.+\\.tsx?$": [ + "ts-jest", + { + useESM: true, + tsconfig: "test/tsconfig.json", + }, + ], }, }; diff --git a/package.json b/package.json index 9e6a7f2..6f7d543 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,11 @@ "main": "artifacts/dist/index.js", "types": "artifacts/dist/index.d.ts", "exports": { - ".": "./artifacts/dist/index.js" + ".": { + "types": "./artifacts/dist/index.d.ts", + "import": "./artifacts/dist/index.js", + "default": "./artifacts/dist/index.js" + } }, "sideEffects": false, "files": [ @@ -35,7 +39,7 @@ "size-limit-clean": "rm -rf artifacts/dist" }, "dependencies": { - "@snout/regexp": "^0.3.0" + "@snout/regexp": "^0.3.2" }, "peerDependencies": { "@snout/router-path": "^0.6.0" @@ -43,12 +47,12 @@ "devDependencies": { "@size-limit/preset-small-lib": "^8.0.0", "@snout/eslint-config": "^3.2.2", - "@snout/jest-config": "^2.1.0", + "@snout/jest-config": "^3.0.0", "@snout/router-path": "^0.7.2", - "@snout/tsconfig": "^2.0.0", + "@snout/tsconfig": "^3.0.0", "prettier": "^2.7.1", "prettier-plugin-organize-imports": "^3.0.0", "size-limit": "^8.0.0", - "typescript": "^4.4.3" + "typescript": "^4.8.4" } } diff --git a/src/index.ts b/src/index.ts index 6fe83de..d2192b0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -export { int } from "./coercion"; -export { optional } from "./optional"; -export { any, some } from "./repeating"; -export { createSlash, slash } from "./slash"; +export { int } from "./coercion.js"; +export { optional } from "./optional.js"; +export { any, some } from "./repeating.js"; +export { createSlash, slash } from "./slash.js"; diff --git a/test/unit/any.spec.ts b/test/unit/any.spec.ts index 0fff5b1..8e62e51 100644 --- a/test/unit/any.spec.ts +++ b/test/unit/any.spec.ts @@ -1,5 +1,5 @@ import { path } from "@snout/router-path"; -import { any } from "../../src/repeating"; +import { any } from "../../src/repeating.js"; describe("any()", () => { it("should allow building from an array", () => { diff --git a/test/unit/index.spec.ts b/test/unit/index.spec.ts index f9d8026..480ca84 100644 --- a/test/unit/index.spec.ts +++ b/test/unit/index.spec.ts @@ -1,8 +1,8 @@ -import { int } from "../../src/coercion"; -import * as index from "../../src/index"; -import { optional } from "../../src/optional"; -import { any, some } from "../../src/repeating"; -import { createSlash, slash } from "../../src/slash"; +import { int } from "../../src/coercion.js"; +import * as index from "../../src/index.js"; +import { optional } from "../../src/optional.js"; +import { any, some } from "../../src/repeating.js"; +import { createSlash, slash } from "../../src/slash.js"; describe("module index", () => { it("should provide access to int()", () => { diff --git a/test/unit/int.spec.ts b/test/unit/int.spec.ts index e116ab5..0329309 100644 --- a/test/unit/int.spec.ts +++ b/test/unit/int.spec.ts @@ -1,5 +1,5 @@ import { path } from "@snout/router-path"; -import { int } from "../../src/coercion"; +import { int } from "../../src/coercion.js"; describe("int()", () => { it("should allow building from a number", () => { diff --git a/test/unit/optional.spec.ts b/test/unit/optional.spec.ts index 1d63146..77de368 100644 --- a/test/unit/optional.spec.ts +++ b/test/unit/optional.spec.ts @@ -1,6 +1,6 @@ import { normalizeParam, path } from "@snout/router-path"; -import { int } from "../../src/coercion"; -import { optional } from "../../src/optional"; +import { int } from "../../src/coercion.js"; +import { optional } from "../../src/optional.js"; describe("optional()", () => { it("should allow building with or without a defined arg", () => { diff --git a/test/unit/slash.spec.ts b/test/unit/slash.spec.ts index a1abbe5..03e2e1c 100644 --- a/test/unit/slash.spec.ts +++ b/test/unit/slash.spec.ts @@ -1,5 +1,5 @@ import { path } from "@snout/router-path"; -import { createSlash, slash } from "../../src/slash"; +import { createSlash, slash } from "../../src/slash.js"; describe("createSlash()", () => { it("should allow building with a boolean indicating whether to include the slash", () => { diff --git a/test/unit/some.spec.ts b/test/unit/some.spec.ts index 2ca0217..7171b5e 100644 --- a/test/unit/some.spec.ts +++ b/test/unit/some.spec.ts @@ -1,5 +1,5 @@ import { path } from "@snout/router-path"; -import { some } from "../../src/repeating"; +import { some } from "../../src/repeating.js"; describe("some()", () => { it("should allow building from an array", () => {