Skip to content

Commit 2f2b1f0

Browse files
committed
INITIAL COMMIT
0 parents  commit 2f2b1f0

45 files changed

Lines changed: 4440 additions & 0 deletions

Some content is hidden

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

.gitattributes

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.yarn/** linguist-vendored
2+
/.yarn/releases/* binary
3+
/.yarn/plugins/**/* binary

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: ycmjason

.github/workflows/cd.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
jobs:
9+
publish:
10+
runs-on: ubuntu-latest
11+
12+
permissions:
13+
contents: read
14+
id-token: write
15+
16+
steps:
17+
- name: Checkout repository
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 24
24+
cache: 'yarn'
25+
registry-url: "https://registry.npmjs.org"
26+
27+
- name: Install dependencies
28+
run: yarn install --immutable
29+
30+
- run: yarn build
31+
32+
- name: Publish to npm
33+
run: bash ./scripts/build-and-publish.bash
34+
env:
35+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/ci.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
8+
jobs:
9+
ci:
10+
name: Build, Lint, Format, TypeCheck and Test
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- uses: actions/setup-node@v4
16+
with:
17+
node-version: 24
18+
cache: 'yarn'
19+
- name: Install dependencies
20+
run: yarn install --immutable
21+
22+
- name: Build
23+
run: yarn build
24+
25+
- name: Lint and Formating
26+
run: yarn check
27+
28+
- name: Typecheck
29+
run: yarn typecheck
30+
31+
- name: Test
32+
run: yarn test

.gitignore

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
.yarn/*
2+
!.yarn/patches
3+
!.yarn/plugins
4+
!.yarn/releases
5+
!.yarn/sdks
6+
!.yarn/versions
7+
8+
# Swap the comments on the following lines if you wish to use zero-installs
9+
# In that case, don't forget to run `yarn config set enableGlobalCache false`!
10+
# Documentation here: https://yarnpkg.com/features/caching#zero-installs
11+
12+
#!.yarn/cache
13+
.pnp.*
14+
15+
dist
16+
17+
node_modules
18+
!examples/**/node_modules

.vscode/settings.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"typescript.tsdk": "node_modules/typescript/lib",
3+
"search.exclude": {
4+
"node_modules": true,
5+
"dist": true,
6+
".yarn": true
7+
}
8+
}

.yarn/releases/yarn-4.9.1.cjs

