From 446da67d6dc3fac1d14ba1308ce2904c997f7706 Mon Sep 17 00:00:00 2001 From: Erik Demaine Date: Sat, 21 Dec 2024 19:02:42 -0500 Subject: [PATCH] Extension bug fix for unplugin on webpack; cleanup old bug workarounds --- source/unplugin/unplugin.civet | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/source/unplugin/unplugin.civet b/source/unplugin/unplugin.civet index e43137d6..7d85e0af 100644 --- a/source/unplugin/unplugin.civet +++ b/source/unplugin/unplugin.civet @@ -142,7 +142,7 @@ export const rawPlugin: Parameters>[0] = cache := new Map unless options.cache is false - plugin: ReturnType & { __virtualModulePrefix?: string } := { + plugin: ReturnType := { name: 'unplugin-civet' enforce: 'pre' @@ -369,15 +369,6 @@ export const rawPlugin: Parameters>[0] = compilerOptions.outDir ?? process.cwd() filePath - // Work around unplugin+esbuild bug where it only creates the - // root output directory, not any subdirectories. - if meta.framework is 'esbuild' - fs.mkdirSync - path.dirname( - path.resolve(esbuildOptions.outdir!, pathFromDistDir) - ) - recursive: true - this.emitFile source: content fileName: pathFromDistDir @@ -392,15 +383,6 @@ export const rawPlugin: Parameters>[0] = id = aliasResolver id if aliasResolver? if (/\0/.test(id)) return null - // unplugin webpack virtualizes our resolved paths, by prepending - // plugin.__virtualModulePrefix and then encodeURIComponent. - // [https://github.com/unjs/unplugin/blob/f6ceb5092715b8047eeb069b249b919f3ef2bcfb/src/webpack/index.ts#L131] - // Undo this transformation on the `importer` path - // so we can correctly resolve its directory. - if plugin.__virtualModulePrefix and - importer?.startsWith plugin.__virtualModulePrefix - importer = decodeURIComponent importer[plugin.__virtualModulePrefix#..] - let postfix: string {id, postfix} = cleanCivetId(id) resolvedId .= @@ -598,7 +580,12 @@ export const rawPlugin: Parameters>[0] = } webpack(compiler) - compiler.options.resolve.extensions.unshift ".civet" if implicitExtension + if implicitExtension + compiler.options ?= {} + compiler.options.resolve ?= {} + // Default from https://webpack.js.org/configuration/resolve/#resolveextensions + compiler.options.resolve.extensions ?= ['', '.js', '.json', '.wasm'] + compiler.options.resolve.extensions.unshift ".civet" aliasResolver = (id) => // Based on normalizeAlias from // https://github.com/webpack/enhanced-resolve/blob/72999caf002f6f7bb4624e65fdeb7ba980b11e24/lib/ResolverFactory.js#L158