@monkeyplus/flow 5.0.0-rc.1 → 5.0.0-rc.10
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/composables/index.d.ts +2 -1
- package/dist/core/runtime/nitro/renderer.mjs +5 -1
- package/dist/index.mjs +25 -6
- package/dist/pages/runtime/index.d.ts +2 -2
- package/dist/pages/runtime/index.mjs +4 -4
- package/dist/pages/runtime/plugin.mjs +16 -10
- package/package.json +21 -9
- package/build.config.ts +0 -25
- package/src/app/composables/index.ts +0 -20
- package/src/app/entry.ts +0 -36
- package/src/app/flow.ts +0 -157
- package/src/app/index.ts +0 -5
- package/src/auto-imports/module.ts +0 -143
- package/src/auto-imports/presets.ts +0 -49
- package/src/auto-imports/transform.ts +0 -48
- package/src/core/app.ts +0 -90
- package/src/core/builder.ts +0 -60
- package/src/core/flow.ts +0 -93
- package/src/core/modules.ts +0 -32
- package/src/core/nitro.ts +0 -206
- package/src/core/plugins/import-protection.ts +0 -49
- package/src/core/plugins/unctx.ts +0 -31
- package/src/core/runtime/nitro/flow.ts +0 -43
- package/src/core/runtime/nitro/paths.ts +0 -20
- package/src/core/runtime/nitro/renderer.ts +0 -74
- package/src/core/templates.ts +0 -119
- package/src/core/vite/builder/css.ts +0 -28
- package/src/core/vite/builder/dev-bundler.ts +0 -248
- package/src/core/vite/builder/index.ts +0 -96
- package/src/core/vite/builder/manifest.ts +0 -33
- package/src/core/vite/builder/plugins/analyze.ts +0 -32
- package/src/core/vite/builder/plugins/cache-dir.ts +0 -13
- package/src/core/vite/builder/plugins/dynamic-base.ts +0 -64
- package/src/core/vite/builder/plugins/virtual.ts +0 -45
- package/src/core/vite/builder/server.ts +0 -164
- package/src/core/vite/builder/types/index.ts +0 -13
- package/src/core/vite/builder/utils/index.ts +0 -53
- package/src/core/vite/builder/utils/warmup.ts +0 -27
- package/src/core/vite/builder/utils/wpfs.ts +0 -7
- package/src/core/vite/builder/vite-node.ts +0 -110
- package/src/core/vite/client/index.ts +0 -63
- package/src/dirs.ts +0 -8
- package/src/head/module.ts +0 -37
- package/src/head/runtime/composables.ts +0 -16
- package/src/head/runtime/index.ts +0 -1
- package/src/head/runtime/plugin.ts +0 -12
- package/src/index.ts +0 -2
- package/src/pages/module.ts +0 -55
- package/src/pages/runtime/helpers/chunks.ts +0 -0
- package/src/pages/runtime/helpers/index.ts +0 -33
- package/src/pages/runtime/index.ts +0 -9
- package/src/pages/runtime/plugin.ts +0 -65
- package/src/pages/templates.ts +0 -20
- package/src/pages/utils.ts +0 -49
- package/src/vite-client/module.ts +0 -84
- package/src/vite-client/runtime/injectManifest.ts +0 -188
- package/src/vite-client/runtime/plugin.ts +0 -33
|
@@ -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
|
-
}
|
package/src/core/builder.ts
DELETED
|
@@ -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 };
|
package/src/core/modules.ts
DELETED
|
@@ -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
|
-
};
|
package/src/core/nitro.ts
DELETED
|
@@ -1,206 +0,0 @@
|
|
|
1
|
-
import { existsSync, promises as fsp } from 'node:fs';
|
|
2
|
-
import {
|
|
3
|
-
build,
|
|
4
|
-
copyPublicAssets,
|
|
5
|
-
createDevServer,
|
|
6
|
-
createNitro,
|
|
7
|
-
prepare,
|
|
8
|
-
prerender,
|
|
9
|
-
scanHandlers,
|
|
10
|
-
writeTypes,
|
|
11
|
-
|
|
12
|
-
} from 'nitropack';
|
|
13
|
-
import fsExtra from 'fs-extra';
|
|
14
|
-
import type { NitroConfig, NitroDevEventHandler, NitroEventHandler } from 'nitropack';
|
|
15
|
-
import defu from 'defu';
|
|
16
|
-
import { join, resolve } from 'pathe';
|
|
17
|
-
import type { Flow } from '@monkeyplus/flow-schema';
|
|
18
|
-
import { dynamicEventHandler, toEventHandler } from 'h3';
|
|
19
|
-
// import { debounce } from 'perfect-debounce';
|
|
20
|
-
import { distDir } from '../dirs';
|
|
21
|
-
import { ImportProtectionPlugin } from './plugins/import-protection';
|
|
22
|
-
|
|
23
|
-
export async function initNitro(flow: Flow): Promise<void> {
|
|
24
|
-
const { handlers, devHandlers } = await resolveHandlers(flow);
|
|
25
|
-
|
|
26
|
-
const _nitroConfig = ((flow.options as any).nitro || {}) as NitroConfig;
|
|
27
|
-
// const vite = await createVite(flow);
|
|
28
|
-
globalThis.generate = {};
|
|
29
|
-
const nitroConfig: NitroConfig = defu(_nitroConfig, <NitroConfig>{
|
|
30
|
-
rootDir: flow.options.rootDir,
|
|
31
|
-
srcDir: join(flow.options.srcDir, 'server'),
|
|
32
|
-
dev: flow.options.dev,
|
|
33
|
-
preset: flow.options.dev ? 'nitro-dev' : undefined,
|
|
34
|
-
buildDir: flow.options.buildDir,
|
|
35
|
-
scanDirs: flow.options._layers.map((layer) => join(layer.config.srcDir, 'server')),
|
|
36
|
-
renderer: resolve(distDir, 'core/runtime/nitro/renderer'),
|
|
37
|
-
// errorHandler: resolve(distDir, 'core/runtime/nitro/error'),
|
|
38
|
-
nodeModulesDirs: flow.options.modulesDir,
|
|
39
|
-
handlers,
|
|
40
|
-
devHandlers: [
|
|
41
|
-
|
|
42
|
-
],
|
|
43
|
-
baseURL: flow.options.app.baseURL,
|
|
44
|
-
runtimeConfig: {
|
|
45
|
-
...flow.options.runtimeConfig,
|
|
46
|
-
app: {
|
|
47
|
-
...flow.options.runtimeConfig.app,
|
|
48
|
-
rootDir: flow.options.rootDir,
|
|
49
|
-
locale: flow.options.locale,
|
|
50
|
-
},
|
|
51
|
-
nitro: {
|
|
52
|
-
envPrefix: 'FLOW_',
|
|
53
|
-
...flow.options.runtimeConfig.nitro,
|
|
54
|
-
},
|
|
55
|
-
generate: flow.options._generate,
|
|
56
|
-
},
|
|
57
|
-
typescript: {
|
|
58
|
-
generateTsConfig: false,
|
|
59
|
-
},
|
|
60
|
-
publicAssets: [
|
|
61
|
-
{
|
|
62
|
-
baseURL: flow.options.app.buildAssetsDir,
|
|
63
|
-
dir: resolve(flow.options.buildDir, 'dist/client'),
|
|
64
|
-
},
|
|
65
|
-
...flow.options._layers
|
|
66
|
-
.map((layer) => join(layer.config.srcDir, layer.config.dir?.public || 'public'))
|
|
67
|
-
.filter((dir) => existsSync(dir))
|
|
68
|
-
.map((dir) => ({ dir })),
|
|
69
|
-
],
|
|
70
|
-
prerender: {
|
|
71
|
-
crawlLinks: flow.options._generate ? flow.options.generate.crawler : false,
|
|
72
|
-
routes: []
|
|
73
|
-
.concat(flow.options._generate ? ['/_urls', ...flow.options.generate.routes] : []),
|
|
74
|
-
},
|
|
75
|
-
sourcemap: flow.options.sourcemap,
|
|
76
|
-
externals: {
|
|
77
|
-
inline: [
|
|
78
|
-
...(flow.options.dev ? [] : ['eta', '@monkeyplus/', '@vue/', '@nuxt/', flow.options.buildDir]),
|
|
79
|
-
'@monkeyplus/flow/dist',
|
|
80
|
-
],
|
|
81
|
-
},
|
|
82
|
-
alias: {
|
|
83
|
-
|
|
84
|
-
// Vue 3 mocks
|
|
85
|
-
'estree-walker': 'unenv/runtime/mock/proxy',
|
|
86
|
-
'@babel/parser': 'unenv/runtime/mock/proxy',
|
|
87
|
-
// Paths
|
|
88
|
-
'#paths': resolve(distDir, 'core/runtime/nitro/paths'),
|
|
89
|
-
// Shortcut to server main file
|
|
90
|
-
'#server': '#build/dist/server/server.mjs',
|
|
91
|
-
//* App dir
|
|
92
|
-
'#app': flow.options.appDir,
|
|
93
|
-
|
|
94
|
-
// Nuxt aliases
|
|
95
|
-
...flow.options.alias,
|
|
96
|
-
},
|
|
97
|
-
rollupConfig: {
|
|
98
|
-
plugins: [],
|
|
99
|
-
},
|
|
100
|
-
|
|
101
|
-
});
|
|
102
|
-
await flow.callHook('nitro:config', nitroConfig);
|
|
103
|
-
|
|
104
|
-
// Base middleware
|
|
105
|
-
nitroConfig.handlers.unshift({
|
|
106
|
-
middleware: true,
|
|
107
|
-
handler: resolve(distDir, 'core/runtime/nitro/flow'),
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
// Extend nitro config with hook
|
|
111
|
-
|
|
112
|
-
const nitro = await createNitro(nitroConfig);
|
|
113
|
-
|
|
114
|
-
// Expose nitro to modules
|
|
115
|
-
await flow.callHook('nitro:init', nitro);
|
|
116
|
-
|
|
117
|
-
// Connect vfs storages
|
|
118
|
-
nitro.vfs = flow.vfs = nitro.vfs || flow.vfs || {};
|
|
119
|
-
|
|
120
|
-
// Connect hooks
|
|
121
|
-
flow.hook('close', () => nitro.hooks.callHook('close'));
|
|
122
|
-
|
|
123
|
-
// Register flow protection patterns
|
|
124
|
-
nitro.hooks.hook('rollup:before', (nitro) => {
|
|
125
|
-
const plugin = ImportProtectionPlugin.rollup({
|
|
126
|
-
rootDir: flow.options.rootDir,
|
|
127
|
-
patterns: [
|
|
128
|
-
...['#app', /^#build(\/|$)/]
|
|
129
|
-
.map((p) => [p, 'Flow app aliases are not allowed in server routes.']) as [RegExp | string, string][],
|
|
130
|
-
],
|
|
131
|
-
});
|
|
132
|
-
nitro.options.rollupConfig.plugins.push(plugin);
|
|
133
|
-
});
|
|
134
|
-
// Setup handlers
|
|
135
|
-
const devMidlewareHandler = dynamicEventHandler();
|
|
136
|
-
nitro.options.devHandlers.unshift({ handler: devMidlewareHandler });
|
|
137
|
-
nitro.options.devHandlers.push(...devHandlers);
|
|
138
|
-
nitro.options.handlers.unshift({
|
|
139
|
-
route: '/__flow_error',
|
|
140
|
-
lazy: true,
|
|
141
|
-
handler: resolve(distDir, 'core/runtime/nitro/renderer'),
|
|
142
|
-
});
|
|
143
|
-
// Add typed route responses
|
|
144
|
-
flow.hook('prepare:types', async(opts) => {
|
|
145
|
-
if (flow.options._prepare) {
|
|
146
|
-
await scanHandlers(nitro);
|
|
147
|
-
await writeTypes(nitro);
|
|
148
|
-
}
|
|
149
|
-
opts.references.push({ path: resolve(flow.options.buildDir, 'types/nitro.d.ts') });
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
flow.hook('build:done', async() => {
|
|
153
|
-
await flow.callHook('nitro:build:before', nitro);
|
|
154
|
-
// console.log(nitro.options._config, nitro.vfs['#build/dist/server/server.mjs']);
|
|
155
|
-
|
|
156
|
-
if (flow.options.dev) {
|
|
157
|
-
await build(nitro);
|
|
158
|
-
}
|
|
159
|
-
else {
|
|
160
|
-
await prepare(nitro);
|
|
161
|
-
|
|
162
|
-
await copyPublicAssets(nitro);
|
|
163
|
-
|
|
164
|
-
await prerender(nitro);
|
|
165
|
-
if (!flow.options._generate) {
|
|
166
|
-
await build(nitro);
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
// TODO: refactor to nuxt
|
|
170
|
-
const nitroDev = await createNitro({
|
|
171
|
-
...nitro.options._config,
|
|
172
|
-
rootDir: nitro.options.rootDir,
|
|
173
|
-
logLevel: 0,
|
|
174
|
-
preset: 'nitro-prerender',
|
|
175
|
-
});
|
|
176
|
-
flow.server = nitroDev;
|
|
177
|
-
|
|
178
|
-
const distDir = resolve(flow.options.rootDir, 'dist');
|
|
179
|
-
if (!existsSync(distDir))
|
|
180
|
-
await fsp.symlink(nitro.options.output.publicDir, distDir, 'junction').catch(() => {});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
if (flow.options.dev) {
|
|
185
|
-
flow.hook('build:compile', ({ compiler }) => {
|
|
186
|
-
compiler.outputFileSystem = { ...fsExtra, join } as any;
|
|
187
|
-
});
|
|
188
|
-
flow.hook('server:devMiddleware', (m) => { devMidlewareHandler.set(toEventHandler(m)); });
|
|
189
|
-
flow.server = createDevServer(nitro);
|
|
190
|
-
flow.hook('build:resources', () => {
|
|
191
|
-
flow.server.reload();
|
|
192
|
-
});
|
|
193
|
-
const waitUntilCompile = new Promise<void>((resolve) => nitro.hooks.hook('compiled', () => resolve()));
|
|
194
|
-
flow.hook('build:done', () => waitUntilCompile);
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async function resolveHandlers(flow: Flow) {
|
|
199
|
-
const handlers: NitroEventHandler[] = [...flow.options.serverHandlers];
|
|
200
|
-
const devHandlers: NitroDevEventHandler[] = [...flow.options.devServerHandlers];
|
|
201
|
-
|
|
202
|
-
return {
|
|
203
|
-
handlers,
|
|
204
|
-
devHandlers,
|
|
205
|
-
};
|
|
206
|
-
}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';
|
|
2
|
-
import { createUnplugin } from 'unplugin';
|
|
3
|
-
import { logger } from '@monkeyplus/flow-kit';
|
|
4
|
-
import { isAbsolute, relative } from 'pathe';
|
|
5
|
-
|
|
6
|
-
const _require = createRequire(import.meta.url);
|
|
7
|
-
|
|
8
|
-
interface ImportProtectionOptions {
|
|
9
|
-
rootDir: string
|
|
10
|
-
patterns: [importPattern: string | RegExp, warning?: string][]
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// export const vueAppPatterns = (flow: Flow) => [
|
|
14
|
-
// [/^(nuxt3|nuxt)$/, '`nuxt3`/`nuxt` cannot be imported directly. Instead, import runtime Nuxt composables from `#app` or `#imports`.'],
|
|
15
|
-
// [/nuxt\.config/, 'Importing directly from a `nuxt.config` file is not allowed. Instead, use runtime config or a module.'],
|
|
16
|
-
// [/(^|node_modules\/)@vue\/composition-api/],
|
|
17
|
-
// ...nuxt.options.modules.filter((m) => typeof m === 'string').map((m: string) =>
|
|
18
|
-
// [new RegExp(`^${escapeRE(m)}$`), 'Importing directly from module entry points is not allowed.']),
|
|
19
|
-
// ...[/(^|node_modules\/)@nuxt\/kit/, /^nitropack/]
|
|
20
|
-
// .map((i) => [i, 'This module cannot be imported in the Vue part of your app.']),
|
|
21
|
-
// [new RegExp(escapeRE(resolve(nuxt.options.srcDir, (nuxt.options.dir as any).server || 'server'))), 'Importing from server middleware is not allowed in the Vue part of your app.'],
|
|
22
|
-
// ] as ImportProtectionOptions['patterns'];
|
|
23
|
-
|
|
24
|
-
export const ImportProtectionPlugin = createUnplugin((options: ImportProtectionOptions) => {
|
|
25
|
-
const cache: Record<string, Map<string | RegExp, boolean>> = {};
|
|
26
|
-
return {
|
|
27
|
-
name: 'flow:import-protection',
|
|
28
|
-
enforce: 'pre',
|
|
29
|
-
resolveId(id, importer) {
|
|
30
|
-
const invalidImports = options.patterns.filter(([pattern]) => pattern instanceof RegExp ? pattern.test(id) : pattern === id);
|
|
31
|
-
let matched: boolean;
|
|
32
|
-
for (const match of invalidImports) {
|
|
33
|
-
cache[id] = cache[id] || new Map();
|
|
34
|
-
const [pattern, warning] = match;
|
|
35
|
-
// Skip if already warned
|
|
36
|
-
if (cache[id].has(pattern)) continue;
|
|
37
|
-
|
|
38
|
-
const relativeImporter = isAbsolute(importer) ? relative(options.rootDir, importer) : importer;
|
|
39
|
-
logger.error(warning || 'Invalid import', `[importing \`${id}\` from \`${relativeImporter}\`]`);
|
|
40
|
-
cache[id].set(pattern, true);
|
|
41
|
-
matched = true;
|
|
42
|
-
}
|
|
43
|
-
if (matched)
|
|
44
|
-
return _require.resolve('unenv/runtime/mock/proxy');
|
|
45
|
-
|
|
46
|
-
return null;
|
|
47
|
-
},
|
|
48
|
-
};
|
|
49
|
-
});
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { Nuxt, NuxtApp, NuxtMiddleware } from '@monkeyplus/flow-schema';
|
|
2
|
-
import { createTransformer } from 'unctx/transform';
|
|
3
|
-
import { createUnplugin } from 'unplugin';
|
|
4
|
-
|
|
5
|
-
export const UnctxTransformPlugin = (nuxt: Nuxt) => {
|
|
6
|
-
const transformer = createTransformer({
|
|
7
|
-
asyncFunctions: ['defineNuxtPlugin', 'defineNuxtRouteMiddleware'],
|
|
8
|
-
});
|
|
9
|
-
|
|
10
|
-
let app: NuxtApp | undefined;
|
|
11
|
-
let middleware: NuxtMiddleware[] = [];
|
|
12
|
-
nuxt.hook('app:resolve', (_app) => { app = _app; });
|
|
13
|
-
nuxt.hook('pages:middleware:extend', (_middlewares) => { middleware = _middlewares; });
|
|
14
|
-
|
|
15
|
-
return createUnplugin((options: { sourcemap?: boolean } = {}) => ({
|
|
16
|
-
name: 'unctx:transfrom',
|
|
17
|
-
enforce: 'post',
|
|
18
|
-
transformInclude(id) {
|
|
19
|
-
return Boolean(app?.plugins.find((i) => i.src === id) || middleware.find((m) => m.path === id));
|
|
20
|
-
},
|
|
21
|
-
transform(code, id) {
|
|
22
|
-
const result = transformer.transform(code);
|
|
23
|
-
if (result) {
|
|
24
|
-
return {
|
|
25
|
-
code: result.code,
|
|
26
|
-
map: options.sourcemap && result.magicString.generateMap({ source: id, includeContent: true }),
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
}));
|
|
31
|
-
};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { defineEventHandler } from 'h3';
|
|
2
|
-
// TODO: remove in node 18
|
|
3
|
-
import 'node-fetch-native/polyfill';
|
|
4
|
-
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import { useRuntimeConfig } from '#internal/nitro';
|
|
7
|
-
|
|
8
|
-
// @ts-ignore
|
|
9
|
-
const getServerApp = cachedImport(() => import('#server'));
|
|
10
|
-
|
|
11
|
-
const getFlowRenderer = cachedResult(async() => {
|
|
12
|
-
// Load server bundle
|
|
13
|
-
const createFlowApp = await getServerApp();
|
|
14
|
-
|
|
15
|
-
if (!createFlowApp) throw new Error('Server bundle is not available');
|
|
16
|
-
// Create renderer
|
|
17
|
-
return createFlowApp(useRuntimeConfig());
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
export default defineEventHandler(async({ context }) => {
|
|
21
|
-
const flow = await getFlowRenderer(); // const flow = module.default(_config);
|
|
22
|
-
context.flow = flow;
|
|
23
|
-
context.render = flow.render;
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
function _interopDefault(e: any) {
|
|
27
|
-
return e && typeof e === 'object' && 'default' in e ? e.default : e;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function cachedImport <M>(importer: () => Promise<M>) {
|
|
31
|
-
return cachedResult(() => importer().then(_interopDefault).then(_interopDefault)) as () => Promise<M>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function cachedResult <T>(fn: () => Promise<T>): () => Promise<T> {
|
|
35
|
-
let res: Promise<T> | null = null;
|
|
36
|
-
// console.log(res);
|
|
37
|
-
return () => {
|
|
38
|
-
if (res === null)
|
|
39
|
-
res = fn().catch((err) => { res = null; throw err; });
|
|
40
|
-
|
|
41
|
-
return res;
|
|
42
|
-
};
|
|
43
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { joinURL } from 'ufo';
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import { useRuntimeConfig } from '#internal/nitro';
|
|
4
|
-
|
|
5
|
-
export function baseURL(): string {
|
|
6
|
-
return useRuntimeConfig().app.baseURL;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function buildAssetsDir(): string {
|
|
10
|
-
return useRuntimeConfig().app.buildAssetsDir;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function buildAssetsURL(...path: string[]): string {
|
|
14
|
-
return joinURL(publicAssetsURL(), useRuntimeConfig().app.buildAssetsDir, ...path);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function publicAssetsURL(...path: string[]): string {
|
|
18
|
-
const publicBase = useRuntimeConfig().app.cdnURL || useRuntimeConfig().app.baseURL;
|
|
19
|
-
return path.length ? joinURL(publicBase, ...path) : publicBase;
|
|
20
|
-
}
|