Skip to content

Commit

Permalink
chore: change merger path to relative, closes #915
Browse files Browse the repository at this point in the history
  • Loading branch information
ineshbose committed Dec 6, 2024
1 parent f47e093 commit 216f9a2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
8 changes: 5 additions & 3 deletions src/internal-context/load.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T extends Partial<TWConfig> | string | undefined>(configs: T | T[], nuxt = useNuxt()) =>
((Array.isArray(configs) ? configs : [configs])
.filter(Boolean)
Expand All @@ -38,7 +40,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux
return { config } as { config: NonNullable<T> }
}

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
Expand Down Expand Up @@ -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
}

Expand All @@ -178,7 +180,7 @@ const createInternalContext = async (moduleOptions: ModuleOptions, nuxt = useNux

return [
`// generated by the @nuxtjs/tailwindcss <https://github.com/nuxt-modules/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`,
Expand Down
5 changes: 3 additions & 2 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,15 @@ export default defineNuxtModule<ModuleOptions>({
}

const ctx = await createInternalContext(moduleOptions, nuxt)
const resolver = createResolver(import.meta.url)

if (moduleOptions.editorSupport) {
const editorSupportConfig = resolvers.resolveEditorSupportConfig(moduleOptions.editorSupport)

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 : {}),
})
Expand Down Expand Up @@ -88,7 +89,7 @@ export default defineNuxtModule<ModuleOptions>({
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
Expand Down

0 comments on commit 216f9a2

Please sign in to comment.