fix: failed build in node and bad lints (#10444)

* fix: failed build in node and bad lints

* chore: update tsconfigs

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
Almeida
2024-08-20 23:40:37 +01:00
committed by GitHub
parent dd795da790
commit 00accf7470
6 changed files with 24 additions and 6 deletions

View File

@@ -6,7 +6,7 @@ import { URL } from 'node:url';
import glob from 'fast-glob'; import glob from 'fast-glob';
import picocolors from 'picocolors'; import picocolors from 'picocolors';
import type { PackageManager } from './helpers/packageManager.js'; import type { PackageManager } from './helpers/packageManager.js';
import { install } from './helpers/packageManager.js'; import { install, isNodePackageManager } from './helpers/packageManager.js';
import { GUIDE_URL } from './util/constants.js'; import { GUIDE_URL } from './util/constants.js';
interface Options { interface Options {
@@ -83,7 +83,7 @@ export async function createDiscordBot({ directory, installPackages, typescript,
const globStream = glob.stream('./src/**/*.ts'); const globStream = glob.stream('./src/**/*.ts');
for await (const file of globStream) { for await (const file of globStream) {
const newData = await readFile(file, { encoding: 'utf8' }).then((str) => const newData = await readFile(file, { encoding: 'utf8' }).then((str) =>
str.replaceAll('[REPLACE_IMPORT_EXT]', typescript ? 'ts' : 'js'), str.replaceAll('[REPLACE_IMPORT_EXT]', typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js'),
); );
await writeFile(file, newData); await writeFile(file, newData);
} }
@@ -93,7 +93,10 @@ export async function createDiscordBot({ directory, installPackages, typescript,
encoding: 'utf8', encoding: 'utf8',
}).then((str) => { }).then((str) => {
let newStr = str.replace('[REPLACE_ME]', directoryName); let newStr = str.replace('[REPLACE_ME]', directoryName);
newStr = newStr.replaceAll('[REPLACE_IMPORT_EXT]', typescript ? 'ts' : 'js'); newStr = newStr.replaceAll(
'[REPLACE_IMPORT_EXT]',
typescript && !isNodePackageManager(packageManager) ? 'ts' : 'js',
);
return newStr; return newStr;
}); });
await writeFile('./package.json', newPackageJSON); await writeFile('./package.json', newPackageJSON);

View File

@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process'; import { execSync } from 'node:child_process';
import process from 'node:process'; import process from 'node:process';
import picocolors from 'picocolors'; import picocolors from 'picocolors';
import { DEFAULT_PACKAGE_MANAGER } from '../util/constants.js'; import { DEFAULT_PACKAGE_MANAGER, NODE_PACKAGE_MANAGERS } from '../util/constants.js';
/** /**
* A union of supported package managers. * A union of supported package managers.
@@ -110,3 +110,12 @@ export function install(packageManager: PackageManager) {
env, 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);
}

View File

@@ -13,6 +13,11 @@ export const DEFAULT_PROJECT_NAME = 'my-bot' as const;
*/ */
export const PACKAGE_MANAGERS = ['npm', 'pnpm', 'yarn', 'bun', 'deno'] 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. * The URL to the guide.
*/ */

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json.schemastore.org/tsconfig.json", "$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@sapphire/ts-config/extra-strict", "extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
"compilerOptions": { "compilerOptions": {
"declaration": false, "declaration": false,
"declarationMap": false, "declarationMap": false,

View File

@@ -0,0 +1 @@
dist

View File

@@ -1,6 +1,6 @@
{ {
"$schema": "https://json.schemastore.org/tsconfig.json", "$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@sapphire/ts-config/extra-strict", "extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
"compilerOptions": { "compilerOptions": {
"declaration": false, "declaration": false,
"declarationMap": false, "declarationMap": false,