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

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/dist/app/entry.async.d.ts +3 -0
  2. package/dist/app/entry.async.mjs +1 -0
  3. package/dist/app/entry.d.ts +2 -2
  4. package/dist/app/entry.mjs +3 -2
  5. package/dist/app/flow.d.ts +12 -3
  6. package/dist/app/flow.mjs +3 -0
  7. package/dist/chunks/dev-bundler.mjs +277 -0
  8. package/dist/core/runtime/client.manifest.d.mts +2 -0
  9. package/dist/core/runtime/client.manifest.mjs +6 -0
  10. package/dist/core/runtime/nitro/flow.d.ts +1 -0
  11. package/dist/core/runtime/nitro/flow.mjs +9 -14
  12. package/dist/core/runtime/nitro/renderer.mjs +82 -18
  13. package/dist/core/runtime/vite-node-shared.d.mts +1 -0
  14. package/dist/core/runtime/vite-node-shared.d.ts +8 -0
  15. package/dist/core/runtime/vite-node-shared.mjs +3 -0
  16. package/dist/core/runtime/vite-node.d.mts +2 -0
  17. package/dist/core/runtime/vite-node.mjs +41 -0
  18. package/dist/head/runtime/plugin.mjs +0 -1
  19. package/dist/index.mjs +543 -772
  20. package/dist/pages/runtime/helpers/index.d.ts +1 -1
  21. package/dist/pages/runtime/helpers/index.mjs +14 -3
  22. package/dist/pages/runtime/index.d.ts +10 -3
  23. package/dist/pages/runtime/index.mjs +12 -4
  24. package/dist/pages/runtime/pages.mjs +123 -0
  25. package/package.json +55 -40
  26. package/build.config.ts +0 -25
  27. package/dist/pages/runtime/plugin.mjs +0 -53
  28. package/dist/vite-client/runtime/injectManifest.d.ts +0 -26
  29. package/dist/vite-client/runtime/injectManifest.mjs +0 -104
  30. package/dist/vite-client/runtime/plugin.d.ts +0 -2
  31. package/dist/vite-client/runtime/plugin.mjs +0 -27
  32. package/src/app/composables/index.ts +0 -20
  33. package/src/app/entry.ts +0 -36
  34. package/src/app/flow.ts +0 -157
  35. package/src/app/index.ts +0 -5
  36. package/src/auto-imports/module.ts +0 -143
  37. package/src/auto-imports/presets.ts +0 -49
  38. package/src/auto-imports/transform.ts +0 -48
  39. package/src/core/app.ts +0 -90
  40. package/src/core/builder.ts +0 -60
  41. package/src/core/flow.ts +0 -93
  42. package/src/core/modules.ts +0 -32
  43. package/src/core/nitro.ts +0 -206
  44. package/src/core/plugins/import-protection.ts +0 -49
  45. package/src/core/plugins/unctx.ts +0 -31
  46. package/src/core/runtime/nitro/flow.ts +0 -43
  47. package/src/core/runtime/nitro/paths.ts +0 -20
  48. package/src/core/runtime/nitro/renderer.ts +0 -74
  49. package/src/core/templates.ts +0 -119
  50. package/src/core/vite/builder/css.ts +0 -28
  51. package/src/core/vite/builder/dev-bundler.ts +0 -248
  52. package/src/core/vite/builder/index.ts +0 -96
  53. package/src/core/vite/builder/manifest.ts +0 -33
  54. package/src/core/vite/builder/plugins/analyze.ts +0 -32
  55. package/src/core/vite/builder/plugins/cache-dir.ts +0 -13
  56. package/src/core/vite/builder/plugins/dynamic-base.ts +0 -64
  57. package/src/core/vite/builder/plugins/virtual.ts +0 -45
  58. package/src/core/vite/builder/server.ts +0 -164
  59. package/src/core/vite/builder/types/index.ts +0 -13
  60. package/src/core/vite/builder/utils/index.ts +0 -53
  61. package/src/core/vite/builder/utils/warmup.ts +0 -27
  62. package/src/core/vite/builder/utils/wpfs.ts +0 -7
  63. package/src/core/vite/builder/vite-node.ts +0 -110
  64. package/src/core/vite/client/index.ts +0 -63
  65. package/src/dirs.ts +0 -8
  66. package/src/head/module.ts +0 -37
  67. package/src/head/runtime/composables.ts +0 -16
  68. package/src/head/runtime/index.ts +0 -1
  69. package/src/head/runtime/plugin.ts +0 -12
  70. package/src/index.ts +0 -2
  71. package/src/pages/module.ts +0 -55
  72. package/src/pages/runtime/helpers/chunks.ts +0 -0
  73. package/src/pages/runtime/helpers/index.ts +0 -33
  74. package/src/pages/runtime/index.ts +0 -9
  75. package/src/pages/runtime/plugin.ts +0 -65
  76. package/src/pages/templates.ts +0 -20
  77. package/src/pages/utils.ts +0 -49
  78. package/src/vite-client/module.ts +0 -84
  79. package/src/vite-client/runtime/injectManifest.ts +0 -188
  80. package/src/vite-client/runtime/plugin.ts +0 -33
  81. /package/dist/pages/runtime/{plugin.d.ts → pages.d.ts} +0 -0
