@netlify/nuxt 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Netlify 🤝 Nuxt
2
+
3
+ [![npm version][npm-version-src]][npm-version-href] [![npm downloads][npm-downloads-src]][npm-downloads-href]
4
+ [![License][license-src]][license-href] [![Nuxt][nuxt-src]][nuxt-href]
5
+
6
+ `@netlify/nuxt` provides local emulation of the Netlify platform directly in `nuxt dev`
7
+
8
+ ## Features
9
+
10
+ This repackages all the same features as `@netlify/vite-plugin`.
11
+ [Check out its docs for details](../packages/vite-plugin/README.md).
12
+
13
+ ## Quick Setup
14
+
15
+ Install the module to your Nuxt application with one command:
16
+
17
+ ```bash
18
+ npx nuxi module add @netlify/nuxt
19
+ ```
20
+
21
+ That's it! You now have local emulation of the full Netlify platform automatically in your nuxt dev server:
22
+
23
+ ```bash
24
+ npx nuxt dev
25
+ ```
26
+
27
+ ## Contribution
28
+
29
+ <details>
30
+ <summary>Local development</summary>
31
+
32
+ ```bash
33
+ # Install dependencies
34
+ npm install
35
+
36
+ # Generate type stubs
37
+ npm run dev:prepare
38
+
39
+ # Develop with the playground
40
+ npm run dev
41
+
42
+ # Build the playground
43
+ npm run dev:build
44
+
45
+ # Run ESLint
46
+ npm run lint
47
+
48
+ # Run Vitest
49
+ npm run test
50
+ npm run test:watch
51
+ ```
52
+
53
+ </details>
54
+
55
+ <!-- Badges -->
56
+
57
+ [npm-version-src]: https://img.shields.io/npm/v/@netlify/nuxt/latest.svg?style=flat&colorA=020420&colorB=00DC82
58
+ [npm-version-href]: https://npmjs.com/package/@netlify/nuxt
59
+ [npm-downloads-src]: https://img.shields.io/npm/dm/@netlify/nuxt.svg?style=flat&colorA=020420&colorB=00DC82
60
+ [npm-downloads-href]: https://npm.chart.dev/@netlify/nuxt
61
+ [license-src]: https://img.shields.io/npm/l/@netlify/nuxt.svg?style=flat&colorA=020420&colorB=00DC82
62
+ [license-href]: https://npmjs.com/package/@netlify/nuxt
63
+ [nuxt-src]: https://img.shields.io/badge/Nuxt-020420?logo=nuxt.js
64
+ [nuxt-href]: https://nuxt.com
@@ -0,0 +1,8 @@
1
+ import * as _nuxt_schema from '@nuxt/schema';
2
+ import { Features } from '@netlify/dev';
3
+
4
+ type NetlifyModuleOptions = Features;
5
+ declare const _default: _nuxt_schema.NuxtModule<Features, Features, false>;
6
+
7
+ export { _default as default };
8
+ export type { NetlifyModuleOptions };
@@ -0,0 +1,9 @@
1
+ {
2
+ "name": "@netlify/nuxt",
3
+ "configKey": "netlify",
4
+ "version": "0.0.0",
5
+ "builder": {
6
+ "@nuxt/module-builder": "1.0.1",
7
+ "unbuild": "3.5.0"
8
+ }
9
+ }
@@ -0,0 +1,88 @@
1
+ import process from 'node:process';
2
+ import { defineNuxtModule } from '@nuxt/kit';
3
+ import { NetlifyDev } from '@netlify/dev';
4
+ import { netlifyCommand, fromWebResponse, netlifyBanner } from '@netlify/dev-utils';
5
+ import { defineLazyEventHandler, fromNodeMiddleware } from 'h3';
6
+
7
+ const createPrefixedLogger = (prefix, logger) => ({
8
+ log: (msg) => {
9
+ logger.log(`${prefix} ${msg ?? ""}`);
10
+ },
11
+ warn: (msg) => {
12
+ logger.warn(`${prefix} ${msg ?? ""}`);
13
+ },
14
+ error: (msg) => {
15
+ logger.error(`${prefix} ${msg ?? ""}`);
16
+ }
17
+ });
18
+ const module = defineNuxtModule({
19
+ meta: {
20
+ name: "@netlify/nuxt",
21
+ configKey: "netlify"
22
+ },
23
+ defaults: {},
24
+ async setup(options, nuxt) {
25
+ if (process.env.NETLIFY_DEV) {
26
+ return;
27
+ }
28
+ if (!(nuxt.options.dev || nuxt.options.test)) {
29
+ return;
30
+ }
31
+ const logger = createPrefixedLogger(netlifyBanner, console);
32
+ const { blobs, edgeFunctions, functions, redirects } = options;
33
+ let netlifyDev;
34
+ nuxt.hook("nitro:init", async (nitro) => {
35
+ netlifyDev = new NetlifyDev({
36
+ blobs,
37
+ edgeFunctions,
38
+ functions,
39
+ logger,
40
+ redirects,
41
+ projectRoot: nuxt.options.rootDir,
42
+ staticFiles: {
43
+ ...options.staticFiles,
44
+ directories: nitro.options.publicAssets.map((d) => d.dir)
45
+ }
46
+ });
47
+ await netlifyDev.start();
48
+ nuxt.hook("close", () => {
49
+ netlifyDev.stop();
50
+ });
51
+ if (!netlifyDev.siteIsLinked) {
52
+ logger.log(
53
+ `\u{1F4AD} Linking this project to a Netlify site lets you deploy your site, use any environment variables defined on your team and site and much more. Run ${netlifyCommand("npx netlify init")} to get started.`
54
+ );
55
+ }
56
+ logger.log("Environment loaded");
57
+ });
58
+ nuxt.options.nitro.devHandlers ??= [];
59
+ nuxt.options.nitro.devHandlers.push({
60
+ handler: defineLazyEventHandler(() => {
61
+ logger.log(`Middleware loaded. Emulating features: ${netlifyDev.getEnabledFeatures().join(", ")}.`);
62
+ return fromNodeMiddleware(async function netlifyPreMiddleware(nodeReq, nodeRes, next) {
63
+ if (!netlifyDev) {
64
+ return;
65
+ }
66
+ const headers = {};
67
+ const result = await netlifyDev.handleAndIntrospectNodeRequest(nodeReq, {
68
+ headersCollector: (key, value) => {
69
+ headers[key] = value;
70
+ },
71
+ serverAddress: `http://localhost:${nodeReq.socket.localPort}`
72
+ });
73
+ const isStaticFile = result?.type === "static";
74
+ if (result && !isStaticFile) {
75
+ fromWebResponse(result.response, nodeRes);
76
+ return;
77
+ }
78
+ for (const key in headers) {
79
+ nodeRes.setHeader(key, headers[key] ?? "");
80
+ }
81
+ next();
82
+ });
83
+ })
84
+ });
85
+ }
86
+ });
87
+
88
+ export { module as default };
@@ -0,0 +1,9 @@
1
+ import type { NuxtModule } from '@nuxt/schema'
2
+
3
+ import type { default as Module } from './module.mjs'
4
+
5
+ export type ModuleOptions = typeof Module extends NuxtModule<infer O> ? Partial<O> : Record<string, any>
6
+
7
+ export { default } from './module.mjs'
8
+
9
+ export { type NetlifyModuleOptions } from './module.mjs'
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@netlify/nuxt",
3
+ "version": "0.0.0",
4
+ "description": "Nuxt module providing local emulation of the Netlify environment",
5
+ "type": "module",
6
+ "engines": {
7
+ "node": "^20.6.1 || >=22"
8
+ },
9
+ "main": "./dist/module.mjs",
10
+ "typesVersions": {
11
+ "*": {
12
+ ".": [
13
+ "./dist/types.d.mts"
14
+ ]
15
+ }
16
+ },
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/types.d.mts",
20
+ "import": "./dist/module.mjs"
21
+ }
22
+ },
23
+ "files": [
24
+ "dist"
25
+ ],
26
+ "scripts": {
27
+ "build": "nuxt-module-build prepare && nuxt-module-build build",
28
+ "dev": "npm run dev:prepare && nuxi dev playground",
29
+ "dev:build": "nuxi build playground",
30
+ "dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground",
31
+ "lint": "eslint .",
32
+ "prepack": "npm run build",
33
+ "publint": "npx -y publint --strict",
34
+ "test": "vitest run",
35
+ "//": "Workaround to run this package's eslint in CI",
36
+ "test:ci": "npm run lint && npm run test:types && npm run test",
37
+ "test:dev": "vitest",
38
+ "test:types": "vue-tsc --noEmit && cd playground && vue-tsc --noEmit",
39
+ "test:watch": "vitest watch"
40
+ },
41
+ "keywords": [
42
+ "netlify",
43
+ "nuxt",
44
+ "nuxt-module",
45
+ "dev"
46
+ ],
47
+ "license": "MIT",
48
+ "repository": "netlify/primitives",
49
+ "bugs": {
50
+ "url": "https://github.com/netlify/primitives/issues"
51
+ },
52
+ "author": "Netlify Inc.",
53
+ "dependencies": {
54
+ "@netlify/dev": "^4.3.8",
55
+ "@netlify/dev-utils": "^3.2.2",
56
+ "@nuxt/kit": "^3.17.6",
57
+ "h3": "^1.15.3"
58
+ },
59
+ "devDependencies": {
60
+ "@nuxt/devtools": "^2.6.2",
61
+ "@nuxt/eslint-config": "^1.5.2",
62
+ "@nuxt/module-builder": "^1.0.1",
63
+ "@nuxt/schema": "^3.17.6",
64
+ "@nuxt/test-utils": "^3.19.2",
65
+ "@types/node": "latest",
66
+ "changelogen": "^0.6.2",
67
+ "eslint": "^9.30.1",
68
+ "nuxt": "^3.17.6",
69
+ "typescript": "~5.8.3",
70
+ "vitest": "^3.2.4",
71
+ "vue-tsc": "^3.0.1"
72
+ }
73
+ }