-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Use mts extension * Also fix import/export in typedef * Remove clog * Fix formatting
- Loading branch information
Showing
7 changed files
with
53 additions
and
44 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 was deleted.
Oops, something went wrong.
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
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
// When using ESM, the default export won't work unless we use .d.mts instead of .d.ts extension | ||
import fs from 'fs/promises'; | ||
import path from 'path'; | ||
|
||
if (process.argv.length < 3) { | ||
throw new Error('Missing folder'); | ||
} | ||
|
||
const folder = process.argv[2]; | ||
console.log(folder); | ||
const extLength = '.m.ts'.length; | ||
|
||
const files = await fs.readdir(folder); | ||
const promises = files | ||
.filter((file) => /\.d\.ts$/.test(file)) | ||
.map(async (file) => { | ||
const fullFile = path.join(folder, file); | ||
const newFullFile = `${fullFile.substring(0, fullFile.length - extLength)}.d.mts`; | ||
|
||
await fs.rename(fullFile, newFullFile); | ||
|
||
const content = (await fs.readFile(newFullFile)).toString(); | ||
const newContent = content.replaceAll( | ||
/ from \'([^']+)\'/g, | ||
` from '$1.d.mts'`, | ||
); | ||
|
||
await fs.writeFile(newFullFile, newContent); | ||
}); | ||
|
||
await Promise.all(promises); |