From 47731a4525b26bf9e195ca05fe5412423bbae178 Mon Sep 17 00:00:00 2001 From: Corbin Crutchley Date: Fri, 7 Jun 2024 03:42:26 -0700 Subject: [PATCH] chore: WIP on resolve plugin --- scripts/esbuild.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/scripts/esbuild.ts b/scripts/esbuild.ts index a249f71..35cdca0 100644 --- a/scripts/esbuild.ts +++ b/scripts/esbuild.ts @@ -18,5 +18,41 @@ build({ path.resolve(__dirname, "../exe-src/inject-asar-fs.ts"), path.resolve(__dirname, "../exe-src/inject-asar-binding.ts") ], + plugins: [ + { + name: "next-compiled-module-resolution", + setup(build) { + const resolvedSymbol = Symbol(); + build.onResolve({filter: /./}, async (args) => { + if (args.kind !== "require-call") return; + if (args.pluginData === resolvedSymbol) return; + + const resolved = await build.resolve(args.path, { + kind: args.kind, + importer: args.importer, + resolveDir: args.resolveDir, + pluginData: resolvedSymbol + }) + + if (resolved.errors.length > 0) { + const second = await build.resolve(args.path, { + kind: args.kind, + importer: args.importer, + resolveDir: path.resolve(__dirname, "../node_modules/next/dist/compiled"), + pluginData: resolvedSymbol + }) + + if (second.errors.length > 0) { + return {errors: resolved.errors} + } + + return second; + } + + return resolved; + }) + } + } + ], entryPoints: [path.resolve(__dirname, "../exe-src/start.js")] }) -- 2.51.2