@monkeyplus/flow 5.0.0-rc.14 → 5.0.0-rc.140
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/entry.async.d.ts +3 -0
- package/dist/app/entry.async.mjs +1 -0
- package/dist/app/entry.mjs +1 -1
- package/dist/app/flow.d.ts +12 -3
- package/dist/app/flow.mjs +3 -0
- package/dist/chunks/dev-bundler.mjs +277 -0
- package/dist/core/runtime/client.manifest.d.mts +2 -0
- package/dist/core/runtime/client.manifest.mjs +6 -0
- package/dist/core/runtime/nitro/flow.d.ts +1 -0
- package/dist/core/runtime/nitro/flow.mjs +9 -14
- package/dist/core/runtime/nitro/renderer.mjs +69 -15
- package/dist/core/runtime/vite-node-shared.d.mts +1 -0
- package/dist/core/runtime/vite-node-shared.d.ts +8 -0
- package/dist/core/runtime/vite-node-shared.mjs +3 -0
- package/dist/core/runtime/vite-node.d.mts +2 -0
- package/dist/core/runtime/vite-node.mjs +41 -0
- package/dist/head/runtime/plugin.mjs +0 -1
- package/dist/index.mjs +527 -767
- package/dist/pages/runtime/helpers/index.d.ts +1 -1
- package/dist/pages/runtime/helpers/index.mjs +14 -3
- package/dist/pages/runtime/index.d.ts +10 -3
- package/dist/pages/runtime/index.mjs +10 -2
- package/dist/pages/runtime/pages.mjs +120 -0
- package/package.json +40 -36
- package/dist/pages/runtime/plugin.mjs +0 -59
- package/dist/vite-client/runtime/injectManifest.d.ts +0 -26
- package/dist/vite-client/runtime/injectManifest.mjs +0 -104
- package/dist/vite-client/runtime/plugin.d.ts +0 -2
- package/dist/vite-client/runtime/plugin.mjs +0 -27
- /package/dist/pages/runtime/{plugin.d.ts → pages.d.ts} +0 -0
package/dist/index.mjs
CHANGED
|
@@ -1,36 +1,33 @@
|
|
|
1
1
|
import { createHooks } from 'hookable';
|
|
2
2
|
import { dirname, resolve, normalize, join, isAbsolute, relative, extname } from 'pathe';
|
|
3
|
-
import { defineFlowModule, addPlugin, defineNuxtModule, logger, addTemplate, addPluginTemplate, addVitePlugin, useNuxt, resolveAlias, resolveFilesFlow, nuxtCtx, installModule, loadFlowConfig,
|
|
3
|
+
import { defineFlowModule, addPlugin, defineNuxtModule, logger, addTemplate, addPluginTemplate, addVitePlugin, addWebpackPlugin, updateTemplates, useNuxt, resolveAlias, resolveFilesFlow, nuxtCtx, installModule, loadFlowConfig, normalizeTemplate, compileTemplate, normalizePlugin, findPath, templateUtils, isIgnoredFlow } from '@monkeyplus/flow-kit';
|
|
4
|
+
import escapeRE from 'escape-string-regexp';
|
|
4
5
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
5
6
|
import { defineUnimportPreset, createUnimport, toImports, scanDirExports } from 'unimport';
|
|
7
|
+
import defu from 'defu';
|
|
6
8
|
import { createUnplugin } from 'unplugin';
|
|
7
|
-
import { parseURL, parseQuery, joinURL
|
|
8
|
-
import
|
|
9
|
+
import { parseURL, parseQuery, joinURL } from 'ufo';
|
|
10
|
+
import fs from 'fs';
|
|
9
11
|
import { camelCase, pascalCase } from 'scule';
|
|
10
|
-
import { genImport, genDynamicImport, genArrayFromRaw, genString
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import {
|
|
15
|
-
import { debounce } from 'perfect-debounce';
|
|
16
|
-
import { existsSync, promises, readdirSync, statSync } from 'node:fs';
|
|
17
|
-
import { createNitro, scanHandlers, writeTypes, build as build$2, prepare, copyPublicAssets, prerender, createDevServer } from 'nitropack';
|
|
18
|
-
import defu from 'defu';
|
|
19
|
-
import { dynamicEventHandler, toEventHandler } from 'h3';
|
|
20
|
-
import { createRequire, builtinModules } from 'node:module';
|
|
12
|
+
import { genImport, genDynamicImport, genSafeVariableName, genArrayFromRaw, genString } from 'knitwork';
|
|
13
|
+
import { existsSync, promises } from 'node:fs';
|
|
14
|
+
import { createNitro, scanHandlers, writeTypes, build as build$1, prepare, copyPublicAssets, prerender, createDevServer } from 'nitropack';
|
|
15
|
+
import { dynamicEventHandler } from 'h3';
|
|
16
|
+
import { createRequire } from 'node:module';
|
|
21
17
|
import chokidar from 'chokidar';
|
|
18
|
+
import { debounce } from 'perfect-debounce';
|
|
22
19
|
import { generateTypes, resolveSchema } from 'untyped';
|
|
23
|
-
import {
|
|
24
|
-
import { sanitizeFilePath } from 'mlly';
|
|
20
|
+
import { hash } from 'ohash';
|
|
21
|
+
import { resolvePath, sanitizeFilePath } from 'mlly';
|
|
22
|
+
import * as vite from 'vite';
|
|
25
23
|
import replace from '@rollup/plugin-replace';
|
|
26
|
-
import {
|
|
27
|
-
import
|
|
28
|
-
import MagicString from 'magic-string';
|
|
24
|
+
import { resolveTSConfig } from 'pkg-types';
|
|
25
|
+
import fse from 'fs-extra';
|
|
29
26
|
|
|
30
|
-
const version = "5.0.0-rc.
|
|
27
|
+
const version = "5.0.0-rc.140";
|
|
31
28
|
|
|
32
29
|
let _distDir = dirname(fileURLToPath(import.meta.url));
|
|
33
|
-
if (_distDir.
|
|
30
|
+
if (_distDir.match(/(chunks|shared)$/))
|
|
34
31
|
_distDir = dirname(_distDir);
|
|
35
32
|
const distDir = _distDir;
|
|
36
33
|
const pkgDir = resolve(distDir, "..");
|
|
@@ -53,35 +50,38 @@ const metaModule = defineFlowModule({
|
|
|
53
50
|
|
|
54
51
|
const TransformPlugin = createUnplugin(({ ctx, options, sourcemap }) => {
|
|
55
52
|
return {
|
|
56
|
-
name: "
|
|
53
|
+
name: "nuxt:imports-transform",
|
|
57
54
|
enforce: "post",
|
|
58
55
|
transformInclude(id) {
|
|
59
56
|
const { pathname, search } = parseURL(decodeURIComponent(pathToFileURL(id).href));
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const include = options.transform?.include || [];
|
|
63
|
-
if (exclude.some((pattern) => id.match(pattern)))
|
|
64
|
-
return false;
|
|
65
|
-
if (include.some((pattern) => id.match(pattern)))
|
|
57
|
+
const query = parseQuery(search);
|
|
58
|
+
if (options.transform?.include?.some((pattern) => id.match(pattern)))
|
|
66
59
|
return true;
|
|
67
|
-
if (
|
|
60
|
+
if (options.transform?.exclude?.some((pattern) => id.match(pattern)))
|
|
61
|
+
return false;
|
|
62
|
+
if (id.endsWith(".vue") || "macro" in query || "vue" in query && (query.type === "template" || query.type === "script" || "setup" in query))
|
|
68
63
|
return true;
|
|
69
64
|
if (pathname.match(/\.((c|m)?j|t)sx?$/g))
|
|
70
65
|
return true;
|
|
71
66
|
},
|
|
72
|
-
async transform(
|
|
73
|
-
|
|
74
|
-
|
|
67
|
+
async transform(code, id) {
|
|
68
|
+
id = normalize(id);
|
|
69
|
+
const isNodeModule = id.match(/[\\/]node_modules[\\/]/) && !options.transform?.include?.some((pattern) => id.match(pattern));
|
|
70
|
+
if (isNodeModule && !code.match(/(['"])#imports\1/))
|
|
75
71
|
return;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
const { s } = await ctx.injectImports(code, id, { autoImport: options.autoImport && !isNodeModule });
|
|
73
|
+
if (s.hasChanged()) {
|
|
74
|
+
return {
|
|
75
|
+
code: s.toString(),
|
|
76
|
+
map: sourcemap ? s.generateMap({ source: id, includeContent: true }) : void 0
|
|
77
|
+
};
|
|
78
|
+
}
|
|
80
79
|
}
|
|
81
80
|
};
|
|
82
81
|
});
|
|
83
82
|
|
|
84
83
|
const commonPresets = [
|
|
84
|
+
// #head
|
|
85
85
|
defineUnimportPreset({
|
|
86
86
|
from: "#head",
|
|
87
87
|
imports: [
|
|
@@ -92,7 +92,8 @@ const commonPresets = [
|
|
|
92
92
|
from: "#_pages",
|
|
93
93
|
imports: [
|
|
94
94
|
"definePage",
|
|
95
|
-
"
|
|
95
|
+
"defineDynamicPage",
|
|
96
|
+
"defineSharedContext"
|
|
96
97
|
]
|
|
97
98
|
})
|
|
98
99
|
];
|
|
@@ -111,10 +112,12 @@ const appPreset = defineUnimportPreset({
|
|
|
111
112
|
const vuePreset = defineUnimportPreset({
|
|
112
113
|
from: "vue",
|
|
113
114
|
imports: [
|
|
115
|
+
// Components
|
|
114
116
|
"defineComponent",
|
|
115
117
|
"getCurrentInstance",
|
|
116
118
|
"useSlots",
|
|
117
119
|
"h",
|
|
120
|
+
// Reactivity
|
|
118
121
|
"computed"
|
|
119
122
|
]
|
|
120
123
|
});
|
|
@@ -124,50 +127,65 @@ const defaultPresets = [
|
|
|
124
127
|
vuePreset
|
|
125
128
|
];
|
|
126
129
|
|
|
127
|
-
const
|
|
130
|
+
const importsModule = defineNuxtModule({
|
|
128
131
|
meta: {
|
|
129
|
-
name: "
|
|
130
|
-
configKey: "
|
|
132
|
+
name: "imports",
|
|
133
|
+
configKey: "imports"
|
|
131
134
|
},
|
|
132
135
|
defaults: {
|
|
136
|
+
autoImport: true,
|
|
133
137
|
presets: defaultPresets,
|
|
134
138
|
global: false,
|
|
135
139
|
imports: [],
|
|
136
140
|
dirs: [],
|
|
137
141
|
transform: {
|
|
142
|
+
include: [],
|
|
138
143
|
exclude: void 0
|
|
139
144
|
}
|
|
140
145
|
},
|
|
141
|
-
async setup(options,
|
|
142
|
-
|
|
143
|
-
|
|
146
|
+
async setup(options, nuxt) {
|
|
147
|
+
if (nuxt.options.autoImports) {
|
|
148
|
+
logger.warn("`autoImports` config is deprecated, use `imports` instead.");
|
|
149
|
+
options = defu(nuxt.options.autoImports, options);
|
|
150
|
+
}
|
|
151
|
+
await nuxt.callHook("imports:sources", options.presets);
|
|
152
|
+
options.presets?.forEach((_i) => {
|
|
153
|
+
const i = _i;
|
|
144
154
|
if (typeof i !== "string" && i.names && !i.imports) {
|
|
145
155
|
i.imports = i.names;
|
|
146
|
-
logger.warn("
|
|
156
|
+
logger.warn("imports: presets.names is deprecated, use presets.imports instead");
|
|
147
157
|
}
|
|
148
158
|
});
|
|
149
159
|
const ctx = createUnimport({
|
|
150
160
|
presets: options.presets,
|
|
151
|
-
imports: options.imports
|
|
161
|
+
imports: options.imports,
|
|
162
|
+
virtualImports: ["#imports"],
|
|
163
|
+
addons: {
|
|
164
|
+
vueTemplate: options.autoImport
|
|
165
|
+
}
|
|
152
166
|
});
|
|
153
167
|
let composablesDirs = [];
|
|
154
|
-
for (const layer of
|
|
168
|
+
for (const layer of nuxt.options._layers) {
|
|
155
169
|
composablesDirs.push(resolve(layer.config.srcDir, "composables"));
|
|
156
|
-
for (const dir of layer.config.
|
|
170
|
+
for (const dir of layer.config.imports?.dirs ?? []) {
|
|
171
|
+
if (!dir)
|
|
172
|
+
continue;
|
|
157
173
|
composablesDirs.push(resolve(layer.config.srcDir, dir));
|
|
174
|
+
}
|
|
158
175
|
}
|
|
159
|
-
await
|
|
176
|
+
await nuxt.callHook("imports:dirs", composablesDirs);
|
|
160
177
|
composablesDirs = composablesDirs.map((dir) => normalize(dir));
|
|
161
178
|
addTemplate({
|
|
162
179
|
filename: "imports.mjs",
|
|
163
|
-
getContents: () => ctx.toExports()
|
|
180
|
+
getContents: async () => `${await ctx.toExports()}
|
|
181
|
+
if (process.dev) { console.warn("[nuxt] \`#imports\` should be transformed with real imports. There seems to be something wrong with the imports plugin.") }`
|
|
164
182
|
});
|
|
165
|
-
|
|
166
|
-
if (
|
|
183
|
+
nuxt.options.alias["#imports"] = join(nuxt.options.buildDir, "imports");
|
|
184
|
+
if (nuxt.options.dev && options.global) {
|
|
167
185
|
addPluginTemplate({
|
|
168
|
-
filename: "
|
|
169
|
-
getContents: () => {
|
|
170
|
-
const imports = ctx.getImports();
|
|
186
|
+
filename: "imports.mjs",
|
|
187
|
+
getContents: async () => {
|
|
188
|
+
const imports = await ctx.getImports();
|
|
171
189
|
const importStatement = toImports(imports);
|
|
172
190
|
const globalThisSet = imports.map((i) => `globalThis.${i.as} = ${i.as};`).join("\n");
|
|
173
191
|
return `${importStatement}
|
|
@@ -178,32 +196,41 @@ export default () => {};`;
|
|
|
178
196
|
}
|
|
179
197
|
});
|
|
180
198
|
} else {
|
|
181
|
-
addVitePlugin(TransformPlugin.vite({ ctx, options, sourcemap:
|
|
199
|
+
addVitePlugin(TransformPlugin.vite({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }));
|
|
200
|
+
addWebpackPlugin(TransformPlugin.webpack({ ctx, options, sourcemap: nuxt.options.sourcemap.server || nuxt.options.sourcemap.client }));
|
|
182
201
|
}
|
|
183
|
-
const
|
|
202
|
+
const regenerateImports = async () => {
|
|
184
203
|
ctx.clearDynamicImports();
|
|
185
204
|
await ctx.modifyDynamicImports(async (imports) => {
|
|
186
205
|
imports.push(...await scanDirExports(composablesDirs));
|
|
187
|
-
await
|
|
206
|
+
await nuxt.callHook("imports:extend", imports);
|
|
188
207
|
});
|
|
189
208
|
};
|
|
190
|
-
await
|
|
191
|
-
addDeclarationTemplates(ctx);
|
|
192
|
-
|
|
193
|
-
references.push({ path: resolve(
|
|
194
|
-
references.push({ path: resolve(
|
|
209
|
+
await regenerateImports();
|
|
210
|
+
addDeclarationTemplates(ctx, options);
|
|
211
|
+
nuxt.hook("prepare:types", ({ references }) => {
|
|
212
|
+
references.push({ path: resolve(nuxt.options.buildDir, "types/imports.d.ts") });
|
|
213
|
+
references.push({ path: resolve(nuxt.options.buildDir, "imports.d.ts") });
|
|
195
214
|
});
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
215
|
+
const templates = [
|
|
216
|
+
"types/imports.d.ts",
|
|
217
|
+
"imports.d.ts",
|
|
218
|
+
"imports.mjs"
|
|
219
|
+
];
|
|
220
|
+
nuxt.hook("builder:watch", async (_, path) => {
|
|
221
|
+
const _resolved = resolve(nuxt.options.srcDir, path);
|
|
222
|
+
if (composablesDirs.find((dir) => _resolved.startsWith(dir))) {
|
|
223
|
+
await updateTemplates({
|
|
224
|
+
filter: (template) => templates.includes(template.filename)
|
|
225
|
+
});
|
|
226
|
+
}
|
|
200
227
|
});
|
|
201
|
-
|
|
202
|
-
await
|
|
228
|
+
nuxt.hook("builder:generateApp", async () => {
|
|
229
|
+
await regenerateImports();
|
|
203
230
|
});
|
|
204
231
|
}
|
|
205
232
|
});
|
|
206
|
-
function addDeclarationTemplates(ctx) {
|
|
233
|
+
function addDeclarationTemplates(ctx, options) {
|
|
207
234
|
const nuxt = useNuxt();
|
|
208
235
|
const stripExtension = (path) => path.replace(/\.[a-z]+$/, "");
|
|
209
236
|
const resolved = {};
|
|
@@ -219,49 +246,64 @@ function addDeclarationTemplates(ctx) {
|
|
|
219
246
|
};
|
|
220
247
|
addTemplate({
|
|
221
248
|
filename: "imports.d.ts",
|
|
222
|
-
getContents: () => ctx.toExports()
|
|
249
|
+
getContents: () => ctx.toExports(nuxt.options.buildDir)
|
|
223
250
|
});
|
|
224
251
|
addTemplate({
|
|
225
|
-
filename: "types/
|
|
226
|
-
getContents: () => `// Generated by auto imports
|
|
227
|
-
${ctx.
|
|
252
|
+
filename: "types/imports.d.ts",
|
|
253
|
+
getContents: async () => `// Generated by auto imports
|
|
254
|
+
${options.autoImport ? await ctx.generateTypeDeclarations({ resolvePath: r }) : "// Implicit auto importing is disabled, you can use explicitly import from `#imports` instead."}`
|
|
228
255
|
});
|
|
229
256
|
}
|
|
230
257
|
|
|
231
|
-
async function
|
|
258
|
+
async function resolveFiles(dir) {
|
|
232
259
|
const nuxt = useNuxt();
|
|
233
|
-
const
|
|
234
|
-
const allRoutes = (await Promise.all(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
260
|
+
const dirs = [resolve(nuxt.options.srcDir, dir)];
|
|
261
|
+
const allRoutes = (await Promise.all(
|
|
262
|
+
dirs.map(async (dir2) => {
|
|
263
|
+
const files = await resolveFilesFlow(dir2, `**/*{${nuxt.options.extensions.join(",")}}`);
|
|
264
|
+
files.sort();
|
|
265
|
+
return files.filter((file) => {
|
|
266
|
+
if (file.includes(" copy"))
|
|
267
|
+
return false;
|
|
268
|
+
if (!fs.readFileSync(file, "utf8").includes("export"))
|
|
269
|
+
return false;
|
|
270
|
+
return true;
|
|
271
|
+
}).map((file) => {
|
|
272
|
+
const segments = relative(dir2, file).replace(new RegExp(`${escapeRE(extname(file))}$`), "").split("/").join("_");
|
|
273
|
+
return {
|
|
274
|
+
file,
|
|
275
|
+
name: camelCase(segments)
|
|
276
|
+
};
|
|
277
|
+
});
|
|
278
|
+
})
|
|
279
|
+
)).flat();
|
|
245
280
|
return allRoutes;
|
|
246
281
|
}
|
|
247
|
-
function
|
|
248
|
-
const imports =
|
|
282
|
+
function normalizeExports(files) {
|
|
283
|
+
const imports = files.map((page) => genImport(page.file, page.name)).join("\n");
|
|
284
|
+
const exports = files.reduce((acc, curr) => {
|
|
285
|
+
const name = curr.name;
|
|
286
|
+
return `${name}:typeof ${name}==='function'?${name}():${name},${acc}`;
|
|
287
|
+
}, "");
|
|
249
288
|
return {
|
|
250
289
|
imports,
|
|
251
|
-
exports
|
|
252
|
-
const name = curr.name;
|
|
253
|
-
return `${name}:typeof ${name}==='function'?${name}():${name},${acc}`;
|
|
254
|
-
}, "")
|
|
290
|
+
exports
|
|
255
291
|
};
|
|
256
292
|
}
|
|
257
293
|
|
|
258
294
|
const pagesTypeTemplate = {
|
|
259
|
-
filename: "pages.d.ts",
|
|
295
|
+
filename: "types/pages.d.ts",
|
|
260
296
|
getContents: ({ options }) => `// Generated by pages discovery
|
|
261
297
|
export {}
|
|
262
298
|
declare global {
|
|
299
|
+
type ArrElement<ArrType> = ArrType extends readonly (infer ElementType)[]
|
|
300
|
+
? ElementType
|
|
301
|
+
: never;
|
|
263
302
|
|
|
264
|
-
${options.pages.map((c) =>
|
|
303
|
+
${options.pages.map((c) => {
|
|
304
|
+
const _type = `ArrElement<typeof ${genDynamicImport(isAbsolute(c.file) ? relative(join(options.buildDir, "types"), c.file) : c.file, { wrapper: false })}['default']>`;
|
|
305
|
+
return `export type ${pascalCase(c.name)}Context=Awaited<ReturnType<${_type}['locales']['es-ec']['context']>>`;
|
|
306
|
+
}).join("\n")}
|
|
265
307
|
}
|
|
266
308
|
export const pagesNames: string[]
|
|
267
309
|
`.replaceAll(".ts", "")
|
|
@@ -275,29 +317,44 @@ const pagesModule = defineNuxtModule({
|
|
|
275
317
|
const runtimeDir = resolve(distDir, "pages/runtime");
|
|
276
318
|
flow.options.alias["#_pages"] = runtimeDir;
|
|
277
319
|
const pages = [];
|
|
278
|
-
const
|
|
320
|
+
const contexts = [];
|
|
321
|
+
const options = { pages, buildDir: flow.options.buildDir, contexts };
|
|
279
322
|
addTemplate({
|
|
280
323
|
...pagesTypeTemplate,
|
|
281
324
|
options
|
|
282
325
|
});
|
|
283
326
|
const pagesDirs = [{ path: resolve(flow.options.srcDir, flow.options.dir.pages) }];
|
|
284
327
|
flow.options.alias["#pages"] = resolve(flow.options.buildDir, "pages.mjs");
|
|
328
|
+
flow.options.alias["#pagesContexts"] = resolve(flow.options.buildDir, "pages.contexts.mjs");
|
|
285
329
|
addTemplate({
|
|
286
330
|
filename: "pages.mjs",
|
|
287
331
|
async getContents({ options: options2 }) {
|
|
288
|
-
const { exports, imports } =
|
|
289
|
-
|
|
332
|
+
const { exports, imports } = normalizeExports(options2.pages);
|
|
333
|
+
const module = [imports, `export default {${exports}}`].join("\n");
|
|
334
|
+
return module;
|
|
335
|
+
},
|
|
336
|
+
options
|
|
337
|
+
});
|
|
338
|
+
addTemplate({
|
|
339
|
+
filename: "pages.contexts.mjs",
|
|
340
|
+
async getContents({ options: options2 }) {
|
|
341
|
+
const { exports, imports } = normalizeExports(options2.contexts);
|
|
342
|
+
const module = [imports, `export default {${exports}}`].join("\n");
|
|
343
|
+
return module;
|
|
290
344
|
},
|
|
291
345
|
options
|
|
292
346
|
});
|
|
293
347
|
flow.hook("app:templates", async () => {
|
|
294
|
-
options.pages = await
|
|
348
|
+
options.pages = await resolveFiles(flow.options.dir?.pages || "pages");
|
|
349
|
+
});
|
|
350
|
+
flow.hook("app:templates", async () => {
|
|
351
|
+
options.contexts = await resolveFiles("shared/contexts");
|
|
295
352
|
});
|
|
296
353
|
flow.hook("prepare:types", ({ references }) => {
|
|
297
|
-
references.push({ path: resolve(flow.options.buildDir, "pages.d.ts") });
|
|
354
|
+
references.push({ path: resolve(flow.options.buildDir, "types/pages.d.ts") });
|
|
298
355
|
});
|
|
299
356
|
flow.hook("builder:watch", async (event, path) => {
|
|
300
|
-
if (!["add", "unlink"].includes(event))
|
|
357
|
+
if (!["add", "unlink", "change"].includes(event))
|
|
301
358
|
return;
|
|
302
359
|
if (path.includes(" copy"))
|
|
303
360
|
return;
|
|
@@ -305,126 +362,28 @@ const pagesModule = defineNuxtModule({
|
|
|
305
362
|
if (pagesDirs.find((dir) => fPath.startsWith(dir.path)))
|
|
306
363
|
await flow.callHook("builder:generateApp");
|
|
307
364
|
});
|
|
308
|
-
addPlugin(
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
const createClient = async (flow) => {
|
|
313
|
-
let vite;
|
|
314
|
-
if (globalThis.viteClient) {
|
|
315
|
-
vite = globalThis.viteClient;
|
|
316
|
-
} else {
|
|
317
|
-
vite = await createServer({
|
|
318
|
-
root: resolve(flow.options.rootDir),
|
|
319
|
-
base: "/_vite/",
|
|
320
|
-
build: {
|
|
321
|
-
manifest: true
|
|
322
|
-
},
|
|
323
|
-
server: {
|
|
324
|
-
watch: {
|
|
325
|
-
ignored: ["**/.env/**", "**/.env*"]
|
|
326
|
-
},
|
|
327
|
-
middlewareMode: "ssr"
|
|
328
|
-
}
|
|
329
|
-
});
|
|
330
|
-
globalThis.viteClient = vite;
|
|
331
|
-
}
|
|
332
|
-
const _doReload = () => {
|
|
333
|
-
if (vite)
|
|
334
|
-
vite?.ws?.send({ type: "full-reload" });
|
|
335
|
-
};
|
|
336
|
-
const doReload = debounce(_doReload, 60);
|
|
337
|
-
flow.hook("bundler:change", () => {
|
|
338
|
-
doReload();
|
|
339
|
-
});
|
|
340
|
-
flow.hook("close", async () => {
|
|
341
|
-
vite.restart();
|
|
342
|
-
});
|
|
343
|
-
return vite;
|
|
344
|
-
};
|
|
345
|
-
const builClient = async (flow) => {
|
|
346
|
-
return await build$1({
|
|
347
|
-
root: flow.options.rootDir,
|
|
348
|
-
mode: "production",
|
|
349
|
-
build: {
|
|
350
|
-
assetsDir: "scripts",
|
|
351
|
-
target: "es2017",
|
|
352
|
-
outDir: ".vite",
|
|
353
|
-
manifest: true
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
const viteModule = defineFlowModule({
|
|
359
|
-
meta: {
|
|
360
|
-
name: "vite-client",
|
|
361
|
-
configKey: "bundle"
|
|
362
|
-
},
|
|
363
|
-
defaults: {
|
|
364
|
-
route: "/_vite/",
|
|
365
|
-
dir: "/client/pages"
|
|
366
|
-
},
|
|
367
|
-
async setup(_options, flow) {
|
|
368
|
-
const runtimeDir = resolve(distDir, "vite-client/runtime");
|
|
369
|
-
flow.options.alias["#viteManifest"] = resolve(flow.options.buildDir, "viteManifest.mjs");
|
|
370
|
-
let vite;
|
|
371
|
-
if (flow.options.dev) {
|
|
372
|
-
flow.hook("nitro:init", async (nitro) => {
|
|
373
|
-
vite = await createClient(flow);
|
|
374
|
-
nitro.options.devHandlers.push({
|
|
375
|
-
handler: vite.middlewares,
|
|
376
|
-
route: _options.route
|
|
377
|
-
});
|
|
378
|
-
});
|
|
379
|
-
addTemplate({
|
|
380
|
-
filename: "viteManifest.mjs",
|
|
381
|
-
async getContents() {
|
|
382
|
-
return [
|
|
383
|
-
"export default {",
|
|
384
|
-
`head:()=>'<script type="module" src="${joinURL("/", _options.route, "/@vite/client")}"><\/script>'`,
|
|
385
|
-
",",
|
|
386
|
-
`body: (bundle)=>\`<script type="module" src="${joinURL("/", _options.route, _options.dir)}/\${bundle}.ts"><\/script>\``,
|
|
387
|
-
"}"
|
|
388
|
-
].join("\n");
|
|
389
|
-
}
|
|
390
|
-
});
|
|
391
|
-
} else {
|
|
392
|
-
flow.hook("modules:done", async () => {
|
|
393
|
-
const start = Date.now();
|
|
394
|
-
logger$1.info("Building client...");
|
|
395
|
-
await builClient(flow);
|
|
396
|
-
const file = resolve(flow.options.rootDir, ".vite/manifest.json");
|
|
397
|
-
const manifest = await fse.readFile(file, "utf8");
|
|
398
|
-
logger$1.success(`Client build in ${Date.now() - start}ms`);
|
|
399
|
-
addTemplate({
|
|
400
|
-
filename: "viteManifest.mjs",
|
|
401
|
-
async getContents() {
|
|
402
|
-
return [
|
|
403
|
-
"export default ()=>(",
|
|
404
|
-
manifest,
|
|
405
|
-
")"
|
|
406
|
-
].join("\n");
|
|
407
|
-
}
|
|
408
|
-
});
|
|
409
|
-
});
|
|
410
|
-
flow.hook("generate:before", async () => {
|
|
411
|
-
const files = resolve(flow.options.rootDir, ".vite/scripts");
|
|
412
|
-
await fse.copy(files, resolve(flow.options.generate.dir, "assets"));
|
|
413
|
-
});
|
|
414
|
-
}
|
|
415
|
-
addPlugin({ src: resolve(runtimeDir, "plugin") });
|
|
365
|
+
addPlugin(resolve(runtimeDir, "pages"));
|
|
416
366
|
}
|
|
417
367
|
});
|
|
418
368
|
|
|
419
369
|
const _require = createRequire(import.meta.url);
|
|
420
370
|
const ImportProtectionPlugin = createUnplugin((options) => {
|
|
421
371
|
const cache = {};
|
|
372
|
+
const importersToExclude = options?.exclude || [];
|
|
422
373
|
return {
|
|
423
|
-
name: "
|
|
374
|
+
name: "nuxt:import-protection",
|
|
424
375
|
enforce: "pre",
|
|
425
376
|
resolveId(id, importer) {
|
|
377
|
+
if (!importer)
|
|
378
|
+
return;
|
|
379
|
+
if (id.startsWith("."))
|
|
380
|
+
id = join(importer, "..", id);
|
|
381
|
+
if (isAbsolute(id))
|
|
382
|
+
id = relative(options.rootDir, id);
|
|
383
|
+
if (importersToExclude.some((p) => typeof p === "string" ? importer === p : p.test(importer)))
|
|
384
|
+
return;
|
|
426
385
|
const invalidImports = options.patterns.filter(([pattern]) => pattern instanceof RegExp ? pattern.test(id) : pattern === id);
|
|
427
|
-
let matched;
|
|
386
|
+
let matched = false;
|
|
428
387
|
for (const match of invalidImports) {
|
|
429
388
|
cache[id] = cache[id] || /* @__PURE__ */ new Map();
|
|
430
389
|
const [pattern, warning] = match;
|
|
@@ -443,25 +402,38 @@ const ImportProtectionPlugin = createUnplugin((options) => {
|
|
|
443
402
|
});
|
|
444
403
|
|
|
445
404
|
async function initNitro(flow) {
|
|
446
|
-
const { handlers, devHandlers } = await resolveHandlers(flow);
|
|
447
405
|
const _nitroConfig = flow.options.nitro || {};
|
|
448
406
|
globalThis.generate = {};
|
|
407
|
+
const scanDirs = flow.options._layers.map((layer) => (layer.config.serverDir || layer.config.srcDir) && resolve(layer.cwd, layer.config.serverDir || resolve(layer.config.srcDir, "server"))).filter(Boolean);
|
|
449
408
|
const nitroConfig = defu(_nitroConfig, {
|
|
450
409
|
rootDir: flow.options.rootDir,
|
|
451
|
-
|
|
410
|
+
workspaceDir: flow.options.workspaceDir,
|
|
411
|
+
srcDir: flow.options.serverDir,
|
|
452
412
|
dev: flow.options.dev,
|
|
453
|
-
preset: flow.options.dev ? "nitro-dev" : void 0,
|
|
454
413
|
buildDir: flow.options.buildDir,
|
|
455
|
-
scanDirs
|
|
414
|
+
scanDirs,
|
|
456
415
|
renderer: resolve(distDir, "core/runtime/nitro/renderer"),
|
|
416
|
+
// errorHandler: resolve(distDir, 'core/runtime/nitro/error'),
|
|
457
417
|
nodeModulesDirs: flow.options.modulesDir,
|
|
458
|
-
handlers
|
|
418
|
+
handlers: [
|
|
419
|
+
//* Important middleware
|
|
420
|
+
{
|
|
421
|
+
middleware: true,
|
|
422
|
+
handler: resolve(distDir, "core/runtime/nitro/flow")
|
|
423
|
+
},
|
|
424
|
+
...flow.options.serverHandlers
|
|
425
|
+
],
|
|
426
|
+
output: {
|
|
427
|
+
dir: resolve(flow.options.buildDir, "output")
|
|
428
|
+
},
|
|
459
429
|
devHandlers: [],
|
|
460
430
|
baseURL: flow.options.app.baseURL,
|
|
431
|
+
virtual: {},
|
|
461
432
|
runtimeConfig: {
|
|
462
433
|
...flow.options.runtimeConfig,
|
|
463
434
|
app: {
|
|
464
435
|
...flow.options.runtimeConfig.app,
|
|
436
|
+
baseURL: flow.options.dev ? "/" : flow.options.app.baseURL,
|
|
465
437
|
rootDir: flow.options.rootDir,
|
|
466
438
|
locale: flow.options.locale
|
|
467
439
|
},
|
|
@@ -476,61 +448,81 @@ async function initNitro(flow) {
|
|
|
476
448
|
},
|
|
477
449
|
publicAssets: [
|
|
478
450
|
{
|
|
479
|
-
baseURL: flow.options.app.buildAssetsDir,
|
|
451
|
+
// baseURL: flow.options.app.buildAssetsDir,
|
|
480
452
|
dir: resolve(flow.options.buildDir, "dist/client")
|
|
481
453
|
},
|
|
482
454
|
...flow.options._layers.map((layer) => join(layer.config.srcDir, layer.config.dir?.public || "public")).filter((dir) => existsSync(dir)).map((dir) => ({ dir }))
|
|
483
455
|
],
|
|
484
456
|
prerender: {
|
|
485
|
-
crawlLinks: flow.options._generate
|
|
486
|
-
routes: [].concat(flow.options._generate ? ["/_urls", ...flow.options.generate.routes] : [])
|
|
457
|
+
crawlLinks: flow.options._generate ?? void 0,
|
|
458
|
+
routes: [].concat(flow.options.generate.routes).concat(flow.options._generate ? ["/_urls", ...flow.options.generate.routes] : [])
|
|
487
459
|
},
|
|
488
|
-
|
|
460
|
+
sourceMap: flow.options.sourcemap.server,
|
|
489
461
|
externals: {
|
|
490
462
|
inline: [
|
|
491
463
|
...flow.options.dev ? [] : ["eta", "@monkeyplus/", "@vue/", "@nuxt/", flow.options.buildDir],
|
|
492
|
-
"@monkeyplus/flow/dist"
|
|
464
|
+
"@monkeyplus/flow/dist",
|
|
465
|
+
// Dev windows
|
|
466
|
+
"C:/Users/gnu/Documents/GitHub/flow/packages/flow/dist/app",
|
|
467
|
+
distDir
|
|
493
468
|
]
|
|
494
469
|
},
|
|
470
|
+
// preset: flow.options.dev ? 'nitro-dev' : undefined,
|
|
471
|
+
// output: {
|
|
472
|
+
// dir: resolve(flow.options.buildDir, 'output'),
|
|
473
|
+
// },
|
|
474
|
+
replace: {
|
|
475
|
+
"process.dev": flow.options.dev
|
|
476
|
+
},
|
|
495
477
|
alias: {
|
|
478
|
+
// Vue 3 mocks
|
|
496
479
|
"estree-walker": "unenv/runtime/mock/proxy",
|
|
497
480
|
"@babel/parser": "unenv/runtime/mock/proxy",
|
|
481
|
+
// Paths
|
|
498
482
|
"#paths": resolve(distDir, "core/runtime/nitro/paths"),
|
|
483
|
+
// Shortcut to server main file
|
|
499
484
|
"#server": "#build/dist/server/server.mjs",
|
|
485
|
+
// Nuxt aliases
|
|
500
486
|
...flow.options.alias
|
|
501
487
|
},
|
|
502
488
|
rollupConfig: {
|
|
503
489
|
plugins: []
|
|
490
|
+
},
|
|
491
|
+
// watchOptions:{}
|
|
492
|
+
//* Include to refresh server
|
|
493
|
+
devServer: {
|
|
494
|
+
watch: [resolve(flow.options.buildDir, "dist/server/server.mjs")]
|
|
504
495
|
}
|
|
505
496
|
});
|
|
497
|
+
nitroConfig.rollupConfig.plugins.push(
|
|
498
|
+
ImportProtectionPlugin.rollup({
|
|
499
|
+
rootDir: flow.options.rootDir,
|
|
500
|
+
patterns: [
|
|
501
|
+
...["#app", /^#build(\/|$)/].map((p) => [p, "Vue app aliases are not allowed in server routes."])
|
|
502
|
+
],
|
|
503
|
+
exclude: [/core[\\/]runtime[\\/]nitro[\\/]renderer/]
|
|
504
|
+
})
|
|
505
|
+
);
|
|
506
506
|
await flow.callHook("nitro:config", nitroConfig);
|
|
507
|
-
nitroConfig.handlers.unshift({
|
|
508
|
-
middleware: true,
|
|
509
|
-
handler: resolve(distDir, "core/runtime/nitro/flow")
|
|
510
|
-
});
|
|
511
507
|
const nitro = await createNitro(nitroConfig);
|
|
508
|
+
flow._nitro = nitro;
|
|
509
|
+
flow.nitro = nitro;
|
|
512
510
|
await flow.callHook("nitro:init", nitro);
|
|
513
511
|
nitro.vfs = flow.vfs = nitro.vfs || flow.vfs || {};
|
|
514
512
|
flow.hook("close", () => nitro.hooks.callHook("close"));
|
|
515
|
-
nitro.hooks.hook("
|
|
516
|
-
|
|
517
|
-
rootDir: flow.options.rootDir,
|
|
518
|
-
patterns: [
|
|
519
|
-
...["#app", /^#build(\/|$)/].map((p) => [p, "Flow app aliases are not allowed in server routes."])
|
|
520
|
-
]
|
|
521
|
-
});
|
|
522
|
-
nitro2.options.rollupConfig.plugins.push(plugin);
|
|
513
|
+
nitro.hooks.hook("prerender:routes", (routes) => {
|
|
514
|
+
flow.callHook("prerender:routes", { routes });
|
|
523
515
|
});
|
|
524
|
-
const
|
|
525
|
-
nitro.options.devHandlers.unshift({ handler:
|
|
526
|
-
nitro.options.devHandlers.push(...
|
|
516
|
+
const devMiddlewareHandler = dynamicEventHandler();
|
|
517
|
+
nitro.options.devHandlers.unshift({ handler: devMiddlewareHandler });
|
|
518
|
+
nitro.options.devHandlers.push(...flow.options.devServerHandlers);
|
|
527
519
|
nitro.options.handlers.unshift({
|
|
528
|
-
route: "/
|
|
520
|
+
route: "/__nuxt_error",
|
|
529
521
|
lazy: true,
|
|
530
522
|
handler: resolve(distDir, "core/runtime/nitro/renderer")
|
|
531
523
|
});
|
|
532
524
|
flow.hook("prepare:types", async (opts) => {
|
|
533
|
-
if (flow.options.
|
|
525
|
+
if (!flow.options.dev) {
|
|
534
526
|
await scanHandlers(nitro);
|
|
535
527
|
await writeTypes(nitro);
|
|
536
528
|
}
|
|
@@ -539,21 +531,15 @@ async function initNitro(flow) {
|
|
|
539
531
|
flow.hook("build:done", async () => {
|
|
540
532
|
await flow.callHook("nitro:build:before", nitro);
|
|
541
533
|
if (flow.options.dev) {
|
|
542
|
-
await build$
|
|
534
|
+
await build$1(nitro);
|
|
543
535
|
} else {
|
|
536
|
+
console.log("build", flow.options._generate);
|
|
544
537
|
await prepare(nitro);
|
|
545
538
|
await copyPublicAssets(nitro);
|
|
546
539
|
await prerender(nitro);
|
|
547
540
|
if (!flow.options._generate) {
|
|
548
|
-
await build$
|
|
541
|
+
await build$1(nitro);
|
|
549
542
|
} else {
|
|
550
|
-
const nitroDev = await createNitro({
|
|
551
|
-
...nitro.options._config,
|
|
552
|
-
rootDir: nitro.options.rootDir,
|
|
553
|
-
logLevel: 0,
|
|
554
|
-
preset: "nitro-prerender"
|
|
555
|
-
});
|
|
556
|
-
flow.server = nitroDev;
|
|
557
543
|
const distDir2 = resolve(flow.options.rootDir, "dist");
|
|
558
544
|
if (!existsSync(distDir2))
|
|
559
545
|
await promises.symlink(nitro.options.output.publicDir, distDir2, "junction").catch(() => {
|
|
@@ -562,37 +548,27 @@ async function initNitro(flow) {
|
|
|
562
548
|
}
|
|
563
549
|
});
|
|
564
550
|
if (flow.options.dev) {
|
|
565
|
-
flow.hook("
|
|
566
|
-
|
|
551
|
+
flow.hook("vite:compiled", () => {
|
|
552
|
+
flow.server.reload();
|
|
567
553
|
});
|
|
568
|
-
flow.hook("server:
|
|
569
|
-
|
|
554
|
+
flow.hook("server:devHandler", (h) => {
|
|
555
|
+
devMiddlewareHandler.set(h);
|
|
570
556
|
});
|
|
571
557
|
flow.server = createDevServer(nitro);
|
|
572
|
-
flow.hook("build:resources", () => {
|
|
573
|
-
flow.server.reload();
|
|
574
|
-
});
|
|
575
558
|
const waitUntilCompile = new Promise((resolve2) => nitro.hooks.hook("compiled", () => resolve2()));
|
|
576
559
|
flow.hook("build:done", () => waitUntilCompile);
|
|
577
560
|
}
|
|
578
561
|
}
|
|
579
|
-
async function resolveHandlers(flow) {
|
|
580
|
-
const handlers = [...flow.options.serverHandlers];
|
|
581
|
-
const devHandlers = [...flow.options.devServerHandlers];
|
|
582
|
-
return {
|
|
583
|
-
handlers,
|
|
584
|
-
devHandlers
|
|
585
|
-
};
|
|
586
|
-
}
|
|
587
562
|
|
|
588
563
|
const addModuleTranspiles = (opts = {}) => {
|
|
589
564
|
const flow = useNuxt();
|
|
590
565
|
const modules = [
|
|
591
566
|
...opts.additionalModules || [],
|
|
567
|
+
// ...flow.options.buildModules,
|
|
592
568
|
...flow.options.modules,
|
|
593
569
|
...flow.options._modules
|
|
594
570
|
].map((m) => typeof m === "string" ? m : Array.isArray(m) ? m[0] : m.src).filter((m) => typeof m === "string").map((m) => m.split("node_modules/").pop());
|
|
595
|
-
flow.options.build.transpile = flow.options.build.transpile.map((m) => typeof m === "string" ? m.split("node_modules/").pop() : m);
|
|
571
|
+
flow.options.build.transpile = flow.options.build.transpile.map((m) => typeof m === "string" ? m.split("node_modules/").pop() : m).filter((x) => !!x);
|
|
596
572
|
function isTranspilePresent(mod) {
|
|
597
573
|
return flow.options.build.transpile.some((t) => !(t instanceof Function) && (t instanceof RegExp ? t.test(mod) : new RegExp(t).test(mod)));
|
|
598
574
|
}
|
|
@@ -605,7 +581,10 @@ const addModuleTranspiles = (opts = {}) => {
|
|
|
605
581
|
function createFlow(options) {
|
|
606
582
|
const hooks = createHooks();
|
|
607
583
|
const flow = {
|
|
608
|
-
|
|
584
|
+
//* Include nuxt version
|
|
585
|
+
_version: "3.0.0",
|
|
586
|
+
//* Include version
|
|
587
|
+
// @ts-ignore
|
|
609
588
|
version,
|
|
610
589
|
options,
|
|
611
590
|
hooks,
|
|
@@ -619,10 +598,12 @@ function createFlow(options) {
|
|
|
619
598
|
return flow;
|
|
620
599
|
}
|
|
621
600
|
async function initFlow(flow) {
|
|
601
|
+
flow.hooks.addHooks(flow.options.hooks);
|
|
622
602
|
nuxtCtx.set(flow);
|
|
623
603
|
flow.hook("close", () => nuxtCtx.unset());
|
|
624
|
-
await flow.callHook("modules:before"
|
|
604
|
+
await flow.callHook("modules:before");
|
|
625
605
|
const modulesToInstall = [
|
|
606
|
+
// ...flow.options.buildModules,
|
|
626
607
|
...flow.options.modules,
|
|
627
608
|
...flow.options._modules
|
|
628
609
|
];
|
|
@@ -632,17 +613,26 @@ async function initFlow(flow) {
|
|
|
632
613
|
else
|
|
633
614
|
await installModule(m, {});
|
|
634
615
|
}
|
|
635
|
-
await flow.callHook("modules:done"
|
|
636
|
-
|
|
616
|
+
await flow.callHook("modules:done");
|
|
617
|
+
flow.options.build.transpile = flow.options.build.transpile.map((t) => typeof t === "string" ? normalize(t) : t);
|
|
618
|
+
addModuleTranspiles();
|
|
637
619
|
await initNitro(flow);
|
|
638
620
|
await flow.callHook("ready", flow);
|
|
639
621
|
}
|
|
640
622
|
async function loadFlow(opts) {
|
|
623
|
+
const start1 = Date.now();
|
|
641
624
|
const options = await loadFlowConfig(opts);
|
|
625
|
+
logger.info(`Config loading in ${Date.now() - start1}ms`);
|
|
642
626
|
options.appDir = resolve(distDir, "app");
|
|
643
627
|
options.alias["#app"] = resolve(distDir, "app/index");
|
|
644
628
|
options._majorVersion = 3;
|
|
645
|
-
options._modules.push(pagesModule, metaModule
|
|
629
|
+
options._modules.push(pagesModule, metaModule);
|
|
630
|
+
options._modules.push([importsModule, {
|
|
631
|
+
transform: {
|
|
632
|
+
include: options._layers.filter((i) => i.cwd && i.cwd.includes("node_modules")).map((i) => new RegExp(`(^|\\/)${escapeRE(i.cwd.split("node_modules/").pop())}(\\/|$)(?!node_modules\\/)`))
|
|
633
|
+
}
|
|
634
|
+
}]);
|
|
635
|
+
options.modulesDir.push(resolve(options.workspaceDir, "node_modules"));
|
|
646
636
|
options.modulesDir.push(resolve(pkgDir, "node_modules"));
|
|
647
637
|
const flow = createFlow(options);
|
|
648
638
|
if (opts.ready !== false)
|
|
@@ -657,11 +647,17 @@ const serverPluginTemplate = {
|
|
|
657
647
|
filename: "plugins/server.mjs",
|
|
658
648
|
getContents(ctx) {
|
|
659
649
|
const serverPlugins = ctx.app.plugins;
|
|
650
|
+
const exports = [];
|
|
651
|
+
const imports = [];
|
|
652
|
+
for (const plugin of serverPlugins) {
|
|
653
|
+
const path = relative(ctx.nuxt.options.rootDir, plugin.src);
|
|
654
|
+
const variable = `${genSafeVariableName(path).replace(/_(45|46|47)/g, "_")}_${hash(path)}`;
|
|
655
|
+
exports.push(variable);
|
|
656
|
+
imports.push(genImport(plugin.src, variable));
|
|
657
|
+
}
|
|
660
658
|
return [
|
|
661
|
-
|
|
662
|
-
`export default ${genArrayFromRaw(
|
|
663
|
-
...serverPlugins.map((p) => templateUtils.importName(p.src))
|
|
664
|
-
])}`
|
|
659
|
+
...imports,
|
|
660
|
+
`export default ${genArrayFromRaw(exports)}`
|
|
665
661
|
].join("\n");
|
|
666
662
|
}
|
|
667
663
|
};
|
|
@@ -690,43 +686,52 @@ export { }
|
|
|
690
686
|
`;
|
|
691
687
|
}
|
|
692
688
|
};
|
|
693
|
-
const adHocModules = ["
|
|
689
|
+
const adHocModules = ["imports", "meta", "pages"];
|
|
694
690
|
const schemaTemplate = {
|
|
695
691
|
filename: "types/schema.d.ts",
|
|
696
|
-
getContents: ({ nuxt }) => {
|
|
692
|
+
getContents: async ({ nuxt }) => {
|
|
697
693
|
const moduleInfo = nuxt.options._installedModules.map((m) => ({
|
|
698
694
|
...m.meta || {},
|
|
699
695
|
importName: m.entryPath || m.meta?.name
|
|
700
696
|
})).filter((m) => m.configKey && m.name && !adHocModules.includes(m.name));
|
|
697
|
+
const relativeRoot = relative(resolve(nuxt.options.buildDir, "types"), nuxt.options.rootDir);
|
|
701
698
|
return [
|
|
702
699
|
"import { FlowModule } from '@monkeyplus/flow-schema'",
|
|
703
700
|
"declare module '@monkeyplus/flow-schema' {",
|
|
704
701
|
" interface FlowConfig {",
|
|
705
|
-
...moduleInfo.filter(Boolean).map(
|
|
702
|
+
...moduleInfo.filter(Boolean).map(
|
|
703
|
+
(meta) => ` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName.startsWith(".") ? `./${join(relativeRoot, meta.importName)}` : meta.importName, { wrapper: false })}.default extends FlowModule<infer O> ? Partial<O> : Record<string, any>`
|
|
704
|
+
),
|
|
706
705
|
" }",
|
|
707
|
-
generateTypes(
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
706
|
+
generateTypes(
|
|
707
|
+
await resolveSchema(Object.fromEntries(Object.entries(nuxt.options.runtimeConfig).filter(([key]) => key !== "public"))),
|
|
708
|
+
{
|
|
709
|
+
interfaceName: "RuntimeConfig",
|
|
710
|
+
addExport: false,
|
|
711
|
+
addDefaults: false,
|
|
712
|
+
allowExtraKeys: false,
|
|
713
|
+
indentation: 2
|
|
714
|
+
}
|
|
715
|
+
),
|
|
716
|
+
generateTypes(
|
|
717
|
+
await resolveSchema(nuxt.options.runtimeConfig.public),
|
|
718
|
+
{
|
|
719
|
+
interfaceName: "PublicRuntimeConfig",
|
|
720
|
+
addExport: false,
|
|
721
|
+
addDefaults: false,
|
|
722
|
+
allowExtraKeys: false,
|
|
723
|
+
indentation: 2
|
|
724
|
+
}
|
|
725
|
+
),
|
|
721
726
|
"}"
|
|
722
727
|
].join("\n");
|
|
723
728
|
}
|
|
724
729
|
};
|
|
725
730
|
const publicPathTemplate = {
|
|
726
731
|
filename: "paths.mjs",
|
|
727
|
-
getContents({ nuxt }) {
|
|
732
|
+
async getContents({ nuxt }) {
|
|
728
733
|
return [
|
|
729
|
-
|
|
734
|
+
`import { joinURL } from '${await _resolveId("ufo")}'`,
|
|
730
735
|
!nuxt.options.dev && "import { useRuntimeConfig } from '#internal/nitro'",
|
|
731
736
|
nuxt.options.dev ? `const appConfig = ${JSON.stringify(nuxt.options.app)}` : "const appConfig = useRuntimeConfig().app",
|
|
732
737
|
"export const baseURL = () => appConfig.baseURL",
|
|
@@ -739,15 +744,39 @@ const publicPathTemplate = {
|
|
|
739
744
|
].filter(Boolean).join("\n");
|
|
740
745
|
}
|
|
741
746
|
};
|
|
747
|
+
function _resolveId(id) {
|
|
748
|
+
return resolvePath(id, {
|
|
749
|
+
url: [
|
|
750
|
+
// @ts-ignore
|
|
751
|
+
global.__NUXT_PREPATHS__,
|
|
752
|
+
import.meta.url,
|
|
753
|
+
process.cwd(),
|
|
754
|
+
// @ts-ignore
|
|
755
|
+
global.__NUXT_PATHS__
|
|
756
|
+
]
|
|
757
|
+
});
|
|
758
|
+
}
|
|
742
759
|
|
|
743
760
|
const defaultTemplates = {
|
|
744
761
|
__proto__: null,
|
|
745
|
-
serverPluginTemplate: serverPluginTemplate,
|
|
746
762
|
pluginsDeclaration: pluginsDeclaration,
|
|
763
|
+
publicPathTemplate: publicPathTemplate,
|
|
747
764
|
schemaTemplate: schemaTemplate,
|
|
748
|
-
|
|
765
|
+
serverPluginTemplate: serverPluginTemplate
|
|
749
766
|
};
|
|
750
767
|
|
|
768
|
+
function uniqueBy(arr, key) {
|
|
769
|
+
const res = [];
|
|
770
|
+
const seen = /* @__PURE__ */ new Set();
|
|
771
|
+
for (const item of arr) {
|
|
772
|
+
if (seen.has(item[key]))
|
|
773
|
+
continue;
|
|
774
|
+
seen.add(item[key]);
|
|
775
|
+
res.push(item);
|
|
776
|
+
}
|
|
777
|
+
return res;
|
|
778
|
+
}
|
|
779
|
+
|
|
751
780
|
function createApp(flow, options = {}) {
|
|
752
781
|
return defu(options, {
|
|
753
782
|
dir: flow.options.srcDir,
|
|
@@ -756,51 +785,95 @@ function createApp(flow, options = {}) {
|
|
|
756
785
|
templates: []
|
|
757
786
|
});
|
|
758
787
|
}
|
|
759
|
-
async function generateApp(flow, app) {
|
|
788
|
+
async function generateApp(flow, app, options) {
|
|
760
789
|
await resolveApp(flow, app);
|
|
761
|
-
app.templates = Object.values(defaultTemplates).concat(
|
|
790
|
+
app.templates = Object.values(defaultTemplates).concat(
|
|
791
|
+
flow.options.build.templates
|
|
792
|
+
);
|
|
762
793
|
await flow.callHook("app:templates", app);
|
|
763
794
|
app.templates = app.templates.map((tmpl) => normalizeTemplate(tmpl));
|
|
764
795
|
const templateContext = { utils: templateUtils, nuxt: flow, app };
|
|
765
|
-
await Promise.all(
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
796
|
+
await Promise.all(
|
|
797
|
+
app.templates.map(async (template) => {
|
|
798
|
+
const contents = await compileTemplate(template, templateContext);
|
|
799
|
+
const fullPath = template.dst || resolve(flow.options.buildDir, template.filename);
|
|
800
|
+
flow.vfs[fullPath] = contents;
|
|
801
|
+
const aliasPath = `#build/${template.filename.replace(/\.\w+$/, "")}`;
|
|
802
|
+
flow.vfs[aliasPath] = contents;
|
|
803
|
+
if (process.platform === "win32")
|
|
804
|
+
flow.vfs[fullPath.replace(/\//g, "\\")] = contents;
|
|
805
|
+
if (template.write) {
|
|
806
|
+
await promises.mkdir(dirname(fullPath), { recursive: true });
|
|
807
|
+
await promises.writeFile(fullPath, contents, "utf8");
|
|
808
|
+
}
|
|
809
|
+
})
|
|
810
|
+
);
|
|
778
811
|
await flow.callHook("app:templatesGenerated", app);
|
|
779
812
|
}
|
|
780
813
|
async function resolveApp(flow, app) {
|
|
781
|
-
app.plugins = [
|
|
814
|
+
app.plugins = [
|
|
815
|
+
...flow.options.plugins.map(normalizePlugin)
|
|
816
|
+
];
|
|
782
817
|
for (const config of flow.options._layers.map((layer) => layer.config)) {
|
|
783
818
|
app.plugins.push(...[
|
|
784
819
|
...config.plugins || [],
|
|
785
|
-
...await resolveFilesFlow(config.srcDir, [
|
|
786
|
-
"plugins/*.{ts,js,mjs,cjs,mts,cts}
|
|
787
|
-
"plugins/*/index.*{ts,js,mjs,cjs,mts,cts}
|
|
788
|
-
])
|
|
820
|
+
...config.srcDir ? await resolveFilesFlow(config.srcDir, [
|
|
821
|
+
`${config.dir?.plugins || "plugins"}/*.{ts,js,mjs,cjs,mts,cts}`,
|
|
822
|
+
`${config.dir?.plugins || "plugins"}/*/index.*{ts,js,mjs,cjs,mts,cts}`
|
|
823
|
+
]) : []
|
|
789
824
|
].map((plugin) => normalizePlugin(plugin)));
|
|
790
825
|
}
|
|
791
|
-
app.
|
|
826
|
+
app.configs = [];
|
|
827
|
+
for (const config of flow.options._layers.map((layer) => layer.config)) {
|
|
828
|
+
const appConfigPath = await findPath(resolve(config.srcDir, "app.config"));
|
|
829
|
+
if (appConfigPath)
|
|
830
|
+
app.configs.push(appConfigPath);
|
|
831
|
+
}
|
|
792
832
|
await flow.callHook("app:resolve", app);
|
|
833
|
+
app.plugins = uniqueBy(app.plugins, "src");
|
|
793
834
|
}
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
835
|
+
|
|
836
|
+
const PREFIX = "virtual:nuxt:";
|
|
837
|
+
function virtual(vfs) {
|
|
838
|
+
const extensions = ["", ".ts", ".vue", ".mjs", ".cjs", ".js", ".json"];
|
|
839
|
+
const resolveWithExt = (id) => {
|
|
840
|
+
for (const ext of extensions) {
|
|
841
|
+
const rId = id + ext;
|
|
842
|
+
if (rId in vfs)
|
|
843
|
+
return rId;
|
|
844
|
+
}
|
|
845
|
+
return null;
|
|
846
|
+
};
|
|
847
|
+
return {
|
|
848
|
+
name: "virtual",
|
|
849
|
+
resolveId(id, importer) {
|
|
850
|
+
if (process.platform === "win32" && isAbsolute(id)) {
|
|
851
|
+
id = resolve(id);
|
|
852
|
+
}
|
|
853
|
+
const resolvedId = resolveWithExt(id);
|
|
854
|
+
if (resolvedId)
|
|
855
|
+
return PREFIX + resolvedId;
|
|
856
|
+
if (importer && !isAbsolute(id)) {
|
|
857
|
+
const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
|
|
858
|
+
const importedDir = dirname(importerNoPrefix);
|
|
859
|
+
const resolved = resolveWithExt(join(importedDir, id));
|
|
860
|
+
if (resolved)
|
|
861
|
+
return PREFIX + resolved;
|
|
862
|
+
}
|
|
863
|
+
return null;
|
|
864
|
+
},
|
|
865
|
+
load(id) {
|
|
866
|
+
if (!id.startsWith(PREFIX))
|
|
867
|
+
return null;
|
|
868
|
+
const idNoPrefix = id.slice(PREFIX.length);
|
|
869
|
+
if (idNoPrefix in vfs) {
|
|
870
|
+
return {
|
|
871
|
+
code: vfs[idNoPrefix],
|
|
872
|
+
map: null
|
|
873
|
+
};
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
};
|
|
804
877
|
}
|
|
805
878
|
|
|
806
879
|
async function warmupViteServer(server, entries) {
|
|
@@ -821,6 +894,11 @@ async function warmupViteServer(server, entries) {
|
|
|
821
894
|
await Promise.all(entries.map((entry) => warmup(entry)));
|
|
822
895
|
}
|
|
823
896
|
|
|
897
|
+
const wpfs = {
|
|
898
|
+
...fse,
|
|
899
|
+
join
|
|
900
|
+
};
|
|
901
|
+
|
|
824
902
|
function cacheDirPlugin(rootDir, name) {
|
|
825
903
|
const optimizeCacheDir = resolve(rootDir, "node_modules/.cache/vite", name);
|
|
826
904
|
return {
|
|
@@ -831,279 +909,63 @@ function cacheDirPlugin(rootDir, name) {
|
|
|
831
909
|
};
|
|
832
910
|
}
|
|
833
911
|
|
|
834
|
-
|
|
835
|
-
...fse,
|
|
836
|
-
join
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
function uniq(arr) {
|
|
840
|
-
return Array.from(new Set(arr));
|
|
841
|
-
}
|
|
842
|
-
const IS_CSS_RE = /\.(?:css|scss|sass|postcss|less|stylus|styl)(\?[^.]+)?$/;
|
|
843
|
-
function isCSS(file) {
|
|
844
|
-
return IS_CSS_RE.test(file);
|
|
845
|
-
}
|
|
846
|
-
function hashId(id) {
|
|
847
|
-
return `$id_${hash(id)}`;
|
|
848
|
-
}
|
|
849
|
-
function hash(input, length = 8) {
|
|
850
|
-
return createHash("sha256").update(input).digest("hex").slice(0, length);
|
|
851
|
-
}
|
|
852
|
-
function readDirRecursively(dir) {
|
|
853
|
-
return readdirSync(dir).reduce((files, file) => {
|
|
854
|
-
const name = join(dir, file);
|
|
855
|
-
const isDirectory2 = statSync(name).isDirectory();
|
|
856
|
-
return isDirectory2 ? [...files, ...readDirRecursively(name)] : [...files, name];
|
|
857
|
-
}, []);
|
|
858
|
-
}
|
|
859
|
-
async function isDirectory(path) {
|
|
860
|
-
try {
|
|
861
|
-
return (await promises.stat(path)).isDirectory();
|
|
862
|
-
} catch (_err) {
|
|
863
|
-
return false;
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
function isExternal(opts, id) {
|
|
868
|
-
const ssrConfig = opts.viteServer.config.ssr;
|
|
869
|
-
const externalOpts = {
|
|
870
|
-
inline: [
|
|
871
|
-
/virtual:/,
|
|
872
|
-
/\.ts$/,
|
|
873
|
-
...ExternalsDefaults.inline,
|
|
874
|
-
...ssrConfig.noExternal
|
|
875
|
-
],
|
|
876
|
-
external: [
|
|
877
|
-
/node_modules/
|
|
878
|
-
],
|
|
879
|
-
resolve: {
|
|
880
|
-
type: "module",
|
|
881
|
-
extensions: [".ts", ".js", ".json", ".vue", ".mjs", ".jsx", ".tsx", ".wasm"]
|
|
882
|
-
}
|
|
883
|
-
};
|
|
884
|
-
return isExternal$1(id, opts.viteServer.config.root, externalOpts);
|
|
885
|
-
}
|
|
886
|
-
async function transformRequest(opts, id) {
|
|
887
|
-
if (id && id.startsWith("/@id/__x00__"))
|
|
888
|
-
id = `\0${id.slice("/@id/__x00__".length)}`;
|
|
889
|
-
if (id && id.startsWith("/@id/"))
|
|
890
|
-
id = id.slice("/@id/".length);
|
|
891
|
-
if (id && id.startsWith("/@fs/")) {
|
|
892
|
-
id = id.slice("/@fs".length);
|
|
893
|
-
if (id.match(/^\/\w:/))
|
|
894
|
-
id = id.slice(1);
|
|
895
|
-
} else if (!id.includes("entry") && id.startsWith("/")) {
|
|
896
|
-
const resolvedPath = resolve(opts.viteServer.config.root, `.${id}`);
|
|
897
|
-
if (existsSync(resolvedPath))
|
|
898
|
-
id = resolvedPath;
|
|
899
|
-
}
|
|
900
|
-
const withoutVersionQuery = id.replace(/\?v=\w+$/, "");
|
|
901
|
-
if (await isExternal(opts, withoutVersionQuery)) {
|
|
902
|
-
const path = builtinModules.includes(withoutVersionQuery.split("node:").pop()) ? withoutVersionQuery : pathToFileURL(withoutVersionQuery).href;
|
|
903
|
-
return {
|
|
904
|
-
code: `(global, module, _, exports, importMeta, ssrImport, ssrDynamicImport, ssrExportAll) =>
|
|
905
|
-
${genDynamicImport(path, { wrapper: false })}
|
|
906
|
-
.then(r => {
|
|
907
|
-
if (r.default && r.default.__esModule)
|
|
908
|
-
r = r.default
|
|
909
|
-
exports.default = r.default
|
|
910
|
-
ssrExportAll(r)
|
|
911
|
-
})
|
|
912
|
-
.catch(e => {
|
|
913
|
-
console.error(e)
|
|
914
|
-
throw new Error(${JSON.stringify(`[vite dev] Error loading external "${id}".`)})
|
|
915
|
-
})`,
|
|
916
|
-
deps: [],
|
|
917
|
-
dynamicDeps: []
|
|
918
|
-
};
|
|
919
|
-
}
|
|
920
|
-
const res = await opts.viteServer.transformRequest(id, { ssr: true }).catch((err) => {
|
|
921
|
-
console.warn(`[SSR] Error transforming ${id}:`, err);
|
|
922
|
-
}) || { code: "", map: {}, deps: [], dynamicDeps: [] };
|
|
923
|
-
const code = `async function (global, module, exports, __vite_ssr_exports__, __vite_ssr_import_meta__, __vite_ssr_import__, __vite_ssr_dynamic_import__, __vite_ssr_exportAll__) {
|
|
924
|
-
${res.code || "/* empty */"};
|
|
925
|
-
}`;
|
|
926
|
-
return { code, deps: res.deps || [], dynamicDeps: res.dynamicDeps || [] };
|
|
927
|
-
}
|
|
928
|
-
async function transformRequestRecursive(opts, id, parent = "<entry>", chunks = {}) {
|
|
929
|
-
if (chunks[id]) {
|
|
930
|
-
chunks[id].parents.push(parent);
|
|
931
|
-
return;
|
|
932
|
-
}
|
|
933
|
-
const res = await transformRequest(opts, id);
|
|
934
|
-
const deps = uniq([...res.deps, ...res.dynamicDeps]);
|
|
935
|
-
chunks[id] = {
|
|
936
|
-
id,
|
|
937
|
-
code: res.code,
|
|
938
|
-
deps,
|
|
939
|
-
parents: [parent]
|
|
940
|
-
};
|
|
941
|
-
for (const dep of deps)
|
|
942
|
-
await transformRequestRecursive(opts, dep, id, chunks);
|
|
943
|
-
return Object.values(chunks);
|
|
944
|
-
}
|
|
945
|
-
async function bundleRequest(opts, entryURL) {
|
|
946
|
-
const chunks = await transformRequestRecursive(opts, entryURL);
|
|
947
|
-
const listIds = (ids) => ids.map((id) => `// - ${id} (${hashId(id)})`).join("\n");
|
|
948
|
-
const chunksCode = chunks.map((chunk) => `
|
|
949
|
-
// --------------------
|
|
950
|
-
// Request: ${chunk.id}
|
|
951
|
-
// Parents:
|
|
952
|
-
${listIds(chunk.parents)}
|
|
953
|
-
// Dependencies:
|
|
954
|
-
${listIds(chunk.deps)}
|
|
955
|
-
// --------------------
|
|
956
|
-
const ${hashId(chunk.id)} = ${chunk.code}
|
|
957
|
-
`).join("\n");
|
|
958
|
-
const manifestCode = `const __modules__ = ${genObjectFromRawEntries(chunks.map((chunk) => [chunk.id, hashId(chunk.id)]))}`;
|
|
959
|
-
const ssrModuleLoader = `
|
|
960
|
-
const __pendingModules__ = new Map()
|
|
961
|
-
const __pendingImports__ = new Map()
|
|
962
|
-
const __ssrContext__ = { global: globalThis }
|
|
963
|
-
|
|
964
|
-
function __ssrLoadModule__(url, urlStack = []) {
|
|
965
|
-
const pendingModule = __pendingModules__.get(url)
|
|
966
|
-
if (pendingModule) { return pendingModule }
|
|
967
|
-
const modulePromise = __instantiateModule__(url, urlStack)
|
|
968
|
-
__pendingModules__.set(url, modulePromise)
|
|
969
|
-
modulePromise.catch(() => { __pendingModules__.delete(url) })
|
|
970
|
-
.finally(() => { __pendingModules__.delete(url) })
|
|
971
|
-
return modulePromise
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
async function __instantiateModule__(url, urlStack) {
|
|
975
|
-
const mod = __modules__[url]
|
|
976
|
-
if (mod.stubModule) { return mod.stubModule }
|
|
977
|
-
const stubModule = { [Symbol.toStringTag]: 'Module' }
|
|
978
|
-
Object.defineProperty(stubModule, '__esModule', { value: true })
|
|
979
|
-
mod.stubModule = stubModule
|
|
980
|
-
// https://vitejs.dev/guide/api-hmr.html
|
|
981
|
-
const importMeta = { url, hot: { accept() {}, prune() {}, dispose() {}, invalidate() {}, decline() {}, on() {} } }
|
|
982
|
-
urlStack = urlStack.concat(url)
|
|
983
|
-
const isCircular = url => urlStack.includes(url)
|
|
984
|
-
const pendingDeps = []
|
|
985
|
-
const ssrImport = async (dep) => {
|
|
986
|
-
// TODO: Handle externals if dep[0] !== '.' | '/'
|
|
987
|
-
if (!isCircular(dep) && !__pendingImports__.get(dep)?.some(isCircular)) {
|
|
988
|
-
pendingDeps.push(dep)
|
|
989
|
-
if (pendingDeps.length === 1) {
|
|
990
|
-
__pendingImports__.set(url, pendingDeps)
|
|
991
|
-
}
|
|
992
|
-
await __ssrLoadModule__(dep, urlStack)
|
|
993
|
-
if (pendingDeps.length === 1) {
|
|
994
|
-
__pendingImports__.delete(url)
|
|
995
|
-
} else {
|
|
996
|
-
pendingDeps.splice(pendingDeps.indexOf(dep), 1)
|
|
997
|
-
}
|
|
998
|
-
}
|
|
999
|
-
return __modules__[dep].stubModule
|
|
1000
|
-
}
|
|
1001
|
-
function ssrDynamicImport (dep) {
|
|
1002
|
-
// TODO: Handle dynamic import starting with . relative to url
|
|
1003
|
-
return ssrImport(dep)
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
function ssrExportAll(sourceModule) {
|
|
1007
|
-
for (const key in sourceModule) {
|
|
1008
|
-
if (key !== 'default') {
|
|
1009
|
-
try {
|
|
1010
|
-
Object.defineProperty(stubModule, key, {
|
|
1011
|
-
enumerable: true,
|
|
1012
|
-
configurable: true,
|
|
1013
|
-
get() { return sourceModule[key] }
|
|
1014
|
-
})
|
|
1015
|
-
} catch (_err) { }
|
|
1016
|
-
}
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
|
|
1020
|
-
const cjsModule = {
|
|
1021
|
-
get exports () {
|
|
1022
|
-
return stubModule.default
|
|
1023
|
-
},
|
|
1024
|
-
set exports (v) {
|
|
1025
|
-
stubModule.default = v
|
|
1026
|
-
},
|
|
1027
|
-
}
|
|
1028
|
-
|
|
1029
|
-
await mod(
|
|
1030
|
-
__ssrContext__.global,
|
|
1031
|
-
cjsModule,
|
|
1032
|
-
stubModule.default,
|
|
1033
|
-
stubModule,
|
|
1034
|
-
importMeta,
|
|
1035
|
-
ssrImport,
|
|
1036
|
-
ssrDynamicImport,
|
|
1037
|
-
ssrExportAll
|
|
1038
|
-
)
|
|
1039
|
-
|
|
1040
|
-
return stubModule
|
|
1041
|
-
}
|
|
1042
|
-
`;
|
|
1043
|
-
const code = [
|
|
1044
|
-
chunksCode,
|
|
1045
|
-
manifestCode,
|
|
1046
|
-
ssrModuleLoader,
|
|
1047
|
-
`export default await __ssrLoadModule__(${JSON.stringify(entryURL)})`
|
|
1048
|
-
].join("\n\n");
|
|
1049
|
-
return {
|
|
1050
|
-
code,
|
|
1051
|
-
ids: chunks.map((i) => i.id)
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
async function writeManifest(ctx, extraEntries = []) {
|
|
1056
|
-
const clientDist = resolve(ctx.flow.options.buildDir, "dist/client");
|
|
1057
|
-
const serverDist = resolve(ctx.flow.options.buildDir, "dist/server");
|
|
1058
|
-
const entries = [
|
|
1059
|
-
"@vite/client",
|
|
1060
|
-
"entry.mjs",
|
|
1061
|
-
...extraEntries
|
|
1062
|
-
];
|
|
1063
|
-
const devClientManifest = {
|
|
1064
|
-
publicPath: joinURL(ctx.flow.options.app.baseURL, ctx.flow.options.app.buildAssetsDir),
|
|
1065
|
-
all: entries,
|
|
1066
|
-
initial: entries,
|
|
1067
|
-
async: [],
|
|
1068
|
-
modules: {}
|
|
1069
|
-
};
|
|
1070
|
-
const clientManifest = ctx.flow.options.dev ? devClientManifest : await fse.readJSON(resolve(clientDist, "manifest.json"));
|
|
1071
|
-
await fse.mkdirp(serverDist);
|
|
1072
|
-
await fse.writeFile(resolve(serverDist, "client.manifest.json"), JSON.stringify(clientManifest, null, 2), "utf8");
|
|
1073
|
-
await fse.writeFile(resolve(serverDist, "client.manifest.mjs"), `export default ${JSON.stringify(clientManifest, null, 2)}`, "utf8");
|
|
1074
|
-
}
|
|
1075
|
-
|
|
1076
|
-
const buildServer = async (ctx) => {
|
|
912
|
+
async function buildServer(ctx) {
|
|
1077
913
|
const serverConfig = vite.mergeConfig(ctx.config, {
|
|
1078
|
-
|
|
914
|
+
base: ctx.nuxt.options.dev ? joinURL(ctx.nuxt.options.app.baseURL.replace(/^\.\//, "/") || "/", ctx.nuxt.options.app.buildAssetsDir) : void 0,
|
|
915
|
+
// experimental: {
|
|
916
|
+
// renderBuiltUrl: (filename, { type, hostType }) => {
|
|
917
|
+
// if (hostType !== 'js') {
|
|
918
|
+
// // In CSS we only use relative paths until we craft a clever runtime CSS hack
|
|
919
|
+
// return { relative: true };
|
|
920
|
+
// }
|
|
921
|
+
// if (type === 'public')
|
|
922
|
+
// return { runtime: `globalThis.__publicAssetsURL(${JSON.stringify(filename)})` };
|
|
923
|
+
// if (type === 'asset') {
|
|
924
|
+
// const relativeFilename = filename.replace(withTrailingSlash(withoutLeadingSlash(ctx.nuxt.options.app.buildAssetsDir)), '');
|
|
925
|
+
// return { runtime: `globalThis.__buildAssetsURL(${JSON.stringify(relativeFilename)})` };
|
|
926
|
+
// }
|
|
927
|
+
// },
|
|
928
|
+
// },
|
|
1079
929
|
define: {
|
|
1080
930
|
"process.server": true,
|
|
931
|
+
"process.client": false,
|
|
1081
932
|
"typeof window": '"undefined"',
|
|
1082
933
|
"typeof document": '"undefined"',
|
|
1083
934
|
"typeof navigator": '"undefined"',
|
|
1084
935
|
"typeof location": '"undefined"',
|
|
1085
936
|
"typeof XMLHttpRequest": '"undefined"'
|
|
1086
937
|
},
|
|
938
|
+
resolve: {
|
|
939
|
+
alias: {
|
|
940
|
+
"#build/plugins": resolve(ctx.nuxt.options.buildDir, "plugins/server")
|
|
941
|
+
}
|
|
942
|
+
},
|
|
1087
943
|
ssr: {
|
|
944
|
+
external: ["#internal/nitro", "#internal/nitro/utils"],
|
|
1088
945
|
noExternal: [
|
|
1089
|
-
...ctx.
|
|
946
|
+
...ctx.nuxt.options.build.transpile,
|
|
947
|
+
// TODO: Use externality for production (rollup) build
|
|
1090
948
|
/\/esm\/.*\.js$/,
|
|
1091
949
|
/\.(es|esm|esm-browser|esm-bundler).js$/,
|
|
1092
950
|
"/__vue-jsx",
|
|
1093
951
|
"#app",
|
|
1094
952
|
/(nuxt|nuxt3)\/(dist|src|app)/,
|
|
953
|
+
/flow\/(dist|src|app)/,
|
|
954
|
+
/flow\/modules\/(content|icons|images|netlify|netlify-cms|seo|sitemap|vue)/,
|
|
1095
955
|
/@monkeyplus\/flow\/(dist|src|app)/,
|
|
1096
956
|
/@nuxt\/nitro\/(dist|src)/
|
|
1097
957
|
]
|
|
1098
958
|
},
|
|
1099
959
|
build: {
|
|
1100
|
-
outDir: resolve(ctx.
|
|
1101
|
-
|
|
960
|
+
outDir: resolve(ctx.nuxt.options.buildDir, "dist/server"),
|
|
961
|
+
ssr: true,
|
|
1102
962
|
rollupOptions: {
|
|
1103
963
|
external: ["#internal/nitro"],
|
|
1104
964
|
output: {
|
|
1105
965
|
entryFileNames: "server.mjs",
|
|
1106
966
|
preferConst: true,
|
|
967
|
+
// TODO: https://github.com/vitejs/vite/pull/8641
|
|
968
|
+
inlineDynamicImports: !ctx.nuxt.options.experimental.viteServerDynamicImports,
|
|
1107
969
|
format: "module"
|
|
1108
970
|
},
|
|
1109
971
|
onwarn(warning, rollupWarn) {
|
|
@@ -1113,39 +975,31 @@ const buildServer = async (ctx) => {
|
|
|
1113
975
|
}
|
|
1114
976
|
},
|
|
1115
977
|
server: {
|
|
978
|
+
// https://github.com/vitest-dev/vitest/issues/229#issuecomment-1002685027
|
|
1116
979
|
preTransformRequests: false,
|
|
1117
|
-
|
|
980
|
+
hmr: false
|
|
1118
981
|
},
|
|
1119
982
|
plugins: [
|
|
1120
|
-
cacheDirPlugin(ctx.
|
|
983
|
+
cacheDirPlugin(ctx.nuxt.options.rootDir, "server"),
|
|
984
|
+
replace({
|
|
985
|
+
...Object.fromEntries([";", "(", "{", "}", " ", " ", "\n"].map((d) => [`${d}global.`, `${d}globalThis.`])),
|
|
986
|
+
preventAssignment: true
|
|
987
|
+
})
|
|
988
|
+
// vuePlugin(ctx.config.vue),
|
|
989
|
+
// viteJsxPlugin(),
|
|
1121
990
|
]
|
|
1122
991
|
});
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
const publicDir = join(ctx.flow.options.srcDir, ctx.flow.options.dir.public);
|
|
1129
|
-
let publicFiles = [];
|
|
1130
|
-
if (await isDirectory(publicDir)) {
|
|
1131
|
-
publicFiles = readDirRecursively(publicDir).map((r) => r.replace(publicDir, ""));
|
|
1132
|
-
for (const file of publicFiles) {
|
|
1133
|
-
try {
|
|
1134
|
-
fse.rmSync(join(clientDist, file));
|
|
1135
|
-
} catch {
|
|
1136
|
-
}
|
|
992
|
+
if (ctx.nuxt.options.typescript.typeCheck === true || ctx.nuxt.options.typescript.typeCheck === "build" && !ctx.nuxt.options.dev) {
|
|
993
|
+
const checker = await import('vite-plugin-checker').then((r) => r.default);
|
|
994
|
+
serverConfig.plugins.push(checker({
|
|
995
|
+
vueTsc: {
|
|
996
|
+
tsconfigPath: await resolveTSConfig(ctx.nuxt.options.rootDir)
|
|
1137
997
|
}
|
|
1138
|
-
}
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
await fse.remove(nestedAssetsPath);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
});
|
|
1147
|
-
const onBuild = () => ctx.flow.callHook("build:resources", wpfs);
|
|
1148
|
-
if (!ctx.flow.options.dev) {
|
|
998
|
+
}));
|
|
999
|
+
}
|
|
1000
|
+
await ctx.nuxt.callHook("vite:extendConfig", serverConfig, { isClient: false, isServer: true });
|
|
1001
|
+
const onBuild = () => ctx.nuxt.callHook("build:resources", wpfs);
|
|
1002
|
+
if (!ctx.nuxt.options.dev) {
|
|
1149
1003
|
const start = Date.now();
|
|
1150
1004
|
logger.info("Building server...");
|
|
1151
1005
|
await vite.build(serverConfig);
|
|
@@ -1155,184 +1009,87 @@ const buildServer = async (ctx) => {
|
|
|
1155
1009
|
}
|
|
1156
1010
|
const viteServer = await vite.createServer(serverConfig);
|
|
1157
1011
|
ctx.ssrServer = viteServer;
|
|
1158
|
-
await ctx.
|
|
1159
|
-
ctx.
|
|
1012
|
+
await ctx.nuxt.callHook("vite:serverCreated", viteServer, { isClient: false, isServer: true });
|
|
1013
|
+
ctx.nuxt.hook("close", () => viteServer.close());
|
|
1160
1014
|
await viteServer.pluginContainer.buildStart({});
|
|
1161
|
-
|
|
1162
|
-
const start = Date.now();
|
|
1163
|
-
const { code, ids } = await bundleRequest({ viteServer }, resolve(ctx.flow.options.appDir, "entry"));
|
|
1164
|
-
await fse.ensureFile(resolve(ctx.flow.options.buildDir, "dist/server/server.mjs"));
|
|
1165
|
-
await fse.writeFile(resolve(ctx.flow.options.buildDir, "dist/server/server.mjs"), code, "utf-8");
|
|
1166
|
-
await writeManifest(ctx, ids.filter(isCSS).map((i) => i.slice(1)));
|
|
1167
|
-
const time = Date.now() - start;
|
|
1168
|
-
logger.success(`Vite server built in ${time}ms`);
|
|
1169
|
-
await onBuild();
|
|
1170
|
-
ctx.flow.callHook("bundler:change", {});
|
|
1171
|
-
};
|
|
1172
|
-
const doBuild = debounce(_doBuild, 50);
|
|
1173
|
-
await _doBuild();
|
|
1174
|
-
viteServer.watcher.on("all", (_event, file) => {
|
|
1175
|
-
file = normalize(file);
|
|
1176
|
-
if (file.indexOf(ctx.flow.options.buildDir) === 0)
|
|
1177
|
-
return;
|
|
1178
|
-
doBuild();
|
|
1179
|
-
});
|
|
1180
|
-
ctx.flow.hook("app:templatesGenerated", () => doBuild());
|
|
1181
|
-
};
|
|
1182
|
-
|
|
1183
|
-
const PREFIX = "virtual:";
|
|
1184
|
-
function virtual(vfs) {
|
|
1185
|
-
const extensions = ["", ".ts", ".vue", ".mjs", ".cjs", ".js", ".json"];
|
|
1186
|
-
const resolveWithExt = (id) => {
|
|
1187
|
-
for (const ext of extensions) {
|
|
1188
|
-
const rId = id + ext;
|
|
1189
|
-
if (rId in vfs)
|
|
1190
|
-
return rId;
|
|
1191
|
-
}
|
|
1192
|
-
return null;
|
|
1193
|
-
};
|
|
1194
|
-
return {
|
|
1195
|
-
name: "virtual",
|
|
1196
|
-
resolveId(id, importer) {
|
|
1197
|
-
if (process.platform === "win32" && isAbsolute(id)) {
|
|
1198
|
-
id = resolve(id);
|
|
1199
|
-
}
|
|
1200
|
-
const resolvedId = resolveWithExt(id);
|
|
1201
|
-
if (resolvedId)
|
|
1202
|
-
return PREFIX + resolvedId;
|
|
1203
|
-
if (importer && !isAbsolute(id)) {
|
|
1204
|
-
const importerNoPrefix = importer.startsWith(PREFIX) ? importer.slice(PREFIX.length) : importer;
|
|
1205
|
-
const importedDir = dirname(importerNoPrefix);
|
|
1206
|
-
const resolved = resolveWithExt(join(importedDir, id));
|
|
1207
|
-
if (resolved)
|
|
1208
|
-
return PREFIX + resolved;
|
|
1209
|
-
}
|
|
1210
|
-
return null;
|
|
1211
|
-
},
|
|
1212
|
-
load(id) {
|
|
1213
|
-
if (!id.startsWith(PREFIX))
|
|
1214
|
-
return null;
|
|
1215
|
-
const idNoPrefix = id.slice(PREFIX.length);
|
|
1216
|
-
return {
|
|
1217
|
-
code: vfs[idNoPrefix],
|
|
1218
|
-
map: null
|
|
1219
|
-
};
|
|
1220
|
-
}
|
|
1221
|
-
};
|
|
1015
|
+
await import('./chunks/dev-bundler.mjs').then((r) => r.initViteDevBundler(ctx, onBuild));
|
|
1222
1016
|
}
|
|
1223
1017
|
|
|
1224
|
-
|
|
1225
|
-
const
|
|
1226
|
-
return {
|
|
1227
|
-
name: "nuxt:dynamic-base-path",
|
|
1228
|
-
resolveId(id) {
|
|
1229
|
-
if (id.startsWith("/__NUXT_BASE__"))
|
|
1230
|
-
return id.replace("/__NUXT_BASE__", "");
|
|
1231
|
-
if (id === "#internal/nitro")
|
|
1232
|
-
return "#internal/nitro";
|
|
1233
|
-
return null;
|
|
1234
|
-
},
|
|
1235
|
-
enforce: "post",
|
|
1236
|
-
transform(code, id) {
|
|
1237
|
-
const s = new MagicString(code);
|
|
1238
|
-
if (options.globalPublicPath && id.includes("paths.mjs") && code.includes("const appConfig = "))
|
|
1239
|
-
s.append(`${options.globalPublicPath} = buildAssetsURL();
|
|
1240
|
-
`);
|
|
1241
|
-
const assetId = code.match(VITE_ASSET_RE);
|
|
1242
|
-
if (assetId) {
|
|
1243
|
-
s.overwrite(0, code.length, [
|
|
1244
|
-
"import { buildAssetsURL } from '#build/paths.mjs';",
|
|
1245
|
-
`export default buildAssetsURL("${assetId[1]}".replace("/__NUXT_BASE__", ""));`
|
|
1246
|
-
].join("\n"));
|
|
1247
|
-
}
|
|
1248
|
-
if (!id.includes("paths.mjs") && code.includes("NUXT_BASE") && !code.includes("import { publicAssetsURL as __publicAssetsURL }"))
|
|
1249
|
-
s.prepend("import { publicAssetsURL as __publicAssetsURL } from '#build/paths.mjs';\n");
|
|
1250
|
-
if (id === "vite/preload-helper") {
|
|
1251
|
-
s.prepend("import { buildAssetsDir } from '#build/paths.mjs';\n");
|
|
1252
|
-
s.replace(/const base = ['"]\/__NUXT_BASE__\/['"]/, "const base = buildAssetsDir()");
|
|
1253
|
-
}
|
|
1254
|
-
s.replace(/from *['"]\/__NUXT_BASE__(\/[^'"]*)['"]/g, 'from "$1"');
|
|
1255
|
-
const delimiterRE = /(?<!(const base = |from *))(`([^`]*)\/__NUXT_BASE__\/([^`]*)`|'([^']*)\/__NUXT_BASE__\/([^']*)'|"([^"]*)\/__NUXT_BASE__\/([^"]*)")/g;
|
|
1256
|
-
s.replace(delimiterRE, (r) => `\`${r.replace(/\/__NUXT_BASE__\//g, "${__publicAssetsURL()}").slice(1, -1)}\``);
|
|
1257
|
-
if (s.hasChanged()) {
|
|
1258
|
-
return {
|
|
1259
|
-
code: s.toString(),
|
|
1260
|
-
map: options.sourcemap && s.generateMap({ source: id, includeContent: true })
|
|
1261
|
-
};
|
|
1262
|
-
}
|
|
1263
|
-
}
|
|
1264
|
-
};
|
|
1265
|
-
});
|
|
1266
|
-
|
|
1267
|
-
async function bundleVite(flow) {
|
|
1268
|
-
const hmrPortDefault = 24678;
|
|
1269
|
-
const hmrPort = await getPort({
|
|
1270
|
-
port: hmrPortDefault,
|
|
1271
|
-
ports: Array.from({ length: 20 }, (_, i) => hmrPortDefault + 1 + i)
|
|
1272
|
-
});
|
|
1018
|
+
async function bundle$1(nuxt) {
|
|
1019
|
+
const entry = resolve(nuxt.options.appDir, nuxt.options.experimental.asyncEntry ? "entry.async" : "entry");
|
|
1273
1020
|
const ctx = {
|
|
1274
|
-
nuxt
|
|
1275
|
-
|
|
1276
|
-
config: vite.mergeConfig(
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
include: []
|
|
1292
|
-
},
|
|
1293
|
-
build: {
|
|
1294
|
-
rollupOptions: {
|
|
1295
|
-
output: { sanitizeFileName: sanitizeFilePath },
|
|
1296
|
-
input: resolve(flow.options.appDir, "entry")
|
|
1297
|
-
}
|
|
1298
|
-
},
|
|
1299
|
-
plugins: [
|
|
1300
|
-
replace({
|
|
1301
|
-
...Object.fromEntries([";", "(", "{", "}", " ", " ", "\n"].map((d) => [`${d}global.`, `${d}globalThis.`])),
|
|
1302
|
-
preventAssignment: true
|
|
1303
|
-
}),
|
|
1304
|
-
virtual(flow.vfs),
|
|
1305
|
-
DynamicBasePlugin.vite({ sourcemap: flow.options.sourcemap })
|
|
1306
|
-
],
|
|
1307
|
-
server: {
|
|
1308
|
-
watch: {
|
|
1309
|
-
ignored: isIgnoredFlow
|
|
1021
|
+
nuxt,
|
|
1022
|
+
entry,
|
|
1023
|
+
config: vite.mergeConfig(
|
|
1024
|
+
{
|
|
1025
|
+
configFile: false,
|
|
1026
|
+
resolve: {
|
|
1027
|
+
alias: {
|
|
1028
|
+
...nuxt.options.alias,
|
|
1029
|
+
"#app": nuxt.options.appDir,
|
|
1030
|
+
// We need this resolution to be present before the following entry, but it
|
|
1031
|
+
// will be filled in client/server configs
|
|
1032
|
+
"#build/plugins": "",
|
|
1033
|
+
"#build": nuxt.options.buildDir,
|
|
1034
|
+
"web-streams-polyfill/ponyfill/es2018": "unenv/runtime/mock/empty",
|
|
1035
|
+
// Cannot destructure property 'AbortController' of ..
|
|
1036
|
+
"abort-controller": "unenv/runtime/mock/empty"
|
|
1037
|
+
}
|
|
1310
1038
|
},
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
port: hmrPort
|
|
1039
|
+
optimizeDeps: {
|
|
1040
|
+
entries: [entry],
|
|
1041
|
+
include: []
|
|
1315
1042
|
},
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1043
|
+
// css: resolveCSSOptions(nuxt),
|
|
1044
|
+
build: {
|
|
1045
|
+
rollupOptions: {
|
|
1046
|
+
output: { sanitizeFileName: sanitizeFilePath },
|
|
1047
|
+
input: resolve(nuxt.options.appDir, "entry")
|
|
1048
|
+
},
|
|
1049
|
+
watch: {
|
|
1050
|
+
exclude: nuxt.options.ignore
|
|
1051
|
+
}
|
|
1052
|
+
},
|
|
1053
|
+
plugins: [
|
|
1054
|
+
// composableKeysPlugin.vite({ sourcemap: nuxt.options.sourcemap, rootDir: nuxt.options.rootDir }),
|
|
1055
|
+
replace({
|
|
1056
|
+
...Object.fromEntries([";", "(", "{", "}", " ", " ", "\n"].map((d) => [`${d}global.`, `${d}globalThis.`])),
|
|
1057
|
+
preventAssignment: true
|
|
1058
|
+
}),
|
|
1059
|
+
virtual(nuxt.vfs)
|
|
1060
|
+
],
|
|
1061
|
+
vue: {
|
|
1062
|
+
reactivityTransform: nuxt.options.experimental.reactivityTransform
|
|
1063
|
+
},
|
|
1064
|
+
server: {
|
|
1065
|
+
watch: { ignored: isIgnoredFlow },
|
|
1066
|
+
fs: {
|
|
1067
|
+
allow: [
|
|
1068
|
+
nuxt.options.appDir
|
|
1069
|
+
]
|
|
1070
|
+
},
|
|
1071
|
+
hmr: false
|
|
1320
1072
|
}
|
|
1321
|
-
}
|
|
1322
|
-
|
|
1073
|
+
},
|
|
1074
|
+
nuxt.options.vite
|
|
1075
|
+
)
|
|
1323
1076
|
};
|
|
1324
|
-
if (
|
|
1325
|
-
ctx.config.
|
|
1326
|
-
|
|
1327
|
-
|
|
1077
|
+
if (!nuxt.options.dev) {
|
|
1078
|
+
ctx.config.server.watch = void 0;
|
|
1079
|
+
ctx.config.build.watch = void 0;
|
|
1080
|
+
}
|
|
1081
|
+
await nuxt.callHook("vite:extend", ctx);
|
|
1082
|
+
nuxt.hook("vite:serverCreated", (server, env) => {
|
|
1328
1083
|
ctx.nuxt.hook("app:templatesGenerated", () => {
|
|
1329
1084
|
for (const [id, mod] of server.moduleGraph.idToModuleMap) {
|
|
1330
|
-
if (id.
|
|
1085
|
+
if (id.includes("pages."))
|
|
1086
|
+
server.moduleGraph.invalidateModule(mod);
|
|
1087
|
+
if (id.startsWith("\virtual:"))
|
|
1331
1088
|
server.moduleGraph.invalidateModule(mod);
|
|
1332
1089
|
}
|
|
1333
1090
|
});
|
|
1334
1091
|
const start = Date.now();
|
|
1335
|
-
warmupViteServer(server, ["/entry
|
|
1092
|
+
warmupViteServer(server, [join("/@fs/", ctx.entry)]).then(() => logger.info(`Vite ${env.isClient ? "client" : "server"} warmed up in ${Date.now() - start}ms`)).catch(logger.error);
|
|
1336
1093
|
});
|
|
1337
1094
|
await buildServer(ctx);
|
|
1338
1095
|
}
|
|
@@ -1347,12 +1104,16 @@ async function build(flow) {
|
|
|
1347
1104
|
if (event !== "change" && /app|error|plugins/i.test(path))
|
|
1348
1105
|
await generateApp$1();
|
|
1349
1106
|
});
|
|
1350
|
-
flow.hook("builder:generateApp",
|
|
1107
|
+
flow.hook("builder:generateApp", (options) => {
|
|
1108
|
+
if (options)
|
|
1109
|
+
return generateApp(flow, app);
|
|
1110
|
+
return generateApp$1();
|
|
1111
|
+
});
|
|
1351
1112
|
}
|
|
1352
|
-
await flow.callHook("build:before"
|
|
1113
|
+
await flow.callHook("build:before");
|
|
1353
1114
|
if (!flow.options._prepare) {
|
|
1354
1115
|
await bundle(flow);
|
|
1355
|
-
await flow.callHook("build:done"
|
|
1116
|
+
await flow.callHook("build:done");
|
|
1356
1117
|
}
|
|
1357
1118
|
if (!flow.options.dev)
|
|
1358
1119
|
await flow.callHook("close", flow);
|
|
@@ -1368,14 +1129,13 @@ function watch(flow) {
|
|
|
1368
1129
|
"node_modules"
|
|
1369
1130
|
]
|
|
1370
1131
|
});
|
|
1371
|
-
|
|
1372
|
-
watcher.on("all", watchHook);
|
|
1132
|
+
watcher.on("all", (event, path) => flow.callHook("builder:watch", event, normalize(path)));
|
|
1373
1133
|
flow.hook("close", () => watcher.close());
|
|
1374
1134
|
return watcher;
|
|
1375
1135
|
}
|
|
1376
1136
|
async function bundle(nuxt) {
|
|
1377
1137
|
try {
|
|
1378
|
-
return
|
|
1138
|
+
return bundle$1(nuxt);
|
|
1379
1139
|
} catch (error) {
|
|
1380
1140
|
await nuxt.callHook("build:error", error);
|
|
1381
1141
|
throw error;
|