@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.
- package/dist/core/runtime/nitro/flow.mjs +1 -1
- package/dist/core/runtime/nitro/renderer.mjs +18 -7
- package/dist/index.mjs +38 -29
- package/dist/pages/runtime/index.d.ts +2 -2
- package/dist/pages/runtime/index.mjs +8 -4
- package/dist/pages/runtime/plugin.mjs +30 -12
- package/dist/vite-client/runtime/plugin.mjs +1 -2
- package/package.json +19 -8
- 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,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
|
-
}
|
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
|
-
};
|