@void/solid 0.21.1 → 0.21.3
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 +24 -37
- package/package.json +3 -3
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";
|
|
@@ -50,22 +50,6 @@ const COMPONENT_EXTENSIONS = [
|
|
|
50
50
|
".ts",
|
|
51
51
|
".js"
|
|
52
52
|
];
|
|
53
|
-
const ISLAND_IMPORT_RE = /import\s+([$_A-Za-z][$_\w]*)\s+from\s+("[^"]+"|'[^']+')\s+with\s*\{\s*island\s*:\s*("[^"]+"|'[^']+')\s*,?\s*\}/g;
|
|
54
|
-
function findIslandImports(code) {
|
|
55
|
-
const imports = [];
|
|
56
|
-
let match;
|
|
57
|
-
ISLAND_IMPORT_RE.lastIndex = 0;
|
|
58
|
-
while ((match = ISLAND_IMPORT_RE.exec(code)) !== null) {
|
|
59
|
-
const specifierRaw = match[2];
|
|
60
|
-
imports.push({
|
|
61
|
-
statement: match[0],
|
|
62
|
-
importName: match[1],
|
|
63
|
-
specifier: specifierRaw.slice(1, -1),
|
|
64
|
-
hydrate: match[3].slice(1, -1)
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
return imports;
|
|
68
|
-
}
|
|
69
53
|
/**
|
|
70
54
|
* Prefix for virtual island wrapper modules. Must NOT use the `\0` prefix
|
|
71
55
|
* because `vite-plugin-solid` skips `\0`-prefixed modules in its transform
|
|
@@ -122,7 +106,7 @@ function islandsPlugin(pagesDir, options) {
|
|
|
122
106
|
const filePath = resolve(pagesDir, entry.filePath);
|
|
123
107
|
const code = readFileSync(filePath, "utf-8");
|
|
124
108
|
const importerDir = dirname(filePath);
|
|
125
|
-
for (const islandImport of findIslandImports(code)) {
|
|
109
|
+
for (const islandImport of findIslandImports(code, filePath)) {
|
|
126
110
|
const spec = islandImport.specifier;
|
|
127
111
|
const strategy = islandImport.hydrate;
|
|
128
112
|
const absPath = resolveSpecifier(spec, importerDir, COMPONENT_EXTENSIONS);
|
|
@@ -188,8 +172,8 @@ function islandsPlugin(pagesDir, options) {
|
|
|
188
172
|
handler(code, id) {
|
|
189
173
|
if (/import\s+\{[^}]*\buseForm\b/.test(code)) this.warn(`islands: useForm cannot be imported in island page '${id}'. Use useIslandForm instead.`);
|
|
190
174
|
const importerDir = dirname(id);
|
|
191
|
-
|
|
192
|
-
for (const islandImport of findIslandImports(code)) {
|
|
175
|
+
const edits = [];
|
|
176
|
+
for (const islandImport of findIslandImports(code, id)) {
|
|
193
177
|
const name = islandImport.importName;
|
|
194
178
|
const spec = islandImport.specifier;
|
|
195
179
|
const strategy = islandImport.hydrate;
|
|
@@ -210,12 +194,13 @@ function islandsPlugin(pagesDir, options) {
|
|
|
210
194
|
hydrate: strategy
|
|
211
195
|
});
|
|
212
196
|
const replacement = `import ${name} from ${JSON.stringify(wrapperUrl)}`;
|
|
213
|
-
|
|
197
|
+
edits.push({
|
|
198
|
+
start: islandImport.start,
|
|
199
|
+
end: islandImport.end,
|
|
200
|
+
text: replacement
|
|
201
|
+
});
|
|
214
202
|
}
|
|
215
|
-
if (
|
|
216
|
-
code: transformed,
|
|
217
|
-
map: null
|
|
218
|
-
};
|
|
203
|
+
if (edits.length > 0) return editIslandSource(code, edits);
|
|
219
204
|
}
|
|
220
205
|
},
|
|
221
206
|
config(_, env) {
|
|
@@ -313,14 +298,9 @@ function generateIslandClientEntry(manifest, cssFiles, isDev) {
|
|
|
313
298
|
for (const entry of entries) uniqueIslands.set(entry.islandId, entry.componentPath);
|
|
314
299
|
const lines = [];
|
|
315
300
|
lines.push("import { initIslands } from \"void/pages-client\";");
|
|
316
|
-
if (!isDev) {
|
|
317
|
-
const
|
|
318
|
-
for (const
|
|
319
|
-
const content = readFileSync(file, "utf-8");
|
|
320
|
-
cssImportRe.lastIndex = 0;
|
|
321
|
-
let match;
|
|
322
|
-
while ((match = cssImportRe.exec(content)) !== null) lines.push(rewriteCssImportForVirtualModule(match[0], match[1], file));
|
|
323
|
-
}
|
|
301
|
+
if (!isDev) for (const file of cssFiles) {
|
|
302
|
+
const content = readFileSync(file, "utf-8");
|
|
303
|
+
for (const item of findStaticCssImports(content, file)) lines.push(rewriteCssImportForVirtualModule(item.statement, item.specifier, file));
|
|
324
304
|
}
|
|
325
305
|
lines.push("const islands = {");
|
|
326
306
|
for (const [id, path] of uniqueIslands) lines.push(` ${JSON.stringify(id)}: () => import(${JSON.stringify(path)}),`);
|
|
@@ -519,6 +499,7 @@ export async function renderPage(pageObj, assetTags) {
|
|
|
519
499
|
function generateClientEntry(scan, pagesDir, viewTransitions, prefetch, staticPageData) {
|
|
520
500
|
return `
|
|
521
501
|
import { createSignal, createComponent, batch } from "solid-js";
|
|
502
|
+
import { createMutable } from "solid-js/store";
|
|
522
503
|
import { hydrate, render } from "solid-js/web";
|
|
523
504
|
import { SharedContext, ErrorsContext, ParamsContext, RouterContext, NavigationContext, setActionRouter } from "@void/solid";
|
|
524
505
|
import { createRouterFacade, createVoidRouter, idleNavigationState } from "void/pages-client";
|
|
@@ -529,12 +510,18 @@ ${generateComponentManifest(scan, pagesDir)}
|
|
|
529
510
|
const [component, setComponent] = createSignal(null);
|
|
530
511
|
const [pageProps, setPageProps] = createSignal({});
|
|
531
512
|
const [layouts, setLayouts] = createSignal([]);
|
|
532
|
-
const
|
|
513
|
+
const shared = createMutable({});
|
|
533
514
|
const [errors, setErrors] = createSignal({});
|
|
534
515
|
const [routeUrl, setRouteUrl] = createSignal(window.location.pathname + window.location.search + window.location.hash);
|
|
535
516
|
const [routeParams, setRouteParams] = createSignal({});
|
|
536
517
|
const [navigation, setNavigation] = createSignal(idleNavigationState());
|
|
537
518
|
|
|
519
|
+
// Keep the context object stable for layouts that call useShared() once.
|
|
520
|
+
function replaceShared(next) {
|
|
521
|
+
for (const key of Object.keys(shared)) delete shared[key];
|
|
522
|
+
Object.assign(shared, next || {});
|
|
523
|
+
}
|
|
524
|
+
|
|
538
525
|
const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
539
526
|
await createVoidRouter({
|
|
540
527
|
adapter: {
|
|
@@ -547,7 +534,7 @@ const { router, initialPageData, initialComponent, initialLayouts, start } =
|
|
|
547
534
|
setPageProps(pageData.props);
|
|
548
535
|
setComponent(() => comp);
|
|
549
536
|
setLayouts(layoutComps);
|
|
550
|
-
|
|
537
|
+
replaceShared(pageData.shared);
|
|
551
538
|
setErrors(pageData.errors || {});
|
|
552
539
|
setRouteParams(pageData.params || {});
|
|
553
540
|
});
|
|
@@ -578,14 +565,14 @@ batch(() => {
|
|
|
578
565
|
setComponent(() => initialComponent);
|
|
579
566
|
setPageProps(initialPageData.props);
|
|
580
567
|
setLayouts(initialLayouts);
|
|
581
|
-
|
|
568
|
+
replaceShared(initialPageData.shared);
|
|
582
569
|
setErrors(initialPageData.errors || {});
|
|
583
570
|
setRouteParams(initialPageData.params || {});
|
|
584
571
|
});
|
|
585
572
|
|
|
586
573
|
function App() {
|
|
587
574
|
return createComponent(SharedContext.Provider, {
|
|
588
|
-
|
|
575
|
+
value: shared,
|
|
589
576
|
get children() {
|
|
590
577
|
return createComponent(ErrorsContext.Provider, {
|
|
591
578
|
value: errors,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/solid",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"solid-js": "^1.9.15",
|
|
34
34
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.1",
|
|
35
35
|
"vite-plus": "0.3.1",
|
|
36
|
-
"void": "0.21.
|
|
36
|
+
"void": "0.21.3"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
39
|
"solid-js": "^1.9.0",
|
|
40
40
|
"vite": "^8.0.0",
|
|
41
|
-
"void": "0.21.
|
|
41
|
+
"void": "0.21.3"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "vp pack",
|