diff --git a/packages/ts-config/UPGRADING-v4-v5.md b/packages/ts-config/UPGRADING-v4-v5.md new file mode 100644 index 0000000000..d9e55f5b34 --- /dev/null +++ b/packages/ts-config/UPGRADING-v4-v5.md @@ -0,0 +1,41 @@ +# Migration guide for @sapphire/ts-config v4.x to v5.x + +Between major version 4 and 5 of `@sapphire/ts-config`, the package has been rewritten to fully leverage that TypeScript's `extends` feature now supports an array of config files. + +The following configs have been removed: + +- `@sapphire/ts-config/extra-strict-without-decorators` +- `@sapphire/ts-config/without-decorators` + +The following changes have been applied to the base config: + +- `experimentalDecorators` is now `false` by default +- `emitDecoratorMetadata` is now `false` by default +- `verbatimModuleSyntax` is now `false` by default. It gets set to true alongside `@sapphire/ts-config/esm`, this is because `verbatimModuleSyntax` doesn't work well together with CJS projects. + +The following configs have been added: + +- `@sapphire/ts-config/extra-strict` +- `@sapphire/ts-config/decorators` +- `@sapphire/ts-config/base` -> This is identical to `@sapphire/ts-config` +- `@sapphire/ts-config/cjs` +- `@sapphire/ts-config/esm` + +In order to achieve the following old configs you now need to use: + +| Old config | New config | +| ------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | +| `"@sapphire/ts-config"` | `["@sapphire/ts-config", "@sapphire/ts-config/decorators"]` | +| `"@sapphire/ts-config/extra-strict"` | `["@sapphire/ts-config", "@sapphire/ts-config/extra-strict", "@sapphire/ts-config/decorators"]` | +| `"@sapphire/ts-config/extra-strict-without-decorators"` | `["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"]` | +| `"@sapphire/ts-config/without-decorators"` | `["@sapphire/ts-config"]` | + +Then you also have to choose either the CJS or ESM config with `@sapphire/ts-config/cjs` or `@sapphire/ts-config/esm` respectively. + +An example of a CJS project with extra-strict and no decorators would therefore be: + +```json +{ + "extends": ["@sapphire/ts-config", "@sapphire/ts-config/cjs", "@sapphire/ts-config/extra-strict"] +} +``` diff --git a/packages/ts-config/extra-strict-without-decorators.json b/packages/ts-config/extra-strict-without-decorators.json deleted file mode 100644 index 29ebda7ccd..0000000000 --- a/packages/ts-config/extra-strict-without-decorators.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/tsconfig.json", - "extends": "./extra-strict.json", - "compilerOptions": { - "emitDecoratorMetadata": false, - "experimentalDecorators": false - } -} diff --git a/packages/ts-config/package.json b/packages/ts-config/package.json index a9b4b4a610..15d068ff52 100644 --- a/packages/ts-config/package.json +++ b/packages/ts-config/package.json @@ -4,23 +4,37 @@ "description": "Shareable TypeScript configuration for the Sapphire Community", "author": "@sapphire", "license": "MIT", - "main": "tsconfig.json", + "main": "src/base/tsconfig.json", "exports": { ".": { - "import": "./tsconfig.json", - "require": "./tsconfig.json" + "types": "./src/base/tsconfig.json", + "import": "./src/base/tsconfig.json", + "require": "./src/base/tsconfig.json" }, - "./without-decorators": { - "import": "./without-decorators.json", - "require": "./without-decorators.json" + "./base": { + "types": "./src/base/tsconfig.json", + "import": "./src/base/tsconfig.json", + "require": "./src/base/tsconfig.json" + }, + "./decorators": { + "types": "./src/base/decorators.json", + "import": "./src/base/decorators.json", + "require": "./src/base/decorators.json" }, "./extra-strict": { - "import": "./extra-strict.json", - "require": "./extra-strict.json" + "types": "./src/base/extra-strict.json", + "import": "./src/base/extra-strict.json", + "require": "./src/base/extra-strict.json" + }, + "./cjs": { + "types": "./src/cjs/tsconfig.json", + "import": "./src/cjs/tsconfig.json", + "require": "./src/cjs/tsconfig.json" }, - "./extra-strict-without-decorators": { - "import": "./extra-strict-without-decorators.json", - "require": "./extra-strict-without-decorators.json" + "./esm": { + "types": "./src/esm/tsconfig.json", + "import": "./src/esm/tsconfig.json", + "require": "./src/esm/tsconfig.json" } }, "sideEffects": false, @@ -34,12 +48,11 @@ }, "dependencies": { "tslib": "^2.6.2", - "typescript": "^5.1.6" + "typescript": "^5.2.2" }, "files": [ - "./tsconfig.json", - "extra-strict*.json", - "*decorators*.json" + "src", + "UPGRADING-*.md" ], "engines": { "node": ">=v16.0.0", diff --git a/packages/ts-config/without-decorators.json b/packages/ts-config/src/base/decorators.json similarity index 58% rename from packages/ts-config/without-decorators.json rename to packages/ts-config/src/base/decorators.json index a0849973f7..b3a5110699 100644 --- a/packages/ts-config/without-decorators.json +++ b/packages/ts-config/src/base/decorators.json @@ -1,8 +1,7 @@ { "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/tsconfig.json", - "extends": "./tsconfig.json", "compilerOptions": { - "emitDecoratorMetadata": false, - "experimentalDecorators": false + "emitDecoratorMetadata": true, + "experimentalDecorators": true } } diff --git a/packages/ts-config/extra-strict.json b/packages/ts-config/src/base/extra-strict.json similarity index 89% rename from packages/ts-config/extra-strict.json rename to packages/ts-config/src/base/extra-strict.json index f49bcd446d..443000fbe8 100644 --- a/packages/ts-config/extra-strict.json +++ b/packages/ts-config/src/base/extra-strict.json @@ -1,6 +1,5 @@ { "$schema": "https://raw.githubusercontent.com/SchemaStore/schemastore/master/src/schemas/json/tsconfig.json", - "extends": "./tsconfig.json", "compilerOptions": { "allowUnreachableCode": false, "allowUnusedLabels": false, diff --git a/packages/ts-config/tsconfig.json b/packages/ts-config/src/base/tsconfig.json similarity index 77% rename from packages/ts-config/tsconfig.json rename to packages/ts-config/src/base/tsconfig.json index 2039de7563..8fb009ba57 100644 --- a/packages/ts-config/tsconfig.json +++ b/packages/ts-config/src/base/tsconfig.json @@ -5,17 +5,12 @@ "alwaysStrict": true, "declaration": true, "declarationMap": true, - "emitDecoratorMetadata": true, "esModuleInterop": true, - "experimentalDecorators": true, - "importHelpers": true, - "verbatimModuleSyntax": true, + "importHelpers": false, + "noEmitHelpers": false, "incremental": true, "lib": ["esnext"], - "module": "Node16", - "moduleResolution": "Node", "newLine": "lf", - "noEmitHelpers": false, "noFallthroughCasesInSwitch": true, "noImplicitReturns": true, "noUnusedLocals": true, diff --git a/packages/ts-config/src/cjs/tsconfig.json b/packages/ts-config/src/cjs/tsconfig.json new file mode 100644 index 0000000000..3ba04825ca --- /dev/null +++ b/packages/ts-config/src/cjs/tsconfig.json @@ -0,0 +1,6 @@ +{ + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "Node" + } +} diff --git a/packages/ts-config/src/esm/tsconfig.json b/packages/ts-config/src/esm/tsconfig.json new file mode 100644 index 0000000000..75c602bb70 --- /dev/null +++ b/packages/ts-config/src/esm/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "module": "Node16", + "moduleResolution": "Node16", + "verbatimModuleSyntax": true + } +} diff --git a/packages/ts-config/tests/tsconfig.json b/packages/ts-config/tests/tsconfig.json index 5ad0d67096..40bfe61b02 100644 --- a/packages/ts-config/tests/tsconfig.json +++ b/packages/ts-config/tests/tsconfig.json @@ -1,5 +1,5 @@ { - "extends": "../extra-strict-without-decorators.json", + "extends": "../../../tsconfig.base.json", "compilerOptions": { "lib": ["ESNext", "DOM"], "noEmit": true, diff --git a/packages/ts-config/tsconfig.eslint.json b/packages/ts-config/tsconfig.eslint.json index f2295025f2..a8910d8e40 100644 --- a/packages/ts-config/tsconfig.eslint.json +++ b/packages/ts-config/tsconfig.eslint.json @@ -1,5 +1,5 @@ { - "extends": "./tsconfig.json", + "extends": "src/base/tsconfig.json", "compilerOptions": { "allowJs": true, "checkJs": true