@void/svelte 0.21.2 → 0.21.4
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 +12 -35
- package/package.json +3 -3
- package/src/runtime/App.svelte +9 -1
package/dist/plugin.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import { generateComponentManifest, resolveEffectiveLayoutChain, resolvePagesDir
|
|
|
3
3
|
import { existsSync, readFileSync, readdirSync } from "node:fs";
|
|
4
4
|
import nodePath from "node:path";
|
|
5
5
|
import { normalizePath } from "vite";
|
|
6
|
-
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, extractCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
|
|
6
|
+
import { ISLANDS_CLIENT_ENTRY_ID, ISLANDS_RENDERER_ID, computePagesNeedingClientJS, editIslandSource, extractCssImports, findIslandImports, findStaticCssImports, needsIslandClientBundle, resolveSpecifier, rewriteCssImportForVirtualModule, watchPagesForRescan } from "void/pages-islands-plugin";
|
|
7
7
|
//#region ../../node_modules/.pnpm/pathslash@0.1.0/node_modules/pathslash/dist/index.mjs
|
|
8
8
|
const BACKSLASH_RE = /\\/g;
|
|
9
9
|
const isWindows = process.platform === "win32";
|
|
@@ -49,22 +49,6 @@ const COMPONENT_EXTENSIONS = [
|
|
|
49
49
|
".ts",
|
|
50
50
|
".js"
|
|
51
51
|
];
|
|
52
|
-
const ISLAND_IMPORT_RE = /import\s+([$_A-Za-z][$_\w]*)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*,?\s*\}/g;
|
|
53
|
-
function findIslandImports(code) {
|
|
54
|
-
const imports = [];
|
|
55
|
-
let match;
|
|
56
|
-
ISLAND_IMPORT_RE.lastIndex = 0;
|
|
57
|
-
while ((match = ISLAND_IMPORT_RE.exec(code)) !== null) {
|
|
58
|
-
const specifierRaw = match[2];
|
|
59
|
-
imports.push({
|
|
60
|
-
statement: match[0],
|
|
61
|
-
importName: match[1],
|
|
62
|
-
specifier: specifierRaw.slice(1, -1),
|
|
63
|
-
hydrate: match[3].slice(1, -1)
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
return imports;
|
|
67
|
-
}
|
|
68
52
|
/**
|
|
69
53
|
* Prefix for virtual island wrapper modules. Must NOT use the `\0` prefix
|
|
70
54
|
* because `@sveltejs/vite-plugin-svelte` skips `\0`-prefixed modules in
|
|
@@ -118,7 +102,7 @@ function islandsPlugin(pagesDir, options) {
|
|
|
118
102
|
const filePath = resolve(pagesDir, entry.filePath);
|
|
119
103
|
const code = readFileSync(filePath, "utf-8");
|
|
120
104
|
const importerDir = dirname(filePath);
|
|
121
|
-
for (const islandImport of findIslandImports(code)) {
|
|
105
|
+
for (const islandImport of findIslandImports(code, filePath)) {
|
|
122
106
|
const spec = islandImport.specifier;
|
|
123
107
|
const strategy = islandImport.hydrate;
|
|
124
108
|
const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
|
|
@@ -181,8 +165,8 @@ function islandsPlugin(pagesDir, options) {
|
|
|
181
165
|
handler(code, id) {
|
|
182
166
|
if (/import\s+\{[^}]*\buseForm\b/.test(code)) this.warn(`islands: useForm cannot be imported in island page '${id}'. Use useIslandForm instead.`);
|
|
183
167
|
const importerDir = dirname(id);
|
|
184
|
-
|
|
185
|
-
for (const islandImport of findIslandImports(code)) {
|
|
168
|
+
const edits = [];
|
|
169
|
+
for (const islandImport of findIslandImports(code, id)) {
|
|
186
170
|
const name = islandImport.importName;
|
|
187
171
|
const spec = islandImport.specifier;
|
|
188
172
|
const strategy = islandImport.hydrate;
|
|
@@ -198,12 +182,13 @@ function islandsPlugin(pagesDir, options) {
|
|
|
198
182
|
const islandId = absPath ? normalizePath(relative(root, absPath)).replace(/\.[^.]+$/, "") : spec;
|
|
199
183
|
const wrapperUrl = WRAPPER_PREFIX + encodeURIComponent(islandId) + ".svelte?src=" + encodeURIComponent(absPath || spec) + "&island=" + encodeURIComponent(islandId) + "&hydrate=" + encodeURIComponent(strategy);
|
|
200
184
|
const replacement = `import ${name} from ${JSON.stringify(wrapperUrl)}`;
|
|
201
|
-
|
|
185
|
+
edits.push({
|
|
186
|
+
start: islandImport.start,
|
|
187
|
+
end: islandImport.end,
|
|
188
|
+
text: replacement
|
|
189
|
+
});
|
|
202
190
|
}
|
|
203
|
-
if (
|
|
204
|
-
code: transformed,
|
|
205
|
-
map: null
|
|
206
|
-
};
|
|
191
|
+
if (edits.length > 0) return editIslandSource(code, edits);
|
|
207
192
|
}
|
|
208
193
|
},
|
|
209
194
|
config(_, env) {
|
|
@@ -329,15 +314,7 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
|
|
|
329
314
|
lines.push(`import ${JSON.stringify(file + "?island-style&index=" + styleIndex + "&lang." + lang)};`);
|
|
330
315
|
styleIndex++;
|
|
331
316
|
}
|
|
332
|
-
const
|
|
333
|
-
const cssImportRe = /^\s*import\b[^"']*["']([^"']+\.(?:css|scss|sass|less|styl|stylus|pcss|postcss))["']/gm;
|
|
334
|
-
let scriptMatch;
|
|
335
|
-
while ((scriptMatch = scriptRe.exec(content)) !== null) {
|
|
336
|
-
const scriptContent = scriptMatch[1];
|
|
337
|
-
let cssMatch;
|
|
338
|
-
cssImportRe.lastIndex = 0;
|
|
339
|
-
while ((cssMatch = cssImportRe.exec(scriptContent)) !== null) lines.push(rewriteCssImportForVirtualModule(cssMatch[0], cssMatch[1], file));
|
|
340
|
-
}
|
|
317
|
+
for (const item of findStaticCssImports(content, file)) lines.push(rewriteCssImportForVirtualModule(item.statement, item.specifier, file));
|
|
341
318
|
}
|
|
342
319
|
lines.push("const islands = {");
|
|
343
320
|
for (const [id, path] of uniqueIslands) lines.push(` ${JSON.stringify(id)}: () => import(${JSON.stringify(path)}),`);
|
|
@@ -542,7 +519,7 @@ const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
|
542
519
|
isLoading: (ref) => ref.loading,
|
|
543
520
|
applyUpdate(pageData, comp, layouts) {
|
|
544
521
|
propsStore.set(pageData.props);
|
|
545
|
-
sharedStore.
|
|
522
|
+
sharedStore.set(pageData.shared || {});
|
|
546
523
|
errorsStore.set(pageData.errors || {});
|
|
547
524
|
routeParams = pageData.params || {};
|
|
548
525
|
paramsStore.set(routeParams);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/svelte",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.4",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"svelte": "^5.57.0",
|
|
38
38
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
|
|
39
39
|
"vite-plus": "0.3.1",
|
|
40
|
-
"void": "0.21.
|
|
40
|
+
"void": "0.21.4"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"svelte": "^5.0.0",
|
|
44
44
|
"vite": "^8.0.0",
|
|
45
|
-
"void": "0.21.
|
|
45
|
+
"void": "0.21.4"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "vp pack",
|
package/src/runtime/App.svelte
CHANGED
|
@@ -31,6 +31,14 @@
|
|
|
31
31
|
let navigation = $state(init.navigation || idleNavigationState());
|
|
32
32
|
const router = createRouterFacade(init.router, () => routeUrl, () => params);
|
|
33
33
|
|
|
34
|
+
// Layouts can keep the object returned by useShared() across navigations.
|
|
35
|
+
function replaceShared(next) {
|
|
36
|
+
for (const key of Object.keys(shared)) {
|
|
37
|
+
delete shared[key];
|
|
38
|
+
}
|
|
39
|
+
Object.assign(shared, next || {});
|
|
40
|
+
}
|
|
41
|
+
|
|
34
42
|
// Capitalized alias for dynamic component rendering
|
|
35
43
|
let Page = $derived(currentPage);
|
|
36
44
|
|
|
@@ -57,7 +65,7 @@
|
|
|
57
65
|
init.stores.page.subscribe((v) => { currentPage = v; }),
|
|
58
66
|
init.stores.props.subscribe((v) => { currentPageProps = v; }),
|
|
59
67
|
init.stores.layouts.subscribe((v) => { currentLayouts = v; }),
|
|
60
|
-
init.stores.shared.subscribe(
|
|
68
|
+
init.stores.shared.subscribe(replaceShared),
|
|
61
69
|
init.stores.errors.subscribe((v) => { errors = v; }),
|
|
62
70
|
init.stores.params.subscribe((v) => { params = v; }),
|
|
63
71
|
init.stores.route.subscribe((v) => { routeUrl = v; }),
|