@meistrari/tela-build 1.50.2 → 1.50.4
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.
package/package.json
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @vitest-environment happy-dom
|
|
3
|
+
*/
|
|
4
|
+
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
5
|
+
|
|
6
|
+
type RuntimeConfig = {
|
|
7
|
+
app?: Record<string, unknown>
|
|
8
|
+
public?: Record<string, unknown>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type NuxtWindow = typeof window & {
|
|
12
|
+
__NUXT__?: {
|
|
13
|
+
config?: {
|
|
14
|
+
app?: Record<string, unknown>
|
|
15
|
+
public?: Record<string, unknown>
|
|
16
|
+
[key: string]: unknown
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const runtimeConfig = vi.hoisted((): { current: RuntimeConfig } => ({
|
|
22
|
+
current: {
|
|
23
|
+
app: {
|
|
24
|
+
baseURL: '/',
|
|
25
|
+
buildAssetsDir: '/_nuxt/',
|
|
26
|
+
cdnURL: 'https://cdn.example.com/',
|
|
27
|
+
},
|
|
28
|
+
public: {
|
|
29
|
+
avatarAllowedOrigins: 'https://assets.example.com',
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
}))
|
|
33
|
+
|
|
34
|
+
vi.mock('nuxt/app', () => ({
|
|
35
|
+
defineNuxtPlugin: (plugin: () => void) => plugin,
|
|
36
|
+
useRuntimeConfig: () => runtimeConfig.current,
|
|
37
|
+
}))
|
|
38
|
+
|
|
39
|
+
// The mocked defineNuxtPlugin returns the setup function unchanged, so the
|
|
40
|
+
// default export is a no-arg callable at runtime even though its static type
|
|
41
|
+
// is Nuxt's Plugin (which expects a nuxtApp argument).
|
|
42
|
+
const { default: mirrorAvatarRuntimeConfig } = await import('../avatar-runtime-config.client') as unknown as { default: () => void }
|
|
43
|
+
|
|
44
|
+
function getWindow(): NuxtWindow {
|
|
45
|
+
return window
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
describe('avatar runtime config plugin', () => {
|
|
49
|
+
beforeEach(() => {
|
|
50
|
+
delete getWindow().__NUXT__
|
|
51
|
+
runtimeConfig.current = {
|
|
52
|
+
app: {
|
|
53
|
+
baseURL: '/',
|
|
54
|
+
buildAssetsDir: '/_nuxt/',
|
|
55
|
+
cdnURL: 'https://cdn.example.com/',
|
|
56
|
+
},
|
|
57
|
+
public: {
|
|
58
|
+
avatarAllowedOrigins: 'https://assets.example.com',
|
|
59
|
+
},
|
|
60
|
+
}
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('mirrors public and app runtime config when creating the legacy global', () => {
|
|
64
|
+
mirrorAvatarRuntimeConfig()
|
|
65
|
+
|
|
66
|
+
expect(getWindow().__NUXT__?.config).toEqual({
|
|
67
|
+
app: runtimeConfig.current.app,
|
|
68
|
+
public: runtimeConfig.current.public,
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
it('adds missing app config when public config already exists', () => {
|
|
73
|
+
getWindow().__NUXT__ = {
|
|
74
|
+
config: {
|
|
75
|
+
public: {
|
|
76
|
+
avatarAllowedOrigins: 'https://existing.example.com',
|
|
77
|
+
},
|
|
78
|
+
otherConfig: 'kept',
|
|
79
|
+
},
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
mirrorAvatarRuntimeConfig()
|
|
83
|
+
|
|
84
|
+
expect(getWindow().__NUXT__?.config).toEqual({
|
|
85
|
+
app: runtimeConfig.current.app,
|
|
86
|
+
public: {
|
|
87
|
+
avatarAllowedOrigins: 'https://existing.example.com',
|
|
88
|
+
},
|
|
89
|
+
otherConfig: 'kept',
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('fills missing fields in partial app and public config', () => {
|
|
94
|
+
getWindow().__NUXT__ = {
|
|
95
|
+
config: {
|
|
96
|
+
app: {
|
|
97
|
+
baseURL: '/custom/',
|
|
98
|
+
},
|
|
99
|
+
public: {
|
|
100
|
+
theme: 'dark',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
mirrorAvatarRuntimeConfig()
|
|
106
|
+
|
|
107
|
+
expect(getWindow().__NUXT__?.config).toEqual({
|
|
108
|
+
app: {
|
|
109
|
+
baseURL: '/custom/',
|
|
110
|
+
buildAssetsDir: '/_nuxt/',
|
|
111
|
+
cdnURL: 'https://cdn.example.com/',
|
|
112
|
+
},
|
|
113
|
+
public: {
|
|
114
|
+
avatarAllowedOrigins: 'https://assets.example.com',
|
|
115
|
+
theme: 'dark',
|
|
116
|
+
},
|
|
117
|
+
})
|
|
118
|
+
})
|
|
119
|
+
})
|
|
@@ -1,5 +1,32 @@
|
|
|
1
1
|
import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
2
2
|
|
|
3
|
+
type RuntimeConfig = {
|
|
4
|
+
app?: Record<string, unknown>
|
|
5
|
+
public?: Record<string, unknown>
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
type NuxtConfig = {
|
|
9
|
+
app?: Record<string, unknown>
|
|
10
|
+
public?: Record<string, unknown>
|
|
11
|
+
[key: string]: unknown
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type NuxtWindow = typeof window & {
|
|
15
|
+
__NUXT__?: {
|
|
16
|
+
config?: NuxtConfig
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function mergeConfigSection(runtimeSection?: Record<string, unknown>, existingSection?: Record<string, unknown>) {
|
|
21
|
+
if (!runtimeSection && !existingSection)
|
|
22
|
+
return
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
...runtimeSection,
|
|
26
|
+
...existingSection,
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
3
30
|
/**
|
|
4
31
|
* tela-build's avatar sanitizer (`sanitizeAvatarImageUrl`) reads its host
|
|
5
32
|
* allowlist from the legacy `window.__NUXT__.config.public` global, which Nuxt 4
|
|
@@ -7,21 +34,23 @@ import { defineNuxtPlugin, useRuntimeConfig } from 'nuxt/app'
|
|
|
7
34
|
* hosts (Google/MS/GitHub/Gravatar), so avatars served from `avatarAllowedOrigins`
|
|
8
35
|
* (e.g. vault asset hosts) fall back to initials.
|
|
9
36
|
*
|
|
10
|
-
* This is a fallback/polyfill, not a replacement:
|
|
11
|
-
*
|
|
12
|
-
* runtime config onto it so the sanitizer can resolve the configured hosts.
|
|
37
|
+
* This is a fallback/polyfill, not a replacement: it fills missing legacy
|
|
38
|
+
* config fields while preserving values already populated by Nuxt.
|
|
13
39
|
*/
|
|
14
40
|
export default defineNuxtPlugin(() => {
|
|
15
|
-
const globalWithNuxt = window
|
|
16
|
-
|
|
17
|
-
|
|
41
|
+
const globalWithNuxt: NuxtWindow = window
|
|
42
|
+
const runtimeConfig = useRuntimeConfig() as RuntimeConfig
|
|
43
|
+
const existingConfig = globalWithNuxt.__NUXT__?.config
|
|
44
|
+
const appConfig = mergeConfigSection(runtimeConfig.app, existingConfig?.app)
|
|
45
|
+
const publicConfig = mergeConfigSection(runtimeConfig.public, existingConfig?.public)
|
|
18
46
|
|
|
19
|
-
if (
|
|
47
|
+
if (!appConfig && !publicConfig)
|
|
20
48
|
return
|
|
21
49
|
|
|
22
|
-
const { public: publicConfig } = useRuntimeConfig()
|
|
23
|
-
|
|
24
50
|
globalWithNuxt.__NUXT__ ??= {}
|
|
25
|
-
globalWithNuxt.__NUXT__.config
|
|
26
|
-
|
|
51
|
+
globalWithNuxt.__NUXT__.config = {
|
|
52
|
+
...existingConfig,
|
|
53
|
+
...(appConfig ? { app: appConfig } : {}),
|
|
54
|
+
...(publicConfig ? { public: publicConfig } : {}),
|
|
55
|
+
}
|
|
27
56
|
})
|