@nuxt/scripts 0.13.2 → 1.0.0-beta.2
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 +15 -0
- package/dist/client/200.html +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/B66N9HCo.js +1 -0
- package/dist/client/_nuxt/B8XOar-X.js +162 -0
- package/dist/client/_nuxt/{Bje-0OHL.js → DfLgoB--.js} +1 -1
- package/dist/client/_nuxt/DvH517bE.js +1 -0
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/133a46c5-a5c1-4a63-87d1-037947a5bcdb.json +1 -0
- package/dist/client/_nuxt/entry.D45OuV0w.css +1 -0
- package/dist/client/_nuxt/error-404.B57D-jUQ.css +1 -0
- package/dist/client/_nuxt/error-500.DTHUW7BI.css +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.d.mts +106 -4
- package/dist/module.json +1 -1
- package/dist/module.mjs +705 -173
- package/dist/registry.mjs +63 -0
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.d.vue.ts +29 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue +35 -10
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMaps.vue.d.ts +29 -1
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.d.vue.ts +20 -8
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue +2 -2
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue.d.ts +20 -8
- package/dist/runtime/components/GoogleMaps/ScriptGoogleMapsPinElement.vue +7 -1
- package/dist/runtime/components/ScriptCrisp.d.vue.ts +1 -1
- package/dist/runtime/components/ScriptCrisp.vue.d.ts +1 -1
- package/dist/runtime/components/ScriptInstagramEmbed.d.vue.ts +53 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue +38 -0
- package/dist/runtime/components/ScriptInstagramEmbed.vue.d.ts +53 -0
- package/dist/runtime/components/ScriptIntercom.d.vue.ts +1 -1
- package/dist/runtime/components/ScriptIntercom.vue.d.ts +1 -1
- package/dist/runtime/components/ScriptVimeoPlayer.d.vue.ts +2 -2
- package/dist/runtime/components/ScriptVimeoPlayer.vue.d.ts +2 -2
- package/dist/runtime/components/ScriptXEmbed.d.vue.ts +82 -0
- package/dist/runtime/components/ScriptXEmbed.vue +76 -0
- package/dist/runtime/components/ScriptXEmbed.vue.d.ts +82 -0
- package/dist/runtime/components/ScriptYouTubePlayer.d.vue.ts +12 -1
- package/dist/runtime/components/ScriptYouTubePlayer.vue +41 -16
- package/dist/runtime/components/ScriptYouTubePlayer.vue.d.ts +12 -1
- package/dist/runtime/composables/useScript.js +34 -3
- package/dist/runtime/composables/useScriptTriggerServiceWorker.d.ts +7 -0
- package/dist/runtime/composables/useScriptTriggerServiceWorker.js +39 -0
- package/dist/runtime/npm-script-stub.d.ts +20 -0
- package/dist/runtime/npm-script-stub.js +73 -0
- package/dist/runtime/plugins/sw-register.client.d.ts +2 -0
- package/dist/runtime/plugins/sw-register.client.js +12 -0
- package/dist/runtime/registry/google-recaptcha.d.ts +27 -0
- package/dist/runtime/registry/google-recaptcha.js +45 -0
- package/dist/runtime/registry/google-sign-in.d.ts +84 -0
- package/dist/runtime/registry/google-sign-in.js +50 -0
- package/dist/runtime/registry/google-tag-manager.d.ts +3 -1
- package/dist/runtime/registry/google-tag-manager.js +15 -5
- package/dist/runtime/registry/instagram-embed.d.ts +23 -0
- package/dist/runtime/registry/instagram-embed.js +22 -0
- package/dist/runtime/registry/lemon-squeezy.d.ts +0 -1
- package/dist/runtime/registry/matomo-analytics.js +1 -1
- package/dist/runtime/registry/plausible-analytics.js +8 -6
- package/dist/runtime/registry/posthog.d.ts +26 -0
- package/dist/runtime/registry/posthog.js +92 -0
- package/dist/runtime/registry/rybbit-analytics.js +38 -8
- package/dist/runtime/registry/tiktok-pixel.d.ts +44 -0
- package/dist/runtime/registry/tiktok-pixel.js +44 -0
- package/dist/runtime/registry/x-embed.d.ts +77 -0
- package/dist/runtime/registry/x-embed.js +41 -0
- package/dist/runtime/server/google-static-maps-proxy.d.ts +2 -0
- package/dist/runtime/server/google-static-maps-proxy.js +54 -0
- package/dist/runtime/server/instagram-embed-asset.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-asset.js +42 -0
- package/dist/runtime/server/instagram-embed-image.d.ts +2 -0
- package/dist/runtime/server/instagram-embed-image.js +54 -0
- package/dist/runtime/server/instagram-embed.d.ts +2 -0
- package/dist/runtime/server/instagram-embed.js +91 -0
- package/dist/runtime/server/proxy-handler.d.ts +6 -0
- package/dist/runtime/server/proxy-handler.js +230 -0
- package/dist/runtime/server/sw-handler.d.ts +2 -0
- package/dist/runtime/server/sw-handler.js +25 -0
- package/dist/runtime/server/utils/privacy.d.ts +97 -0
- package/dist/runtime/server/utils/privacy.js +268 -0
- package/dist/runtime/server/x-embed-image.d.ts +2 -0
- package/dist/runtime/server/x-embed-image.js +53 -0
- package/dist/runtime/server/x-embed.d.ts +49 -0
- package/dist/runtime/server/x-embed.js +31 -0
- package/dist/runtime/sw/proxy-sw.template.d.ts +1 -0
- package/dist/runtime/sw/proxy-sw.template.js +54 -0
- package/dist/runtime/types.d.ts +42 -1
- package/dist/runtime/utils/pure.d.ts +13 -0
- package/dist/runtime/utils/pure.js +67 -0
- package/dist/runtime/utils.d.ts +3 -2
- package/dist/runtime/utils.js +11 -1
- package/dist/types.d.mts +1 -1
- package/package.json +39 -32
- package/dist/client/_nuxt/DMut0W-e.js +0 -162
- package/dist/client/_nuxt/builds/meta/5e0206fe-a683-423c-8d59-2596d0b16fee.json +0 -1
- package/dist/client/_nuxt/entry.BjfcJo5q.css +0 -1
- package/dist/client/_nuxt/error-404.B0ZhSNwd.css +0 -1
- package/dist/client/_nuxt/error-500.D4MdgPaC.css +0 -1
- package/dist/client/_nuxt/iNmKC7TZ.js +0 -1
- package/dist/client/_nuxt/rttsH3SL.js +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
interface TweetData {
|
|
2
|
+
id_str: string;
|
|
3
|
+
text: string;
|
|
4
|
+
created_at: string;
|
|
5
|
+
favorite_count: number;
|
|
6
|
+
conversation_count: number;
|
|
7
|
+
user: {
|
|
8
|
+
name: string;
|
|
9
|
+
screen_name: string;
|
|
10
|
+
profile_image_url_https: string;
|
|
11
|
+
verified?: boolean;
|
|
12
|
+
is_blue_verified?: boolean;
|
|
13
|
+
};
|
|
14
|
+
entities?: {
|
|
15
|
+
media?: Array<{
|
|
16
|
+
media_url_https: string;
|
|
17
|
+
type: string;
|
|
18
|
+
sizes: Record<string, {
|
|
19
|
+
w: number;
|
|
20
|
+
h: number;
|
|
21
|
+
}>;
|
|
22
|
+
}>;
|
|
23
|
+
urls?: Array<{
|
|
24
|
+
url: string;
|
|
25
|
+
expanded_url: string;
|
|
26
|
+
display_url: string;
|
|
27
|
+
}>;
|
|
28
|
+
};
|
|
29
|
+
photos?: Array<{
|
|
30
|
+
url: string;
|
|
31
|
+
width: number;
|
|
32
|
+
height: number;
|
|
33
|
+
}>;
|
|
34
|
+
video?: {
|
|
35
|
+
poster: string;
|
|
36
|
+
variants: Array<{
|
|
37
|
+
type: string;
|
|
38
|
+
src: string;
|
|
39
|
+
}>;
|
|
40
|
+
};
|
|
41
|
+
quoted_tweet?: TweetData;
|
|
42
|
+
parent?: {
|
|
43
|
+
user: {
|
|
44
|
+
screen_name: string;
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<TweetData>>;
|
|
49
|
+
export default _default;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { createError, defineEventHandler, getQuery, setHeader } from "h3";
|
|
2
|
+
import { $fetch } from "ofetch";
|
|
3
|
+
export default defineEventHandler(async (event) => {
|
|
4
|
+
const query = getQuery(event);
|
|
5
|
+
const tweetId = query.id;
|
|
6
|
+
if (!tweetId || !/^\d+$/.test(tweetId)) {
|
|
7
|
+
throw createError({
|
|
8
|
+
statusCode: 400,
|
|
9
|
+
statusMessage: "Valid Tweet ID is required"
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
const randomToken = [...Array(11)].map(() => (Math.random() * 36).toString(36)[2]).join("");
|
|
13
|
+
const params = new URLSearchParams({ id: tweetId, token: randomToken });
|
|
14
|
+
const tweetData = await $fetch(
|
|
15
|
+
`https://cdn.syndication.twimg.com/tweet-result?${params.toString()}`,
|
|
16
|
+
{
|
|
17
|
+
headers: {
|
|
18
|
+
"Accept": "application/json",
|
|
19
|
+
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
).catch((error) => {
|
|
23
|
+
throw createError({
|
|
24
|
+
statusCode: error.statusCode || 500,
|
|
25
|
+
statusMessage: error.statusMessage || "Failed to fetch tweet"
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
setHeader(event, "Content-Type", "application/json");
|
|
29
|
+
setHeader(event, "Cache-Control", "public, max-age=600, s-maxage=600");
|
|
30
|
+
return tweetData;
|
|
31
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
})
|
package/dist/runtime/types.d.ts
CHANGED
|
@@ -29,8 +29,17 @@ import type { UmamiAnalyticsInput } from './registry/umami-analytics.js';
|
|
|
29
29
|
import type { RybbitAnalyticsInput } from './registry/rybbit-analytics.js';
|
|
30
30
|
import type { RedditPixelInput } from './registry/reddit-pixel.js';
|
|
31
31
|
import type { PayPalInput } from './registry/paypal.js';
|
|
32
|
+
import type { PostHogInput } from './registry/posthog.js';
|
|
33
|
+
import type { GoogleRecaptchaInput } from './registry/google-recaptcha.js';
|
|
34
|
+
import type { TikTokPixelInput } from './registry/tiktok-pixel.js';
|
|
32
35
|
export type WarmupStrategy = false | 'preload' | 'preconnect' | 'dns-prefetch';
|
|
33
|
-
export type UseScriptContext<T extends Record<symbol | string, any>> = VueScriptInstance<T
|
|
36
|
+
export type UseScriptContext<T extends Record<symbol | string, any>> = VueScriptInstance<T> & {
|
|
37
|
+
/**
|
|
38
|
+
* Remove and reload the script. Useful for scripts that need to re-execute
|
|
39
|
+
* after SPA navigation (e.g., DOM-scanning scripts like iubenda).
|
|
40
|
+
*/
|
|
41
|
+
reload: () => Promise<T>;
|
|
42
|
+
};
|
|
34
43
|
export type NuxtUseScriptOptions<T extends Record<symbol | string, any> = {}> = Omit<UseScriptOptions<T>, 'trigger'> & {
|
|
35
44
|
/**
|
|
36
45
|
* The trigger to load the script:
|
|
@@ -48,8 +57,24 @@ export type NuxtUseScriptOptions<T extends Record<symbol | string, any> = {}> =
|
|
|
48
57
|
* - `false` - Do not bundle the script. (default)
|
|
49
58
|
*
|
|
50
59
|
* Note: Using 'force' may significantly increase build time as scripts will be re-downloaded on every build.
|
|
60
|
+
*
|
|
61
|
+
* @deprecated Use `scripts.firstParty: true` in nuxt.config instead for bundling and routing scripts through your domain.
|
|
51
62
|
*/
|
|
52
63
|
bundle?: boolean | 'force';
|
|
64
|
+
/**
|
|
65
|
+
* Opt-out of first-party routing for this specific script when global `scripts.firstParty` is enabled.
|
|
66
|
+
* Set to `false` to load this script directly from its original source instead of through your domain.
|
|
67
|
+
*
|
|
68
|
+
* Note: This option only works as an opt-out. To enable first-party routing, use the global `scripts.firstParty` option in nuxt.config.
|
|
69
|
+
*/
|
|
70
|
+
firstParty?: false;
|
|
71
|
+
/**
|
|
72
|
+
* Load the script in a web worker using Partytown.
|
|
73
|
+
* When enabled, adds `type="text/partytown"` to the script tag.
|
|
74
|
+
* Requires @nuxtjs/partytown to be installed and configured separately.
|
|
75
|
+
* @see https://partytown.qwik.dev/
|
|
76
|
+
*/
|
|
77
|
+
partytown?: boolean;
|
|
53
78
|
/**
|
|
54
79
|
* Skip any schema validation for the script input. This is useful for loading the script stubs for development without
|
|
55
80
|
* loading the actual script and not getting warnings.
|
|
@@ -90,6 +115,8 @@ export type NuxtUseScriptOptionsSerializable = Omit<NuxtUseScriptOptions, 'use'
|
|
|
90
115
|
idleTimeout: number;
|
|
91
116
|
} | {
|
|
92
117
|
interaction: string[];
|
|
118
|
+
} | {
|
|
119
|
+
serviceWorker: true;
|
|
93
120
|
};
|
|
94
121
|
};
|
|
95
122
|
export type NuxtUseScriptInput = UseScriptInput;
|
|
@@ -135,16 +162,19 @@ export interface ScriptRegistry {
|
|
|
135
162
|
googleAdsense?: GoogleAdsenseInput;
|
|
136
163
|
googleAnalytics?: GoogleAnalyticsInput;
|
|
137
164
|
googleMaps?: GoogleMapsInput;
|
|
165
|
+
googleRecaptcha?: GoogleRecaptchaInput;
|
|
138
166
|
lemonSqueezy?: LemonSqueezyInput;
|
|
139
167
|
googleTagManager?: GoogleTagManagerInput;
|
|
140
168
|
hotjar?: HotjarInput;
|
|
141
169
|
intercom?: IntercomInput;
|
|
142
170
|
paypal?: PayPalInput;
|
|
171
|
+
posthog?: PostHogInput;
|
|
143
172
|
matomoAnalytics?: MatomoAnalyticsInput;
|
|
144
173
|
rybbitAnalytics?: RybbitAnalyticsInput;
|
|
145
174
|
redditPixel?: RedditPixelInput;
|
|
146
175
|
segment?: SegmentInput;
|
|
147
176
|
stripe?: StripeInput;
|
|
177
|
+
tiktokPixel?: TikTokPixelInput;
|
|
148
178
|
xPixel?: XPixelInput;
|
|
149
179
|
snapchatPixel?: SnapTrPixelInput;
|
|
150
180
|
youtubePlayer?: YouTubePlayerInput;
|
|
@@ -181,6 +211,17 @@ export type RegistryScriptInput<T = EmptyOptionsSchema, Bundelable extends boole
|
|
|
181
211
|
export interface RegistryScript {
|
|
182
212
|
import?: Import;
|
|
183
213
|
scriptBundling?: false | ((options?: any) => string | false);
|
|
214
|
+
/**
|
|
215
|
+
* First-party routing configuration for this script.
|
|
216
|
+
* - `string` - The proxy config key to use (e.g., 'googleAnalytics', 'metaPixel')
|
|
217
|
+
* - `false` - Explicitly disable first-party routing for this script
|
|
218
|
+
* - `undefined` - Use the default key derived from the function name
|
|
219
|
+
*
|
|
220
|
+
* When set to a string, the script's URLs will be rewritten and collection
|
|
221
|
+
* endpoints will be routed through your server when `scripts.firstParty` is enabled.
|
|
222
|
+
* @internal
|
|
223
|
+
*/
|
|
224
|
+
proxy?: string | false;
|
|
184
225
|
label?: string;
|
|
185
226
|
src?: string | false;
|
|
186
227
|
category?: string;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy configuration for third-party scripts.
|
|
3
|
+
*/
|
|
4
|
+
export interface ProxyRewrite {
|
|
5
|
+
/** Domain and path to match (e.g., 'www.google-analytics.com/g/collect') */
|
|
6
|
+
from: string;
|
|
7
|
+
/** Local path to rewrite to (e.g., '/_scripts/c/ga/g/collect') */
|
|
8
|
+
to: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Rewrite URLs in script content based on proxy config.
|
|
12
|
+
*/
|
|
13
|
+
export declare function rewriteScriptUrls(content: string, rewrites: ProxyRewrite[]): string;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { parseURL, joinURL } from "ufo";
|
|
2
|
+
export function rewriteScriptUrls(content, rewrites) {
|
|
3
|
+
let result = content;
|
|
4
|
+
const literalRegex = /(['"`])(.*?)\1/g;
|
|
5
|
+
for (const { from, to } of rewrites) {
|
|
6
|
+
const isSuffixMatch = from.startsWith(".");
|
|
7
|
+
const fromSlashIdx = from.indexOf("/");
|
|
8
|
+
const fromHost = fromSlashIdx > 0 ? from.slice(0, fromSlashIdx) : from;
|
|
9
|
+
const fromPath = fromSlashIdx > 0 ? from.slice(fromSlashIdx) : "";
|
|
10
|
+
result = result.replace(literalRegex, (match, quote, inner) => {
|
|
11
|
+
if (!inner.includes(fromHost)) return match;
|
|
12
|
+
const url = parseURL(inner);
|
|
13
|
+
let shouldRewrite = false;
|
|
14
|
+
let rewriteSuffix = "";
|
|
15
|
+
if (url.host) {
|
|
16
|
+
const hostMatches = isSuffixMatch ? url.host.endsWith(fromHost) : url.host === fromHost;
|
|
17
|
+
if (hostMatches) {
|
|
18
|
+
const fullPath = url.pathname + (url.search || "") + (url.hash || "");
|
|
19
|
+
if (fromPath && fullPath.startsWith(fromPath)) {
|
|
20
|
+
shouldRewrite = true;
|
|
21
|
+
rewriteSuffix = fullPath.slice(fromPath.length);
|
|
22
|
+
} else if (!fromPath) {
|
|
23
|
+
shouldRewrite = true;
|
|
24
|
+
rewriteSuffix = fullPath;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
} else if (inner.startsWith("//")) {
|
|
28
|
+
const hostPart = inner.slice(2).split("/")[0];
|
|
29
|
+
const hostMatches = isSuffixMatch ? hostPart?.endsWith(fromHost) ?? false : hostPart === fromHost;
|
|
30
|
+
if (hostMatches) {
|
|
31
|
+
const remainder = inner.slice(2 + (hostPart?.length ?? 0));
|
|
32
|
+
if (fromPath && remainder.startsWith(fromPath)) {
|
|
33
|
+
shouldRewrite = true;
|
|
34
|
+
rewriteSuffix = remainder.slice(fromPath.length);
|
|
35
|
+
} else if (!fromPath) {
|
|
36
|
+
shouldRewrite = true;
|
|
37
|
+
rewriteSuffix = remainder;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
} else if (fromPath && inner.startsWith(from) || isSuffixMatch && inner.includes(from)) {
|
|
41
|
+
const domainEnd = inner.indexOf(from) + from.length;
|
|
42
|
+
const nextChar = inner[domainEnd];
|
|
43
|
+
if (!nextChar || nextChar === "/" || nextChar === "?" || nextChar === "#") {
|
|
44
|
+
shouldRewrite = true;
|
|
45
|
+
rewriteSuffix = inner.slice(domainEnd);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (shouldRewrite) {
|
|
49
|
+
const rewritten = rewriteSuffix === "/" || rewriteSuffix.startsWith("?") || rewriteSuffix.startsWith("#") ? to + rewriteSuffix : joinURL(to, rewriteSuffix);
|
|
50
|
+
return quote + rewritten + quote;
|
|
51
|
+
}
|
|
52
|
+
return match;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
const gaRewrite = rewrites.find((r) => r.from.includes("google-analytics.com/g/collect"));
|
|
56
|
+
if (gaRewrite) {
|
|
57
|
+
result = result.replace(
|
|
58
|
+
/"https:\/\/"\+\(.*?\)\+"\.google-analytics\.com\/g\/collect"/g,
|
|
59
|
+
`"${gaRewrite.to}"`
|
|
60
|
+
);
|
|
61
|
+
result = result.replace(
|
|
62
|
+
/"https:\/\/"\+\(.*?\)\+"\.analytics\.google\.com\/g\/collect"/g,
|
|
63
|
+
`"${gaRewrite.to}"`
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
package/dist/runtime/utils.d.ts
CHANGED
|
@@ -10,8 +10,9 @@ type OptionsFn<O> = (options: InferIfSchema<O>, ctx: {
|
|
|
10
10
|
scriptInput?: UseScriptInput;
|
|
11
11
|
scriptOptions?: NuxtUseScriptOptions;
|
|
12
12
|
schema?: O extends ObjectSchema<any, any> ? O : undefined;
|
|
13
|
-
clientInit?: () => void
|
|
13
|
+
clientInit?: () => void | Promise<any>;
|
|
14
|
+
scriptMode?: 'external' | 'npm';
|
|
14
15
|
});
|
|
15
16
|
export declare function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T): ScriptRegistry[T];
|
|
16
17
|
export declare function useRegistryScript<T extends Record<string | symbol, any>, O = EmptyOptionsSchema>(registryKey: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): UseScriptContext<UseFunctionType<NuxtUseScriptOptions<T>, T>>;
|
|
17
|
-
export
|
|
18
|
+
export * from './utils/pure.js';
|
package/dist/runtime/utils.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { defu } from "defu";
|
|
2
2
|
import { useRuntimeConfig } from "nuxt/app";
|
|
3
|
+
import { parseURL, withQuery, parseQuery } from "ufo";
|
|
3
4
|
import { useScript } from "./composables/useScript.js";
|
|
5
|
+
import { createNpmScriptStub } from "./npm-script-stub.js";
|
|
4
6
|
import { parse } from "#nuxt-scripts-validator";
|
|
5
|
-
import { parseURL, withQuery, parseQuery } from "ufo";
|
|
6
7
|
function validateScriptInputSchema(key, schema, options) {
|
|
7
8
|
if (import.meta.dev) {
|
|
8
9
|
try {
|
|
@@ -20,6 +21,14 @@ export function useRegistryScript(registryKey, optionsFn, _userOptions) {
|
|
|
20
21
|
const scriptConfig = scriptRuntimeConfig(registryKey);
|
|
21
22
|
const userOptions = Object.assign(_userOptions || {}, typeof scriptConfig === "object" ? scriptConfig : {});
|
|
22
23
|
const options = optionsFn(userOptions, { scriptInput: userOptions.scriptInput });
|
|
24
|
+
if (options.scriptMode === "npm") {
|
|
25
|
+
return createNpmScriptStub({
|
|
26
|
+
key: String(registryKey),
|
|
27
|
+
use: options.scriptOptions?.use,
|
|
28
|
+
clientInit: options.clientInit,
|
|
29
|
+
trigger: userOptions.scriptOptions?.trigger
|
|
30
|
+
});
|
|
31
|
+
}
|
|
23
32
|
let finalScriptInput = options.scriptInput;
|
|
24
33
|
const userSrc = userOptions.scriptInput?.src;
|
|
25
34
|
const optionsSrc = options.scriptInput?.src;
|
|
@@ -86,3 +95,4 @@ export function useRegistryScript(registryKey, optionsFn, _userOptions) {
|
|
|
86
95
|
};
|
|
87
96
|
return useScript(scriptInput, scriptOptions);
|
|
88
97
|
}
|
|
98
|
+
export * from "./utils/pure.js";
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/scripts",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-beta.2",
|
|
5
5
|
"description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
|
|
6
6
|
"author": {
|
|
7
7
|
"website": "https://harlanzw.com",
|
|
8
8
|
"name": "Harlan Wilton",
|
|
9
|
-
"
|
|
9
|
+
"email": "harlan@harlanzw.com"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
12
|
"repository": {
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
"@unhead/vue",
|
|
44
44
|
"@unhead/schema",
|
|
45
45
|
"knitwork",
|
|
46
|
-
"estree-walker",
|
|
47
46
|
"#build/modules/nuxt-scripts-gtm",
|
|
48
47
|
"#build/modules/nuxt-scripts-ga",
|
|
49
48
|
"@vimeo/player",
|
|
50
49
|
"esbuild",
|
|
51
50
|
"unimport",
|
|
52
51
|
"#nuxt-scripts/types",
|
|
53
|
-
"#nuxt-scripts-validator"
|
|
52
|
+
"#nuxt-scripts-validator",
|
|
53
|
+
"posthog-js"
|
|
54
54
|
]
|
|
55
55
|
},
|
|
56
56
|
"peerDependencies": {
|
|
@@ -60,7 +60,8 @@
|
|
|
60
60
|
"@types/google.maps": "^3.58.1",
|
|
61
61
|
"@types/vimeo__player": "^2.18.3",
|
|
62
62
|
"@types/youtube": "^0.1.0",
|
|
63
|
-
"@unhead/vue": "^2.0.3"
|
|
63
|
+
"@unhead/vue": "^2.0.3",
|
|
64
|
+
"posthog-js": "^1.0.0"
|
|
64
65
|
},
|
|
65
66
|
"peerDependenciesMeta": {
|
|
66
67
|
"@googlemaps/markerclusterer": {
|
|
@@ -80,52 +81,58 @@
|
|
|
80
81
|
},
|
|
81
82
|
"@types/youtube": {
|
|
82
83
|
"optional": true
|
|
84
|
+
},
|
|
85
|
+
"posthog-js": {
|
|
86
|
+
"optional": true
|
|
83
87
|
}
|
|
84
88
|
},
|
|
85
89
|
"dependencies": {
|
|
86
|
-
"@nuxt/kit": "^
|
|
87
|
-
"@
|
|
90
|
+
"@nuxt/devtools-kit": "^3.2.1",
|
|
91
|
+
"@nuxt/kit": "^4.3.1",
|
|
92
|
+
"@vueuse/core": "^14.2.1",
|
|
88
93
|
"consola": "^3.4.2",
|
|
89
94
|
"defu": "^6.1.4",
|
|
90
|
-
"h3": "^1.15.
|
|
95
|
+
"h3": "^1.15.5",
|
|
91
96
|
"magic-string": "^0.30.21",
|
|
92
97
|
"ofetch": "^1.5.1",
|
|
93
98
|
"ohash": "^2.0.11",
|
|
99
|
+
"oxc-parser": "^0.115.0",
|
|
100
|
+
"oxc-walker": "^0.7.0",
|
|
94
101
|
"pathe": "^2.0.3",
|
|
95
102
|
"pkg-types": "^2.3.0",
|
|
96
103
|
"sirv": "^3.0.2",
|
|
97
104
|
"std-env": "^3.10.0",
|
|
98
|
-
"ufo": "^1.6.
|
|
99
|
-
"unplugin": "^
|
|
100
|
-
"unstorage": "^1.17.
|
|
105
|
+
"ufo": "^1.6.3",
|
|
106
|
+
"unplugin": "^3.0.0",
|
|
107
|
+
"unstorage": "^1.17.4",
|
|
101
108
|
"valibot": "^1.2.0"
|
|
102
109
|
},
|
|
103
110
|
"devDependencies": {
|
|
104
|
-
"@nuxt/devtools-kit": "^3.
|
|
105
|
-
"@nuxt/
|
|
106
|
-
"@nuxt/eslint-config": "^1.12.1",
|
|
111
|
+
"@nuxt/devtools-ui-kit": "^3.2.1",
|
|
112
|
+
"@nuxt/eslint-config": "^1.15.2",
|
|
107
113
|
"@nuxt/module-builder": "^1.0.2",
|
|
108
|
-
"@nuxt/test-utils": "
|
|
109
|
-
"@
|
|
114
|
+
"@nuxt/test-utils": "^4.0.0",
|
|
115
|
+
"@nuxtjs/partytown": "^2.0.0",
|
|
116
|
+
"@paypal/paypal-js": "^9.3.0",
|
|
110
117
|
"@types/semver": "^7.7.1",
|
|
111
|
-
"@typescript-eslint/typescript-estree": "^8.
|
|
118
|
+
"@typescript-eslint/typescript-estree": "^8.56.1",
|
|
112
119
|
"@vue/test-utils": "^2.4.6",
|
|
113
|
-
"
|
|
114
|
-
"bumpp": "^10.3.2",
|
|
120
|
+
"bumpp": "^10.4.1",
|
|
115
121
|
"changelogen": "^0.6.2",
|
|
116
|
-
"eslint": "^
|
|
117
|
-
"eslint-plugin-n": "^17.
|
|
118
|
-
"happy-dom": "^20.0
|
|
122
|
+
"eslint": "^10.0.2",
|
|
123
|
+
"eslint-plugin-n": "^17.24.0",
|
|
124
|
+
"happy-dom": "^20.7.0",
|
|
119
125
|
"knitwork": "^1.3.0",
|
|
120
|
-
"nuxt": "^4.
|
|
121
|
-
"playwright-core": "^1.
|
|
122
|
-
"
|
|
126
|
+
"nuxt": "^4.3.1",
|
|
127
|
+
"playwright-core": "^1.58.2",
|
|
128
|
+
"posthog-js": "^1.353.0",
|
|
129
|
+
"shiki": "^3.22.0",
|
|
123
130
|
"typescript": "5.9.3",
|
|
124
|
-
"vitest": "^4.0.
|
|
125
|
-
"vue": "^3.5.
|
|
126
|
-
"vue-router": "^
|
|
127
|
-
"vue-tsc": "^3.
|
|
128
|
-
"@nuxt/scripts": "0.
|
|
131
|
+
"vitest": "^4.0.18",
|
|
132
|
+
"vue": "^3.5.29",
|
|
133
|
+
"vue-router": "^5.0.3",
|
|
134
|
+
"vue-tsc": "^3.2.5",
|
|
135
|
+
"@nuxt/scripts": "1.0.0-beta.2"
|
|
129
136
|
},
|
|
130
137
|
"resolutions": {
|
|
131
138
|
"@nuxt/scripts": "workspace:*"
|
|
@@ -136,7 +143,7 @@
|
|
|
136
143
|
"client:dev": "nuxi dev client --port 3300",
|
|
137
144
|
"dev": "nuxi dev playground",
|
|
138
145
|
"dev:ssl": "nuxi dev playground --https",
|
|
139
|
-
"prepare:fixtures": "nuxi prepare test/fixtures/basic && nuxi prepare test/fixtures/cdn && nuxi prepare test/fixtures/extend-registry",
|
|
146
|
+
"prepare:fixtures": "nuxi prepare test/fixtures/basic && nuxi prepare test/fixtures/cdn && nuxi prepare test/fixtures/extend-registry && nuxi prepare test/fixtures/partytown && nuxi prepare test/fixtures/first-party",
|
|
140
147
|
"dev:prepare": "nuxt-module-build build --stub && nuxt-module-build prepare && nuxi prepare playground && pnpm run prepare:fixtures",
|
|
141
148
|
"typecheck": "vue-tsc --noEmit",
|
|
142
149
|
"bump": "bumpp package.json --commit --push --tag",
|
|
@@ -144,6 +151,6 @@
|
|
|
144
151
|
"lint": "eslint .",
|
|
145
152
|
"lint:fix": "eslint . --fix",
|
|
146
153
|
"test": "pnpm dev:prepare && vitest --run",
|
|
147
|
-
"test:types": "
|
|
154
|
+
"test:types": "vitest run --project typecheck"
|
|
148
155
|
}
|
|
149
156
|
}
|