@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.
Files changed (93) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +2 -0
  3. package/commits.txt +1 -1
  4. package/dist/cli/create/index.js +7 -3
  5. package/dist/cli/create/index.js.map +1 -1
  6. package/dist/cli/create/templates/spa/.gitignore.tpl +25 -0
  7. package/dist/cli/create/templates/spa/index.html.tpl +1 -1
  8. package/dist/cli/create/templates/ssg/.gitignore.tpl +25 -0
  9. package/dist/cli/create/templates/ssg/index.html.tpl +1 -1
  10. package/dist/cli/create/templates/ssr/.gitignore.tpl +25 -0
  11. package/dist/cli/create/templates/ssr/cer.config.ts.tpl +0 -1
  12. package/dist/cli/create/templates/ssr/index.html.tpl +1 -1
  13. package/dist/plugin/build-ssr.d.ts.map +1 -1
  14. package/dist/plugin/build-ssr.js +18 -0
  15. package/dist/plugin/build-ssr.js.map +1 -1
  16. package/dist/plugin/dev-server.d.ts +0 -1
  17. package/dist/plugin/dev-server.d.ts.map +1 -1
  18. package/dist/plugin/dts-generator.js +1 -1
  19. package/dist/plugin/dts-generator.js.map +1 -1
  20. package/dist/plugin/generated-dir.d.ts +5 -11
  21. package/dist/plugin/generated-dir.d.ts.map +1 -1
  22. package/dist/plugin/generated-dir.js +43 -31
  23. package/dist/plugin/generated-dir.js.map +1 -1
  24. package/dist/plugin/index.d.ts.map +1 -1
  25. package/dist/plugin/index.js +9 -1
  26. package/dist/plugin/index.js.map +1 -1
  27. package/dist/plugin/transforms/auto-import.js +2 -2
  28. package/dist/plugin/transforms/auto-import.js.map +1 -1
  29. package/dist/runtime/app-template.d.ts +5 -4
  30. package/dist/runtime/app-template.d.ts.map +1 -1
  31. package/dist/runtime/app-template.js +6 -5
  32. package/dist/runtime/app-template.js.map +1 -1
  33. package/dist/runtime/composables/index.d.ts +1 -0
  34. package/dist/runtime/composables/index.d.ts.map +1 -1
  35. package/dist/runtime/composables/index.js +1 -0
  36. package/dist/runtime/composables/index.js.map +1 -1
  37. package/dist/runtime/composables/use-inject.d.ts +29 -0
  38. package/dist/runtime/composables/use-inject.d.ts.map +1 -0
  39. package/dist/runtime/composables/use-inject.js +48 -0
  40. package/dist/runtime/composables/use-inject.js.map +1 -0
  41. package/dist/runtime/entry-server-template.d.ts +1 -1
  42. package/dist/runtime/entry-server-template.d.ts.map +1 -1
  43. package/dist/runtime/entry-server-template.js +20 -0
  44. package/dist/runtime/entry-server-template.js.map +1 -1
  45. package/dist/types/config.d.ts +0 -1
  46. package/dist/types/config.d.ts.map +1 -1
  47. package/dist/types/config.js.map +1 -1
  48. package/docs/cli.md +1 -1
  49. package/docs/composables.md +37 -0
  50. package/docs/configuration.md +2 -11
  51. package/docs/getting-started.md +2 -100
  52. package/docs/plugins.md +23 -15
  53. package/docs/rendering-modes.md +3 -4
  54. package/docs/testing.md +3 -3
  55. package/e2e/kitchen-sink/app/pages/(auth)/protected.ts +1 -5
  56. package/e2e/kitchen-sink/cer-auto-imports.d.ts +1 -0
  57. package/package.json +1 -1
  58. package/src/__tests__/plugin/build-ssr.test.ts +10 -0
  59. package/src/__tests__/plugin/cer-app-plugin.test.ts +15 -0
  60. package/src/__tests__/plugin/dev-server.test.ts +1 -1
  61. package/src/__tests__/plugin/dts-generator.test.ts +5 -0
  62. package/src/__tests__/plugin/entry-server-template.test.ts +24 -0
  63. package/src/__tests__/plugin/generated-dir.test.ts +8 -39
  64. package/src/__tests__/plugin/resolve-config.test.ts +0 -5
  65. package/src/__tests__/plugin/transforms/auto-import.test.ts +7 -0
  66. package/src/__tests__/runtime/use-inject-client.test.ts +67 -0
  67. package/src/__tests__/runtime/use-inject.test.ts +66 -0
  68. package/src/__tests__/types/config.test.ts +1 -1
  69. package/src/cli/create/index.ts +12 -8
  70. package/src/cli/create/templates/spa/.gitignore.tpl +25 -0
  71. package/src/cli/create/templates/spa/index.html.tpl +1 -1
  72. package/src/cli/create/templates/ssg/.gitignore.tpl +25 -0
  73. package/src/cli/create/templates/ssg/index.html.tpl +1 -1
  74. package/src/cli/create/templates/ssr/.gitignore.tpl +25 -0
  75. package/src/cli/create/templates/ssr/cer.config.ts.tpl +0 -1
  76. package/src/cli/create/templates/ssr/index.html.tpl +1 -1
  77. package/src/plugin/build-ssr.ts +18 -0
  78. package/src/plugin/dev-server.ts +1 -1
  79. package/src/plugin/dts-generator.ts +1 -1
  80. package/src/plugin/generated-dir.ts +44 -31
  81. package/src/plugin/index.ts +9 -1
  82. package/src/plugin/transforms/auto-import.ts +2 -2
  83. package/src/runtime/app-template.ts +6 -5
  84. package/src/runtime/composables/index.ts +1 -0
  85. package/src/runtime/composables/use-inject.ts +49 -0
  86. package/src/runtime/entry-server-template.ts +20 -0
  87. package/src/types/config.ts +0 -1
  88. package/dist/cli/create/templates/spa/app/app.ts.tpl +0 -93
  89. package/dist/cli/create/templates/ssg/app/app.ts.tpl +0 -97
  90. package/dist/cli/create/templates/ssr/app/app.ts.tpl +0 -97
  91. package/src/cli/create/templates/spa/app/app.ts.tpl +0 -93
  92. package/src/cli/create/templates/ssg/app/app.ts.tpl +0 -97
  93. 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 }