@nuxt/scripts 0.6.4 → 0.6.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.
Files changed (66) hide show
  1. package/README.md +73 -73
  2. package/dist/client/200.html +9 -9
  3. package/dist/client/404.html +9 -9
  4. package/dist/client/_nuxt/{DX8FDaDx.js → BKIFFtfV.js} +1 -1
  5. package/dist/client/_nuxt/{DUCgB8kF.js → BKJqCZ0j.js} +1 -1
  6. package/dist/client/_nuxt/DcF05ETD.js +31 -0
  7. package/dist/client/_nuxt/aQeyjCqJ.js +1 -0
  8. package/dist/client/_nuxt/builds/latest.json +1 -1
  9. package/dist/client/_nuxt/builds/meta/3dcaf2bf-82f1-460f-80a6-1412196a7a77.json +1 -0
  10. package/dist/client/_nuxt/entry.FVeyw1Qn.css +1 -0
  11. package/dist/client/_nuxt/error-404.B7Lh29wY.css +1 -0
  12. package/dist/client/_nuxt/error-500.B_VIyt60.css +1 -0
  13. package/dist/client/index.html +9 -9
  14. package/dist/module.d.mts +2 -10
  15. package/dist/module.d.ts +2 -10
  16. package/dist/module.json +1 -1
  17. package/dist/module.mjs +3 -0
  18. package/dist/registry.mjs +2 -2
  19. package/dist/runtime/components/ScriptCarbonAds.vue +71 -71
  20. package/dist/runtime/components/ScriptCrisp.vue +84 -84
  21. package/dist/runtime/components/ScriptGoogleAdsense.vue +69 -69
  22. package/dist/runtime/components/ScriptGoogleMaps.vue +267 -265
  23. package/dist/runtime/components/ScriptIntercom.vue +93 -93
  24. package/dist/runtime/components/ScriptLemonSqueezy.vue +45 -45
  25. package/dist/runtime/components/ScriptLoadingIndicator.vue +22 -22
  26. package/dist/runtime/components/ScriptStripePricingTable.vue +68 -68
  27. package/dist/runtime/components/ScriptVimeoPlayer.vue +258 -256
  28. package/dist/runtime/components/ScriptYouTubePlayer.vue +171 -170
  29. package/dist/runtime/composables/useScript.js +2 -2
  30. package/dist/runtime/composables/useScriptEventPage.d.ts +4 -1
  31. package/dist/runtime/composables/useScriptEventPage.js +6 -5
  32. package/dist/runtime/registry/clarity.js +1 -1
  33. package/dist/runtime/registry/cloudflare-web-analytics.js +1 -1
  34. package/dist/runtime/registry/crisp.js +1 -1
  35. package/dist/runtime/registry/fathom-analytics.js +1 -1
  36. package/dist/runtime/registry/google-adsense.js +1 -1
  37. package/dist/runtime/registry/google-analytics.d.ts +13 -7
  38. package/dist/runtime/registry/google-analytics.js +25 -13
  39. package/dist/runtime/registry/google-maps.js +1 -1
  40. package/dist/runtime/registry/google-tag-manager.d.ts +16 -6
  41. package/dist/runtime/registry/google-tag-manager.js +16 -10
  42. package/dist/runtime/registry/hotjar.js +1 -1
  43. package/dist/runtime/registry/intercom.js +1 -1
  44. package/dist/runtime/registry/lemon-squeezy.js +1 -1
  45. package/dist/runtime/registry/matomo-analytics.js +7 -3
  46. package/dist/runtime/registry/meta-pixel.d.ts +1 -0
  47. package/dist/runtime/registry/meta-pixel.js +6 -2
  48. package/dist/runtime/registry/npm.js +1 -1
  49. package/dist/runtime/registry/plausible-analytics.js +1 -1
  50. package/dist/runtime/registry/segment.d.ts +1 -2
  51. package/dist/runtime/registry/segment.js +1 -1
  52. package/dist/runtime/registry/stripe.js +1 -1
  53. package/dist/runtime/registry/vimeo-player.js +1 -1
  54. package/dist/runtime/registry/x-pixel.js +7 -3
  55. package/dist/runtime/registry/youtube-player.js +1 -1
  56. package/dist/runtime/types.d.ts +20 -4
  57. package/dist/runtime/types.js +1 -1
  58. package/dist/runtime/utils.d.ts +1 -1
  59. package/dist/runtime/utils.js +16 -4
  60. package/package.json +30 -32
  61. package/dist/client/_nuxt/B8kiEHWd.js +0 -31
  62. package/dist/client/_nuxt/CE8XWCBP.js +0 -1
  63. package/dist/client/_nuxt/builds/meta/a56fe5f5-907d-4907-9967-836d6a0f3850.json +0 -1
  64. package/dist/client/_nuxt/entry.DvGwvmL9.css +0 -1
  65. package/dist/client/_nuxt/error-404.-RjlvToe.css +0 -1
  66. package/dist/client/_nuxt/error-500.Bz7LXgZy.css +0 -1
