diff --git a/scripts/build/build.mts b/scripts/build/build.mts index 6e936257..cc74f0e7 100644 --- a/scripts/build/build.mts +++ b/scripts/build/build.mts @@ -23,7 +23,7 @@ import { existsSync, readdirSync } from "fs"; import { readdir, rm, writeFile } from "fs/promises"; import { join } from "path"; -import { addBuild, BUILD_TIMESTAMP, buildOrWatchAll, commonOpts, commonRendererPlugins, exists, globPlugins, IS_DEV, IS_REPORTER, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, watch } from "./common.mjs"; +import { addBuild, BUILD_TIMESTAMP, buildOrWatchAll, commonOpts, exists, globPlugins, IS_DEV, IS_REPORTER, IS_STANDALONE, IS_UPDATER_DISABLED, resolvePluginName, VERSION, watch } from "./common.mjs"; const defines = { IS_STANDALONE: String(IS_STANDALONE), @@ -128,7 +128,7 @@ await Promise.all([ sourcemap, plugins: [ globPlugins("discordDesktop"), - ...commonRendererPlugins + ...commonOpts.plugins ], define: { ...defines, @@ -180,7 +180,7 @@ await Promise.all([ sourcemap, plugins: [ globPlugins("vencordDesktop"), - ...commonRendererPlugins + ...commonOpts.plugins ], define: { ...defines, @@ -232,7 +232,7 @@ await Promise.all([ sourcemap, plugins: [ globPlugins("equicordDesktop"), - ...commonRendererPlugins + ...commonOpts.plugins ], define: { ...defines, diff --git a/scripts/build/buildWeb.mts b/scripts/build/buildWeb.mts index fd465868..8f1b33ef 100644 --- a/scripts/build/buildWeb.mts +++ b/scripts/build/buildWeb.mts @@ -23,7 +23,7 @@ import { appendFile, mkdir, readdir, readFile, rm, writeFile } from "fs/promises import { join } from "path"; import Zip from "zip-local"; -import { addBuild, BUILD_TIMESTAMP, buildOrWatchAll, commonOpts, commonRendererPlugins, globPlugins, IS_DEV, IS_REPORTER, VERSION } from "./common.mjs"; +import { addBuild, BUILD_TIMESTAMP, buildOrWatchAll, commonOpts, globPlugins, IS_DEV, IS_REPORTER, VERSION } from "./common.mjs"; /** * @type {esbuild.BuildOptions} @@ -36,7 +36,7 @@ const commonOptions: esbuild.BuildOptions = { external: ["~plugins", "~git-hash", "/assets/*"], plugins: [ globPlugins("web"), - ...commonRendererPlugins + ...commonOpts.plugins ], target: ["esnext"], define: { diff --git a/scripts/build/common.mts b/scripts/build/common.mts index 72d842ca..c2321fcf 100644 --- a/scripts/build/common.mts +++ b/scripts/build/common.mts @@ -28,7 +28,6 @@ import { join, relative } from "path"; import { promisify } from "util"; import { getPluginTarget } from "../utils.mjs"; -import { builtinModules } from "module"; const PackageJSON: typeof import("../../package.json") = JSON.parse(readFileSync("package.json", "utf-8")); @@ -263,15 +262,6 @@ export const stylePlugin: Plugin = { } }; -export const banImportPlugin = (filter: RegExp, message: string) => ({ - name: "ban-imports", - setup: build => { - build.onResolve({ filter }, () => { - return { errors: [{ text: message }] }; - }); - } -}); - export const commonOpts = { logLevel: "info", bundle: true, @@ -312,15 +302,3 @@ export async function buildOrWatchAll() { } } } - -const escapedBuiltinModules = builtinModules - .map(m => m.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")) - .join("|"); -const builtinModuleRegex = new RegExp(`^(node:)?(${escapedBuiltinModules})$`); - -export const commonRendererPlugins = [ - banImportPlugin(builtinModuleRegex, "Cannot import node inbuilt modules in browser code. You need to use a native.ts file"), - banImportPlugin(/^react$/, "Cannot import from react. React and hooks should be imported from @webpack/common"), - banImportPlugin(/^electron(\/.*)?$/, "Cannot import electron in browser code. You need to use a native.ts file"), - ...commonOpts.plugins -];