@monkeyplus/flow 6.0.14 → 6.0.16

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.
@@ -1,3 +1,3 @@
1
- export { defineCmsCollection } from '../server/lib/composables';
2
- export { widgets } from '../server/lib/cms/widgets';
3
1
  export { collections } from '../server/lib/cms/helpers';
2
+ export { widgets } from '../server/lib/cms/widgets';
3
+ export { defineCmsCollection } from '../server/lib/composables';
@@ -1,3 +1,3 @@
1
- export { defineCmsCollection } from "../server/lib/composables.mjs";
2
- export { widgets } from "../server/lib/cms/widgets.mjs";
3
1
  export { collections } from "../server/lib/cms/helpers.mjs";
2
+ export { widgets } from "../server/lib/cms/widgets.mjs";
3
+ export { defineCmsCollection } from "../server/lib/composables.mjs";
@@ -1,12 +1,12 @@
1
+ import fs from "node:fs";
2
+ import { resolve } from "node:path";
3
+ import process from "node:process";
1
4
  import defu from "defu";
5
+ import { createJiti } from "jiti";
2
6
  import yml from "js-yaml";
3
7
  import { defineEventHandler, setResponseHeader } from "nitro/h3";
4
8
  import { collections, defineCms } from "../lib/cms/helpers.mjs";
5
9
  import { widgets } from "../lib/cms/widgets.mjs";
6
- import fs from "node:fs";
7
- import { resolve } from "node:path";
8
- import { createJiti } from "jiti";
9
- import process from "node:process";
10
10
  import { defineCmsCollection } from "../lib/composables.mjs";
