@nuxt/scripts 0.1.12 → 0.3.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.
Files changed (151) hide show
  1. package/README.md +10 -200
  2. package/dist/client/200.html +63 -54
  3. package/dist/client/404.html +63 -54
  4. package/dist/client/_nuxt/8T3kBMJO.js +31 -0
  5. package/dist/client/_nuxt/B5NHDIr7.js +353 -0
  6. package/dist/client/_nuxt/{Bz4xi2rU.js → B6ZnTe72.js} +1 -1
  7. package/dist/client/_nuxt/{B6nY7VDA.js → B6bHXiXE.js} +1 -1
  8. package/dist/client/_nuxt/BAMIS8DD.js +1 -0
  9. package/dist/client/_nuxt/{A1WiD9SJ.js → BGq4KZyx.js} +1 -1
  10. package/dist/client/_nuxt/BVGdgKAv.js +1 -0
  11. package/dist/client/_nuxt/{wORFcijT.js → BXR915QZ.js} +1 -1
  12. package/dist/client/_nuxt/{DCj4DH6i.js → BYdKNJ10.js} +1 -1
  13. package/dist/client/_nuxt/BZfs-ost.js +1 -0
  14. package/dist/client/_nuxt/{DCdPDLy4.js → BacI6-DX.js} +1 -1
  15. package/dist/client/_nuxt/{DCk2z-Tu.js → BdfWgkoX.js} +1 -1
  16. package/dist/client/_nuxt/BscxmKrE.js +8 -0
  17. package/dist/client/_nuxt/C3qJFuQy.js +3 -0
  18. package/dist/client/_nuxt/C6XIsc4F.js +1 -0
  19. package/dist/client/_nuxt/C9UBdavN.js +1 -0
  20. package/dist/client/_nuxt/CA9nliXM.js +1 -0
  21. package/dist/client/_nuxt/CDJL3WWm.js +1 -0
  22. package/dist/client/_nuxt/{BsfQk1vf.js → CEfge3mM.js} +1 -1
  23. package/dist/client/_nuxt/{CQTpvb7m.js → CHCTrc3a.js} +1 -1
  24. package/dist/client/_nuxt/{DZ3fVoEH.js → CSPeAESR.js} +1 -1
  25. package/dist/client/_nuxt/CX2EUjC8.js +301 -0
  26. package/dist/client/_nuxt/{DCAtC51B.js → CarfVElc.js} +1 -1
  27. package/dist/client/_nuxt/{BgBwMnrY.js → CcYwH0AH.js} +1 -1
  28. package/dist/client/_nuxt/Cgl53LJQ.js +1 -0
  29. package/dist/client/_nuxt/{RgJsN3zu.js → ChMCFiS0.js} +1 -1
  30. package/dist/client/_nuxt/{CW3w6uup.js → CovTDKFE.js} +1 -1
  31. package/dist/client/_nuxt/{DfUNg_8t.js → CqYeW6XZ.js} +1 -1
  32. package/dist/client/_nuxt/{CL7Ixq1B.js → CrgTADc5.js} +1 -1
  33. package/dist/client/_nuxt/CuJfdYLG.js +1 -0
  34. package/dist/client/_nuxt/CudBhkk3.js +1 -0
  35. package/dist/client/_nuxt/D71BffLY.js +1 -0
  36. package/dist/client/_nuxt/{7fd6vGzb.js → DBeuZS66.js} +1 -1
  37. package/dist/client/_nuxt/{Bd7iooY8.js → DGDuLtS6.js} +1 -1
  38. package/dist/client/_nuxt/{j8KhMG0x.js → DGxQkqYo.js} +1 -1
  39. package/dist/client/_nuxt/DIt5FBMJ.js +1 -0
  40. package/dist/client/_nuxt/DOakR0z3.js +1 -0
  41. package/dist/client/_nuxt/{CUVblut_.js → DR5YgmI2.js} +1 -1
  42. package/dist/client/_nuxt/DS9ZWoKD.js +1 -0
  43. package/dist/client/_nuxt/{D-pQtGOP.js → DVLwECkk.js} +1 -1
  44. package/dist/client/_nuxt/DZLoTQm4.js +1 -0
  45. package/dist/client/_nuxt/{ZQC2c-5V.js → D_T9yQUo.js} +3 -3
  46. package/dist/client/_nuxt/Db2-y2xY.js +1 -0
  47. package/dist/client/_nuxt/{CRWwmX0L.js → Di3qjVs2.js} +1 -1
  48. package/dist/client/_nuxt/{DXpYegZJ.js → Djqq6n-7.js} +1 -1
  49. package/dist/client/_nuxt/Dkb1Nx48.js +1 -0
  50. package/dist/client/_nuxt/{BBv1LFm6.js → DtT2Dbx_.js} +1 -1
  51. package/dist/client/_nuxt/{DywwDckn.js → Du6_OKDb.js} +1 -1
  52. package/dist/client/_nuxt/{IHMnEr_d.js → G-Jz5hiA.js} +1 -1
  53. package/dist/client/_nuxt/HrnDn_2Q.js +1 -0
  54. package/dist/client/_nuxt/{CPHkTjfH.js → JgH_6NEN.js} +1 -1
  55. package/dist/client/_nuxt/Ksn5IXup.js +1 -0
  56. package/dist/client/_nuxt/{wPLeKH6q.js → Lpdzc9s2.js} +1 -1
  57. package/dist/client/_nuxt/{DggdVF2v.js → V_y36BGi.js} +1 -1
  58. package/dist/client/_nuxt/{BILqrcpa.js → YdT6Gj0u.js} +1 -1
  59. package/dist/client/_nuxt/alpzPJ78.js +1 -0
  60. package/dist/client/_nuxt/builds/latest.json +1 -1
  61. package/dist/client/_nuxt/builds/meta/ccc94de9-89fa-400b-88f2-8fc2599e191f.json +1 -0
  62. package/dist/client/_nuxt/{Bdb36Id5.js → dIHJ9UdL.js} +1 -1
  63. package/dist/client/_nuxt/error-404.BRldFSII.css +1 -0
  64. package/dist/client/_nuxt/error-500.D8yw_IbC.css +1 -0
  65. package/dist/client/_nuxt/o5b8QYQO.js +3 -0
  66. package/dist/client/_nuxt/{doGI2cFk.js → wKgfcFVx.js} +1 -1
  67. package/dist/client/index.html +63 -54
  68. package/dist/module.d.mts +2 -6
  69. package/dist/module.d.ts +2 -6
  70. package/dist/module.json +6 -2
  71. package/dist/module.mjs +68 -137
  72. package/dist/registry.d.mts +13 -0
  73. package/dist/registry.d.ts +13 -0
  74. package/dist/registry.mjs +214 -0
  75. package/dist/runtime/components/GoogleMaps.vue +130 -0
  76. package/dist/runtime/components/LemonSqueezyButton.vue +28 -0
  77. package/dist/runtime/components/StripePricingTableEmbed.vue +33 -0
  78. package/dist/runtime/components/VimeoEmbed.vue +161 -0
  79. package/dist/runtime/components/YouTubeEmbed.vue +79 -0
  80. package/dist/runtime/composables/createConsentScriptTrigger.d.ts +6 -0
  81. package/dist/runtime/composables/{createScriptConsentTrigger.mjs → createConsentScriptTrigger.mjs} +1 -1
  82. package/dist/runtime/composables/useAnalyticsPageEvent.d.ts +4 -1
  83. package/dist/runtime/composables/useElementScriptTrigger.d.ts +3 -0
  84. package/dist/runtime/composables/useElementScriptTrigger.mjs +9 -0
  85. package/dist/runtime/composables/useScript.d.ts +2 -2
  86. package/dist/runtime/composables/useScript.mjs +1 -2
  87. package/dist/runtime/registry/cloudflare-web-analytics.d.ts +11 -7
  88. package/dist/runtime/registry/cloudflare-web-analytics.mjs +16 -18
  89. package/dist/runtime/registry/facebook-pixel.d.ts +6 -5
  90. package/dist/runtime/registry/facebook-pixel.mjs +15 -17
  91. package/dist/runtime/registry/fathom-analytics.d.ts +39 -14
  92. package/dist/runtime/registry/fathom-analytics.mjs +40 -21
  93. package/dist/runtime/registry/google-analytics.d.ts +21 -1
  94. package/dist/runtime/registry/google-analytics.mjs +30 -3
  95. package/dist/runtime/registry/google-maps.d.ts +23 -1
  96. package/dist/runtime/registry/google-maps.mjs +40 -3
  97. package/dist/runtime/registry/google-tag-manager.d.ts +21 -1
  98. package/dist/runtime/registry/google-tag-manager.mjs +29 -3
  99. package/dist/runtime/registry/hotjar.d.ts +5 -3
  100. package/dist/runtime/registry/hotjar.mjs +14 -18
  101. package/dist/runtime/registry/intercom.d.ts +5 -3
  102. package/dist/runtime/registry/intercom.mjs +19 -16
  103. package/dist/runtime/registry/lemon-squeezy.d.ts +68 -0
  104. package/dist/runtime/registry/lemon-squeezy.mjs +21 -0
  105. package/dist/runtime/registry/matomo-analytics.d.ts +24 -0
  106. package/dist/runtime/registry/matomo-analytics.mjs +33 -0
  107. package/dist/runtime/registry/npm.d.ts +7 -3
  108. package/dist/runtime/registry/npm.mjs +10 -11
  109. package/dist/runtime/registry/plausible-analytics.d.ts +22 -0
  110. package/dist/runtime/registry/plausible-analytics.mjs +35 -0
  111. package/dist/runtime/registry/segment.d.ts +5 -3
  112. package/dist/runtime/registry/segment.mjs +34 -34
  113. package/dist/runtime/registry/stripe.d.ts +18 -0
  114. package/dist/runtime/registry/stripe.mjs +27 -0
  115. package/dist/runtime/registry/vimeo-player.d.ts +15 -0
  116. package/dist/runtime/registry/vimeo-player.mjs +45 -0
  117. package/dist/runtime/registry/x-pixel.d.ts +41 -0
  118. package/dist/runtime/registry/x-pixel.mjs +28 -0
  119. package/dist/runtime/registry/youtube-iframe.d.ts +15 -0
  120. package/dist/runtime/registry/youtube-iframe.mjs +54 -0
  121. package/dist/runtime/types.d.ts +31 -17
  122. package/dist/runtime/utils.d.ts +16 -1
  123. package/dist/runtime/utils.mjs +30 -1
  124. package/package.json +40 -25
  125. package/dist/client/_nuxt/BG_OyJVq.js +0 -1
  126. package/dist/client/_nuxt/BIMuYTWL.js +0 -3
  127. package/dist/client/_nuxt/BSyl5yf0.js +0 -1
  128. package/dist/client/_nuxt/BswfO-CF.js +0 -1
  129. package/dist/client/_nuxt/C3YqBJkQ.js +0 -1
  130. package/dist/client/_nuxt/CGQbO34C.js +0 -1
  131. package/dist/client/_nuxt/CKtB_0Vj.js +0 -36
  132. package/dist/client/_nuxt/CrjQeCwm.js +0 -1
  133. package/dist/client/_nuxt/D4LhxNOI.js +0 -1
  134. package/dist/client/_nuxt/D4k753MY.js +0 -1
  135. package/dist/client/_nuxt/D75a3hZQ.js +0 -1
  136. package/dist/client/_nuxt/DnhXxWz-.js +0 -1
  137. package/dist/client/_nuxt/DzPyIVdT.js +0 -9
  138. package/dist/client/_nuxt/TQ9oWRfF.js +0 -1
  139. package/dist/client/_nuxt/WoBtJUue.js +0 -1
  140. package/dist/client/_nuxt/bmJ2objS.js +0 -1
  141. package/dist/client/_nuxt/builds/meta/7bb27f9d-e4a9-494c-83a3-01bc2df7d17d.json +0 -1
  142. package/dist/client/_nuxt/error-404.ORekjfyJ.css +0 -1
  143. package/dist/client/_nuxt/error-500.BIuFL0tW.css +0 -1
  144. package/dist/client/_nuxt/yr0V4Txy.js +0 -1
  145. package/dist/runtime/composables/createScriptConsentTrigger.d.ts +0 -6
  146. package/dist/runtime/composables/validateScriptInputSchema.d.ts +0 -2
  147. package/dist/runtime/composables/validateScriptInputSchema.mjs +0 -14
  148. package/dist/runtime/registry/cloudflare-turnstile.d.ts +0 -1
  149. package/dist/runtime/registry/cloudflare-turnstile.mjs +0 -4
  150. package/dist/runtime/registry/confetti.d.ts +0 -23
  151. package/dist/runtime/registry/confetti.mjs +0 -15
