ts6to7 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -5
- package/package.json +5 -3
- package/src/cli.js +12 -2
- package/src/transform-package-json.js +18 -3
- package/src/transform-tsconfig.js +37 -6
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[](https://github.com/zi-gae/ts6to7/actions/workflows/ci.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/ts6to7)
|
|
5
5
|
|
|
6
|
-
Codemod that migrates a **TypeScript 6** project to **TypeScript 7 (tsgo)**.
|
|
6
|
+
Codemod that migrates a **TypeScript 5 or 6** project to **TypeScript 7 (tsgo)**.
|
|
7
7
|
No install needed — try it in 10 seconds:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
@@ -13,9 +13,11 @@ npx ts6to7 --dry
|
|
|
13
13
|

|
|
14
14
|
|
|
15
15
|
TypeScript 7 is the native (Go) rewrite of the compiler. It removes every option
|
|
16
|
-
that TypeScript 6 marked as deprecated and flips some defaults.
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
that TypeScript 5 and 6 marked as deprecated and flips some defaults. Almost all
|
|
17
|
+
of the removed options date back to the TS 5.0 deprecation list, so migrating
|
|
18
|
+
straight from 5.x works the same as from 6.x — this tool rewrites your config
|
|
19
|
+
files to the TS7 equivalents and prints a checklist of the things it cannot
|
|
20
|
+
safely change for you.
|
|
19
21
|
|
|
20
22
|
## Usage
|
|
21
23
|
|
|
@@ -41,7 +43,7 @@ npx tsc --noEmit # fix any remaining errors it reports
|
|
|
41
43
|
|
|
42
44
|
### `tsconfig*.json` (comments and formatting are preserved)
|
|
43
45
|
|
|
44
|
-
| Before (
|
|
46
|
+
| Before (TS 5/6) | After (TS7) |
|
|
45
47
|
| --- | --- |
|
|
46
48
|
| `"target": "es3"` / `"es5"` | `"ES2015"` — ES5 output was removed |
|
|
47
49
|
| `"module": "amd"` / `"umd"` / `"system"` / `"none"` | `"ESNext"` |
|
|
@@ -49,6 +51,8 @@ npx tsc --noEmit # fix any remaining errors it reports
|
|
|
49
51
|
| `"importsNotUsedAsValues"`, `"preserveValueImports"` | `"verbatimModuleSyntax": true` |
|
|
50
52
|
| `"baseUrl"` | folded into `"paths"` (mappings become tsconfig-relative) |
|
|
51
53
|
| `charset`, `keyofStringsOnly`, `out`, `noImplicitUseStrict`, `noStrictGenericChecks`, `suppressExcessPropertyErrors`, `suppressImplicitAnyIndexErrors` | removed |
|
|
54
|
+
| `"ignoreDeprecations": "5.0"` (the TS5 escape hatch) | removed — the options it silenced no longer exist |
|
|
55
|
+
| `"prepend": true` in project `references` | removed — output prepending is gone since TS6 |
|
|
52
56
|
| `strict` unset | pinned to `false` to preserve behavior (TS7 defaults to `true`) — delete it when you're ready |
|
|
53
57
|
|
|
54
58
|
### `package.json`
|
|
@@ -73,6 +77,14 @@ npx tsc --noEmit # fix any remaining errors it reports
|
|
|
73
77
|
Everything in this list is also printed as a `Needs manual review` item when
|
|
74
78
|
the codemod runs, scoped to the file that triggered it.
|
|
75
79
|
|
|
80
|
+
## Coming from TypeScript 5?
|
|
81
|
+
|
|
82
|
+
You don't need to stop at 6 first — run the codemod directly on a 5.x project.
|
|
83
|
+
The transforms match on option values, not on your current compiler version:
|
|
84
|
+
`typescript: "^5.x"` is bumped straight to `^7.0.0`, TS5-era escape hatches
|
|
85
|
+
like `"ignoreDeprecations": "5.0"` are cleaned up, and `prepend` in project
|
|
86
|
+
references (already gone in TS6) is removed too.
|
|
87
|
+
|
|
76
88
|
## Development
|
|
77
89
|
|
|
78
90
|
```bash
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ts6to7",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/zi-gae/ts6to7.git"
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"bugs": {
|
|
10
10
|
"url": "https://github.com/zi-gae/ts6to7/issues"
|
|
11
11
|
},
|
|
12
|
-
"description": "Codemod that migrates a TypeScript 6 project to TypeScript 7 (tsgo): rewrites tsconfig.json options removed in TS7 and flags changes that need manual review.",
|
|
12
|
+
"description": "Codemod that migrates a TypeScript 5 or 6 project to TypeScript 7 (tsgo): rewrites tsconfig.json options removed in TS7 and flags changes that need manual review.",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"bin": {
|
|
15
15
|
"ts6to7": "bin/ts6to7.js"
|
|
@@ -29,7 +29,9 @@
|
|
|
29
29
|
"codemod",
|
|
30
30
|
"migration",
|
|
31
31
|
"tsgo",
|
|
32
|
-
"typescript-7"
|
|
32
|
+
"typescript-7",
|
|
33
|
+
"typescript-5",
|
|
34
|
+
"ts5to7"
|
|
33
35
|
],
|
|
34
36
|
"dependencies": {
|
|
35
37
|
"jsonc-parser": "^3.3.1"
|
package/src/cli.js
CHANGED
|
@@ -10,7 +10,7 @@ const green = (s) => (tty ? `\x1b[32m${s}\x1b[0m` : s);
|
|
|
10
10
|
const yellow = (s) => (tty ? `\x1b[33m${s}\x1b[0m` : s);
|
|
11
11
|
const dim = (s) => (tty ? `\x1b[2m${s}\x1b[0m` : s);
|
|
12
12
|
|
|
13
|
-
const HELP = `ts6to7 — migrate a TypeScript 6 project to TypeScript 7 (tsgo)
|
|
13
|
+
const HELP = `ts6to7 — migrate a TypeScript 5 or 6 project to TypeScript 7 (tsgo)
|
|
14
14
|
|
|
15
15
|
Usage:
|
|
16
16
|
npx ts6to7 [directory] [options]
|
|
@@ -26,13 +26,16 @@ What it does:
|
|
|
26
26
|
- moduleResolution node10/classic -> NodeNext or Bundler
|
|
27
27
|
- importsNotUsedAsValues / preserveValueImports -> verbatimModuleSyntax
|
|
28
28
|
- baseUrl -> folded into "paths" (removed in TS7)
|
|
29
|
-
- removes charset, keyofStringsOnly, out,
|
|
29
|
+
- removes charset, keyofStringsOnly, out, ignoreDeprecations, ...
|
|
30
|
+
- removes "prepend" from project references (gone since TS6)
|
|
30
31
|
- pins strict: false if unset (TS7 defaults strict to true)
|
|
31
32
|
package.json
|
|
32
33
|
- typescript dependency -> ^7.0.0
|
|
33
34
|
- warns about compiler-API tools (ts-node, ts-patch, ts-jest, ...)
|
|
34
35
|
`;
|
|
35
36
|
|
|
37
|
+
const KNOWN_FLAGS = new Set(['--dry', '-d', '--help', '-h']);
|
|
38
|
+
|
|
36
39
|
export async function run(argv) {
|
|
37
40
|
const args = [...argv];
|
|
38
41
|
const dry = args.includes('--dry') || args.includes('-d');
|
|
@@ -40,6 +43,13 @@ export async function run(argv) {
|
|
|
40
43
|
console.log(HELP);
|
|
41
44
|
return 0;
|
|
42
45
|
}
|
|
46
|
+
// A typo like --dr must not silently run in write mode.
|
|
47
|
+
const unknown = args.find((a) => a.startsWith('-') && !KNOWN_FLAGS.has(a));
|
|
48
|
+
if (unknown) {
|
|
49
|
+
console.error(`Unknown option: ${unknown}\n`);
|
|
50
|
+
console.log(HELP);
|
|
51
|
+
return 1;
|
|
52
|
+
}
|
|
43
53
|
const dirArg = args.find((a) => !a.startsWith('-'));
|
|
44
54
|
const root = resolve(process.cwd(), dirArg ?? '.');
|
|
45
55
|
|
|
@@ -8,8 +8,9 @@ const API_DEPENDENT = ['ts-patch', 'ttypescript', 'ts-node', 'ts-loader', 'ts-je
|
|
|
8
8
|
const DEP_FIELDS = ['dependencies', 'devDependencies'];
|
|
9
9
|
|
|
10
10
|
function majorOf(range) {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// First integer in the range: handles "^6.2.0", "~6.0", ">=6", "6", "workspace:^6".
|
|
12
|
+
const m = String(range).match(/\d+/);
|
|
13
|
+
return m ? Number(m[0]) : null;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/**
|
|
@@ -22,6 +23,7 @@ export function transformPackageJson(text) {
|
|
|
22
23
|
let result = text;
|
|
23
24
|
|
|
24
25
|
const json = parse(text) ?? {};
|
|
26
|
+
const warnedTools = new Set();
|
|
25
27
|
|
|
26
28
|
for (const field of DEP_FIELDS) {
|
|
27
29
|
const deps = json[field];
|
|
@@ -36,7 +38,8 @@ export function transformPackageJson(text) {
|
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
for (const name of API_DEPENDENT) {
|
|
39
|
-
if (deps[name]) {
|
|
41
|
+
if (deps[name] && !warnedTools.has(name)) {
|
|
42
|
+
warnedTools.add(name);
|
|
40
43
|
warnings.push(
|
|
41
44
|
`"${name}" uses the TypeScript compiler API, which tsgo does not expose in 7.0 ` +
|
|
42
45
|
'(a new API ships with 7.1). Check that your version supports TS7 or find an alternative.',
|
|
@@ -45,5 +48,17 @@ export function transformPackageJson(text) {
|
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
50
|
|
|
51
|
+
// Peer ranges are a compatibility statement — widen manually, don't auto-bump.
|
|
52
|
+
const peerTs = json.peerDependencies?.typescript;
|
|
53
|
+
if (typeof peerTs === 'string') {
|
|
54
|
+
const major = majorOf(peerTs);
|
|
55
|
+
if (major !== null && major < 7) {
|
|
56
|
+
warnings.push(
|
|
57
|
+
`peerDependencies.typescript ("${peerTs}") does not allow 7.x — widen the range ` +
|
|
58
|
+
'manually (e.g. "^6.0.0 || ^7.0.0") so consumers on TS7 can install this package.',
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
48
63
|
return { text: result, changes, warnings };
|
|
49
64
|
}
|
|
@@ -14,6 +14,7 @@ const REMOVED_OPTIONS = {
|
|
|
14
14
|
suppressExcessPropertyErrors: null,
|
|
15
15
|
suppressImplicitAnyIndexErrors: null,
|
|
16
16
|
out: 'use "outFile" instead if you relied on single-file output',
|
|
17
|
+
ignoreDeprecations: 'the deprecated options it silenced are gone, so the flag has no meaning',
|
|
17
18
|
};
|
|
18
19
|
|
|
19
20
|
function lower(value) {
|
|
@@ -39,6 +40,27 @@ export function transformTsconfig(text) {
|
|
|
39
40
|
let result = text;
|
|
40
41
|
|
|
41
42
|
const json = parse(text) ?? {};
|
|
43
|
+
|
|
44
|
+
// --- references[].prepend: deprecated in TS 5.5, gone since TS6 ----------
|
|
45
|
+
// Handled before the compilerOptions guard: solution-style tsconfigs have
|
|
46
|
+
// references but no compilerOptions.
|
|
47
|
+
if (Array.isArray(json.references)) {
|
|
48
|
+
let prepends = 0;
|
|
49
|
+
json.references.forEach((ref, i) => {
|
|
50
|
+
if (ref && typeof ref === 'object' && Object.prototype.hasOwnProperty.call(ref, 'prepend')) {
|
|
51
|
+
result = applyEdits(result, modify(result, ['references', i, 'prepend'], undefined, FORMAT));
|
|
52
|
+
prepends += 1;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
if (prepends > 0) {
|
|
56
|
+
changes.push(`removed "prepend" from ${prepends} project reference(s) (option no longer exists in TS7)`);
|
|
57
|
+
warnings.push(
|
|
58
|
+
'Project references no longer prepend referenced output. If you relied on prepend to ' +
|
|
59
|
+
'concatenate outputs, switch to a bundler or explicit outFile ordering.',
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
42
64
|
const co = json.compilerOptions;
|
|
43
65
|
if (typeof co !== 'object' || co === null) {
|
|
44
66
|
return { text: result, changes, warnings };
|
|
@@ -152,12 +174,21 @@ export function transformTsconfig(text) {
|
|
|
152
174
|
|
|
153
175
|
// --- strict becomes the default in TS7 -----------------------------------
|
|
154
176
|
if (!Object.prototype.hasOwnProperty.call(co, 'strict')) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
'strict
|
|
160
|
-
|
|
177
|
+
// An extending config may inherit strict from its base; pinning false here
|
|
178
|
+
// would override the base and change behavior.
|
|
179
|
+
if (json.extends !== undefined) {
|
|
180
|
+
warnings.push(
|
|
181
|
+
'strict is not set here and this config extends another. TS7 defaults strict to true — ' +
|
|
182
|
+
'make sure the extended chain sets it explicitly, or add strict yourself.',
|
|
183
|
+
);
|
|
184
|
+
} else {
|
|
185
|
+
edit('strict', false);
|
|
186
|
+
changes.push('added explicit strict: false (TS7 flips the default to true)');
|
|
187
|
+
warnings.push(
|
|
188
|
+
'strict: false was added to preserve current behavior. Consider deleting it and fixing ' +
|
|
189
|
+
'strict-mode errors instead — TS7 projects are strict by default.',
|
|
190
|
+
);
|
|
191
|
+
}
|
|
161
192
|
}
|
|
162
193
|
|
|
163
194
|
// --- types auto-inclusion behavior change (report only) -------------------
|