You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: recipes/correct-ts-specifiers/README.md
+50-50Lines changed: 50 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,56 +4,6 @@ This package transforms import specifiers from the old `tsc` (TypeScript's compi
4
4
5
5
This is a one-and-done process, and the updated source-code should be committed to your version control (eg git); thereafter, source-code import statements should be authored compliant with the ECMAScript (JavaScript) standard.
6
6
7
-
> [!TIP]
8
-
> Those using `tsc` to compile will need to enable [`rewriteRelativeImportExtensions`](https://www.typescriptlang.org/tsconfig/#rewriteRelativeImportExtensions); using `tsc` for only type-checking (ex via a lint/test step like `npm run test:types`) needs [`allowImportingTsExtensions`](https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions) (and some additional compile options—see the cited documentation);
9
-
10
-
This package does not just blindly find & replace file extensions within specifiers: It confirms that the replacement specifier actually exists; in ambiguous cases (such as two files with the same basename in the same location but different relevant file extensions like `/tmp/foo.js` and `/tmp/foo.ts`), it logs an error, skips that specifier, and continues processing.
11
-
12
-
> [!CAUTION]
13
-
> This package does not confirm that imported modules contain the desired export(s). This _shouldn't_ actually ever result in a problem because ambiguous cases are skipped (so if there is a problem, it existed before the migration started). Merely running your source-code after the mirgration completes will confirm all is well (if there are problems, node will error, citing the problems).
14
-
15
-
> [!TIP]
16
-
> Node.js requires the `type` keyword be present on type imports. For own code, this package usually handles that. However, in some cases and for node modules, it does not. Robust tooling already exists that will automatically fix this, such as
17
-
>
18
-
> *[`use-import-type` via biome](https://biomejs.dev/linter/rules/use-import-type/)
19
-
> *[`typescript/no-import-type-side-effects` via oxlint](https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-import-type-side-effects)
20
-
> *[`consistent-type-imports` via typescript-lint](https://typescript-eslint.io/rules/consistent-type-imports)
21
-
>
22
-
> If your source code needs that, first run this codemod and then one of those fixers.
23
-
24
-
## Running
25
-
26
-
> [!CAUTION]
27
-
> This will change your source-code. Commit any unsaved changes before running this package.
28
-
29
-
> [!IMPORTANT]
30
-
> [`--experimental-import-meta-resolve`](https://nodejs.org/api/cli.html#--experimental-import-meta-resolve) MUST be enabled; the feature is not really experimental—it's nonstandard because it's not relevant for browsers.
For best results, run this _within_ each workspace of the monorepo.
40
-
41
-
```text
42
-
project-root/
43
-
├ workspaces/
44
-
├ foo/ ←--------- RUN HERE
45
-
├ …
46
-
├ package.json
47
-
└ tsconfig.json
48
-
└ bar/ ←--------- RUN HERE
49
-
├ …
50
-
├ package.json
51
-
└ tsconfig.json
52
-
└ utils/ ←--------- RUN HERE
53
-
├ qux.js
54
-
└ zed.js
55
-
```
56
-
57
7
## Supported cases
58
8
59
9
* no file extension → `.cts`, `.mts`, `.js`, `.ts`, `.d.cts`, `.d.mts`, or `.d.ts`
@@ -111,3 +61,53 @@ const bird = new Bird('Tweety');
111
61
const cat =newCat('Milo');
112
62
const dog =newDog('Otis');
113
63
```
64
+
65
+
> [!TIP]
66
+
> Those using `tsc` to compile will need to enable [`rewriteRelativeImportExtensions`](https://www.typescriptlang.org/tsconfig/#rewriteRelativeImportExtensions); using `tsc` for only type-checking (ex via a lint/test step like `npm run test:types`) needs [`allowImportingTsExtensions`](https://www.typescriptlang.org/tsconfig/#allowImportingTsExtensions) (and some additional compile options—see the cited documentation);
67
+
68
+
This package does not just blindly find & replace file extensions within specifiers: It confirms that the replacement specifier actually exists; in ambiguous cases (such as two files with the same basename in the same location but different relevant file extensions like `/tmp/foo.js` and `/tmp/foo.ts`), it logs an error, skips that specifier, and continues processing.
69
+
70
+
> [!CAUTION]
71
+
> This package does not confirm that imported modules contain the desired export(s). This _shouldn't_ actually ever result in a problem because ambiguous cases are skipped (so if there is a problem, it existed before the migration started). Merely running your source-code after the mirgration completes will confirm all is well (if there are problems, node will error, citing the problems).
72
+
73
+
> [!TIP]
74
+
> Node.js requires the `type` keyword be present on type imports. For own code, this package usually handles that. However, in some cases and for node modules, it does not. Robust tooling already exists that will automatically fix this, such as
75
+
>
76
+
> *[`use-import-type` via biome](https://biomejs.dev/linter/rules/use-import-type/)
77
+
> *[`typescript/no-import-type-side-effects` via oxlint](https://oxc.rs/docs/guide/usage/linter/rules/typescript/no-import-type-side-effects)
78
+
> *[`consistent-type-imports` via typescript-lint](https://typescript-eslint.io/rules/consistent-type-imports)
79
+
>
80
+
> If your source code needs that, first run this codemod and then one of those fixers.
81
+
82
+
## Running
83
+
84
+
> [!CAUTION]
85
+
> This will change your source-code. Commit any unsaved changes before running this package.
86
+
87
+
> [!IMPORTANT]
88
+
> [`--experimental-import-meta-resolve`](https://nodejs.org/api/cli.html#--experimental-import-meta-resolve) MUST be enabled; the feature is not really experimental—it's nonstandard because it's not relevant for browsers.
0 commit comments