@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.
@@ -1102,29 +1102,50 @@ const HANDLER_ID$1 = 'virtual:solid-server-function-handler';
1102
1102
  // (`vite build` then `vite build --ssr`) does not, so the client build
1103
1103
  // persists its findings for the SSR build to merge (mirroring the plugin's
1104
1104
  // dist/client/.vite/manifest.json convention).
1105
+ //
1106
+ // The file doubles as the build's statement of which server functions the
1107
+ // CLIENT can reach — every reference the client compile emitted, by wire id
1108
+ // — for build tooling that needs that set without re-deriving it from
1109
+ // compiled output (a static-site prerenderer checking that each reachable
1110
+ // function was captured, for example). Paths are root-relative, posix.
1105
1111
  const PERSISTED_MANIFEST_PATH = '.vite/solid-server-functions.json';
1112
+
1113
+ /** The persisted manifest's on-disk shape (the array form is the pre-`functions` legacy). */
1114
+
1106
1115
  function readPersistedManifest(root) {
1107
1116
  const file = path.resolve(root, 'dist/client', PERSISTED_MANIFEST_PATH);
1108
1117
  if (!fs.existsSync(file)) return new Set();
1109
1118
  try {
1110
- const entries = JSON.parse(fs.readFileSync(file, 'utf-8'));
1119
+ const parsed = JSON.parse(fs.readFileSync(file, 'utf-8'));
1120
+ const entries = Array.isArray(parsed) ? parsed : parsed.modules;
1111
1121
  return new Set(entries.map(entry => path.resolve(root, entry)).filter(entry => fs.existsSync(entry)));
1112
1122
  } catch {
1113
1123
  return new Set();
1114
1124
  }
1115
1125
  }
1116
- function writePersistedManifest(root, outDir, entries) {
1126
+ function writePersistedManifest(root, outDir, entries, functions) {
1117
1127
  const file = path.resolve(root, outDir, PERSISTED_MANIFEST_PATH);
1118
1128
  fs.mkdirSync(path.dirname(file), {
1119
1129
  recursive: true
1120
1130
  });
1121
- const relative = [...entries].map(entry => path.relative(root, entry).split(path.sep).join('/'));
1122
- fs.writeFileSync(file, JSON.stringify(relative, null, 2));
1131
+ const relative = entry => path.relative(root, entry).split(path.sep).join('/');
1132
+ const manifest = {
1133
+ modules: [...entries].map(relative),
1134
+ functions: [...functions].map(([id, record]) => ({
1135
+ id,
1136
+ name: record.name,
1137
+ module: relative(record.module)
1138
+ }))
1139
+ };
1140
+ fs.writeFileSync(file, JSON.stringify(manifest, null, 2));
1123
1141
  }
1124
1142
  function createManifest() {
1125
1143
  return {
1126
- server: new Set(),
1127
- client: new Set()
1144
+ modules: {
1145
+ server: new Set(),
1146
+ client: new Set()
1147
+ },
1148
+ clientFunctions: new Map()
1128
1149
  };
1129
1150
  }
1130
1151
  function createDeferredPromise() {
@@ -1332,13 +1353,13 @@ function serverFunctions(options = {}, internal = {}) {
1332
1353
  const hashIndex = new Map();
1333
1354
  let hashIndexSize = -1;
1334
1355
  function moduleForFunctionId(functionId) {
1335
- if (manifest.server.size !== hashIndexSize) {
1356
+ if (manifest.modules.server.size !== hashIndexSize) {
1336
1357
  hashIndex.clear();
1337
- for (const entry of manifest.server) {
1358
+ for (const entry of manifest.modules.server) {
1338
1359
  const relative = path.relative(root, entry).split(path.sep).join('/');
1339
1360
  hashIndex.set(xxHash32(relative).toString(16), entry);
1340
1361
  }
1341
- hashIndexSize = manifest.server.size;
1362
+ hashIndexSize = manifest.modules.server.size;
1342
1363
  }
1343
1364
  return hashIndex.get(functionId.split('-')[1]);
1344
1365
  }
@@ -1462,9 +1483,25 @@ function serverFunctions(options = {}, internal = {}) {
1462
1483
  sourceMap: !tsrx || !!internal.tsrxSourceMap
1463
1484
  });
1464
1485
  if (!result.valid) return null;
1486
+
1487
+ // The client compile is the authority on what the browser can dispatch:
1488
+ // record every reference it emitted, by wire id, for the persisted
1489
+ // manifest. A module is re-transformed on change, so its previous ids
1490
+ // are dropped first (a renamed function must not linger as reachable).
1491
+ if (mode === 'client') {
1492
+ for (const [functionId, record] of manifest.clientFunctions) {
1493
+ if (record.module === id) manifest.clientFunctions.delete(functionId);
1494
+ }
1495
+ for (const fn of result.functions) {
1496
+ manifest.clientFunctions.set(fn.id, {
1497
+ name: fn.name,
1498
+ module: id
1499
+ });
1500
+ }
1501
+ }
1465
1502
  const preloader = preload[mode];
1466
1503
  if (preloader) preloader.defer();
1467
- invalidateModules(currentServer, mergeManifestRecord(manifest.server, new Set([id])), manifestId);
1504
+ invalidateModules(currentServer, mergeManifestRecord(manifest.modules.server, new Set([id])), manifestId);
1468
1505
  return {
1469
1506
  // Appended (not prepended) so the source map for the compiled module
1470
1507
  // stays valid; imports hoist and the endpoint is only read at call time.
@@ -1512,7 +1549,7 @@ function serverFunctions(options = {}, internal = {}) {
1512
1549
  // build discovered so the server manifest registers them even when
1513
1550
  // the SSR module graph never imports them.
1514
1551
  for (const entry of readPersistedManifest(root)) {
1515
- manifest.server.add(entry);
1552
+ manifest.modules.server.add(entry);
1516
1553
  }
1517
1554
  }
1518
1555
  },
@@ -1527,7 +1564,7 @@ function serverFunctions(options = {}, internal = {}) {
1527
1564
  const consumer = ctx.environment?.config?.consumer;
1528
1565
  const isClient = consumer ? consumer === 'client' : !isSsrBuild;
1529
1566
  if (isBuild && isClient) {
1530
- writePersistedManifest(root, outDir, manifest.server);
1567
+ writePersistedManifest(root, outDir, manifest.modules.server, manifest.clientFunctions);
1531
1568
  }
1532
1569
  }
1533
1570
  }, {
@@ -1552,10 +1589,10 @@ function serverFunctions(options = {}, internal = {}) {
1552
1589
  // configs resolve before the client build has written the file,
1553
1590
  // but this load runs once the SSR environment builds — after it.
1554
1591
  for (const entry of readPersistedManifest(root)) {
1555
- manifest.server.add(entry);
1592
+ manifest.modules.server.add(entry);
1556
1593
  }
1557
1594
  }
1558
- const current = new Debouncer(() => [...manifest[mode]].map(entry => `import ${JSON.stringify(entry)};`).join('\n'));
1595
+ const current = new Debouncer(() => [...manifest.modules[mode]].map(entry => `import ${JSON.stringify(entry)};`).join('\n'));
1559
1596
  preload[mode] = current;
1560
1597
  const result = await current.promise.reference;
1561
1598
  return result;