Skip to content

Commit

Permalink
feat(tsconfig): rework entire tsconfig setup
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The tsconfig has been majorly restructured. Please see [the upgrading guide](https://github.com/sapphiredev/utilities/blob/main/packages/ts-config/UPGRADING-v4-v5.md) for how to migrate to the new version.
  • Loading branch information
favna committed Aug 24, 2023
1 parent 6b0fa68 commit a5ba402
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 36 deletions.
41 changes: 41 additions & 0 deletions packages/ts-config/UPGRADING-v4-v5.md
Original file line number Diff line number Diff line change
@@ -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"]
}
```
8 changes: 0 additions & 8 deletions packages/ts-config/extra-strict-without-decorators.json

This file was deleted.

43 changes: 28 additions & 15 deletions packages/ts-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions packages/ts-config/src/cjs/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "Node"
}
}
7 changes: 7 additions & 0 deletions packages/ts-config/src/esm/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"module": "Node16",
"moduleResolution": "Node16",
"verbatimModuleSyntax": true
}
}
2 changes: 1 addition & 1 deletion packages/ts-config/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "../extra-strict-without-decorators.json",
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"lib": ["ESNext", "DOM"],
"noEmit": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/ts-config/tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "./tsconfig.json",
"extends": "src/base/tsconfig.json",
"compilerOptions": {
"allowJs": true,
"checkJs": true
Expand Down

0 comments on commit a5ba402

Please sign in to comment.