@nuxt/scripts 1.0.0-beta.5 → 1.0.0-beta.6

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.
@@ -1 +0,0 @@
1
- {"id":"d7be6a88-31d8-4c91-90c7-54ab7d487a0f","timestamp":1772073969311,"prerendered":[]}
@@ -1,2 +0,0 @@
1
- declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
2
- export default _default;
@@ -1,12 +0,0 @@
1
- import { defineNuxtPlugin } from "nuxt/app";
2
- export default defineNuxtPlugin({
3
- name: "nuxt-scripts:sw-register",
4
- enforce: "pre",
5
- async setup() {
6
- if (!("serviceWorker" in navigator))
7
- return;
8
- await navigator.serviceWorker.register(SW_PATH, { scope: "/" }).catch((err) => {
9
- console.warn("[nuxt-scripts] Service worker registration failed:", err);
10
- });
11
- }
12
- });
@@ -1,2 +0,0 @@
1
- declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<string>>;
2
- export default _default;
@@ -1,25 +0,0 @@
1
- import { defineEventHandler, setResponseHeader } from "h3";
2
- import { useRuntimeConfig } from "#imports";
3
- import { parseURL } from "ufo";
4
- export default defineEventHandler(async (event) => {
5
- const config = useRuntimeConfig(event);
6
- const proxyConfig = config["nuxt-scripts-proxy"];
7
- const swTemplate = config["nuxt-scripts"]?.swTemplate || "";
8
- const routes = proxyConfig?.routes || {};
9
- const rules = Object.entries(routes).map(([localPath, proxy]) => {
10
- const url = parseURL(proxy.replace(/\*\*$/, ""));
11
- if (!url.host) return null;
12
- return {
13
- pattern: url.host,
14
- pathPrefix: url.pathname || "",
15
- target: localPath.replace(/\/\*\*$/, "")
16
- };
17
- }).filter(Boolean);
18
- const swCode = `const INTERCEPT_RULES = ${JSON.stringify(rules)};
19
-
20
- ${swTemplate}`;
21
- setResponseHeader(event, "Content-Type", "application/javascript");
22
- setResponseHeader(event, "Service-Worker-Allowed", "/");
23
- setResponseHeader(event, "Cache-Control", "no-cache");
24
- return swCode;
25
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,54 +0,0 @@
1
- /**
2
- * Nuxt Scripts Service Worker - intercepts analytics requests
3
- *
4
- * Injected at runtime:
5
- * - INTERCEPT_RULES: Array<{ pattern: string, pathPrefix: string, target: string }>
6
- */
7
-
8
- /* global INTERCEPT_RULES */
9
-
10
- self.addEventListener('install', () => {
11
- // console.log('[nuxt-scripts-sw] Installing...');
12
- self.skipWaiting()
13
- })
14
-
15
- self.addEventListener('activate', (event) => {
16
- // console.log('[nuxt-scripts-sw] Activating...');
17
- event.waitUntil(self.clients.claim())
18
- })
19
-
20
- self.addEventListener('fetch', (event) => {
21
- const url = new URL(event.request.url)
22
-
23
- // Only intercept cross-origin requests
24
- if (url.origin === self.location.origin) return
25
-
26
- for (const rule of INTERCEPT_RULES) {
27
- const hostMatches = url.host === rule.pattern || url.host.endsWith('.' + rule.pattern)
28
- // Check if path prefix matches (if one is required)
29
- const pathMatches = !rule.pathPrefix || url.pathname.startsWith(rule.pathPrefix)
30
-
31
- if (hostMatches && pathMatches) {
32
- // Strip path prefix from the original URL path before building proxy URL
33
- const strippedPath = rule.pathPrefix
34
- ? url.pathname.slice(rule.pathPrefix.length) || '/'
35
- : url.pathname
36
-
37
- // console.log('[nuxt-scripts-sw] Intercepting:', url.href, '->', rule.target + strippedPath);
38
-
39
- const separator = strippedPath.startsWith('/') ? '' : '/'
40
- const proxyUrl = new URL(rule.target + separator + strippedPath + url.search, self.location.origin)
41
- const clonedRequest = event.request.clone()
42
- event.respondWith(
43
- fetch(proxyUrl.href, {
44
- method: clonedRequest.method,
45
- headers: clonedRequest.headers,
46
- body: clonedRequest.method !== 'GET' && clonedRequest.method !== 'HEAD' ? clonedRequest.body : undefined,
47
- credentials: 'same-origin',
48
- redirect: 'follow',
49
- }),
50
- )
51
- return
52
- }
53
- }
54
- })