Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into fix/21721-spa-loading
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 9, 2024
2 parents 2f778d2 + 8c956db commit fcf076d
Show file tree
Hide file tree
Showing 34 changed files with 272 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ jobs:
- name: Build
run: pnpm build

- name: Check types
run: pnpm test:attw

- name: Cache dist
uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
with:
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"test:runtime": "vitest -c vitest.nuxt.config.ts",
"test:types": "pnpm --filter './test/fixtures/**' test:types",
"test:unit": "vitest run packages/",
"test:attw": "pnpm --filter './packages/**' test:attw",
"typecheck": "tsc --noEmit",
"typecheck:docs": "DOCS_TYPECHECK=true pnpm nuxi prepare && nuxt-content-twoslash verify --content-dir docs --languages html"
},
Expand Down Expand Up @@ -67,6 +68,7 @@
"vue": "3.5.13"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.17.1",
"@nuxt/eslint-config": "0.7.2",
"@nuxt/kit": "workspace:*",
"@nuxt/rspack-builder": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/kit/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
}
3 changes: 2 additions & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
"dist"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"dependencies": {
"@nuxt/schema": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/nuxt/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm", "false-esm"]
}
3 changes: 2 additions & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@
"schema.*"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"dependencies": {
"@nuxt/devalue": "^2.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/components/nuxt-route-announcer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { defineComponent, h } from 'vue'
import type { Politeness } from '#app/composables/route-announcer'
import type { Politeness } from 'nuxt/app'
import { useRouteAnnouncer } from '#app/composables/route-announcer'

export default defineComponent({
Expand Down
1 change: 1 addition & 0 deletions packages/nuxt/src/app/composables/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ export { useRequestURL } from './url'
export { usePreviewMode } from './preview'
export { useId } from './id'
export { useRouteAnnouncer } from './route-announcer'
export type { Politeness } from './route-announcer'
export { useRuntimeHook } from './runtime-hook'
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { applyPlugin, applyPlugins, callWithNuxt, createNuxtApp, defineAppConfig
export type { CreateOptions, NuxtApp, NuxtPayload, NuxtPluginIndicator, NuxtSSRContext, ObjectPlugin, Plugin, PluginEnvContext, PluginMeta, ResolvedPluginMeta, RuntimeNuxtHooks } from './nuxt'

export { defineNuxtComponent, useAsyncData, useLazyAsyncData, useNuxtData, refreshNuxtData, clearNuxtData, useHydration, callOnce, useState, clearNuxtState, clearError, createError, isNuxtError, showError, useError, useFetch, useLazyFetch, useCookie, refreshCookie, onPrehydrate, prerenderRoutes, useRequestHeaders, useRequestEvent, useRequestFetch, setResponseStatus, useResponseHeader, onNuxtReady, abortNavigation, addRouteMiddleware, defineNuxtRouteMiddleware, onBeforeRouteLeave, onBeforeRouteUpdate, setPageLayout, navigateTo, useRoute, useRouter, preloadComponents, prefetchComponents, preloadRouteComponents, isPrerendered, loadPayload, preloadPayload, definePayloadReducer, definePayloadReviver, getAppManifest, getRouteRules, reloadNuxtApp, useRequestURL, usePreviewMode, useId, useRouteAnnouncer, useHead, useSeoMeta, useServerSeoMeta, useRuntimeHook } from './composables/index'
export type { AddRouteMiddlewareOptions, AsyncData, AsyncDataOptions, AsyncDataRequestStatus, CookieOptions, CookieRef, FetchResult, NuxtAppManifest, NuxtAppManifestMeta, NuxtError, ReloadNuxtAppOptions, RouteMiddleware, UseFetchOptions } from './composables/index'
export type { AddRouteMiddlewareOptions, AsyncData, AsyncDataOptions, AsyncDataRequestStatus, CookieOptions, CookieRef, FetchResult, NuxtAppManifest, NuxtAppManifestMeta, NuxtError, Politeness, ReloadNuxtAppOptions, RouteMiddleware, UseFetchOptions } from './composables/index'

export { defineNuxtLink } from './components/index'
export type { NuxtLinkOptions, NuxtLinkProps } from './components/index'
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import type { RenderResponse } from 'nitro/types'
import type { LogObject } from 'consola'
import type { MergeHead, VueHeadClient } from '@unhead/vue'

import type { NuxtAppLiterals } from 'nuxt/app'

import type { NuxtIslandContext } from '../app/types'
import type { RouteMiddleware } from '../app/composables/router'
import type { NuxtError } from '../app/composables/error'
Expand All @@ -22,8 +24,6 @@ import type { RouteAnnouncer } from '../app/composables/route-announcer'
// @ts-expect-error virtual file
import { appId, chunkErrorEvent, multiApp } from '#build/nuxt.config.mjs'

import type { NuxtAppLiterals } from '#app'

function getNuxtAppCtx (id = appId || 'nuxt-app') {
return getContext<NuxtApp>(id, {
asyncContext: !!__NUXT_ASYNC_CONTEXT__ && import.meta.server,
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/components/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export type getComponentsT = (mode?: 'client' | 'server' | 'all') => Component[]

export default defineNuxtModule<ComponentsOptions>({
meta: {
name: 'components',
name: 'nuxt:components',
configKey: 'components',
},
defaults: {
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 @@ -4,12 +4,12 @@ import { defu } from 'defu'
import { findPath, logger, normalizePlugin, normalizeTemplate, resolveAlias, resolveFiles, resolvePath } from '@nuxt/kit'
import type { Nuxt, NuxtApp, NuxtPlugin, NuxtTemplate, ResolvedNuxtTemplate } from 'nuxt/schema'

import type { PluginMeta } from 'nuxt/app'

import * as defaultTemplates from './templates'
import { getNameFromPath, hasSuffix, uniqueBy } from './utils'
import { extractMetadata, orderMap } from './plugins/plugin-metadata'

import type { PluginMeta } from '#app'

export function createApp (nuxt: Nuxt, options: Partial<NuxtApp> = {}): NuxtApp {
return defu(options, {
dir: nuxt.options.srcDir,
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/src/core/plugins/plugin-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@ import { createUnplugin } from 'unplugin'
import MagicString from 'magic-string'
import { normalize } from 'pathe'
import { logger } from '@nuxt/kit'
import type { ObjectPlugin, PluginMeta } from 'nuxt/app'

import { parseAndWalk, withLocations } from '../../core/utils/parse'

import type { ObjectPlugin, PluginMeta } from '#app'

const internalOrderMap = {
// -50: pre-all (nuxt)
'nuxt-pre-all': -50,
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/runtime/nitro/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { NitroErrorHandler } from 'nitro/types'
import type { H3Error, H3Event } from 'h3'
import { getRequestHeader, getRequestHeaders, send, setResponseHeader, setResponseStatus } from 'h3'
import { useNitroApp, useRuntimeConfig } from 'nitro/runtime'
import type { NuxtPayload } from '#app'
import type { NuxtPayload } from 'nuxt/app'

export default <NitroErrorHandler> async function errorhandler (error: H3Error, event) {
// Parse and normalize error
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ import type { Link, Script, Style } from '@unhead/vue'
import { createServerHead, resolveUnrefHeadInput } from '@unhead/vue'

import { defineRenderHandler, getRouteRules, useNitroApp, useRuntimeConfig, useStorage } from 'nitro/runtime'
import type { NuxtPayload, NuxtSSRContext } from 'nuxt/app'

// @ts-expect-error virtual file
import unheadPlugins from '#internal/unhead-plugins.mjs'
// @ts-expect-error virtual file
import { renderSSRHeadOptions } from '#internal/unhead.config.mjs'

import type { NuxtPayload, NuxtSSRContext } from '#app'
// @ts-expect-error virtual file
import { appHead, appId, appRootAttrs, appRootTag, appSpaLoaderAttrs, appSpaLoaderTag, appTeleportAttrs, appTeleportTag, componentIslands, appManifest as isAppManifestEnabled, multiApp, spaLoadingTemplateOutside } from '#internal/nuxt.config.mjs'
// @ts-expect-error virtual file
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/core/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { createJiti } from 'jiti'

export default defineNuxtModule({
meta: {
name: 'nuxt-config-schema',
name: 'nuxt:nuxt-config-schema',
},
async setup (_, nuxt) {
const resolver = createResolver(import.meta.url)
Expand Down
3 changes: 1 addition & 2 deletions packages/nuxt/src/core/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ export { }
},
}

const adHocModules = ['router', 'pages', 'imports', 'meta', 'components', 'nuxt-config-schema']
const IMPORT_NAME_RE = /\.\w+$/
const GIT_RE = /^git\+/
export const schemaTemplate: NuxtTemplate = {
Expand All @@ -187,7 +186,7 @@ export const schemaTemplate: NuxtTemplate = {
const getImportName = (name: string) => (name[0] === '.' ? './' + join(relativeRoot, name) : name).replace(IMPORT_NAME_RE, '')

const modules = nuxt.options._installedModules
.filter(m => m.meta && m.meta.configKey && m.meta.name && !adHocModules.includes(m.meta.name))
.filter(m => m.meta && m.meta.configKey && m.meta.name && !m.meta.name.startsWith('nuxt:') && m.meta.name !== 'nuxt-config-schema')
.map(m => [genString(m.meta.configKey), getImportName(m.entryPath || m.meta.name), m] as const)

const privateRuntimeConfig = Object.create(null)
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/head/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const components = ['NoScript', 'Link', 'Base', 'Title', 'Meta', 'Style', 'Head'

export default defineNuxtModule<NuxtOptions['unhead']>({
meta: {
name: 'meta',
name: 'nuxt:meta',
configKey: 'unhead',
},
async setup (options, nuxt) {
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 @@ -13,7 +13,7 @@ import { defaultPresets } from './presets'

export default defineNuxtModule<Partial<ImportsOptions>>({
meta: {
name: 'imports',
name: 'nuxt:imports',
configKey: 'imports',
},
defaults: nuxt => ({
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt/src/pages/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ const OPTIONAL_PARAM_RE = /^\/?:.*(?:\?|\(\.\*\)\*)$/

export default defineNuxtModule({
meta: {
name: 'pages',
name: 'nuxt:pages',
configKey: 'pages',
},
async setup (_options, nuxt) {
const useExperimentalTypedPages = nuxt.options.experimental.typedPages
Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/src/pages/runtime/composables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { getCurrentInstance } from 'vue'
import type { RouteLocationNormalized, RouteLocationNormalizedLoaded, RouteRecordRaw, RouteRecordRedirectOption } from 'vue-router'
import { useRoute } from 'vue-router'
import type { NitroRouteConfig } from 'nitro/types'
import type { NuxtError } from 'nuxt/app'
import { useNuxtApp } from '#app/nuxt'
import type { NuxtError } from '#app'

export interface PageMeta {
[key: string]: unknown
Expand Down
3 changes: 2 additions & 1 deletion packages/nuxt/src/pages/runtime/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { START_LOCATION, createMemoryHistory, createRouter, createWebHashHistory
import { createError } from 'h3'
import { isEqual, withoutBase } from 'ufo'

import type { Plugin, RouteMiddleware } from 'nuxt/app'
import type { PageMeta } from '../composables'

import { toArray } from '../utils'
import type { Plugin, RouteMiddleware } from '#app'

import { getRouteRules } from '#app/composables/manifest'
import { defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
import { clearError, showError, useError } from '#app/composables/error'
Expand Down
3 changes: 3 additions & 0 deletions packages/rspack/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
}
3 changes: 2 additions & 1 deletion packages/rspack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"builder.mjs"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"dependencies": {
"@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
Expand Down
5 changes: 5 additions & 0 deletions packages/schema/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"ignoreRules": [
"cjs-resolves-to-esm"
]
}
2 changes: 1 addition & 1 deletion packages/schema/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default defineBuildConfig({
],
externals: [
// Type imports
'#app/components/nuxt-link',
'nuxt/app',
'cssnano',
'autoprefixer',
'ofetch',
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/builder-env.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './dist/env'
export * from './dist/builder-env'
4 changes: 3 additions & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@
"files": [
"dist",
"schema",
"builder-env.d.ts",
"env.d.ts"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"devDependencies": {
"@types/file-loader": "5.0.4",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/src/config/experimental.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export default defineUntypedSchema({
* `app/` directory.
*/
defaults: {
/** @type {typeof import('#app/components/nuxt-link')['NuxtLinkOptions']} */
/** @type {typeof import('nuxt/app')['NuxtLinkOptions']} */
nuxtLink: {
componentName: 'NuxtLink',
prefetch: true,
Expand Down
3 changes: 3 additions & 0 deletions packages/vite/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
}
3 changes: 2 additions & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
"dist"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"devDependencies": {
"@nuxt/schema": "workspace:*",
Expand Down
3 changes: 3 additions & 0 deletions packages/webpack/.attw.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"ignoreRules": ["cjs-resolves-to-esm"]
}
3 changes: 2 additions & 1 deletion packages/webpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"builder.mjs"
],
"scripts": {
"prepack": "unbuild"
"prepack": "unbuild",
"test:attw": "attw --pack"
},
"dependencies": {
"@nuxt/friendly-errors-webpack-plugin": "^2.6.0",
Expand Down
Loading

0 comments on commit fcf076d

Please sign in to comment.