@nuxt/scripts 0.1.9 → 0.1.11

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.
Files changed (38) hide show
  1. package/dist/client/200.html +5 -5
  2. package/dist/client/404.html +5 -5
  3. package/dist/client/_nuxt/{Cx7pcWFu.js → BVxXpP8q.js} +1 -1
  4. package/dist/client/_nuxt/{BAdl5pI-.js → CgE1uXjm.js} +1 -1
  5. package/dist/client/_nuxt/{598pLFA2.js → DWfzZAoR.js} +1 -1
  6. package/dist/client/_nuxt/builds/latest.json +1 -1
  7. package/dist/client/_nuxt/builds/meta/30ab3bf1-cef9-406d-a50f-876dac2441b6.json +1 -0
  8. package/dist/client/_nuxt/{C-ajRY17.js → tEXKqKss.js} +3 -3
  9. package/dist/client/index.html +5 -5
  10. package/dist/module.json +1 -1
  11. package/dist/module.mjs +110 -33
  12. package/dist/runtime/registry/cloudflare-turnstile.d.ts +1 -1
  13. package/dist/runtime/registry/cloudflare-turnstile.mjs +2 -1
  14. package/dist/runtime/registry/cloudflare-web-analytics.d.ts +3 -2
  15. package/dist/runtime/registry/cloudflare-web-analytics.mjs +1 -0
  16. package/dist/runtime/registry/confetti.d.ts +6 -5
  17. package/dist/runtime/registry/confetti.mjs +1 -1
  18. package/dist/runtime/registry/facebook-pixel.d.ts +3 -2
  19. package/dist/runtime/registry/facebook-pixel.mjs +1 -0
  20. package/dist/runtime/registry/fathom-analytics.d.ts +3 -2
  21. package/dist/runtime/registry/fathom-analytics.mjs +1 -0
  22. package/dist/runtime/registry/google-analytics.d.ts +1 -1
  23. package/dist/runtime/registry/google-analytics.mjs +2 -1
  24. package/dist/runtime/registry/google-maps.d.ts +1 -0
  25. package/dist/runtime/registry/google-maps.mjs +4 -0
  26. package/dist/runtime/registry/google-tag-manager.d.ts +1 -1
  27. package/dist/runtime/registry/google-tag-manager.mjs +2 -1
  28. package/dist/runtime/registry/hotjar.d.ts +2 -2
  29. package/dist/runtime/registry/hotjar.mjs +1 -0
  30. package/dist/runtime/registry/intercom.d.ts +2 -2
  31. package/dist/runtime/registry/intercom.mjs +1 -0
  32. package/dist/runtime/registry/segment.d.ts +2 -2
  33. package/dist/runtime/registry/segment.mjs +1 -0
  34. package/dist/runtime/types.d.ts +18 -15
  35. package/dist/runtime/utils.d.ts +1 -0
  36. package/dist/runtime/utils.mjs +5 -0
  37. package/package.json +2 -1
  38. package/dist/client/_nuxt/builds/meta/5fdc85c0-58a5-4956-bedd-f94dc9ec3924.json +0 -1
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html><html><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-scripts/_nuxt/entry.D91GVkD7.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/C-ajRY17.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-scripts/_nuxt/tEXKqKss.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DXFkqnOI.js">
6
6
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/D6NljDpC.js">
7
7
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CowR2XfX.js">
@@ -230,10 +230,10 @@
230
230
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DggdVF2v.js">
231
231
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/A1WiD9SJ.js">
232
232
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-404.ORekjfyJ.css">
233
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BAdl5pI-.js">
234
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/598pLFA2.js">
233
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/CgE1uXjm.js">
234
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/DWfzZAoR.js">
235
235
  <link rel="prefetch" as="style" href="/__nuxt-scripts/_nuxt/error-500.BIuFL0tW.css">
