Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
refactor: rename limiter option to filter
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 22, 2022
1 parent 5225e2b commit 203cae6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions packages/kit/src/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export function normalizeTemplate (template: NuxtTemplate<any> | string): Resolv
/**
* Trigger rebuilding Nuxt templates
*
* You can pass a limiter within the options to selectively regenerate a subset of templates.
* You can pass a filter within the options to selectively regenerate a subset of templates.
*/
export function updateTemplates (options?: { limiter?: (template: ResolvedNuxtTemplate<any>) => boolean }) {
export function updateTemplates (options?: { filter?: (template: ResolvedNuxtTemplate<any>) => boolean }) {
return useNuxt().hooks.callHook('builder:generateApp', options)
}
6 changes: 3 additions & 3 deletions packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ export default defineNuxtModule<ComponentsOptions>({

nuxt.hook('vite:extendConfig', (config, { isClient }) => {
const mode = isClient ? 'client' : 'server'
;(config.resolve!.alias as any)['#components'] = resolve(nuxt.options.buildDir, `components.${mode}.mjs`)
; (config.resolve!.alias as any)['#components'] = resolve(nuxt.options.buildDir, `components.${mode}.mjs`)
})
nuxt.hook('webpack:config', (configs) => {
for (const config of configs) {
const mode = config.name === 'server' ? 'server' : 'client'
;(config.resolve!.alias as any)['#components'] = resolve(nuxt.options.buildDir, `components.${mode}.mjs`)
; (config.resolve!.alias as any)['#components'] = resolve(nuxt.options.buildDir, `components.${mode}.mjs`)
}
})

Expand Down Expand Up @@ -174,7 +174,7 @@ export default defineNuxtModule<ComponentsOptions>({
const fPath = resolve(nuxt.options.srcDir, path)
if (componentDirs.find(dir => fPath.startsWith(dir.path))) {
await updateTemplates({
limiter: template => [
filter: template => [
'components.plugin.mjs',
'components.d.ts',
'components.server.mjs',
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/core/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function createApp (nuxt: Nuxt, options: Partial<NuxtApp> = {}): NuxtApp
} as unknown as NuxtApp) as NuxtApp
}

export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { limiter?: (template: ResolvedNuxtTemplate<any>) => boolean } = {}) {
export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { filter?: (template: ResolvedNuxtTemplate<any>) => boolean } = {}) {
// Resolve app
await resolveApp(nuxt, app)

Expand All @@ -32,7 +32,7 @@ export async function generateApp (nuxt: Nuxt, app: NuxtApp, options: { limiter?
// Compile templates into vfs
const templateContext = { utils: templateUtils, nuxt, app }
await Promise.all((app.templates as Array<ReturnType<typeof normalizeTemplate>>)
.filter(template => !options.limiter || options.limiter(template))
.filter(template => !options.filter || options.filter(template))
.map(async (template) => {
const contents = await compileTemplate(template, templateContext)

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/imports/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export default defineNuxtModule<Partial<ImportsOptions>>({
const _resolved = resolve(nuxt.options.srcDir, path)
if (composablesDirs.find(dir => _resolved.startsWith(dir))) {
await updateTemplates({
limiter: template => templates.includes(template.filename)
filter: template => templates.includes(template.filename)
})
}
})
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/types/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export interface ImportPresetWithDeprecation extends ImportPreset {
}

export interface GenerateAppOptions {
limiter?: (template: ResolvedNuxtTemplate<any>) => boolean
filter?: (template: ResolvedNuxtTemplate<any>) => boolean
}

export interface NuxtHooks {
Expand Down

0 comments on commit 203cae6

Please sign in to comment.