@monkeyplus/flow 6.0.14 → 6.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monkeyplus/flow",
3
- "version": "6.0.14",
3
+ "version": "6.0.15",
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) {
@@ -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",
@@ -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
+ }