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

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 (58) hide show
  1. package/dist/core/runtime/nitro/flow.mjs +1 -1
  2. package/dist/core/runtime/nitro/renderer.mjs +18 -7
  3. package/dist/index.mjs +38 -29
  4. package/dist/pages/runtime/index.d.ts +2 -2
  5. package/dist/pages/runtime/index.mjs +8 -4
  6. package/dist/pages/runtime/plugin.mjs +30 -12
  7. package/dist/vite-client/runtime/plugin.mjs +1 -2
  8. package/package.json +19 -8
  9. package/build.config.ts +0 -25
  10. package/src/app/composables/index.ts +0 -20
  11. package/src/app/entry.ts +0 -36
  12. package/src/app/flow.ts +0 -157
  13. package/src/app/index.ts +0 -5
  14. package/src/auto-imports/module.ts +0 -143
  15. package/src/auto-imports/presets.ts +0 -49
  16. package/src/auto-imports/transform.ts +0 -48
  17. package/src/core/app.ts +0 -90
  18. package/src/core/builder.ts +0 -60
  19. package/src/core/flow.ts +0 -93
  20. package/src/core/modules.ts +0 -32
  21. package/src/core/nitro.ts +0 -206
  22. package/src/core/plugins/import-protection.ts +0 -49
  23. package/src/core/plugins/unctx.ts +0 -31
  24. package/src/core/runtime/nitro/flow.ts +0 -43
  25. package/src/core/runtime/nitro/paths.ts +0 -20
  26. package/src/core/runtime/nitro/renderer.ts +0 -74
  27. package/src/core/templates.ts +0 -119
  28. package/src/core/vite/builder/css.ts +0 -28
  29. package/src/core/vite/builder/dev-bundler.ts +0 -248
  30. package/src/core/vite/builder/index.ts +0 -96
  31. package/src/core/vite/builder/manifest.ts +0 -33
  32. package/src/core/vite/builder/plugins/analyze.ts +0 -32
  33. package/src/core/vite/builder/plugins/cache-dir.ts +0 -13
  34. package/src/core/vite/builder/plugins/dynamic-base.ts +0 -64
  35. package/src/core/vite/builder/plugins/virtual.ts +0 -45
  36. package/src/core/vite/builder/server.ts +0 -164
  37. package/src/core/vite/builder/types/index.ts +0 -13
  38. package/src/core/vite/builder/utils/index.ts +0 -53
  39. package/src/core/vite/builder/utils/warmup.ts +0 -27
  40. package/src/core/vite/builder/utils/wpfs.ts +0 -7
  41. package/src/core/vite/builder/vite-node.ts +0 -110
  42. package/src/core/vite/client/index.ts +0 -63
  43. package/src/dirs.ts +0 -8
  44. package/src/head/module.ts +0 -37
  45. package/src/head/runtime/composables.ts +0 -16
  46. package/src/head/runtime/index.ts +0 -1
  47. package/src/head/runtime/plugin.ts +0 -12
  48. package/src/index.ts +0 -2
  49. package/src/pages/module.ts +0 -55
  50. package/src/pages/runtime/helpers/chunks.ts +0 -0
  51. package/src/pages/runtime/helpers/index.ts +0 -33
  52. package/src/pages/runtime/index.ts +0 -9
  53. package/src/pages/runtime/plugin.ts +0 -65
  54. package/src/pages/templates.ts +0 -20
  55. package/src/pages/utils.ts +0 -49
  56. package/src/vite-client/module.ts +0 -84
  57. package/src/vite-client/runtime/injectManifest.ts +0 -188
  58. package/src/vite-client/runtime/plugin.ts +0 -33
