perf(schema): use parallel promises (#24771)

Co-authored-by: Daniel Roe <daniel@roe.dev>
This commit is contained in:
Michael Brevard 2023-12-15 16:16:35 +02:00 committed by GitHub
parent ce18fdaf9f
commit 153d5ff273
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 25 deletions

View File

@ -110,8 +110,7 @@ export default defineUntypedSchema({
*/ */
analyze: { analyze: {
$resolve: async (val, get) => { $resolve: async (val, get) => {
const rootDir = await get('rootDir') const [rootDir, analyzeDir] = await Promise.all([get('rootDir'), get('analyzeDir')])
const analyzeDir = await get('analyzeDir')
return defu(typeof val === 'boolean' ? { enabled: val } : val, { return defu(typeof val === 'boolean' ? { enabled: val } : val, {
template: 'treemap', template: 'treemap',
projectRoot: rootDir, projectRoot: rootDir,

View File

@ -134,10 +134,13 @@ export default defineUntypedSchema({
*/ */
modulesDir: { modulesDir: {
$default: ['node_modules'], $default: ['node_modules'],
$resolve: async (val, get) => [ $resolve: async (val, get) => {
...await Promise.all(val.map(async (dir: string) => resolve(await get('rootDir'), dir))), const rootDir = await get('rootDir')
resolve(process.cwd(), 'node_modules') return [
] ...await Promise.all(val.map(async (dir: string) => resolve(rootDir, dir))),
resolve(process.cwd(), 'node_modules')
]
}
}, },
/** /**
@ -309,17 +312,14 @@ export default defineUntypedSchema({
*/ */
alias: { alias: {
$resolve: async (val, get) => { $resolve: async (val, get) => {
const srcDir = await get('srcDir') const [srcDir, rootDir, assetsDir, publicDir] = await Promise.all([get('srcDir'), get('rootDir'), get('dir.assets'), get('dir.public')])
const rootDir = await get('rootDir')
const dirAssets = await get('dir.assets')
const dirPublic = await get('dir.public')
return { return {
'~': srcDir, '~': srcDir,
'@': srcDir, '@': srcDir,
'~~': rootDir, '~~': rootDir,
'@@': rootDir, '@@': rootDir,
[dirAssets]: join(srcDir, dirAssets), [assetsDir]: join(srcDir, assetsDir),
[dirPublic]: join(srcDir, dirPublic), [publicDir]: join(srcDir, publicDir),
...val ...val
} }
} }
@ -352,15 +352,14 @@ export default defineUntypedSchema({
*/ */
ignore: { ignore: {
$resolve: async (val, get) => { $resolve: async (val, get) => {
const rootDir = await get('rootDir') const [rootDir, ignorePrefix, analyzeDir, buildDir] = await Promise.all([get('rootDir'), get('ignorePrefix'), get('analyzeDir'), get('buildDir')])
const ignorePrefix = await get('ignorePrefix')
return [ return [
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files '**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests '**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
'**/*.d.{cts,mts,ts}', // ignore type declarations '**/*.d.{cts,mts,ts}', // ignore type declarations
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}', '**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
relative(rootDir, await get('analyzeDir')), relative(rootDir, analyzeDir),
relative(rootDir, await get('buildDir')), relative(rootDir, buildDir),
ignorePrefix && `**/${ignorePrefix}*.*` ignorePrefix && `**/${ignorePrefix}*.*`
].concat(val).filter(Boolean) ].concat(val).filter(Boolean)
} }

View File

@ -39,7 +39,7 @@ export default defineUntypedSchema({
if (val) { if (val) {
consola.warn('Directly configuring the `vite.publicDir` option is not supported. Instead, set `dir.public`. You can read more in `https://nuxt.com/docs/api/nuxt-config#public`.') consola.warn('Directly configuring the `vite.publicDir` option is not supported. Instead, set `dir.public`. You can read more in `https://nuxt.com/docs/api/nuxt-config#public`.')
} }
return val ?? resolve((await get('srcDir')), (await get('dir')).public) return val ?? await Promise.all([get('srcDir'), get('dir')]).then(([srcDir, dir]) => resolve(srcDir, dir.public))
} }
}, },
vue: { vue: {
@ -92,14 +92,17 @@ export default defineUntypedSchema({
server: { server: {
fs: { fs: {
allow: { allow: {
$resolve: async (val, get) => [ $resolve: async (val, get) => {
await get('buildDir'), const [buildDir, srcDir, rootDir, workspaceDir, modulesDir] = await Promise.all([get('buildDir'), get('srcDir'), get('rootDir'), get('workspaceDir'), get('modulesDir')])
await get('srcDir'), return [
await get('rootDir'), buildDir,
await get('workspaceDir'), srcDir,
...(await get('modulesDir')), rootDir,
...val ?? [] workspaceDir,
] ...(modulesDir),
...val ?? []
]
}
} }
} }
} }