Skip to content

Commit 67b7e70

Browse files
committed
fix: drop #imports usage
Fixes #288
1 parent b7213e0 commit 67b7e70

File tree

6 files changed

+21
-8
lines changed

6 files changed

+21
-8
lines changed

src/runtime/components/ScriptPayPalButtons.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ import type {
1414
PayPalButtonsComponentOptions,
1515
OnInitActions,
1616
} from '@paypal/paypal-js'
17-
import { onBeforeUnmount, resolveComponent, useScriptPayPal, useScriptTriggerElement } from '#imports'
17+
import { useScriptPayPal } from '../registry/paypal'
18+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
19+
import { onBeforeUnmount, resolveComponent } from 'vue'
1820
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
1921
import type { PayPalInput } from '../registry/paypal'
2022

src/runtime/components/ScriptPayPalMarks.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import { computed, type HTMLAttributes, onMounted, ref, type ReservedProps, shallowRef, watch } from 'vue'
33
import { defu } from 'defu'
44
import type { PayPalMarksComponent, PayPalMarksComponentOptions } from '@paypal/paypal-js'
5-
import { onBeforeUnmount, resolveComponent, useScriptPayPal, useScriptTriggerElement } from '#imports'
5+
import { useScriptPayPal } from '../registry/paypal'
6+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
7+
import { onBeforeUnmount, resolveComponent } from 'vue'
68
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
79
import type { PayPalInput } from '../registry/paypal'
810

src/runtime/components/ScriptPayPalMessages.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import { computed, type HTMLAttributes, onMounted, ref, type ReservedProps, shallowRef, watch } from 'vue'
33
import { defu } from 'defu'
44
import type { PayPalMessagesComponent, PayPalMessagesComponentOptions } from '@paypal/paypal-js'
5-
import { onBeforeUnmount, resolveComponent, useScriptPayPal, useScriptTriggerElement } from '#imports'
5+
import { useScriptPayPal } from '../registry/paypal'
6+
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
7+
import { onBeforeUnmount, resolveComponent } from 'vue'
68
import type { ElementScriptTrigger } from '#nuxt-scripts/types'
79
import type { PayPalInput } from '../registry/paypal'
810

src/runtime/components/ScriptStripePricingTable.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import { ref, computed, onBeforeUnmount, onMounted, watch } from 'vue'
33
import type { ElementScriptTrigger } from '../types'
44
import { useScriptTriggerElement } from '../composables/useScriptTriggerElement'
5-
import { useScript } from '#imports'
5+
import { useScript } from '../composables/useScript'
66
77
const props = withDefaults(defineProps<{
88
trigger?: ElementScriptTrigger

src/runtime/composables/useScript.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defu } from 'defu'
33
import { useScript as _useScript } from '@unhead/vue/scripts'
44
import { reactive } from 'vue'
55
import type { NuxtDevToolsScriptInstance, NuxtUseScriptOptions, UseFunctionType, UseScriptContext } from '../types'
6-
import { onNuxtReady, useNuxtApp, useRuntimeConfig, injectHead } from '#imports'
6+
import { onNuxtReady, useNuxtApp, useRuntimeConfig, injectHead } from 'nuxt/app'
77
import { logger } from '../logger'
88

99
function useNuxtScriptRuntimeConfig() {

src/templates.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,26 @@ import { hash } from 'ohash'
22
import type { ModuleOptions } from './module'
33
import { logger } from './logger'
44
import type { RegistryScript } from '#nuxt-scripts/types'
5+
import {useNuxt} from "@nuxt/kit";
6+
import {relative} from "pathe";
57

68
export function templatePlugin(config: Partial<ModuleOptions>, registry: Required<RegistryScript>[]) {
79
if (Array.isArray(config.globals)) {
810
// convert to object
911
config.globals = Object.fromEntries(config.globals.map(i => [hash(i), i]))
1012
logger.warn('The `globals` array option is deprecated, please convert to an object.')
1113
}
12-
const imports = ['useScript', 'defineNuxtPlugin']
14+
const nuxt = useNuxt()
15+
const buildDir = nuxt.options.buildDir
16+
const imports = []
1317
const inits = []
1418
// for global scripts, we can initialise them script away
1519
for (const [k, c] of Object.entries(config.registry || {})) {
1620
const importDefinition = registry.find(i => i.import.name === `useScript${k.substring(0, 1).toUpperCase() + k.substring(1)}`)
1721
if (importDefinition) {
1822
// title case
19-
imports.unshift(importDefinition.import.name)
23+
imports.unshift(`import { ${importDefinition.import.name} } from '${relative(buildDir, importDefinition.import.from)}'`)
24+
console.log(`import { ${importDefinition.import.name} } from '${relative(buildDir, importDefinition.import.from)}'`)
2025
const args = (typeof c !== 'object' ? {} : c) || {}
2126
if (c === 'mock')
2227
args.scriptOptions = { trigger: 'manual', skipValidation: true }
@@ -35,7 +40,9 @@ export function templatePlugin(config: Partial<ModuleOptions>, registry: Require
3540
}
3641
}
3742
return [
38-
`import { ${imports.join(', ')} } from '#imports'`,
43+
`import { useScript } from '#nuxt-scripts/composables/useScript'`,
44+
`import { defineNuxtPlugin } from 'nuxt/app'`,
45+
...imports,
3946
'',
4047
`export default defineNuxtPlugin({`,
4148
` name: "scripts:init",`,

0 commit comments

Comments
 (0)