build: switch to esbuild-plugin-version-injector for injecting version strings (#8723)

This commit is contained in:
Jeroen Claassens
2022-10-08 02:54:45 +02:00
committed by GitHub
parent 62332c2720
commit d923d0ab96
20 changed files with 91 additions and 13 deletions

View File

@@ -68,6 +68,7 @@
"@types/node": "^16.11.64",
"cross-env": "^7.0.3",
"downlevel-dts": "^0.10.1",
"esbuild-plugin-version-injector": "^1.0.0",
"eslint": "^8.24.0",
"eslint-config-neon": "^0.1.35",
"jest": "^29.1.2",

View File

@@ -19,3 +19,12 @@ export {
} from './VoiceConnection';
export { type JoinConfig, getVoiceConnection, getVoiceConnections, getGroups } from './DataStore';
/**
* The [\@discordjs/voice](https://github.com/discordjs/discord.js/blob/main/packages/voice/#readme) version
* that you are currently using.
*
* Note to developers: This needs to explicitly be `string` so it is not typed as a "const string" that gets injected by esbuild
*/
// eslint-disable-next-line @typescript-eslint/no-inferrable-types
export const version: string = '[VI]{{inject}}[/VI]';

View File

@@ -33,10 +33,11 @@ function findPackageJSON(
*/
function version(name: string): string {
try {
const pkg =
name === '@discordjs/voice'
? require('../../package.json')
: findPackageJSON(dirname(require.resolve(name)), name, 3);
if (name === '@discordjs/voice') {
return '[VI]{{inject}}[/VI]';
}
const pkg = findPackageJSON(dirname(require.resolve(name)), name, 3);
return pkg?.version ?? 'not found';
} catch {
return 'not found';

View File

@@ -1,3 +1,6 @@
import { esbuildPluginVersionInjector } from 'esbuild-plugin-version-injector';
import { createTsupConfig } from '../../tsup.config.js';
export default createTsupConfig();
export default createTsupConfig({
esbuildPlugins: [esbuildPluginVersionInjector()],
});