Skip to content

Commit

Permalink
fix: failed build in node and bad lints (#10444)
Browse files Browse the repository at this point in the history
* fix: failed build in node and bad lints

* chore: update tsconfigs

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
almeidx and kodiakhq[bot] authored Aug 20, 2024
1 parent dd795da commit 00accf7
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 6 deletions.
9 changes: 6 additions & 3 deletions packages/create-discord-bot/src/create-discord-bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { URL } from 'node:url';
import glob from 'fast-glob';
import picocolors from 'picocolors';
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';

interface Options {
Expand Down Expand Up @@ -83,7 +83,7 @@ export async function createDiscordBot({ directory, installPackages, typescript,
const globStream = glob.stream('./src/**/*.ts');
for await (const file of globStream) {
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);
}
Expand All @@ -93,7 +93,10 @@ export async function createDiscordBot({ directory, installPackages, typescript,
encoding: 'utf8',
}).then((str) => {
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;
});
await writeFile('./package.json', newPackageJSON);
Expand Down
11 changes: 10 additions & 1 deletion packages/create-discord-bot/src/helpers/packageManager.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { execSync } from 'node:child_process';
import process from 'node:process';
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.
Expand Down Expand Up @@ -110,3 +110,12 @@ 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);
}
5 changes: 5 additions & 0 deletions packages/create-discord-bot/src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ 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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@sapphire/ts-config/extra-strict",
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
"compilerOptions": {
"declaration": false,
"declarationMap": false,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://json.schemastore.org/tsconfig.json",
"extends": "@sapphire/ts-config/extra-strict",
"extends": ["@sapphire/ts-config", "@sapphire/ts-config/extra-strict"],
"compilerOptions": {
"declaration": false,
"declarationMap": false,
Expand Down

0 comments on commit 00accf7

Please sign in to comment.