Skip to content

Commit

Permalink
chore: broken linting
Browse files Browse the repository at this point in the history
  • Loading branch information
harlan-zw committed Aug 5, 2024
1 parent b27d4ee commit 3c46cff
Show file tree
Hide file tree
Showing 21 changed files with 64 additions and 53 deletions.
10 changes: 6 additions & 4 deletions docs/pages/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,13 @@ const { $script } = useScript<JSConfettiApi>({
},
})
onMounted(() => {
confettiEl.value && useEventListener(confettiEl.value, 'mouseenter', () => {
$script.then(({ JSConfetti }) => {
new JSConfetti().addConfetti({ emojis: ['🎉', '🎊'] })
if (confettiEl.value) {
useEventListener(confettiEl.value, 'mouseenter', () => {
$script.then(({ JSConfetti }) => {
new JSConfetti().addConfetti({ emojis: ['🎉', '🎊'] })
})
})
})
}
})
const links = [
Expand Down
2 changes: 1 addition & 1 deletion playground/pages/npm/js-confetti.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export interface JSConfettiApi {
}
declare global {
interface Window extends JSConfettiApi {}
type Window = JSConfettiApi
}
const { $script } = useScriptNpm<JSConfettiApi>({
Expand Down
3 changes: 1 addition & 2 deletions playground/scripts/myCustomScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import type { Input } from 'valibot'
import { useScript } from '#imports'
import type { NuxtUseScriptOptions } from '#nuxt-scripts'

export interface MyCustomScriptApi {
}
export type MyCustomScriptApi = Record<string, any>

export const MyCustomScriptOptions = object({
id: string(),
Expand Down
2 changes: 1 addition & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export async function generateTpcContent(input: TpcDescriptor) {

chunks.push(`
declare global {
interface Window extends ${input.tpcTypeAugmentation} {}
type Window = ${input.tpcTypeAugmentation}
}`)
}

Expand Down
4 changes: 0 additions & 4 deletions src/devtools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ import { useNuxt } from '@nuxt/kit'
import type { ModuleOptions } from './module'
import { DEVTOOLS_UI_LOCAL_PORT, DEVTOOLS_UI_ROUTE } from './constants'

export interface ServerFunctions {}

export interface ClientFunctions {}

export function setupDevToolsUI(options: ModuleOptions, resolve: Resolver['resolve'], nuxt: Nuxt = useNuxt()) {
const clientPath = resolve('./client')
const isProductionBuild = existsSync(clientPath)
Expand Down
2 changes: 1 addition & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default defineNuxtModule<ModuleOptions>({
nuxt.hooks.hook('modules:done', async () => {
const registryScripts = [...scripts]

// @ts-ignore nuxi prepare is broken to generate these types, possibly because of the runtime path
// @ts-expect-error nuxi prepare is broken to generate these types, possibly because of the runtime path
await nuxt.hooks.callHook('scripts:registry', registryScripts)
const registryScriptsWithImport = registryScripts.filter(i => !!i.import?.name) as Required<RegistryScript>[]
addImports(registryScriptsWithImport.map((i) => {
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/components/ScriptGoogleMaps.vue
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ defineExpose({
onMounted(() => {
watch(ready, (v) => {
v && emits('ready', map)
if (v) {
emits('ready', map)
}
})
watch($script.status, () => {
if ($script.status.value === 'error') {
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/components/ScriptVimeoPlayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,9 @@ onMounted(() => {
})
watch(() => props.id, (v) => {
v && player?.loadVideo(Number(v))
if (v) {
player?.loadVideo(Number(v))
}
})
watch($script.status, (status) => {
if (status === 'error') {
Expand Down
28 changes: 15 additions & 13 deletions src/runtime/composables/useScriptEventPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export function useScriptEventPage(onChange?: (payload: TrackedPage) => void) {
return payload

let lastPayload: TrackedPage = { path: '', title: '' }
let stopDomWatcher: () => void
let stopDomWatcher = () => {}
// TODO make sure useAsyncData isn't running
nuxt.hooks.hook('page:finish', () => {
Promise.race([
Expand All @@ -23,18 +23,20 @@ export function useScriptEventPage(onChange?: (payload: TrackedPage) => void) {
new Promise<void>((resolve) => {
stopDomWatcher = head.hooks.hook('dom:rendered', () => resolve())
}),
]).finally(() => {
stopDomWatcher && stopDomWatcher()
}).then(() => {
payload.value = {
path: route.fullPath,
title: document.title,
}
if (lastPayload.path !== payload.value.path || lastPayload.title !== payload.value.title) {
onChange && onChange(payload.value)
lastPayload = payload.value
}
})
])
.finally(stopDomWatcher)
.then(() => {
payload.value = {
path: route.fullPath,
title: document.title,
}
if (lastPayload.path !== payload.value.path || lastPayload.title !== payload.value.title) {
if (onChange) {
onChange(payload.value)
}
lastPayload = payload.value
}
})
})
return payload
}
2 changes: 1 addition & 1 deletion src/runtime/registry/clarity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface ClarityApi {
}

declare global {
interface Window extends ClarityApi {}
type Window = ClarityApi

Check failure on line 36 in src/runtime/registry/clarity.ts

View workflow job for this annotation

GitHub Actions / ci

Duplicate identifier 'Window'.
}

export const ClarityOptions = object({
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/cloudflare-web-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export interface CloudflareWebAnalyticsApi {
}

declare global {
interface Window extends CloudflareWebAnalyticsApi {}
type Window = CloudflareWebAnalyticsApi

Check failure on line 21 in src/runtime/registry/cloudflare-web-analytics.ts

View workflow job for this annotation

GitHub Actions / ci

Duplicate identifier 'Window'.
}

export const CloudflareWebAnalyticsOptions = object({
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/google-adsense.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface GoogleAdsenseApi {
}

declare global {
interface Window extends GoogleAdsenseApi {}
type Window = GoogleAdsenseApi
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/google-maps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const GoogleMapsOptions = object({

export type GoogleMapsInput = RegistryScriptInput<typeof GoogleMapsOptions>

type MapsNamespace = typeof google.maps
type MapsNamespace = google.maps
export interface GoogleMapsApi {
maps: MapsNamespace | Promise<MapsNamespace>
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/google-tag-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { RegistryScriptInput } from '#nuxt-scripts'
import { object, string, optional } from '#nuxt-scripts-validator'

declare global {
interface Window extends GoogleTagManagerApi {}
type Window = GoogleTagManagerApi
}
export const GoogleTagManagerOptions = object({
id: string(),
Expand Down
10 changes: 7 additions & 3 deletions src/runtime/registry/matomo-analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ interface MatomoAnalyticsApi {
}

declare global {
interface Window extends MatomoAnalyticsApi {}
type Window = MatomoAnalyticsApi
}

export function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?: MatomoAnalyticsInput) {
Expand All @@ -42,8 +42,12 @@ export function useScriptMatomoAnalytics<T extends MatomoAnalyticsApi>(_options?
? undefined
: () => {
const _paq = window._paq = window._paq || []
options?.trackPageView !== false && _paq.push(['trackPageView'])
options?.enableLinkTracking !== false && _paq.push(['enableLinkTracking'])
if (options?.trackPageView) {
_paq.push(['trackPageView'])
}
if (options?.enableLinkTracking) {
_paq.push(['enableLinkTracking'])
}
_paq.push(['setTrackerUrl', withBase(`/matomo.php`, withHttps(options?.matomoUrl))])
_paq.push(['setSiteId', options?.siteId || '1'])
},
Expand Down
11 changes: 7 additions & 4 deletions src/runtime/registry/meta-pixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export interface MetaPixelApi {
}

declare global {
interface Window extends MetaPixelApi {
}
type Window = MetaPixelApi
}

export const MetaPixelOptions = object({
Expand All @@ -57,8 +56,12 @@ export function useScriptMetaPixel<T extends MetaPixelApi>(_options?: MetaPixelI
? undefined
: () => {
const fbq: MetaPixelApi['fbq'] = window.fbq = function (...params: any[]) {
// @ts-expect-error untyped
fbq.callMethod ? fbq.callMethod(...params) : fbq.queue.push(params)
if (fbq.callMethod) {
fbq.callMethod(...params)
}
else {
fbq.queue.push(params)
}
} as any as MetaPixelApi['fbq']
if (!window._fbq)
window._fbq = fbq
Expand Down
5 changes: 2 additions & 3 deletions src/runtime/registry/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@ interface AnalyticsApi {
push: (args: any[]) => void
}

export interface SegmentApi extends Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'> {
}
export type SegmentApi = Pick<AnalyticsApi, 'track' | 'page' | 'identify' | 'group' | 'alias' | 'reset'>

declare global {
interface Window extends SegmentApi { }
type Window = SegmentApi
}

const methods = ['track', 'page', 'identify', 'group', 'alias', 'reset']
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface StripeApi {
}

declare global {
interface Window extends StripeApi {}
type Window = StripeApi
}

export function useScriptStripe<T extends StripeApi>(_options?: StripeInput) {
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/registry/vimeo-player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface VimeoPlayerApi {
export type VimeoPlayerInput = RegistryScriptInput

declare global {
interface Window extends VimeoPlayerApi {}
type Window = VimeoPlayerApi
}

export function useScriptVimeoPlayer<T extends VimeoPlayerApi>(_options?: VimeoPlayerInput) {
Expand Down
14 changes: 8 additions & 6 deletions src/runtime/registry/x-pixel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ export interface XPixelApi {
}

declare global {
interface Window extends XPixelApi {
}
type Window = XPixelApi
}

export const XPixelOptions = object({
Expand All @@ -57,10 +56,13 @@ export function useScriptXPixel<T extends XPixelApi>(_options?: XPixelInput) {
? undefined
: () => {
// @ts-expect-error untyped
const s = window.twq = function () {
// @ts-expect-error untyped
// eslint-disable-next-line prefer-rest-params
s.exe ? s.exe(s, arguments) : s.queue.push(arguments)
const s = window.twq = function (...args) {
if (e.exe) {
s.exe(s, args)
}
else {
s.queue.push(args)
}
}
// @ts-expect-error untyped
s.version = options?.version || '1.1'
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,9 @@ export type NuxtConfigScriptRegistry<T extends keyof ScriptRegistry = keyof Scri
[key in T]: NuxtConfigScriptRegistryEntry<ScriptRegistry[key]>
}>

const emptyOptions = object({})
const _emptyOptions = object({})

export type EmptyOptionsSchema = typeof emptyOptions
export type EmptyOptionsSchema = typeof _emptyOptions

type ScriptInput = ScriptBase & DataKeys & SchemaAugmentations['script']

Expand Down

0 comments on commit 3c46cff

Please sign in to comment.