@@ -34,10 +34,25 @@ const PNPM_NODE_MODULES_RE = /\.pnpm\/.+\/node_modules\/(.+)$/
3434export async function initNitro ( nuxt : Nuxt & { _nitro ?: Nitro } ) {
3535 // Resolve config
3636 const layerDirs = getLayerDirectories ( nuxt )
37- const excludePaths = layerDirs . flatMap ( dirs => [
38- dirs . root . match ( NODE_MODULES_RE ) ?. [ 1 ] ?. replace ( / \/ $ / , '' ) ,
39- dirs . root . match ( PNPM_NODE_MODULES_RE ) ?. [ 1 ] ?. replace ( / \/ $ / , '' ) ,
40- ] . filter ( ( dir ) : dir is string => Boolean ( dir ) ) . map ( dir => escapeRE ( dir ) ) )
37+ const excludePaths : string [ ] = [ ]
38+ for ( const dirs of layerDirs ) {
39+ const paths = [
40+ dirs . root . match ( NODE_MODULES_RE ) ?. [ 1 ] ?. replace ( / \/ $ / , '' ) ,
41+ dirs . root . match ( PNPM_NODE_MODULES_RE ) ?. [ 1 ] ?. replace ( / \/ $ / , '' ) ,
42+ ]
43+ for ( const dir of paths ) {
44+ if ( dir ) {
45+ excludePaths . push ( escapeRE ( dir ) )
46+ }
47+ }
48+ }
49+
50+ const layerPublicAssetsDirs : Array < { dir : string } > = [ ]
51+ for ( const dirs of layerDirs ) {
52+ if ( existsSync ( dirs . public ) ) {
53+ layerPublicAssetsDirs . push ( { dir : dirs . public } )
54+ }
55+ }
4156
4257 const excludePattern = excludePaths . length
4358 ? [ new RegExp ( `node_modules\\/(?!${ excludePaths . join ( '|' ) } )` ) ]
@@ -155,7 +170,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
155170 join ( moduleDir , 'dist/runtime/server' ) ,
156171 ]
157172 } ) ,
158- ...getLayerDirectories ( nuxt ) . map ( dirs => relativeWithDot ( nuxt . options . buildDir , join ( dirs . shared , '**/*.d.ts' ) ) ) ,
173+ ...layerDirs . map ( dirs => relativeWithDot ( nuxt . options . buildDir , join ( dirs . shared , '**/*.d.ts' ) ) ) ,
159174 ] ,
160175 exclude : [
161176 ...nuxt . options . modulesDir . map ( m => relativeWithDot ( nuxt . options . buildDir , m ) ) ,
@@ -172,9 +187,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
172187 maxAge : 31536000 /* 1 year */ ,
173188 baseURL : nuxt . options . app . buildAssetsDir ,
174189 } ,
175- ...getLayerDirectories ( nuxt )
176- . filter ( dirs => existsSync ( dirs . public ) )
177- . map ( dirs => ( { dir : dirs . public } ) ) ,
190+ ...layerPublicAssetsDirs ,
178191 ] ,
179192 prerender : {
180193 ignoreUnprefixedPublicAssets : true ,
@@ -198,7 +211,7 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
198211 'nuxt-nightly/dist' ,
199212 distDir ,
200213 // Ensure app config files have auto-imports injected even if they are pure .js files
201- ...getLayerDirectories ( nuxt ) . map ( dirs => join ( dirs . app , 'app.config' ) ) ,
214+ ...layerDirs . map ( dirs => join ( dirs . app , 'app.config' ) ) ,
202215 ] ,
203216 traceInclude : [
204217 // force include files used in generated code from the runtime-compiler
0 commit comments