11
11
  export default defineEventHandler(async (event) => {
12
12
  if (!globalThis.defineCmsCollection) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.14",
3
+ "version": "6.0.16",
4
4
  "description": "@monkeyplus/flow package-first runtime with Vite, Nitro, Vue and a workspace playground.",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
package/src/main.d.ts CHANGED
@@ -1 +1 @@
1
- export {};
1
+ import 'virtual:flow/server-styles';
package/src/main.mjs CHANGED
@@ -1,5 +1,6 @@
1
- import { hydrateIslands } from "./runtime/islands.mjs";
2
1
  import bundles from "virtual:flow/client-pages";
2
+ import { hydrateIslands } from "./runtime/islands.mjs";
3
+ import "virtual:flow/server-styles";
3
4
  function readBoot() {
4
5
  const element = document.getElementById("flow-boot");
5
6
  if (!element?.textContent) {
@@ -67,6 +67,7 @@ export function createFlowNitroConfig(options = {}) {
67
67
  storage: flowModules.nitro.storage,
68
68
  routeRules: {
69
69
  "/api/**": { cors: true },
70
+ ...flowNitroConfig.routeRules,
70
71
  ...flowModules.nitro.routeRules
71
72
  },
72
73
  imports: flowModules.nitro.imports,
@@ -1,4 +1,4 @@
1
- import { existsSync } from "node:fs";
1
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
2
2
  import { relative, resolve } from "node:path";
3
3
  import ui from "@nuxt/ui/vite";
4
4
  import Vue from "@vitejs/plugin-vue";
@@ -17,6 +17,7 @@ import {
17
17
  createVirtualLayoutContextsModule,
18
18
  createVirtualLayoutsModule,
19
19
  createVirtualPagesModule,
20
+ createVirtualServerStylesModule,
20
21
  createVirtualTemplatesModule
21
22
  } from "../runtime/virtual-pages.mjs";
22
23
  const flowRestartPatterns = [
@@ -55,6 +56,9 @@ function getVirtualModuleIdsForPath(projectPath) {
55
56
  if (projectPath === "flow.config.ts" || projectPath.startsWith("pages/")) {
56
57
  ids.add("virtual:flow/pages");
57
58
  }
59
+ if (projectPath.startsWith("views/")) {
60
+ ids.add("virtual:flow/server-styles");
61
+ }
58
62
  if (projectPath.startsWith("views/templates/")) {
59
63
  ids.add("virtual:flow/templates");
60
64
  }
@@ -141,7 +145,7 @@ function createFlowHotReload(projectRoot, extraWatchPaths = []) {
141
145
  });
142
146
  }, 0);
143
147
  }
144
- async function handleServerChange(server, filePath, event) {
148
+ async function handleServerChange(server, filePath, event, hmrModules) {
145
149
  const projectPath = toProjectPath(filePath);
146
150
  invalidateFileModules(server, filePath, event);
147
151
  invalidateVirtualModules(server, projectPath);
@@ -153,11 +157,21 @@ function createFlowHotReload(projectRoot, extraWatchPaths = []) {
153
157
  if (!shouldReload) {
154
158
  return false;
155
159
  }
156
- server.ws.send({ type: "full-reload", path: "*" });
160
+ if (event === "change" && projectPath.endsWith(".vue") && hmrModules) {
161
+ const validModules = hmrModules.filter((m) => m && m.id);
162
+ const isStyleOnly = validModules.length > 0 && validModules.every((m) => m.id.includes("type=style"));
163
+ if (isStyleOnly) {
164
+ return false;
165
+ }
166
+ }
167
+ setTimeout(() => {
168
+ server.ws.send({ type: "full-reload", path: "*" });
169
+ }, 50);
157
170
  return true;
158
171
  }
159
172
  return {
160
173
  name: "flow:hot-reload",
174
+ enforce: "post",
161
175
  configureServer(server) {
162
176
  if (extraWatchPaths.length) {
163
177
  server.watcher.add(extraWatchPaths);
@@ -170,9 +184,7 @@ function createFlowHotReload(projectRoot, extraWatchPaths = []) {
170
184
  });
171
185
  },
172
186
  async handleHotUpdate(ctx) {
173
- if (await handleServerChange(ctx.server, ctx.file, "change")) {
174
- return [];
175
- }
187
+ await handleServerChange(ctx.server, ctx.file, "change", ctx.modules);
176
188
  }
177
189
  };
178
190
  }
@@ -184,7 +196,8 @@ function createFlowVirtualServerModules(projectRoot, flowConfig) {
184
196
  ["virtual:flow/templates", () => createVirtualTemplatesModule(projectRoot)],
185
197
  ["virtual:flow/layouts", () => createVirtualLayoutsModule(projectRoot)],
186
198
  ["virtual:flow/layout-contexts", () => createVirtualLayoutContextsModule(projectRoot)],
187
- ["virtual:flow/bases", () => createVirtualBaseTemplatesModule(projectRoot)]
199
+ ["virtual:flow/bases", () => createVirtualBaseTemplatesModule(projectRoot)],
200
+ ["virtual:flow/server-styles", () => createVirtualServerStylesModule(projectRoot)]
188
201
  ]);
189
202
  return {
190
203
  name: "flow:server-virtuals",
@@ -227,11 +240,27 @@ function createFlowVirtualClientPages(projectRoot) {
227
240
  }
228
241
  };
229
242
  }
243
+ function FlowComponentsResolver() {
244
+ return {
245
+ type: "component",
246
+ resolve: (name) => {
247
+ if (["FlowIsland", "MkImage", "MkLink", "MkPicture"].includes(name)) {
248
+ return {
249
+ name,
250
+ from: "@monkeyplus/flow/components"
251
+ };
252
+ }
253
+ }
254
+ };
255
+ }
230
256
  export function createFlowViteConfig(options = {}) {
231
257
  const projectRoot = resolve(options.projectRoot || process.cwd());
232
258
  const flowConfig = resolveFlowConfig(options.userFlowConfig || {});
233
259
  const flowModules = loadFlowModules(projectRoot, flowConfig);
234
- const flowNitroConfig = { ...flowConfig.nitro || {} };
260
+ const flowNitroConfig = {
261
+ typescript: { generateTsConfig: true },
262
+ ...flowConfig.nitro || {}
263
+ };
235
264
  const flowNitroHooks = flowNitroConfig.hooks || {};
236
265
  const flowPackagePattern = /^@monkeyplus\/flow(?:\/.*)?$/;
237
266
  const userPrerenderRoutesHook = typeof flowNitroHooks["prerender:routes"] === "function" ? flowNitroHooks["prerender:routes"] : void 0;
@@ -247,6 +276,29 @@ export function createFlowViteConfig(options = {}) {
247
276
  moduleWatch.additionalPaths,
248
277
  componentDirs
249
278
  );
279
+ const flowTypesDir = resolve(projectRoot, ".flow/types");
280
+ if (!existsSync(flowTypesDir)) {
281
+ mkdirSync(flowTypesDir, { recursive: true });
282
+ }
283
+ writeFileSync(resolve(flowTypesDir, "flow.d.ts"), [
284
+ '/// <reference path="./auto-imports.d.ts" />',
285
+ '/// <reference path="./components.d.ts" />',
286
+ '/// <reference path="../../.nitro/types/nitro-imports.d.ts" />'
287
+ ].join("\n"));
288
+ const mappedNitroImports = {};
289
+ if (flowModules.nitro.imports?.imports && Array.isArray(flowModules.nitro.imports.imports)) {
290
+ for (const item of flowModules.nitro.imports.imports) {
291
+ if (!item.from || !item.name) continue;
292
+ if (!mappedNitroImports[item.from]) {
293
+ mappedNitroImports[item.from] = [];
294
+ }
295
+ if (item.as) {
296
+ mappedNitroImports[item.from].push([item.name, item.as]);
297
+ } else {
298
+ mappedNitroImports[item.from].push(item.name);
299
+ }
300
+ }
301
+ }
250
302
  return defineConfig({
251
303
  plugins: [
252
304
  createFlowVirtualServerModules(projectRoot, flowConfig),
@@ -261,14 +313,25 @@ export function createFlowViteConfig(options = {}) {
261
313
  ui({
262
314
  router: false,
263
315
  components: {
316
+ dts: resolve(projectRoot, ".flow/types/components.d.ts"),
264
317
  ...options.userFlowConfig?.components,
265
318
  resolvers: [
319
+ FlowComponentsResolver(),
266
320
  IconsResolver(),
267
321
  ...options.userFlowConfig?.components?.resolvers || []
268
322
  ]
269
- // dirs: [],
270
323
  },
271
- autoImport: options.userFlowConfig?.autoImport
324
+ autoImport: {
325
+ dts: resolve(projectRoot, ".flow/types/auto-imports.d.ts"),
326
+ imports: [
327
+ {
328
+ "@monkeyplus/flow": ["definePage", "defineLayoutContext", "queryContent"],
329
+ ...mappedNitroImports
330
+ },
331
+ ...options.userFlowConfig?.autoImport?.imports || []
332
+ ],
333
+ ...options.userFlowConfig?.autoImport
334
+ }
272
335
  }),
273
336
  nitro({
274
337
  ...flowNitroConfig,
@@ -7,3 +7,4 @@ export declare function createVirtualBaseTemplatesModule(projectRoot: string): s
7
7
  export declare function createVirtualIslandsModule(projectRoot: string): string;
8
8
  export declare function createVirtualClientPagesModule(projectRoot: string): string;
9
9
  export declare function createVirtualClientPageAssetsModule(projectRoot: string): string;
10
+ export declare function createVirtualServerStylesModule(projectRoot: string): string;
@@ -1,3 +1,4 @@
1
+ import { parse } from "vue/compiler-sfc";
1
2
  import { existsSync, readFileSync, readdirSync } from "node:fs";
2
3
  import { basename, extname, resolve } from "node:path";
3
4
  function collectFiles(rootDir, extensions, currentDir = rootDir) {
@@ -170,3 +171,20 @@ export function createVirtualClientPageAssetsModule(projectRoot) {
170
171
  ""
171
172
  ].join("\n");
172
173
  }
174
+ export function createVirtualServerStylesModule(projectRoot) {
175
+ const viewsDir = resolve(projectRoot, "views");
176
+ const files = existsSync(viewsDir) ? collectFiles(viewsDir, [".vue"]) : [];
177
+ const imports = files.flatMap((filePath) => {
178
+ const code = readFileSync(filePath, "utf8");
179
+ const { descriptor } = parse(code);
180
+ return descriptor.styles.map((style, i) => {
181
+ return `import "${toAbsoluteImport(filePath)}?vue&type=style&index=${i}&lang.${style.lang || "css"}";`;
182
+ });
183
+ });
184
+ return [
185
+ ...imports,
186
+ "",
187
+ "export default {};",
188
+ ""
189
+ ].join("\n");
190
+ }