@monkeyplus/flow 5.0.0-beta.12 → 5.0.0-beta.3

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.
@@ -10,12 +10,12 @@ export default eventHandler(async (event) => {
10
10
  const chunks = { head: [], body: [] };
11
11
  const generate = {};
12
12
  const { page, locale, params, view } = flow.router.byUrl.lookup(url) || {};
13
- if (!page)
14
- return;
15
13
  await flow.callHook("page:scripts", scripts);
16
14
  if (view.bundle)
17
15
  await flow.callHook("page:chunks", view.bundle, chunks);
18
16
  const templateContext = {};
17
+ if (!page)
18
+ return;
19
19
  const dynamyc = params?._;
20
20
  const contextPage = {};
21
21
  const utils = Object.assign({ getLocale: () => locale }, flow.app.utils);
package/dist/index.mjs CHANGED
@@ -1,6 +1,6 @@
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, templateUtils, normalizeTemplate, compileTemplate, normalizePlugin, isIgnoredFlow } from '@monkeyplus/flow-kit';
3
+ import { defineFlowModule, addPlugin, defineNuxtModule, logger, addTemplate, addPluginTemplate, addVitePlugin, useNuxt, resolveAlias, resolveFiles, addDevServerHandler, nuxtCtx, installModule, loadFlowConfig, templateUtils, normalizeTemplate, compileTemplate, normalizePlugin, resolveFilesFlow, isIgnoredFlow } from '@monkeyplus/flow-kit';
4
4
  import { fileURLToPath, pathToFileURL } from 'node:url';
5
5
  import { defineUnimportPreset, createUnimport, toImports, scanDirExports } from 'unimport';
6
6
  import { createUnplugin } from 'unplugin';
@@ -27,7 +27,7 @@ import { isExternal as isExternal$1, ExternalsDefaults } from 'externality';
27
27
  import { createHash } from 'node:crypto';
28
28
  import MagicString from 'magic-string';
29
29
 
30
- const version = "5.0.0-beta.12";
30
+ const version = "5.0.0-beta.3";
31
31
 
32
32
  let _distDir = dirname(fileURLToPath(import.meta.url));
33
33
  if (_distDir.endsWith("chunks"))
@@ -225,7 +225,7 @@ async function resolvePagesRoutes() {
225
225
  const nuxt = useNuxt();
226
226
  const pagesDirs = [...new Set(nuxt.options._layers.map((layer) => resolve(layer.config.srcDir, layer.config.dir?.pages || "pages")))];
227
227
  const allRoutes = (await Promise.all(pagesDirs.map(async (dir) => {
228
- const files = await resolveFilesFlow(dir, `**/*{${nuxt.options.extensions.join(",")}}`);
228
+ const files = await resolveFiles(dir, `**/*{${nuxt.options.extensions.join(",")}}`);
229
229
  files.sort();
230
230
  return files.map((file) => {
231
231
  const segments = relative(dir, file).replace(new RegExp(`${escapeRE(extname(file))}$`), "").split("/").join("_");
@@ -306,17 +306,13 @@ const createClient = async (flow) => {
306
306
  manifest: true
307
307
  },
308
308
  server: {
309
- watch: {
310
- ignored: ["**/.env/**", "**/.env*"]
311
- },
312
309
  middlewareMode: "ssr"
313
310
  }
314
311
  });
315
312
  const _doReload = () => {
316
- if (vite)
317
- vite?.ws?.send({ type: "full-reload" });
313
+ vite.ws.send({ type: "full-reload" });
318
314
  };
319
- const doReload = debounce(_doReload, 60);
315
+ const doReload = debounce(_doReload, 50);
320
316
  flow.hook("bundler:change", () => {
321
317
  doReload();
322
318
  });
@@ -340,34 +336,28 @@ const builClient = async (flow) => {
340
336
 
341
337
  const viteModule = defineFlowModule({
342
338
  meta: {
343
- name: "vite-client",
344
- configKey: "bundle"
339
+ name: "viteClient"
345
340
  },
346
341
  defaults: {
347
- route: "/_vite/",
348
- dir: "/client/pages"
342
+ route: "/_vite/"
349
343
  },
350
344
  async setup(_options, flow) {
351
345
  const runtimeDir = resolve(distDir, "vite-client/runtime");
352
346
  flow.options.alias["#viteManifest"] = resolve(flow.options.buildDir, "viteManifest.mjs");
353
- console.log(_options);
354
- let vite;
355
347
  if (flow.options.dev) {
356
- flow.hook("nitro:init", async (nitro) => {
357
- vite = await createClient(flow);
358
- nitro.options.devHandlers.push({
359
- handler: vite.middlewares,
360
- route: _options.route
361
- });
348
+ const _vite = await createClient(flow);
349
+ addDevServerHandler({
350
+ handler: _vite.middlewares,
351
+ route: _options.route
362
352
  });
363
353
  addTemplate({
364
354
  filename: "viteManifest.mjs",
365
355
  async getContents() {
366
356
  return [
367
357
  "export default {",
368
- `head:()=>'<script type="module" src="${joinURL("/", _options.route, "/@vite/client")}"><\/script>'`,
358
+ 'head:()=>`<script type="module" src="/_vite/@vite/client"><\/script>`',
369
359
  ",",
370
- `body: (bundle)=>\`<script type="module" src="${joinURL("/", _options.route, _options.dir)}/\${bundle}.ts"><\/script>\``,
360
+ 'body: (bundle)=>`<script type="module" src="/_vite/client/pages/${bundle}.ts"><\/script>`',
371
361
  "}"
372
362
  ].join("\n");
373
363
  }
@@ -1258,7 +1248,6 @@ async function bundleVite(flow) {
1258
1248
  nuxt: flow,
1259
1249
  flow,
1260
1250
  config: vite.mergeConfig({
1261
- mode: flow.options.dev ? "development" : void 0,
1262
1251
  resolve: {
1263
1252
  alias: {
1264
1253
  ...flow.options.alias,
@@ -1305,8 +1294,6 @@ async function bundleVite(flow) {
1305
1294
  }
1306
1295
  }, flow.options.vite)
1307
1296
  };
1308
- if (flow.options.dev)
1309
- ctx.config.mode = process.env.NODE_ENV || "development";
1310
1297
  await flow.callHook("vite:extend", ctx);
1311
1298
  flow.hook("vite:serverCreated", (server) => {
1312
1299
  ctx.nuxt.hook("app:templatesGenerated", () => {
@@ -1347,7 +1334,6 @@ function watch(flow) {
1347
1334
  cwd: flow.options.srcDir,
1348
1335
  ignoreInitial: true,
1349
1336
  ignored: [
1350
- isIgnoredFlow,
1351
1337
  ".flow",
1352
1338
  "node_modules"
1353
1339
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "5.0.0-beta.12",
3
+ "version": "5.0.0-beta.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,9 +14,10 @@
14
14
  "flow": "./bin/flow.mjs"
15
15
  },
16
16
  "dependencies": {
17
- "@monkeyplus/flow-cli": "5.0.0-beta.12",
18
- "@monkeyplus/flow-kit": "5.0.0-beta.12",
19
- "@monkeyplus/flow-schema": "5.0.0-beta.12",
17
+ "@monkeyplus/flow-cli": "5.0.0-beta.3",
18
+ "@monkeyplus/flow-kit": "5.0.0-beta.3",
19
+ "@monkeyplus/flow-schema": "5.0.0-beta.3",
20
+ "@nuxt/vite-builder": "3.0.0-rc.1",
20
21
  "@rollup/plugin-replace": "^4.0.0",
21
22
  "@vueuse/head": "^0.7.6",
22
23
  "c12": "^0.2.7",
@@ -55,7 +56,7 @@
55
56
  "unplugin": "^0.6.3",
56
57
  "untyped": "^0.4.4",
57
58
  "vite": "^2.9.9",
58
- "vue": "^3.2.33"
59
+ "vue": "^3"
59
60
  },
60
61
  "devDependencies": {
61
62
  "@types/fs-extra": "^9.0.13"
@@ -1,7 +1,6 @@
1
1
  import { normalize } from 'pathe';
2
2
  import chokidar from 'chokidar';
3
3
  import type { Flow } from '@monkeyplus/flow-schema';
4
- import { isIgnoredFlow } from '@monkeyplus/flow-kit';
5
4
  import { debounce } from 'perfect-debounce';
6
5
  import { generateApp as _generateApp, createApp } from './app';
7
6
 
@@ -37,7 +36,7 @@ function watch(flow: Flow) {
37
36
  cwd: flow.options.srcDir,
38
37
  ignoreInitial: true,
39
38
  ignored: [
40
- isIgnoredFlow,
39
+ // isIgnored,
41
40
  '.flow',
42
41
  'node_modules',
43
42
  ],
@@ -17,14 +17,12 @@ export default eventHandler(async(event) => {
17
17
 
18
18
  // console.log(flow);
19
19
  const { page, locale, params, view } = flow.router.byUrl.lookup(url!) || {};
20
- // Truncate page
21
- if (!page) return;
22
-
23
20
  await flow.callHook('page:scripts', scripts);
24
21
  if (view.bundle)
25
22
  await flow.callHook('page:chunks', view.bundle, chunks);
26
23
 
27
24
  const templateContext = {} as any;
25
+ if (!page) return;
28
26
 
29
27
  const dynamyc = params?._;
30
28
  const contextPage = {} as any;
@@ -22,7 +22,6 @@ export async function bundleVite(flow: Flow) {
22
22
  nuxt: flow,
23
23
  flow,
24
24
  config: vite.mergeConfig({
25
- mode: flow.options.dev ? 'development' : undefined,
26
25
  resolve: {
27
26
  alias: {
28
27
  ...flow.options.alias,
@@ -72,9 +71,6 @@ export async function bundleVite(flow: Flow) {
72
71
  },
73
72
  }, flow.options.vite),
74
73
  };
75
- if (flow.options.dev)
76
- ctx.config.mode = process.env.NODE_ENV || 'development';
77
-
78
74
  await flow.callHook('vite:extend', ctx);
79
75
 
80
76
  flow.hook('vite:serverCreated', (server: vite.ViteDevServer) => {
@@ -7,25 +7,18 @@ export const createClient = async(flow: Flow) => {
7
7
  const vite = await createServer({
8
8
  root: resolve(flow.options.rootDir),
9
9
  base: '/_vite/',
10
-
11
10
  build: {
12
-
13
11
  manifest: true,
14
12
  },
15
13
  server: {
16
- watch: {
17
- ignored: ['**/.env/**', '**/.env*'],
18
- },
19
14
  middlewareMode: 'ssr',
20
- //
21
15
  },
22
16
  });
23
17
  const _doReload = () => {
24
- if (vite)
25
- vite?.ws?.send({ type: 'full-reload' });
18
+ vite.ws.send({ type: 'full-reload' });
26
19
  };
27
20
 
28
- const doReload = debounce(_doReload, 60);
21
+ const doReload = debounce(_doReload, 50);
29
22
 
30
23
  // Use this to refresh page
31
24
  flow.hook('bundler:change', () => {
@@ -1,5 +1,5 @@
1
1
 
2
- import { resolveFilesFlow, useNuxt } from '@monkeyplus/flow-kit';
2
+ import { resolveFiles, useNuxt } from '@monkeyplus/flow-kit';
3
3
  import { extname, relative, resolve } from 'pathe';
4
4
  import escapeRE from 'escape-string-regexp';
5
5
  import { camelCase } from 'scule';
@@ -17,7 +17,7 @@ export async function resolvePagesRoutes(): Promise<Pages[]> {
17
17
 
18
18
  const allRoutes: Pages[] = (await Promise.all(
19
19
  pagesDirs.map(async(dir) => {
20
- const files = await resolveFilesFlow(dir, `**/*{${nuxt.options.extensions.join(',')}}`);
20
+ const files = await resolveFiles(dir, `**/*{${nuxt.options.extensions.join(',')}}`);
21
21
 
22
22
  // Sort to make sure parent are listed first
23
23
 
@@ -4,54 +4,38 @@ import { resolve } from 'pathe';
4
4
  // import { genImport } from 'knitwork';
5
5
  import fse from 'fs-extra';
6
6
  import logger from 'consola';
7
- import { joinURL } from 'ufo';
8
7
  import { builClient, createClient } from '../core/vite/client';
9
8
  import { distDir } from '../dirs';
10
9
 
11
10
  interface OptionsViteClient{
12
11
  route: string
13
- dir: string
14
12
  }
15
13
  export default defineFlowModule<OptionsViteClient>({
16
14
 
17
15
  meta: {
18
- name: 'vite-client',
19
- configKey: 'bundle',
16
+ name: 'viteClient',
20
17
  },
21
18
  defaults: {
22
19
  route: '/_vite/',
23
- dir: '/client/pages',
24
20
  },
25
21
  async setup(_options, flow) {
26
22
  const runtimeDir = resolve(distDir, 'vite-client/runtime');
27
23
  flow.options.alias['#viteManifest'] = resolve(flow.options.buildDir, 'viteManifest.mjs');
28
- console.log(_options);
29
24
 
30
- let vite: any;
31
25
  if (flow.options.dev) {
32
- flow.hook('nitro:init', async(nitro) => {
33
- vite = await createClient(flow);
34
- // return vite.middlewares;
35
- nitro.options.devHandlers.push({
36
- handler: vite.middlewares,
37
- route: _options.route,
38
- });
26
+ const _vite = await createClient(flow);
27
+ addDevServerHandler({
28
+ handler: _vite.middlewares,
29
+ route: _options.route,
39
30
  });
40
- // addDevServerHandler({
41
- // route: _options.route,
42
- // handler: async(req, res) => {
43
- // return await vite.middlewares(req, res);
44
- // },
45
- // });
46
-
47
31
  addTemplate({
48
32
  filename: 'viteManifest.mjs',
49
33
  async getContents() {
50
34
  return ['export default {',
51
- `head:()=>'<script type="module" src="${joinURL('/', _options.route, '/@vite/client')}"></script>'`,
35
+ 'head:()=>`<script type="module" src="/_vite/@vite/client"></script>`',
52
36
  ',',
53
37
  // eslint-disable-next-line no-template-curly-in-string
54
- `body: (bundle)=>\`<script type="module" src="${joinURL('/', _options.route, _options.dir)}/\${bundle}.ts"></script>\``,
38
+ 'body: (bundle)=>`<script type="module" src="/_vite/client/pages/${bundle}.ts"></script>`',
55
39
  '}',
56
40
  ].join('\n');
57
41
  },