polen 0.9.0-next.3 → 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 +12 -3
- package/build/api/vite/plugins/pages.d.ts.map +1 -1
- package/build/api/vite/plugins/pages.js +155 -35
- package/build/api/vite/plugins/pages.js.map +1 -1
- 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 +2 -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 +185 -40
- 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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"report-error.d.ts","sourceRoot":"","sources":["../../../src/api/server/report-error.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW,GAAU,OAAO,OAAO,KAAG,OAAO,CAAC,IAAI,CAkB9D,CAAA"}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import { Err } from '@wollybeard/kit';
|
2
|
+
import cleanStack from 'clean-stack';
|
3
|
+
import { ErrorParser } from 'youch-core';
|
4
|
+
export const reportError = async (value) => {
|
5
|
+
const error = Err.ensure(value);
|
6
|
+
const excludeStackFramesPattern = /.*(?:rolldown-vite|rolldown|node_modules).*/;
|
7
|
+
cleanStackRecursive(error, excludeStackFramesPattern);
|
8
|
+
Err.log(error);
|
9
|
+
const parser = new ErrorParser();
|
10
|
+
const parsedError = await parser.parse(error);
|
11
|
+
const snippets = createSnippets(parsedError);
|
12
|
+
if (snippets) {
|
13
|
+
console.log('\n\n\n\n' + snippets);
|
14
|
+
}
|
15
|
+
};
|
16
|
+
const createSnippets = (parsedError) => {
|
17
|
+
const snippets = parsedError.frames.map((frame) => {
|
18
|
+
let snippet = createSnippet(frame);
|
19
|
+
snippet = frame.fileName + '\n' + frame.lineNumber + '\n\n' + snippet;
|
20
|
+
return snippet;
|
21
|
+
}).join('\n\n----------------------------------------------------------------------------------\n\n');
|
22
|
+
return snippets;
|
23
|
+
};
|
24
|
+
const createSnippet = (stackFrame) => {
|
25
|
+
const snippet = stackFrame.source?.map(line => {
|
26
|
+
return line.lineNumber.toString().padStart(4, ' ') + `: ` + line.chunk;
|
27
|
+
}).join(`\n`);
|
28
|
+
return snippet;
|
29
|
+
};
|
30
|
+
// todo:
|
31
|
+
// pathFilter: Fn.compose(Str.isMatchWith(excludePattern), Bool.negate)
|
32
|
+
const cleanStackRecursive = (value, excludePattern) => {
|
33
|
+
if (value instanceof AggregateError) {
|
34
|
+
value.errors.forEach((error) => cleanStackRecursive(error, excludePattern));
|
35
|
+
}
|
36
|
+
// console.log(`Filtering path: ${path}`, isInclude ? 'Included' : 'Excluded')
|
37
|
+
if (value instanceof Error) {
|
38
|
+
value.stack = cleanStack(value.stack, {
|
39
|
+
pathFilter: (path) => !path.match(excludePattern),
|
40
|
+
// todo
|
41
|
+
// basePath: config.paths.project.rootDir,
|
42
|
+
// pretty: true,
|
43
|
+
});
|
44
|
+
cleanStackRecursive(value.cause, excludePattern);
|
45
|
+
}
|
46
|
+
};
|
47
|
+
//# sourceMappingURL=report-error.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"report-error.js","sourceRoot":"","sources":["../../../src/api/server/report-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACrC,OAAO,UAAU,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAAE,KAAc,EAAiB,EAAE;IACjE,MAAM,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;IAE/B,MAAM,yBAAyB,GAAG,6CAA6C,CAAA;IAE/E,mBAAmB,CAAC,KAAK,EAAE,yBAAyB,CAAC,CAAA;IAErD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IAEd,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAA;IAEhC,MAAM,WAAW,GAAG,MAAM,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IAE7C,MAAM,QAAQ,GAAG,cAAc,CAAC,WAAW,CAAC,CAAA;IAE5C,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,GAAG,CAAC,UAAU,GAAG,QAAQ,CAAC,CAAA;IACpC,CAAC;AACH,CAAC,CAAA;AAED,MAAM,cAAc,GAAG,CAAC,WAAwB,EAAE,EAAE;IAClD,MAAM,QAAQ,GAAG,WAAW,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;QAChD,IAAI,OAAO,GAAG,aAAa,CAAC,KAAK,CAAC,CAAA;QAElC,OAAO,GAAG,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,KAAK,CAAC,UAAU,GAAG,MAAM,GAAG,OAAO,CAAA;QACrE,OAAO,OAAO,CAAA;IAChB,CAAC,CAAC,CAAC,IAAI,CAAC,4FAA4F,CAAC,CAAA;IACrG,OAAO,QAAQ,CAAA;AACjB,CAAC,CAAA;AAED,MAAM,aAAa,GAAG,CAAC,UAAsB,EAAE,EAAE;IAC/C,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,CAAC,IAAI,CAAC,EAAE;QAC5C,OAAO,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;IACxE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO,OAAO,CAAA;AAChB,CAAC,CAAA;AAED,QAAQ;AACR,uEAAuE;AACvE,MAAM,mBAAmB,GAAG,CAAC,KAAc,EAAE,cAAsB,EAAE,EAAE;IACrE,IAAI,KAAK,YAAY,cAAc,EAAE,CAAC;QACpC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,mBAAmB,CAAC,KAAK,EAAE,cAAc,CAAC,CAAC,CAAA;IAC7E,CAAC;IACD,8EAA8E;IAC9E,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,KAAK,CAAC,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,KAAK,EAAE;YACpC,UAAU,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC;YACjD,OAAO;YACP,0CAA0C;YAC1C,gBAAgB;SACjB,CAAC,CAAA;QAEF,mBAAmB,CAAC,KAAK,CAAC,KAAK,EAAE,cAAc,CAAC,CAAA;IAClD,CAAC;AACH,CAAC,CAAA"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ExtensibleData } from '#lib/extensible-data/index';
|
2
|
+
export interface NavbarItem {
|
3
|
+
pathExp: string;
|
4
|
+
title: string;
|
5
|
+
}
|
6
|
+
export type NavbarData = NavbarItem[];
|
7
|
+
export type NavbarDataRegistry = ExtensibleData.ExtensibleData<NavbarData>;
|
8
|
+
export declare const NavbarData: () => ExtensibleData.ExtensibleData<NavbarData>;
|
9
|
+
//# sourceMappingURL=navbar.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"navbar.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/data/navbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAE3D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;CACd;AACD,MAAM,MAAM,UAAU,GAAG,UAAU,EAAE,CAAA;AAErC,MAAM,MAAM,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;AAE1E,eAAO,MAAM,UAAU,iDAInB,CAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"navbar.js","sourceRoot":"","sources":["../../../../src/api/vite/data/navbar.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAU3D,MAAM,CAAC,MAAM,UAAU,GAAG,GAAG,EAAE,CAC7B,cAAc,CAAC,MAAM,CAAa;IAChC,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE;IAChB,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,IAAI,EAAE;CAChC,CAAC,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/plugins/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/plugins/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAG/C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAC1D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAoB3C,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,WAAW,CAAC,WAAW,EAAE,CAAA;CACjC;AAED,eAAO,MAAM,IAAI,GAAI,QAAQ,MAAM,CAAC,MAAM,KAAG,IAAI,CAAC,YAAY,EAqM7D,CAAA"}
|
@@ -1,26 +1,21 @@
|
|
1
|
+
import { NavbarData } from '#api/vite/data/navbar';
|
1
2
|
import { VitePluginSelfContainedMode } from '#cli/_/self-contained-mode';
|
2
|
-
import {
|
3
|
-
import {
|
4
|
-
import { Tree } from '#lib/tree/index';
|
3
|
+
import { VitePluginJson } from '#lib/vite-plugin-json/index';
|
4
|
+
import { VitePluginReactiveData } from '#lib/vite-plugin-reactive-data/index';
|
5
5
|
import { ViteVirtual } from '#lib/vite-virtual/index';
|
6
6
|
import { debug } from '#singletons/debug';
|
7
|
+
import { superjson } from '#singletons/superjson';
|
7
8
|
import { Json, Str } from '@wollybeard/kit';
|
8
|
-
import jsesc from 'jsesc';
|
9
|
-
import { superjson } from "../../../singletons/superjson.js";
|
10
9
|
import { SchemaAugmentation } from "../../schema-augmentation/index.js";
|
11
10
|
import { Schema } from "../../schema/index.js";
|
12
11
|
import { createLogger } from "../logger.js";
|
13
12
|
import { polenVirtual } from "../vi.js";
|
14
|
-
import {
|
13
|
+
import { Pages } from "./pages.js";
|
15
14
|
const _debug = debug.sub(`vite-plugin-core`);
|
16
15
|
const viTemplateVariables = polenVirtual([`template`, `variables`]);
|
17
16
|
const viTemplateSchemaAugmentations = polenVirtual([`template`, `schema-augmentations`]);
|
18
|
-
const viProjectData = polenVirtual([`project`, `data`]);
|
17
|
+
const viProjectData = polenVirtual([`project`, `data.jsonsuper`], { allowPluginProcessing: true });
|
19
18
|
export const Core = (config) => {
|
20
|
-
// State for current pages data (updated by pages plugin)
|
21
|
-
let currentPagesData = null;
|
22
|
-
let currentTreeData = null;
|
23
|
-
let viteDevServer = null;
|
24
19
|
// Schema cache management
|
25
20
|
let schemaCache = null;
|
26
21
|
const readSchema = async () => {
|
@@ -38,6 +33,7 @@ export const Core = (config) => {
|
|
38
33
|
return schemaCache;
|
39
34
|
};
|
40
35
|
const plugins = [];
|
36
|
+
const navbarData = NavbarData();
|
41
37
|
// Note: The main use for this right now is to resolve the react imports
|
42
38
|
// from the mdx vite plugin which have to go through the Polen exports since Polen keeps those deps bundled.
|
43
39
|
//
|
@@ -48,25 +44,18 @@ export const Core = (config) => {
|
|
48
44
|
projectDirPathExp: config.paths.project.rootDir,
|
49
45
|
}));
|
50
46
|
}
|
47
|
+
const json = VitePluginJson.create({
|
48
|
+
codec: {
|
49
|
+
validate: superjson,
|
50
|
+
importPath: import.meta.resolve('#singletons/superjson'),
|
51
|
+
importExport: 'superjson',
|
52
|
+
},
|
53
|
+
filter: {
|
54
|
+
moduleTypes: ['jsonsuper'],
|
55
|
+
},
|
56
|
+
});
|
51
57
|
return [
|
52
58
|
...plugins,
|
53
|
-
// Self-contained pages plugin
|
54
|
-
...createPagesPlugin({
|
55
|
-
config,
|
56
|
-
onPagesChange: (pages) => {
|
57
|
-
currentPagesData = pages;
|
58
|
-
// Invalidate project data virtual module to regenerate navigation/sidebar
|
59
|
-
if (viteDevServer) {
|
60
|
-
const projectDataModule = viteDevServer.moduleGraph.getModuleById(viProjectData.resolved);
|
61
|
-
if (projectDataModule) {
|
62
|
-
viteDevServer.moduleGraph.invalidateModule(projectDataModule);
|
63
|
-
}
|
64
|
-
}
|
65
|
-
},
|
66
|
-
onTreeChange: (tree) => {
|
67
|
-
currentTreeData = tree;
|
68
|
-
},
|
69
|
-
}),
|
70
59
|
/**
|
71
60
|
* If a `polen*` import is encountered from the user's project, resolve it to the currently
|
72
61
|
* running source code of Polen rather than the user's node_modules.
|
@@ -80,6 +69,7 @@ export const Core = (config) => {
|
|
80
69
|
*/
|
81
70
|
{
|
82
71
|
name: `polen:internal-import-alias`,
|
72
|
+
enforce: 'pre',
|
83
73
|
resolveId(id, importer) {
|
84
74
|
const d = debug.sub(`vite-plugin:internal-import-alias`);
|
85
75
|
const isPolenImporter = Boolean(importer
|
@@ -108,11 +98,20 @@ export const Core = (config) => {
|
|
108
98
|
return to;
|
109
99
|
},
|
110
100
|
},
|
101
|
+
json,
|
102
|
+
VitePluginReactiveData.create({
|
103
|
+
moduleId: `virtual:polen/project/data/navbar`,
|
104
|
+
data: navbarData.value,
|
105
|
+
codec: superjson,
|
106
|
+
name: `polen-navbar`,
|
107
|
+
moduleType: 'jsonsuper',
|
108
|
+
}),
|
109
|
+
...Pages({
|
110
|
+
config,
|
111
|
+
navbarData,
|
112
|
+
}),
|
111
113
|
{
|
112
114
|
name: `polen:core`,
|
113
|
-
configureServer(server) {
|
114
|
-
viteDevServer = server;
|
115
|
-
},
|
116
115
|
config(_, { command }) {
|
117
116
|
// isServing = command === `serve`
|
118
117
|
return {
|
@@ -159,73 +158,14 @@ export const Core = (config) => {
|
|
159
158
|
identifier: viProjectData,
|
160
159
|
async loader() {
|
161
160
|
_debug(`loadingViProjectDataVirtualModule`);
|
162
|
-
// todo: parallel
|
163
161
|
const schema = await readSchema();
|
164
|
-
// Get pages data from the pages plugin or load initially
|
165
|
-
if (!currentPagesData) {
|
166
|
-
_debug(`loadingPagesDataInitially`);
|
167
|
-
currentPagesData = await FileRouter.scan({
|
168
|
-
dir: config.paths.project.absolute.pages,
|
169
|
-
glob: `**/*.{md,mdx}`,
|
170
|
-
});
|
171
|
-
// Report any diagnostics from initial scan
|
172
|
-
reportDiagnostics(currentPagesData.diagnostics);
|
173
|
-
}
|
174
|
-
if (!currentTreeData) {
|
175
|
-
_debug(`loadingTreeDataInitially`);
|
176
|
-
currentTreeData = await getRouteTree(config);
|
177
|
-
}
|
178
|
-
const pagesScanResult = currentPagesData;
|
179
|
-
const routeTree = currentTreeData;
|
180
|
-
_debug(`usingPageRoutesFromPagesPlugin`, pagesScanResult.routes.length);
|
181
|
-
const siteNavigationItems = [];
|
182
|
-
//
|
183
|
-
// ━━ Build Navbar
|
184
|
-
//
|
185
|
-
// Process first-level children as navigation items
|
186
|
-
for (const child of routeTree.children) {
|
187
|
-
if (child.value.type === 'directory') {
|
188
|
-
// Check if this directory has an index file
|
189
|
-
const hasIndex = child.children.some(c => c.value.type === 'file' && c.value.name === 'index');
|
190
|
-
if (hasIndex) {
|
191
|
-
const pathExp = FileRouter.pathToExpression([child.value.name]);
|
192
|
-
const title = Str.titlizeSlug(child.value.name);
|
193
|
-
siteNavigationItems.push({
|
194
|
-
pathExp: pathExp.startsWith('/') ? pathExp.slice(1) : pathExp,
|
195
|
-
title,
|
196
|
-
});
|
197
|
-
}
|
198
|
-
}
|
199
|
-
else if (child.value.type === 'file' && child.value.name !== 'index') {
|
200
|
-
const pathExp = FileRouter.pathToExpression([child.value.name]);
|
201
|
-
const title = Str.titlizeSlug(child.value.name);
|
202
|
-
siteNavigationItems.push({
|
203
|
-
pathExp: pathExp.startsWith('/') ? pathExp.slice(1) : pathExp,
|
204
|
-
title,
|
205
|
-
});
|
206
|
-
}
|
207
|
-
}
|
208
162
|
// ━ Schema presence causes adding some navbar items
|
163
|
+
const schemaNavbar = navbarData.get('schema');
|
164
|
+
schemaNavbar.length = 0; // Clear existing
|
209
165
|
if (schema) {
|
210
|
-
|
166
|
+
schemaNavbar.push({ pathExp: `reference`, title: `Reference` });
|
211
167
|
if (schema.versions.length > 1) {
|
212
|
-
|
213
|
-
}
|
214
|
-
}
|
215
|
-
//
|
216
|
-
// ━━ Build Sidebar
|
217
|
-
//
|
218
|
-
const sidebarIndex = {};
|
219
|
-
// Build sidebar for each top-level directory
|
220
|
-
for (const child of routeTree.children) {
|
221
|
-
if (child.value.type === 'directory') {
|
222
|
-
const pathExp = `/${child.value.name}`;
|
223
|
-
// Create a subtree starting from this directory
|
224
|
-
const subtree = Tree.node(child.value, child.children);
|
225
|
-
// Pass the directory name as base path so paths are built correctly
|
226
|
-
const sidebar = FileRouter.Sidebar.buildFromTree(subtree, [child.value.name]);
|
227
|
-
_debug(`Built sidebar for ${pathExp}:`, sidebar);
|
228
|
-
sidebarIndex[pathExp] = sidebar;
|
168
|
+
schemaNavbar.push({ pathExp: `changelog`, title: `Changelog` });
|
229
169
|
}
|
230
170
|
}
|
231
171
|
//
|
@@ -233,10 +173,7 @@ export const Core = (config) => {
|
|
233
173
|
//
|
234
174
|
const projectData = {
|
235
175
|
schema,
|
236
|
-
siteNavigationItems,
|
237
|
-
sidebarIndex,
|
238
176
|
faviconPath: `/logo.svg`,
|
239
|
-
pagesScanResult: pagesScanResult,
|
240
177
|
paths: config.paths.project,
|
241
178
|
server: {
|
242
179
|
static: {
|
@@ -249,13 +186,8 @@ export const Core = (config) => {
|
|
249
186
|
},
|
250
187
|
},
|
251
188
|
};
|
252
|
-
|
253
|
-
|
254
|
-
import { superjson } from '#singletons/superjson'
|
255
|
-
|
256
|
-
export const PROJECT_DATA = superjson.parse('${projectDataCode}')
|
257
|
-
`;
|
258
|
-
return content;
|
189
|
+
// Return just the JSON string - let the JSON plugin handle the transformation
|
190
|
+
return superjson.stringify(projectData);
|
259
191
|
},
|
260
192
|
}),
|
261
193
|
},
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/api/vite/plugins/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
1
|
+
{"version":3,"file":"core.js","sourceRoot":"","sources":["../../../../src/api/vite/plugins/core.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAA;AAClD,OAAO,EAAE,2BAA2B,EAAE,MAAM,4BAA4B,CAAA;AAGxE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,sCAAsC,CAAA;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AACrD,OAAO,EAAE,K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A8E;oBAC9E,OAAO,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC,CAAA;gBACzC,CAAC;aACF,CACF;SACF;KACF,CAAA;AACH,CAAC,CAAA"}
|
@@ -1,16 +1,25 @@
|
|
1
1
|
import type { Config } from '#api/config/index';
|
2
|
+
import type { NavbarDataRegistry } from '#api/vite/data/navbar';
|
2
3
|
import type { Vite } from '#dep/vite/index';
|
3
4
|
import { FileRouter } from '#lib/file-router/index';
|
4
|
-
|
5
|
-
export declare const
|
5
|
+
export declare const viProjectPages: import("../../../lib/vite-virtual/identifier.ts").Identifier;
|
6
|
+
export declare const viProjectPagesData: import("../../../lib/vite-virtual/identifier.ts").Identifier;
|
6
7
|
export interface PagesTreePluginOptions {
|
7
8
|
config: Config.Config;
|
9
|
+
navbarData?: NavbarDataRegistry;
|
8
10
|
onPagesChange?: (pages: FileRouter.ScanResult) => void;
|
9
11
|
onTreeChange?: (tree: FileRouter.RouteTreeNode) => void;
|
10
12
|
}
|
13
|
+
export interface ProjectDataPages {
|
14
|
+
sidebarIndex: SidebarIndex;
|
15
|
+
pagesScanResult: FileRouter.ScanResult;
|
16
|
+
}
|
17
|
+
export interface SidebarIndex {
|
18
|
+
[pathExpression: string]: FileRouter.Sidebar.Sidebar;
|
19
|
+
}
|
11
20
|
/**
|
12
21
|
* Pages plugin with tree support
|
13
22
|
*/
|
14
|
-
export declare const
|
23
|
+
export declare const Pages: ({ config, navbarData, onPagesChange, onTreeChange, }: PagesTreePluginOptions) => Vite.Plugin[];
|
15
24
|
export declare const getRouteTree: (config: Config.Config) => Promise<FileRouter.RouteTreeNode>;
|
16
25
|
//# sourceMappingURL=pages.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/plugins/pages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;
|
1
|
+
{"version":3,"file":"pages.d.ts","sourceRoot":"","sources":["../../../../src/api/vite/plugins/pages.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE/D,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAA;AAE3C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAUnD,eAAO,MAAM,cAAc,8DAA0E,CAAA;AACrG,eAAO,MAAM,kBAAkB,8DAAwF,CAAA;AAEvH,MAAM,WAAW,sBAAsB;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,CAAA;IACrB,UAAU,CAAC,EAAE,kBAAkB,CAAA;IAC/B,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,MAAM,WAAW,gBAAgB;IAC/B,YAAY,EAAE,YAAY,CAAA;IAC1B,eAAe,EAAE,UAAU,CAAC,UAAU,CAAA;CACvC;AAED,MAAM,WAAW,YAAY;IAC3B,CAAC,cAAc,EAAE,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAA;CACrD;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,GAAI,sDAKnB,sBAAsB,KAAG,IAAI,CAAC,MAAM,EAwRtC,CAAA;AAGD,eAAO,MAAM,YAAY,GAAU,QAAQ,MAAM,CAAC,MAAM,KAAG,OAAO,CAAC,UAAU,CAAC,aAAa,CAM1F,CAAA"}
|
@@ -1,17 +1,21 @@
|
|
1
1
|
import { polenVirtual } from '#api/vite/vi';
|
2
2
|
import { reportDiagnostics } from '#lib/file-router/diagnostic-reporter';
|
3
3
|
import { FileRouter } from '#lib/file-router/index';
|
4
|
-
import {
|
4
|
+
import { Tree } from '#lib/tree/index';
|
5
5
|
import { debug } from '#singletons/debug';
|
6
|
+
import { superjson } from '#singletons/superjson';
|
6
7
|
import mdx from '@mdx-js/rollup';
|
7
8
|
import { Path, Str } from '@wollybeard/kit';
|
8
9
|
import remarkGfm from 'remark-gfm';
|
9
10
|
const _debug = debug.sub(`vite-plugin-pages`);
|
10
11
|
export const viProjectPages = polenVirtual([`project`, `pages.jsx`], { allowPluginProcessing: true });
|
12
|
+
export const viProjectPagesData = polenVirtual([`project`, `data`, 'pages.jsonsuper'], { allowPluginProcessing: true });
|
11
13
|
/**
|
12
14
|
* Pages plugin with tree support
|
13
15
|
*/
|
14
|
-
export const
|
16
|
+
export const Pages = ({ config, navbarData, onPagesChange, onTreeChange, }) => {
|
17
|
+
let currentPagesData = null;
|
18
|
+
let currentTreeData = null;
|
15
19
|
// State management
|
16
20
|
let pagesCache = null;
|
17
21
|
let treeCache = null;
|
@@ -95,50 +99,166 @@ export const createPagesPlugin = ({ config, onPagesChange, onTreeChange }) => {
|
|
95
99
|
server.watcher.add(config.paths.project.absolute.pages);
|
96
100
|
},
|
97
101
|
// Hot update handling
|
98
|
-
async handleHotUpdate({ file, server }) {
|
102
|
+
async handleHotUpdate({ file, server, modules }) {
|
99
103
|
_debug(`handleHotUpdate`, file);
|
100
104
|
if (!isPageFile(file))
|
101
105
|
return;
|
102
106
|
_debug(`Page file changed:`, file);
|
103
|
-
//
|
107
|
+
// Check if this is a content-only change to an existing page
|
108
|
+
const oldPages = pagesCache;
|
109
|
+
// Clear cache and rescan
|
104
110
|
clearCache();
|
105
|
-
|
106
|
-
|
107
|
-
if (
|
108
|
-
|
109
|
-
|
111
|
+
const newPages = await scanPages();
|
112
|
+
currentPagesData = newPages;
|
113
|
+
// Check if page structure changed (added/removed pages)
|
114
|
+
const structureChanged = !oldPages
|
115
|
+
|| oldPages.routes.length !== newPages.routes.length
|
116
|
+
|| !oldPages.routes.every((oldRoute, i) => oldRoute.file.path.absolute === newPages.routes[i]?.file.path.absolute);
|
117
|
+
if (structureChanged) {
|
118
|
+
_debug(`Page structure changed, triggering full reload`);
|
119
|
+
// Invalidate virtual module
|
120
|
+
const mod = server.moduleGraph.getModuleById(viProjectPages.id);
|
121
|
+
if (mod) {
|
122
|
+
server.moduleGraph.invalidateModule(mod);
|
123
|
+
_debug(`Invalidated pages virtual module`);
|
124
|
+
}
|
125
|
+
// Notify about changes
|
126
|
+
if (onPagesChange) {
|
127
|
+
reportDiagnostics(newPages.diagnostics);
|
128
|
+
onPagesChange(newPages);
|
129
|
+
}
|
130
|
+
if (onTreeChange) {
|
131
|
+
const tree = await scanTree();
|
132
|
+
onTreeChange(tree);
|
133
|
+
currentTreeData = tree;
|
134
|
+
}
|
135
|
+
// Trigger full reload for structure changes
|
136
|
+
server.ws.send({ type: `full-reload` });
|
137
|
+
return [];
|
110
138
|
}
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
reportDiagnostics(pages.diagnostics);
|
116
|
-
onPagesChange(pages);
|
139
|
+
else {
|
140
|
+
_debug(`Page content changed, allowing HMR`);
|
141
|
+
// Let default HMR handle the MDX file change
|
142
|
+
return modules;
|
117
143
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
144
|
+
},
|
145
|
+
resolveId(id) {
|
146
|
+
if (id === viProjectPagesData.id) {
|
147
|
+
return viProjectPagesData.resolved;
|
122
148
|
}
|
123
|
-
// Trigger full reload
|
124
|
-
server.ws.send({ type: `full-reload` });
|
125
|
-
return [];
|
126
149
|
},
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
150
|
+
load: {
|
151
|
+
// filter: {
|
152
|
+
// id: viProjectPagesData.resolved,
|
153
|
+
// },
|
154
|
+
async handler(id) {
|
155
|
+
if (id !== viProjectPagesData.resolved)
|
156
|
+
return;
|
157
|
+
_debug(`viProjectDataPages`);
|
158
|
+
// Get pages data from the pages plugin or load initially
|
159
|
+
if (!currentPagesData) {
|
160
|
+
_debug(`loadingPagesDataInitially`);
|
161
|
+
currentPagesData = await FileRouter.scan({
|
162
|
+
dir: config.paths.project.absolute.pages,
|
163
|
+
glob: `**/*.{md,mdx}`,
|
164
|
+
});
|
165
|
+
// Report any diagnostics from initial scan
|
166
|
+
reportDiagnostics(currentPagesData.diagnostics);
|
167
|
+
}
|
168
|
+
if (!currentTreeData) {
|
169
|
+
_debug(`loadingTreeDataInitially`);
|
170
|
+
currentTreeData = await getRouteTree(config);
|
171
|
+
}
|
172
|
+
const pagesScanResult = currentPagesData;
|
173
|
+
const routeTree = currentTreeData;
|
174
|
+
_debug(`usingPageRoutesFromPagesPlugin`, pagesScanResult.routes.length);
|
175
|
+
//
|
176
|
+
// ━━ Build Navbar
|
177
|
+
//
|
178
|
+
// Update navbar if provided
|
179
|
+
if (navbarData) {
|
180
|
+
const navbarPages = navbarData.get('pages');
|
181
|
+
navbarPages.length = 0; // Clear existing
|
182
|
+
// Process first-level children as navigation items
|
183
|
+
for (const child of routeTree.children) {
|
184
|
+
if (child.value.type === 'directory') {
|
185
|
+
// Check if this directory has an index file
|
186
|
+
const hasIndex = child.children.some(c => c.value.type === 'file' && c.value.name === 'index');
|
187
|
+
if (hasIndex) {
|
188
|
+
const pathExp = FileRouter.pathToExpression([child.value.name]);
|
189
|
+
const title = Str.titlizeSlug(child.value.name);
|
190
|
+
navbarPages.push({
|
191
|
+
pathExp: pathExp.startsWith('/') ? pathExp.slice(1) : pathExp,
|
192
|
+
title,
|
193
|
+
});
|
194
|
+
}
|
195
|
+
}
|
196
|
+
else if (child.value.type === 'file' && child.value.name !== 'index') {
|
197
|
+
const pathExp = FileRouter.pathToExpression([child.value.name]);
|
198
|
+
const title = Str.titlizeSlug(child.value.name);
|
199
|
+
navbarPages.push({
|
200
|
+
pathExp: pathExp.startsWith('/') ? pathExp.slice(1) : pathExp,
|
201
|
+
title,
|
202
|
+
});
|
203
|
+
}
|
204
|
+
}
|
205
|
+
}
|
206
|
+
//
|
207
|
+
// ━━ Build Sidebar
|
208
|
+
//
|
209
|
+
const sidebarIndex = {};
|
210
|
+
// Build sidebar for each top-level directory
|
211
|
+
for (const child of routeTree.children) {
|
212
|
+
if (child.value.type === 'directory') {
|
213
|
+
const pathExp = `/${child.value.name}`;
|
214
|
+
// Create a subtree starting from this directory
|
215
|
+
const subtree = Tree.node(child.value, child.children);
|
216
|
+
// Pass the directory name as base path so paths are built correctly
|
217
|
+
const sidebar = FileRouter.Sidebar.buildFromTree(subtree, [child.value.name]);
|
218
|
+
_debug(`Built sidebar for ${pathExp}:`, sidebar);
|
219
|
+
sidebarIndex[pathExp] = sidebar;
|
220
|
+
}
|
221
|
+
}
|
222
|
+
//
|
223
|
+
// ━━ Put It All together
|
224
|
+
//
|
225
|
+
const projectDataPages = {
|
226
|
+
sidebarIndex,
|
227
|
+
pagesScanResult: pagesScanResult,
|
228
|
+
};
|
229
|
+
// Return just the JSON string - let the JSON plugin handle the transformation
|
230
|
+
return superjson.stringify(projectDataPages);
|
231
|
+
},
|
232
|
+
},
|
233
|
+
},
|
234
|
+
// Plugin 4: Virtual Module for Pages Routes
|
235
|
+
{
|
236
|
+
name: 'polen:pages:routes',
|
237
|
+
resolveId(id) {
|
238
|
+
if (id === viProjectPages.id) {
|
239
|
+
return viProjectPages.resolved;
|
240
|
+
}
|
241
|
+
},
|
242
|
+
load: {
|
243
|
+
// filter: {
|
244
|
+
// id: viProjectPages.resolved,
|
245
|
+
// },
|
246
|
+
handler: async (id) => {
|
247
|
+
if (id !== viProjectPages.resolved)
|
248
|
+
return;
|
131
249
|
_debug(`Loading viProjectPages virtual module`);
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
250
|
+
// Ensure we have pages data
|
251
|
+
if (!currentPagesData) {
|
252
|
+
currentPagesData = await scanPages();
|
253
|
+
reportDiagnostics(currentPagesData.diagnostics);
|
254
|
+
}
|
255
|
+
// Generate the module code
|
256
|
+
return {
|
257
|
+
code: generatePagesModule(currentPagesData),
|
258
|
+
moduleType: 'js',
|
259
|
+
};
|
140
260
|
},
|
141
|
-
}
|
261
|
+
},
|
142
262
|
},
|
143
263
|
];
|
144
264
|
};
|