From d269cc18315bb21a674a26f55c7f18eb98ddba1d Mon Sep 17 00:00:00 2001 From: userquin Date: Thu, 19 Dec 2024 19:59:33 +0100 Subject: [PATCH] fix: replace `@tresjs/post-processing` with its subpackage exports --- src/module.ts | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/module.ts b/src/module.ts index 3ce00a1..67d71ed 100644 --- a/src/module.ts +++ b/src/module.ts @@ -50,15 +50,33 @@ export default defineNuxtModule({ }, ]) + 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[] = [] for (const mod of new Set([...options.modules, ...coreDeps])) { if (mod === '@tresjs/core' || mod === '@tresjs/nuxt') { continue @@ -79,15 +97,17 @@ export default defineNuxtModule({ }) } 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'], }) @@ -96,7 +116,7 @@ export default defineNuxtModule({ include: ['three'], }) - await Promise.all([ + promises.push( addComponent({ name: 'TresCanvas', filePath: resolver.resolve('./runtime/TresCanvas.client.vue'), @@ -105,7 +125,9 @@ export default defineNuxtModule({ name: 'TresCanvas', filePath: resolver.resolve('./runtime/TresCanvas.server.vue'), }), - ]) + ) + + await Promise.all(promises) if (options.devtools) { setupDevToolsUI(nuxt, resolver)