From 9a242225ee4b44ab4b424e3eccc3b1536077a886 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 3 Sep 2026 13:05:20 +0000 Subject: [PATCH] :bug: Use .ts extensions in imports for node --strip-types MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Node's --strip-types does not rewrite import specifiers the way bundlers and Deno do, so 'import ... from "./match.js"' literally looks for match.js (not match.ts) and fails with ERR_MODULE_NOT_FOUND at test time. Fix by switching source imports to .ts extensions and letting TypeScript's rewriteRelativeImportExtensions do the rewrite at build emit time. Changes: - tsconfig.json: enable allowImportingTsExtensions (works because the root config has noEmit: true) - tsconfig.build.json: enable rewriteRelativeImportExtensions so the emitted dist/*.js files keep './match.js' style imports (correct for consumers), not './match.ts' - src/index.ts: import './match.ts' and './pattern.ts' - src/match.ts: import './pattern.ts' - src/index.test.ts: import './index.ts' Verified: npm run test runs tsc --noEmit (passes) and node --test --strip-types src/ — all 6 tests pass. tsc -p tsconfig.build.json emits dist/*.js with './match.js' imports as before; consumers see no change. --- src/index.test.ts | 2 +- src/index.ts | 4 ++-- src/match.ts | 2 +- tsconfig.build.json | 1 + tsconfig.json | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/index.test.ts b/src/index.test.ts index 24b6a2e..3f47feb 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -1,7 +1,7 @@ import { test } from "node:test"; import { strict as assert } from "node:assert"; import { expectTypeOf } from "expect-type"; -import { match, P, type Matcher } from "./index.js"; +import { match, P, type Matcher } from "./index.ts"; test("match returns a builder", () => { const builder = match("x"); diff --git a/src/index.ts b/src/index.ts index 970ea6a..20f0ec7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,2 +1,2 @@ -export { match, P } from "./match.js"; -export type { Matcher, Pattern } from "./pattern.js"; +export { match, P } from "./match.ts"; +export type { Matcher, Pattern } from "./pattern.ts"; diff --git a/src/match.ts b/src/match.ts index 6487acb..a7b6c84 100644 --- a/src/match.ts +++ b/src/match.ts @@ -1,4 +1,4 @@ -import { P, type Matcher, type Pattern } from "./pattern.js"; +import { P, type Matcher, type Pattern } from "./pattern.ts"; type Cases = ReadonlyArray< readonly [Matcher, (value: unknown) => R] diff --git a/tsconfig.build.json b/tsconfig.build.json index dd7d10f..2342359 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "noEmit": false, + "rewriteRelativeImportExtensions": true, "rootDir": "src", "outDir": "dist" }, diff --git a/tsconfig.json b/tsconfig.json index e5c3c91..e3bea47 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -23,6 +23,7 @@ "noUnusedParameters": true, "isolatedModules": true, "verbatimModuleSyntax": true, + "allowImportingTsExtensions": true, "declaration": true, "declarationMap": true, "sourceMap": true, @@ -34,4 +35,4 @@ "types": ["node"] }, "include": ["src"] -} \ No newline at end of file +}