@monkeyplus/flow 5.0.0-rc.199 → 5.0.0-rc.2

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 (81) hide show
  1. package/build.config.ts +25 -0
  2. package/dist/app/entry.d.ts +2 -2
  3. package/dist/app/entry.mjs +2 -3
  4. package/dist/app/flow.d.ts +3 -12
  5. package/dist/app/flow.mjs +0 -3
  6. package/dist/core/runtime/nitro/flow.d.ts +0 -1
  7. package/dist/core/runtime/nitro/flow.mjs +14 -9
  8. package/dist/core/runtime/nitro/renderer.mjs +18 -82
  9. package/dist/head/runtime/plugin.mjs +1 -0
  10. package/dist/index.mjs +772 -543
  11. package/dist/pages/runtime/helpers/index.d.ts +1 -1
  12. package/dist/pages/runtime/helpers/index.mjs +3 -14
  13. package/dist/pages/runtime/index.d.ts +3 -10
  14. package/dist/pages/runtime/index.mjs +4 -12
  15. package/dist/pages/runtime/plugin.mjs +53 -0
  16. package/dist/vite-client/runtime/injectManifest.d.ts +26 -0
  17. package/dist/vite-client/runtime/injectManifest.mjs +104 -0
  18. package/dist/vite-client/runtime/plugin.d.ts +2 -0
  19. package/dist/vite-client/runtime/plugin.mjs +27 -0
  20. package/package.json +40 -55
  21. package/src/app/composables/index.ts +20 -0
  22. package/src/app/entry.ts +36 -0
  23. package/src/app/flow.ts +157 -0
  24. package/src/app/index.ts +5 -0
  25. package/src/auto-imports/module.ts +143 -0
  26. package/src/auto-imports/presets.ts +49 -0
  27. package/src/auto-imports/transform.ts +48 -0
  28. package/src/core/app.ts +90 -0
  29. package/src/core/builder.ts +60 -0
  30. package/src/core/flow.ts +93 -0
  31. package/src/core/modules.ts +32 -0
  32. package/src/core/nitro.ts +206 -0
  33. package/src/core/plugins/import-protection.ts +49 -0
  34. package/src/core/plugins/unctx.ts +31 -0
  35. package/src/core/runtime/nitro/flow.ts +43 -0
  36. package/src/core/runtime/nitro/paths.ts +20 -0
  37. package/src/core/runtime/nitro/renderer.ts +74 -0
  38. package/src/core/templates.ts +119 -0
  39. package/src/core/vite/builder/css.ts +28 -0
  40. package/src/core/vite/builder/dev-bundler.ts +248 -0
  41. package/src/core/vite/builder/index.ts +96 -0
  42. package/src/core/vite/builder/manifest.ts +33 -0
  43. package/src/core/vite/builder/plugins/analyze.ts +32 -0
  44. package/src/core/vite/builder/plugins/cache-dir.ts +13 -0
  45. package/src/core/vite/builder/plugins/dynamic-base.ts +64 -0
  46. package/src/core/vite/builder/plugins/virtual.ts +45 -0
  47. package/src/core/vite/builder/server.ts +164 -0
  48. package/src/core/vite/builder/types/index.ts +13 -0
  49. package/src/core/vite/builder/utils/index.ts +53 -0
  50. package/src/core/vite/builder/utils/warmup.ts +27 -0
  51. package/src/core/vite/builder/utils/wpfs.ts +7 -0
  52. package/src/core/vite/builder/vite-node.ts +110 -0
  53. package/src/core/vite/client/index.ts +63 -0
  54. package/src/dirs.ts +8 -0
  55. package/src/head/module.ts +37 -0
  56. package/src/head/runtime/composables.ts +16 -0
  57. package/src/head/runtime/index.ts +1 -0
  58. package/src/head/runtime/plugin.ts +12 -0
  59. package/src/index.ts +2 -0
  60. package/src/pages/module.ts +55 -0
  61. package/src/pages/runtime/helpers/chunks.ts +0 -0
  62. package/src/pages/runtime/helpers/index.ts +33 -0
  63. package/src/pages/runtime/index.ts +9 -0
  64. package/src/pages/runtime/plugin.ts +65 -0
  65. package/src/pages/templates.ts +20 -0
  66. package/src/pages/utils.ts +49 -0
  67. package/src/vite-client/module.ts +84 -0
  68. package/src/vite-client/runtime/injectManifest.ts +188 -0
  69. package/src/vite-client/runtime/plugin.ts +33 -0
  70. package/dist/app/entry.async.d.ts +0 -3
  71. package/dist/app/entry.async.mjs +0 -1
  72. package/dist/chunks/dev-bundler.mjs +0 -277
  73. package/dist/core/runtime/client.manifest.d.mts +0 -2
  74. package/dist/core/runtime/client.manifest.mjs +0 -6
  75. package/dist/core/runtime/vite-node-shared.d.mts +0 -1
  76. package/dist/core/runtime/vite-node-shared.d.ts +0 -8
  77. package/dist/core/runtime/vite-node-shared.mjs +0 -3
  78. package/dist/core/runtime/vite-node.d.mts +0 -2
  79. package/dist/core/runtime/vite-node.mjs +0 -41
  80. package/dist/pages/runtime/pages.mjs +0 -123
  81. /package/dist/pages/runtime/{pages.d.ts → plugin.d.ts} +0 -0