236
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/Cx7pcWFu.js">
237
- <script type="module" src="/__nuxt-scripts/_nuxt/C-ajRY17.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
236
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-scripts/_nuxt/BVxXpP8q.js">
237
+ <script type="module" src="/__nuxt-scripts/_nuxt/tEXKqKss.js" crossorigin></script><script>"use strict";(()=>{const a=window,e=document.documentElement,c=window.localStorage,d=["dark","light"],n=c&&c.getItem&&c.getItem("nuxt-color-mode")||"system";let l=n==="system"?f():n;const i=e.getAttribute("data-color-mode-forced");i&&(l=i),r(l),a["__NUXT_COLOR_MODE__"]={preference:n,value:l,getColorScheme:f,addColorScheme:r,removeColorScheme:u};function r(o){const t=""+o+"",s="";e.classList?e.classList.add(t):e.className+=" "+t,s&&e.setAttribute("data-"+s,o)}function u(o){const t=""+o+"",s="";e.classList?e.classList.remove(t):e.className=e.className.replace(new RegExp(t,"g"),""),s&&e.removeAttribute("data-"+s)}function m(o){return a.matchMedia("(prefers-color-scheme"+o+")")}function f(){if(a.matchMedia&&m("").media!=="not all"){for(const o of d)if(m(":"+o).matches)return o}return"light"}})();
238
238
  </script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" id="__NUXT_DATA__" data-ssr="false">[{"_errors":1,"serverRendered":2,"data":3,"state":4,"once":5},{},false,{},{},["Set"]]</script>
239
239
  <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-scripts",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.json CHANGED
@@ -5,5 +5,5 @@
5
5
  "nuxt": "^3.11.1",
6
6
  "bridge": false
7
7
  },
8
- "version": "0.1.9"
8
+ "version": "0.1.11"
9
9
  }
package/dist/module.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, defineNuxtModule, addImportsDir, addImports, addPlugin, addBuildPlugin } from '@nuxt/kit';
2
- import { readPackageJSON } from 'pkg-types';
1
+ import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, tryUseNuxt, logger as logger$1, defineNuxtModule, addImportsDir, addImports, addPlugin, addBuildPlugin, hasNuxtModule } from '@nuxt/kit';
2
+ import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
3
3
  import { parseURL, parseQuery, joinURL, hasProtocol, withQuery, withBase } from 'ufo';
4
4
  import { existsSync } from 'node:fs';
5
5
  import { pathToFileURL } from 'node:url';
@@ -15,6 +15,7 @@ import { join, relative } from 'pathe';
15
15
  import { hash } from 'ohash';
16
16
  import { createStorage } from 'unstorage';
17
17
  import fsDriver from 'unstorage/drivers/fs-lite';
18
+ import { isCI, provider } from 'std-env';
18
19
 
19
20
  const DEVTOOLS_UI_ROUTE = "/__nuxt-scripts";
20
21
  const DEVTOOLS_UI_LOCAL_PORT = 3030;
@@ -106,6 +107,7 @@ function NuxtScriptAssetBundlerTransformer(options) {
106
107
  console.warn(`[Nuxt Scripts] Integration ${fnName} not found in registry. Used in ${id}.`);
107
108
  return;
108
109
  }
110
+ options.moduleDetected(registryNode.module);
109
111
  if (!registryNode.transform && !registryNode.src)
110
112
  return;
111
113
  const optionsNode = node.arguments[0];
@@ -118,10 +120,13 @@ function NuxtScriptAssetBundlerTransformer(options) {
118
120
  const srcProperty = node.arguments[0].properties.find(
119
121
  (p) => p.key?.name === "src" || p.key?.value === "src"
120
122
  );
121
- if (srcProperty?.value?.value)
123
+ if (srcProperty?.value?.value) {
122
124
  scriptSrcNode = srcProperty.value;
123
- else
125
+ } else {
124
126
  src = registryNode.src || registryNode.transform?.(fnArg0);
127
+ if (src === false)
128
+ return;
129
+ }
125
130
  scriptKey = registryNode.key;
126
131
  }
127
132
  }