package/dist/module.mjs CHANGED
@@ -1,9 +1,12 @@
1
- import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, tryUseNuxt, logger as logger$1, defineNuxtModule, addImportsDir, addImports, addPlugin, addBuildPlugin, hasNuxtModule } from '@nuxt/kit';
1
+ import { useNuxt, useLogger, addDevServerHandler, createResolver, addTemplate, tryUseNuxt, logger as logger$1, defineNuxtModule, addImportsDir, addComponentsDir, addImports, addPluginTemplate, addBuildPlugin, hasNuxtModule } from '@nuxt/kit';
2
2
  import { resolvePackageJSON, readPackageJSON } from 'pkg-types';
3
- import { parseURL, parseQuery, joinURL, hasProtocol, withQuery, withBase } from 'ufo';
3
+ import { lt } from 'semver';
4
+ import { resolvePath } from 'mlly';
5
+ import { join, relative } from 'pathe';
4
6
  import { existsSync } from 'node:fs';
5
7
  import { pathToFileURL } from 'node:url';
6
8
  import { createUnplugin } from 'unplugin';
9
+ import { parseURL, parseQuery, joinURL, hasProtocol } from 'ufo';
7
10
  import MagicString from 'magic-string';
8
11
  import { walk } from 'estree-walker';
9
12
  import fsp from 'node:fs/promises';
