@jasonshimmy/vite-plugin-cer-app 0.2.0 → 0.4.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.
- package/CHANGELOG.md +8 -0
- package/README.md +2 -0
- package/commits.txt +1 -1
- package/dist/cli/create/index.js +7 -3
- package/dist/cli/create/index.js.map +1 -1
- package/dist/cli/create/templates/spa/.gitignore.tpl +25 -0
- package/dist/cli/create/templates/spa/index.html.tpl +1 -1
- package/dist/cli/create/templates/ssg/.gitignore.tpl +25 -0
- package/dist/cli/create/templates/ssg/index.html.tpl +1 -1
- package/dist/cli/create/templates/ssr/.gitignore.tpl +25 -0
- package/dist/cli/create/templates/ssr/cer.config.ts.tpl +0 -1
- package/dist/cli/create/templates/ssr/index.html.tpl +1 -1
- package/dist/plugin/build-ssr.d.ts.map +1 -1
- package/dist/plugin/build-ssr.js +18 -0
- package/dist/plugin/build-ssr.js.map +1 -1
- package/dist/plugin/dev-server.d.ts +0 -1
- package/dist/plugin/dev-server.d.ts.map +1 -1
- package/dist/plugin/dts-generator.js +1 -1
- package/dist/plugin/dts-generator.js.map +1 -1
- package/dist/plugin/generated-dir.d.ts +5 -11
- package/dist/plugin/generated-dir.d.ts.map +1 -1
- package/dist/plugin/generated-dir.js +43 -31
- package/dist/plugin/generated-dir.js.map +1 -1
- package/dist/plugin/index.d.ts.map +1 -1
- package/dist/plugin/index.js +9 -1
- package/dist/plugin/index.js.map +1 -1
- package/dist/plugin/transforms/auto-import.js +2 -2
- package/dist/plugin/transforms/auto-import.js.map +1 -1
- package/dist/runtime/app-template.d.ts +5 -4
- package/dist/runtime/app-template.d.ts.map +1 -1
- package/dist/runtime/app-template.js +6 -5
- package/dist/runtime/app-template.js.map +1 -1
- package/dist/runtime/composables/index.d.ts +1 -0
- package/dist/runtime/composables/index.d.ts.map +1 -1
- package/dist/runtime/composables/index.js +1 -0
- package/dist/runtime/composables/index.js.map +1 -1
- package/dist/runtime/composables/use-inject.d.ts +29 -0
- package/dist/runtime/composables/use-inject.d.ts.map +1 -0
- package/dist/runtime/composables/use-inject.js +48 -0
- package/dist/runtime/composables/use-inject.js.map +1 -0
- package/dist/runtime/entry-server-template.d.ts +1 -1
- package/dist/runtime/entry-server-template.d.ts.map +1 -1
- package/dist/runtime/entry-server-template.js +20 -0
- package/dist/runtime/entry-server-template.js.map +1 -1
- package/dist/types/config.d.ts +0 -1
- package/dist/types/config.d.ts.map +1 -1
- package/dist/types/config.js.map +1 -1
- package/docs/cli.md +1 -1
- package/docs/composables.md +37 -0
- package/docs/configuration.md +2 -11
- package/docs/getting-started.md +2 -100
- package/docs/plugins.md +23 -15
- package/docs/rendering-modes.md +3 -4
- package/docs/testing.md +3 -3
- package/e2e/kitchen-sink/app/pages/(auth)/protected.ts +1 -5
- package/e2e/kitchen-sink/cer-auto-imports.d.ts +1 -0
- package/package.json +1 -1
- package/src/__tests__/plugin/build-ssr.test.ts +10 -0
- package/src/__tests__/plugin/cer-app-plugin.test.ts +15 -0
- package/src/__tests__/plugin/dev-server.test.ts +1 -1
- package/src/__tests__/plugin/dts-generator.test.ts +5 -0
- package/src/__tests__/plugin/entry-server-template.test.ts +24 -0
- package/src/__tests__/plugin/generated-dir.test.ts +8 -39
- package/src/__tests__/plugin/resolve-config.test.ts +0 -5
- package/src/__tests__/plugin/transforms/auto-import.test.ts +7 -0
- package/src/__tests__/runtime/use-inject-client.test.ts +67 -0
- package/src/__tests__/runtime/use-inject.test.ts +66 -0
- package/src/__tests__/types/config.test.ts +1 -1
- package/src/cli/create/index.ts +12 -8
- package/src/cli/create/templates/spa/.gitignore.tpl +25 -0
- package/src/cli/create/templates/spa/index.html.tpl +1 -1
- package/src/cli/create/templates/ssg/.gitignore.tpl +25 -0
- package/src/cli/create/templates/ssg/index.html.tpl +1 -1
- package/src/cli/create/templates/ssr/.gitignore.tpl +25 -0
- package/src/cli/create/templates/ssr/cer.config.ts.tpl +0 -1
- package/src/cli/create/templates/ssr/index.html.tpl +1 -1
- package/src/plugin/build-ssr.ts +18 -0
- package/src/plugin/dev-server.ts +1 -1
- package/src/plugin/dts-generator.ts +1 -1
- package/src/plugin/generated-dir.ts +44 -31
- package/src/plugin/index.ts +9 -1
- package/src/plugin/transforms/auto-import.ts +2 -2
- package/src/runtime/app-template.ts +6 -5
- package/src/runtime/composables/index.ts +1 -0
- package/src/runtime/composables/use-inject.ts +49 -0
- package/src/runtime/entry-server-template.ts +20 -0
- package/src/types/config.ts +0 -1
- package/dist/cli/create/templates/spa/app/app.ts.tpl +0 -93
- package/dist/cli/create/templates/ssg/app/app.ts.tpl +0 -97
- package/dist/cli/create/templates/ssr/app/app.ts.tpl +0 -97
- package/src/cli/create/templates/spa/app/app.ts.tpl +0 -93
- package/src/cli/create/templates/ssg/app/app.ts.tpl +0 -97
- package/src/cli/create/templates/ssr/app/app.ts.tpl +0 -97
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import '@jasonshimmy/custom-elements-runtime/css'
|
|
2
|
-
import 'virtual:cer-jit-css'
|
|
3
|
-
import 'virtual:cer-components'
|
|
4
|
-
import routes from 'virtual:cer-routes'
|
|
5
|
-
import layouts from 'virtual:cer-layouts'
|
|
6
|
-
import plugins from 'virtual:cer-plugins'
|
|
7
|
-
import { hasLoading, loadingTag } from 'virtual:cer-loading'
|
|
8
|
-
import { hasError, errorTag } from 'virtual:cer-error'
|
|
9
|
-
import {
|
|
10
|
-
component,
|
|
11
|
-
ref,
|
|
12
|
-
provide,
|
|
13
|
-
useOnConnected,
|
|
14
|
-
useOnDisconnected,
|
|
15
|
-
registerBuiltinComponents,
|
|
16
|
-
} from '@jasonshimmy/custom-elements-runtime'
|
|
17
|
-
import { initRouter } from '@jasonshimmy/custom-elements-runtime/router'
|
|
18
|
-
import { enableJITCSS } from '@jasonshimmy/custom-elements-runtime/jit-css'
|
|
19
|
-
|
|
20
|
-
registerBuiltinComponents()
|
|
21
|
-
enableJITCSS()
|
|
22
|
-
|
|
23
|
-
const router = initRouter({ routes })
|
|
24
|
-
|
|
25
|
-
const isNavigating = ref(false)
|
|
26
|
-
const currentError = ref(null)
|
|
27
|
-
;(globalThis as any).resetError = () => {
|
|
28
|
-
currentError.value = null
|
|
29
|
-
router.replace(router.getCurrent().path)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const _push = router.push.bind(router)
|
|
33
|
-
const _replace = router.replace.bind(router)
|
|
34
|
-
router.push = async (path) => {
|
|
35
|
-
isNavigating.value = true
|
|
36
|
-
currentError.value = null
|
|
37
|
-
try { await _push(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
38
|
-
}
|
|
39
|
-
router.replace = async (path) => {
|
|
40
|
-
isNavigating.value = true
|
|
41
|
-
currentError.value = null
|
|
42
|
-
try { await _replace(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const _pluginProvides = new Map<string, unknown>()
|
|
46
|
-
;(globalThis as any).__cerPluginProvides = _pluginProvides
|
|
47
|
-
|
|
48
|
-
component('cer-layout-view', () => {
|
|
49
|
-
for (const [key, value] of _pluginProvides) {
|
|
50
|
-
provide(key, value)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const current = ref(router.getCurrent())
|
|
54
|
-
let unsub: (() => void) | undefined
|
|
55
|
-
useOnConnected(() => { unsub = router.subscribe((s: typeof current.value) => { current.value = s }) })
|
|
56
|
-
useOnDisconnected(() => { unsub?.(); unsub = undefined })
|
|
57
|
-
|
|
58
|
-
if (currentError.value !== null) {
|
|
59
|
-
if (hasError && errorTag) return { tag: errorTag, props: { attrs: { error: String(currentError.value) } }, children: [] }
|
|
60
|
-
return { tag: 'div', props: { attrs: { style: 'padding:2rem;font-family:monospace' } }, children: String(currentError.value) }
|
|
61
|
-
}
|
|
62
|
-
if (isNavigating.value && hasLoading && loadingTag) return { tag: loadingTag, props: {}, children: [] }
|
|
63
|
-
|
|
64
|
-
const matched = router.matchRoute(current.value.path)
|
|
65
|
-
const layoutName = (matched?.route as any)?.meta?.layout ?? 'default'
|
|
66
|
-
const layoutTag = (layouts as Record<string, string>)[layoutName]
|
|
67
|
-
const routerView = { tag: 'router-view', props: {}, children: [] }
|
|
68
|
-
return layoutTag ? { tag: layoutTag, props: {}, children: [routerView] } : routerView
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
for (const plugin of plugins) {
|
|
72
|
-
if (plugin && typeof plugin.setup === 'function') {
|
|
73
|
-
await plugin.setup({ router, provide: (key: string, value: unknown) => { _pluginProvides.set(key, value) }, config: {} })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Pre-load the current page's route chunk AFTER plugins run so that
|
|
78
|
-
// cer-layout-view's first render (which calls provide()) completes before
|
|
79
|
-
// page components are defined. This ensures inject() in child components
|
|
80
|
-
// can find values stored by provide().
|
|
81
|
-
if (typeof window !== 'undefined') {
|
|
82
|
-
const _initMatch = router.matchRoute(window.location.pathname)
|
|
83
|
-
if (_initMatch?.route?.load) {
|
|
84
|
-
try { await _initMatch.route.load() } catch { /* non-fatal */ }
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof window !== 'undefined') {
|
|
89
|
-
// Use the original (unwrapped) replace so isNavigating stays false on first paint.
|
|
90
|
-
await _replace(window.location.pathname + window.location.search + window.location.hash)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { router }
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import '@jasonshimmy/custom-elements-runtime/css'
|
|
2
|
-
import 'virtual:cer-jit-css'
|
|
3
|
-
import 'virtual:cer-components'
|
|
4
|
-
import routes from 'virtual:cer-routes'
|
|
5
|
-
import layouts from 'virtual:cer-layouts'
|
|
6
|
-
import plugins from 'virtual:cer-plugins'
|
|
7
|
-
import { hasLoading, loadingTag } from 'virtual:cer-loading'
|
|
8
|
-
import { hasError, errorTag } from 'virtual:cer-error'
|
|
9
|
-
import {
|
|
10
|
-
component,
|
|
11
|
-
ref,
|
|
12
|
-
provide,
|
|
13
|
-
useOnConnected,
|
|
14
|
-
useOnDisconnected,
|
|
15
|
-
registerBuiltinComponents,
|
|
16
|
-
} from '@jasonshimmy/custom-elements-runtime'
|
|
17
|
-
import { initRouter } from '@jasonshimmy/custom-elements-runtime/router'
|
|
18
|
-
import { enableJITCSS } from '@jasonshimmy/custom-elements-runtime/jit-css'
|
|
19
|
-
|
|
20
|
-
registerBuiltinComponents()
|
|
21
|
-
enableJITCSS()
|
|
22
|
-
|
|
23
|
-
const router = initRouter({ routes })
|
|
24
|
-
|
|
25
|
-
const isNavigating = ref(false)
|
|
26
|
-
const currentError = ref(null)
|
|
27
|
-
;(globalThis as any).resetError = () => {
|
|
28
|
-
currentError.value = null
|
|
29
|
-
router.replace(router.getCurrent().path)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const _push = router.push.bind(router)
|
|
33
|
-
const _replace = router.replace.bind(router)
|
|
34
|
-
router.push = async (path) => {
|
|
35
|
-
isNavigating.value = true
|
|
36
|
-
currentError.value = null
|
|
37
|
-
try { await _push(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
38
|
-
}
|
|
39
|
-
router.replace = async (path) => {
|
|
40
|
-
isNavigating.value = true
|
|
41
|
-
currentError.value = null
|
|
42
|
-
try { await _replace(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const _pluginProvides = new Map<string, unknown>()
|
|
46
|
-
;(globalThis as any).__cerPluginProvides = _pluginProvides
|
|
47
|
-
|
|
48
|
-
component('cer-layout-view', () => {
|
|
49
|
-
for (const [key, value] of _pluginProvides) {
|
|
50
|
-
provide(key, value)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const current = ref(router.getCurrent())
|
|
54
|
-
let unsub: (() => void) | undefined
|
|
55
|
-
useOnConnected(() => { unsub = router.subscribe((s: typeof current.value) => { current.value = s }) })
|
|
56
|
-
useOnDisconnected(() => { unsub?.(); unsub = undefined })
|
|
57
|
-
|
|
58
|
-
if (currentError.value !== null) {
|
|
59
|
-
if (hasError && errorTag) return { tag: errorTag, props: { attrs: { error: String(currentError.value) } }, children: [] }
|
|
60
|
-
return { tag: 'div', props: { attrs: { style: 'padding:2rem;font-family:monospace' } }, children: String(currentError.value) }
|
|
61
|
-
}
|
|
62
|
-
if (isNavigating.value && hasLoading && loadingTag) return { tag: loadingTag, props: {}, children: [] }
|
|
63
|
-
|
|
64
|
-
const matched = router.matchRoute(current.value.path)
|
|
65
|
-
const layoutName = (matched?.route as any)?.meta?.layout ?? 'default'
|
|
66
|
-
const layoutTag = (layouts as Record<string, string>)[layoutName]
|
|
67
|
-
const routerView = { tag: 'router-view', props: {}, children: [] }
|
|
68
|
-
return layoutTag ? { tag: layoutTag, props: {}, children: [routerView] } : routerView
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
for (const plugin of plugins) {
|
|
72
|
-
if (plugin && typeof plugin.setup === 'function') {
|
|
73
|
-
await plugin.setup({ router, provide: (key: string, value: unknown) => { _pluginProvides.set(key, value) }, config: {} })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Pre-load the current page's route chunk AFTER plugins run so that
|
|
78
|
-
// cer-layout-view's first render (which calls provide()) completes before
|
|
79
|
-
// page components are defined. This ensures inject() in child components
|
|
80
|
-
// can find values stored by provide().
|
|
81
|
-
if (typeof window !== 'undefined') {
|
|
82
|
-
const _initMatch = router.matchRoute(window.location.pathname)
|
|
83
|
-
if (_initMatch?.route?.load) {
|
|
84
|
-
try { await _initMatch.route.load() } catch { /* non-fatal */ }
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof window !== 'undefined') {
|
|
89
|
-
// Use the original (unwrapped) replace so isNavigating stays false on first
|
|
90
|
-
// paint — the loading component must not flash over pre-rendered SSG content.
|
|
91
|
-
await _replace(window.location.pathname + window.location.search + window.location.hash)
|
|
92
|
-
// Clear SSR hydration data after initial navigation so subsequent navigations
|
|
93
|
-
// don't accidentally reuse it.
|
|
94
|
-
delete (globalThis as any).__CER_DATA__
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export { router }
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import '@jasonshimmy/custom-elements-runtime/css'
|
|
2
|
-
import 'virtual:cer-jit-css'
|
|
3
|
-
import 'virtual:cer-components'
|
|
4
|
-
import routes from 'virtual:cer-routes'
|
|
5
|
-
import layouts from 'virtual:cer-layouts'
|
|
6
|
-
import plugins from 'virtual:cer-plugins'
|
|
7
|
-
import { hasLoading, loadingTag } from 'virtual:cer-loading'
|
|
8
|
-
import { hasError, errorTag } from 'virtual:cer-error'
|
|
9
|
-
import {
|
|
10
|
-
component,
|
|
11
|
-
ref,
|
|
12
|
-
provide,
|
|
13
|
-
useOnConnected,
|
|
14
|
-
useOnDisconnected,
|
|
15
|
-
registerBuiltinComponents,
|
|
16
|
-
} from '@jasonshimmy/custom-elements-runtime'
|
|
17
|
-
import { initRouter } from '@jasonshimmy/custom-elements-runtime/router'
|
|
18
|
-
import { enableJITCSS } from '@jasonshimmy/custom-elements-runtime/jit-css'
|
|
19
|
-
|
|
20
|
-
registerBuiltinComponents()
|
|
21
|
-
enableJITCSS()
|
|
22
|
-
|
|
23
|
-
const router = initRouter({ routes })
|
|
24
|
-
|
|
25
|
-
const isNavigating = ref(false)
|
|
26
|
-
const currentError = ref(null)
|
|
27
|
-
;(globalThis as any).resetError = () => {
|
|
28
|
-
currentError.value = null
|
|
29
|
-
router.replace(router.getCurrent().path)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const _push = router.push.bind(router)
|
|
33
|
-
const _replace = router.replace.bind(router)
|
|
34
|
-
router.push = async (path) => {
|
|
35
|
-
isNavigating.value = true
|
|
36
|
-
currentError.value = null
|
|
37
|
-
try { await _push(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
38
|
-
}
|
|
39
|
-
router.replace = async (path) => {
|
|
40
|
-
isNavigating.value = true
|
|
41
|
-
currentError.value = null
|
|
42
|
-
try { await _replace(path) } catch (err) { currentError.value = err instanceof Error ? err.message : String(err) } finally { isNavigating.value = false }
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const _pluginProvides = new Map<string, unknown>()
|
|
46
|
-
;(globalThis as any).__cerPluginProvides = _pluginProvides
|
|
47
|
-
|
|
48
|
-
component('cer-layout-view', () => {
|
|
49
|
-
for (const [key, value] of _pluginProvides) {
|
|
50
|
-
provide(key, value)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const current = ref(router.getCurrent())
|
|
54
|
-
let unsub: (() => void) | undefined
|
|
55
|
-
useOnConnected(() => { unsub = router.subscribe((s: typeof current.value) => { current.value = s }) })
|
|
56
|
-
useOnDisconnected(() => { unsub?.(); unsub = undefined })
|
|
57
|
-
|
|
58
|
-
if (currentError.value !== null) {
|
|
59
|
-
if (hasError && errorTag) return { tag: errorTag, props: { attrs: { error: String(currentError.value) } }, children: [] }
|
|
60
|
-
return { tag: 'div', props: { attrs: { style: 'padding:2rem;font-family:monospace' } }, children: String(currentError.value) }
|
|
61
|
-
}
|
|
62
|
-
if (isNavigating.value && hasLoading && loadingTag) return { tag: loadingTag, props: {}, children: [] }
|
|
63
|
-
|
|
64
|
-
const matched = router.matchRoute(current.value.path)
|
|
65
|
-
const layoutName = (matched?.route as any)?.meta?.layout ?? 'default'
|
|
66
|
-
const layoutTag = (layouts as Record<string, string>)[layoutName]
|
|
67
|
-
const routerView = { tag: 'router-view', props: {}, children: [] }
|
|
68
|
-
return layoutTag ? { tag: layoutTag, props: {}, children: [routerView] } : routerView
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
for (const plugin of plugins) {
|
|
72
|
-
if (plugin && typeof plugin.setup === 'function') {
|
|
73
|
-
await plugin.setup({ router, provide: (key: string, value: unknown) => { _pluginProvides.set(key, value) }, config: {} })
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// Pre-load the current page's route chunk AFTER plugins run so that
|
|
78
|
-
// cer-layout-view's first render (which calls provide()) completes before
|
|
79
|
-
// page components are defined. This ensures inject() in child components
|
|
80
|
-
// can find values stored by provide().
|
|
81
|
-
if (typeof window !== 'undefined') {
|
|
82
|
-
const _initMatch = router.matchRoute(window.location.pathname)
|
|
83
|
-
if (_initMatch?.route?.load) {
|
|
84
|
-
try { await _initMatch.route.load() } catch { /* non-fatal */ }
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
if (typeof window !== 'undefined') {
|
|
89
|
-
// Use the original (unwrapped) replace so isNavigating stays false on first
|
|
90
|
-
// paint — the loading component must not flash over pre-rendered SSR content.
|
|
91
|
-
await _replace(window.location.pathname + window.location.search + window.location.hash)
|
|
92
|
-
// Clear SSR hydration data after initial navigation so subsequent navigations
|
|
93
|
-
// don't accidentally reuse it.
|
|
94
|
-
delete (globalThis as any).__CER_DATA__
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export { router }
|