perf(schema): avoid duplicate get operations (#24734)

This commit is contained in:
Michael Brevard 2023-12-15 11:38:19 +02:00 committed by GitHub
parent 0c04dc094a
commit 24bedc5e56
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 29 deletions

View File

@ -50,7 +50,10 @@ export default defineUntypedSchema({
* It is normally not needed to configure this option. * It is normally not needed to configure this option.
*/ */
workspaceDir: { workspaceDir: {
$resolve: async (val, get) => val ? resolve(await get('rootDir'), val) : await findWorkspaceDir(await get('rootDir')).catch(() => get('rootDir')) $resolve: async (val, get) => {
const rootDir = await get('rootDir')
return val ? resolve(rootDir, val) : await findWorkspaceDir(rootDir).catch(() => rootDir)
}
}, },
/** /**
@ -305,15 +308,21 @@ export default defineUntypedSchema({
* @type {Record<string, string>} * @type {Record<string, string>}
*/ */
alias: { alias: {
$resolve: async (val, get) => ({ $resolve: async (val, get) => {
'~': await get('srcDir'), const srcDir = await get('srcDir')
'@': await get('srcDir'), const rootDir = await get('rootDir')
'~~': await get('rootDir'), const dirAssets = await get('dir.assets')
'@@': await get('rootDir'), const dirPublic = await get('dir.public')
[await get('dir.assets')]: join(await get('srcDir'), await get('dir.assets')), return {
[await get('dir.public')]: join(await get('srcDir'), await get('dir.public')), '~': srcDir,
'@': srcDir,
'~~': rootDir,
'@@': rootDir,
[dirAssets]: join(srcDir, dirAssets),
[dirPublic]: join(srcDir, dirPublic),
...val ...val
}) }
}
}, },
/** /**
@ -342,15 +351,19 @@ export default defineUntypedSchema({
* inside the `ignore` array will be ignored in building. * inside the `ignore` array will be ignored in building.
*/ */
ignore: { ignore: {
$resolve: async (val, get) => [ $resolve: async (val, get) => {
const rootDir = await get('rootDir')
const ignorePrefix = await get('ignorePrefix')
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(await get('rootDir'), await get('analyzeDir')), relative(rootDir, await get('analyzeDir')),
relative(await get('rootDir'), await get('buildDir')), relative(rootDir, await get('buildDir')),
await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*` ignorePrefix && `**/${ignorePrefix}*.*`
].concat(val).filter(Boolean) ].concat(val).filter(Boolean)
}
}, },
/** /**
@ -444,13 +457,14 @@ export default defineUntypedSchema({
*/ */
runtimeConfig: { runtimeConfig: {
$resolve: async (val: RuntimeConfig, get) => { $resolve: async (val: RuntimeConfig, get) => {
const app = await get('app')
provideFallbackValues(val) provideFallbackValues(val)
return defu(val, { return defu(val, {
public: {}, public: {},
app: { app: {
baseURL: (await get('app')).baseURL, baseURL: app.baseURL,
buildAssetsDir: (await get('app')).buildAssetsDir, buildAssetsDir: app.buildAssetsDir,
cdnURL: (await get('app')).cdnURL cdnURL: app.cdnURL
} }
}) })
} }

View File

@ -20,13 +20,16 @@ export default defineUntypedSchema({
$resolve: async (val, get) => val ?? (await get('dev') ? 'development' : 'production') $resolve: async (val, get) => val ?? (await get('dev') ? 'development' : 'production')
}, },
define: { define: {
$resolve: async (val, get) => ({ $resolve: async (val, get) => {
'process.dev': await get('dev'), const dev = await get('dev')
'import.meta.dev': await get('dev'), return {
'process.dev': dev,
'import.meta.dev': dev,
'process.test': isTest, 'process.test': isTest,
'import.meta.test': isTest, 'import.meta.test': isTest,
...val ...val
}) }
}
}, },
resolve: { resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue'] extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']