@@ -11,11 +14,11 @@ import { lazyEventHandler, eventHandler, createError } from 'h3';
11
14
  import { fetch } from 'ofetch';
12
15
  import { colors } from 'consola/utils';
13
16
  import { defu } from 'defu';
14
- import { join, relative } from 'pathe';
15
17
  import { hash } from 'ohash';
16
18
  import { createStorage } from 'unstorage';
17
19
  import fsDriver from 'unstorage/drivers/fs-lite';
18
20
  import { isCI, provider } from 'std-env';
21
+ import { registry } from './registry.mjs';
19
22
 
20
23
  const DEVTOOLS_UI_ROUTE = "/__nuxt-scripts";
21
24
  const DEVTOOLS_UI_LOCAL_PORT = 3030;
@@ -81,34 +84,29 @@ function NuxtScriptAssetBundlerTransformer(options) {
81
84
  const s = new MagicString(code);
82
85
  walk(ast, {
83
86
  enter(_node) {
84
- if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && _node.callee?.name.startsWith("useScript")) {
87
+ const calleeName = _node.callee?.name;
88
+ const isValidCallee = calleeName === "useScript" || calleeName?.startsWith("useScript") && /^[A-Z]$/.test(calleeName?.charAt(9));
89
+ if (_node.type === "CallExpression" && _node.callee.type === "Identifier" && isValidCallee) {
85
90
  const fnName = _node.callee?.name;
86
91
  const node = _node;
87
- let scriptKey;
88
92
  let scriptSrcNode;
89
93
  let src;
90
94
  if (fnName === "useScript") {
91
95
  if (node.arguments[0].type === "Literal") {
92
96
  scriptSrcNode = node.arguments[0];
93
- scriptKey = scriptSrcNode.value;
94
97
  } else if (node.arguments[0].type === "ObjectExpression") {
95
98
  const srcProperty = node.arguments[0].properties.find(
96
99
  (p) => p.key?.name === "src" || p.key?.value === "src"
97
100
  );
98
- const keyProperty = node.arguments[0].properties.find(
99
- (p) => p.key?.name === "key" || p.key?.value === "key"
100
- );
101
- scriptKey = keyProperty?.value?.value || srcProperty?.value;
102
101
  scriptSrcNode = srcProperty?.value;
103
102
  }
104
103
  } else {
105
- const registryNode = options.registry?.find((i) => i.name === fnName);
104
+ const registryNode = options.scripts?.find((i) => i.import.name === fnName);
106
105
  if (!registryNode) {
107
- console.warn(`[Nuxt Scripts] Integration ${fnName} not found in registry. Used in ${id}.`);
108
106
  return;
109
107
  }
110
- options.moduleDetected(registryNode.module);
111
- if (!registryNode.transform && !registryNode.src)
108
+ options.moduleDetected?.(registryNode.module);
109
+ if (!registryNode.scriptBundling && !registryNode.src)
112
110
  return;
113
111
  const optionsNode = node.arguments[0];
114
112
  if (optionsNode?.type === "ObjectExpression") {
@@ -123,11 +121,10 @@ function NuxtScriptAssetBundlerTransformer(options) {
123
121
  if (srcProperty?.value?.value) {
124
122
  scriptSrcNode = srcProperty.value;
125
123
  } else {
126
- src = registryNode.src || registryNode.transform?.(fnArg0);
124
+ src = registryNode.scriptBundling && registryNode.scriptBundling(fnArg0);
127
125
  if (src === false)
128
126
  return;
129
127
  }
130
- scriptKey = registryNode.key;
131
128
  }
132
129
  }
133
130
  if (scriptSrcNode || src) {
@@ -135,29 +132,43 @@ function NuxtScriptAssetBundlerTransformer(options) {
135
132
  if (src) {
136
133
  let canBundle = options.defaultBundle;
137
134
  if (node.arguments[1]?.type === "ObjectExpression") {
138
- const assetStrategyProperty = node.arguments[1]?.properties.find(
139
- (p) => p.key?.name === "assetStrategy" || p.key?.value === "assetStrategy"
135
+ const bundleProperty = node.arguments[1]?.properties.find(
136
+ (p) => p.key?.name === "bundle" || p.key?.value === "bundle"
140
137
  );
141
- if (assetStrategyProperty) {
142
- if (assetStrategyProperty?.value?.value !== "bundle") {
138
+ if (bundleProperty) {
139
+ if (String(bundleProperty?.value?.value) !== "true") {
143
140
  canBundle = false;
144
141
  return;
145
142
  }
146
143
  if (node.arguments[1]?.properties.length === 1)
147
144
  s.remove(node.arguments[1].start, node.arguments[1].end);
148
145
  else
149
- s.remove(assetStrategyProperty.start, assetStrategyProperty.end);
146
+ s.remove(bundleProperty.start, bundleProperty.end);
150
147
  canBundle = true;
151
148
  }
152
149
  }
153
- canBundle = canBundle || options.overrides?.[scriptKey]?.assetStrategy === "bundle";
154
150
  if (canBundle) {
155
151
  const newSrc = options.resolveScript(src);
156
152
  if (scriptSrcNode) {
157
153
  s.overwrite(scriptSrcNode.start, scriptSrcNode.end, `'${newSrc}'`);
158
154
  } else {
159
- const lastProperty = node.arguments[0].properties[node.arguments[0].properties.length - 1];
160
- s.appendRight(lastProperty.end, `, src: '${newSrc}'`);
155
+ const scriptInputProperty = node.arguments[0].properties.find(
156
+ (p) => p.key?.name === "scriptInput" || p.key?.value === "scriptInput"
157
+ );
158
+ if (scriptInputProperty) {
159
+ const scriptInput = scriptInputProperty.value;
160
+ if (scriptInput.type === "ObjectExpression") {
161
+ const srcProperty = scriptInput.properties.find(
162
+ (p) => p.key?.name === "src" || p.key?.value === "src"
163
+ );
164
+ if (srcProperty)
165
+ s.overwrite(srcProperty.value.start, srcProperty.value.end, `'${newSrc}'`);
166
+ else
167
+ s.appendRight(scriptInput.end, `, src: '${newSrc}'`);
168
+ }
169
+ } else {
170
+ s.appendRight(node.arguments[0].start + 1, ` scriptInput: { src: '${newSrc}' }, `);
171
+ }
161
172
  }
162
173
  }
163
174
  }
@@ -257,7 +268,8 @@ function setupPublicAssetStrategy(options = {}) {
257
268
  let size = 0;
258
269
  res = await fetch(url).then((r) => {
259
270
  encoding = r.headers.get("content-encoding");
260
- size = Number(r.headers.get("content-length") / 1024);
271
+ const contentLength = r.headers.get("content-length");
272
+ size = contentLength ? Number(contentLength) / 1024 : 0;
261
273
  return r.arrayBuffer();
262
274
  }).then((r) => Buffer.from(r));
263
275
  logger.log(colors.gray(` \u251C\u2500 ${url} \u2192 ${joinURL(assetsBaseURL, filename)} (${size.toFixed(2)} kB ${encoding})`));
@@ -335,14 +347,12 @@ const module = defineNuxtModule({
335
347
  name: "@nuxt/scripts",
336
348
  configKey: "scripts",
337
349
  compatibility: {
338
- nuxt: "^3.11.1",
350
+ nuxt: ">=3",
339
351
  bridge: false
340
352
  }
341
353
  },
342
354
  defaults: {
343
355
  defaultScriptOptions: {
344
- assetStrategy: "bundle",
345
- // Not supported on all scripts, only if the src is static, runtime fallback?
346
356
  trigger: "onNuxtReady"
347
357
  },
348
358
  enabled: true,
@@ -351,6 +361,11 @@ const module = defineNuxtModule({
351
361
  async setup(config, nuxt) {
352
362
  const { resolve } = createResolver(import.meta.url);
353
363
  const { version, name } = await readPackageJSON(resolve("../package.json"));
364
+ const { version: unheadVersion } = await readPackageJSON(join(await resolvePath("@unhead/vue"), "package.json"));
365
+ if (!unheadVersion || lt(unheadVersion, "1.8.0")) {
366
+ logger.warn("@nuxt/scripts requires @unhead/vue >= 1.8.0, please upgrade to use the module.");
367
+ return;
368
+ }
354
369
  if (!config.enabled) {
355
370
  logger.debug("The module is disabled, skipping setup.");
356
371
  return;
@@ -361,101 +376,20 @@ const module = defineNuxtModule({
361
376
  addImportsDir([
362
377
  resolve("./runtime/composables")
363
378
  ]);
379
+ addComponentsDir({
380
+ path: resolve("./runtime/components")
381
+ });
382
+ const scripts = registry(resolve);
364
383
  nuxt.hooks.hook("modules:done", async () => {
365
- let registry = [
366
- {
367
- name: "useScriptCloudflareWebAnalytics",
368
- key: "cloudflareWebAnalytics",
369
- from: resolve("./runtime/registry/cloudflare-web-analytics"),
370
- src: "https://static.cloudflareinsights.com/beacon.min.js"
371
- },
372
- {
373
- name: "useScriptConfetti",
374
- key: "confetti",
375
- from: resolve("./runtime/registry/confetti"),
376
- src: "https://unpkg.com/js-confetti@latest/dist/js-confetti.browser.js"
377
- },
378
- {
379
- name: "useScriptFacebookPixel",
380
- key: "facebookPixel",
381
- from: resolve("./runtime/registry/facebook-pixel"),
382
- src: "https://connect.facebook.net/en_US/fbevents.js"
383
- },
384
- {
385
- name: "useScriptFathomAnalytics",
386
- key: "fathomAnalytics",
387
- from: resolve("./runtime/registry/fathom-analytics"),
388
- src: false
389
- // can not be bundled, breaks script
390
- },
391
- {
392
- name: "useScriptHotjar",
393
- from: resolve("./runtime/registry/hotjar"),
394
- key: "hotjar",
395
- transform(options) {
396
- return withQuery(`https://static.hotjar.com/c/hotjar-${options?.id || ""}.js`, {
397
- sv: options?.sv || "6"
398
- });
399
- }
400
- },
401
- {
402
- name: "useScriptIntercom",
403
- from: resolve("./runtime/registry/intercom"),
404
- key: "intercom",
405
- transform(options) {
406
- return joinURL(`https://widget.intercom.io/widget`, options?.app_id || "");
407
- }
408
- },
409
- {
410
- name: "useScriptSegment",
411
- from: resolve("./runtime/registry/segment"),
412
- key: "segment",
413
- transform(options) {
414
- return joinURL("https://cdn.segment.com/analytics.js/v1", options?.writeKey || "", "analytics.min.js");
415
- }
416
- },
417
- {
418
- name: "useScriptNpm",
419
- // key is based on package name
420
- from: resolve("./runtime/registry/npm"),
421
- transform(options) {
422
- return withBase(options?.file || "", `https://unpkg.com/${options?.packageName || ""}@${options?.version || "latest"}`);
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"
450
- }
451
- ];
452
- registry = registry.map((i) => {
453
- i.priority = -1;
454
- i.module = i.module || "@nuxt/scripts";
455
- return i;
456
- });
457
- addImports(registry);
458
- await nuxt.hooks.callHook("scripts:registry", registry);
384
+ const registryScripts = [...scripts];
385
+ await nuxt.hooks.callHook("scripts:registry", registryScripts);
386
+ addImports(registryScripts.map((i) => {
387
+ return {
388
+ priority: -1,
389
+ ...i.import
390
+ };
391
+ }));
392
+ const newScripts = registryScripts.filter((i) => !scripts.some((r) => r.import.name === i.import.name));
459
393
  extendTypes(name, async ({ typesPath }) => {
460
394
  return `
461
395
  declare module '#app' {
@@ -466,26 +400,26 @@ declare module '#app' {
466
400
  declare module '#nuxt-scripts' {
467
401
  type NuxtUseScriptOptions = Omit<import('${typesPath}').NuxtUseScriptOptions, 'use' | 'beforeInit'>
468
402
  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]`;
403
+ ${newScripts.map((i) => {
404
+ const key = i.import.name.replace("useScript", "");
405
+ const keyLcFirst = key.substring(0, 1).toLowerCase() + key.substring(1);
406
+ return ` ${keyLcFirst}?: import('${i.import.from}').${key}Input | [import('${i.import.from}').${key}Input, NuxtUseScriptOptions]`;
472
407
  }).join("\n")}
473
408
  }
474
409
  }
475
410
  `;
476
411
  });
477
- if (config.globals?.length || Object.keys(config.register || {}).length) {
478
- const template = addTemplate({
412
+ if (config.globals?.length || Object.keys(config.registry || {}).length) {
413
+ addPluginTemplate({
479
414
  filename: `modules/${name.replace("/", "-")}.mjs`,
480
- write: true,
481
415
  getContents() {
482
416
  const imports = ["useScript", "defineNuxtPlugin"];
483
417
  const inits = [];
484
- for (const [k, c] of Object.entries(config.register || {})) {
485
- const importDefinition = registry.find((i) => i.name === `useScript${k.substring(0, 1).toUpperCase() + k.substring(1)}`);
418
+ for (const [k, c] of Object.entries(config.registry || {})) {
419
+ const importDefinition = registryScripts.find((i) => i.import.name === `useScript${k.substring(0, 1).toUpperCase() + k.substring(1)}`);
486
420
  if (importDefinition) {
487
- imports.unshift(importDefinition.name);
488
- inits.push(`${importDefinition.name}(${JSON.stringify(c)});`);
421
+ imports.unshift(importDefinition.import.name);
422
+ inits.push(`${importDefinition.import.name}(${JSON.stringify(c === true ? {} : c)});`);
489
423
  }
490
424
  }
491
425
  return `import { ${imports.join(", ")} } from '#imports'
@@ -498,16 +432,13 @@ ${(config.globals || []).map((g) => !Array.isArray(g) ? ` useScript("${g.toSt
498
432
  })`;
499
433
  }
500
434
  });
501
- addPlugin({
502
- src: template.dst
503
- });
504
435
  }
505
436
  const scriptMap = /* @__PURE__ */ new Map();
506
437
  const { normalizeScriptData } = setupPublicAssetStrategy(config.assets);
507
438
  const moduleInstallPromises = /* @__PURE__ */ new Map();
508
439
  addBuildPlugin(NuxtScriptAssetBundlerTransformer({
509
- registry,
510
- defaultBundle: config.defaultScriptOptions?.assetStrategy === "bundle",
440
+ scripts,
441
+ defaultBundle: config.defaultScriptOptions?.bundle,
511
442
  moduleDetected(module) {
512
443
  if (nuxt.options.dev && module !== "@nuxt/scripts" && !moduleInstallPromises.has(module) && !hasNuxtModule(module))
513
444
  moduleInstallPromises.set(module, () => installNuxtModule(module));
@@ -0,0 +1,13 @@
1
+ import { SegmentInput } from './runtime/registry/segment.ts';
2
+ import { PlausibleAnalyticsInput } from './runtime/registry/plausible-analytics.ts';
3
+ import { GoogleAnalyticsInput } from './runtime/registry/google-analytics.ts';
4
+ import { RegistryScripts } from '#nuxt-scripts';
5
+
6
+ declare function GoogleAnalyticsScriptResolver(options?: GoogleAnalyticsInput): string;
7
+ declare function PlausibleAnalyticsScriptResolver(options: PlausibleAnalyticsInput): string;
8
+ declare function CloudflareWebAnalyticsScriptResolver(): string;
9
+ declare function SegmentScriptResolver(options: SegmentInput): string;
10
+ declare function FacebookPixelScriptResolver(): string;
11
+ declare const registry: (resolve?: (s: string) => string) => RegistryScripts;
12
+
13
+ export { CloudflareWebAnalyticsScriptResolver, FacebookPixelScriptResolver, GoogleAnalyticsScriptResolver, PlausibleAnalyticsScriptResolver, SegmentScriptResolver, registry };
@@ -0,0 +1,13 @@
1
+ import { SegmentInput } from './runtime/registry/segment.ts';
2
+ import { PlausibleAnalyticsInput } from './runtime/registry/plausible-analytics.ts';
3
+ import { GoogleAnalyticsInput } from './runtime/registry/google-analytics.ts';
4
+ import { RegistryScripts } from '#nuxt-scripts';
5
+
6
+ declare function GoogleAnalyticsScriptResolver(options?: GoogleAnalyticsInput): string;
7
+ declare function PlausibleAnalyticsScriptResolver(options: PlausibleAnalyticsInput): string;
8
+ declare function CloudflareWebAnalyticsScriptResolver(): string;
9
+ declare function SegmentScriptResolver(options: SegmentInput): string;
10
+ declare function FacebookPixelScriptResolver(): string;
11
+ declare const registry: (resolve?: (s: string) => string) => RegistryScripts;
12
+
13
+ export { CloudflareWebAnalyticsScriptResolver, FacebookPixelScriptResolver, GoogleAnalyticsScriptResolver, PlausibleAnalyticsScriptResolver, SegmentScriptResolver, registry };