@@ -1,65 +0,0 @@
1
-
2
- import { joinURL } from 'ufo';
3
- import type { FlowPage } from '@monkeyplus/flow-schema';
4
- import { definePage } from './helpers';
5
- import { defineFlowPlugin, useRuntimeConfig } from '#app';
6
- // @ts-ignore
7
- import pages from '#pages';
8
-
9
- export default defineFlowPlugin(async(flow) => {
10
- const { app } = useRuntimeConfig();
11
- const allPages: FlowPage['context'] [] = [];
12
-
13
- Object.entries(pages).forEach(([name, page]) => {
14
- const { getPages } = definePage({
15
- name,
16
- // @ts-expect-error
17
- ...page,
18
- });
19
- const _pages = getPages(app.locale.location!, app.locale.language!);
20
- _pages.forEach((page) => {
21
- flow.router.byUrl.insert(page.url, page.context);
22
- flow.router.byName.insert(page.name, page.context);
23
- allPages.push(page.context);
24
- });
25
- });
26
-
27
- function getUrl(namePage: string, localeCode?: string): string {
28
- const code: string = localeCode || this?.getLocale()?.code;
29
- const [lang, loc] = code.split('-');
30
- const name = joinURL('/', loc, lang, namePage);
31
- const { path } = flow.router.byName.lookup(name) || {};
32
- return path || '/404';
33
- }
34
-
35
- async function getUrls(withLocale = false) {
36
- const urls: (string|{ url: string; locale: string; name: string })[] = [];
37
- for (const page of allPages) {
38
- if (!page.path.includes('/**')) {
39
- urls.push(withLocale
40
- ? { url: page.path, locale: page.locale.code, name: page.name }
41
- : page.path);
42
- }
43
- else {
44
- const dPages = await page.page.dynamic.method({
45
- locale: page.locale,
46
- utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
47
- });
48
- dPages.forEach((dPage) => {
49
- const _path = joinURL(page.path.replace('/**', ''), dPage.url);
50
- urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
51
- });
52
- }
53
- }
54
- return urls.sort();
55
- }
56
- flow.setUtil('getUrl', getUrl);
57
- flow.setUtil('getUrls', getUrls);
58
- flow.setUtil('getPages', () => allPages);
59
-
60
- return {
61
- provide: {
62
- pages: { allPages },
63
- },
64
- };
65
- });
@@ -1,20 +0,0 @@
1
- import { genDynamicImport } from 'knitwork';
2
- import { isAbsolute, relative } from 'pathe';
3
- import { pascalCase } from 'scule';
4
- import type { Pages } from './utils';
5
- export interface PagesTemplateOptions {
6
- buildDir?: string
7
- pages: Pages[]
8
- }
9
- // TODO: include localeDefault
10
- export const pagesTypeTemplate = {
11
- filename: 'pages.d.ts',
12
- getContents: ({ options }: { options: PagesTemplateOptions }) => `// Generated by pages discovery
13
- export {}
14
- declare global {
15
-
16
- ${options.pages.map((c) => `export type ${pascalCase(c.name)}Context=Awaited<ReturnType<typeof ${genDynamicImport(isAbsolute(c.file) ? relative(options.buildDir, c.file) : c.file, { wrapper: false })}['pages']['locales']['es-ec']['context']>>`).join('\n')}
17
- }
18
- export const pagesNames: string[]
19
- `.replaceAll('.ts', ''),
20
- };
@@ -1,49 +0,0 @@
1
-
2
- import { resolveFilesFlow, useNuxt } from '@monkeyplus/flow-kit';
3
- import { extname, relative, resolve } from 'pathe';
4
- import escapeRE from 'escape-string-regexp';
5
- import { camelCase } from 'scule';
6
- import { genImport } from 'knitwork';
7
-
8
- // import {} from
9
-
10
- export interface Pages{ file: string; name: string }
11
- export async function resolvePagesRoutes(): Promise<Pages[]> {
12
- const nuxt = useNuxt();
13
-
14
- const pagesDirs = [...new Set(nuxt.options._layers.map(
15
- (layer) => resolve(layer.config.srcDir, layer.config.dir?.pages || 'pages'),
16
- ))];
17
-
18
- const allRoutes: Pages[] = (await Promise.all(
19
- pagesDirs.map(async(dir) => {
20
- const files = await resolveFilesFlow(dir, `**/*{${nuxt.options.extensions.join(',')}}`);
21
-
22
- // Sort to make sure parent are listed first
23
-
24
- files.sort();
25
- return files.map((file) => {
26
- const segments = relative(dir, file).replace(new RegExp(`${escapeRE(extname(file))}$`), '')
27
- .split('/').join('_');
28
-
29
- return {
30
- file,
31
- name: camelCase(segments),
32
- };
33
- });
34
- }),
35
- )).flat();
36
-
37
- return allRoutes;
38
-
39
- // return uniqueBy(allRoutes, 'path');
40
- }
41
-
42
- export function normalizePages(pages: Pages[]) {
43
- const imports = pages.map((page) => genImport(page.file, [{ name: 'pages', as: page.name }])).join('\n');
44
- return {
45
- imports,
46
- exports: pages.reduce((acc, curr) => `${curr.name || ''},${acc}`, ''),
47
-
48
- };
49
- }
@@ -1,84 +0,0 @@
1
- import { addPlugin, addTemplate, defineFlowModule } from '@monkeyplus/flow-kit';
2
- import type { FlowModule } from '@monkeyplus/flow-schema';
3
- import { resolve } from 'pathe';
4
- // import { genImport } from 'knitwork';
5
- import fse from 'fs-extra';
6
- import logger from 'consola';
7
- import { joinURL } from 'ufo';
8
- import { builClient, createClient } from '../core/vite/client';
9
- import { distDir } from '../dirs';
10
-
11
- interface OptionsViteClient{
12
- route: string
13
- dir: string
14
- }
15
- export default defineFlowModule<OptionsViteClient>({
16
-
17
- meta: {
18
- name: 'vite-client',
19
- configKey: 'bundle',
20
- },
21
- defaults: {
22
- route: '/_vite/',
23
- dir: '/client/pages',
24
- },
25
- async setup(_options, flow) {
26
- const runtimeDir = resolve(distDir, 'vite-client/runtime');
27
- flow.options.alias['#viteManifest'] = resolve(flow.options.buildDir, 'viteManifest.mjs');
28
- let vite: any;
29
- if (flow.options.dev) {
30
- flow.hook('nitro:init', async(nitro) => {
31
- vite = await createClient(flow);
32
- // return vite.middlewares;
33
- nitro.options.devHandlers.push({
34
- handler: vite.middlewares,
35
- route: _options.route,
36
- });
37
- });
38
- // addDevServerHandler({
39
- // route: _options.route,
40
- // handler: async(req, res) => {
41
- // return await vite.middlewares(req, res);
42
- // },
43
- // });
44
-
45
- addTemplate({
46
- filename: 'viteManifest.mjs',
47
- async getContents() {
48
- return ['export default {',
49
- `head:()=>'<script type="module" src="${joinURL('/', _options.route, '/@vite/client')}"></script>'`,
50
- ',',
51
- // eslint-disable-next-line no-template-curly-in-string
52
- `body: (bundle)=>\`<script type="module" src="${joinURL('/', _options.route, _options.dir)}/\${bundle}.ts"></script>\``,
53
- '}',
54
- ].join('\n');
55
- },
56
- });
57
- }
58
- else {
59
- flow.hook('modules:done', async() => {
60
- const start = Date.now();
61
- logger.info('Building client...');
62
- await builClient(flow);
63
-
64
- const file = resolve(flow.options.rootDir, '.vite/manifest.json');
65
- const manifest = await fse.readFile(file, 'utf8');
66
- logger.success(`Client build in ${Date.now() - start}ms`);
67
-
68
- addTemplate({
69
- filename: 'viteManifest.mjs',
70
- async getContents() {
71
- return ['export default ()=>(', manifest, ')',
72
- ].join('\n');
73
- },
74
- });
75
- // Manifest json
76
- });
77
- flow.hook('generate:before', async() => {
78
- const files = resolve(flow.options.rootDir, '.vite/scripts');
79
- await fse.copy(files, resolve(flow.options.generate.dir, 'assets'));
80
- });
81
- }
82
- addPlugin({ src: resolve(runtimeDir, 'plugin') });
83
- },
84
- }) as FlowModule<OptionsViteClient>;
@@ -1,188 +0,0 @@
1
- import { joinURL } from 'ufo';
2
- export type Manifest = Record<string, ManifestChunk>;
3
-
4
- export interface ManifestChunk {
5
- src?: string
6
- file: string
7
- css?: string[]
8
- assets?: string[]
9
- isEntry?: boolean
10
- isDynamicEntry?: boolean
11
- imports?: string[]
12
- dynamicImports?: string[]
13
- }
14
-
15
- export interface HtmlTagDescriptor {
16
- tag: string
17
- attrs?: Record<string, string | boolean | undefined>
18
- children?: string | HtmlTagDescriptor[]
19
- /**
20
- * default: 'head-prepend'
21
- */
22
- injectTo?: 'head' | 'body' | 'head-prepend' | 'body-prepend'
23
- }
24
- export const generateBundle = (config: any, bundle: Manifest, _id: string) => {
25
- const analyzedChunk: Map<ManifestChunk, number> = new Map();
26
-
27
- const getImportedChunks = (
28
- chunk: ManifestChunk,
29
- seen: Set<string> = new Set(),
30
- ): ManifestChunk[] => {
31
- const chunks: ManifestChunk[] = [];
32
- chunk.imports?.forEach((file) => {
33
- const importee = bundle[file];
34
- if (file.startsWith('_') && !seen.has(file)) {
35
- seen.add(file);
36
-
37
- // post-order traversal
38
- chunks.push(...getImportedChunks(importee, seen));
39
- chunks.push(importee);
40
- }
41
- });
42
- // TODO: evaluate if is nesesary
43
- // chunk.dynamicImports?.forEach((file) => {
44
- // const importee = bundle[file];
45
- // if (!seen.has(file)) {
46
- // seen.add(file);
47
- // // post-order traversal
48
- // chunks.push(...getImportedChunks(importee, seen));
49
- // chunks.push(importee);
50
- // }
51
- // });
52
- return chunks;
53
- };
54
- const toScriptTag = (
55
- chunk: ManifestChunk,
56
- publicBase: string,
57
- isAsync: boolean,
58
- ): HtmlTagDescriptor => ({
59
- tag: 'script',
60
- attrs: {
61
- ...(isAsync ? { async: true } : {}),
62
- type: 'module',
63
- crossorigin: true,
64
- src: toPublicPath(chunk.file, publicBase),
65
- },
66
- });
67
-
68
- const toPreloadTag = (
69
- chunk: ManifestChunk,
70
- publicBase: string,
71
- ): HtmlTagDescriptor => ({
72
- tag: 'link',
73
- attrs: {
74
- rel: 'modulepreload',
75
- crossorigin: true,
76
- href: toPublicPath(chunk.file, publicBase),
77
- },
78
- });
79
-
80
- const getCssTagsForChunk = (
81
- chunk: ManifestChunk,
82
- publicBase: string,
83
- seen: Set<string> = new Set(),
84
- ): HtmlTagDescriptor[] => {
85
- const tags: HtmlTagDescriptor[] = [];
86
- if (!analyzedChunk.has(chunk)) {
87
- analyzedChunk.set(chunk, 1);
88
- chunk.imports?.forEach((file) => {
89
- const importee = bundle[file];
90
- if (file.startsWith('_'))
91
- tags.push(...getCssTagsForChunk(importee, publicBase, seen));
92
- });
93
- }
94
-
95
- chunk.css?.forEach((file) => {
96
- if (!seen.has(file)) {
97
- seen.add(file);
98
- tags.push({
99
- tag: 'link',
100
- attrs: {
101
- rel: 'stylesheet',
102
- href: toPublicPath(file, publicBase),
103
- },
104
- });
105
- }
106
- });
107
-
108
- return tags;
109
- };
110
-
111
- // const relativeUrlPath = path.posix.relative(config.root, id);
112
- const publicBase = config.baseURL || '/'; // getPublicBase(relativeUrlPath, config);
113
-
114
- const isAsync = false;// isAsyncScriptMap.get(config)!.get(id)!;
115
-
116
- // const result = html;
117
- const chunk = Object.values(bundle).find(
118
- (chunk) =>
119
- chunk.isEntry && chunk.src === _id,
120
- );
121
-
122
- if (chunk) {
123
- // when not inlined, inject <script> for entry and modulepreload its dependencies
124
- // when inlined, discard entry chunk and inject <script> for everything in post-order
125
- const imports = getImportedChunks(chunk);
126
- const assetTags = [
127
- toScriptTag(chunk, publicBase, isAsync),
128
- ...imports.map((i) => toPreloadTag(i, publicBase)),
129
- ];
130
-
131
- assetTags.push(...getCssTagsForChunk(chunk, publicBase));
132
- const tags = serializeTags(assetTags);
133
- return { head: tags, body: '' };
134
- // result = injectToHead(result, assetTags);
135
- }
136
- };
137
-
138
- export const externalRE = /^(https?:)?\/\//;
139
- export const isExternalUrl = (url: string): boolean => externalRE.test(url);
140
-
141
- function toPublicPath(filename: string, publicBase: string) {
142
- return isExternalUrl(filename) ? filename : joinURL(publicBase, filename.replace('scripts', 'assets'));
143
- }
144
-
145
- const unaryTags = new Set(['link', 'meta', 'base']);
146
-
147
- function serializeTag(
148
- { tag, attrs, children }: HtmlTagDescriptor,
149
- indent = '',
150
- ): string {
151
- if (unaryTags.has(tag)) {
152
- return `<${tag}${serializeAttrs(attrs)}>`;
153
- }
154
- else {
155
- return `<${tag}${serializeAttrs(attrs)}>${serializeTags(
156
- children,
157
- incrementIndent(indent),
158
- )}</${tag}>`;
159
- }
160
- }
161
-
162
- function serializeTags(
163
- tags: HtmlTagDescriptor['children'],
164
- indent = '',
165
- ): string {
166
- if (typeof tags === 'string')
167
- return tags;
168
-
169
- else if (tags && tags.length)
170
- return tags.map((tag) => `${indent}${serializeTag(tag, indent)}\n`).join('');
171
-
172
- return '';
173
- }
174
-
175
- function serializeAttrs(attrs: HtmlTagDescriptor['attrs']): string {
176
- let res = '';
177
- for (const key in attrs) {
178
- if (typeof attrs[key] === 'boolean')
179
- res += attrs[key] ? ` ${key}` : '';
180
-
181
- else
182
- res += ` ${key}=${JSON.stringify(attrs[key])}`;
183
- }
184
- return res;
185
- }
186
- function incrementIndent(indent = '') {
187
- return `${indent}${indent[0] === '\t' ? '\t' : ' '}`;
188
- }
@@ -1,33 +0,0 @@
1
-
2
- import logger from 'consola';
3
- import { generateBundle } from './injectManifest';
4
- import { defineFlowPlugin } from '#app';
5
- // @ts-ignore
6
- import manifest from '#viteManifest';
7
- export default defineFlowPlugin((flow) => {
8
- if (typeof manifest === 'function') {
9
- const _manifest = manifest();
10
- flow.hook('page:chunks', (bundle, chunks) => {
11
- try {
12
- const chunk = generateBundle(flow.$config.app || {}, _manifest, `client/pages/${bundle}.ts`);
13
-
14
- if (chunk) {
15
- chunks.head.push(chunk.head);
16
- chunks.body.push(chunk.body);
17
- }
18
- else {
19
- logger.warn('Entry "%s" not found ', bundle);
20
- }
21
- }
22
- catch (error) {
23
- logger.error('Error in inject %s ', bundle);
24
- }
25
- });
26
- }
27
- else {
28
- flow.hook('page:chunks', (bundle, chunks) => {
29
- chunks.head.push(manifest.head());
30
- chunks.body.push(manifest.body(bundle));
31
- });
32
- }
33
- });