@void/solid 0.7.13 → 0.8.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.
Files changed (2) hide show
  1. package/dist/plugin.mjs +54 -50
  2. package/package.json +3 -3
package/dist/plugin.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import solid from "vite-plugin-solid";
2
+ import { generateComponentManifest, resolveEffectiveLayoutChain, resolvePagesDir, resolveStaticPageDataBuildOptions, scanPages } from "void/pages";
2
3
  import { existsSync, readFileSync, readdirSync } from "node:fs";
3
4
  import { normalizePath } from "vite";
4
- import { generateComponentManifest, resolveEffectiveLayoutChain, resolveStaticPageDataBuildOptions, scanPages } from "void/pages";
5
5
  import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, extractCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
6
6
  //#region ../../node_modules/.pnpm/pathe@2.0.3/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs
7
7
  const _DRIVE_LETTER_START_RE = /^[A-Za-z]:\//;
@@ -9,42 +9,9 @@ function normalizeWindowsPath(input = "") {
9
9
  if (!input) return input;
10
10
  return input.replace(/\\/g, "/").replace(_DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
11
11
  }
12
- const _UNC_REGEX = /^[/\\]{2}/;
13
12
  const _IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/;
14
13
  const _DRIVE_LETTER_RE = /^[A-Za-z]:$/;
15
14
  const _ROOT_FOLDER_RE = /^\/([A-Za-z]:)?$/;
16
- const normalize = function(path) {
17
- if (path.length === 0) return ".";
18
- path = normalizeWindowsPath(path);
19
- const isUNCPath = path.match(_UNC_REGEX);
20
- const isPathAbsolute = isAbsolute(path);
21
- const trailingSeparator = path[path.length - 1] === "/";
22
- path = normalizeString(path, !isPathAbsolute);
23
- if (path.length === 0) {
24
- if (isPathAbsolute) return "/";
25
- return trailingSeparator ? "./" : ".";
26
- }
27
- if (trailingSeparator) path += "/";
28
- if (_DRIVE_LETTER_RE.test(path)) path += "/";
29
- if (isUNCPath) {
30
- if (!isPathAbsolute) return `//./${path}`;
31
- return `//${path}`;
32
- }
33
- return isPathAbsolute && !isAbsolute(path) ? `/${path}` : path;
34
- };
35
- const join = function(...segments) {
36
- let path = "";
37
- for (const seg of segments) {
38
- if (!seg) continue;
39
- if (path.length > 0) {
40
- const pathTrailing = path[path.length - 1] === "/";
41
- const segLeading = seg[0] === "/";
42
- if (pathTrailing && segLeading) path += seg.slice(1);
43
- else path += pathTrailing || segLeading ? seg : `/${seg}`;
44
- } else path += seg;
45
- }
46
- return normalize(path);
47
- };
48
15
  function cwd() {
49
16
  if (typeof process !== "undefined" && typeof process.cwd === "function") return process.cwd().replace(/\\/g, "/");
50
17
  return "/";
@@ -164,10 +131,10 @@ function findIslandImports(code) {
164
131
  * detect the language.
165
132
  */
166
133
  const WRAPPER_PREFIX = "/@void-island-wrap/";
167
- function islandsPlugin(pagesDir) {
134
+ function islandsPlugin(pagesDir, options) {
168
135
  let pageScan = null;
169
136
  let isDev = false;
170
- const root = dirname(pagesDir);
137
+ const root = options?.root ?? dirname(pagesDir);
171
138
  const islandManifest = /* @__PURE__ */ new Map();
172
139
  const islandCssFiles = /* @__PURE__ */ new Set();
173
140
  const wrapperMeta = /* @__PURE__ */ new Map();
@@ -193,7 +160,7 @@ function islandsPlugin(pagesDir) {
193
160
  },
194
161
  async buildStart() {
195
162
  if (existsSync(pagesDir)) {
196
- pageScan = await scanPages(root);
163
+ pageScan = await scanPages(root, { pagesDir });
197
164
  const filesToScan = [
198
165
  ...pageScan.pages.map((page) => ({
199
166
  filePath: page.componentPath,
@@ -451,12 +418,30 @@ function hasNonIslandPages(dir) {
451
418
  }
452
419
  function pagesPlugin(pagesDir, options) {
453
420
  let pageScan = null;
421
+ let isDev = false;
454
422
  let viteConfig;
455
- const root = dirname(pagesDir);
423
+ const root = options?.root ?? dirname(pagesDir);
424
+ const normalizedPagesDir = normalizePath(pagesDir);
425
+ let pendingRescan = null;
426
+ const rescanPages = async () => {
427
+ pageScan = existsSync(pagesDir) ? await scanPages(root, { pagesDir }) : null;
428
+ };
429
+ const runRescan = () => {
430
+ pendingRescan ??= rescanPages().finally(() => {
431
+ pendingRescan = null;
432
+ });
433
+ return pendingRescan;
434
+ };
435
+ const invalidatePageModules = (server) => {
436
+ for (const env of Object.values(server.environments)) for (const id of ["\0" + RENDERER_ID, "\0" + CLIENT_ENTRY_ID]) {
437
+ const mod = env.moduleGraph.getModuleById(id);
438
+ if (mod) env.moduleGraph.invalidateModule(mod);
439
+ }
440
+ };
456
441
  return {
457
442
  name: "void-solid:pages",
458
443
  async buildStart() {
459
- if (existsSync(pagesDir)) pageScan = await scanPages(root);
444
+ await runRescan();
460
445
  },
461
446
  resolveId: {
462
447
  filter: { id: /^virtual:void-pages-(renderer|client)$/ },
@@ -466,7 +451,9 @@ function pagesPlugin(pagesDir, options) {
466
451
  },
467
452
  load: {
468
453
  filter: { id: /^\0virtual:void-pages-(renderer|client)$/ },
469
- handler(id) {
454
+ async handler(id) {
455
+ if (isDev && pendingRescan) await pendingRescan;
456
+ if (!pageScan && existsSync(pagesDir)) await runRescan();
470
457
  if (id === "\0" + RENDERER_ID) {
471
458
  if (!pageScan) return "export function renderPage() { throw new Error('No pages found'); }";
472
459
  return generateRendererModule(pageScan, pagesDir);
@@ -477,19 +464,34 @@ function pagesPlugin(pagesDir, options) {
477
464
  }
478
465
  }
479
466
  },
467
+ configureServer(server) {
468
+ const handlePagesChange = async (path, event) => {
469
+ const normalizedPath = normalizePath(path);
470
+ if (normalizedPath !== normalizedPagesDir && !normalizedPath.startsWith(normalizedPagesDir + "/")) return;
471
+ if (event === "change" && !normalizedPath.endsWith(".md")) return;
472
+ await runRescan();
473
+ invalidatePageModules(server);
474
+ };
475
+ server.watcher.on("add", (path) => handlePagesChange(path, "add"));
476
+ server.watcher.on("change", (path) => handlePagesChange(path, "change"));
477
+ server.watcher.on("unlink", (path) => handlePagesChange(path, "unlink"));
478
+ },
480
479
  configResolved(config) {
481
480
  viteConfig = config;
482
481
  },
483
482
  config(_, env) {
484
483
  if (!existsSync(pagesDir)) return;
485
- if (env.command === "serve") return { optimizeDeps: {
486
- exclude: ["@void/solid"],
487
- include: [
488
- "solid-js",
489
- "solid-js/web",
490
- "solid-js/store"
491
- ]
492
- } };
484
+ if (env.command === "serve") {
485
+ isDev = true;
486
+ return { optimizeDeps: {
487
+ exclude: ["@void/solid"],
488
+ include: [
489
+ "solid-js",
490
+ "solid-js/web",
491
+ "solid-js/store"
492
+ ]
493
+ } };
494
+ }
493
495
  if (!hasNonIslandPages(pagesDir)) return;
494
496
  return { build: {
495
497
  manifest: true,
@@ -708,7 +710,8 @@ function configPlugin() {
708
710
  };
709
711
  }
710
712
  function voidSolid(options) {
711
- const pagesDir = join(process.cwd(), "pages");
713
+ const root = process.cwd();
714
+ const pagesDir = resolvePagesDir(root);
712
715
  return [
713
716
  configPlugin(),
714
717
  solid({
@@ -716,10 +719,11 @@ function voidSolid(options) {
716
719
  ...options?.solid
717
720
  }),
718
721
  pagesPlugin(pagesDir, {
722
+ root,
719
723
  viewTransitions: options?.viewTransitions,
720
724
  prefetch: options?.prefetch
721
725
  }),
722
- ...islandsPlugin(pagesDir)
726
+ ...islandsPlugin(pagesDir, { root })
723
727
  ];
724
728
  }
725
729
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@void/solid",
3
- "version": "0.7.13",
3
+ "version": "0.8.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/voidzero-dev/void.git",
@@ -43,12 +43,12 @@
43
43
  "solid-js": "^1.9.12",
44
44
  "vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
45
45
  "vite-plus": "^0.1.20",
46
- "void": "0.7.13"
46
+ "void": "0.8.1"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "solid-js": "^1.9.0",
50
50
  "vite": "^8.0.0",
51
- "void": "0.7.13"
51
+ "void": "0.8.1"
52
52
  },
53
53
  "scripts": {
54
54
  "build": "vp pack",