@@ -9,7 +9,7 @@ export const MatomoAnalyticsOptions = object({
9
9
  enableLinkTracking: optional(boolean())
10
10
  });
11
11
  export function useScriptMatomoAnalytics(_options) {
12
- return useRegistryScript(_options?.key || "matomoAnalytics", (options) => ({
12
+ return useRegistryScript("matomoAnalytics", (options) => ({
13
13
  scriptInput: {
14
14
  src: withBase(`/matomo.js`, withHttps(options?.matomoUrl)),
15
15
  crossorigin: false
@@ -26,8 +26,12 @@ export function useScriptMatomoAnalytics(_options) {
26
26
  },
27
27
  clientInit: import.meta.server ? void 0 : () => {
28
28
  const _paq = window._paq = window._paq || [];
29
- options?.trackPageView !== false && _paq.push(["trackPageView"]);
30
- options?.enableLinkTracking !== false && _paq.push(["enableLinkTracking"]);
29
+ if (options?.trackPageView) {
30
+ _paq.push(["trackPageView"]);
31
+ }
32
+ if (options?.enableLinkTracking) {
33
+ _paq.push(["enableLinkTracking"]);
34
+ }
31
35
  _paq.push(["setTrackerUrl", withBase(`/matomo.php`, withHttps(options?.matomoUrl))]);
32
36
  _paq.push(["setSiteId", options?.siteId || "1"]);
33
37
  }
@@ -27,6 +27,7 @@ export interface MetaPixelApi {
27
27
  queue: any[];
28
28
  };
29
29
  _fbq: MetaPixelApi['fbq'];
30
+ callMethod?: FbqFns;
30
31
  }
31
32
  declare global {
32
33
  interface Window extends MetaPixelApi {
@@ -4,7 +4,7 @@ export const MetaPixelOptions = object({
4
4
  id: union([string(), number()])
5
5
  });
6
6
  export function useScriptMetaPixel(_options) {
7
- return useRegistryScript(_options?.key || "metaPixel", (options) => ({
7
+ return useRegistryScript("metaPixel", (options) => ({
8
8
  scriptInput: {
9
9
  src: "https://connect.facebook.net/en_US/fbevents.js",
10
10
  crossorigin: false
@@ -17,7 +17,11 @@ export function useScriptMetaPixel(_options) {
17
17
  },
18
18
  clientInit: import.meta.server ? void 0 : () => {
19
19
  const fbq = window.fbq = function(...params) {
20
- fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params);
20
+ if (fbq.callMethod) {
21
+ fbq.callMethod(...params);
22
+ } else {
23
+ fbq.queue.push(params);
24
+ }
21
25
  };
22
26
  if (!window._fbq)
23
27
  window._fbq = fbq;
@@ -8,7 +8,7 @@ export const NpmOptions = object({
8
8
  type: optional(string())
9
9
  });
10
10
  export function useScriptNpm(_options) {
11
- return useRegistryScript(_options?.key || `${_options.packageName}-npm`, (options) => ({
11
+ return useRegistryScript(`${_options.packageName}-npm`, (options) => ({
12
12
  scriptInput: {
13
13
  src: withBase(options.file || "", `https://unpkg.com/${options?.packageName}@${options.version || "latest"}`)
14
14
  },
@@ -17,7 +17,7 @@ export const PlausibleAnalyticsOptions = object({
17
17
  extension: optional(union([union(extensions), array(union(extensions))]))
18
18
  });
19
19
  export function useScriptPlausibleAnalytics(_options) {
20
- return useRegistryScript(_options?.key || "plausibleAnalytics", (options) => {
20
+ return useRegistryScript("plausibleAnalytics", (options) => {
21
21
  const extensions2 = Array.isArray(options?.extension) ? options.extension.join(".") : [options?.extension];
22
22
  return {
23
23
  scriptInput: {
@@ -24,8 +24,7 @@ interface AnalyticsApi {
24
24
  */
25
25
  push: (args: any[]) => void;
26
26
  }
27
- export interface SegmentApi extends Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'> {
28
- }
27
+ export type SegmentApi = Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'>;
29
28
  declare global {
30
29
  interface Window extends SegmentApi {
31
30
  }
@@ -7,7 +7,7 @@ export const SegmentOptions = object({
7
7
  });
8
8
  const methods = ["track", "page", "identify", "group", "alias", "reset"];
9
9
  export function useScriptSegment(_options) {
10
- return useRegistryScript(_options?.key || "segment", (options) => {
10
+ return useRegistryScript("segment", (options) => {
11
11
  const k = options?.analyticsKey ?? "analytics";
12
12
  return {
13
13
  scriptInput: {
@@ -5,7 +5,7 @@ export const StripeOptions = object({
5
5
  advancedFraudSignals: optional(boolean())
6
6
  });
7
7
  export function useScriptStripe(_options) {
8
- return useRegistryScript(_options?.key || "stripe", (options) => ({
8
+ return useRegistryScript("stripe", (options) => ({
9
9
  scriptInput: {
10
10
  src: withQuery(
11
11
  `https://js.stripe.com/v3/`,
@@ -2,7 +2,7 @@ import { watch } from "vue";
2
2
  import { useRegistryScript } from "../utils.js";
3
3
  import { useHead } from "#imports";
4
4
  export function useScriptVimeoPlayer(_options) {
5
- const instance = useRegistryScript(_options?.key || "vimeoPlayer", () => ({
5
+ const instance = useRegistryScript("vimeoPlayer", () => ({
6
6
  scriptInput: {
7
7
  src: "https://player.vimeo.com/api/player.js"
8
8
  },
@@ -5,15 +5,19 @@ export const XPixelOptions = object({
5
5
  version: optional(string())
6
6
  });
7
7
  export function useScriptXPixel(_options) {
8
- return useRegistryScript(_options?.key || "xPixel", (options) => {
8
+ return useRegistryScript("xPixel", (options) => {
9
9
  return {
10
10
  scriptInput: {
11
11
  src: "https://static.ads-twitter.com/uwt.js",
12
12
  crossorigin: false
13
13
  },
14
14
  clientInit: import.meta.server ? void 0 : () => {
15
- const s = window.twq = function() {
16
- s.exe ? s.exe(s, arguments) : s.queue.push(arguments);
15
+ const s = window.twq = function(...args) {
16
+ if (e.exe) {
17
+ s.exe(s, args);
18
+ } else {
19
+ s.queue.push(args);
20
+ }
17
21
  };
18
22
  s.version = options?.version || "1.1";
19
23
  s.queue = [
@@ -3,7 +3,7 @@ import { useRegistryScript } from "../utils.js";
3
3
  import { useHead } from "#imports";
4
4
  export function useScriptYouTubePlayer(_options) {
5
5
  let readyPromise = Promise.resolve();
6
- const instance = useRegistryScript(_options?.key || "youtubePlayer", () => ({
6
+ const instance = useRegistryScript("youtubePlayer", () => ({
7
7
  scriptInput: {
8
8
  src: "https://www.youtube.com/iframe_api",
9
9
  crossorigin: false
@@ -48,6 +48,21 @@ export type NuxtUseScriptOptions<T = any> = Omit<UseScriptOptions<T>, 'trigger'>
48
48
  * @internal
49
49
  */
50
50
  performanceMarkFeature?: string;
51
+ /**
52
+ * @internal
53
+ */
54
+ devtools?: {
55
+ /**
56
+ * Key used to map to the registry script for Nuxt DevTools.
57
+ * @internal
58
+ */
59
+ registryKey?: string;
60
+ /**
61
+ * Extra metadata to show with the registry script
62
+ * @internal
63
+ */
64
+ registryMeta?: Record<string, string>;
65
+ };
51
66
  };
52
67
  export type NuxtUseScriptOptionsSerializable = Omit<NuxtUseScriptOptions, 'use' | 'skipValidation' | 'stub' | 'trigger' | 'eventContext' | 'beforeInit'> & {
53
68
  trigger?: 'client' | 'server' | 'onNuxtReady';
@@ -69,8 +84,9 @@ export interface ConsentScriptTriggerOptions {
69
84
  */
70
85
  postConsentTrigger?: NuxtUseScriptOptions['trigger'];
71
86
  }
72
- export interface NuxtAppScript {
73
- key: string;
87
+ export interface NuxtDevToolsScriptInstance {
88
+ registryKey?: string;
89
+ registryMeta?: Record<string, string>;
74
90
  src: string;
75
91
  $script: VueScriptInstance<any>;
76
92
  events: {
@@ -108,8 +124,8 @@ export type NuxtConfigScriptRegistryEntry<T> = true | 'mock' | T | [T, NuxtUseSc
108
124
  export type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof ScriptRegistry> = Partial<{
109
125
  [key in T]: NuxtConfigScriptRegistryEntry<ScriptRegistry[key]>;
110
126
  }>;
111
- declare const emptyOptions: ObjectSchema<{}, undefined>;
112
- export type EmptyOptionsSchema = typeof emptyOptions;
127
+ declare const _emptyOptions: ObjectSchema<{}, undefined>;
128
+ export type EmptyOptionsSchema = typeof _emptyOptions;
113
129
  type ScriptInput = ScriptBase & DataKeys & SchemaAugmentations['script'];
114
130
  export type RegistryScriptInput<T extends ObjectSchema<any, any> = EmptyOptionsSchema, Bundelable extends boolean = true, Usable extends boolean = false, CanBypassOptions extends boolean = true> = (InferInput<T> & {
115
131
  /**
@@ -1,2 +1,2 @@
1
1
  import { object } from "valibot";
2
- const emptyOptions = object({});
2
+ const _emptyOptions = object({});
@@ -8,7 +8,7 @@ type OptionsFn<O extends ObjectSchema<any, any>> = (options: InferInput<O>) => (
8
8
  clientInit?: () => void;
9
9
  });
10
10
  export declare function scriptRuntimeConfig<T extends keyof ScriptRegistry>(key: T): ScriptRegistry[T];
11
- export declare function useRegistryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any, any> = EmptyOptionsSchema>(key: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
11
+ export declare function useRegistryScript<T extends Record<string | symbol, any>, O extends ObjectSchema<any, any> = EmptyOptionsSchema>(registryKey: keyof ScriptRegistry | string, optionsFn: OptionsFn<O>, _userOptions?: RegistryScriptInput<O>): T & {
12
12
  $script: Promise<T> & VueScriptInstance<T>;
13
13
  };
14
14
  export {};
@@ -15,17 +15,29 @@ function validateScriptInputSchema(key, schema, options) {
15
15
  export function scriptRuntimeConfig(key) {
16
16
  return (useRuntimeConfig().public.scripts || {})[key];
17
17
  }
18
- export function useRegistryScript(key, optionsFn, _userOptions) {
19
- const scriptConfig = scriptRuntimeConfig(key);
18
+ export function useRegistryScript(registryKey, optionsFn, _userOptions) {
19
+ const scriptConfig = scriptRuntimeConfig(registryKey);
20
20
  const userOptions = Object.assign(_userOptions || {}, typeof scriptConfig === "object" ? scriptConfig : {});
21
21
  const options = optionsFn(userOptions);
22
- const scriptInput = defu(userOptions.scriptInput, options.scriptInput, { key });
22
+ const scriptInput = defu(userOptions.scriptInput, options.scriptInput, { key: registryKey });
23
23
  const scriptOptions = Object.assign(userOptions?.scriptOptions || {}, options.scriptOptions || {});
24
+ if (import.meta.dev) {
25
+ scriptOptions.devtools = defu(scriptOptions.devtools, { registryKey });
26
+ if (options.schema) {
27
+ const registryMeta = {};
28
+ for (const k in options.schema.entries) {
29
+ if (options.schema.entries[k].type !== "optional") {
30
+ registryMeta[k] = String(userOptions[k]);
31
+ }
32
+ }
33
+ scriptOptions.devtools.registryMeta = registryMeta;
34
+ }
35
+ }
24
36
  const init = scriptOptions.beforeInit;
25
37
  scriptOptions.beforeInit = () => {
26
38
  if (import.meta.dev && !scriptOptions.skipValidation && options.schema) {
27
39
  if (!userOptions.scriptInput?.src) {
28
- validateScriptInputSchema(key, options.schema, userOptions);
40
+ validateScriptInputSchema(registryKey, options.schema, userOptions);
29
41
  }
30
42
  }
31
43
  init?.();
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@nuxt/scripts",
3
3
  "type": "module",
4
- "version": "0.6.4",
5
- "packageManager": "pnpm@9.5.0",
4
+ "version": "0.6.6",
5
+ "packageManager": "pnpm@9.6.0",
6
6
  "description": "Load third-party scripts with better performance, privacy and DX in Nuxt Apps.",
7
7
  "author": {
8
8
  "website": "https://harlanzw.com",
@@ -35,7 +35,7 @@
35
35
  "dist"
36
36
  ],
37
37
  "scripts": {
38
- "build": "pnpm prepack",
38
+ "build": "pnpm dev:prepare && pnpm prepack",
39
39
  "client:build": "nuxi generate client",
40
40
  "client:dev": "nuxi dev client --port 3300",
41
41
  "prepack": "nuxt-module-build build && npm run client:build",
@@ -48,15 +48,13 @@
48
48
  "lint": "eslint .",
49
49
  "lint:fix": "eslint . --fix",
50
50
  "test": "vitest",
51
- "test:types": "npx nuxi typecheck",
51
+ "test:types": "echo 'broken due to type regeneration, use pnpm typecheck' && npx nuxi typecheck",
52
52
  "script:generate-tpc": "bun ./scripts/generateTpcScripts.ts && pnpm lint:fix"
53
53
  },
54
54
  "build": {
55
55
  "externals": [
56
56
  "@unhead/vue",
57
57
  "@unhead/schema",
58
- "#nuxt-scripts",
59
- "#nuxt-scripts-validator",
60
58
  "third-party-capital",
61
59
  "knitwork",
62
60
  "estree-walker",
@@ -69,8 +67,8 @@
69
67
  "dependencies": {
70
68
  "@nuxt/devtools-kit": "^1.3.9",
71
69
  "@nuxt/devtools-ui-kit": "^1.3.9",
72
- "@nuxt/kit": "^3.12.3",
73
- "@types/google.maps": "^3.55.11",
70
+ "@nuxt/kit": "^3.12.4",
71
+ "@types/google.maps": "^3.55.12",
74
72
  "@types/stripe-v3": "^3.1.33",
75
73
  "@types/vimeo__player": "^2.18.3",
76
74
  "@types/youtube": "^0.0.50",
@@ -79,51 +77,51 @@
79
77
  "consola": "^3.2.3",
80
78
  "defu": "^6.1.4",
81
79
  "h3": "^1.12.0",
82
- "magic-string": "^0.30.10",
80
+ "magic-string": "^0.30.11",
83
81
  "mlly": "^1.7.1",
84
82
  "ofetch": "^1.3.4",
85
83
  "ohash": "^1.1.3",
86
84
  "pathe": "^1.1.2",
87
85
  "pkg-types": "^1.1.3",
88
- "semver": "^7.6.2",
89
- "shiki": "^1.10.3",
86
+ "semver": "^7.6.3",
87
+ "shiki": "1.12.1",
90
88
  "sirv": "^2.0.4",
91
89
  "std-env": "^3.7.0",
92
- "third-party-capital": "^1.0.31",
93
- "ufo": "^1.5.3",
94
- "unimport": "^3.7.2",
95
- "unplugin": "^1.11.0",
90
+ "third-party-capital": "2.3.0",
91
+ "ufo": "^1.5.4",
92
+ "unimport": "^3.10.0",
93
+ "unplugin": "^1.12.0",
96
94
  "unstorage": "^1.10.2",
97
- "valibot": "^0.36.0"
95
+ "valibot": "^0.37.0"
98
96
  },
99
97
  "devDependencies": {
100
98
  "@nuxt/devtools-ui-kit": "^1.3.9",
101
- "@nuxt/eslint-config": "^0.3.13",
99
+ "@nuxt/eslint-config": "^0.5.0",
102
100
  "@nuxt/module-builder": "^0.8.1",
103
- "@nuxt/test-utils": "3.13.1",
101
+ "@nuxt/test-utils": "3.14.0",
104
102
  "@types/semver": "^7.5.8",
105
- "@typescript-eslint/typescript-estree": "^7.16.0",
103
+ "@typescript-eslint/typescript-estree": "^8.0.1",
106
104
  "@unhead/schema": "^1.9.16",
107
105
  "acorn-loose": "^8.4.0",
108
- "bumpp": "^9.4.1",
106
+ "bumpp": "^9.4.2",
109
107
  "changelogen": "^0.5.5",
110
- "eslint": "9.7.0",
111
- "eslint-plugin-n": "^17.9.0",
108
+ "eslint": "9.8.0",
109
+ "eslint-plugin-n": "^17.10.2",
112
110
  "knitwork": "^1.1.0",
113
- "nuxt": "^3.12.3",
111
+ "nuxt": "^3.12.4",
114
112
  "nuxt-scripts-devtools": "workspace:*",
115
- "playwright-core": "^1.45.1",
116
- "typescript": "^5.5.3",
117
- "vitest": "^2.0.2",
118
- "vue": "^3.4.31",
119
- "vue-router": "^4.4.0"
113
+ "playwright-core": "^1.46.0",
114
+ "typescript": "^5.5.4",
115
+ "vitest": "^2.0.5",
116
+ "vue": "^3.4.35",
117
+ "vue-router": "^4.4.2"
120
118
  },
121
119
  "resolutions": {
122
120
  "@nuxt/scripts": "workspace:*",
123
- "nuxt": "^3.12.3",
121
+ "nuxt": "^3.12.4",
124
122
  "nuxt-scripts-devtools": "workspace:*",
125
- "vue": "^3.4.31",
126
- "vue-router": "^4.4.0",
127
- "shiki": "1.10.3"
123
+ "shiki": "1.10.3",
124
+ "vue": "^3.4.35",
125
+ "vue-router": "^4.4.2"
128
126
  }
129
127
  }