From 9bee320c7a83a9837b5a199844ca81537f6f3600 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Fri, 25 Aug 2023 14:57:25 +0100 Subject: [PATCH] fix(nuxt): fully resolve `unctx` where possible (#22811) --- packages/nuxt/src/core/nuxt.ts | 10 +++++++--- packages/nuxt/src/core/plugins/unctx.ts | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nuxt/src/core/nuxt.ts b/packages/nuxt/src/core/nuxt.ts index f992ec2433..36ccb593be 100644 --- a/packages/nuxt/src/core/nuxt.ts +++ b/packages/nuxt/src/core/nuxt.ts @@ -16,6 +16,7 @@ import importsModule from '../imports/module' import { distDir, pkgDir } from '../dirs' import { version } from '../../package.json' import { ImportProtectionPlugin, vueAppPatterns } from './plugins/import-protection' +import type { UnctxTransformPluginOptions } from './plugins/unctx' import { UnctxTransformPlugin } from './plugins/unctx' import type { TreeShakeComposablesPluginOptions } from './plugins/tree-shake' import { TreeShakeComposablesPlugin } from './plugins/tree-shake' @@ -110,12 +111,15 @@ async function initNuxt (nuxt: Nuxt) { })) } - nuxt.hook('modules:done', () => { + nuxt.hook('modules:done', async () => { // Add unctx transform const options = { sourcemap: !!nuxt.options.sourcemap.server || !!nuxt.options.sourcemap.client, - transformerOptions: nuxt.options.optimization.asyncTransforms - } + transformerOptions: { + ...nuxt.options.optimization.asyncTransforms, + helperModule: await tryResolveModule('unctx', nuxt.options.modulesDir) ?? 'unctx' + } + } satisfies UnctxTransformPluginOptions addVitePlugin(() => UnctxTransformPlugin.vite(options)) addWebpackPlugin(() => UnctxTransformPlugin.webpack(options)) diff --git a/packages/nuxt/src/core/plugins/unctx.ts b/packages/nuxt/src/core/plugins/unctx.ts index 19ce781e94..1e458eda49 100644 --- a/packages/nuxt/src/core/plugins/unctx.ts +++ b/packages/nuxt/src/core/plugins/unctx.ts @@ -6,7 +6,7 @@ import { isJS, isVue } from '../utils' const TRANSFORM_MARKER = '/* _processed_nuxt_unctx_transform */\n' -interface UnctxTransformPluginOptions { +export interface UnctxTransformPluginOptions { sourcemap?: boolean transformerOptions: TransformerOptions }