@void/svelte 0.7.13 → 0.8.0
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 +42 -42
- 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,
|
|
@@ -468,11 +435,28 @@ function pagesPlugin(pagesDir, options) {
|
|
|
468
435
|
let pageScan = null;
|
|
469
436
|
let isDev = false;
|
|
470
437
|
let viteConfig;
|
|
471
|
-
const root = dirname(pagesDir);
|
|
438
|
+
const root = options?.root ?? dirname(pagesDir);
|
|
439
|
+
const normalizedPagesDir = normalizePath(pagesDir);
|
|
440
|
+
let pendingRescan = null;
|
|
441
|
+
const rescanPages = async () => {
|
|
442
|
+
pageScan = existsSync(pagesDir) ? await scanPages(root, { pagesDir }) : null;
|
|
443
|
+
};
|
|
444
|
+
const runRescan = () => {
|
|
445
|
+
pendingRescan ??= rescanPages().finally(() => {
|
|
446
|
+
pendingRescan = null;
|
|
447
|
+
});
|
|
448
|
+
return pendingRescan;
|
|
449
|
+
};
|
|
450
|
+
const invalidatePageModules = (server) => {
|
|
451
|
+
for (const env of Object.values(server.environments)) for (const id of ["\0" + RENDERER_ID, "\0" + CLIENT_ENTRY_ID]) {
|
|
452
|
+
const mod = env.moduleGraph.getModuleById(id);
|
|
453
|
+
if (mod) env.moduleGraph.invalidateModule(mod);
|
|
454
|
+
}
|
|
455
|
+
};
|
|
472
456
|
return {
|
|
473
457
|
name: "void-svelte:pages",
|
|
474
458
|
async buildStart() {
|
|
475
|
-
|
|
459
|
+
await runRescan();
|
|
476
460
|
},
|
|
477
461
|
resolveId: {
|
|
478
462
|
filter: { id: /^virtual:void-pages-(renderer|client)$/ },
|
|
@@ -482,7 +466,9 @@ function pagesPlugin(pagesDir, options) {
|
|
|
482
466
|
},
|
|
483
467
|
load: {
|
|
484
468
|
filter: { id: /^\0virtual:void-pages-(renderer|client)$/ },
|
|
485
|
-
handler(id) {
|
|
469
|
+
async handler(id) {
|
|
470
|
+
if (isDev && pendingRescan) await pendingRescan;
|
|
471
|
+
if (!pageScan && existsSync(pagesDir)) await runRescan();
|
|
486
472
|
if (id === "\0" + RENDERER_ID) {
|
|
487
473
|
if (!pageScan) return "export function renderPage() { throw new Error('No pages found'); }";
|
|
488
474
|
return generateRendererModule(pageScan, pagesDir, isDev);
|
|
@@ -493,6 +479,18 @@ function pagesPlugin(pagesDir, options) {
|
|
|
493
479
|
}
|
|
494
480
|
}
|
|
495
481
|
},
|
|
482
|
+
configureServer(server) {
|
|
483
|
+
const handlePagesChange = async (path, event) => {
|
|
484
|
+
const normalizedPath = normalizePath(path);
|
|
485
|
+
if (normalizedPath !== normalizedPagesDir && !normalizedPath.startsWith(normalizedPagesDir + "/")) return;
|
|
486
|
+
if (event === "change" && !normalizedPath.endsWith(".md")) return;
|
|
487
|
+
await runRescan();
|
|
488
|
+
invalidatePageModules(server);
|
|
489
|
+
};
|
|
490
|
+
server.watcher.on("add", (path) => handlePagesChange(path, "add"));
|
|
491
|
+
server.watcher.on("change", (path) => handlePagesChange(path, "change"));
|
|
492
|
+
server.watcher.on("unlink", (path) => handlePagesChange(path, "unlink"));
|
|
493
|
+
},
|
|
496
494
|
configResolved(config) {
|
|
497
495
|
viteConfig = config;
|
|
498
496
|
},
|
|
@@ -670,14 +668,16 @@ start();
|
|
|
670
668
|
//#endregion
|
|
671
669
|
//#region src/plugin.ts
|
|
672
670
|
function voidSvelte(options) {
|
|
673
|
-
const
|
|
671
|
+
const root = process.cwd();
|
|
672
|
+
const pagesDir = resolvePagesDir(root);
|
|
674
673
|
return [
|
|
675
674
|
...svelte(options?.svelte),
|
|
676
675
|
pagesPlugin(pagesDir, {
|
|
676
|
+
root,
|
|
677
677
|
viewTransitions: options?.viewTransitions,
|
|
678
678
|
prefetch: options?.prefetch
|
|
679
679
|
}),
|
|
680
|
-
...islandsPlugin(pagesDir)
|
|
680
|
+
...islandsPlugin(pagesDir, { root })
|
|
681
681
|
];
|
|
682
682
|
}
|
|
683
683
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
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.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"svelte": "^5.0.0",
|
|
51
51
|
"vite": "^8.0.0",
|
|
52
|
-
"void": "0.
|
|
52
|
+
"void": "0.8.0"
|
|
53
53
|
},
|
|
54
54
|
"scripts": {
|
|
55
55
|
"build": "vp pack",
|