mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-01 18:07:22 +00:00
perf: use fixed-length array for known result sizes
This commit is contained in:
parent
49242b2500
commit
a7dcc6a48c
@ -251,14 +251,14 @@ function resolvePaths<Item extends Record<string, any>> (items: Item[], key: { [
|
|||||||
const IS_TSX = /\.[jt]sx$/
|
const IS_TSX = /\.[jt]sx$/
|
||||||
|
|
||||||
export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) {
|
export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) {
|
||||||
const _plugins: Array<NuxtPlugin & Omit<PluginMeta, 'enforce'>> = []
|
const _plugins: Array<NuxtPlugin & Omit<PluginMeta, 'enforce'>> = new Array(plugins.length)
|
||||||
for (const plugin of plugins) {
|
for (let i = 0; i < plugins.length; i++) {
|
||||||
try {
|
try {
|
||||||
const code = plugin.src in nuxt.vfs ? nuxt.vfs[plugin.src]! : await fsp.readFile(plugin.src!, 'utf-8')
|
const code = plugin.src in nuxt.vfs ? nuxt.vfs[plugin.src]! : await fsp.readFile(plugin.src!, 'utf-8')
|
||||||
_plugins.push({
|
_plugins[i] = {
|
||||||
...await extractMetadata(code, IS_TSX.test(plugin.src) ? 'tsx' : 'ts'),
|
...await extractMetadata(code, IS_TSX.test(plugin.src) ? 'tsx' : 'ts'),
|
||||||
...plugin,
|
...plugin,
|
||||||
})
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const relativePluginSrc = relative(nuxt.options.rootDir, plugin.src)
|
const relativePluginSrc = relative(nuxt.options.rootDir, plugin.src)
|
||||||
if ((e as Error).message === 'Invalid plugin metadata') {
|
if ((e as Error).message === 'Invalid plugin metadata') {
|
||||||
@ -266,7 +266,7 @@ export async function annotatePlugins (nuxt: Nuxt, plugins: NuxtPlugin[]) {
|
|||||||
} else {
|
} else {
|
||||||
logger.warn(`Failed to parse static properties from plugin \`${relativePluginSrc}\`.`, e)
|
logger.warn(`Failed to parse static properties from plugin \`${relativePluginSrc}\`.`, e)
|
||||||
}
|
}
|
||||||
_plugins.push(plugin)
|
_plugins[i] = plugins[i]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user