@monkeyplus/flow 5.0.0-beta.9 → 5.0.0-rc.1

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/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, resolveFiles, nuxtCtx, installModule, loadFlowConfig, templateUtils, normalizeTemplate, compileTemplate, normalizePlugin, resolveFilesFlow, isIgnoredFlow } from '@monkeyplus/flow-kit';
3
+ import { defineFlowModule, addPlugin, defineNuxtModule, logger, addTemplate, addPluginTemplate, addVitePlugin, useNuxt, resolveAlias, resolveFilesFlow, nuxtCtx, installModule, loadFlowConfig, templateUtils, normalizeTemplate, compileTemplate, normalizePlugin, 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.9";
30
+ const version = "5.0.0-rc.1";
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 resolveFiles(dir, `**/*{${nuxt.options.extensions.join(",")}}`);
228
+ const files = await resolveFilesFlow(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("_");
@@ -299,29 +299,35 @@ const pagesModule = defineNuxtModule({
299
299
  });
300
300
 
301
301
  const createClient = async (flow) => {
302
- const vite = await createServer({
303
- root: resolve(flow.options.rootDir),
304
- base: "/_vite/",
305
- build: {
306
- manifest: true
307
- },
308
- server: {
309
- watch: {
310
- ignored: ["**/.env/**", "**/.env*"]
302
+ let vite;
303
+ if (globalThis.viteClient) {
304
+ vite = globalThis.viteClient;
305
+ } else {
306
+ vite = await createServer({
307
+ root: resolve(flow.options.rootDir),
308
+ base: "/_vite/",
309
+ build: {
310
+ manifest: true
311
311
  },
312
- middlewareMode: "ssr"
313
- }
314
- });
312
+ server: {
313
+ watch: {
314
+ ignored: ["**/.env/**", "**/.env*"]
315
+ },
316
+ middlewareMode: "ssr"
317
+ }
318
+ });
319
+ globalThis.viteClient = vite;
320
+ }
315
321
  const _doReload = () => {
316
322
  if (vite)
317
323
  vite?.ws?.send({ type: "full-reload" });
318
324
  };
319
- const doReload = debounce(_doReload, 50);
325
+ const doReload = debounce(_doReload, 60);
320
326
  flow.hook("bundler:change", () => {
321
327
  doReload();
322
328
  });
323
329
  flow.hook("close", async () => {
324
- await vite.close();
330
+ vite.restart();
325
331
  });
326
332
  return vite;
327
333
  };
@@ -340,10 +346,12 @@ const builClient = async (flow) => {
340
346
 
341
347
  const viteModule = defineFlowModule({
342
348
  meta: {
343
- name: "viteClient"
349
+ name: "vite-client",
350
+ configKey: "bundle"
344
351
  },
345
352
  defaults: {
346
- route: "/_vite/"
353
+ route: "/_vite/",
354
+ dir: "/client/pages"
347
355
  },
348
356
  async setup(_options, flow) {
349
357
  const runtimeDir = resolve(distDir, "vite-client/runtime");
@@ -362,9 +370,9 @@ const viteModule = defineFlowModule({
362
370
  async getContents() {
363
371
  return [
364
372
  "export default {",
365
- 'head:()=>`<script type="module" src="/_vite/@vite/client"><\/script>`',
373
+ `head:()=>'<script type="module" src="${joinURL("/", _options.route, "/@vite/client")}"><\/script>'`,
366
374
  ",",
367
- 'body: (bundle)=>`<script type="module" src="/_vite/client/pages/${bundle}.ts"><\/script>`',
375
+ `body: (bundle)=>\`<script type="module" src="${joinURL("/", _options.route, _options.dir)}/\${bundle}.ts"><\/script>\``,
368
376
  "}"
369
377
  ].join("\n");
370
378
  }
@@ -1095,10 +1103,7 @@ const buildServer = async (ctx) => {
1095
1103
  },
1096
1104
  server: {
1097
1105
  preTransformRequests: false,
1098
- cors: true,
1099
- watch: {
1100
- ignored: ["**/.env*"]
1101
- }
1106
+ cors: true
1102
1107
  },
1103
1108
  plugins: [
1104
1109
  cacheDirPlugin(ctx.flow.options.rootDir, "server")
@@ -1347,6 +1352,7 @@ function watch(flow) {
1347
1352
  cwd: flow.options.srcDir,
1348
1353
  ignoreInitial: true,
1349
1354
  ignored: [
1355
+ isIgnoredFlow,
1350
1356
  ".flow",
1351
1357
  "node_modules"
1352
1358
  ]
@@ -16,7 +16,7 @@ const buildPages = (page) => (location, language) => {
16
16
  return {
17
17
  name,
18
18
  url: path,
19
- context: { page: localePage, locale: _locale, path, view: page.view, name }
19
+ context: { page: localePage, locale: _locale, path, view: page.view, name: page.name }
20
20
  };
21
21
  });
22
22
  };
@@ -0,0 +1,3 @@
1
+ import type { DynamicPage, SimplePage } from '@monkeyplus/flow-schema';
2
+ export declare function definePage(page: SimplePage): SimplePage;
3
+ export declare function defineDinamycPage(page: DynamicPage): DynamicPage;
@@ -0,0 +1,6 @@
1
+ export function definePage(page) {
2
+ return page;
3
+ }
4
+ export function defineDinamycPage(page) {
5
+ return page;
6
+ }
@@ -24,18 +24,19 @@ export default defineFlowPlugin(async (flow) => {
24
24
  const { path } = flow.router.byName.lookup(name) || {};
25
25
  return path || "/404";
26
26
  }
27
- async function getUrls() {
27
+ async function getUrls(withLocale = false) {
28
28
  const urls = [];
29
29
  for (const page of allPages) {
30
30
  if (!page.path.includes("/**")) {
31
- urls.push(page.path);
31
+ urls.push(withLocale ? { url: page.path, locale: page.locale.code, name: page.name } : page.path);
32
32
  } else {
33
33
  const dPages = await page.page.dynamic.method({
34
34
  locale: page.locale,
35
35
  utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils)
36
36
  });
37
37
  dPages.forEach((dPage) => {
38
- urls.push(joinURL(page.path.replace("/**", ""), dPage.url));
38
+ const _path = joinURL(page.path.replace("/**", ""), dPage.url);
39
+ urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
39
40
  });
40
41
  }
41
42
  }
@@ -43,6 +44,7 @@ export default defineFlowPlugin(async (flow) => {
43
44
  }
44
45
  flow.setUtil("getUrl", getUrl);
45
46
  flow.setUtil("getUrls", getUrls);
47
+ flow.setUtil("getPages", () => allPages);
46
48
  return {
47
49
  provide: {
48
50
  pages: { allPages }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "5.0.0-beta.9",
3
+ "version": "5.0.0-rc.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "exports": {
@@ -14,10 +14,9 @@
14
14
  "flow": "./bin/flow.mjs"
15
15
  },
16
16
  "dependencies": {
17
- "@monkeyplus/flow-cli": "5.0.0-beta.9",
18
- "@monkeyplus/flow-kit": "5.0.0-beta.9",
19
- "@monkeyplus/flow-schema": "5.0.0-beta.9",
20
- "@nuxt/vite-builder": "3.0.0-rc.1",
17
+ "@monkeyplus/flow-cli": "5.0.0-rc.1",
18
+ "@monkeyplus/flow-kit": "5.0.0-rc.1",
19
+ "@monkeyplus/flow-schema": "5.0.0-rc.1",
21
20
  "@rollup/plugin-replace": "^4.0.0",
22
21
  "@vueuse/head": "^0.7.6",
23
22
  "c12": "^0.2.7",
@@ -56,7 +55,7 @@
56
55
  "unplugin": "^0.6.3",
57
56
  "untyped": "^0.4.4",
58
57
  "vite": "^2.9.9",
59
- "vue": "^3"
58
+ "vue": "^3.2.33"
60
59
  },
61
60
  "devDependencies": {
62
61
  "@types/fs-extra": "^9.0.13"
@@ -1,6 +1,7 @@
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';
4
5
  import { debounce } from 'perfect-debounce';
5
6
  import { generateApp as _generateApp, createApp } from './app';
6
7
 
@@ -36,7 +37,7 @@ function watch(flow: Flow) {
36
37
  cwd: flow.options.srcDir,
37
38
  ignoreInitial: true,
38
39
  ignored: [
39
- // isIgnored,
40
+ isIgnoredFlow,
40
41
  '.flow',
41
42
  'node_modules',
42
43
  ],
@@ -57,9 +57,6 @@ export const buildServer = async(ctx: ViteBuildContext) => {
57
57
  // https://github.com/vitest-dev/vitest/issues/229#issuecomment-1002685027
58
58
  preTransformRequests: false,
59
59
  cors: true,
60
- watch: {
61
- ignored: ['**/.env*'],
62
- },
63
60
  },
64
61
  plugins: [
65
62
  cacheDirPlugin(ctx.flow.options.rootDir, 'server'),
@@ -1,31 +1,38 @@
1
1
  import { resolve } from 'pathe';
2
2
  import type { Flow } from '@monkeyplus/flow-schema';
3
+ import type { ViteDevServer } from 'vite';
3
4
  import { build, createServer } from 'vite';
4
5
  import { debounce } from 'perfect-debounce';
5
6
 
6
7
  export const createClient = async(flow: Flow) => {
7
- const vite = await createServer({
8
- root: resolve(flow.options.rootDir),
9
- base: '/_vite/',
10
-
11
- build: {
12
-
13
- manifest: true,
14
- },
15
- server: {
16
- watch: {
17
- ignored: ['**/.env/**', '**/.env*'],
8
+ let vite: ViteDevServer;
9
+ if (globalThis.viteClient) {
10
+ vite = globalThis.viteClient as ViteDevServer;
11
+ }
12
+ else {
13
+ vite = await createServer({
14
+ root: resolve(flow.options.rootDir),
15
+ base: '/_vite/',
16
+ build: {
17
+ manifest: true,
18
18
  },
19
- middlewareMode: 'ssr',
19
+ server: {
20
+ watch: {
21
+ ignored: ['**/.env/**', '**/.env*'],
22
+ },
23
+ middlewareMode: 'ssr',
20
24
  //
21
- },
22
- });
25
+ },
26
+ });
27
+ globalThis.viteClient = vite;
28
+ }
29
+
23
30
  const _doReload = () => {
24
31
  if (vite)
25
32
  vite?.ws?.send({ type: 'full-reload' });
26
33
  };
27
34
 
28
- const doReload = debounce(_doReload, 50);
35
+ const doReload = debounce(_doReload, 60);
29
36
 
30
37
  // Use this to refresh page
31
38
  flow.hook('bundler:change', () => {
@@ -33,7 +40,8 @@ export const createClient = async(flow: Flow) => {
33
40
  });
34
41
 
35
42
  flow.hook('close', async() => {
36
- await vite.close();
43
+ vite.restart();
44
+ // await vite.close();
37
45
  });
38
46
 
39
47
  return vite;
@@ -19,7 +19,7 @@ const buildPages = (page: PageDefinition): GetPages => (location: string, langua
19
19
  return {
20
20
  name,
21
21
  url: path,
22
- context: { page: localePage, locale: _locale, path, view: page.view, name },
22
+ context: { page: localePage, locale: _locale, path, view: page.view, name: page.name },
23
23
  // locale: _locale,
24
24
  };
25
25
  });
@@ -0,0 +1,9 @@
1
+ import type { DynamicPage, SimplePage } from '@monkeyplus/flow-schema';
2
+
3
+ export function definePage(page: SimplePage) {
4
+ return page;
5
+ }
6
+
7
+ export function defineDinamycPage(page: DynamicPage) {
8
+ return page;
9
+ }
@@ -32,17 +32,22 @@ export default defineFlowPlugin(async(flow) => {
32
32
  return path || '/404';
33
33
  }
34
34
 
35
- async function getUrls() {
36
- const urls: string[] = [];
35
+ async function getUrls(withLocale = false) {
36
+ const urls: (string|{ url: string; locale: string; name: string })[] = [];
37
37
  for (const page of allPages) {
38
- if (!page.path.includes('/**')) { urls.push(page.path); }
38
+ if (!page.path.includes('/**')) {
39
+ urls.push(withLocale
40
+ ? { url: page.path, locale: page.locale.code, name: page.name }
41
+ : page.path);
42
+ }
39
43
  else {
40
44
  const dPages = await page.page.dynamic.method({
41
45
  locale: page.locale,
42
46
  utils: Object.assign({ getLocale: () => page.locale }, flow.app.utils),
43
47
  });
44
48
  dPages.forEach((dPage) => {
45
- urls.push(joinURL(page.path.replace('/**', ''), dPage.url));
49
+ const _path = joinURL(page.path.replace('/**', ''), dPage.url);
50
+ urls.push(withLocale ? { url: _path, locale: page.locale.code, name: joinURL(page.name, dPage.name) } : _path);
46
51
  });
47
52
  }
48
53
  }
@@ -50,6 +55,8 @@ export default defineFlowPlugin(async(flow) => {
50
55
  }
51
56
  flow.setUtil('getUrl', getUrl);
52
57
  flow.setUtil('getUrls', getUrls);
58
+ flow.setUtil('getPages', () => allPages);
59
+
53
60
  return {
54
61
  provide: {
55
62
  pages: { allPages },
@@ -1,5 +1,5 @@
1
1
 
2
- import { resolveFiles, useNuxt } from '@monkeyplus/flow-kit';
2
+ import { resolveFilesFlow, 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 resolveFiles(dir, `**/*{${nuxt.options.extensions.join(',')}}`);
20
+ const files = await resolveFilesFlow(dir, `**/*{${nuxt.options.extensions.join(',')}}`);
21
21
 
22
22
  // Sort to make sure parent are listed first
23
23
 
@@ -1,27 +1,30 @@
1
- import { addDevServerHandler, addPlugin, addTemplate, defineFlowModule } from '@monkeyplus/flow-kit';
1
+ import { addPlugin, addTemplate, defineFlowModule } from '@monkeyplus/flow-kit';
2
2
  import type { FlowModule } from '@monkeyplus/flow-schema';
3
3
  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';
7
8
  import { builClient, createClient } from '../core/vite/client';
8
9
  import { distDir } from '../dirs';
9
10
 
10
11
  interface OptionsViteClient{
11
12
  route: string
13
+ dir: string
12
14
  }
13
15
  export default defineFlowModule<OptionsViteClient>({
14
16
 
15
17
  meta: {
16
- name: 'viteClient',
18
+ name: 'vite-client',
19
+ configKey: 'bundle',
17
20
  },
18
21
  defaults: {
19
22
  route: '/_vite/',
23
+ dir: '/client/pages',
20
24
  },
21
25
  async setup(_options, flow) {
22
26
  const runtimeDir = resolve(distDir, 'vite-client/runtime');
23
27
  flow.options.alias['#viteManifest'] = resolve(flow.options.buildDir, 'viteManifest.mjs');
24
-
25
28
  let vite: any;
26
29
  if (flow.options.dev) {
27
30
  flow.hook('nitro:init', async(nitro) => {
@@ -43,10 +46,10 @@ export default defineFlowModule<OptionsViteClient>({
43
46
  filename: 'viteManifest.mjs',
44
47
  async getContents() {
45
48
  return ['export default {',
46
- 'head:()=>`<script type="module" src="/_vite/@vite/client"></script>`',
49
+ `head:()=>'<script type="module" src="${joinURL('/', _options.route, '/@vite/client')}"></script>'`,
47
50
  ',',
48
51
  // eslint-disable-next-line no-template-curly-in-string
49
- 'body: (bundle)=>`<script type="module" src="/_vite/client/pages/${bundle}.ts"></script>`',
52
+ `body: (bundle)=>\`<script type="module" src="${joinURL('/', _options.route, _options.dir)}/\${bundle}.ts"></script>\``,
50
53
  '}',
51
54
  ].join('\n');
52
55
  },