diff --git a/package.json b/package.json index a935756..064d056 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "license": "ISC", "devDependencies": { "@electron/asar": "^3.2.1", - "@fal-works/esbuild-plugin-global-externals": "^2.1.2", "@types/node": "^18.11.2", "@typescript-eslint/eslint-plugin": "^5.40.1", "@typescript-eslint/parser": "^5.40.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 18e8eba..3802883 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -2,7 +2,6 @@ lockfileVersion: 5.4 specifiers: '@electron/asar': ^3.2.1 - '@fal-works/esbuild-plugin-global-externals': ^2.1.2 '@types/node': ^18.11.2 '@typescript-eslint/eslint-plugin': ^5.40.1 '@typescript-eslint/parser': ^5.40.1 @@ -18,7 +17,6 @@ specifiers: devDependencies: '@electron/asar': 3.2.1 - '@fal-works/esbuild-plugin-global-externals': 2.1.2 '@types/node': 18.11.2 '@typescript-eslint/eslint-plugin': 5.40.1_ukgdydjtebaxmxfqp5v5ulh64y '@typescript-eslint/parser': 5.40.1_z4bbprzjrhnsfa24uvmcbu7f5q @@ -103,10 +101,6 @@ packages: - supports-color dev: true - /@fal-works/esbuild-plugin-global-externals/2.1.2: - resolution: {integrity: sha512-cEee/Z+I12mZcFJshKcCqC8tuX5hG3s+d+9nZ3LabqKF1vKdF41B92pJVCBggjAGORAeOzyyDDKrZwIkLffeOQ==} - dev: true - /@humanwhocodes/config-array/0.10.7: resolution: {integrity: sha512-MDl6D6sBsaV452/QSdX+4CXIjZhIcI0PELsxUjk4U828yd58vk3bTIvk/6w5FY+4hIy9sLW0sfrV7K7Kc++j/w==} engines: {node: '>=10.10.0'} diff --git a/scripts/build.ts b/scripts/build.ts index 4f0e84f..77d1c09 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -1,5 +1,4 @@ import esbuild from "esbuild"; -import { globalExternals } from "@fal-works/esbuild-plugin-global-externals"; import path, { join } from "path"; import fs, { existsSync, rmSync } from "fs"; import _manifest from "../manifest.json"; @@ -10,26 +9,41 @@ const manifest: Plugin = _manifest; const NODE_VERSION = "14"; const CHROME_VERSION = "91"; -const globalModules = { - replugged: { - varName: "replugged", - namedExports: [ - "Injector", - "Logger", - "webpack", - "common", - "notices", - "commands", - "settings", - "quickCSS", - "themes", - "ignition", - "plugins", - "util", - "logger", - "types", - ], - defaultExport: true, +const globalModules: esbuild.Plugin = { + name: "globalModules", + setup: (build) => { + build.onResolve({ filter: /^replugged.+$/ }, (args) => { + if (args.kind !== "import-statement") return; + + return { + errors: [ + { + text: `Importing from a path (${args.path}) is not supported. Instead, please import from "replugged" and destructure the required modules.`, + }, + ], + }; + }); + + build.onResolve({ filter: /^replugged$/ }, (args) => { + if (args.kind !== "import-statement") return; + + return { + path: args.path, + namespace: "replugged", + }; + }); + + build.onLoad( + { + filter: /.*/, + namespace: "replugged", + }, + () => { + return { + contents: "module.exports = window.replugged", + }; + }, + ); }, }; @@ -88,7 +102,7 @@ if ("renderer" in manifest) { target: `chrome${CHROME_VERSION}`, outfile: "dist/renderer.js", format: "esm" as esbuild.Format, - plugins: [globalExternals(globalModules), install], + plugins: [globalModules, install], }), ); @@ -134,7 +148,7 @@ if ("plaintextPatches" in manifest) { target: `chrome${CHROME_VERSION}`, outfile: "dist/plaintextPatches.js", format: "esm" as esbuild.Format, - plugins: [globalExternals(globalModules), install], + plugins: [globalModules, install], }), );