-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add explicit file extensions to annotations
- Loading branch information
1 parent
efd21a0
commit 117d097
Showing
2 changed files
with
24 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
const shell = require('shelljs') | ||
const fs = require('fs') | ||
|
||
const files = shell.find('dist/**/*.d.ts') | ||
|
||
for (const file of files) { | ||
const cts = file.replace('.d.ts', '.d.cts') | ||
|
||
// Add type qualifiers in annotations | ||
shell.sed('-i', /(import|export [*{])\s+(?!type\b)/, '$1 type ', file) | ||
// Remove .js extensions | ||
shell.sed('-i', /from '(\.[^.]+)\.js'/, "from '$1'", file) | ||
|
||
fs.copyFileSync(file, cts) | ||
|
||
// Add explicit .d.ts extensions for ESM | ||
shell.sed('-i', / from '(\.[^']+)'/, " from '$1.d.ts'", file) | ||
shell.sed('-i', /^declare module '(\.[^']+)'/, "declare module '$1.d.ts'", file) | ||
|
||
// Add explicit .d.cts extensions for CJS | ||
shell.sed('-i', / from '(\.[^']+)'/, " from '$1.d.cts'", cts) | ||
shell.sed('-i', /^declare module '(\.[^']+)'/, "declare module '$1.d.cts'", cts) | ||
} |