@void/svelte 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.
- package/dist/plugin.mjs +55 -51
- package/package.json +3 -3
package/dist/plugin.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
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 "/";
|
|
@@ -162,9 +129,9 @@ function findIslandImports(code) {
|
|
|
162
129
|
* its transform filter.
|
|
163
130
|
*/
|
|
164
131
|
const WRAPPER_PREFIX = "/@void-island-wrap/";
|
|
165
|
-
function islandsPlugin(pagesDir) {
|
|
132
|
+
function islandsPlugin(pagesDir, options) {
|
|
166
133
|
let pageScan = null;
|
|
167
|
-
const root = dirname(pagesDir);
|
|
134
|
+
const root = options?.root ?? dirname(pagesDir);
|
|
168
135
|
const islandManifest = /* @__PURE__ */ new Map();
|
|
169
136
|
const islandCssFiles = /* @__PURE__ */ new Set();
|
|
170
137
|
let isDev = false;
|
|
@@ -189,7 +156,7 @@ function islandsPlugin(pagesDir) {
|
|
|
189
156
|
},
|
|
190
157
|
async buildStart() {
|
|
191
158
|
if (existsSync(pagesDir)) {
|
|
192
|
-
pageScan = await scanPages(root);
|
|
159
|
+
pageScan = await scanPages(root, { pagesDir });
|
|
193
160
|
const filesToScan = [
|
|
194
161
|
...pageScan.pages.map((page) => ({
|
|
195
162
|
filePath: page.componentPath,
|
|
@@ -449,6 +416,15 @@ initIslands(islands, hydrateIsland);
|
|
|
449
416
|
//#region src/plugin-pages.ts
|
|
450
417
|
const RENDERER_ID = "virtual:void-pages-renderer";
|
|
451
418
|
const CLIENT_ENTRY_ID = "virtual:void-pages-client";
|
|
419
|
+
const SVELTE_OPTIMIZE_DEPS = {
|
|
420
|
+
exclude: ["@void/svelte"],
|
|
421
|
+
include: [
|
|
422
|
+
"svelte",
|
|
423
|
+
"svelte/store",
|
|
424
|
+
"svelte/internal",
|
|
425
|
+
"svelte/internal/client"
|
|
426
|
+
]
|
|
427
|
+
};
|
|
452
428
|
/** Check if the pages directory has any non-island Svelte page files. */
|
|
453
429
|
function hasNonIslandPages(dir) {
|
|
454
430
|
try {
|
|
@@ -468,11 +444,28 @@ function pagesPlugin(pagesDir, options) {
|
|
|
468
444
|
let pageScan = null;
|
|
469
445
|
let isDev = false;
|
|
470
446
|
let viteConfig;
|
|
471
|
-
const root = dirname(pagesDir);
|
|
447
|
+
const root = options?.root ?? dirname(pagesDir);
|
|
448
|
+
const normalizedPagesDir = normalizePath(pagesDir);
|
|
449
|
+
let pendingRescan = null;
|
|
450
|
+
const rescanPages = async () => {
|
|
451
|
+
pageScan = existsSync(pagesDir) ? await scanPages(root, { pagesDir }) : null;
|
|
452
|
+
};
|
|
453
|
+
const runRescan = () => {
|
|
454
|
+
pendingRescan ??= rescanPages().finally(() => {
|
|
455
|
+
pendingRescan = null;
|
|
456
|
+
});
|
|
457
|
+
return pendingRescan;
|
|
458
|
+
};
|
|
459
|
+
const invalidatePageModules = (server) => {
|
|
460
|
+
for (const env of Object.values(server.environments)) for (const id of ["\0" + RENDERER_ID, "\0" + CLIENT_ENTRY_ID]) {
|
|
461
|
+
const mod = env.moduleGraph.getModuleById(id);
|
|
462
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
463
|
+
}
|
|
464
|
+
};
|
|
472
465
|
return {
|
|
473
466
|
name: "void-svelte:pages",
|
|
474
467
|
async buildStart() {
|
|
475
|
-
|
|
468
|
+
await runRescan();
|
|
476
469
|
},
|
|
477
470
|
resolveId: {
|
|
478
471
|
filter: { id: /^virtual:void-pages-(renderer|client)$/ },
|
|
@@ -482,7 +475,9 @@ function pagesPlugin(pagesDir, options) {
|
|
|
482
475
|
},
|
|
483
476
|
load: {
|
|
484
477
|
filter: { id: /^\0virtual:void-pages-(renderer|client)$/ },
|
|
485
|
-
handler(id) {
|
|
478
|
+
async handler(id) {
|
|
479
|
+
if (isDev && pendingRescan) await pendingRescan;
|
|
480
|
+
if (!pageScan && existsSync(pagesDir)) await runRescan();
|
|
486
481
|
if (id === "\0" + RENDERER_ID) {
|
|
487
482
|
if (!pageScan) return "export function renderPage() { throw new Error('No pages found'); }";
|
|
488
483
|
return generateRendererModule(pageScan, pagesDir, isDev);
|
|
@@ -493,6 +488,18 @@ function pagesPlugin(pagesDir, options) {
|
|
|
493
488
|
}
|
|
494
489
|
}
|
|
495
490
|
},
|
|
491
|
+
configureServer(server) {
|
|
492
|
+
const handlePagesChange = async (path, event) => {
|
|
493
|
+
const normalizedPath = normalizePath(path);
|
|
494
|
+
if (normalizedPath !== normalizedPagesDir && !normalizedPath.startsWith(normalizedPagesDir + "/")) return;
|
|
495
|
+
if (event === "change" && !normalizedPath.endsWith(".md")) return;
|
|
496
|
+
await runRescan();
|
|
497
|
+
invalidatePageModules(server);
|
|
498
|
+
};
|
|
499
|
+
server.watcher.on("add", (path) => handlePagesChange(path, "add"));
|
|
500
|
+
server.watcher.on("change", (path) => handlePagesChange(path, "change"));
|
|
501
|
+
server.watcher.on("unlink", (path) => handlePagesChange(path, "unlink"));
|
|
502
|
+
},
|
|
496
503
|
configResolved(config) {
|
|
497
504
|
viteConfig = config;
|
|
498
505
|
},
|
|
@@ -500,15 +507,10 @@ function pagesPlugin(pagesDir, options) {
|
|
|
500
507
|
if (!existsSync(pagesDir)) return;
|
|
501
508
|
if (env.command === "serve") {
|
|
502
509
|
isDev = true;
|
|
503
|
-
return {
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
"svelte/store",
|
|
508
|
-
"svelte/internal",
|
|
509
|
-
"svelte/internal/client"
|
|
510
|
-
]
|
|
511
|
-
} };
|
|
510
|
+
return {
|
|
511
|
+
optimizeDeps: SVELTE_OPTIMIZE_DEPS,
|
|
512
|
+
environments: { void_worker: { optimizeDeps: { exclude: ["@void/svelte"] } } }
|
|
513
|
+
};
|
|
512
514
|
}
|
|
513
515
|
if (!hasNonIslandPages(pagesDir)) return;
|
|
514
516
|
return { build: {
|
|
@@ -670,14 +672,16 @@ start();
|
|
|
670
672
|
//#endregion
|
|
671
673
|
//#region src/plugin.ts
|
|
672
674
|
function voidSvelte(options) {
|
|
673
|
-
const
|
|
675
|
+
const root = process.cwd();
|
|
676
|
+
const pagesDir = resolvePagesDir(root);
|
|
674
677
|
return [
|
|
675
678
|
...svelte(options?.svelte),
|
|
676
679
|
pagesPlugin(pagesDir, {
|
|
680
|
+
root,
|
|
677
681
|
viewTransitions: options?.viewTransitions,
|
|
678
682
|
prefetch: options?.prefetch
|
|
679
683
|
}),
|
|
680
|
-
...islandsPlugin(pagesDir)
|
|
684
|
+
...islandsPlugin(pagesDir, { root })
|
|
681
685
|
];
|
|
682
686
|
}
|
|
683
687
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"svelte": "^5.55.5",
|
|
45
45
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.1.20",
|
|
46
46
|
"vite-plus": "^0.1.20",
|
|
47
|
-
"void": "0.
|
|
47
|
+
"void": "0.8.1"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"svelte": "^5.0.0",
|
|
51
51
|
"vite": "^8.0.0",
|
|
52
|
-
"void": "0.
|
|
52
|
+
"void": "0.8.1"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vp pack",
|