Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update module and moduleResolution to stop using node and invalid combintations #197

Merged
merged 8 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bases/create-react-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"module": "esnext",
"moduleResolution": "bundler",
"target": "es2015",

"allowJs": true,
Expand All @@ -14,7 +15,6 @@
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
Expand Down
3 changes: 2 additions & 1 deletion bases/docusaurus.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"esModuleInterop": true,
"jsx": "react",
"lib": ["DOM"],
"moduleResolution": "Node16",
"module": "esnext",
"moduleResolution": "bundler",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"noEmit": true,
"types": ["node", "@docusaurus/module-type-aliases", "@docusaurus/theme-classic"],
"baseUrl": ".",
Expand Down
2 changes: 1 addition & 1 deletion bases/ember.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"compilerOptions": {
"target": "ES2021",
"module": "ES2020",
"moduleResolution": "node",
"moduleResolution": "bundler",

// Trying to check Ember apps and addons with `allowJs: true` is a recipe
// for many unresolveable type errors, because with *considerable* extra
Expand Down
1 change: 1 addition & 0 deletions bases/esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"compilerOptions": {
"module": "es2022",
"moduleResolution": "bundler",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I strongly object to this base existing at all. It’s a trap that might prevent a user from finding the config they should be using for Node or Vite or whatever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I delisted it in the latest commit.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the suggested approach to now use base/node18 and then set moduleResolution manually in tsconfig.json to bundler?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would like to know that as well. It's not clear to me what is the recommended config for ESM modules which target nodejs (particularly 22). What if it's modules shared between frontend and backend in a monorepo?


"verbatimModuleSyntax": true
}
Expand Down
2 changes: 1 addition & 1 deletion bases/next.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"moduleResolution": "bundler",
Copy link
Contributor

@styfle styfle Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a breaking change in Next.js since its only TS 5+

While we're at it, we could probably remove target since Next.js doesn't use it.

Also include looks outdated since its missing ".next/types/**/*.ts"

You can find the latest with create next app

"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
Expand Down
8 changes: 4 additions & 4 deletions bases/node-lts.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node LTS",
"_version": "18.12.1",
"_version": "2.0.0",
"compilerOptions": {
"lib": [
"es2022"
"es2023"
],
"module": "Node16",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
}
4 changes: 2 additions & 2 deletions bases/node14.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

"compilerOptions": {
"lib": ["es2020"],
"module": "commonjs",
"module": "node16",
"target": "es2020",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
2 changes: 1 addition & 1 deletion bases/node16.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
2 changes: 1 addition & 1 deletion bases/node17.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
2 changes: 1 addition & 1 deletion bases/node18.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
2 changes: 1 addition & 1 deletion bases/node19.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
2 changes: 1 addition & 1 deletion bases/node20.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be nodenext instead?

Copy link

@jakebailey jakebailey Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it should match the module setting above (the linked PR on TS would enforce it). At the moment, node16 is nodenext, as no new resolution semantics have been introduced. Eventually maybe there will be a node24 if that version changes something.

Related, but "node" was renamed to "node10" for that reason.

}
}
2 changes: 1 addition & 1 deletion bases/nuxt.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "bundler",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
Expand Down
2 changes: 1 addition & 1 deletion bases/remix.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
Expand Down
3 changes: 2 additions & 1 deletion bases/svelte.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"_version": "4.0.0",

"compilerOptions": {
"moduleResolution": "node",
"module": "esnext",
"moduleResolution": "bundler",
"target": "es2017",
/**
Svelte Preprocess cannot figure out whether you have a value or a type, so tell TypeScript
Expand Down
13 changes: 4 additions & 9 deletions scripts/generate-lts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// deno run --allow-read --allow-write scripts/generate-lts.ts
//

import { gt } from "https://deno.land/[email protected]/semver/gt.ts";
import { parse } from "https://deno.land/[email protected]/semver/parse.ts";

interface NodeReleaseMetadata {
version: string;
date: string;
Expand All @@ -19,20 +22,12 @@ type Tsconfig = Record<string, any>;

const versionRegex = /v(\d+)\.(\d+)\.(\d+)/;

function calcVersion(x: string) {
const match = x.match(versionRegex);
if (!match) {
throw new Error(`version regex failed to match version string '${x}'`);
}
return +match[1] * 1000000 + +match[2] * 1000 + +match[3];
}

const releasesResponse = await fetch("https://nodejs.org/download/release/index.json");
const releasesJson = (await releasesResponse.json()) as NodeReleaseMetadata[];
const lts = releasesJson
.filter((r) => r.lts)
.reduce(
(prevValue, currValue) => (calcVersion(currValue.version) > calcVersion(prevValue.version) ? currValue : prevValue),
(prevValue, currValue) => (gt(parse(currValue.version), parse(prevValue.version)) ? currValue : prevValue),
{
version: "v0.0.0"
}
Expand Down