Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf(schema): avoid duplicate get operations #24734

Merged
merged 9 commits into from Dec 15, 2023
58 changes: 36 additions & 22 deletions packages/schema/src/config/common.ts
Expand Up @@ -50,7 +50,10 @@ export default defineUntypedSchema({
* It is normally not needed to configure this option.
*/
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)
}
},

/**
Expand Down Expand Up @@ -305,15 +308,21 @@ export default defineUntypedSchema({
* @type {Record<string, string>}
*/
alias: {
$resolve: async (val, get) => ({
'~': await get('srcDir'),
'@': await get('srcDir'),
'~~': await get('rootDir'),
'@@': await get('rootDir'),
[await get('dir.assets')]: join(await get('srcDir'), await get('dir.assets')),
[await get('dir.public')]: join(await get('srcDir'), await get('dir.public')),
...val
})
$resolve: async (val, get) => {
const srcDir = await get('srcDir')
const rootDir = await get('rootDir')
const dirAssets = await get('dir.assets')
const dirPublic = await get('dir.public')
return {
'~': srcDir,
'@': srcDir,
'~~': rootDir,
'@@': rootDir,
[dirAssets]: join(srcDir, dirAssets),
[dirPublic]: join(srcDir, dirPublic),
...val
}
}
},

/**
Expand Down Expand Up @@ -342,15 +351,19 @@ export default defineUntypedSchema({
* inside the `ignore` array will be ignored in building.
*/
ignore: {
$resolve: async (val, get) => [
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
'**/*.d.{cts,mts,ts}', // ignore type declarations
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
relative(await get('rootDir'), await get('analyzeDir')),
relative(await get('rootDir'), await get('buildDir')),
await get('ignorePrefix') && `**/${await get('ignorePrefix')}*.*`
].concat(val).filter(Boolean)
$resolve: async (val, get) => {
const rootDir = await get('rootDir')
const ignorePrefix = await get('ignorePrefix')
GalacticHypernova marked this conversation as resolved.
Show resolved Hide resolved
return [
'**/*.stories.{js,cts,mts,ts,jsx,tsx}', // ignore storybook files
'**/*.{spec,test}.{js,cts,mts,ts,jsx,tsx}', // ignore tests
'**/*.d.{cts,mts,ts}', // ignore type declarations
'**/.{pnpm-store,vercel,netlify,output,git,cache,data}',
relative(rootDir, await get('analyzeDir')),
relative(rootDir, await get('buildDir')),
ignorePrefix && `**/${ignorePrefix}*.*`
].concat(val).filter(Boolean)
}
},

/**
Expand Down Expand Up @@ -444,13 +457,14 @@ export default defineUntypedSchema({
*/
runtimeConfig: {
$resolve: async (val: RuntimeConfig, get) => {
const app = await get('app')
provideFallbackValues(val)
return defu(val, {
public: {},
app: {
baseURL: (await get('app')).baseURL,
buildAssetsDir: (await get('app')).buildAssetsDir,
cdnURL: (await get('app')).cdnURL
baseURL: app.baseURL,
buildAssetsDir: app.buildAssetsDir,
cdnURL: app.cdnURL
}
})
}
Expand Down
17 changes: 10 additions & 7 deletions packages/schema/src/config/vite.ts
Expand Up @@ -20,13 +20,16 @@ export default defineUntypedSchema({
$resolve: async (val, get) => val ?? (await get('dev') ? 'development' : 'production')
},
define: {
$resolve: async (val, get) => ({
'process.dev': await get('dev'),
'import.meta.dev': await get('dev'),
'process.test': isTest,
'import.meta.test': isTest,
...val
})
$resolve: async (val, get) => {
const dev = await get('dev')
return {
'process.dev': dev,
'import.meta.dev': dev,
'process.test': isTest,
'import.meta.test': isTest,
...val
}
}
},
resolve: {
extensions: ['.mjs', '.js', '.ts', '.jsx', '.tsx', '.json', '.vue']
Expand Down