Skip to content

Commit e5da940

Browse files
authored
chores: tsconfig module: node20 and import extensions (#2974)
`module: node20` introduced in Typescript 5.9 as a stable replacement for `nodenext`: https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-9.html#support-for---module-node20 The recommended combination is with `moduleResolution: node16`: microsoft/TypeScript#61805 That change implies relative imports to have extensions, however, it's possible to change them directly to `.ts`, which will also reiterate and resolve #2289 . It will enable running typescript natively by Node.js without `tsx`. It may also come handy if I decide to publish to JSR. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - Chores - Project build and compiler settings standardized; JSON imports made explicit and some tooling switched to static JSON imports. - Refactor - Internal module references normalized to explicit TypeScript entries; some runtime identifiers now derive from environment-provided build metadata. - Tests - Test imports updated for explicit module resolution; migration tests expanded with additional valid cases. - Style - New lint rules encourage .ts extensions for local imports and discourage direct package.json imports. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent a99cbf4 commit e5da940

File tree

117 files changed

+402
-412
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+402
-412
lines changed

compat-test/quick-start.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
expect,
99
test,
1010
} from "vitest";
11-
import { givePort } from "../tools/ports";
11+
import { givePort } from "../tools/ports.ts";
1212

1313
describe("ESM Test", async () => {
1414
let out = "";

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ const importConcerns = [
2424
selector: "ImportDeclaration[source.value=/^zod/] > ImportDefaultSpecifier",
2525
message: "do import { z } instead",
2626
},
27+
{
28+
selector: "ImportDeclaration[source.value=/\\.js$/]",
29+
message: "use .ts extension for relative imports",
30+
},
2731
...builtinModules.map((mod) => ({
2832
selector: `ImportDeclaration[source.value='${mod}']`,
2933
message: `use node:${mod} for the built-in module`,
@@ -64,6 +68,10 @@ const performanceConcerns = [
6468
selector: "MemberExpression[object.name='R'] > Identifier[name='union']", // #2599
6569
message: "R.union() is 1.5x slower than [...Set().add()]",
6670
},
71+
{
72+
selector: "ImportDeclaration[source.value=/package.json$/]", // #2974
73+
message: "it can not be tree shaken, use tsdown and process.env instead",
74+
},
6775
];
6876

6977
const tsFactoryConcerns = [

esm-test/quick-start.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { spawn } from "node:child_process";
2-
import { givePort } from "../tools/ports";
2+
import { givePort } from "../tools/ports.ts";
33

44
describe("ESM Test", async () => {
55
let out = "";

esm-test/tsconfig.json

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

example/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { BuiltinLogger, createConfig } from "express-zod-api";
22
import ui from "swagger-ui-express";
33
import createHttpError from "http-errors";
4-
import { givePort } from "../tools/ports";
4+
import { givePort } from "../tools/ports.ts";
55
import qs from "qs";
66

77
export const config = createConfig({

example/endpoints/create-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createHttpError from "http-errors";
22
import assert from "node:assert/strict";
33
import { z } from "zod";
4-
import { statusDependingFactory } from "../factories";
4+
import { statusDependingFactory } from "../factories.ts";
55

66
const namePart = z.string().regex(/^\w+$/);
77

example/endpoints/delete-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import createHttpError from "http-errors";
22
import assert from "node:assert/strict";
33
import { z } from "zod";
4-
import { noContentFactory } from "../factories";
4+
import { noContentFactory } from "../factories.ts";
55

66
/** @desc The endpoint demonstrates no content response established by its factory */
77
export const deleteUserEndpoint = noContentFactory.buildVoid({

example/endpoints/list-users.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from "zod";
2-
import { arrayRespondingFactory } from "../factories";
2+
import { arrayRespondingFactory } from "../factories.ts";
33

44
const roleSchema = z.enum(["manager", "operator", "admin"]);
55

example/endpoints/retrieve-user.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import createHttpError from "http-errors";
22
import assert from "node:assert/strict";
33
import { z } from "zod";
44
import { defaultEndpointsFactory } from "express-zod-api";
5-
import { methodProviderMiddleware } from "../middlewares";
5+
import { methodProviderMiddleware } from "../middlewares.ts";
66

77
// Demonstrating circular schemas using z.object()
88
const feature = z.object({

example/endpoints/send-avatar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { z } from "zod";
2-
import { fileSendingEndpointsFactory } from "../factories";
2+
import { fileSendingEndpointsFactory } from "../factories.ts";
33
import { readFile } from "node:fs/promises";
44

55
export const sendAvatarEndpoint = fileSendingEndpointsFactory.build({

0 commit comments

Comments
 (0)