From 216f9a23490a4c7e16a1aff904ede651e4fde0c9 Mon Sep 17 00:00:00 2001 From: Inesh Bose Date: Fri, 6 Dec 2024 19:41:14 +0000 Subject: [PATCH] chore: change merger path to relative, closes #915 --- src/internal-context/load.ts | 8 +++++--- src/module.ts | 5 +++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/internal-context/load.ts b/src/internal-context/load.ts index e31daaba..66446425 100644 --- a/src/internal-context/load.ts +++ b/src/internal-context/load.ts @@ -20,6 +20,8 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux const { meta = { disableHMR: moduleOptions.disableHMR } } = twCtx.tryUse() ?? {} const trackObjChanges = createObjProxy(configUpdatedHook, meta) + const { buildDir } = nuxt.options + const resolveConfigs = | string | undefined>(configs: T | T[], nuxt = useNuxt()) => ((Array.isArray(configs) ? configs : [configs]) .filter(Boolean) @@ -38,7 +40,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux return { config } as { config: NonNullable } } - const configFile = await (config.startsWith(nuxt.options.buildDir) ? config : findPath(config, { extensions: ['.js', '.cjs', '.mjs', '.ts'] })) + const configFile = await (config.startsWith(buildDir) ? config : findPath(config, { extensions: ['.js', '.cjs', '.mjs', '.ts'] })) return configFile ? loadConfig({ configFile }).then(async (resolvedConfig) => { const { configFile: resolvedConfigFile = configFile } = resolvedConfig @@ -169,7 +171,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux const layerConfigs = resolvedConfigsCtx.use().map((c) => { if (c?.configFile) { - const configImport = `require(${JSON.stringify(/[/\\]node_modules[/\\]/.test(c.configFile) ? c.configFile : './' + relative(nuxt.options.buildDir, c.configFile))})` + const configImport = `require(${JSON.stringify(/[/\\]node_modules[/\\]/.test(c.configFile) ? c.configFile : './' + relative(buildDir, c.configFile))})` return configUpdatedHook[c.configFile] ? `(() => {const cfg=configMerger(undefined, ${configImport});${configUpdatedHook[c.configFile]};return cfg;})()` : configImport } @@ -178,7 +180,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux return [ `// generated by the @nuxtjs/tailwindcss module at ${(new Date()).toLocaleString()}`, - `const configMerger = require(${JSON.stringify(options.mergerPath)});\n`, + `const configMerger = require(${JSON.stringify(relative(buildDir, options.mergerPath))});\n`, 'const config = [', layerConfigs.join(',\n'), `].reduce((acc, curr) => configMerger(acc, curr), {});\n`, diff --git a/src/module.ts b/src/module.ts index d6fe962d..7aa3b3a0 100644 --- a/src/module.ts +++ b/src/module.ts @@ -47,6 +47,7 @@ export default defineNuxtModule({ } const ctx = await createInternalContext(moduleOptions, nuxt) + const resolver = createResolver(import.meta.url) if (moduleOptions.editorSupport) { const editorSupportConfig = resolvers.resolveEditorSupportConfig(moduleOptions.editorSupport) @@ -54,7 +55,7 @@ export default defineNuxtModule({ if ((editorSupportConfig.autocompleteUtil) && !isNuxtMajorVersion(2, nuxt)) { addImports({ name: 'autocompleteUtil', - from: createResolver(import.meta.url).resolve('./runtime/utils'), + from: resolver.resolve('./runtime/utils'), as: 'tw', ...(typeof editorSupportConfig.autocompleteUtil === 'object' ? editorSupportConfig.autocompleteUtil : {}), }) @@ -88,7 +89,7 @@ export default defineNuxtModule({ nuxt.hook('modules:done', async () => { const _config = await ctx.loadConfigs() - const twConfig = ctx.generateConfig({ mergerPath: createResolver(import.meta.url).resolve('./runtime/merger.js') }) + const twConfig = ctx.generateConfig({ mergerPath: resolver.resolve('./runtime/merger.js') }) ctx.registerHooks() nuxt2ViewerConfig = twConfig.dst || _config