@@ -271,7 +276,7 @@ function extendTypes(module, template) {
271
276
  const nuxt = useNuxt();
272
277
  const { resolve } = createResolver(import.meta.url);
273
278
  addTemplate({
274
- filename: `modules/${module}.d.ts`,
279
+ filename: `modules/${module.replace("/", "-")}.d.ts`,
275
280
  getContents: async () => {
276
281
  const typesPath = relative(resolve(nuxt.options.rootDir, nuxt.options.buildDir, "module"), resolve("runtime/types"));
277
282
  const s = await template({ typesPath });
@@ -285,6 +290,45 @@ export {}
285
290
  references.push({ path: resolve(nuxt.options.buildDir, `module/${module}.d.ts`) });
286
291
  });
287
292
  }
293
+ const isStackblitz = provider === "stackblitz";
294
+ async function promptToInstall(name, installCommand, options) {
295
+ if (await resolvePackageJSON(name, { url: options.searchPaths }).catch(() => null))
296
+ return true;
297
+ logger$1.info(`Package ${name} is missing`);
298
+ if (isCI)
299
+ return false;
300
+ if (options.prompt === true || options.prompt !== false && !isStackblitz) {
301
+ const confirm = await logger$1.prompt(`Do you want to install ${name} package?`, {
302
+ type: "confirm",
303
+ name: "confirm",
304
+ initial: true
305
+ });
306
+ if (!confirm)
307
+ return false;
308
+ }
309
+ logger$1.info(`Installing ${name}...`);
310
+ try {
311
+ await installCommand();
312
+ logger$1.success(`Installed ${name}`);
313
+ return true;
314
+ } catch (err) {
315
+ logger$1.error(err);
316
+ return false;
317
+ }
318
+ }
319
+ const installPrompts = /* @__PURE__ */ new Set();
320
+ function installNuxtModule(name, options) {
321
+ if (installPrompts.has(name))
322
+ return;
323
+ installPrompts.add(name);
324
+ const nuxt = tryUseNuxt();
325
+ if (!nuxt)
326
+ return;
327
+ return promptToInstall(name, async () => {
328
+ const { runCommand } = await import(String("nuxi"));
329
+ await runCommand("module", ["add", name, "--cwd", nuxt.options.rootDir]);
330
+ }, { rootDir: nuxt.options.rootDir, searchPaths: nuxt.options.modulesDir, ...options });
331
+ }
288
332
 
289
333
  const module = defineNuxtModule({
290
334
  meta: {
@@ -318,12 +362,7 @@ const module = defineNuxtModule({
318
362
  resolve("./runtime/composables")
319
363
  ]);
320
364
  nuxt.hooks.hook("modules:done", async () => {
321
- const registry = [
322
- {
323
- name: "useScriptCloudflareTurnstile",
324
- key: "cloudflareTurnstile",
325
- from: resolve("./runtime/registry/cloudflare-turnstile")
326
- },
365
+ let registry = [
327
366
  {
328
367
  name: "useScriptCloudflareWebAnalytics",
329
368
  key: "cloudflareWebAnalytics",
@@ -346,17 +385,8 @@ const module = defineNuxtModule({
346
385
  name: "useScriptFathomAnalytics",
347
386
  key: "fathomAnalytics",
348
387
  from: resolve("./runtime/registry/fathom-analytics"),
349
- src: "https://cdn.usefathom.com/script.js"
350
- },
351
- {
352
- name: "useScriptGoogleAnalytics",
353
- key: "googleAnalytics",
354
- from: resolve("./runtime/registry/google-analytics")
355
- },
356
- {
357
- name: "useScriptGoogleTagManager",
358
- key: "googleTagmanager",
359
- from: resolve("./runtime/registry/google-tag-manager")
388
+ src: false
389
+ // can not be bundled, breaks script
360
390
  },
361
391
  {
362
392
  name: "useScriptHotjar",
@@ -391,16 +421,62 @@ const module = defineNuxtModule({
391
421
  transform(options) {
392
422
  return withBase(options?.file || "", `https://unpkg.com/${options?.packageName || ""}@${options?.version || "latest"}`);
393
423
  }
424
+ },
425
+ // cloudflare turnstile
426
+ {
427
+ name: "useScriptCloudflareTurnstile",
428
+ key: "cloudflareTurnstile",
429
+ from: resolve("./runtime/registry/cloudflare-turnstile"),
430
+ module: "nuxt-turnstile"
431
+ },
432
+ // third-party-capital
433
+ {
434
+ name: "useScriptGoogleAnalytics",
435
+ key: "googleAnalytics",
436
+ from: resolve("./runtime/registry/google-analytics"),
437
+ module: "@nuxt/third-party-capital"
438
+ },
439
+ {
440
+ name: "useScriptGoogleTagManager",
441
+ key: "googleTagManager",
442
+ from: resolve("./runtime/registry/google-tag-manager"),
443
+ module: "@nuxt/third-party-capital"
444
+ },
445
+ {
446
+ name: "useScriptGoogleMaps",
447
+ key: "googleMaps",
448
+ from: resolve("./runtime/registry/google-tag-manager"),
449
+ module: "@nuxt/third-party-capital"
394
450
  }
395
- ].map((i) => {
451
+ ];
452
+ registry = registry.map((i) => {
396
453
  i.priority = -1;
454
+ i.module = i.module || "@nuxt/scripts";
397
455
  return i;
398
456
  });
399
457
  addImports(registry);
400
458
  await nuxt.hooks.callHook("scripts:registry", registry);
459
+ extendTypes(name, async ({ typesPath }) => {
460
+ return `
461
+ declare module '#app' {
462
+ interface NuxtApp {
463
+ ${nuxt.options.dev ? `_scripts: (import('#nuxt-scripts').NuxtAppScript)[]` : ""}
464
+ }
465
+ }
466
+ declare module '#nuxt-scripts' {
467
+ type NuxtUseScriptOptions = Omit<import('${typesPath}').NuxtUseScriptOptions, 'use' | 'beforeInit'>
468
+ interface ScriptRegistry {
469
+ ${registry.filter((i) => i.key && i.module !== "@nuxt/scripts").map((i) => {
470
+ const ucFirstKey = i.key.substring(0, 1).toUpperCase() + i.key.substring(1);
471
+ return ` ${i.key}?: import('${i.from}').${ucFirstKey}Input | [import('${i.from}').${ucFirstKey}Input, NuxtUseScriptOptions]`;
472
+ }).join("\n")}
473
+ }
474
+ }
475
+ `;
476
+ });
401
477
  if (config.globals?.length || Object.keys(config.register || {}).length) {
402
478
  const template = addTemplate({
403
- filename: `modules/${name}.mjs`,
479
+ filename: `modules/${name.replace("/", "-")}.mjs`,
404
480
  write: true,
405
481
  getContents() {
406
482
  const imports = ["useScript", "defineNuxtPlugin"];
@@ -428,9 +504,14 @@ ${(config.globals || []).map((g) => !Array.isArray(g) ? ` useScript("${g.toSt
428
504
  }
429
505
  const scriptMap = /* @__PURE__ */ new Map();
430
506
  const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
507
+ const moduleInstallPromises = /* @__PURE__ */ new Map();
431
508
  addBuildPlugin(NuxtScriptAssetBundlerTransformer({
432
509
  registry,
433
510
  defaultBundle: config.defaultScriptOptions?.assetStrategy === "bundle",
511
+ moduleDetected(module) {
512
+ if (nuxt.options.dev && module !== "@nuxt/scripts" && !moduleInstallPromises.has(module) && !hasNuxtModule(module))
513
+ moduleInstallPromises.set(module, () => installNuxtModule(module));
514
+ },
434
515
  resolveScript(src) {
435
516
  if (scriptMap.has(src))
436
517
  return scriptMap.get(src);
@@ -439,15 +520,11 @@ ${(config.globals || []).map((g) => !Array.isArray(g) ? ` useScript("${g.toSt
439
520
  return url;
440
521
  }
441
522
  }));
442
- });
443
- extendTypes(name, async () => {
444
- return `
445
- declare module '#app' {
446
- interface NuxtApp {
447
- ${nuxt.options.dev ? `_scripts: (import('#nuxt-scripts').NuxtAppScript)[]` : ""}
448
- }
449
- }
450
- `;
523
+ nuxt.hooks.hook("build:done", async () => {
524
+ const initPromise = Array.from(moduleInstallPromises.values());
525
+ for (const p of initPromise)
526
+ await p?.();
527
+ });
451
528
  });
452
529
  if (nuxt.options.dev)
453
530
  setupDevToolsUI(config, resolve);
@@ -1 +1 @@
1
- export declare function useScriptCloudflareTurnstile(): void;
1
+ export declare function useScriptCloudflareTurnstile(): any;
@@ -1,3 +1,4 @@
1
+ import { mockFallbackScript } from "../utils.mjs";
1
2
  export function useScriptCloudflareTurnstile() {
2
- throw new Error("Failed to load Cloudflare Turnstile script. Make sure you have @nuxtjs/turnstile installed and configured.");
3
+ return mockFallbackScript("useScriptCloudflareTurnstile", "nuxt-turnstile");
3
4
  }
@@ -1,5 +1,5 @@
1
1
  import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions } from '#nuxt-scripts';
2
+ import type { NuxtUseScriptIntegrationOptions } from '#nuxt-scripts';
3
3
  export interface CloudflareWebAnalyticsApi {
4
4
  __cfBeacon: {
5
5
  load: 'single';
@@ -30,4 +30,5 @@ export declare const CloudflareWebAnalyticsOptions: import("valibot").ObjectSche
30
30
  token: string;
31
31
  spa?: boolean | undefined;
32
32
  }>;
33
- export declare function useScriptCloudflareWebAnalytics<T extends CloudflareWebAnalyticsApi>(options?: Input<typeof CloudflareWebAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
33
+ export type CloudflareWebAnalyticsInput = Input<typeof CloudflareWebAnalyticsOptions>;
34
+ export declare function useScriptCloudflareWebAnalytics<T extends CloudflareWebAnalyticsApi>(options?: CloudflareWebAnalyticsInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
@@ -20,6 +20,7 @@ export function useScriptCloudflareWebAnalytics(options, _scriptOptions) {
20
20
  const scriptOptions = _scriptOptions || {};
21
21
  scriptOptions.beforeInit = () => {
22
22
  import.meta.dev && validateScriptInputSchema(CloudflareWebAnalyticsOptions, options);
23
+ scriptOptions.beforeInit?.();
23
24
  };
24
25
  return useScript({
25
26
  "src": "https://static.cloudflareinsights.com/beacon.min.js",
@@ -1,6 +1,6 @@
1
1
  import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions } from '#nuxt-scripts';
3
- export interface JSConfettiApi {
2
+ import type { NuxtUseScriptIntegrationOptions } from '#nuxt-scripts';
3
+ export interface ConfettiApi {
4
4
  addConfetti: (options?: {
5
5
  emojis: string[];
6
6
  }) => void;
@@ -8,15 +8,16 @@ export interface JSConfettiApi {
8
8
  declare global {
9
9
  interface Window {
10
10
  JSConfetti: {
11
- new (): JSConfettiApi;
11
+ new (): ConfettiApi;
12
12
  };
13
13
  }
14
14
  }
15
- export declare const JSConfettiOptions: import("valibot").ObjectSchema<Pick<{
15
+ export declare const ConfettiOptions: import("valibot").ObjectSchema<Pick<{
16
16
  packageName: import("valibot").StringSchema<string>;
17
17
  file: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
18
18
  version: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
19
19
  }, "version">, undefined, {
20
20
  version?: string | undefined;
21
21
  }>;
22
- export declare function useScriptConfetti<T extends JSConfettiApi>(options: Input<typeof JSConfettiOptions>, _scriptOptions?: NuxtUseScriptOptions<T>): any;
22
+ export type ConfettiInput = Input<typeof ConfettiOptions>;
23
+ export declare function useScriptConfetti(options: ConfettiInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
@@ -1,6 +1,6 @@
1
1
  import { pick } from "valibot";
2
2
  import { NpmOptions, useScriptNpm } from "./npm.mjs";
3
- export const JSConfettiOptions = pick(NpmOptions, ["version"]);
3
+ export const ConfettiOptions = pick(NpmOptions, ["version"]);
4
4
  export function useScriptConfetti(options, _scriptOptions = {}) {
5
5
  return useScriptNpm({
6
6
  packageName: "js-confetti",
@@ -1,5 +1,5 @@
1
1
  import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions } from '#nuxt-scripts';
2
+ import type { NuxtUseScriptIntegrationOptions } from '#nuxt-scripts';
3
3
  type StandardEvents = 'AddPaymentInfo' | 'AddToCart' | 'AddToWishlist' | 'CompleteRegistration' | 'Contact' | 'CustomizeProduct' | 'Donate' | 'FindLocation' | 'InitiateCheckout' | 'Lead' | 'Purchase' | 'Schedule' | 'Search' | 'StartTrial' | 'SubmitApplication' | 'Subscribe' | 'ViewContent';
4
4
  interface EventObjectProperties {
5
5
  content_category?: string;
@@ -38,5 +38,6 @@ export declare const FacebookPixelOptions: import("valibot").ObjectSchema<{
38
38
  }, undefined, {
39
39
  id: string | number;
40
40
  }>;
41
- export declare function useScriptFacebookPixel<T extends FacebookPixelApi>(options?: Input<typeof FacebookPixelOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
41
+ export type FacebookPixelInput = Input<typeof FacebookPixelOptions>;
42
+ export declare function useScriptFacebookPixel<T extends FacebookPixelApi>(options?: FacebookPixelInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
42
43
  export {};
@@ -20,6 +20,7 @@ export function useScriptFacebookPixel(options, _scriptOptions) {
20
20
  fbq("init", options?.id);
21
21
  fbq("track", "PageView");
22
22
  }
23
+ scriptOptions.beforeInit?.();
23
24
  };
24
25
  return useScript({
25
26
  key: "facebookPixel",
@@ -1,5 +1,5 @@
1
1
  import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions } from '#nuxt-scripts';
2
+ import type { NuxtUseScriptIntegrationOptions } from '#nuxt-scripts';
3
3
  export declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
4
4
  site: import("valibot").StringSchema<string>;
5
5
  src: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
@@ -15,6 +15,7 @@ export declare const FathomAnalyticsOptions: import("valibot").ObjectSchema<{
15
15
  'data-canonical'?: boolean | undefined;
16
16
  'data-honor-dnt'?: boolean | undefined;
17
17
  }>;
18
+ export type FathomAnalyticsInput = Input<typeof FathomAnalyticsOptions>;
18
19
  export interface FathomAnalyticsApi {
19
20
  trackPageview: (ctx?: {
20
21
  url: string;
@@ -29,4 +30,4 @@ declare global {
29
30
  fathom: FathomAnalyticsApi;
30
31
  }
31
32
  }
32
- export declare function useScriptFathomAnalytics<T extends FathomAnalyticsApi>(options?: Input<typeof FathomAnalyticsOptions>, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
33
+ export declare function useScriptFathomAnalytics<T extends FathomAnalyticsApi>(options?: FathomAnalyticsInput, _scriptOptions?: Omit<NuxtUseScriptIntegrationOptions, 'assetStrategy'>): any;
@@ -13,6 +13,7 @@ export function useScriptFathomAnalytics(options, _scriptOptions) {
13
13
  const scriptOptions = _scriptOptions || {};
14
14
  scriptOptions.beforeInit = () => {
15
15
  import.meta.dev && validateScriptInputSchema(FathomAnalyticsOptions, options);
16
+ scriptOptions.beforeInit?.();
16
17
  };
17
18
  return useScript({
18
19
  src: "https://cdn.usefathom.com/script.js",
@@ -1 +1 @@
1
- export declare function useScriptGoogleAnalytics(): void;
1
+ export declare function useScriptGoogleAnalytics(): any;
@@ -1,3 +1,4 @@
1
+ import { mockFallbackScript } from "../utils.mjs";
1
2
  export function useScriptGoogleAnalytics() {
2
- throw new Error("Failed to load Google Analytics script. Make sure you have @nuxtjs/third-party-capital installed and configured.");
3
+ return mockFallbackScript("useScriptGoogleMaps", "@nuxtjs/third-party-capital");
3
4
  }
@@ -0,0 +1 @@
1
+ export declare function useScriptGoogleMaps(): any;
@@ -0,0 +1,4 @@
1
+ import { mockFallbackScript } from "../utils.mjs";
2
+ export function useScriptGoogleMaps() {
3
+ return mockFallbackScript("useScriptGoogleMaps", "@nuxtjs/third-party-capital");
4
+ }
@@ -1 +1 @@
1
- export declare function useScriptGoogleTagManager(): void;
1
+ export declare function useScriptGoogleTagManager(): any;
@@ -1,3 +1,4 @@
1
+ import { mockFallbackScript } from "../utils.mjs";
1
2
  export function useScriptGoogleTagManager() {
2
- throw new Error("Failed to load Google Tag Manager script. Make sure you have @nuxtjs/third-party-capital installed and configured.");
3
+ return mockFallbackScript("useScriptGoogleTagManager", "@nuxtjs/third-party-capital");
3
4
  }
@@ -1,4 +1,4 @@
1
- import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
1
+ import type { NuxtUseScriptIntegrationOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
2
2
  export interface HotjarApi {
3
3
  hj: ((event: 'identify', userId: string, attributes?: Record<string, any>) => void) & ((event: 'stateChange', path: string) => void) & ((event: 'event', eventName: string) => void) & ((event: string, arg?: string) => void) & ((...params: any[]) => void) & {
4
4
  q: any[];
@@ -20,4 +20,4 @@ export declare const HotjarOptions: import("valibot").ObjectSchema<{
20
20
  sv?: number | undefined;
21
21
  }>;
22
22
  export type HotjarInput = ScriptDynamicSrcInput<typeof HotjarOptions>;
23
- export declare function useScriptHotjar<T extends HotjarApi>(options?: HotjarInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'assetStrategy' | 'beforeInit' | 'use'>): any;
23
+ export declare function useScriptHotjar<T extends HotjarApi>(options?: HotjarInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
@@ -14,6 +14,7 @@ export function useScriptHotjar(options, _scriptOptions) {
14
14
  (window.hj.q = window.hj.q || []).push(params);
15
15
  };
16
16
  }
17
+ scriptOptions.beforeInit?.();
17
18
  };
18
19
  return useScript({
19
20
  key: "hotjar",
@@ -1,5 +1,5 @@
1
1
  import { type Input } from 'valibot';
2
- import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
2
+ import type { NuxtUseScriptIntegrationOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
3
3
  export declare const IntercomOptions: import("valibot").ObjectSchema<{
4
4
  app_id: import("valibot").StringSchema<string>;
5
5
  api_base: import("valibot").OptionalSchema<import("valibot").UnionSchema<(import("valibot").LiteralSchema<"https://api-iam.intercom.io", "https://api-iam.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.eu.intercom.io", "https://api-iam.eu.intercom.io"> | import("valibot").LiteralSchema<"https://api-iam.au.intercom.io", "https://api-iam.au.intercom.io">)[], "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io">, undefined, "https://api-iam.intercom.io" | "https://api-iam.eu.intercom.io" | "https://api-iam.au.intercom.io" | undefined>;
@@ -28,4 +28,4 @@ declare global {
28
28
  intercomSettings?: IntercomInput;
29
29
  }
30
30
  }
31
- export declare function useScriptIntercom<T extends IntercomApi>(options?: IntercomInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
31
+ export declare function useScriptIntercom<T extends IntercomApi>(options?: IntercomInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
@@ -18,6 +18,7 @@ export function useScriptIntercom(options, _scriptOptions) {
18
18
  import.meta.dev && validateScriptInputSchema(IntercomOptions, options);
19
19
  if (import.meta.client)
20
20
  window.intercomSettings = options;
21
+ scriptOptions.beforeInit?.();
21
22
  };
22
23
  return useScript({
23
24
  key: "intercom",
@@ -1,4 +1,4 @@
1
- import type { NuxtUseScriptOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
1
+ import type { NuxtUseScriptIntegrationOptions, ScriptDynamicSrcInput } from '#nuxt-scripts';
2
2
  export declare const SegmentOptions: import("valibot").ObjectSchema<{
3
3
  writeKey: import("valibot").StringSchema<string>;
4
4
  analyticsKey: import("valibot").OptionalSchema<import("valibot").StringSchema<string>, undefined, string | undefined>;
@@ -21,4 +21,4 @@ declare global {
21
21
  interface Window extends SegmentApi {
22
22
  }
23
23
  }
24
- export declare function useScriptSegment<T extends SegmentApi>(options?: SegmentInput, _scriptOptions?: Omit<NuxtUseScriptOptions<T>, 'beforeInit' | 'use'>): any;
24
+ export declare function useScriptSegment<T extends SegmentApi>(options?: SegmentInput, _scriptOptions?: NuxtUseScriptIntegrationOptions): any;
@@ -25,6 +25,7 @@ export function useScriptSegment(options, _scriptOptions) {
25
25
  }
26
26
  window.analytics.page();
27
27
  }
28
+ scriptOptions.beforeInit?.();
28
29
  };
29
30
  const analyticsKey = options?.analyticsKey || "analytics";
30
31
  return useScript({
@@ -3,12 +3,13 @@ import type { UseScriptInput, VueScriptInstance } from '@unhead/vue';
3
3
  import type { ComputedRef, Ref } from 'vue';
4
4
  import type { Input, ObjectSchema } from 'valibot';
5
5
  import type { Import } from 'unimport';
6
- import type { SegmentOptions } from './registry/segment';
7
- import type { CloudflareWebAnalyticsOptions } from './registry/cloudflare-web-analytics';
8
- import type { FacebookPixelOptions } from './registry/facebook-pixel';
9
- import type { FathomAnalyticsOptions } from './registry/fathom-analytics';
10
- import type { HotjarOptions } from './registry/hotjar';
11
- import type { IntercomOptions } from './registry/intercom';
6
+ import type { SegmentInput } from './registry/segment';
7
+ import type { CloudflareWebAnalyticsInput } from './registry/cloudflare-web-analytics';
8
+ import type { FacebookPixelInput } from './registry/facebook-pixel';
9
+ import type { FathomAnalyticsInput } from './registry/fathom-analytics';
10
+ import type { HotjarInput } from './registry/hotjar';
11
+ import type { IntercomInput } from './registry/intercom';
12
+ import type { ConfettiInput } from './registry/confetti';
12
13
  export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'> & {
13
14
  /**
14
15
  * The trigger to load the script:
@@ -30,6 +31,7 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
30
31
  */
31
32
  beforeInit?: () => void;
32
33
  };
34
+ export type NuxtUseScriptIntegrationOptions = Omit<NuxtUseScriptOptions, 'use'>;
33
35
  export type NuxtUseScriptInput = UseScriptInput;
34
36
  export interface TrackedPage {
35
37
  title?: string;
@@ -60,21 +62,22 @@ export interface NuxtAppScript {
60
62
  at: number;
61
63
  }[];
62
64
  }
63
- export type ScriptRegistryEntry<T extends ObjectSchema<any>> = Input<T> | [Input<T>, NuxtUseScriptOptions<T>];
65
+ export type ScriptRegistryEntry<T> = T | [T, NuxtUseScriptOptions<T>];
64
66
  export interface ScriptRegistry {
65
- cloudflareWebAnalytics?: ScriptRegistryEntry<typeof CloudflareWebAnalyticsOptions>;
66
- confetti?: ScriptRegistryEntry<typeof CloudflareWebAnalyticsOptions>;
67
- facebookPixel?: ScriptRegistryEntry<typeof FacebookPixelOptions>;
68
- fathomAnalytics?: ScriptRegistryEntry<typeof FathomAnalyticsOptions>;
69
- hotjar?: ScriptRegistryEntry<typeof HotjarOptions>;
70
- segment?: ScriptRegistryEntry<typeof SegmentOptions>;
71
- intercom?: ScriptRegistryEntry<typeof IntercomOptions>;
67
+ cloudflareWebAnalytics?: ScriptRegistryEntry<CloudflareWebAnalyticsInput>;
68
+ confetti?: ScriptRegistryEntry<ConfettiInput>;
69
+ facebookPixel?: ScriptRegistryEntry<FacebookPixelInput>;
70
+ fathomAnalytics?: ScriptRegistryEntry<FathomAnalyticsInput>;
71
+ hotjar?: ScriptRegistryEntry<HotjarInput>;
72
+ intercom?: ScriptRegistryEntry<IntercomInput>;
73
+ segment?: ScriptRegistryEntry<SegmentInput>;
72
74
  }
73
75
  export type ScriptDynamicSrcInput<T extends ObjectSchema<any>> = Input<T> & {
74
76
  src?: string;
75
77
  };
76
78
  export type RegistryScripts = (Import & {
77
- src?: string;
79
+ src?: string | false;
80
+ module?: '@nuxt/scripts' | string;
78
81
  key?: string;
79
82
  transform?: (options: any) => string;
80
83
  })[];
@@ -0,0 +1 @@
1
+ export declare function mockFallbackScript(name: string, module: string): any;
@@ -0,0 +1,5 @@
1
+ import { useScript } from "#imports";
2
+ export function mockFallbackScript(name, module) {
3
+ console.error(`${name} is provided by ${module}. Check your console to install it or run 'npx nuxi@latest module add ${module}'`);
4
+ return useScript("", { trigger: "manual" });
5
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@nuxt/scripts",
3
3
  "type": "module",
4
- "version": "0.1.9",
4
+ "version": "0.1.11",
5
5
  "packageManager": "pnpm@8.15.6",
6
6
  "description": "Next-gen Scripts for Nuxt",
7
7
  "author": {
@@ -53,6 +53,7 @@
53
53
  "pkg-types": "^1.0.3",
54
54
  "shiki": "^1.2.3",
55
55
  "sirv": "^2.0.4",
56
+ "std-env": "^3.7.0",
56
57
  "ufo": "^1.5.3",
57
58
  "unimport": "^3.7.1",
58
59
  "unplugin": "^1.10.1",
@@ -1 +0,0 @@
1
- {"id":"5fdc85c0-58a5-4956-bedd-f94dc9ec3924","timestamp":1712059997492,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}