mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
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>
This commit is contained in:
@@ -202,7 +202,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"files": ["typings/*.ts"],
|
"files": ["typings/*.ts", "scripts/*.mjs"],
|
||||||
"parser": "@typescript-eslint/parser",
|
"parser": "@typescript-eslint/parser",
|
||||||
"plugins": ["@typescript-eslint"],
|
"plugins": ["@typescript-eslint"],
|
||||||
"rules": {
|
"rules": {
|
||||||
|
|||||||
4
packages/discord.js/.gitignore
vendored
4
packages/discord.js/.gitignore
vendored
@@ -25,3 +25,7 @@ docs/**/*
|
|||||||
# Miscellaneous
|
# Miscellaneous
|
||||||
.turbo
|
.turbo
|
||||||
.tmp
|
.tmp
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
typings/index.d.mts
|
||||||
|
typings/rawDataTypes.d.mts
|
||||||
|
|||||||
@@ -12,12 +12,24 @@
|
|||||||
"docs": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
|
"docs": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../ -o ./docs/docs.json && pnpm run docs:new",
|
||||||
"docs:test": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../",
|
"docs:test": "docgen -i './src/*.js' './src/**/*.js' -c ./docs/index.json -r ../../",
|
||||||
"docs:new": "api-extractor run --local --minify",
|
"docs:new": "api-extractor run --local --minify",
|
||||||
"prepack": "pnpm run lint && pnpm run test",
|
"prepack": "pnpm run lint && pnpm run test && node ./scripts/esmDts.mjs",
|
||||||
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/discord.js/*'",
|
"changelog": "git cliff --prepend ./CHANGELOG.md -u -c ./cliff.toml -r ../../ --include-path 'packages/discord.js/*'",
|
||||||
"release": "cliff-jumper"
|
"release": "cliff-jumper"
|
||||||
},
|
},
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"types": "./typings/index.d.ts",
|
"types": "./typings/index.d.ts",
|
||||||
|
"exports": {
|
||||||
|
".": {
|
||||||
|
"import": {
|
||||||
|
"types": "./typings/index.d.mts",
|
||||||
|
"default": "./src/index.js"
|
||||||
|
},
|
||||||
|
"require": {
|
||||||
|
"types": "./typings/index.d.ts",
|
||||||
|
"default": "./src/index.js"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "src",
|
"lib": "src",
|
||||||
"test": "test"
|
"test": "test"
|
||||||
|
|||||||
38
packages/discord.js/scripts/esmDts.mjs
Normal file
38
packages/discord.js/scripts/esmDts.mjs
Normal file
@@ -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)]);
|
||||||
2
packages/discord.js/typings/index.d.ts
vendored
2
packages/discord.js/typings/index.d.ts
vendored
@@ -231,7 +231,7 @@ import {
|
|||||||
RawWelcomeScreenData,
|
RawWelcomeScreenData,
|
||||||
RawWidgetData,
|
RawWidgetData,
|
||||||
RawWidgetMemberData,
|
RawWidgetMemberData,
|
||||||
} from './rawDataTypes';
|
} from './rawDataTypes.js';
|
||||||
|
|
||||||
declare module 'node:events' {
|
declare module 'node:events' {
|
||||||
class EventEmitter {
|
class EventEmitter {
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ import {
|
|||||||
Snowflake,
|
Snowflake,
|
||||||
APIGuildScheduledEvent,
|
APIGuildScheduledEvent,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import { GuildChannel, Guild, PermissionOverwrites } from '.';
|
import { GuildChannel, Guild, PermissionOverwrites } from './index.js';
|
||||||
|
|
||||||
export type RawActivityData = GatewayActivity;
|
export type RawActivityData = GatewayActivity;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user