@monkeyplus/flow 5.0.0-rc.169 → 5.0.0-rc.17
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/dist/app/entry.mjs +1 -1
- package/dist/app/flow.d.ts +3 -12
- package/dist/app/flow.mjs +0 -3
- package/dist/core/runtime/nitro/flow.d.ts +0 -1
- package/dist/core/runtime/nitro/flow.mjs +14 -9
- package/dist/core/runtime/nitro/renderer.mjs +15 -69
- package/dist/head/runtime/plugin.mjs +1 -0
- package/dist/index.mjs +765 -527
- package/dist/pages/runtime/helpers/index.d.ts +1 -1
- package/dist/pages/runtime/helpers/index.mjs +3 -14
- package/dist/pages/runtime/index.d.ts +3 -10
- package/dist/pages/runtime/index.mjs +2 -10
- package/dist/pages/runtime/plugin.mjs +59 -0
- package/dist/vite-client/runtime/injectManifest.d.ts +26 -0
- package/dist/vite-client/runtime/injectManifest.mjs +104 -0
- package/dist/vite-client/runtime/plugin.d.ts +2 -0
- package/dist/vite-client/runtime/plugin.mjs +26 -0
- package/package.json +36 -40
- package/dist/app/entry.async.d.ts +0 -3
- package/dist/app/entry.async.mjs +0 -1
- package/dist/chunks/dev-bundler.mjs +0 -277
- package/dist/core/runtime/client.manifest.d.mts +0 -2
- package/dist/core/runtime/client.manifest.mjs +0 -6
- package/dist/core/runtime/vite-node-shared.d.mts +0 -1
- package/dist/core/runtime/vite-node-shared.d.ts +0 -8
- package/dist/core/runtime/vite-node-shared.mjs +0 -3
- package/dist/core/runtime/vite-node.d.mts +0 -2
- package/dist/core/runtime/vite-node.mjs +0 -41
- package/dist/pages/runtime/pages.mjs +0 -120
- /package/dist/pages/runtime/{pages.d.ts → plugin.d.ts} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function getViteNodeOptions(): any;
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { performance } from 'node:perf_hooks';
|
|
2
|
-
import { ViteNodeRunner } from 'vite-node/client';
|
|
3
|
-
import { $fetch } from 'ohmyfetch';
|
|
4
|
-
import consola from 'consola';
|
|
5
|
-
import { getViteNodeOptions } from './vite-node-shared.mjs';
|
|
6
|
-
|
|
7
|
-
const viteNodeOptions = getViteNodeOptions();
|
|
8
|
-
const runner = new ViteNodeRunner({
|
|
9
|
-
root: viteNodeOptions.root, // Equals to Nuxt `srcDir`
|
|
10
|
-
base: viteNodeOptions.base,
|
|
11
|
-
async fetchModule(id) {
|
|
12
|
-
return await $fetch(`/module/${encodeURI(id)}`, {
|
|
13
|
-
baseURL: viteNodeOptions.baseURL,
|
|
14
|
-
});
|
|
15
|
-
},
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
let render;
|
|
19
|
-
|
|
20
|
-
export default async(ssrContext) => {
|
|
21
|
-
// Workaround for stub mode
|
|
22
|
-
// https://github.com/nuxt/framework/pull/3983
|
|
23
|
-
process.server = true;
|
|
24
|
-
|
|
25
|
-
// Invalidate cache for files changed since last rendering
|
|
26
|
-
const invalidates = await $fetch('/invalidates', {
|
|
27
|
-
baseURL: viteNodeOptions.baseURL,
|
|
28
|
-
});
|
|
29
|
-
const updates = runner.moduleCache.invalidateDepTree(invalidates);
|
|
30
|
-
|
|
31
|
-
// Execute SSR bundle on demand
|
|
32
|
-
const start = performance.now();
|
|
33
|
-
render = render || (await runner.executeFile(viteNodeOptions.entryPath)).default;
|
|
34
|
-
if (updates.size) {
|
|
35
|
-
const time = Math.round((performance.now() - start) * 1000) / 1000;
|
|
36
|
-
consola.success(`Vite server hmr ${updates.size} files`, time ? `in ${time}ms` : '');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const result = await render(ssrContext);
|
|
40
|
-
return result;
|
|
41
|
-
};
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { joinURL } from "ufo";
|
|
2
|
-
import consola from "consola";
|
|
3
|
-
import { definePage } from "./helpers/index.mjs";
|
|
4
|
-
import { defineFlowPlugin, useRuntimeConfig } from "#app";
|
|
5
|
-
import pages from "#build/pages";
|
|
6
|
-
import contexts from "#build/pages.contexts";
|
|
7
|
-
export default defineFlowPlugin(async (flow) => {
|
|
8
|
-
const { app } = useRuntimeConfig();
|
|
9
|
-
const allPages = [];
|
|
10
|
-
const basePages = Object.entries(pages);
|
|
11
|
-
consola.success("Parsed %i pages files", basePages.length);
|
|
12
|
-
basePages.forEach(([name, _pages]) => {
|
|
13
|
-
const __pages = Array.isArray(_pages) ? _pages : [_pages];
|
|
14
|
-
__pages.forEach((page) => {
|
|
15
|
-
const { getPages } = definePage({
|
|
16
|
-
name,
|
|
17
|
-
...page
|
|
18
|
-
});
|
|
19
|
-
const _pages2 = getPages(
|
|
20
|
-
app.locale.location,
|
|
21
|
-
app.locale.language,
|
|
22
|
-
app.locale.locales
|
|
23
|
-
);
|
|
24
|
-
_pages2.forEach((page2) => {
|
|
25
|
-
flow.router.byUrl.insert(page2.url, page2.context);
|
|
26
|
-
if (page2.url.includes("**") && !page2.context.page.dynamic) {
|
|
27
|
-
const _url = page2.url.replaceAll("*", "");
|
|
28
|
-
flow.router.byUrl.insert(_url, {
|
|
29
|
-
...page2.context,
|
|
30
|
-
path: _url
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
flow.router.byName.insert(page2.name, page2.context);
|
|
34
|
-
allPages.push(page2.context);
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
const cache = {};
|
|
39
|
-
function replacePath(_path, url) {
|
|
40
|
-
if (typeof url === "string") {
|
|
41
|
-
_path = joinURL(_path.replace("/**", ""), url);
|
|
42
|
-
} else {
|
|
43
|
-
Object.entries(url).forEach(([key, value]) => {
|
|
44
|
-
_path = _path.replace(`:${key}`, value);
|
|
45
|
-
});
|
|
46
|
-
if (url._ && _path.endsWith("**"))
|
|
47
|
-
_path = joinURL(_path.replace("/**", ""), url._);
|
|
48
|
-
}
|
|
49
|
-
return _path;
|
|
50
|
-
}
|
|
51
|
-
async function getUrl(namePage, localeCode) {
|
|
52
|
-
const code = localeCode || this?.getLocale()?.code;
|
|
53
|
-
const [lang, loc] = code.split("-");
|
|
54
|
-
const name = joinURL("/", loc, lang, namePage);
|
|
55
|
-
const { path, params, page } = flow.router.byName.lookup(name) || {};
|
|
56
|
-
if (params?._ && page.dynamic) {
|
|
57
|
-
if (!cache[path]) {
|
|
58
|
-
cache[path] = this.defineCachedFunction(async (_ctx) => {
|
|
59
|
-
return await page.dynamic.method(_ctx);
|
|
60
|
-
}, { maxAge: 8, getKey: () => path, swr: false });
|
|
61
|
-
}
|
|
62
|
-
const fn = cache[path];
|
|
63
|
-
const list = await fn({ utils: this, locale: this.getLocale() });
|
|
64
|
-
const dPage = list.find((el) => el.name === params._);
|
|
65
|
-
return dPage ? replacePath(path, dPage.url) : "/404";
|
|
66
|
-
}
|
|
67
|
-
return path?.replaceAll("*", "") || "/404";
|
|
68
|
-
}
|
|
69
|
-
async function getUrls(withLocale = false, omitNoPublish = false) {
|
|
70
|
-
const urls = [];
|
|
71
|
-
const _allPages = allPages.filter((p) => omitNoPublish ? !p.noPublish : true);
|
|
72
|
-
for (const page of _allPages) {
|
|
73
|
-
if ((page.path.includes("/:") || page.path.includes("/**")) && page.page.dynamic) {
|
|
74
|
-
const dPages = await page.page.dynamic.method({
|
|
75
|
-
locale: page.locale,
|
|
76
|
-
utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
|
|
77
|
-
chunks: {},
|
|
78
|
-
page: {}
|
|
79
|
-
});
|
|
80
|
-
dPages.forEach((dPage) => {
|
|
81
|
-
const _path = replacePath(page.path, dPage.url);
|
|
82
|
-
urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
|
|
83
|
-
});
|
|
84
|
-
} else {
|
|
85
|
-
const url = page.path.replaceAll("*", "");
|
|
86
|
-
urls.push(withLocale ? { url, locale: page.locale.code, name: page.name } : url);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return urls.sort();
|
|
90
|
-
}
|
|
91
|
-
async function getSharedContext(ctx) {
|
|
92
|
-
const entries = Object.entries(contexts);
|
|
93
|
-
if (!entries.length)
|
|
94
|
-
return {};
|
|
95
|
-
const _contexts = await Promise.all(entries.map(async ([key, method]) => {
|
|
96
|
-
const data = await method.setup(ctx);
|
|
97
|
-
const setupLocal = method?.locales?.[ctx.locale.code];
|
|
98
|
-
let dataLocal = {};
|
|
99
|
-
if (setupLocal)
|
|
100
|
-
dataLocal = await setupLocal(ctx);
|
|
101
|
-
const obj = method.merge ? { ...data, ...dataLocal } : { [key]: { ...data, ...dataLocal } };
|
|
102
|
-
return obj;
|
|
103
|
-
}));
|
|
104
|
-
return _contexts.reduce((acc, curr) => {
|
|
105
|
-
return {
|
|
106
|
-
...acc,
|
|
107
|
-
...curr
|
|
108
|
-
};
|
|
109
|
-
}, {});
|
|
110
|
-
}
|
|
111
|
-
flow.setUtil("getUrl", getUrl);
|
|
112
|
-
flow.setUtil("getUrls", getUrls);
|
|
113
|
-
flow.setUtil("getPages", () => allPages);
|
|
114
|
-
flow.setUtil("getSharedContext", getSharedContext);
|
|
115
|
-
return {
|
|
116
|
-
provide: {
|
|
117
|
-
pages: { allPages }
|
|
118
|
-
}
|
|
119
|
-
};
|
|
120
|
-
});
|
|
File without changes
|