mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
feat: use native node typescript (#11259)
* feat: use native node typescript * fix: use basename * Update packages/create-discord-bot/template/Bun/TypeScript/tsconfig.json Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Change module and moduleResolution to ESNext and Bundler --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import type { ExecException } from 'node:child_process';
|
||||
import { cp, glob, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import { cp, mkdir, stat, readdir, readFile, writeFile } from 'node:fs/promises';
|
||||
import path from 'node:path';
|
||||
import process from 'node:process';
|
||||
import { URL } from 'node:url';
|
||||
import { styleText } from 'node:util';
|
||||
import type { PackageManager } from './helpers/packageManager.js';
|
||||
import { install, isNodePackageManager } from './helpers/packageManager.js';
|
||||
import { install } from './helpers/packageManager.js';
|
||||
import { GUIDE_URL } from './util/constants.js';
|
||||
|
||||
interface Options {
|
||||
@@ -67,39 +67,18 @@ export async function createDiscordBot({ directory, installPackages, typescript,
|
||||
|
||||
process.chdir(root);
|
||||
|
||||
const newVSCodeSettings = await readFile('./.vscode/settings.json', {
|
||||
encoding: 'utf8',
|
||||
}).then((str) => {
|
||||
let newStr = str.replace('[REPLACE_ME]', deno || bun ? 'auto' : packageManager);
|
||||
if (deno) {
|
||||
// @ts-expect-error: This is fine
|
||||
newStr = newStr.replaceAll('"[REPLACE_BOOL]"', true);
|
||||
}
|
||||
|
||||
return newStr;
|
||||
});
|
||||
await writeFile('./.vscode/settings.json', newVSCodeSettings);
|
||||
|
||||
const globIterator = glob('./src/**/*.ts');
|
||||
for await (const file of globIterator) {
|
||||
const newData = await readFile(file, { encoding: 'utf8' }).then((str) =>
|
||||
str.replaceAll('[REPLACE_IMPORT_EXT]', typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js'),
|
||||
);
|
||||
await writeFile(file, newData);
|
||||
}
|
||||
const newVSCodeSettings = await readFile('./.vscode/settings.json', { encoding: 'utf8' });
|
||||
await writeFile(
|
||||
'./.vscode/settings.json',
|
||||
newVSCodeSettings.replace(
|
||||
/"npm\.packageManager":\s*"[^"]+"/,
|
||||
`"npm.packageManager": "${deno || bun ? 'auto' : packageManager}"`,
|
||||
),
|
||||
);
|
||||
|
||||
if (!deno) {
|
||||
const newPackageJSON = await readFile('./package.json', {
|
||||
encoding: 'utf8',
|
||||
}).then((str) => {
|
||||
let newStr = str.replace('[REPLACE_ME]', directoryName);
|
||||
newStr = newStr.replaceAll(
|
||||
'[REPLACE_IMPORT_EXT]',
|
||||
typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js',
|
||||
);
|
||||
return newStr;
|
||||
});
|
||||
await writeFile('./package.json', newPackageJSON);
|
||||
const newPackageJSON = await readFile('./package.json', { encoding: 'utf8' });
|
||||
await writeFile('./package.json', newPackageJSON.replace(/"name":\s*"[^"]+"/, `"name": "${directoryName}"`));
|
||||
}
|
||||
|
||||
if (installPackages) {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { execSync } from 'node:child_process';
|
||||
import process from 'node:process';
|
||||
import { styleText } from 'node:util';
|
||||
import { DEFAULT_PACKAGE_MANAGER, NODE_PACKAGE_MANAGERS } from '../util/constants.js';
|
||||
import { DEFAULT_PACKAGE_MANAGER, type PACKAGE_MANAGERS } from '../util/constants.js';
|
||||
|
||||
/**
|
||||
* A union of supported package managers.
|
||||
*/
|
||||
export type PackageManager = 'bun' | 'deno' | 'npm' | 'pnpm' | 'yarn';
|
||||
export type PackageManager = (typeof PACKAGE_MANAGERS)[number];
|
||||
|
||||
/**
|
||||
* Resolves the package manager from `npm_config_user_agent`.
|
||||
@@ -117,12 +117,3 @@ export function install(packageManager: PackageManager) {
|
||||
env,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the provided package manager is a Node package manager.
|
||||
*
|
||||
* @param packageManager - The package manager to check
|
||||
*/
|
||||
export function isNodePackageManager(packageManager: PackageManager): packageManager is 'npm' | 'pnpm' | 'yarn' {
|
||||
return NODE_PACKAGE_MANAGERS.includes(packageManager as any);
|
||||
}
|
||||
|
||||
@@ -13,11 +13,6 @@ export const DEFAULT_PROJECT_NAME = 'my-bot' as const;
|
||||
*/
|
||||
export const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'deno'] as const;
|
||||
|
||||
/**
|
||||
* The supported Node.js package managers.
|
||||
*/
|
||||
export const NODE_PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn'] as const;
|
||||
|
||||
/**
|
||||
* The URL to the guide.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user