@monkeyplus/flow 5.0.0-rc.9 → 5.0.0-rc.90
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.async.d.ts +3 -0
- package/dist/app/entry.async.mjs +1 -0
- package/dist/app/flow.d.ts +9 -2
- package/dist/app/flow.mjs +3 -0
- package/dist/chunks/dev-bundler.mjs +245 -0
- package/dist/chunks/external.mjs +37 -0
- package/dist/chunks/index.mjs +1142 -0
- package/dist/chunks/vite-node.mjs +155 -0
- package/dist/core/runtime/client.manifest.d.mts +2 -0
- package/dist/core/runtime/client.manifest.mjs +6 -0
- package/dist/core/runtime/nitro/flow.mjs +3 -2
- package/dist/core/runtime/nitro/renderer.mjs +52 -14
- package/dist/core/runtime/vite-node-shared.d.mts +1 -0
- package/dist/core/runtime/vite-node-shared.d.ts +8 -0
- package/dist/core/runtime/vite-node-shared.mjs +3 -0
- package/dist/core/runtime/vite-node.d.mts +2 -0
- package/dist/core/runtime/vite-node.mjs +42 -0
- package/dist/head/runtime/plugin.mjs +0 -1
- package/dist/index.mjs +27 -1393
- package/dist/pages/runtime/helpers/index.mjs +5 -2
- package/dist/pages/runtime/index.d.ts +10 -3
- package/dist/pages/runtime/index.mjs +11 -4
- package/dist/pages/runtime/pages.mjs +100 -0
- package/dist/vite-client/runtime/injectManifest.mjs +15 -9
- package/dist/vite-client/runtime/plugin.mjs +3 -2
- package/package.json +32 -27
- package/dist/pages/runtime/plugin.mjs +0 -56
- /package/dist/pages/runtime/{plugin.d.ts → pages.d.ts} +0 -0
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { joinURL, withTrailingSlash } from "ufo";
|
|
2
|
-
const buildPages = (page) => (location, language) => {
|
|
3
|
-
const locales =
|
|
2
|
+
const buildPages = (page) => (location, language, _locales) => {
|
|
3
|
+
const locales = _locales.map((key) => {
|
|
4
|
+
const _page = page.locales[key];
|
|
5
|
+
return [key, _page];
|
|
6
|
+
}).filter((el) => !!el[1]);
|
|
4
7
|
return locales.map(([locale, localePage]) => {
|
|
5
8
|
const [_language, _location] = locale.split("-");
|
|
6
9
|
const name = joinURL("/", _location, _language, page.name);
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
import type { DynamicPage, SimplePage } from '@monkeyplus/flow-schema';
|
|
2
|
-
export declare function definePage(
|
|
3
|
-
export declare function
|
|
1
|
+
import type { DynamicPage, PageCtx, SimplePage } from '@monkeyplus/flow-schema';
|
|
2
|
+
export declare function definePage<T>(...pages: SimplePage<T>[]): SimplePage<T>[];
|
|
3
|
+
export declare function defineDynamicPage<T>(...pages: DynamicPage<T>[]): DynamicPage<T>[];
|
|
4
|
+
export interface SharedContext {
|
|
5
|
+
assign?: 'global' | 'local';
|
|
6
|
+
merge?: boolean;
|
|
7
|
+
setup: (cxt: PageCtx) => any;
|
|
8
|
+
locales?: Record<string, (ctx: PageCtx) => any>;
|
|
9
|
+
}
|
|
10
|
+
export declare function defineSharedContext(shared: SharedContext): SharedContext;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
export function definePage(
|
|
2
|
-
return
|
|
1
|
+
export function definePage(...pages) {
|
|
2
|
+
return pages;
|
|
3
3
|
}
|
|
4
|
-
export function
|
|
5
|
-
return page
|
|
4
|
+
export function defineDynamicPage(...pages) {
|
|
5
|
+
return pages.map((page) => {
|
|
6
|
+
if (!page.name.endsWith("/**"))
|
|
7
|
+
page.name = `${page.name}/**`;
|
|
8
|
+
return page;
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export function defineSharedContext(shared) {
|
|
12
|
+
return shared;
|
|
6
13
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
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
|
+
flow.router.byName.insert(page2.name, page2.context);
|
|
27
|
+
allPages.push(page2.context);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
const cache = {};
|
|
32
|
+
async function getUrl(namePage, localeCode) {
|
|
33
|
+
const code = localeCode || this?.getLocale()?.code;
|
|
34
|
+
const [lang, loc] = code.split("-");
|
|
35
|
+
const name = joinURL("/", loc, lang, namePage);
|
|
36
|
+
const { path, params, page } = flow.router.byName.lookup(name) || {};
|
|
37
|
+
if (params?._ && page.dynamic) {
|
|
38
|
+
if (!cache[path]) {
|
|
39
|
+
cache[path] = this.defineCachedFunction(async (_ctx) => {
|
|
40
|
+
return await page.dynamic.method(_ctx);
|
|
41
|
+
}, { maxAge: 8, getKey: () => path, swr: false });
|
|
42
|
+
}
|
|
43
|
+
const fn = cache[path];
|
|
44
|
+
const list = await fn({ utils: this, locale: this.getLocale() });
|
|
45
|
+
const dPage = list.find((el) => el.name === params._);
|
|
46
|
+
return dPage ? path.replace("**", dPage.url) : "/404";
|
|
47
|
+
}
|
|
48
|
+
return path || "/404";
|
|
49
|
+
}
|
|
50
|
+
async function getUrls(withLocale = false) {
|
|
51
|
+
const urls = [];
|
|
52
|
+
for (const page of allPages) {
|
|
53
|
+
if (page.path.includes("/**") && page.page.dynamic) {
|
|
54
|
+
const dPages = await page.page.dynamic.method({
|
|
55
|
+
locale: page.locale,
|
|
56
|
+
utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
|
|
57
|
+
chunks: {},
|
|
58
|
+
page: {}
|
|
59
|
+
});
|
|
60
|
+
dPages.forEach((dPage) => {
|
|
61
|
+
const _path = joinURL(page.path.replace("/**", ""), dPage.url);
|
|
62
|
+
urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
|
|
63
|
+
});
|
|
64
|
+
} else {
|
|
65
|
+
const url = page.path.replaceAll("*", "");
|
|
66
|
+
urls.push(withLocale ? { url, locale: page.locale.code, name: page.name } : url);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return urls.sort();
|
|
70
|
+
}
|
|
71
|
+
async function getSharedContext(ctx) {
|
|
72
|
+
const entries = Object.entries(contexts);
|
|
73
|
+
if (!entries.length)
|
|
74
|
+
return {};
|
|
75
|
+
const _contexts = await Promise.all(entries.map(async ([key, method]) => {
|
|
76
|
+
const data = await method.setup(ctx);
|
|
77
|
+
const setupLocal = method?.locales?.[ctx.locale.code];
|
|
78
|
+
let dataLocal = {};
|
|
79
|
+
if (setupLocal)
|
|
80
|
+
dataLocal = await setupLocal(ctx);
|
|
81
|
+
const obj = method.merge ? { ...data, ...dataLocal } : { [key]: { ...data, ...dataLocal } };
|
|
82
|
+
return obj;
|
|
83
|
+
}));
|
|
84
|
+
return _contexts.reduce((acc, curr) => {
|
|
85
|
+
return {
|
|
86
|
+
...acc,
|
|
87
|
+
...curr
|
|
88
|
+
};
|
|
89
|
+
}, {});
|
|
90
|
+
}
|
|
91
|
+
flow.setUtil("getUrl", getUrl);
|
|
92
|
+
flow.setUtil("getUrls", getUrls);
|
|
93
|
+
flow.setUtil("getPages", () => allPages);
|
|
94
|
+
flow.setUtil("getSharedContext", getSharedContext);
|
|
95
|
+
return {
|
|
96
|
+
provide: {
|
|
97
|
+
pages: { allPages }
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
});
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { joinURL } from "ufo";
|
|
2
2
|
export const generateBundle = (config, bundle, _id) => {
|
|
3
|
-
const analyzedChunk = new Map();
|
|
4
|
-
const getImportedChunks = (chunk2, seen = new Set()) => {
|
|
3
|
+
const analyzedChunk = /* @__PURE__ */ new Map();
|
|
4
|
+
const getImportedChunks = (chunk2, seen = /* @__PURE__ */ new Set()) => {
|
|
5
5
|
const chunks = [];
|
|
6
6
|
chunk2.imports?.forEach((file) => {
|
|
7
7
|
const importee = bundle[file];
|
|
8
|
-
|
|
8
|
+
const isChunk = file.startsWith("_") || importee.isEntry;
|
|
9
|
+
if (isChunk && !seen.has(file)) {
|
|
9
10
|
seen.add(file);
|
|
10
11
|
chunks.push(...getImportedChunks(importee, seen));
|
|
11
12
|
chunks.push(importee);
|
|
@@ -30,13 +31,13 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
30
31
|
href: toPublicPath(chunk2.file, publicBase2)
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
|
-
const getCssTagsForChunk = (chunk2, publicBase2, seen = new Set()) => {
|
|
34
|
+
const getCssTagsForChunk = (chunk2, publicBase2, seen = /* @__PURE__ */ new Set()) => {
|
|
34
35
|
const tags = [];
|
|
35
36
|
if (!analyzedChunk.has(chunk2)) {
|
|
36
37
|
analyzedChunk.set(chunk2, 1);
|
|
37
38
|
chunk2.imports?.forEach((file) => {
|
|
38
39
|
const importee = bundle[file];
|
|
39
|
-
if (file.startsWith("_"))
|
|
40
|
+
if (file.startsWith("_") || importee.isEntry)
|
|
40
41
|
tags.push(...getCssTagsForChunk(importee, publicBase2, seen));
|
|
41
42
|
});
|
|
42
43
|
}
|
|
@@ -56,7 +57,9 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
56
57
|
};
|
|
57
58
|
const publicBase = config.baseURL || "/";
|
|
58
59
|
const isAsync = false;
|
|
59
|
-
const chunk = Object.values(bundle).find(
|
|
60
|
+
const chunk = Object.values(bundle).find(
|
|
61
|
+
(chunk2) => chunk2.isEntry && chunk2.src === _id
|
|
62
|
+
);
|
|
60
63
|
if (chunk) {
|
|
61
64
|
const imports = getImportedChunks(chunk);
|
|
62
65
|
const assetTags = [
|
|
@@ -71,14 +74,17 @@ export const generateBundle = (config, bundle, _id) => {
|
|
|
71
74
|
export const externalRE = /^(https?:)?\/\//;
|
|
72
75
|
export const isExternalUrl = (url) => externalRE.test(url);
|
|
73
76
|
function toPublicPath(filename, publicBase) {
|
|
74
|
-
return isExternalUrl(filename) ? filename : joinURL(publicBase, filename
|
|
77
|
+
return isExternalUrl(filename) ? filename : joinURL(publicBase, filename);
|
|
75
78
|
}
|
|
76
|
-
const unaryTags = new Set(["link", "meta", "base"]);
|
|
79
|
+
const unaryTags = /* @__PURE__ */ new Set(["link", "meta", "base"]);
|
|
77
80
|
function serializeTag({ tag, attrs, children }, indent = "") {
|
|
78
81
|
if (unaryTags.has(tag)) {
|
|
79
82
|
return `<${tag}${serializeAttrs(attrs)}>`;
|
|
80
83
|
} else {
|
|
81
|
-
return `<${tag}${serializeAttrs(attrs)}>${serializeTags(
|
|
84
|
+
return `<${tag}${serializeAttrs(attrs)}>${serializeTags(
|
|
85
|
+
children,
|
|
86
|
+
incrementIndent(indent)
|
|
87
|
+
)}</${tag}>`;
|
|
82
88
|
}
|
|
83
89
|
}
|
|
84
90
|
function serializeTags(tags, indent = "") {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import logger from "consola";
|
|
2
|
+
import { joinURL } from "ufo";
|
|
2
3
|
import { generateBundle } from "./injectManifest.mjs";
|
|
3
4
|
import { defineFlowPlugin } from "#app";
|
|
4
5
|
import manifest from "#viteManifest";
|
|
5
6
|
export default defineFlowPlugin((flow) => {
|
|
6
7
|
if (typeof manifest === "function") {
|
|
7
|
-
const _manifest = manifest();
|
|
8
8
|
flow.hook("page:chunks", (bundle, chunks) => {
|
|
9
9
|
try {
|
|
10
|
-
const
|
|
10
|
+
const data = manifest();
|
|
11
|
+
const chunk = generateBundle(flow.$config.app || {}, data.manifest, joinURL("/", data.base, `${bundle}.ts`).replace("/", ""));
|
|
11
12
|
if (chunk) {
|
|
12
13
|
chunks.head.push(chunk.head);
|
|
13
14
|
chunks.body.push(chunk.body);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monkeyplus/flow",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.90",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.mjs",
|
|
@@ -25,52 +25,57 @@
|
|
|
25
25
|
"dist"
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@monkeyplus/flow-cli": "5.0.0-rc.
|
|
29
|
-
"@monkeyplus/flow-kit": "5.0.0-rc.
|
|
30
|
-
"@monkeyplus/flow-schema": "5.0.0-rc.
|
|
28
|
+
"@monkeyplus/flow-cli": "5.0.0-rc.90",
|
|
29
|
+
"@monkeyplus/flow-kit": "5.0.0-rc.90",
|
|
30
|
+
"@monkeyplus/flow-schema": "5.0.0-rc.90",
|
|
31
31
|
"@rollup/plugin-replace": "^4.0.0",
|
|
32
32
|
"@vueuse/head": "^0.7.6",
|
|
33
|
-
"c12": "^0.2.
|
|
33
|
+
"c12": "^0.2.8",
|
|
34
34
|
"chokidar": "^3.5.3",
|
|
35
35
|
"consola": "^2.15.3",
|
|
36
36
|
"defu": "^6.0.0",
|
|
37
|
-
"esbuild": "^0.14.
|
|
37
|
+
"esbuild": "^0.14.49",
|
|
38
38
|
"escape-string-regexp": "^5.0.0",
|
|
39
|
-
"esno": "^0.
|
|
39
|
+
"esno": "^0.16.3",
|
|
40
40
|
"eta": "^1.12.3",
|
|
41
|
-
"externality": "^0.2.
|
|
41
|
+
"externality": "^0.2.2",
|
|
42
42
|
"fs-extra": "^10.1.0",
|
|
43
43
|
"get-port-please": "^2.5.0",
|
|
44
|
-
"globby": "^13.1.
|
|
45
|
-
"h3": "^0.7.
|
|
44
|
+
"globby": "^13.1.2",
|
|
45
|
+
"h3": "^0.7.16",
|
|
46
46
|
"hookable": "^5.1.1",
|
|
47
|
-
"jiti": "^1.
|
|
48
|
-
"
|
|
49
|
-
"
|
|
47
|
+
"jiti": "^1.14.0",
|
|
48
|
+
"ohash": "^0.1.5",
|
|
49
|
+
"knitwork": "^0.1.2",
|
|
50
|
+
"listhen": "^0.2.13",
|
|
50
51
|
"magic-string": "^0.26.2",
|
|
51
|
-
"mlly": "^0.5.
|
|
52
|
+
"mlly": "^0.5.4",
|
|
52
53
|
"mri": "^1.2.0",
|
|
53
|
-
"nitropack": "^0.4.
|
|
54
|
-
"pathe": "^0.2
|
|
54
|
+
"nitropack": "^0.4.12",
|
|
55
|
+
"pathe": "^0.3.2",
|
|
55
56
|
"perfect-debounce": "^0.1.3",
|
|
56
57
|
"radix3": "^0.1.2",
|
|
57
58
|
"unenv": "^0.5.2",
|
|
58
59
|
"ohmyfetch": "^0.4.18",
|
|
59
|
-
"node-fetch-native": "^0.1.
|
|
60
|
-
"rollup": "^2.
|
|
61
|
-
"rollup-plugin-visualizer": "^5.
|
|
60
|
+
"node-fetch-native": "^0.1.4",
|
|
61
|
+
"rollup": "^2.77.0",
|
|
62
|
+
"rollup-plugin-visualizer": "^5.7.1",
|
|
62
63
|
"scule": "^0.2.1",
|
|
63
|
-
"ufo": "^0.8.
|
|
64
|
-
"unctx": "^
|
|
65
|
-
"unimport": "^0.
|
|
66
|
-
"unplugin": "^0.
|
|
67
|
-
"untyped": "^0.4.
|
|
68
|
-
"
|
|
69
|
-
"
|
|
64
|
+
"ufo": "^0.8.5",
|
|
65
|
+
"unctx": "^2.0.1",
|
|
66
|
+
"unimport": "^0.4.5",
|
|
67
|
+
"unplugin": "^0.9.4",
|
|
68
|
+
"untyped": "^0.4.5",
|
|
69
|
+
"pkg-types": "^0.3.3",
|
|
70
|
+
"vite": "2.9.15",
|
|
71
|
+
"vite-node": "^0.22.1",
|
|
72
|
+
"vite-plugin-checker": "^0.4.9",
|
|
73
|
+
"vue-bundle-renderer": "^0.4.2",
|
|
74
|
+
"vue": "^3.2.37"
|
|
70
75
|
},
|
|
71
76
|
"devDependencies": {
|
|
72
77
|
"@types/fs-extra": "^9.0.13",
|
|
73
|
-
"vue-router": "^4.
|
|
78
|
+
"vue-router": "^4.1.2"
|
|
74
79
|
},
|
|
75
80
|
"engines": {
|
|
76
81
|
"node": "^16.11.0 || ^17.0.0 || ^18.0.0"
|
|
@@ -1,56 +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 "#pages";
|
|
6
|
-
export default defineFlowPlugin(async (flow) => {
|
|
7
|
-
const { app } = useRuntimeConfig();
|
|
8
|
-
const allPages = [];
|
|
9
|
-
const basePages = Object.entries(pages);
|
|
10
|
-
consola.success("Parsed %i pages", basePages.length);
|
|
11
|
-
basePages.forEach(([name, page]) => {
|
|
12
|
-
const { getPages } = definePage({
|
|
13
|
-
name,
|
|
14
|
-
...page
|
|
15
|
-
});
|
|
16
|
-
const _pages = getPages(app.locale.location, app.locale.language);
|
|
17
|
-
_pages.forEach((page2) => {
|
|
18
|
-
flow.router.byUrl.insert(page2.url, page2.context);
|
|
19
|
-
flow.router.byName.insert(page2.name, page2.context);
|
|
20
|
-
allPages.push(page2.context);
|
|
21
|
-
});
|
|
22
|
-
});
|
|
23
|
-
function getUrl(namePage, localeCode) {
|
|
24
|
-
const code = localeCode || this?.getLocale()?.code;
|
|
25
|
-
const [lang, loc] = code.split("-");
|
|
26
|
-
const name = joinURL("/", loc, lang, namePage);
|
|
27
|
-
const { path } = flow.router.byName.lookup(name) || {};
|
|
28
|
-
return path || "/404";
|
|
29
|
-
}
|
|
30
|
-
async function getUrls(withLocale = false) {
|
|
31
|
-
const urls = [];
|
|
32
|
-
for (const page of allPages) {
|
|
33
|
-
if (!page.path.includes("/**")) {
|
|
34
|
-
urls.push(withLocale ? { url: page.path, locale: page.locale.code, name: page.name } : page.path);
|
|
35
|
-
} else {
|
|
36
|
-
const dPages = await page.page.dynamic.method({
|
|
37
|
-
locale: page.locale,
|
|
38
|
-
utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils)
|
|
39
|
-
});
|
|
40
|
-
dPages.forEach((dPage) => {
|
|
41
|
-
const _path = joinURL(page.path.replace("/**", ""), dPage.url);
|
|
42
|
-
urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return urls.sort();
|
|
47
|
-
}
|
|
48
|
-
flow.setUtil("getUrl", getUrl);
|
|
49
|
-
flow.setUtil("getUrls", getUrls);
|
|
50
|
-
flow.setUtil("getPages", () => allPages);
|
|
51
|
-
return {
|
|
52
|
-
provide: {
|
|
53
|
-
pages: { allPages }
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
});
|
|
File without changes
|