Skip to content

Commit 230cd32

Browse files
committed
fix: quite warnings for embeds
1 parent f4a4df6 commit 230cd32

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

packages/script/src/module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,8 +454,9 @@ export default defineNuxtModule<ModuleOptions>({
454454
// Normalize registry entries to [input, scriptOptions?] tuple form
455455
// Eliminates 4-shape polymorphism (true | 'mock' | object | array) for all downstream consumers
456456
if (config.registry) {
457+
const componentOnlyKeys = new Set(scripts.filter(s => !s.import).map(s => s.registryKey!))
457458
migrateDeprecatedRegistryKeys(config.registry as Record<string, any>, msg => logger.warn(msg))
458-
normalizeRegistryConfig(config.registry as Record<string, any>, msg => logger.warn(msg))
459+
normalizeRegistryConfig(config.registry as Record<string, any>, msg => logger.warn(msg), componentOnlyKeys)
459460
nuxt.options.runtimeConfig.public = nuxt.options.runtimeConfig.public || {}
460461

461462
// Auto-populate env var defaults for enabled registry scripts so that

packages/script/src/normalize.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ export function migrateDeprecatedRegistryKeys(
8484
export function normalizeRegistryConfig(
8585
registry: Record<string, unknown>,
8686
warn?: (msg: string) => void,
87+
componentOnlyKeys?: Set<string>,
8788
): void {
8889
for (const key of Object.keys(registry)) {
8990
const entry = registry[key]
@@ -92,6 +93,12 @@ export function normalizeRegistryConfig(
9293
continue
9394
}
9495
if (entry === true) {
96+
// Component-only scripts (embeds) have no composable; `true` means
97+
// "enable infrastructure" (server endpoints) with no trigger semantics.
98+
if (componentOnlyKeys?.has(key)) {
99+
registry[key] = [{}] satisfies NormalizedRegistryEntry
100+
continue
101+
}
95102
warn?.(`[nuxt-scripts] registry.${key}: \`true\` shorthand is deprecated. Use \`{ trigger: 'onNuxtReady' }\` instead.`)
96103
registry[key] = [{}, { trigger: 'onNuxtReady' }] satisfies NormalizedRegistryEntry
97104
continue

test/unit/normalize.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ describe('normalizeRegistryConfig', () => {
1717
expect(warn.mock.calls[0][0]).toContain('deprecated')
1818
})
1919

20+
it('normalizes true for component-only scripts to [{}] with no warning', () => {
21+
const warn = vi.fn()
22+
const registry: Record<string, any> = { xEmbed: true }
23+
normalizeRegistryConfig(registry, warn, new Set(['xEmbed']))
24+
expect(registry.xEmbed).toEqual([{}])
25+
expect(warn).not.toHaveBeenCalled()
26+
})
27+
2028
it('throws on "proxy-only" with migration message', () => {
2129
const registry: Record<string, any> = { ga: 'proxy-only' }
2230
expect(() => normalizeRegistryConfig(registry)).toThrowError(/proxy-only.*no longer supported/)

0 commit comments

Comments
 (0)