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 all commits
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
20 changes: 6 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Hosts TSConfigs for you to extend in your apps, tuned to a particular runtime environment. Owned and improved by the community.
Basically Definitely Typed for TSConfigs.

We target the latest versions stable version of TypeScript, note that because we want to be consistent with the versioning the target runtime we can't always do semver releases.

### Available TSConfigs

<!-- AUTO -->
Expand Down Expand Up @@ -90,20 +92,6 @@ Add to your `tsconfig.json`:
```json
"extends": "@tsconfig/ember/tsconfig.json"
```
### ESM <kbd><a href="./bases/esm.json">tsconfig.json</a></kbd>

Install:

```sh
npm install --save-dev @tsconfig/esm
yarn add --dev @tsconfig/esm
```

Add to your `tsconfig.json`:

```json
"extends": "@tsconfig/esm/tsconfig.json"
```
### Next.js <kbd><a href="./bases/next.json">tsconfig.json</a></kbd>

Install:
Expand Down Expand Up @@ -367,6 +355,10 @@ to start from a Node 18 + Strictest base config, you can install both

You can see the result of the combined configs via `tsc --showConfig`.

### What about `@tsconfig/esm`?

We deprecated it in favour of setting [module/moduleResolution](https://github.com/tsconfig/bases/pull/197) to node/bundler.

### Contributing

```sh
Expand Down
4 changes: 2 additions & 2 deletions bases/create-react-app.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Create React App",

"_version": "2.0.0",

"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
4 changes: 3 additions & 1 deletion bases/docusaurus.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Docusaurus v2",
"docs": "https://v2.docusaurus.io/docs/typescript-support",
"_version": "2.0.0",

"compilerOptions": {
"allowJs": true,
"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
6 changes: 3 additions & 3 deletions bases/ember.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Ember",
"docs": "https://docs.ember-cli-typescript.com",
"_version": "2.0.0",
"_version": "3.0.0",

// This is the base config used by Ember apps and addons. When actually used
// via Ember CLI (e.g. ember-cli-typescript's blueprint), it additionally has
// `compilerOptions.baseUrl`, `compilerOptions.paths`, and `include` set.
"compilerOptions": {
"target": "ES2021",
"module": "ES2020",
"moduleResolution": "node",
"module": "esnext",
"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
2 changes: 2 additions & 0 deletions bases/esm.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"_deprecated": true,
"$schema": "https://json.schemastore.org/tsconfig",
"display": "ESM",

"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
5 changes: 3 additions & 2 deletions bases/next.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Next.js",
"_version": "2.0.0",

"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
Expand All @@ -11,7 +12,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": "18.1.0",
"compilerOptions": {
"lib": [
"es2022"
"es2023"
],
"module": "Node16",
"target": "es2022",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
}
5 changes: 3 additions & 2 deletions bases/node12.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 12",
"_version": "12.1.0",

"compilerOptions": {
"lib": ["es2019", "es2020.promise", "es2020.bigint", "es2020.string"],
"module": "commonjs",
"module": "node16",
"target": "es2019",

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The changes reflected in node16 are mostly present as of Node v12.

}
}
5 changes: 3 additions & 2 deletions bases/node14.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 14",
"_version": "14.1.0",

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

"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
3 changes: 2 additions & 1 deletion bases/node16.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 16",
"_version": "16.1.0",

"compilerOptions": {
"lib": ["es2021"],
Expand All @@ -11,6 +12,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
4 changes: 2 additions & 2 deletions bases/node17.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 17",

"_version": "17.1.0",
"compilerOptions": {
"lib": ["es2022"],
"module": "Node16",
Expand All @@ -12,6 +12,6 @@
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"useDefineForClassFields": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
4 changes: 2 additions & 2 deletions bases/node18.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 18",

"_version": "2.0.0",
"_version": "18.2.0",

"compilerOptions": {
"lib": ["es2023"],
Expand All @@ -13,6 +13,6 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "node"
"moduleResolution": "node16"
}
}
4 changes: 2 additions & 2 deletions bases/node19.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Node 19",

"_version": "2.0.0",
"_version": "19.1.0",

"compilerOptions": {
"lib": ["es2023"],
Expand All @@ -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.

}
}
5 changes: 3 additions & 2 deletions bases/nuxt.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Nuxt",

"_version": "2.0.0",

"compilerOptions": {
"target": "ES2018",
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "bundler",
"lib": [
"ESNext",
"ESNext.AsyncIterable",
Expand Down
5 changes: 4 additions & 1 deletion bases/remix.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Remix",
"_version": "2.0.0",

"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "node",
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"target": "ES2019",
"strict": true,
Expand Down
5 changes: 3 additions & 2 deletions bases/svelte.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"display": "Svelte",
"_version": "4.0.0",
"_version": "5.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/std@0.192.0/semver/gt.ts";
import { parse } from "https://deno.land/std@0.192.0/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
1 change: 1 addition & 0 deletions scripts/update-markdown-readme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ for await (const tsconfigEntry of Deno.readDir("bases")) {
const sortedPaths = paths.sort((l, r) => l.localeCompare(r)).filter(r => !r.includes("recommended"))
const basePaths = ["recommended.json", ...sortedPaths]
for (const base of basePaths) {
if (base === "esm.json") continue
const tsconfigFilePath = path.join("bases", base)
const name = path.basename(base).replace(".json", "")

Expand Down