Skip to content

Commit

Permalink
Merge branch 'main' into feat/granular-client
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Dec 14, 2023
2 parents 4433eae + 0c04dc0 commit 4a7d11d
Show file tree
Hide file tree
Showing 47 changed files with 889 additions and 338 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
run: pnpm build

- name: Cache dist
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
with:
retention-days: 3
name: dist
Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
queries: +security-and-quality

- name: Restore dist cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
with:
name: dist
path: packages
Expand Down Expand Up @@ -125,7 +125,7 @@ jobs:
run: pnpm install

- name: Restore dist cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
with:
name: dist
path: packages
Expand Down Expand Up @@ -245,7 +245,7 @@ jobs:
run: pnpm playwright-core install chromium

- name: Restore dist cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
with:
name: dist
path: packages
Expand Down Expand Up @@ -293,7 +293,7 @@ jobs:
run: pnpm install

- name: Restore dist cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
with:
name: dist
path: packages
Expand Down Expand Up @@ -332,7 +332,7 @@ jobs:
run: pnpm install

- name: Restore dist cache
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
uses: actions/download-artifact@7a1cd3216ca9260cd8022db641d960b1db4d1be4 # v4.0.0
with:
name: dist
path: packages
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scorecards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
uses: actions/upload-artifact@c7d193f32edcb7bfad88892161225aeda64e9392 # v4.0.0
with:
name: SARIF file
path: results.sarif
Expand Down
1 change: 1 addition & 0 deletions docs/1.getting-started/4.styling.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Here are a few modules to help you get started:
- [Fontaine](https://github.com/nuxt-modules/fontaine): Font metric fallback
- [Pinceau](https://pinceau.dev): Adaptable styling framework
- [Nuxt UI](https://ui.nuxt.com): A UI Library for Modern Web Apps
- [Panda CSS](https://panda-css.com/docs/installation/nuxt): CSS-in-JS engine that generates atomic CSS at build time

Nuxt modules provide you with a good developer experience out of the box, but remember that if your favorite tool doesn't have a module, it doesn't mean that you can't use it with Nuxt! You can configure it yourself for your own project. Depending on the tool, you might need to use a [Nuxt plugin](/docs/guide/directory-structure/plugins) and/or [make your own module](/docs/guide/going-further/modules). Share them with the [community](/modules) if you do!

Expand Down
30 changes: 29 additions & 1 deletion docs/2.guide/2.directory-structure/1.middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Unlike [navigation guards](https://router.vuejs.org/guide/advanced/navigation-gu

Possible return values are:

* nothing - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
* nothing (a simple `return` or no return at all) - does not block navigation and will move to the next middleware function, if any, or complete the route navigation
* `return navigateTo('/')` - redirects to the given path and will set the redirect code to [`302` Found](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/302) if the redirect happens on the server side
* `return navigateTo('/', { redirectCode: 301 })` - redirects to the given path and will set the redirect code to [`301` Moved Permanently](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/301) if the redirect happens on the server side
* `return abortNavigation()` - stops the current navigation
Expand Down Expand Up @@ -171,3 +171,31 @@ definePageMeta({
Now, before navigation to that page can complete, the `auth` route middleware will be run.

:link-example{to="/docs/examples/routing/middleware"}

## Setting Middleware At Build Time

Instead of using `definePageMeta` on each page, you can add named route middleware within the `pages:extend` hook.

```ts [nuxt.config.ts]
import type { NuxtPage } from 'nuxt/schema'

export default defineNuxtConfig({
hooks: {
'pages:extend' (pages) {
function setMiddleware (pages: NuxtPage[]) {
for (const page of pages) {
if (/* some condition */ true) {
page.meta ||= {}
// Note that this will override any middleware set in `definePageMeta` in the page
page.meta.middleware = ['named']
}
if (page.children) {
setMiddleware(page.children)
}
}
}
setMiddleware(pages)
}
}
})
```
18 changes: 17 additions & 1 deletion docs/2.guide/2.directory-structure/1.plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ In case you're new to 'alphabetical' numbering, remember that filenames are sort

## Loading Strategy

### Parallel Plugins

By default, Nuxt loads plugins sequentially. You can define a plugin as `parallel` so Nuxt won't wait the end of the plugin's execution before loading the next plugin.

```ts [plugins/hello.ts]
```ts [plugins/my-plugin.ts]
export default defineNuxtPlugin({
name: 'my-plugin',
parallel: true,
Expand All @@ -113,6 +115,20 @@ export default defineNuxtPlugin({
})
```

### Plugins With Dependencies

If a plugin needs to await a parallel plugin before it runs, you can add the plugin's name to the `dependsOn` array.

```ts [plugins/depending-on-my-plugin.ts]
export default defineNuxtPlugin({
name: 'depends-on-my-plugin',
dependsOn: ['my-plugin']
async setup (nuxtApp) {
// this plugin will wait for the end of `my-plugin`'s execution before it runs
}
})
```

## Using Composables

You can use [composables](/docs/guide/directory-structure/composables) as well as [utils](/docs/guide/directory-structure/utils) within Nuxt plugins:
Expand Down
39 changes: 38 additions & 1 deletion docs/3.api/5.kit/11.nitro.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ Add a directory to be scanned for auto-imports by Nitro.
### Type

```ts
function function addServerImportsDir (dirs: string | string[], opts: { prepend?: boolean }): void
function addServerImportsDir (dirs: string | string[], opts: { prepend?: boolean }): void
```

### Parameters
Expand Down Expand Up @@ -395,3 +395,40 @@ export default defineNuxtModule({
}
})
```

## `addServerScanDir`

Add directories to be scanned by Nitro. It will check for subdirectories, which will be registered
just like the `~/server` folder is.

### Type

```ts
function addServerScanDir (dirs: string | string[], opts: { prepend?: boolean }): void
```

### Parameters

#### `dirs`

**Type**: `string | string[]`

**Required**: `true`

A directory or an array of directories to register to be scanned for by Nitro as server dirs.

### Examples

```ts
import { defineNuxtModule, addServerScanDir } from '@nuxt/kit'
export default defineNuxtModule({
meta: {
name: 'my-module',
configKey: 'myModule',
},
setup(options) {
const resolver = createResolver(import.meta.url)
addServerScanDir(resolver.resolve('./runtime/server'))
}
})
```
22 changes: 0 additions & 22 deletions docs/3.api/5.kit/2.programmatic.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ async function loadNuxt (loadOptions?: LoadNuxtOptions): Promise<Nuxt>
interface LoadNuxtOptions extends LoadNuxtConfigOptions {
dev?: boolean
ready?: boolean
rootDir?: string
config?: LoadNuxtConfigOptions['overrides']
}
```

Expand Down Expand Up @@ -53,26 +51,6 @@ Loading conditions for Nuxt. `loadNuxt` uses [`c12`](https://github.com/unjs/c12

If set to `true`, Nuxt will be ready to use after the `loadNuxt` call. If set to `false`, you will need to call `nuxt.ready()` to make sure Nuxt is ready to use.

- `rootDir` (optional)

**Type**: `string`

**Default**: `null`

**Deprecated**: Use `cwd` option instead.

The root directory of the Nuxt project.

- `config` (optional)

**Type**: `LoadNuxtConfigOptions['overrides']`

**Default**: `{}`

**Deprecated**: Use `overrides` option instead.

Overrides for the Nuxt configuration.

## `buildNuxt`

Build Nuxt programmatically. It will invoke the builder (currently [@nuxt/vite-builder](https://github.com/nuxt/nuxt/tree/main/packages/vite) or [@nuxt/webpack-builder](https://github.com/nuxt/nuxt/tree/main/packages/webpack)) to bundle the application.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"@nuxt/vite-builder": "workspace:*",
"@nuxt/webpack-builder": "workspace:*",
"nuxt": "workspace:*",
"vite": "5.0.8",
"vite": "5.0.9",
"vue": "3.3.11",
"magic-string": "^0.30.5"
},
Expand All @@ -54,7 +54,7 @@
"consola": "3.2.3",
"devalue": "4.3.2",
"eslint": "8.55.0",
"eslint-plugin-import": "2.29.0",
"eslint-plugin-import": "2.29.1",
"eslint-plugin-jsdoc": "46.9.1",
"eslint-plugin-no-only-tests": "3.1.0",
"eslint-plugin-unicorn": "49.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"lodash-es": "4.17.21",
"nitropack": "2.8.1",
"unbuild": "latest",
"vite": "5.0.8",
"vite": "5.0.9",
"vitest": "1.0.4",
"webpack": "5.89.0"
},
Expand Down
15 changes: 15 additions & 0 deletions packages/kit/src/nitro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ export function addServerImportsDir (dirs: string | string[], opts: { prepend?:
config.imports.dirs[opts.prepend ? 'unshift' : 'push'](..._dirs)
})
}

/**
* Add directories to be scanned by Nitro. It will check for subdirectories,
* which will be registered just like the `~/server` folder is.
*/
export function addServerScanDir (dirs: string | string[], opts: { prepend?: boolean } = {}) {
const nuxt = useNuxt()
nuxt.hook('nitro:config', (config) => {
config.scanDirs = config.scanDirs || []

for (const dir of (Array.isArray(dirs) ? dirs : [dirs])) {
config.scanDirs[opts.prepend ? 'unshift' : 'push'](dir)
}
})
}
1 change: 1 addition & 0 deletions packages/nuxt/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-var */
declare global {
var __NUXT_VERSION__: string
var __NUXT_ASYNC_CONTEXT__: boolean
var __NUXT_PREPATHS__: string[] | string | undefined
var __NUXT_PATHS__: string[] | string | undefined

Expand Down
2 changes: 1 addition & 1 deletion packages/nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"@types/fs-extra": "11.0.4",
"@vitejs/plugin-vue": "4.5.2",
"unbuild": "latest",
"vite": "5.0.8",
"vite": "5.0.9",
"vitest": "1.0.4"
},
"peerDependencies": {
Expand Down
4 changes: 2 additions & 2 deletions packages/nuxt/src/app/components/client-only.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
: h(res)
} else {
const fragment = getFragmentHTML(ctx._.vnode.el ?? null) ?? ['<div></div>']
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.$attrs ?? ctx._.attrs)
}
}
} else if (clone.template) {
Expand Down Expand Up @@ -80,7 +80,7 @@ export function createClientOnly<T extends ComponentOptions> (component: T) {
: h(res)
} else {
const fragment = getFragmentHTML(instance?.vnode.el ?? null) ?? ['<div></div>']
return process.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
return import.meta.client ? createStaticVNode(fragment.join(''), fragment.length) : h('div', ctx.attrs)
}
}
})
Expand Down
10 changes: 6 additions & 4 deletions packages/nuxt/src/app/composables/asyncContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// @ts-expect-error withAsyncContext is internal API
import { getCurrentInstance, withAsyncContext as withVueAsyncContext } from 'vue'

export function withNuxtContext <T>(fn: () => T) {
const nuxtApp = getCurrentInstance()?.appContext.app.$nuxt
return nuxtApp ? nuxtApp.runWithContext(fn) : fn()
}

export function withAsyncContext (fn: () => PromiseLike<unknown>) {
return withVueAsyncContext(() => {
const nuxtApp = getCurrentInstance()?.appContext.app.$nuxt
return nuxtApp ? nuxtApp.runWithContext(fn) : fn()
})
return withVueAsyncContext(() => withNuxtContext(fn))
}

0 comments on commit 4a7d11d

Please sign in to comment.