Lines changed: 948 additions & 0 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
yarnPath: .yarn/releases/yarn-4.9.1.cjs
2+
3+
nodeLinker: node-modules

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 YCM Jason
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
# `@ts-migrating` — Progressively Upgrade `tsconfig.json`
2+
3+
🚀 **TypeScript keeps evolving — and your `tsconfig` should too.**
4+
5+
But upgrading often breaks existing code, and fixing all errors at once is unrealistic.
6+
7+
**`@ts-migrating`** helps your team migrate to a desired `tsconfig` gradually and safely.
8+
9+
> I chose `@ts-migrating` (rather than `@ts-migration`) to better reflect the plugin’s progressive and incremental philosophy.
10+
11+
## 🤖 How does this work?
12+
13+
`@ts-migrating` is a TypeScript plugin that lets you **enable your target tsconfig during development** (in IDEs or editors that use the [TypeScript Language Service](https://github.com/microsoft/typescript/wiki/Using-the-Language-Service-API)) and in CI — **without affecting `tsc` or your production build**.
14+
15+
The philosophy behind the plugin follows three simple steps:
16+
17+
1. 🛑 **Prevention**
18+
19+
* Errors from your target config are surfaced during development and in CI.
20+
* This ensures no new violations are introduced into the codebase.
21+
22+
2. 🔧 **Reduction**
23+
24+
* Lines marked with `@ts-migrating` are temporarily suppressed.
25+
* Developers can progressively fix these lines, reducing violations over time.
26+
27+
3.**Migration**
28+
29+
* Once all violations are fixed, no `@ts-migrating` directives remain.
30+
* At this point, you're ready to fully adopt the new tsconfig — and the plugin has served its purpose.
31+
32+
## 📚 Overview
33+
34+
`@ts-migrating` consists of two parts:
35+
36+
1. 🔌 **[TypeScript Language Service Plugin](https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin)**
37+
38+
* Enables IDEs to show errors from the `tsconfig` you're migrating to.
39+
* Suppresses errors on lines marked with `@ts-migrating`.
40+
41+
2. 🖥️ **Standalone CLI: `ts-migrating`**
42+
43+
* `ts-migrating check`
44+
45+
* Run `@ts-migrating`-aware type checking using your new `tsconfig`.
46+
* `ts-migrating annotate`
47+
48+
* Automatically mark all errors caused by your new `tsconfig` with `@ts-migrating`.
49+
* ⚠️ Run this with a clean git state!!! This script will automatically add the `@ts-migrating` directive above every new TypeScript error introduced by your new `tsconfig`. There are edge cases where this will break the code, please review the changes carefully. It is recommended to run your formatter and linter afterwards.
50+
51+
## 🎪 Examples
52+
53+
* [Migrating to `noUncheckedIndexedAccess`](./examples/no-unchecked-indexed-access-migration/src/index.ts):
54+
55+
| Without `@ts-migrating` | With `@ts-migrating` |
56+
| ----------------------- | -------------------- |
57+
| ![Migrating to noUncheckedIndexedAccess](./assets/ts-migrating-no-unchecked-indexed-access.png) | ![Migrating to noUncheckedIndexedAccess marked](./assets/ts-migrating-no-unchecked-indexed-access-marked.png) |
58+
59+
* [Migrating to `noUncheckedIndexAccess`](./examples/erasable-syntax-only-migration/src/index.ts)
60+
* [Migrating to `erasableSyntaxOnly`](./examples/erasable-syntax-only-migration/src/index.ts)
61+
62+
## 📦 Install and Setup
63+
64+
This project does **NOT** require any IDE extensions. It relies purely on TypeScript's own Language Service, so it works on most IDEs and editors that support TypeScript (e.g., VSCode, WebStorm).
65+
66+
To install:
67+
68+
```bash
69+
cd my-cool-project
70+
npm install -D ts-migrating
71+
```
72+
73+
In your existing `tsconfig.json`, add the plugin:
74+
75+
```jsonc
76+
{
77+
// ...
78+
"compilerOptions": {
79+
// ...
80+
"plugins": [
81+
{
82+
"name": "ts-migrating",
83+
"compilerOptions": {
84+
// ... put the compiler options you wish to migrate to, for example:
85+
"strict": true
86+
}
87+
}
88+
]
89+
// ...
90+
}
91+
// ...
92+
}
93+
```
94+
95+
ℹ️ *Note: `plugins` only affect the TypeScript Language Service (used by IDEs). They do **not** impact `tsc` or your build.*
96+
97+
🎉 Your codebase is now ready!
98+
99+
### ✅ Verify the Setup
100+
101+
#### 🧑‍💻 In your IDE
102+
103+
* Restart the IDE, or just the TS server.
104+
* Confirm that type errors now reflect the new `compilerOptions`. For example, when migrating to strict mode, verify that strict-specific errors appear.
105+
* Add `// @ts-migrating` before a line with an error — the error should disappear in the IDE.
106+
107+
#### 🖥 In the terminal
108+
109+
* Run:
110+
111+
```bash
112+
npx ts-migrating check
113+
```
114+
115+
You should see errors from the new config, excluding those marked with `@ts-migrating`.
116+
117+
### ✨ Optional Next Steps
118+
119+
* Run `npx ts-migrating annotate` to automatically annotate newly introduced errors with `// @ts-migrating`.
120+
* Replace your CI type-check step with `npx ts-migrating check` to prevent unreviewed errors from slipping through.
121+
122+
## 📣 Shoutout
123+
124+
This project wouldn't be possible without inspiration from:
125+
126+
* [allegro/typescript-strict-plugin](https://github.com/allegro/typescript-strict-plugin):
127+
Especially for revealing the undocumented [`updateFromProject` option](https://github.com/allegro/typescript-strict-plugin/blob/master/src/plugin/utils.ts#L28-L32) which helped fix a critical issue with the standalone script. [You can find out more here](./src/plugin/mod.ts#L31)).
128+
129+
## 👤 Author
130+
131+
YCM Jason

0 commit comments

Comments
 (0)