@solidjs/vite-plugin 3.0.0-next.38 → 3.0.0-next.39
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/esm/index.mjs
CHANGED
|
@@ -1078,29 +1078,50 @@ const HANDLER_ID$1 = 'virtual:solid-server-function-handler';
|
|
|
1078
1078
|
// (`vite build` then `vite build --ssr`) does not, so the client build
|
|
1079
1079
|
// persists its findings for the SSR build to merge (mirroring the plugin's
|
|
1080
1080
|
// dist/client/.vite/manifest.json convention).
|
|
1081
|
+
//
|
|
1082
|
+
// The file doubles as the build's statement of which server functions the
|
|
1083
|
+
// CLIENT can reach — every reference the client compile emitted, by wire id
|
|
1084
|
+
// — for build tooling that needs that set without re-deriving it from
|
|
1085
|
+
// compiled output (a static-site prerenderer checking that each reachable
|
|
1086
|
+
// function was captured, for example). Paths are root-relative, posix.
|
|
1081
1087
|
const PERSISTED_MANIFEST_PATH = '.vite/solid-server-functions.json';
|
|
1088
|
+
|
|
1089
|
+
/** The persisted manifest's on-disk shape (the array form is the pre-`functions` legacy). */
|
|
1090
|
+
|
|
1082
1091
|
function readPersistedManifest(root) {
|
|
1083
1092
|
const file = path.resolve(root, 'dist/client', PERSISTED_MANIFEST_PATH);
|
|
1084
1093
|
if (!existsSync(file)) return new Set();
|
|
1085
1094
|
try {
|
|
1086
|
-
const
|
|
1095
|
+
const parsed = JSON.parse(readFileSync(file, 'utf-8'));
|
|
1096
|
+
const entries = Array.isArray(parsed) ? parsed : parsed.modules;
|
|
1087
1097
|
return new Set(entries.map(entry => path.resolve(root, entry)).filter(entry => existsSync(entry)));
|
|
1088
1098
|
} catch {
|
|
1089
1099
|
return new Set();
|
|
1090
1100
|
}
|
|
1091
1101
|
}
|
|
1092
|
-
function writePersistedManifest(root, outDir, entries) {
|
|
1102
|
+
function writePersistedManifest(root, outDir, entries, functions) {
|
|
1093
1103
|
const file = path.resolve(root, outDir, PERSISTED_MANIFEST_PATH);
|
|
1094
1104
|
mkdirSync(path.dirname(file), {
|
|
1095
1105
|
recursive: true
|
|
1096
1106
|
});
|
|
1097
|
-
const relative =
|
|
1098
|
-
|
|
1107
|
+
const relative = entry => path.relative(root, entry).split(path.sep).join('/');
|
|
1108
|
+
const manifest = {
|
|
1109
|
+
modules: [...entries].map(relative),
|
|
1110
|
+
functions: [...functions].map(([id, record]) => ({
|
|
1111
|
+
id,
|
|
1112
|
+
name: record.name,
|
|
1113
|
+
module: relative(record.module)
|
|
1114
|
+
}))
|
|
1115
|
+
};
|
|
1116
|
+
writeFileSync(file, JSON.stringify(manifest, null, 2));
|
|
1099
1117
|
}
|
|
1100
1118
|
function createManifest() {
|
|
1101
1119
|
return {
|
|
1102
|
-
|
|
1103
|
-
|
|
1120
|
+
modules: {
|
|
1121
|
+
server: new Set(),
|
|
1122
|
+
client: new Set()
|
|
1123
|
+
},
|
|
1124
|
+
clientFunctions: new Map()
|
|
1104
1125
|
};
|
|
1105
1126
|
}
|
|
1106
1127
|
function createDeferredPromise() {
|
|
@@ -1308,13 +1329,13 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1308
1329
|
const hashIndex = new Map();
|
|
1309
1330
|
let hashIndexSize = -1;
|
|
1310
1331
|
function moduleForFunctionId(functionId) {
|
|
1311
|
-
if (manifest.server.size !== hashIndexSize) {
|
|
1332
|
+
if (manifest.modules.server.size !== hashIndexSize) {
|
|
1312
1333
|
hashIndex.clear();
|
|
1313
|
-
for (const entry of manifest.server) {
|
|
1334
|
+
for (const entry of manifest.modules.server) {
|
|
1314
1335
|
const relative = path.relative(root, entry).split(path.sep).join('/');
|
|
1315
1336
|
hashIndex.set(xxHash32(relative).toString(16), entry);
|
|
1316
1337
|
}
|
|
1317
|
-
hashIndexSize = manifest.server.size;
|
|
1338
|
+
hashIndexSize = manifest.modules.server.size;
|
|
1318
1339
|
}
|
|
1319
1340
|
return hashIndex.get(functionId.split('-')[1]);
|
|
1320
1341
|
}
|
|
@@ -1438,9 +1459,25 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1438
1459
|
sourceMap: !tsrx || !!internal.tsrxSourceMap
|
|
1439
1460
|
});
|
|
1440
1461
|
if (!result.valid) return null;
|
|
1462
|
+
|
|
1463
|
+
// The client compile is the authority on what the browser can dispatch:
|
|
1464
|
+
// record every reference it emitted, by wire id, for the persisted
|
|
1465
|
+
// manifest. A module is re-transformed on change, so its previous ids
|
|
1466
|
+
// are dropped first (a renamed function must not linger as reachable).
|
|
1467
|
+
if (mode === 'client') {
|
|
1468
|
+
for (const [functionId, record] of manifest.clientFunctions) {
|
|
1469
|
+
if (record.module === id) manifest.clientFunctions.delete(functionId);
|
|
1470
|
+
}
|
|
1471
|
+
for (const fn of result.functions) {
|
|
1472
|
+
manifest.clientFunctions.set(fn.id, {
|
|
1473
|
+
name: fn.name,
|
|
1474
|
+
module: id
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1441
1478
|
const preloader = preload[mode];
|
|
1442
1479
|
if (preloader) preloader.defer();
|
|
1443
|
-
invalidateModules(currentServer, mergeManifestRecord(manifest.server, new Set([id])), manifestId);
|
|
1480
|
+
invalidateModules(currentServer, mergeManifestRecord(manifest.modules.server, new Set([id])), manifestId);
|
|
1444
1481
|
return {
|
|
1445
1482
|
// Appended (not prepended) so the source map for the compiled module
|
|
1446
1483
|
// stays valid; imports hoist and the endpoint is only read at call time.
|
|
@@ -1488,7 +1525,7 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1488
1525
|
// build discovered so the server manifest registers them even when
|
|
1489
1526
|
// the SSR module graph never imports them.
|
|
1490
1527
|
for (const entry of readPersistedManifest(root)) {
|
|
1491
|
-
manifest.server.add(entry);
|
|
1528
|
+
manifest.modules.server.add(entry);
|
|
1492
1529
|
}
|
|
1493
1530
|
}
|
|
1494
1531
|
},
|
|
@@ -1503,7 +1540,7 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1503
1540
|
const consumer = ctx.environment?.config?.consumer;
|
|
1504
1541
|
const isClient = consumer ? consumer === 'client' : !isSsrBuild;
|
|
1505
1542
|
if (isBuild && isClient) {
|
|
1506
|
-
writePersistedManifest(root, outDir, manifest.server);
|
|
1543
|
+
writePersistedManifest(root, outDir, manifest.modules.server, manifest.clientFunctions);
|
|
1507
1544
|
}
|
|
1508
1545
|
}
|
|
1509
1546
|
}, {
|
|
@@ -1528,10 +1565,10 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1528
1565
|
// configs resolve before the client build has written the file,
|
|
1529
1566
|
// but this load runs once the SSR environment builds — after it.
|
|
1530
1567
|
for (const entry of readPersistedManifest(root)) {
|
|
1531
|
-
manifest.server.add(entry);
|
|
1568
|
+
manifest.modules.server.add(entry);
|
|
1532
1569
|
}
|
|
1533
1570
|
}
|
|
1534
|
-
const current = new Debouncer(() => [...manifest[mode]].map(entry => `import ${JSON.stringify(entry)};`).join('\n'));
|
|
1571
|
+
const current = new Debouncer(() => [...manifest.modules[mode]].map(entry => `import ${JSON.stringify(entry)};`).join('\n'));
|
|
1535
1572
|
preload[mode] = current;
|
|
1536
1573
|
const result = await current.promise.reference;
|
|
1537
1574
|
return result;
|