mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-14 02:23:31 +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:
@@ -0,0 +1,21 @@
|
||||
import common from 'eslint-config-neon/common';
|
||||
import node from 'eslint-config-neon/node';
|
||||
import prettier from 'eslint-config-neon/prettier';
|
||||
|
||||
const config = [
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
...common,
|
||||
...node,
|
||||
...prettier,
|
||||
{
|
||||
rules: {
|
||||
'jsdoc/check-tag-names': 0,
|
||||
'jsdoc/no-undefined-types': 0,
|
||||
'jsdoc/valid-types': 0,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default config;
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "[REPLACE_ME]",
|
||||
"name": "@discordjs/template-bun-javascript",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"lint": "prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
|
||||
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
|
||||
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
|
||||
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
|
||||
"lint": "prettier --check . && eslint --ext .js --format=pretty src",
|
||||
"deploy": "bun run src/util/deploy.js",
|
||||
"format": "prettier --write . && eslint --ext .js --fix --format=pretty src",
|
||||
"start": "bun run src/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/core": "^2.4.0",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
console.log();
|
||||
@@ -0,0 +1,26 @@
|
||||
import common from 'eslint-config-neon/common';
|
||||
import node from 'eslint-config-neon/node';
|
||||
import prettier from 'eslint-config-neon/prettier';
|
||||
import typescript from 'eslint-config-neon/typescript';
|
||||
|
||||
const config = [
|
||||
{
|
||||
ignores: [],
|
||||
},
|
||||
...common,
|
||||
...node,
|
||||
...typescript,
|
||||
...prettier,
|
||||
{
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.eslint.json'],
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'import/extensions': 0,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default config;
|
||||
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "[REPLACE_ME]",
|
||||
"name": "@discordjs/template-bun-typescript",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"lint": "tsc && prettier --check . && eslint --ext .[REPLACE_IMPORT_EXT] --format=pretty src",
|
||||
"deploy": "bun run src/util/deploy.[REPLACE_IMPORT_EXT]",
|
||||
"format": "prettier --write . && eslint --ext .[REPLACE_IMPORT_EXT] --fix --format=pretty src",
|
||||
"start": "bun run src/index.[REPLACE_IMPORT_EXT]"
|
||||
"lint": "tsc && prettier --check . && eslint --ext .ts --format=pretty src",
|
||||
"deploy": "bun run src/util/deploy.ts",
|
||||
"format": "prettier --write . && eslint --ext .ts --fix --format=pretty src",
|
||||
"start": "bun run src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/core": "^2.4.0",
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
export {};
|
||||
@@ -2,14 +2,14 @@
|
||||
"$schema": "https://json.schemastore.org/tsconfig.json",
|
||||
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
|
||||
"compilerOptions": {
|
||||
"allowImportingTsExtensions": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"incremental": false,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"target": "ESNext",
|
||||
"outDir": "dist",
|
||||
"noEmit": true,
|
||||
"allowImportingTsExtensions": true,
|
||||
"target": "ESNext",
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@
|
||||
"editor.trimAutoWhitespace": false,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.eol": "\n",
|
||||
"deno.enable": "[REPLACE_BOOL]"
|
||||
"deno.enable": true
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { PathLike } from 'node:fs';
|
||||
import { glob, stat } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { basename, resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { Command } from '../commands/index.ts';
|
||||
import { predicate as commandPredicate } from '../commands/index.ts';
|
||||
@@ -43,7 +43,7 @@ export async function loadStructures<Structure>(
|
||||
// Loop through all the matching files in the directory
|
||||
for await (const file of glob(pattern)) {
|
||||
// If the file is index.ts, skip the file
|
||||
if (file.endsWith('/index.ts')) {
|
||||
if (basename(file) === 'index.ts') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
pnpm-lock.yaml
|
||||
@@ -2,7 +2,6 @@
|
||||
"recommendations": [
|
||||
"esbenp.prettier-vscode",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"tamasfe.even-better-toml",
|
||||
"codezombiech.gitignore",
|
||||
"christian-kohler.npm-intellisense",
|
||||
"christian-kohler.path-intellisense"
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
"editor.trimAutoWhitespace": false,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.eol": "\n",
|
||||
"npm.packageManager": "[REPLACE_ME]"
|
||||
"npm.packageManager": "[REPLACE_PACKAGE_MANAGER]"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "[REPLACE_ME]",
|
||||
"name": "@discordjs/template-javascript",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { glob, stat } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { basename, resolve } from 'node:path';
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
import { predicate as commandPredicate } from '../commands/index.js';
|
||||
import { predicate as eventPredicate } from '../events/index.js';
|
||||
@@ -40,7 +40,7 @@ export async function loadStructures(dir, predicate, recursive = true) {
|
||||
// Loop through all the matching files in the directory
|
||||
for await (const file of glob(pattern)) {
|
||||
// If the file is index.js, skip the file
|
||||
if (file.endsWith('/index.js')) {
|
||||
if (basename(file) === 'index.js') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
dist
|
||||
pnpm-lock.yaml
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"recommendations": [
|
||||
"esbenp.prettier-vscode",
|
||||
"dbaeumer.vscode-eslint",
|
||||
"tamasfe.even-better-toml",
|
||||
"codezombiech.gitignore",
|
||||
"christian-kohler.npm-intellisense",
|
||||
"christian-kohler.path-intellisense"
|
||||
|
||||
@@ -9,5 +9,5 @@
|
||||
"editor.trimAutoWhitespace": false,
|
||||
"files.insertFinalNewline": true,
|
||||
"files.eol": "\n",
|
||||
"npm.packageManager": "[REPLACE_ME]"
|
||||
"npm.packageManager": "[REPLACE_PACKAGE_MANAGER]"
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import typescript from 'eslint-config-neon/typescript';
|
||||
|
||||
const config = [
|
||||
{
|
||||
ignores: ['**/dist/*'],
|
||||
ignores: [],
|
||||
},
|
||||
...common,
|
||||
...node,
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/package.json",
|
||||
"name": "[REPLACE_ME]",
|
||||
"name": "@discordjs/template-typescript",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"lint": "prettier --check . && eslint --ext .ts --format=pretty src",
|
||||
"deploy": "node --env-file=.env dist/util/deploy.js",
|
||||
"deploy": "node --env-file=.env src/util/deploy.ts",
|
||||
"format": "prettier --write . && eslint --ext .ts --fix --format=pretty src",
|
||||
"start": "node --env-file=.env dist/index.js"
|
||||
"start": "node --env-file=.env src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@discordjs/core": "^2.4.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { RESTPostAPIApplicationCommandsJSONBody, CommandInteraction } from 'discord.js';
|
||||
import { z } from 'zod';
|
||||
import type { StructurePredicate } from '../util/loaders.[REPLACE_IMPORT_EXT]';
|
||||
import type { StructurePredicate } from '../util/loaders.ts';
|
||||
|
||||
/**
|
||||
* Defines the structure of a command
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Command } from './index.[REPLACE_IMPORT_EXT]';
|
||||
import type { Command } from './index.ts';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { Command } from '../index.[REPLACE_IMPORT_EXT]';
|
||||
import type { Command } from '../index.ts';
|
||||
|
||||
export default {
|
||||
data: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ClientEvents } from 'discord.js';
|
||||
import { z } from 'zod';
|
||||
import type { StructurePredicate } from '../util/loaders.[REPLACE_IMPORT_EXT]';
|
||||
import type { StructurePredicate } from '../util/loaders.ts';
|
||||
|
||||
/**
|
||||
* Defines the structure of an event.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { URL } from 'node:url';
|
||||
import { Events } from 'discord.js';
|
||||
import { loadCommands } from '../util/loaders.[REPLACE_IMPORT_EXT]';
|
||||
import type { Event } from './index.[REPLACE_IMPORT_EXT]';
|
||||
import { loadCommands } from '../util/loaders.ts';
|
||||
import type { Event } from './index.ts';
|
||||
|
||||
const commands = await loadCommands(new URL('../commands/', import.meta.url));
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Events } from 'discord.js';
|
||||
import type { Event } from './index.[REPLACE_IMPORT_EXT]';
|
||||
import type { Event } from './index.ts';
|
||||
|
||||
export default {
|
||||
name: Events.ClientReady,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import process from 'node:process';
|
||||
import { URL } from 'node:url';
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
import { loadEvents } from './util/loaders.[REPLACE_IMPORT_EXT]';
|
||||
import { loadEvents } from './util/loaders.ts';
|
||||
|
||||
// Initialize the client
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
@@ -2,7 +2,7 @@ import process from 'node:process';
|
||||
import { URL } from 'node:url';
|
||||
import { API } from '@discordjs/core/http-only';
|
||||
import { REST } from 'discord.js';
|
||||
import { loadCommands } from './loaders.[REPLACE_IMPORT_EXT]';
|
||||
import { loadCommands } from './loaders.ts';
|
||||
|
||||
const commands = await loadCommands(new URL('../commands/', import.meta.url));
|
||||
const commandData = [...commands.values()].map((command) => command.data);
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import type { PathLike } from 'node:fs';
|
||||
import { glob, stat } from 'node:fs/promises';
|
||||
import { resolve } from 'node:path';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import type { Command } from '../commands/index.[REPLACE_IMPORT_EXT]';
|
||||
import { predicate as commandPredicate } from '../commands/index.[REPLACE_IMPORT_EXT]';
|
||||
import type { Event } from '../events/index.[REPLACE_IMPORT_EXT]';
|
||||
import { predicate as eventPredicate } from '../events/index.[REPLACE_IMPORT_EXT]';
|
||||
import { basename, resolve } from 'node:path';
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
import { predicate as commandPredicate, type Command } from '../commands/index.ts';
|
||||
import { predicate as eventPredicate, type Event } from '../events/index.ts';
|
||||
|
||||
/**
|
||||
* A predicate to check if the structure is valid
|
||||
@@ -36,14 +34,14 @@ export async function loadStructures<Structure>(
|
||||
// Create an empty array to store the structures
|
||||
const structures: Structure[] = [];
|
||||
|
||||
// Create a glob pattern to match the .[REPLACE_IMPORT_EXT] files
|
||||
// Create a glob pattern to match the .ts files
|
||||
const basePath = dir instanceof URL ? fileURLToPath(dir) : dir.toString();
|
||||
const pattern = resolve(basePath, recursive ? '**/*.[REPLACE_IMPORT_EXT]' : '*.[REPLACE_IMPORT_EXT]');
|
||||
const pattern = resolve(basePath, recursive ? '**/*.ts' : '*.ts');
|
||||
|
||||
// Loop through all the matching files in the directory
|
||||
for await (const file of glob(pattern)) {
|
||||
// If the file is index.[REPLACE_IMPORT_EXT], skip the file
|
||||
if (file.endsWith('/index.[REPLACE_IMPORT_EXT]')) {
|
||||
// If the file is index.ts, skip the file
|
||||
if (basename(file) === 'index.ts') {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,15 @@
|
||||
"$schema": "https://json.schemastore.org/tsconfig.json",
|
||||
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
|
||||
"compilerOptions": {
|
||||
"allowImportingTsExtensions": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"declaration": false,
|
||||
"declarationMap": false,
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"incremental": false,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Bundler",
|
||||
"noEmit": true,
|
||||
"target": "ESNext",
|
||||
"outDir": "dist",
|
||||
"skipLibCheck": true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user