@@ -0,0 +1,25 @@
1
+ import type { BuildEntry } from 'unbuild';
2
+ import { defineBuildConfig } from 'unbuild';
3
+
4
+ export default defineBuildConfig({
5
+ declaration: true,
6
+ entries: [
7
+ 'src/index',
8
+ { input: 'src/app/', outDir: 'dist/app/' },
9
+ ...[
10
+ 'core',
11
+ 'head',
12
+ 'pages',
13
+ 'vite-client',
14
+ ].map((name) => ({ input: `src/${name}/runtime/`, outDir: `dist/${name}/runtime`, format: 'esm' } as BuildEntry)),
15
+ // { input: 'src/runtime/', outDir: 'dist/runtime', format: 'esm' },
16
+ ],
17
+ dependencies: [
18
+ '@monkeyplus/flow-cli',
19
+ 'ohmyfetch',
20
+
21
+ ],
22
+ externals: [
23
+
24
+ ],
25
+ });
@@ -1,3 +1,3 @@
1
1
  import type { RuntimeConfig } from '@monkeyplus/flow-schema';
2
- export declare const entry: (runtimeConfig: RuntimeConfig) => Promise<import("./flow").FlowApp>;
3
- export default entry;
2
+ declare const _default: (runtimeConfig: RuntimeConfig) => Promise<import("./flow").FlowApp>;
3
+ export default _default;
@@ -1,7 +1,7 @@
1
1
  import { config, configure, render } from "eta";
2
2
  import { applyPlugins, createFlowApp } from "./flow.mjs";
3
3
  import plugins from "#build/plugins";
4
- export const entry = async (runtimeConfig) => {
4
+ export default async (runtimeConfig) => {
5
5
  const flow = createFlowApp({ runtimeConfig });
6
6
  try {
7
7
  await applyPlugins(flow, plugins);
@@ -17,8 +17,7 @@ export const entry = async (runtimeConfig) => {
17
17
  });
18
18
  };
19
19
  } catch (err) {
20
- console.error(err);
20
+ console.log(err);
21
21
  }
22
22
  return flow;
23
23
  };
24
- export default entry;
@@ -1,7 +1,7 @@
1
1
  import type { RadixRouter } from 'radix3';
2
2
  import type { Hookable } from 'hookable';