package/src/app/flow.ts DELETED
@@ -1,157 +0,0 @@
1
- import type { RadixRouter } from 'radix3';
2
- import { createRouter } from 'radix3';
3
- import type { Hookable } from 'hookable';
4
- import { createHooks } from 'hookable';
5
- import type { FlowPage, RuntimeConfig } from '@monkeyplus/flow-schema';
6
- import { getContext } from 'unctx';
7
- import { globby } from 'globby';
8
- import { join, resolve } from 'pathe';
9
-
10
- const flowAppCtx = getContext<FlowApp>('flow-app');
11
-
12
- type HookResult = Promise<void> | void;
13
- export interface FlowAppHooks{
14
- 'flow:pages': (page: FlowPage[]) => HookResult
15
- 'eta:plugin': (options: any) => HookResult
16
- 'page:scripts': (scripts: { head: string[]; bodyEnd: string[]; bodyStart: string[] }) => HookResult
17
- 'page:links': (links: string[]) => HookResult
18
- 'page:chunks': (bundle: string, scripts: { head: string[]; body: string[] }) => HookResult
19
- 'page:generate': (generate: any) => HookResult
20
-
21
- }
22
- export interface FlowApp {
23
- router: { byUrl: RadixRouter<FlowPage['context']>; byName: RadixRouter<FlowPage['context']> }
24
- hooks: Hookable<FlowAppHooks>
25
- hook: FlowApp['hooks']['hook']
26
- callHook: FlowApp['hooks']['callHook']
27
- eta: any
28
- app: {
29
- utils: Record<string, any>
30
- plugins: Record<string, any>
31
- globals: Record<string, any>
32
- }
33
- engine: string
34
-
35
- engines: Record<string, (template: string) => string>
36
- generate: boolean
37
- render: (view: Record<string, string>, data: any) => Promise<string>|void|string
38
- provide: (name: string, value: any) => void
39
- setUtil: (name: string, value: any) => void
40
-
41
- [key: string]: any
42
-
43
- }
44
-
45
- export const FlowPluginIndicator = '__flow_plugin';
46
- export const NuxtPluginIndicator = '__nuxt_plugin';
47
-
48
- export interface Plugin<Injections extends Record<string, any> = Record<string, any>> {
49
- (flow: FlowApp): Promise<void> | Promise<{ provide?: Injections }> | void | { provide?: Injections }
50
- [FlowPluginIndicator]?: true
51
- }
52
- interface OptionsApp {
53
- runtimeConfig: RuntimeConfig
54
- }
55
-
56
- export function createFlowApp({ runtimeConfig }: OptionsApp): FlowApp {
57
- //
58
-
59
- const viewsDir = join(runtimeConfig.app.rootDir, 'views');
60
-
61
- const flowApp: FlowApp = {
62
- router: { byUrl: createRouter(), byName: createRouter() },
63
- app: {
64
- utils: {},
65
- globals: {},
66
- },
67
- eta: {
68
- views: viewsDir,
69
- plugins: [],
70
- },
71
- engine: 'eta',
72
- engines: { },
73
- generate: runtimeConfig.generate,
74
- } as FlowApp;
75
-
76
- flowApp.engines.eta = (template: string) => {
77
- return `<%~ await includeFile('templates/${template}',it) %>`;
78
- };
79
- flowApp.hooks = createHooks<FlowAppHooks>();
80
- flowApp.hook = flowApp.hooks.hook;
81
- flowApp.callHook = flowApp.hooks.callHook;
82
-
83
- flowApp.provide = (name: string, value: any) => {
84
- const $name = `$${name}`;
85
- defineGetter(flowApp, $name, value);
86
- // defineGetter(nuxtApp.vueApp.config.globalProperties, $name, value);
87
- };
88
- flowApp.setUtil = (name: string, method: any) => {
89
- flowApp.app.utils[name] = method;
90
- };
91
-
92
- flowApp.hook('eta:plugin', (_plugin) => {
93
- flowApp.eta.plugins.push(_plugin);
94
- });
95
-
96
- flowApp.provide('config', runtimeConfig);
97
-
98
- return flowApp;
99
- }
100
-
101
- export function defineFlowPlugin<T>(plugin: Plugin<T>) {
102
- plugin[FlowPluginIndicator] = true;
103
- return plugin;
104
- }
105
-
106
- export function defineNuxtPlugin<T>(plugin: Plugin<T>) {
107
- plugin[NuxtPluginIndicator] = true;
108
- return plugin;
109
- }
110
-
111
- export async function applyPlugin(flowApp: FlowApp, plugin: Plugin) {
112
- if (typeof plugin !== 'function') return;
113
- const { provide } = await callWithFlow(flowApp, plugin, [flowApp]) || {};
114
- if (provide && typeof provide === 'object') {
115
- for (const key in provide)
116
- flowApp.provide(key, provide[key]);
117
- }
118
- }
119
- export async function applyPlugins(flowApp: FlowApp, plugins: Plugin[]) {
120
- for (const plugin of plugins)
121
- await applyPlugin(flowApp, plugin);
122
- }
123
-
124
- /**
125
- * Ensures that the setup function passed in has access to the Nuxt instance via `useNuxt`.
126
- *
127
- * @param flow A Flow instance
128
- * @param setup The function to call
129
- */
130
- export function callWithFlow<T extends(...args: any[]) => any> (flow: FlowApp, setup: T, args?: Parameters<T>) {
131
- const fn = () => args ? setup(...args as Parameters<T>) : setup();
132
- // TODO: posible error
133
- flowAppCtx.set(flow);
134
- return flowAppCtx.callAsync<ReturnType<T>>(flow, fn);
135
- }
136
- /**
137
- * Returns the current Nuxt instance.
138
- */
139
- export function useFlowApp() {
140
- const flowAppInstance = flowAppCtx.use();
141
- if (!flowAppInstance)
142
- throw new Error('flow instance unavailable');
143
-
144
- return flowAppInstance;
145
- }
146
- export function useRuntimeConfig(): RuntimeConfig {
147
- return useFlowApp().$config;
148
- }
149
-
150
- function defineGetter<K extends string | number | symbol, V>(obj: Record<K, V>, key: K, val: V) {
151
- Object.defineProperty(obj, key, { get: () => val });
152
- }
153
-
154
- export async function resolveFiles(path: string, pattern: string | string[]) {
155
- const files = await globby(pattern, { cwd: path, followSymbolicLinks: true });
156
- return files.filter((file) => !file.includes('copy.ts')).map((p) => resolve(path, p));
157
- }
package/src/app/index.ts DELETED
@@ -1,5 +0,0 @@
1
- export * from './flow';
2
- export * from './composables';
3
-
4
- // @ts-ignore
5
- export { useHead } from '#head';
@@ -1,143 +0,0 @@
1
- import { addPluginTemplate, addTemplate, addVitePlugin, defineNuxtModule, logger, resolveAlias, useNuxt } from '@monkeyplus/flow-kit';
2
- import { isAbsolute, join, normalize, relative, resolve } from 'pathe';
3
- import type { Import, Unimport } from 'unimport';
4
- import { createUnimport, scanDirExports, toImports } from 'unimport';
5
- import type { AutoImportsOptions, FlowModule, ImportPresetWithDeprecation } from '@monkeyplus/flow-schema';
6
- import { TransformPlugin } from './transform';
7
- import { defaultPresets } from './presets';
8
-
9
- export default defineNuxtModule<Partial<AutoImportsOptions>>({
10
- meta: {
11
- name: 'auto-imports',
12
- configKey: 'autoImports',
13
- },
14
- defaults: {
15
- presets: defaultPresets,
16
- global: false,
17
- imports: [],
18
- dirs: [],
19
- transform: {
20
- exclude: undefined,
21
- },
22
- },
23
- async setup(options, flow) {
24
- // Allow modules extending sources
25
- await flow.callHook('autoImports:sources', options.presets as ImportPresetWithDeprecation[]);
26
-
27
- options.presets.forEach((i: ImportPresetWithDeprecation) => {
28
- if (typeof i !== 'string' && i.names && !i.imports) {
29
- i.imports = i.names;
30
- logger.warn('auto-imports: presets.names is deprecated, use presets.imports instead');
31
- }
32
- });
33
-
34
- // Filter disabled sources
35
- // options.sources = options.sources.filter(source => source.disabled !== true)
36
-
37
- // Create a context to share state between module internals
38
- const ctx = createUnimport({
39
- presets: options.presets,
40
- imports: options.imports,
41
- });
42
-
43
- // composables/ dirs from all layers
44
- let composablesDirs = [];
45
- for (const layer of flow.options._layers) {
46
- composablesDirs.push(resolve(layer.config.srcDir, 'composables'));
47
- for (const dir of (layer.config.autoImports?.dirs ?? []))
48
- composablesDirs.push(resolve(layer.config.srcDir, dir));
49
- }
50
-
51
- await flow.callHook('autoImports:dirs', composablesDirs);
52
- composablesDirs = composablesDirs.map((dir) => normalize(dir));
53
-
54
- // Support for importing from '#imports'
55
- addTemplate({
56
- filename: 'imports.mjs',
57
- getContents: () => ctx.toExports(),
58
- });
59
- flow.options.alias['#imports'] = join(flow.options.buildDir, 'imports');
60
-
61
- // Transpile and injection
62
- // @ts-ignore temporary disabled due to #746
63
- if (flow.options.dev && options.global) {
64
- // Add all imports to globalThis in development mode
65
- addPluginTemplate({
66
- filename: 'auto-imports.mjs',
67
- getContents: () => {
68
- const imports = ctx.getImports();
69
- const importStatement = toImports(imports);
70
- const globalThisSet = imports.map((i) => `globalThis.${i.as} = ${i.as};`).join('\n');
71
- return `${importStatement}\n\n${globalThisSet}\n\nexport default () => {};`;
72
- },
73
- });
74
- }
75
- else {
76
- // Transform to inject imports in production mode
77
- addVitePlugin(TransformPlugin.vite({ ctx, options, sourcemap: flow.options.sourcemap }));
78
- }
79
-
80
- const regenerateAutoImports = async() => {
81
- ctx.clearDynamicImports();
82
- await ctx.modifyDynamicImports(async(imports) => {
83
- // Scan composables/
84
- imports.push(...await scanDirExports(composablesDirs));
85
- // Modules extending
86
- await flow.callHook('autoImports:extend', imports);
87
- });
88
- };
89
-
90
- await regenerateAutoImports();
91
-
92
- // Generate types
93
- addDeclarationTemplates(ctx);
94
-
95
- // Add generated types to `nuxt.d.ts`
96
- flow.hook('prepare:types', ({ references }) => {
97
- references.push({ path: resolve(flow.options.buildDir, 'types/auto-imports.d.ts') });
98
- references.push({ path: resolve(flow.options.buildDir, 'imports.d.ts') });
99
- });
100
-
101
- // Watch composables/ directory
102
- flow.hook('builder:watch', async(_, path) => {
103
- const _resolved = resolve(flow.options.srcDir, path);
104
- if (composablesDirs.find((dir) => _resolved.startsWith(dir)))
105
- await flow.callHook('builder:generateApp');
106
- });
107
-
108
- flow.hook('builder:generateApp', async() => {
109
- await regenerateAutoImports();
110
- });
111
- },
112
- }) as FlowModule<any>;
113
-
114
- function addDeclarationTemplates(ctx: Unimport) {
115
- const nuxt = useNuxt();
116
-
117
- // Remove file extension for benefit of TypeScript
118
- const stripExtension = (path: string) => path.replace(/\.[a-z]+$/, '');
119
-
120
- const resolved = {};
121
- const r = ({ from }: Import) => {
122
- if (resolved[from])
123
- return resolved[from];
124
-
125
- let path = resolveAlias(from);
126
- if (isAbsolute(path))
127
- path = relative(join(nuxt.options.buildDir, 'types'), path);
128
-
129
- path = stripExtension(path);
130
- resolved[from] = path;
131
- return path;
132
- };
133
-
134
- addTemplate({
135
- filename: 'imports.d.ts',
136
- getContents: () => ctx.toExports(),
137
- });
138
-
139
- addTemplate({
140
- filename: 'types/auto-imports.d.ts',
141
- getContents: () => `// Generated by auto imports\n${ctx.generateTypeDecarations({ resolvePath: r })}`,
142
- });
143
- }
@@ -1,49 +0,0 @@
1
- import type { Preset } from 'unimport';
2
- import { defineUnimportPreset } from 'unimport';
3
-
4
- export const commonPresets: Preset[] = [
5
- // #head
6
- defineUnimportPreset({
7
- from: '#head',
8
- imports: [
9
- 'useHead',
10
- ],
11
- }),
12
-
13
- ];
14
-
15
- export const appPreset = defineUnimportPreset({
16
- from: '#app',
17
- imports: [
18
- 'useRuntimeConfig',
19
- 'defineFlowPlugin',
20
- 'defineNuxtPlugin',
21
- 'useCookie',
22
- 'refreshNuxtData',
23
- 'useAsyncData',
24
- 'useRoute',
25
-
26
- ],
27
- });
28
-
29
- // * Compatibilitie Nuxt
30
- export const vuePreset = defineUnimportPreset({
31
- from: 'vue',
32
- imports: [
33
- // Components
34
- 'defineComponent',
35
- 'getCurrentInstance',
36
- 'useSlots',
37
- 'h',
38
-
39
- // Reactivity
40
- 'computed',
41
-
42
- ],
43
- });
44
-
45
- export const defaultPresets = [
46
- ...commonPresets,
47
- appPreset,
48
- vuePreset,
49
- ];
@@ -1,48 +0,0 @@
1
- import { pathToFileURL } from 'node:url';
2
- import { createUnplugin } from 'unplugin';
3
- import { parseQuery, parseURL } from 'ufo';
4
- import type { Unimport } from 'unimport';
5
- import type { AutoImportsOptions } from '@monkeyplus/flow-schema';
6
-
7
- export const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }: { ctx: Unimport; options: Partial<AutoImportsOptions>; sourcemap?: boolean }) => {
8
- return {
9
- name: 'flow:auto-imports-transform',
10
- enforce: 'post',
11
- transformInclude(id) {
12
- const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
13
- const { type, macro } = parseQuery(search);
14
-
15
- const exclude = options.transform?.exclude || [/[\\/]node_modules[\\/]/];
16
- const include = options.transform?.include || [];
17
-
18
- // Exclude node_modules by default
19
- if (exclude.some((pattern) => id.match(pattern)))
20
- return false;
21
-
22
- // Custom includes
23
- if (include.some((pattern) => id.match(pattern)))
24
- return true;
25
-
26
- // vue files
27
- if (
28
- pathname.endsWith('.vue')
29
- && (type === 'template' || type === 'script' || macro || !search)
30
- )
31
- return true;
32
-
33
- // js files
34
- if (pathname.match(/\.((c|m)?j|t)sx?$/g))
35
- return true;
36
- },
37
- async transform(_code, id) {
38
- const { code, s } = await ctx.injectImports(_code);
39
- if (code === _code)
40
- return;
41
-
42
- return {
43
- code,
44
- map: sourcemap && s.generateMap({ source: id, includeContent: true }),
45
- };
46
- },
47
- };
48
- });
package/src/core/app.ts DELETED
@@ -1,90 +0,0 @@
1
- import { promises as fsp } from 'node:fs';
2
- import type { Flow, FlowApp, FlowPlugin } from '@monkeyplus/flow-schema';
3
- import { compileTemplate, normalizePlugin, normalizeTemplate, resolveFilesFlow, templateUtils } from '@monkeyplus/flow-kit';
4
- import defu from 'defu';
5
-
6
- import { dirname, resolve } from 'pathe';
7
-
8
- import * as defaultTemplates from './templates';
9
-
10
- export function createApp(flow: Flow, options: Partial<FlowApp> = {}): FlowApp {
11
- return defu(options, {
12
- dir: flow.options.srcDir,
13
- extensions: flow.options.extensions,
14
- plugins: [],
15
- templates: [],
16
-
17
- } as FlowApp);
18
- }
19
-
20
- export async function generateApp(flow: Flow, app: FlowApp) {
21
- await resolveApp(flow, app);
22
- // User templates from options.build.templates
23
- app.templates = Object.values(defaultTemplates).concat(
24
- flow.options.build.templates,
25
- );
26
-
27
- // Extend templates with hook
28
- await flow.callHook('app:templates', app);
29
- // Normalize templates
30
- app.templates = app.templates.map((tmpl) => normalizeTemplate(tmpl));
31
-
32
- // Compile templates into vfs
33
- const templateContext = { utils: templateUtils, nuxt: flow, app };
34
- await Promise.all(
35
- app.templates.map(async(template) => {
36
- const contents = await compileTemplate(template, templateContext);
37
-
38
- const fullPath
39
- = template.dst || resolve(flow.options.buildDir, template.filename);
40
- flow.vfs[fullPath] = contents;
41
-
42
- const aliasPath = `#build/${template.filename.replace(/\.\w+$/, '')}`;
43
- flow.vfs[aliasPath] = contents;
44
-
45
- // In case a non-normalized absolute path is called for on Windows
46
- if (process.platform === 'win32')
47
- flow.vfs[fullPath.replace(/\//g, '\\')] = contents;
48
-
49
- if (template.write) {
50
- await fsp.mkdir(dirname(fullPath), { recursive: true });
51
- await fsp.writeFile(fullPath, contents, 'utf8');
52
- }
53
- }),
54
- );
55
-
56
- await flow.callHook('app:templatesGenerated', app);
57
- }
58
-
59
- export async function resolveApp(flow: Flow, app: FlowApp) {
60
- // Resolve plugins
61
- app.plugins = [...flow.options.plugins.map(normalizePlugin)];
62
- for (const config of flow.options._layers.map((layer) => layer.config)) {
63
- app.plugins.push(
64
- ...[
65
- ...(config.plugins || []),
66
- ...(await resolveFilesFlow(config.srcDir, [
67
- 'plugins/*.{ts,js,mjs,cjs,mts,cts}',
68
- 'plugins/*/index.*{ts,js,mjs,cjs,mts,cts}',
69
- ])),
70
- ].map((plugin) => normalizePlugin(plugin as FlowPlugin)),
71
- );
72
- }
73
- app.plugins = uniqueBy(app.plugins, 'src');
74
-
75
- // Extend app
76
- await flow.callHook('app:resolve', app);
77
- }
78
-
79
- function uniqueBy<T, K extends keyof T>(arr: T[], key: K) {
80
- const res: T[] = [];
81
- const seen = new Set<T[K]>();
82
- for (const item of arr) {
83
- if (seen.has(item[key]))
84
- continue;
85
-
86
- seen.add(item[key]);
87
- res.push(item);
88
- }
89
- return res;
90
- }
@@ -1,60 +0,0 @@
1
- import { normalize } from 'pathe';
2
- import chokidar from 'chokidar';
3
- import type { Flow } from '@monkeyplus/flow-schema';
4
- import { isIgnoredFlow } from '@monkeyplus/flow-kit';
5
- import { debounce } from 'perfect-debounce';
6
- import { generateApp as _generateApp, createApp } from './app';
7
-
8
- import { bundleVite } from './vite/builder';
9
-
10
- export async function build(flow: Flow) {
11
- const app = createApp(flow);
12
- const generateApp = debounce(() => _generateApp(flow, app), undefined, { leading: true });
13
- await generateApp();
14
-
15
- if (flow.options.dev) {
16
- watch(flow);
17
- flow.hook('builder:watch', async(event, path) => {
18
- if (event !== 'change' && /app|error|plugins/i.test(path))
19
- await generateApp();
20
- });
21
- flow.hook('builder:generateApp', generateApp);
22
- }
23
-
24
- await flow.callHook('build:before', { flow }, flow.options.build);
25
- if (!flow.options._prepare) {
26
- await bundle(flow);
27
- await flow.callHook('build:done', { flow });
28
- }
29
-
30
- if (!flow.options.dev)
31
- await flow.callHook('close', flow);
32
- }
33
-
34
- function watch(flow: Flow) {
35
- const watcher = chokidar.watch(flow.options.srcDir, {
36
- ...flow.options.watchers.chokidar,
37
- cwd: flow.options.srcDir,
38
- ignoreInitial: true,
39
- ignored: [
40
- isIgnoredFlow,
41
- '.flow',
42
- 'node_modules',
43
- ],
44
- });
45
-
46
- const watchHook = debounce((event: 'add' | 'addDir' | 'change' | 'unlink' | 'unlinkDir', path: string) => flow.callHook('builder:watch', event, normalize(path)));
47
- watcher.on('all', watchHook);
48
- flow.hook('close', () => watcher.close());
49
- return watcher;
50
- }
51
-
52
- async function bundle(nuxt: Flow) {
53
- try {
54
- return bundleVite(nuxt);
55
- }
56
- catch (error) {
57
- await nuxt.callHook('build:error', error);
58
- throw error;
59
- }
60
- }
package/src/core/flow.ts DELETED
@@ -1,93 +0,0 @@
1
- import { createHooks } from 'hookable';
2
- import type { Flow, FlowConfig, FlowHooks, FlowOptions, ModuleContainer } from '@monkeyplus/flow-schema';
3
- import { resolve } from 'pathe';
4
- import type { LoadFlowOptions } from '@monkeyplus/flow-kit';
5
- import { installModule, loadFlowConfig, nuxtCtx } from '@monkeyplus/flow-kit';
6
- import { version } from '../../package.json';
7
- import { distDir, pkgDir } from '../dirs';
8
- import metaModule from '../head/module';
9
- import autoImportsModule from '../auto-imports/module';
10
- import pagesModule from '../pages/module';
11
- import viteModule from '../vite-client/module';
12
-
13
- import { initNitro } from './nitro';
14
- import { addModuleTranspiles } from './modules';
15
-
16
- export function createFlow(options: FlowOptions): Flow {
17
- const hooks = createHooks<FlowHooks>();
18
-
19
- const flow: Flow = {
20
- //* Include nuxt version
21
- _version: '3.0.0-rc.3',
22
- //* Include version
23
- // @ts-ignore
24
- version,
25
- options,
26
- hooks,
27
- callHook: hooks.callHook,
28
- addHooks: hooks.addHooks,
29
- hook: hooks.hook,
30
- ready: () => initFlow(flow),
31
- close: () => Promise.resolve(hooks.callHook('close', flow)),
32
- vfs: {},
33
- };
34
-
35
- return flow;
36
- }
37
-
38
- async function initFlow(flow: Flow): Promise<void> {
39
- // Register user hooks
40
- nuxtCtx.set(flow);
41
-
42
- flow.hook('close', () => nuxtCtx.unset());
43
- // flow.hook('prepare:types', (opts) => {...})
44
-
45
- await flow.callHook('modules:before', { nuxt: flow } as ModuleContainer);
46
-
47
- const modulesToInstall = [
48
- // ...flow.options.buildModules,
49
- ...flow.options.modules,
50
- ...flow.options._modules,
51
- ];
52
-
53
- for (const m of modulesToInstall) {
54
- if (Array.isArray(m))
55
- await installModule(m[0], m[1]);
56
-
57
- else
58
- await installModule(m, {});
59
- }
60
- await flow.callHook('modules:done', { nuxt: flow } as ModuleContainer);
61
-
62
- await addModuleTranspiles();
63
-
64
- await initNitro(flow);
65
-
66
- await flow.callHook('ready', flow);
67
- }
68
-
69
- export async function loadFlow(opts: LoadFlowOptions): Promise<Flow> {
70
- const options = await loadFlowConfig(opts);
71
- options.appDir = resolve(distDir, 'app');
72
- options._majorVersion = 3;
73
- options._modules.push(pagesModule, metaModule, autoImportsModule, viteModule);
74
- options.modulesDir.push(resolve(pkgDir, 'node_modules'));
75
- // options.build.transpile.push('@nuxt/ui-templates');
76
- // options.alias['vue-demi'] = resolve(options.appDir, 'compat/vue-demi');
77
- // options.alias['@vue/composition-api'] = resolve(options.appDir, 'compat/capi');
78
- // if (options.telemetry !== false && !process.env.NUXT_TELEMETRY_DISABLED)
79
- // options._modules.push('@nuxt/telemetry');
80
-
81
- const flow = createFlow(options);
82
-
83
- if (opts.ready !== false)
84
- await flow.ready();
85
-
86
- return flow;
87
- }
88
-
89
- export function defineFlowConfig(config: FlowConfig): FlowConfig {
90
- return config;
91
- }
92
-
93
- export type { FlowConfig };
@@ -1,32 +0,0 @@
1
- import { useNuxt } from '@monkeyplus/flow-kit';
2
-
3
- export interface AddModuleTranspilesOptions {
4
- additionalModules?: string[]
5
- }
6
-
7
- export const addModuleTranspiles = (opts: AddModuleTranspilesOptions = {}) => {
8
- const flow = useNuxt();
9
-
10
- const modules = [
11
- ...opts.additionalModules || [],
12
- ...flow.options.modules,
13
- ...flow.options._modules,
14
- ]
15
- .map((m) => typeof m === 'string' ? m : Array.isArray(m) ? m[0] : m.src)
16
- .filter((m) => typeof m === 'string')
17
- .map((m) => m.split('node_modules/').pop());
18
-
19
- // Try to sanitize modules to better match imports
20
- flow.options.build.transpile
21
- = flow.options.build.transpile.map((m) => typeof m === 'string' ? m.split('node_modules/').pop() : m);
22
-
23
- function isTranspilePresent(mod: string) {
24
- return flow.options.build.transpile.some((t) => !(t instanceof Function) && (t instanceof RegExp ? t.test(mod) : new RegExp(t).test(mod)));
25
- }
26
-
27
- // Automatically add used modules to the transpile
28
- for (const module of modules) {
29
- if (!isTranspilePresent(module))
30
- flow.options.build.transpile.push(module);
31
- }
32
- };