polen 0.9.0-next.2 → 0.9.0-next.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/build/api/server/report-error.d.ts +2 -0
- package/build/api/server/report-error.d.ts.map +1 -0
- package/build/api/server/report-error.js +47 -0
- package/build/api/server/report-error.js.map +1 -0
- package/build/api/vite/data/navbar.d.ts +9 -0
- package/build/api/vite/data/navbar.d.ts.map +1 -0
- package/build/api/vite/data/navbar.js +6 -0
- package/build/api/vite/data/navbar.js.map +1 -0
- package/build/api/vite/plugins/core.d.ts.map +1 -1
- package/build/api/vite/plugins/core.js +36 -104
- package/build/api/vite/plugins/core.js.map +1 -1
- package/build/api/vite/plugins/pages.d.ts +25 -0
- package/build/api/vite/plugins/pages.d.ts.map +1 -0
- package/build/api/vite/plugins/pages.js +273 -0
- package/build/api/vite/plugins/pages.js.map +1 -0
- package/build/api/vite/plugins/serve.d.ts.map +1 -1
- package/build/api/vite/plugins/serve.js +5 -26
- package/build/api/vite/plugins/serve.js.map +1 -1
- package/build/cli/commands/dev.js +9 -1
- package/build/cli/commands/dev.js.map +1 -1
- package/build/lib/debug/environment-variable.d.ts +1 -0
- package/build/lib/debug/environment-variable.d.ts.map +1 -1
- package/build/lib/debug/environment-variable.js +30 -15
- package/build/lib/debug/environment-variable.js.map +1 -1
- package/build/lib/extensible-data/extensible-data.d.ts +17 -0
- package/build/lib/extensible-data/extensible-data.d.ts.map +1 -0
- package/build/lib/extensible-data/extensible-data.js +24 -0
- package/build/lib/extensible-data/extensible-data.js.map +1 -0
- package/build/lib/extensible-data/index.d.ts +2 -0
- package/build/lib/extensible-data/index.d.ts.map +1 -0
- package/build/lib/extensible-data/index.js +2 -0
- package/build/lib/extensible-data/index.js.map +1 -0
- package/build/lib/kit-temp.d.ts +2 -0
- package/build/lib/kit-temp.d.ts.map +1 -1
- package/build/lib/kit-temp.js +10 -1
- package/build/lib/kit-temp.js.map +1 -1
- package/build/lib/react-router-loader/react-router-loader.d.ts.map +1 -1
- package/build/lib/react-router-loader/react-router-loader.js +0 -1
- package/build/lib/react-router-loader/react-router-loader.js.map +1 -1
- package/build/lib/vite-plugin-json/index.d.ts +2 -0
- package/build/lib/vite-plugin-json/index.d.ts.map +1 -0
- package/build/lib/vite-plugin-json/index.js +2 -0
- package/build/lib/vite-plugin-json/index.js.map +1 -0
- package/build/lib/vite-plugin-json/vite-plugin-json.d.ts +64 -0
- package/build/lib/vite-plugin-json/vite-plugin-json.d.ts.map +1 -0
- package/build/lib/vite-plugin-json/vite-plugin-json.js +59 -0
- package/build/lib/vite-plugin-json/vite-plugin-json.js.map +1 -0
- package/build/lib/vite-plugin-reactive-data/index.d.ts +2 -0
- package/build/lib/vite-plugin-reactive-data/index.d.ts.map +1 -0
- package/build/lib/vite-plugin-reactive-data/index.js +2 -0
- package/build/lib/vite-plugin-reactive-data/index.js.map +1 -0
- package/build/lib/vite-plugin-reactive-data/vite-plugin-reactive-data.d.ts +39 -0
- package/build/lib/vite-plugin-reactive-data/vite-plugin-reactive-data.d.ts.map +1 -0
- package/build/lib/vite-plugin-reactive-data/vite-plugin-reactive-data.js +92 -0
- package/build/lib/vite-plugin-reactive-data/vite-plugin-reactive-data.js.map +1 -0
- package/build/lib/vite-plugins/build-logger.d.ts.map +1 -1
- package/build/lib/vite-plugins/build-logger.js +9 -8
- package/build/lib/vite-plugins/build-logger.js.map +1 -1
- package/build/project-data.d.ts +0 -11
- package/build/project-data.d.ts.map +1 -1
- package/build/template/components/Link.d.ts.map +1 -1
- package/build/template/components/Link.jsx +4 -3
- package/build/template/components/Link.jsx.map +1 -1
- package/build/template/routes/changelog.jsx +1 -1
- package/build/template/routes/changelog.jsx.map +1 -1
- package/build/template/routes/reference.jsx +1 -1
- package/build/template/routes/reference.jsx.map +1 -1
- package/build/template/routes/root.d.ts.map +1 -1
- package/build/template/routes/root.jsx +5 -3
- package/build/template/routes/root.jsx.map +1 -1
- package/build/template/server/app.js +1 -1
- package/build/template/server/app.js.map +1 -1
- package/build/template/server/render-page.d.ts.map +1 -1
- package/build/template/server/render-page.jsx +4 -1
- package/build/template/server/render-page.jsx.map +1 -1
- package/build/template/server/ssg/generate.js +1 -1
- package/build/template/server/ssg/generate.js.map +1 -1
- package/build/template/server/ssg/get-route-paths.js +1 -1
- package/build/template/server/ssg/get-route-paths.js.map +1 -1
- package/package.json +3 -1
- package/src/api/server/report-error.ts +61 -0
- package/src/api/vite/data/navbar.ts +15 -0
- package/src/api/vite/plugins/core.ts +38 -116
- package/src/api/vite/plugins/pages.ts +332 -0
- package/src/api/vite/plugins/serve.ts +5 -26
- package/src/cli/commands/dev.ts +9 -1
- package/src/lib/debug/environment-variable.ts +31 -14
- package/src/lib/extensible-data/extensible-data.ts +38 -0
- package/src/lib/extensible-data/index.ts +1 -0
- package/src/lib/kit-temp.ts +12 -1
- package/src/lib/react-router-loader/react-router-loader.ts +0 -1
- package/src/lib/vite-plugin-json/index.ts +1 -0
- package/src/lib/vite-plugin-json/vite-plugin-json.ts +128 -0
- package/src/lib/vite-plugin-reactive-data/index.ts +1 -0
- package/src/lib/vite-plugin-reactive-data/vite-plugin-reactive-data.ts +131 -0
- package/src/lib/vite-plugins/build-logger.ts +10 -8
- package/src/project-data.ts +0 -13
- package/src/template/components/Link.tsx +6 -3
- package/src/template/routes/changelog.tsx +1 -1
- package/src/template/routes/reference.tsx +1 -1
- package/src/template/routes/root.tsx +5 -3
- package/src/template/server/app.ts +1 -1
- package/src/template/server/render-page.tsx +4 -1
- package/src/template/server/ssg/generate.ts +1 -1
- package/src/template/server/ssg/get-route-paths.ts +1 -1
- package/build/api/vite/plugins/pages-tree.d.ts +0 -16
- package/build/api/vite/plugins/pages-tree.d.ts.map +0 -1
- package/build/api/vite/plugins/pages-tree.js +0 -153
- package/build/api/vite/plugins/pages-tree.js.map +0 -1
- package/src/api/vite/plugins/pages-tree.ts +0 -187
@@ -2,6 +2,7 @@ import { Arr, Language } from '@wollybeard/kit'
|
|
2
2
|
|
3
3
|
export const enVarName = `DEBUG`
|
4
4
|
|
5
|
+
export const deliminator = `,`
|
5
6
|
export const wildcard = `*`
|
6
7
|
export const enVarEnabledValuesStatic = [`true`, wildcard, `1`]
|
7
8
|
|
@@ -10,29 +11,45 @@ export const calcIsEnabledFromEnv = (
|
|
10
11
|
namespace?: string[],
|
11
12
|
): boolean => {
|
12
13
|
const namespace_ = namespace?.map(_ => _.toLowerCase())
|
13
|
-
|
14
|
+
|
15
|
+
const includeFilters = typeof enVars[enVarName] === `string`
|
14
16
|
? enVars[enVarName]
|
15
17
|
.trim()
|
16
18
|
.toLowerCase()
|
17
|
-
.split(
|
18
|
-
.map(
|
19
|
+
.split(deliminator)
|
20
|
+
.map(patternExpression => {
|
21
|
+
return patternExpression
|
22
|
+
.trim()
|
23
|
+
.split(`:`)
|
24
|
+
.map(_ => _.trim())
|
25
|
+
})
|
19
26
|
: undefined
|
20
27
|
|
21
|
-
if (!
|
28
|
+
if (!includeFilters) return false
|
22
29
|
|
23
|
-
if (
|
30
|
+
if (includeFilters.length === 0) return false
|
24
31
|
|
25
|
-
|
32
|
+
// If any is like * then it means "enable everything"
|
33
|
+
if (
|
34
|
+
includeFilters.some(includeFilter => {
|
35
|
+
if (includeFilter.length === 1 && enVarEnabledValuesStatic.includes(includeFilter[0]!)) return true
|
36
|
+
})
|
37
|
+
) return true
|
26
38
|
|
27
|
-
if (
|
28
|
-
|
29
|
-
}
|
39
|
+
// At this point, if there is no namespace (e.g. root), then we cannot match anything
|
40
|
+
if (!namespace_) return false
|
30
41
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
42
|
+
for (const includeFilter of includeFilters) {
|
43
|
+
if (Arr.getLast(includeFilter) !== wildcard) {
|
44
|
+
return includeFilter.join() === namespace_.join()
|
45
|
+
}
|
46
|
+
|
47
|
+
let i = 0
|
48
|
+
for (const segment of includeFilter) {
|
49
|
+
if (segment === wildcard) return true
|
50
|
+
if (segment !== namespace_[i]) return false
|
51
|
+
i++
|
52
|
+
}
|
36
53
|
}
|
37
54
|
|
38
55
|
Language.never()
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { computed, reactive } from '@vue/reactivity'
|
2
|
+
import type { ComputedRef, UnwrapRefSimple } from '@vue/reactivity'
|
3
|
+
|
4
|
+
type Join<$Data> = (chunks: $Data[]) => $Data
|
5
|
+
type Create<$Data> = () => $Data
|
6
|
+
|
7
|
+
interface DataTypeOperations<$Data> {
|
8
|
+
join: Join<$Data>
|
9
|
+
create: Create<$Data>
|
10
|
+
}
|
11
|
+
|
12
|
+
export const create = <$Data extends object = object>(dataTypeOperations: DataTypeOperations<$Data>) => {
|
13
|
+
return new ExtensibleData<$Data>(dataTypeOperations)
|
14
|
+
}
|
15
|
+
|
16
|
+
export class ExtensibleData<$Data extends object = object> {
|
17
|
+
public value: ComputedRef<$Data> = computed(() => {
|
18
|
+
const namespacedDataItems = Array.from(this.namespacedReactiveData.values())
|
19
|
+
const data = this.dataTypeOperations.join(namespacedDataItems as $Data[])
|
20
|
+
return data
|
21
|
+
})
|
22
|
+
|
23
|
+
private namespacedReactiveData = reactive(new Map<string, $Data>())
|
24
|
+
|
25
|
+
private dataTypeOperations: DataTypeOperations<$Data>
|
26
|
+
|
27
|
+
constructor(dataTypeOperations: DataTypeOperations<$Data>) {
|
28
|
+
this.dataTypeOperations = dataTypeOperations
|
29
|
+
}
|
30
|
+
|
31
|
+
get(namespace: string): $Data {
|
32
|
+
if (!this.namespacedReactiveData.has(namespace)) {
|
33
|
+
const data = this.dataTypeOperations.create()
|
34
|
+
this.namespacedReactiveData.set(namespace, data as UnwrapRefSimple<$Data>)
|
35
|
+
}
|
36
|
+
return this.namespacedReactiveData.get(namespace)! as $Data
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as ExtensibleData from './extensible-data.ts'
|
package/src/lib/kit-temp.ts
CHANGED
@@ -12,7 +12,7 @@
|
|
12
12
|
//
|
13
13
|
//
|
14
14
|
|
15
|
-
import { Fs, Path, Undefined } from '@wollybeard/kit'
|
15
|
+
import { Fs, Http, Path, Undefined } from '@wollybeard/kit'
|
16
16
|
import type { ResolveHookContext } from 'node:module'
|
17
17
|
|
18
18
|
export const arrayEquals = (a: any[], b: any[]) => {
|
@@ -95,3 +95,14 @@ export const ObjPartition = <T extends object, K extends keyof T>(
|
|
95
95
|
picked: {} as Pick<T, K>,
|
96
96
|
})
|
97
97
|
}
|
98
|
+
|
99
|
+
export const ensureEnd = (string: string, ending: string) => {
|
100
|
+
if (string.endsWith(ending)) return string
|
101
|
+
return string + ending
|
102
|
+
}
|
103
|
+
|
104
|
+
export const ResponseInternalServerError = () =>
|
105
|
+
new Response(null, {
|
106
|
+
status: Http.Status.InternalServerError.code,
|
107
|
+
statusText: Http.Status.InternalServerError.description,
|
108
|
+
})
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as VitePluginJson from './vite-plugin-json.ts'
|
@@ -0,0 +1,128 @@
|
|
1
|
+
import jsesc from 'jsesc'
|
2
|
+
// import { id,or,exclude } from 'rolldown/filter'
|
3
|
+
import {} from '@rolldown/pluginutils'
|
4
|
+
import type { Plugin } from 'vite'
|
5
|
+
|
6
|
+
export interface Codec {
|
7
|
+
stringify(value: any): string
|
8
|
+
parse(text: string): any
|
9
|
+
}
|
10
|
+
|
11
|
+
export interface VitePluginJsonImportsOptions {
|
12
|
+
/**
|
13
|
+
* Use a custom codec.
|
14
|
+
*/
|
15
|
+
codec?: {
|
16
|
+
/**
|
17
|
+
* Import path for the custom codec to use in generated code.
|
18
|
+
*
|
19
|
+
* Must be a package name or use a path alias.
|
20
|
+
*
|
21
|
+
* Examples:
|
22
|
+
* - '@my-org/my-codec' (npm package)
|
23
|
+
* - '#utils/codec' (package subpath)
|
24
|
+
* - 'my-codec' (npm package)
|
25
|
+
* - '~/utils/codec' (if ~ is aliased in vite config)
|
26
|
+
*/
|
27
|
+
importPath: string
|
28
|
+
/**
|
29
|
+
* Custom codec for validation and runtime parsing
|
30
|
+
* The codec.parse() is used at build time to validate the JSON
|
31
|
+
* The codec will be imported in the generated code for runtime parsing
|
32
|
+
* @default JSON
|
33
|
+
*/
|
34
|
+
validate?: Codec
|
35
|
+
/**
|
36
|
+
* The export (its name) to import.
|
37
|
+
*
|
38
|
+
* @default 'default'
|
39
|
+
*/
|
40
|
+
importExport?: string
|
41
|
+
}
|
42
|
+
filter?: {
|
43
|
+
/**
|
44
|
+
* Module types to process (the file extension without the dot).
|
45
|
+
* @default ['json']
|
46
|
+
*/
|
47
|
+
moduleTypes?: string[]
|
48
|
+
/**
|
49
|
+
* Picomatch patterns to include
|
50
|
+
* @default includes all files with configured extensions
|
51
|
+
*/
|
52
|
+
id?: {
|
53
|
+
include?: string | string[]
|
54
|
+
/**
|
55
|
+
* Picomatch patterns to exclude
|
56
|
+
* @default excludes node_modules and files with \0 prefix
|
57
|
+
*/
|
58
|
+
exclude?: string | string[]
|
59
|
+
}
|
60
|
+
}
|
61
|
+
/**
|
62
|
+
* Plugin name. Useful to customize if providing a custom codec e.g. `superjson`.
|
63
|
+
*
|
64
|
+
* @default 'json'
|
65
|
+
*/
|
66
|
+
name?: string
|
67
|
+
}
|
68
|
+
|
69
|
+
export const create = (options: VitePluginJsonImportsOptions = {}): Plugin => {
|
70
|
+
const codec = options.codec?.validate ?? JSON
|
71
|
+
const codecImportExport = options.codec?.importExport ?? `default`
|
72
|
+
|
73
|
+
const pluginName = options.name ?? `json-imports`
|
74
|
+
|
75
|
+
// Always exclude \0 prefixed modules
|
76
|
+
// eslint-disable-next-line no-control-regex
|
77
|
+
const baseExcludePatterns: (string | RegExp)[] = [/^\0/]
|
78
|
+
const moduleTypes = options.filter?.moduleTypes ?? [`json`]
|
79
|
+
const isCustomCodec = Boolean(options.codec?.importPath)
|
80
|
+
|
81
|
+
// Check if we should handle this file based on extension
|
82
|
+
const shouldHandle = (id: string) => {
|
83
|
+
// Exclude internal modules with \0 prefix
|
84
|
+
if (id.startsWith('\0')) return false
|
85
|
+
|
86
|
+
// Check if it has one of our configured extensions
|
87
|
+
return moduleTypes.some(type => id.endsWith(`.${type}`))
|
88
|
+
}
|
89
|
+
|
90
|
+
return {
|
91
|
+
name: pluginName,
|
92
|
+
enforce: 'pre' as const,
|
93
|
+
// Transform files based on extension
|
94
|
+
transform(code, id) {
|
95
|
+
if (!shouldHandle(id)) return
|
96
|
+
|
97
|
+
try {
|
98
|
+
// Skip validation for superjson since the codec validates the envelope format
|
99
|
+
if (options.codec?.validate && !options.codec.importPath?.includes('superjson')) {
|
100
|
+
codec.parse(code)
|
101
|
+
}
|
102
|
+
|
103
|
+
if (!isCustomCodec) {
|
104
|
+
// For native JSON, directly export as JavaScript object literal
|
105
|
+
return `export default ${code}`
|
106
|
+
} else {
|
107
|
+
// For custom codecs, we need to parse at runtime
|
108
|
+
if (!options.codec?.importPath) {
|
109
|
+
throw new Error(`codec.importPath is required when using a custom codec`)
|
110
|
+
}
|
111
|
+
|
112
|
+
const importIdentifier = codecImportExport === `default` ? `codec` : codecImportExport
|
113
|
+
const importStatement = codecImportExport === `default`
|
114
|
+
? `import ${importIdentifier} from '${options.codec.importPath}'`
|
115
|
+
: `import { ${codecImportExport} } from '${options.codec.importPath}'`
|
116
|
+
|
117
|
+
return `
|
118
|
+
${importStatement}
|
119
|
+
const data = ${importIdentifier}.parse('${jsesc(code)}')
|
120
|
+
export { data as default }`
|
121
|
+
}
|
122
|
+
} catch (error) {
|
123
|
+
const message = error instanceof Error ? error.message : String(error)
|
124
|
+
this.error(`Failed to parse JSON in ${id}: ${message}`)
|
125
|
+
}
|
126
|
+
},
|
127
|
+
}
|
128
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export * as VitePluginReactiveData from './vite-plugin-reactive-data.ts'
|
@@ -0,0 +1,131 @@
|
|
1
|
+
import { ensureEnd } from '#lib/kit-temp'
|
2
|
+
import { VitePluginJson } from '#lib/vite-plugin-json/index'
|
3
|
+
import { superjson } from '#singletons/superjson'
|
4
|
+
import { type ComputedRef, effect, isRef } from '@vue/reactivity'
|
5
|
+
import { Debug } from '@wollybeard/kit'
|
6
|
+
import type { Plugin, ViteDevServer } from 'vite'
|
7
|
+
|
8
|
+
interface ReactiveDataOptions {
|
9
|
+
/**
|
10
|
+
* Virtual module ID (e.g., 'virtual:polen/navbar') that this data will be exported from.
|
11
|
+
* The appropriate extension will be appended automatically based on moduleType.
|
12
|
+
*/
|
13
|
+
moduleId: string
|
14
|
+
/**
|
15
|
+
* The reactive data to expose.
|
16
|
+
* Can be either:
|
17
|
+
* - A Vue computed ref (recommended)
|
18
|
+
* - A function that returns reactive data
|
19
|
+
* - A reactive value directly
|
20
|
+
*/
|
21
|
+
data: ComputedRef<object | unknown[]> | (() => object | unknown[]) | object | unknown[]
|
22
|
+
/** Debounce updates (ms). If not set, uses process.nextTick for batching */
|
23
|
+
debounce?: number
|
24
|
+
/**
|
25
|
+
* JSON codec to use (e.g., superjson)
|
26
|
+
* Default: superjson
|
27
|
+
* Only used when includeJsonPlugin is true
|
28
|
+
*/
|
29
|
+
codec?: VitePluginJson.Codec
|
30
|
+
/**
|
31
|
+
* Custom plugin name. Can use to help identify this plugin in logs if using many instances of this plugin.
|
32
|
+
@default 'reactive-data'
|
33
|
+
*/
|
34
|
+
name?: string
|
35
|
+
/**
|
36
|
+
* Module type to return. Default: 'json'
|
37
|
+
* Use 'superjson' to avoid conflicts with built-in JSON plugin
|
38
|
+
*/
|
39
|
+
moduleType?: string
|
40
|
+
}
|
41
|
+
|
42
|
+
const debug = Debug.create('vite-plugin-reactive-data')
|
43
|
+
|
44
|
+
export const create = (options: ReactiveDataOptions): Plugin => {
|
45
|
+
const codec = options.codec ?? superjson
|
46
|
+
const moduleType = options.moduleType ?? 'json'
|
47
|
+
const moduleId = ensureEnd(options.moduleId, `.${moduleType}`)
|
48
|
+
const name = options.name ?? `reactive-data`
|
49
|
+
|
50
|
+
let server: ViteDevServer
|
51
|
+
let updateTimer: NodeJS.Timeout | undefined
|
52
|
+
let updateScheduled = false
|
53
|
+
|
54
|
+
const doUpdate = () => {
|
55
|
+
debug('update')
|
56
|
+
updateTimer = undefined
|
57
|
+
updateScheduled = false
|
58
|
+
if (!server) return
|
59
|
+
const moduleNode = server.moduleGraph.getModuleById(moduleId)
|
60
|
+
if (moduleNode) {
|
61
|
+
server.moduleGraph.invalidateModule(moduleNode)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
const scheduleUpdate = () => {
|
66
|
+
if (options.debounce) {
|
67
|
+
// User wants actual debouncing for rapid updates
|
68
|
+
if (updateTimer) clearTimeout(updateTimer)
|
69
|
+
updateTimer = setTimeout(doUpdate, options.debounce)
|
70
|
+
} else {
|
71
|
+
// Just batch synchronous updates using nextTick
|
72
|
+
if (updateScheduled) return
|
73
|
+
updateScheduled = true
|
74
|
+
process.nextTick(doUpdate)
|
75
|
+
}
|
76
|
+
}
|
77
|
+
|
78
|
+
// Helper to get the current data value
|
79
|
+
const getData = () => {
|
80
|
+
if (isRef(options.data)) {
|
81
|
+
return options.data.value
|
82
|
+
} else if (typeof options.data === 'function') {
|
83
|
+
return options.data()
|
84
|
+
} else {
|
85
|
+
return options.data
|
86
|
+
}
|
87
|
+
}
|
88
|
+
|
89
|
+
// Set up reactive effect immediately
|
90
|
+
effect(() => {
|
91
|
+
// Access data to track dependencies
|
92
|
+
const data = getData()
|
93
|
+
debug('data changed:', data)
|
94
|
+
// Trigger update only if server is available
|
95
|
+
if (server) {
|
96
|
+
scheduleUpdate()
|
97
|
+
}
|
98
|
+
})
|
99
|
+
|
100
|
+
return {
|
101
|
+
name,
|
102
|
+
|
103
|
+
configureServer(_server) {
|
104
|
+
server = _server
|
105
|
+
// Trigger initial update since server is now available
|
106
|
+
scheduleUpdate()
|
107
|
+
},
|
108
|
+
|
109
|
+
resolveId(id) {
|
110
|
+
if (id === moduleId) {
|
111
|
+
return moduleId
|
112
|
+
}
|
113
|
+
},
|
114
|
+
|
115
|
+
load: {
|
116
|
+
// todo: doesn't work for some reason, prefer over handler
|
117
|
+
// filter: {
|
118
|
+
// id: {
|
119
|
+
// include: moduleId,
|
120
|
+
// },
|
121
|
+
// },
|
122
|
+
handler: (id) => {
|
123
|
+
if (id !== moduleId) return
|
124
|
+
|
125
|
+
const data = getData()
|
126
|
+
// Return just the raw JSON string - let the JSON plugin handle the transformation
|
127
|
+
return codec.stringify(data)
|
128
|
+
},
|
129
|
+
},
|
130
|
+
}
|
131
|
+
}
|
@@ -1,31 +1,33 @@
|
|
1
1
|
import type { Plugin } from 'vite'
|
2
2
|
|
3
|
+
const log = console.log
|
4
|
+
|
3
5
|
export const BuildLogger: Plugin = {
|
4
6
|
// https://rollupjs.org/plugin-development/#build-hooks
|
5
7
|
name: `build-logger`,
|
6
8
|
buildStart(...args) {
|
7
|
-
|
9
|
+
log(`buildStart`, args)
|
8
10
|
},
|
9
11
|
resolveId(...args) {
|
10
|
-
|
12
|
+
log(`resolveId`, args)
|
11
13
|
},
|
12
14
|
load(...args) {
|
13
|
-
|
15
|
+
log(`load`, JSON.stringify(args))
|
14
16
|
},
|
15
17
|
shouldTransformCachedModule(...args) {
|
16
|
-
|
18
|
+
log(`shouldTransformCachedModule`, args)
|
17
19
|
},
|
18
20
|
transform(...args) {
|
19
|
-
|
21
|
+
log(`transform`, args)
|
20
22
|
return args[0]
|
21
23
|
},
|
22
24
|
moduleParsed(...args) {
|
23
|
-
|
25
|
+
log(`\nmoduleParsed`, args)
|
24
26
|
},
|
25
27
|
resolveDynamicImport(...args) {
|
26
|
-
|
28
|
+
log(`resolveDynamicImport`, args)
|
27
29
|
},
|
28
30
|
buildEnd(...args) {
|
29
|
-
|
31
|
+
log(`buildEnd`, args)
|
30
32
|
},
|
31
33
|
}
|
package/src/project-data.ts
CHANGED
@@ -1,14 +1,10 @@
|
|
1
1
|
import type { Config } from '#api/config/index'
|
2
|
-
import type { FileRouter } from '#lib/file-router/index'
|
3
2
|
import type { Schema } from './api/schema/index.ts'
|
4
3
|
|
5
4
|
export interface ProjectData {
|
6
5
|
schema: null | Schema.Schema
|
7
|
-
siteNavigationItems: SiteNavigationItem[]
|
8
|
-
sidebarIndex: SidebarIndex
|
9
6
|
faviconPath: string
|
10
7
|
paths: Config.Config[`paths`][`project`]
|
11
|
-
pagesScanResult: FileRouter.ScanResult
|
12
8
|
server: {
|
13
9
|
static: {
|
14
10
|
directory: string
|
@@ -16,12 +12,3 @@ export interface ProjectData {
|
|
16
12
|
}
|
17
13
|
}
|
18
14
|
}
|
19
|
-
|
20
|
-
export interface SiteNavigationItem {
|
21
|
-
title: string
|
22
|
-
pathExp: string
|
23
|
-
}
|
24
|
-
|
25
|
-
export interface SidebarIndex {
|
26
|
-
[pathExpression: string]: FileRouter.Sidebar.Sidebar
|
27
|
-
}
|
@@ -49,11 +49,14 @@ export const getPathActiveReport = (
|
|
49
49
|
pathExp: string,
|
50
50
|
currentPathExp: string,
|
51
51
|
): PathActiveReport => {
|
52
|
-
// Normalize paths for comparison
|
52
|
+
// Normalize both paths for comparison
|
53
|
+
const normalizedPath = pathExp.startsWith('/') ? pathExp.slice(1) : pathExp
|
53
54
|
const normalizedCurrentPath = currentPathExp.startsWith('/') ? currentPathExp.slice(1) : currentPathExp
|
54
|
-
|
55
|
-
const
|
55
|
+
|
56
|
+
const isDirect = normalizedCurrentPath === normalizedPath
|
57
|
+
const isdescendant = normalizedCurrentPath.startsWith(normalizedPath + '/') && normalizedCurrentPath !== normalizedPath
|
56
58
|
const is = isDirect || isdescendant
|
59
|
+
|
57
60
|
return {
|
58
61
|
is,
|
59
62
|
isDirect,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
2
2
|
import { createLoader, useLoaderData } from '#lib/react-router-loader/react-router-loader'
|
3
|
-
import
|
3
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
4
4
|
import { Changelog } from '../components/Changelog.jsx'
|
5
5
|
|
6
6
|
const loader = createLoader(() => {
|
@@ -2,7 +2,7 @@ import { createRoute } from '#lib/react-router-aid/react-router-aid'
|
|
2
2
|
import { createLoader, useLoaderData } from '#lib/react-router-loader/react-router-loader'
|
3
3
|
import { Container, Flex } from '@radix-ui/themes'
|
4
4
|
import { Outlet } from 'react-router'
|
5
|
-
import
|
5
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
6
6
|
import { MissingSchema } from '../components/MissingSchema.jsx'
|
7
7
|
import { TypeIndex } from '../components/TypeIndex.jsx'
|
8
8
|
import { reference$type } from './reference.$type.jsx'
|
@@ -7,7 +7,9 @@ import radixStylesUrl from '@radix-ui/themes/styles.css?url'
|
|
7
7
|
import { Arr } from '@wollybeard/kit'
|
8
8
|
import { Link as LinkReactRouter } from 'react-router'
|
9
9
|
import { Outlet, ScrollRestoration, useLocation } from 'react-router'
|
10
|
-
import
|
10
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
11
|
+
import projectDataNavbar from 'virtual:polen/project/data/navbar.jsonsuper'
|
12
|
+
import projectDataPages from 'virtual:polen/project/data/pages.jsonsuper'
|
11
13
|
import { pages } from 'virtual:polen/project/pages.jsx'
|
12
14
|
import { templateVariables } from 'virtual:polen/template/variables'
|
13
15
|
import { Link } from '../components/Link.jsx'
|
@@ -72,7 +74,7 @@ const Layout = () => {
|
|
72
74
|
}
|
73
75
|
|
74
76
|
const currentNavPathExp = getCurrentNavPathExp()
|
75
|
-
const sidebar = currentNavPathExp &&
|
77
|
+
const sidebar = currentNavPathExp && projectDataPages.sidebarIndex[currentNavPathExp]
|
76
78
|
const showSidebar = sidebar && sidebar.items.length > 0
|
77
79
|
return (
|
78
80
|
<Theme asChild>
|
@@ -98,7 +100,7 @@ const Layout = () => {
|
|
98
100
|
</Flex>
|
99
101
|
</LinkReactRouter>
|
100
102
|
<Flex direction='row' gap='4'>
|
101
|
-
{
|
103
|
+
{projectDataNavbar.map((item, key) => (
|
102
104
|
<Link key={key} color='gray' to={item.pathExp}>
|
103
105
|
{item.title}
|
104
106
|
</Link>
|
@@ -5,7 +5,7 @@ import { AppleTouchIcon } from '#lib/apple-touch-icon/index'
|
|
5
5
|
import { Favicon } from '#lib/favicon/index'
|
6
6
|
import { serveStatic } from '@hono/node-server/serve-static'
|
7
7
|
import { Fs, Http, Path } from '@wollybeard/kit'
|
8
|
-
import
|
8
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
9
9
|
import { renderPage } from './render-page.jsx'
|
10
10
|
import { view } from './view.ts'
|
11
11
|
|
@@ -1,4 +1,6 @@
|
|
1
|
+
import { reportError } from '#api/server/report-error'
|
1
2
|
import type { ReactRouter } from '#dep/react-router/index'
|
3
|
+
import { ResponseInternalServerError } from '#lib/kit-temp'
|
2
4
|
import type { ReactRouterAid } from '#lib/react-router-aid/index'
|
3
5
|
import { Arr } from '@wollybeard/kit'
|
4
6
|
import { StrictMode } from 'react'
|
@@ -22,7 +24,8 @@ export const renderPage = (
|
|
22
24
|
</StrictMode>,
|
23
25
|
)
|
24
26
|
} catch (cause) {
|
25
|
-
|
27
|
+
reportError(new Error(`Failed to server side render the HTML`, { cause }))
|
28
|
+
return ResponseInternalServerError()
|
26
29
|
}
|
27
30
|
|
28
31
|
if (__BUILDING__) {
|
@@ -2,7 +2,7 @@ import { Hono } from '#dep/hono/index'
|
|
2
2
|
import type { ReactRouter } from '#dep/react-router/index'
|
3
3
|
import { app } from '#template/server/app'
|
4
4
|
import * as NodeFs from 'node:fs/promises'
|
5
|
-
import
|
5
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
6
6
|
import { renderPage } from '../render-page.jsx'
|
7
7
|
import { getRoutesPaths } from './get-route-paths.ts'
|
8
8
|
|
@@ -2,7 +2,7 @@ import { Grafaid } from '#lib/grafaid/index'
|
|
2
2
|
import { visit } from 'graphql'
|
3
3
|
// Or your specific import path for this type
|
4
4
|
import { ReactRouterAid } from '#lib/react-router-aid/index'
|
5
|
-
import
|
5
|
+
import PROJECT_DATA from 'virtual:polen/project/data.jsonsuper'
|
6
6
|
import { routes } from '../../routes.jsx'
|
7
7
|
|
8
8
|
// todo: Frameworks tend to colocate ssg data loaders with routes to solve the following
|
@@ -1,16 +0,0 @@
|
|
1
|
-
import type { Config } from '#api/config/index';
|
2
|
-
import type { Vite } from '#dep/vite/index';
|
3
|
-
import { FileRouter } from '#lib/file-router/index';
|
4
|
-
import { ViteVirtual } from '#lib/vite-virtual/index';
|
5
|
-
export declare const viProjectPages: ViteVirtual.Identifier.Identifier;
|
6
|
-
export interface PagesTreePluginOptions {
|
7
|
-
config: Config.Config;
|
8
|
-
onPagesChange?: (pages: FileRouter.ScanResult) => void;
|
9
|
-
onTreeChange?: (tree: FileRouter.RouteTreeNode) => void;
|
10
|
-
}
|
11
|
-
/**
|
12
|
-
* Pages plugin with tree support
|
13
|
-
*/
|
14
|
-
export declare const createPagesPlugin: ({ config, onPagesChange, onTreeChange }: PagesTreePluginOptions) => Vite.Plugin[];
|
15
|
-
export declare const getRouteTree: (config: Config.Config) => Promise<FileRouter.RouteTreeNode>;
|
16
|
-
//# sourceMappingURL=pages-tree.d.ts.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"pages-tree.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/plugins/pages-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAE/C,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAQrD,eAAO,MAAM,cAAc,mCAA0E,CAAA;AAErG,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAA;IACrB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,KAAK,IAAI,CAAA;IACtD,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,UAAU,CAAC,aAAa,KAAK,IAAI,CAAA;CACxD;AAED;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAC5B,yCAAyC,sBAAsB,KAC9D,IAAI,CAAC,MAAM,EAuJb,CAAA;AAGD,eAAO,MAAM,YAAY,GAAU,QAAQ,MAAM,CAAC,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAM1F,CAAA"}
|