mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-12 03:38:07 +00:00
perf: unify shared patterns
This commit is contained in:
parent
f49c0497ad
commit
dc4d032246
@ -114,7 +114,7 @@ export interface NavigateToOptions {
|
|||||||
open?: OpenOptions
|
open?: OpenOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
const QUOTE_RE = /"/g
|
const URL_QUOTE_RE = /"/g
|
||||||
/** @since 3.0.0 */
|
/** @since 3.0.0 */
|
||||||
export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: NavigateToOptions): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw => {
|
export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: NavigateToOptions): Promise<void | NavigationFailure | false> | false | void | RouteLocationRaw => {
|
||||||
if (!to) {
|
if (!to) {
|
||||||
@ -167,7 +167,7 @@ export const navigateTo = (to: RouteLocationRaw | undefined | null, options?: Na
|
|||||||
const redirect = async function (response: any) {
|
const redirect = async function (response: any) {
|
||||||
// TODO: consider deprecating in favour of `app:rendered` and removing
|
// TODO: consider deprecating in favour of `app:rendered` and removing
|
||||||
await nuxtApp.callHook('app:redirected')
|
await nuxtApp.callHook('app:redirected')
|
||||||
const encodedLoc = location.replace(QUOTE_RE, '%22')
|
const encodedLoc = location.replace(URL_QUOTE_RE, '%22')
|
||||||
const encodedHeader = encodeURL(location, isExternalHost)
|
const encodedHeader = encodeURL(location, isExternalHost)
|
||||||
|
|
||||||
nuxtApp.ssrContext!._renderResponse = {
|
nuxtApp.ssrContext!._renderResponse = {
|
||||||
|
@ -6,7 +6,7 @@ import { relative } from 'pathe'
|
|||||||
import type { Component, ComponentsOptions } from 'nuxt/schema'
|
import type { Component, ComponentsOptions } from 'nuxt/schema'
|
||||||
|
|
||||||
import { logger, tryUseNuxt } from '@nuxt/kit'
|
import { logger, tryUseNuxt } from '@nuxt/kit'
|
||||||
import { isVue } from '../../core/utils'
|
import { isVue, QUOTE_RE } from '../../core/utils'
|
||||||
|
|
||||||
interface LoaderOptions {
|
interface LoaderOptions {
|
||||||
getComponents (): Component[]
|
getComponents (): Component[]
|
||||||
@ -112,7 +112,6 @@ export const LoaderPlugin = (options: LoaderOptions) => createUnplugin(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const QUOTE_RE = /["']/g
|
|
||||||
function findComponent (components: Component[], name: string, mode: LoaderOptions['mode']) {
|
function findComponent (components: Component[], name: string, mode: LoaderOptions['mode']) {
|
||||||
const id = pascalCase(name).replace(QUOTE_RE, '')
|
const id = pascalCase(name).replace(QUOTE_RE, '')
|
||||||
// Prefer exact match
|
// Prefer exact match
|
||||||
|
@ -6,13 +6,12 @@ import { isIgnored, logger, useNuxt } from '@nuxt/kit'
|
|||||||
import { withTrailingSlash } from 'ufo'
|
import { withTrailingSlash } from 'ufo'
|
||||||
import type { Component, ComponentsDir } from 'nuxt/schema'
|
import type { Component, ComponentsDir } from 'nuxt/schema'
|
||||||
|
|
||||||
import { resolveComponentNameSegments } from '../core/utils'
|
import { QUOTE_RE, resolveComponentNameSegments } from '../core/utils'
|
||||||
|
|
||||||
const ISLAND_RE = /\.island(?:\.global)?$/
|
const ISLAND_RE = /\.island(?:\.global)?$/
|
||||||
const GLOBAL_RE = /\.global(?:\.island)?$/
|
const GLOBAL_RE = /\.global(?:\.island)?$/
|
||||||
const COMPONENT_MODE_RE = /(?<=\.)(client|server)(\.global|\.island)*$/
|
const COMPONENT_MODE_RE = /(?<=\.)(client|server)(\.global|\.island)*$/
|
||||||
const MODE_REPLACEMENT_RE = /(\.(client|server))?(\.global|\.island)*$/
|
const MODE_REPLACEMENT_RE = /(\.(client|server))?(\.global|\.island)*$/
|
||||||
const QUOTE_RE = /["']/g
|
|
||||||
/**
|
/**
|
||||||
* Scan the components inside different components folders
|
* Scan the components inside different components folders
|
||||||
* and return a unique list of components
|
* and return a unique list of components
|
||||||
|
@ -18,6 +18,7 @@ import { distDir } from '../dirs'
|
|||||||
import { toArray } from '../utils'
|
import { toArray } from '../utils'
|
||||||
import { template as defaultSpaLoadingTemplate } from '../../../ui-templates/dist/templates/spa-loading-icon'
|
import { template as defaultSpaLoadingTemplate } from '../../../ui-templates/dist/templates/spa-loading-icon'
|
||||||
import { nuxtImportProtections } from './plugins/import-protection'
|
import { nuxtImportProtections } from './plugins/import-protection'
|
||||||
|
import { EXTENSION_RE } from './utils'
|
||||||
|
|
||||||
const logLevelMapReverse = {
|
const logLevelMapReverse = {
|
||||||
silent: 0,
|
silent: 0,
|
||||||
@ -374,7 +375,6 @@ export async function initNitro (nuxt: Nuxt & { _nitro?: Nitro }) {
|
|||||||
|
|
||||||
// TODO: extract to shared utility?
|
// TODO: extract to shared utility?
|
||||||
const excludedAlias = [/^@vue\/.*$/, '#imports', 'vue-demi', /^#app/]
|
const excludedAlias = [/^@vue\/.*$/, '#imports', 'vue-demi', /^#app/]
|
||||||
const EXTENSION_RE = /\b\.\w+$/g
|
|
||||||
const basePath = nitroConfig.typescript!.tsConfig!.compilerOptions?.baseUrl ? resolve(nuxt.options.buildDir, nitroConfig.typescript!.tsConfig!.compilerOptions?.baseUrl) : nuxt.options.buildDir
|
const basePath = nitroConfig.typescript!.tsConfig!.compilerOptions?.baseUrl ? resolve(nuxt.options.buildDir, nitroConfig.typescript!.tsConfig!.compilerOptions?.baseUrl) : nuxt.options.buildDir
|
||||||
const aliases = nitroConfig.alias!
|
const aliases = nitroConfig.alias!
|
||||||
const tsConfig = nitroConfig.typescript!.tsConfig!
|
const tsConfig = nitroConfig.typescript!.tsConfig!
|
||||||
|
@ -11,6 +11,7 @@ import type { NuxtTemplate } from 'nuxt/schema'
|
|||||||
import type { Nitro } from 'nitro/types'
|
import type { Nitro } from 'nitro/types'
|
||||||
|
|
||||||
import { annotatePlugins, checkForCircularDependencies } from './app'
|
import { annotatePlugins, checkForCircularDependencies } from './app'
|
||||||
|
import { EXTENSION_RE } from './utils'
|
||||||
|
|
||||||
export const vueShim: NuxtTemplate = {
|
export const vueShim: NuxtTemplate = {
|
||||||
filename: 'types/vue-shim.d.ts',
|
filename: 'types/vue-shim.d.ts',
|
||||||
@ -378,12 +379,11 @@ export const clientConfigTemplate: NuxtTemplate = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const FILENAME_EXTENSION_RE = /\b\.\w+$/g
|
|
||||||
export const appConfigDeclarationTemplate: NuxtTemplate = {
|
export const appConfigDeclarationTemplate: NuxtTemplate = {
|
||||||
filename: 'types/app.config.d.ts',
|
filename: 'types/app.config.d.ts',
|
||||||
getContents ({ app, nuxt }) {
|
getContents ({ app, nuxt }) {
|
||||||
const typesDir = join(nuxt.options.buildDir, 'types')
|
const typesDir = join(nuxt.options.buildDir, 'types')
|
||||||
const configPaths = app.configs.map(path => relative(typesDir, path).replace(FILENAME_EXTENSION_RE, ''))
|
const configPaths = app.configs.map(path => relative(typesDir, path).replace(EXTENSION_RE, ''))
|
||||||
|
|
||||||
return `
|
return `
|
||||||
import type { CustomAppConfig } from 'nuxt/schema'
|
import type { CustomAppConfig } from 'nuxt/schema'
|
||||||
|
@ -14,3 +14,6 @@ export function uniqueBy<T, K extends keyof T> (arr: T[], key: K) {
|
|||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const QUOTE_RE = /["']/g
|
||||||
|
export const EXTENSION_RE = /\b\.\w+$/g
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { basename, dirname, extname, normalize } from 'pathe'
|
import { basename, dirname, extname, normalize } from 'pathe'
|
||||||
import { kebabCase, splitByCase } from 'scule'
|
import { kebabCase, splitByCase } from 'scule'
|
||||||
import { withTrailingSlash } from 'ufo'
|
import { withTrailingSlash } from 'ufo'
|
||||||
|
import { QUOTE_RE } from '.'
|
||||||
|
|
||||||
const QUOTE_RE = /["']/g
|
|
||||||
export function getNameFromPath (path: string, relativeTo?: string) {
|
export function getNameFromPath (path: string, relativeTo?: string) {
|
||||||
const relativePath = relativeTo
|
const relativePath = relativeTo
|
||||||
? normalize(path).replace(withTrailingSlash(normalize(relativeTo)), '')
|
? normalize(path).replace(withTrailingSlash(normalize(relativeTo)), '')
|
||||||
|
@ -177,8 +177,9 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions) => createUnplugin
|
|||||||
// https://github.com/vuejs/vue-loader/pull/1911
|
// https://github.com/vuejs/vue-loader/pull/1911
|
||||||
// https://github.com/vitejs/vite/issues/8473
|
// https://github.com/vitejs/vite/issues/8473
|
||||||
const QUERY_START_RE = /^\?/
|
const QUERY_START_RE = /^\?/
|
||||||
|
const MACRO_RE = /¯o=true/
|
||||||
function rewriteQuery (id: string) {
|
function rewriteQuery (id: string) {
|
||||||
return id.replace(/\?.+$/, r => '?macro=true&' + r.replace(QUERY_START_RE, '').replace(/¯o=true/, ''))
|
return id.replace(/\?.+$/, r => '?macro=true&' + r.replace(QUERY_START_RE, '').replace(MACRO_RE, ''))
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseMacroQuery (id: string) {
|
function parseMacroQuery (id: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user