35 lines
1.1 KiB
JavaScript
35 lines
1.1 KiB
JavaScript
/**
|
|
* Standalone pack binding. Static import so bare-pack rewrites discord.js
|
|
* into the host bundle. Adapters in ws-bootstrap.cjs must load first.
|
|
* Avoid Node `module` / createRequire — those are missing in the packed graph.
|
|
*/
|
|
import discord from 'discord.js';
|
|
import registry from './registry.js';
|
|
|
|
const registerPackedDiscordJs =
|
|
(registry && registry.registerPackedDiscordJs) ||
|
|
(registry && registry.default && registry.default.registerPackedDiscordJs);
|
|
|
|
function unwrap(mod) {
|
|
if (mod && typeof mod.Client === 'function') return mod;
|
|
const def = mod && mod.default;
|
|
if (def && typeof def === 'object' && typeof def.Client === 'function') return def;
|
|
return null;
|
|
}
|
|
|
|
function applyShims(d) {
|
|
if (!d || typeof d !== 'object') return d;
|
|
const events = d.Events;
|
|
if (events && events.ClientReady && events.Ready == null) {
|
|
events.Ready = events.ClientReady;
|
|
}
|
|
return d;
|
|
}
|
|
|
|
if (typeof registerPackedDiscordJs !== 'function') {
|
|
throw new Error('discord registry missing registerPackedDiscordJs');
|
|
}
|
|
|
|
export const bareDiscordJs = registerPackedDiscordJs(applyShims(unwrap(discord)));
|
|
export default bareDiscordJs;
|