-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: export "ESM" types when discord.js is imported in ESM land (#10009)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
30f6a5f
commit e412a22
Showing
6 changed files
with
58 additions
and
4 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 |
---|---|---|
|
@@ -25,3 +25,7 @@ docs/**/* | |
# Miscellaneous | ||
.turbo | ||
.tmp | ||
|
||
# Generated files | ||
typings/index.d.mts | ||
typings/rawDataTypes.d.mts |
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,38 @@ | ||
import { readFile, writeFile } from 'node:fs/promises'; | ||
|
||
const rawTypesDTS = new URL('../typings/rawDataTypes.d.ts', import.meta.url); | ||
const rawIndexDTS = new URL('../typings/index.d.ts', import.meta.url); | ||
|
||
const rawTypesMDTS = new URL('../typings/rawDataTypes.d.mts', import.meta.url); | ||
const rawIndexMTS = new URL('../typings/index.d.mts', import.meta.url); | ||
|
||
const [rawTypesString, rawIndexString] = await Promise.all([ | ||
readFile(rawTypesDTS, 'utf8'), | ||
readFile(rawIndexDTS, 'utf8'), | ||
]); | ||
|
||
/** | ||
* | ||
* @param {string} source | ||
* @param {[from: string, to: string][]} imports | ||
*/ | ||
function updateImports(source, imports) { | ||
return imports.reduce((code, [from, to]) => { | ||
return code.replaceAll(from, to); | ||
}, source); | ||
} | ||
|
||
/** @type {[string, string][]} */ | ||
const rawTypesImports = [ | ||
['./index.js', './index.mjs'], // | ||
]; | ||
|
||
/** @type {[string, string][]} */ | ||
const rawIndexImports = [ | ||
['./rawDataTypes.js', './rawDataTypes.mjs'], // | ||
]; | ||
|
||
const rawTypesMDTSString = updateImports(rawTypesString, rawTypesImports); | ||
const rawIndexMTSString = updateImports(rawIndexString, rawIndexImports); | ||
|
||
await Promise.all([writeFile(rawTypesMDTS, rawTypesMDTSString), writeFile(rawIndexMTS, rawIndexMTSString)]); |
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