Skip to content

Commit

Permalink
fix: replace @tresjs/post-processing with its subpackage exports
Browse files Browse the repository at this point in the history
  • Loading branch information
userquin committed Dec 19, 2024
1 parent f19abcb commit d269cc1
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,33 @@ export default defineNuxtModule<ModuleOptions>({
},
])

const pkg = await readPackageJSON(nuxt.options.rootDir)
const coreDeps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).filter(d => d.startsWith('@tresjs/'))

const mods = new Set([...options.modules, ...coreDeps])
// @tresjs/post-processing doesn't have default subpackage export,
// we need to import submodules manually here.
// The resolvePath call will not be able to resolve the entry file and will fail
// when reading the content to get the exports.
if (mods.has('@tresjs/post-processing')) {
mods.delete('@tresjs/post-processing')
mods.add('@tresjs/post-processing/three')
mods.add('@tresjs/post-processing/pmndrs')
}

nuxt.hook('prepare:types', ({ references }) => {
references.push({ types: '@tresjs/core' })
if (mods.has('@tresjs/post-processing/three')) {
references.push({ types: '@tresjs/post-processing/three' })
}
if (mods.has('@tresjs/post-processing/pmndrs')) {
references.push({ types: '@tresjs/post-processing/pmndrs' })
}
})

nuxt.options.vue.compilerOptions.isCustomElement = templateCompilerOptions.template.compilerOptions.isCustomElement

const pkg = await readPackageJSON(nuxt.options.rootDir)
const coreDeps = Object.keys({ ...pkg.dependencies, ...pkg.devDependencies }).filter(d => d.startsWith('@tresjs/'))

const promises: Promise<void>[] = []
for (const mod of new Set([...options.modules, ...coreDeps])) {
if (mod === '@tresjs/core' || mod === '@tresjs/nuxt') {
continue
Expand All @@ -79,15 +97,17 @@ export default defineNuxtModule<ModuleOptions>({
})
}
else {
addComponent({
promises.push(addComponent({
name,
filePath: mod,
export: name,
})
}))
}
}
}

await Promise.all(promises)

nuxt.options.vite.resolve = defu(nuxt.options.vite.resolve, {
dedupe: ['three'],
})
Expand All @@ -96,7 +116,7 @@ export default defineNuxtModule<ModuleOptions>({
include: ['three'],
})

await Promise.all([
promises.push(
addComponent({
name: 'TresCanvas',
filePath: resolver.resolve('./runtime/TresCanvas.client.vue'),
Expand All @@ -105,7 +125,9 @@ export default defineNuxtModule<ModuleOptions>({
name: 'TresCanvas',
filePath: resolver.resolve('./runtime/TresCanvas.server.vue'),
}),
])
)

await Promise.all(promises)

if (options.devtools) {
setupDevToolsUI(nuxt, resolver)
Expand Down

0 comments on commit d269cc1

Please sign in to comment.