3
- import type { FlowAppUtils, FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
4
- type HookResult = Promise<void> | void;
3
+ import type { FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
4
+ declare type HookResult = Promise<void> | void;
5
5
  export interface FlowAppHooks {
6
6
  'flow:pages': (page: FlowPage[]) => HookResult;
7
7
  'eta:plugin': (options: any) => HookResult;
@@ -11,11 +11,6 @@ export interface FlowAppHooks {
11
11
  bodyStart: string[];
12
12
  }) => HookResult;
13
13
  'page:links': (links: string[]) => HookResult;
14
- 'page:context': (ctx: {
15
- page: string;
16
- localeCode: string;
17
- ctx: any;
18
- }, utils: any, data: Record<string, any>) => HookResult;
19
14
  'page:chunks': (bundle: string, scripts: {
20
15
  head: string[];
21
16
  body: string[];
@@ -32,20 +27,16 @@ export interface FlowApp {
32
27
  callHook: FlowApp['hooks']['callHook'];
33
28
  eta: any;
34
29
  app: {
35
- utils: FlowAppUtils;
30
+ utils: Record<string, any>;
36
31
  plugins: Record<string, any>;
37
32
  globals: Record<string, any>;
38
33
  };
39
34
  engine: string;
40
- site: {
41
- origin: string;
42
- };
43
35
  engines: Record<string, (template: string) => string>;
44
36
  generate: boolean;
45
37
  render: (view: Record<string, string>, data: any) => Promise<string> | void | string;
46
38
  provide: (name: string, value: any) => void;
47
39
  setUtil: (name: string, value: any) => void;
48
- $config: RuntimeConfig;
49
40
  [key: string]: any;
50
41
  }
51
42
  export declare const FlowPluginIndicator = "__flow_plugin";
package/dist/app/flow.mjs CHANGED
@@ -20,9 +20,6 @@ export function createFlowApp({ runtimeConfig }) {
20
20
  },
21
21
  engine: "eta",
22
22
  engines: {},
23
- site: {
24
- origin: `${process.env.URL || "http://localhost"}`
25
- },
26
23
  generate: runtimeConfig.generate
27
24
  };
28
25
  flowApp.engines.eta = (template) => {
@@ -1,4 +1,3 @@
1
1
  import 'node-fetch-native/polyfill';
2
- export declare const getFlowRenderer: () => Promise<any>;
3
2
  declare const _default: import("h3").EventHandler<void>;
4
3
  export default _default;
@@ -1,20 +1,25 @@
1
+ import { defineEventHandler } from "h3";
1
2
  import "node-fetch-native/polyfill";
2
- import { eventHandler } from "h3";
3
- import { defineCachedFunction, useRuntimeConfig } from "#internal/nitro";
4
- const getServerApp = () => import("#server").then((r) => r?.default?.default || r?.default || r);
5
- export const getFlowRenderer = lazyCachedFunction(async () => {
3
+ import { useRuntimeConfig } from "#internal/nitro";
4
+ const getServerApp = cachedImport(() => import("#server"));
5
+ const getFlowRenderer = cachedResult(async () => {
6
6
  const createFlowApp = await getServerApp();
7
7
  if (!createFlowApp)
8
8
  throw new Error("Server bundle is not available");
9
9
  return createFlowApp(useRuntimeConfig());
10
10
  });
11
- export default eventHandler(async (event) => {
11
+ export default defineEventHandler(async ({ context }) => {
12
12
  const flow = await getFlowRenderer();
13
- event.context.flow = flow;
14
- event.context.render = flow.render;
15
- event.context.defineCachedFunction = defineCachedFunction;
13
+ context.flow = flow;
14
+ context.render = flow.render;
16
15
  });
17
- function lazyCachedFunction(fn) {
16
+ function _interopDefault(e) {
17
+ return e && typeof e === "object" && "default" in e ? e.default : e;
18
+ }
19
+ function cachedImport(importer) {
20
+ return cachedResult(() => importer().then(_interopDefault).then(_interopDefault));
21
+ }
22
+ function cachedResult(fn) {
18
23
  let res = null;
19
24
  return () => {
20
25
  if (res === null)
@@ -1,120 +1,56 @@
1
- import { eventHandler, getQuery, readBody } from "h3";
2
- import { joinURL } from "ufo";
3
- import { getFlowRenderer } from "./flow.mjs";
4
- const normalizeCall = async (seo, ctx) => {
5
- if (typeof seo === "function")
6
- return await seo(ctx);
7
- return seo || {};
8
- };
9
- function replacePath(_path, url) {
10
- if (typeof url === "string") {
11
- _path = joinURL(_path.replace("/**", ""), url);
12
- } else {
13
- Object.entries(url).forEach(([key, value]) => {
14
- _path = _path.replace(`:${key}`, value);
15
- });
16
- if (url._ && _path.endsWith("**"))
17
- _path = joinURL(_path.replace("/**", ""), url._);
18
- }
19
- return _path;
20
- }
1
+ import { eventHandler, useQuery } from "h3";
21
2
  export default eventHandler(async (event) => {
22
3
  const url = event.req.url?.split("?")[0];
23
- const flow = await getFlowRenderer();
4
+ const flow = event.context.flow;
24
5
  if (url.includes("_urls")) {
25
- const urls = await flow.app.utils.getUrls(false, true);
6
+ const urls = await flow.app.utils.getUrls();
26
7
  return urls;
27
8
  }
28
9
  const scripts = { head: [], bodyStart: [], bodyEnd: [] };
29
10
  const chunks = { head: [], body: [] };
30
11
  const generate = {};
31
- const { page, locale, params, view, name: pageName, path: pagePath } = flow.router.byUrl.lookup(url) || {};
12
+ const { page, locale, params, view } = flow.router.byUrl.lookup(url) || {};
32
13
  if (!page)
33
14
  return;
15
+ await flow.callHook("page:scripts", scripts);
34
16
  if (view.bundle)
35
17
  await flow.callHook("page:chunks", view.bundle, chunks);
36
18
  const templateContext = {};
37
- const isDynamic = !!Object.keys(params || {});
38
- const contextPage = {
39
- chunks,
40
- locale,
41
- _post: {}
42
- };
43
- const contextInject = {};
44
- const utils = Object.assign({ getLocale: () => locale, injectContext: (key, value) => contextInject[key] = value, defineCachedFunction: event.context.defineCachedFunction }, flow.app.utils);
45
- const contextHooks = {};
46
- if (event.node.req.method.toLowerCase() === "post") {
47
- const body = await readBody(event);
48
- contextPage._post = body;
49
- }
19
+ const dynamyc = params?._;
20
+ const contextPage = {};
21
+ const utils = Object.assign({ getLocale: () => locale }, flow.app.utils);
50
22
  templateContext.url = url;
51
- templateContext.baseURL = flow.$config.app.baseURL;
52
- const pageObject = {
53
- name: pageName,
54
- pathname: url,
55
- url: joinURL(flow.site.origin, templateContext.baseURL, `${url}`),
56
- origin: flow.site.origin,
57
- joinOrigin: (_url, includeBase) => joinURL(flow.site.origin, includeBase ? templateContext.baseURL : "/", _url)
58
- };
59
- templateContext.page = pageObject;
60
- contextPage.page = pageObject;
61
23
  templateContext.locale = locale;
62
24
  templateContext.view = view;
63
- if (isDynamic && page.dynamic) {
25
+ if (dynamyc && page.dynamic) {
64
26
  const pages = await page.dynamic.method({ locale, utils });
65
- const dynamicPage = pages.find((_page) => {
66
- const aUrl = replacePath(pagePath, _page.url);
67
- const bUrl = replacePath(pagePath, params);
68
- return aUrl === bUrl;
69
- });
27
+ const dynamicPage = pages.find((_page) => _page.url === dynamyc);
70
28
  if (!dynamicPage)
71
29
  return;
72
30
  if (page.dynamic.assign)
73
31
  templateContext[page.dynamic.assign] = dynamicPage.context;
74
- contextPage.dynamic = dynamicPage;
32
+ contextPage.dynamyc = dynamicPage;
75
33
  }
76
- await flow.callHook("page:context", { localeCode: locale.code, page: pageName, ctx: contextPage }, utils, contextHooks);
77
34
  templateContext.seo = {};
78
- const sharedContext = await utils.getSharedContext({
79
- ...contextHooks,
80
- ...contextPage,
81
- utils
82
- });
83
- templateContext.sharedContext = sharedContext || {};
35
+ templateContext.context = {};
36
+ templateContext.sharedContext = {};
84
37
  templateContext.utils = utils;
85
- templateContext.seo = await normalizeCall(page?.seo, { ...contextHooks, ...contextPage, utils, sharedContext });
86
- const contexData = await page.context?.({ ...contextHooks, ...contextPage, utils, sharedContext }) || {};
87
- templateContext.context = {
88
- ...contextHooks,
89
- ...contexData
90
- };
91
- await flow.callHook("page:scripts", scripts, templateContext);
38
+ templateContext.seo = await page.seo?.({ ...contextPage, utils }) || {};
39
+ templateContext.context = await page.context?.({ ...contextPage, utils }) || {};
92
40
  templateContext.getHeadScripts = () => {
93
41
  return scripts.head.join("\n");
94
42
  };
95
- templateContext.getBodyEndScripts = () => {
96
- return scripts.bodyEnd.join("\n");
97
- };
98
43
  templateContext.getHeadChunks = () => {
99
44
  return chunks.head.join("\n");
100
45
  };
101
46
  templateContext.getBodyChunks = () => {
102
47
  return chunks.body.join("\n");
103
48
  };
104
- templateContext.getInjectContext = () => {
105
- return `<script id="__FLOW_DATA__" type="application/json">${JSON.stringify(contextInject)}<\/script>`;
106
- };
107
- const query = getQuery(event);
49
+ const query = useQuery(event);
108
50
  if (query?.context)
109
51
  return { ...templateContext, utils: Object.keys(utils) };
110
- let html;
111
- if (view.render)
112
- html = await view.render(templateContext, event);
113
- else
114
- html = await flow.render(view, templateContext);
115
- event.res.setHeader("Content-Type", view.contentType || "text/html;charset=UTF-8");
116
- if (view.postRender)
117
- html = await view.postRender(html, event);
52
+ const html = await flow.render(view, templateContext);
53
+ event.res.setHeader("Content-Type", "text/html;charset=UTF-8");
118
54
  if (flow.generate) {
119
55
  await flow.callHook("page:generate", generate);
120
56
  globalThis.generate = generate;
@@ -1,5 +1,6 @@
1
1
  import { defineFlowPlugin } from "#app";
2
2
  export default defineFlowPlugin((flow) => {
3
3
  flow._useHead = (_meta) => {
4
+ console.log(_meta);
4
5
  };
5
6
  });