@solidjs/vite-plugin 3.0.0-next.39 → 3.0.0-next.40
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/README.md +67 -2
- package/dist/cjs/index.cjs +341 -37
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/esm/index.mjs +342 -38
- package/dist/esm/index.mjs.map +1 -1
- package/dist/types/src/ssr/index.d.ts +37 -0
- package/package.json +3 -3
- package/virtual-solid-manifest.d.ts +10 -0
package/dist/esm/index.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import * as babel from '@babel/core';
|
|
2
2
|
import remapping from '@ampproject/remapping';
|
|
3
3
|
import solid from '@solidjs/babel-plugin';
|
|
4
|
-
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, rmSync } from 'fs';
|
|
4
|
+
import fs, { existsSync, readFileSync, mkdirSync, writeFileSync, rmSync, realpathSync } from 'fs';
|
|
5
5
|
import { mergeAndConcat } from 'merge-anything';
|
|
6
6
|
import { createRequire } from 'module';
|
|
7
7
|
import path from 'path';
|
|
8
8
|
import { Readable } from 'node:stream';
|
|
9
|
+
import { randomBytes } from 'crypto';
|
|
9
10
|
import { createFilter, normalizePath, loadEnv, runnerImport, transformWithOxc, defaultClientConditions, defaultServerConditions, defaultExternalConditions } from 'vite';
|
|
10
11
|
import { pathToFileURL, fileURLToPath } from 'node:url';
|
|
11
12
|
import { crawlFrameworkPkgs } from 'vitefu';
|
|
@@ -733,6 +734,22 @@ function solidDiagnostics(mode = 'auto') {
|
|
|
733
734
|
apply(_config, env) {
|
|
734
735
|
return env.command === 'serve' && !env.isPreview && env.mode !== 'test';
|
|
735
736
|
},
|
|
737
|
+
// The bridge module is virtual and reaches the page behind the
|
|
738
|
+
// scanner's back (a script injected into index.html at transform time,
|
|
739
|
+
// or an import the generated start entry adds), so the optimizer never
|
|
740
|
+
// sees its two package imports up front. Pre-bundle them: otherwise the
|
|
741
|
+
// first page load discovers them, re-optimizes and full-reloads — a
|
|
742
|
+
// flash at best, and a broken page whenever anything else on the page
|
|
743
|
+
// was resolved against the first optimizer pass.
|
|
744
|
+
config(userConfig) {
|
|
745
|
+
const rootDir = path.resolve(userConfig.root || process.cwd());
|
|
746
|
+
if (mode !== true && !detectDiagnosticsPackage(rootDir)) return;
|
|
747
|
+
return {
|
|
748
|
+
optimizeDeps: {
|
|
749
|
+
include: [`${DIAGNOSTICS_PACKAGE}/browser`, `${DIAGNOSTICS_PACKAGE}/protocol`]
|
|
750
|
+
}
|
|
751
|
+
};
|
|
752
|
+
},
|
|
736
753
|
configResolved(config) {
|
|
737
754
|
root = config.root;
|
|
738
755
|
base = config.base;
|
|
@@ -1229,6 +1246,23 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1229
1246
|
client: undefined
|
|
1230
1247
|
};
|
|
1231
1248
|
let currentServer;
|
|
1249
|
+
|
|
1250
|
+
// THE DEPLOYMENT SECRET (solidjs/solid#3239): the runtime's flash cookie
|
|
1251
|
+
// — the no-JS form outcome — carries the submitted input, so it is
|
|
1252
|
+
// AES-GCM encrypted under a key derived from a deployment-wide secret,
|
|
1253
|
+
// and without one the outcome is withheld entirely. This plugin provides
|
|
1254
|
+
// that secret with zero configuration through the internal
|
|
1255
|
+
// `globalThis.__SOLID_SECRET__ ??=` contract: generated once per plugin
|
|
1256
|
+
// instance, so a production build bakes one value into the emitted server
|
|
1257
|
+
// chunk — every instance of that deployment shares it (a per-process
|
|
1258
|
+
// value would silently lose flashes behind a load balancer) — and a dev
|
|
1259
|
+
// session holds one for its lifetime (a restart invalidates in-flight
|
|
1260
|
+
// flashes, which are 60-second one-shot cookies; the next render just
|
|
1261
|
+
// reads "no flash"). Server output only, never the client graph. The
|
|
1262
|
+
// `??=` keeps an explicit `configureServerFunctionsServer({ secret })` —
|
|
1263
|
+
// or a value injected by an outer harness — authoritative.
|
|
1264
|
+
const deploymentSecret = randomBytes(32).toString('hex');
|
|
1265
|
+
const deploymentSecretSnippet = `globalThis.__SOLID_SECRET__ ??= ${JSON.stringify(deploymentSecret)};`;
|
|
1232
1266
|
const clientOptions = {
|
|
1233
1267
|
directive,
|
|
1234
1268
|
definitions: {
|
|
@@ -1288,6 +1322,14 @@ function serverFunctions(options = {}, internal = {}) {
|
|
|
1288
1322
|
// import is only emitted when the option is on, so disabled setups keep
|
|
1289
1323
|
// a server-component-free graph.
|
|
1290
1324
|
return [
|
|
1325
|
+
// The deployment secret. Imports are hoisted above it, but nothing
|
|
1326
|
+
// reads the global at module evaluation — the runtime resolves it
|
|
1327
|
+
// lazily per encode/decode — so leading textually is just the honest
|
|
1328
|
+
// placement. This module is loaded before any dispatch on both
|
|
1329
|
+
// surfaces, and the generated SSR handler imports it at module load,
|
|
1330
|
+
// so the secret is in place for the flash's encode (the form POST)
|
|
1331
|
+
// and its decode (the render that follows the redirect) alike.
|
|
1332
|
+
deploymentSecretSnippet,
|
|
1291
1333
|
// The user's `configure` module comes first: a side-effect import in
|
|
1292
1334
|
// the handler graph, evaluated before any dispatch on both surfaces
|
|
1293
1335
|
// (dev middleware and prod handler) and bundled into the handler
|
|
@@ -1617,6 +1659,11 @@ function devtoolsMountModuleCode() {
|
|
|
1617
1659
|
// it, and page responses go through the runtime's `createSSRResponse`
|
|
1618
1660
|
// head lifecycle (commit at shell flush, real pre-flush redirects, the
|
|
1619
1661
|
// script fallback post-flush).
|
|
1662
|
+
// - `start.renderMode` decides how a page render becomes a body: `'stream'`
|
|
1663
|
+
// (default) flushes the shell with fallbacks and streams boundaries in
|
|
1664
|
+
// behind it; `'async'` awaits the settled document (no fallbacks or swap
|
|
1665
|
+
// scripts — complete for no-JS clients); a module path decides per
|
|
1666
|
+
// request, and `handleRequest(request, { renderMode })` overrides both.
|
|
1620
1667
|
// - `vite preview` serves dist/client statically and dispatches everything
|
|
1621
1668
|
// else through the built handler — the production path, middleware
|
|
1622
1669
|
// included, with no server file needed.
|
|
@@ -1692,6 +1739,37 @@ function normalizeUserPath(root, spec, option) {
|
|
|
1692
1739
|
}
|
|
1693
1740
|
return relative;
|
|
1694
1741
|
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Resolves `start.renderMode` at config time: a literal mode, or the
|
|
1744
|
+
* absolute path of a per-request module (`mode` stays the `'stream'`
|
|
1745
|
+
* default then; the module decides per request). Anything else is a
|
|
1746
|
+
* config error with the fix in the message — an unknown literal is far
|
|
1747
|
+
* more likely a typo than a file, so the message names both readings.
|
|
1748
|
+
*/
|
|
1749
|
+
function resolveRenderMode(root, value) {
|
|
1750
|
+
if (value === undefined) return {
|
|
1751
|
+
mode: 'stream',
|
|
1752
|
+
path: null
|
|
1753
|
+
};
|
|
1754
|
+
// (`string & {}` keeps editor completion for the literals; TS cannot
|
|
1755
|
+
// narrow it away by equality, hence the assertion.)
|
|
1756
|
+
if (value === 'stream' || value === 'async') return {
|
|
1757
|
+
mode: value,
|
|
1758
|
+
path: null
|
|
1759
|
+
};
|
|
1760
|
+
const usage = `start.renderMode must be 'stream' (the default), 'async', or the path of a module ` + `(relative to the Vite root) default-exporting a per-request function ` + `((event) => 'stream' | 'async' | Promise<...>)`;
|
|
1761
|
+
if (typeof value !== 'string') {
|
|
1762
|
+
throw new Error(`[@solidjs/vite-plugin] ${usage}; got ${typeof value}. A Vite config cannot serialize a ` + `closure into the generated handler — put the function in a module (e.g. ` + `./src/render-mode.ts) and pass its path instead.`);
|
|
1763
|
+
}
|
|
1764
|
+
const absolute = path.isAbsolute(value) ? value : path.resolve(root, value);
|
|
1765
|
+
if (!existsSync(absolute)) {
|
|
1766
|
+
throw new Error(`[@solidjs/vite-plugin] ${usage}; got ${JSON.stringify(value)}, which is neither a mode ` + `nor an existing file.`);
|
|
1767
|
+
}
|
|
1768
|
+
return {
|
|
1769
|
+
mode: 'stream',
|
|
1770
|
+
path: path.resolve(root, normalizeUserPath(root, value, 'renderMode'))
|
|
1771
|
+
};
|
|
1772
|
+
}
|
|
1695
1773
|
function resolveEntries(root, options, clientMode) {
|
|
1696
1774
|
const explicitClient = options.entryClient ? normalizeUserPath(root, options.entryClient, 'entryClient') : null;
|
|
1697
1775
|
if (clientMode) {
|
|
@@ -1784,8 +1862,11 @@ function startServe(options, internal = {}) {
|
|
|
1784
1862
|
// any of the (lazy) uses in entry codegen and the entry transform.
|
|
1785
1863
|
let diagnostics = internal.diagnostics === true;
|
|
1786
1864
|
let devtoolsEnabled = false;
|
|
1787
|
-
|
|
1788
|
-
|
|
1865
|
+
// Toolbar detection, memoized per consumer: whether @solidjs/start-devtools
|
|
1866
|
+
// resolves at all, and the app importer it was probed from. Only the
|
|
1867
|
+
// verdict is kept — the resolved id is deliberately not (see resolveId).
|
|
1868
|
+
let devtoolsDetections = {};
|
|
1869
|
+
let devtoolsImporters = {};
|
|
1789
1870
|
// `external` is server-mode-only (documented no-op in client mode, so a
|
|
1790
1871
|
// host-integrated config survives the `ssr` boolean flip untouched).
|
|
1791
1872
|
const externalServer = !clientMode && !!options.external;
|
|
@@ -1797,31 +1878,45 @@ function startServe(options, internal = {}) {
|
|
|
1797
1878
|
let middlewarePath = null;
|
|
1798
1879
|
/** Absolute path of the per-request setup module, when configured (server mode). */
|
|
1799
1880
|
let setupPath = null;
|
|
1881
|
+
/**
|
|
1882
|
+
* `start.renderMode`, resolved at config time: the static mode baked into
|
|
1883
|
+
* the handler, or the absolute path of the per-request module deciding it
|
|
1884
|
+
* (server mode only — a documented no-op in client mode, whose shell has
|
|
1885
|
+
* no boundaries to settle).
|
|
1886
|
+
*/
|
|
1887
|
+
let renderMode = 'stream';
|
|
1888
|
+
let renderModePath = null;
|
|
1800
1889
|
function requireEntries() {
|
|
1801
1890
|
// config() always runs before resolveId/load/configureServer.
|
|
1802
1891
|
if (!entries) throw new Error('[@solidjs/vite-plugin] SSR entries not resolved yet');
|
|
1803
1892
|
return entries;
|
|
1804
1893
|
}
|
|
1894
|
+
/**
|
|
1895
|
+
* Resolve @solidjs/start-devtools for generated code: from the app graph
|
|
1896
|
+
* first (the documented install location), then from the plugin's own
|
|
1897
|
+
* file — in pnpm-isolated apps a copy that is only a dependency of the
|
|
1898
|
+
* plugin is not reachable from the app's importers. Resolving from the
|
|
1899
|
+
* plugin's own file never yields null when the package is absent: it is
|
|
1900
|
+
* declared an optional peer dependency, so Vite answers with its
|
|
1901
|
+
* `__vite-optional-peer-dep:` stub (an empty module). That stub counts as
|
|
1902
|
+
* "not installed".
|
|
1903
|
+
*/
|
|
1904
|
+
async function resolveDevtoolsId(resolve, importer) {
|
|
1905
|
+
const realId = resolved => resolved && !resolved.id.startsWith('__vite-optional-peer-dep:') ? resolved.id : null;
|
|
1906
|
+
return realId(await resolve(DEVTOOLS_PACKAGE, importer)) ?? realId(await resolve(DEVTOOLS_PACKAGE, fileURLToPath(import.meta.url)));
|
|
1907
|
+
}
|
|
1805
1908
|
async function resolveDevtools(resolve, importer, consumer) {
|
|
1806
1909
|
if (!devtoolsEnabled) return false;
|
|
1807
|
-
//
|
|
1808
|
-
//
|
|
1809
|
-
//
|
|
1810
|
-
|
|
1811
|
-
|
|
1812
|
-
|
|
1813
|
-
|
|
1814
|
-
// Vite answers with its `__vite-optional-peer-dep:` stub (an empty
|
|
1815
|
-
// module). Treat that stub as "not installed".
|
|
1816
|
-
const realId = resolved => resolved && !resolved.id.startsWith('__vite-optional-peer-dep:') ? resolved.id : null;
|
|
1817
|
-
return realId(await resolve(DEVTOOLS_PACKAGE, importer)) ?? realId(await resolve(DEVTOOLS_PACKAGE, fileURLToPath(import.meta.url)));
|
|
1818
|
-
})();
|
|
1819
|
-
const id = await devtoolsResolutions[consumer];
|
|
1820
|
-
devtoolsIds[consumer] = id;
|
|
1821
|
-
if (!id && options.devtools === true) {
|
|
1910
|
+
// An install cannot change under a running server, so the verdict is
|
|
1911
|
+
// memoized per consumer. The id it was reached with is not reused for
|
|
1912
|
+
// generated imports: resolveId resolves afresh from the same importer.
|
|
1913
|
+
devtoolsImporters[consumer] ??= importer;
|
|
1914
|
+
devtoolsDetections[consumer] ??= resolveDevtoolsId(resolve, importer).then(id => id !== null);
|
|
1915
|
+
const detected = await devtoolsDetections[consumer];
|
|
1916
|
+
if (!detected && options.devtools === true) {
|
|
1822
1917
|
throw new Error('[@solidjs/vite-plugin] start.devtools requires @solidjs/start-devtools. ' + 'Install it as a development dependency or set start.devtools to false.');
|
|
1823
1918
|
}
|
|
1824
|
-
return
|
|
1919
|
+
return detected;
|
|
1825
1920
|
}
|
|
1826
1921
|
|
|
1827
1922
|
/**
|
|
@@ -1996,7 +2091,7 @@ function startServe(options, internal = {}) {
|
|
|
1996
2091
|
entryClient
|
|
1997
2092
|
} = requireEntries();
|
|
1998
2093
|
const composeServerFunctions = internal.serverFunctions;
|
|
1999
|
-
const lines = [`import { createRequestEvent, createSSRResponse, commitEventResponse${middlewarePath ? ', composeMiddleware' : ''} } from '@solidjs/web';`, `import { provideRequestEvent } from ${JSON.stringify(STORAGE_SOURCE)};`, `import * as entry from ${JSON.stringify(entryServerSpec())};`, ...(middlewarePath ? [`import middlewareModule from ${JSON.stringify(middlewarePath)};`] : []), ...(externalDev ? [`import DEV_STYLES_HEAD from ${JSON.stringify(DEV_STYLES_ID)};`] : []), ...(composeServerFunctions ? [`import { handleServerFunctionRequest, endpoint } from ${JSON.stringify(SERVER_FUNCTION_HANDLER_ID)};`] : [])];
|
|
2094
|
+
const lines = [`import { createRequestEvent, createSSRResponse, commitEventResponse${middlewarePath ? ', composeMiddleware' : ''} } from '@solidjs/web';`, `import { provideRequestEvent } from ${JSON.stringify(STORAGE_SOURCE)};`, `import * as entry from ${JSON.stringify(entryServerSpec())};`, ...(middlewarePath ? [`import middlewareModule from ${JSON.stringify(middlewarePath)};`] : []), ...(renderModePath ? [`import renderModeModule from ${JSON.stringify(renderModePath)};`] : []), ...(externalDev ? [`import DEV_STYLES_HEAD from ${JSON.stringify(DEV_STYLES_ID)};`] : []), ...(composeServerFunctions ? [`import { handleServerFunctionRequest, endpoint } from ${JSON.stringify(SERVER_FUNCTION_HANDLER_ID)};`] : [])];
|
|
2000
2095
|
if (isBuild) {
|
|
2001
2096
|
lines.push(`import manifest from ${JSON.stringify(MANIFEST_ID)};`);
|
|
2002
2097
|
lines.push(``, `function joinAssetPath(base, file) {`, ` if (typeof base !== 'string' || !base) base = '/';`, ` if (base[base.length - 1] !== '/') base += '/';`, ` return base + (file[0] === '/' ? file.slice(1) : file);`, `}`, ``, `let clientEntryUrl;`, `function resolveClientEntry() {`, ` if (clientEntryUrl !== undefined) return clientEntryUrl;`, ` clientEntryUrl = null;`,
|
|
@@ -2018,6 +2113,21 @@ function startServe(options, internal = {}) {
|
|
|
2018
2113
|
lines.push(`const runMiddleware = (request, next) => next(request);`);
|
|
2019
2114
|
}
|
|
2020
2115
|
|
|
2116
|
+
// Render mode (`start.renderMode`): 'stream' flushes the shell with
|
|
2117
|
+
// fallbacks in place and streams boundary content after it; 'async'
|
|
2118
|
+
// adopts the renderToStream result's thenable — which waits for the
|
|
2119
|
+
// complete render — so one settled document goes out (the fix for
|
|
2120
|
+
// no-JS clients, solidjs/solid#3280). Precedence per request: the
|
|
2121
|
+
// `handleRequest` option (hosts driving the handler directly), then the
|
|
2122
|
+
// configured module's per-request result, then the static config. Every
|
|
2123
|
+
// source is validated against the two literals with the offender named.
|
|
2124
|
+
lines.push(``, `function assertRenderMode(mode, source) {`, ` if (mode !== 'stream' && mode !== 'async') {`, ` throw new Error('[@solidjs/vite-plugin] ' + source + " must be 'stream' or 'async', got " + JSON.stringify(mode));`, ` }`, ` return mode;`, `}`);
|
|
2125
|
+
if (renderModePath) {
|
|
2126
|
+
lines.push(`if (typeof renderModeModule !== 'function') {`, ` throw new Error('[@solidjs/vite-plugin] start.renderMode must default-export a function ' +`, ` "((event) => 'stream' | 'async' | Promise<...>): " + ${JSON.stringify(renderModePath)});`, `}`, `async function resolveRenderMode(event, options) {`, ` if (options.renderMode !== undefined) return assertRenderMode(options.renderMode, 'handleRequest options.renderMode');`, ` return assertRenderMode(await renderModeModule(event), 'the start.renderMode module (' + ${JSON.stringify(renderModePath)} + ') result');`, `}`);
|
|
2127
|
+
} else {
|
|
2128
|
+
lines.push(`function resolveRenderMode(event, options) {`, ` if (options.renderMode !== undefined) return assertRenderMode(options.renderMode, 'handleRequest options.renderMode');`, ` return ${JSON.stringify(renderMode)};`, `}`);
|
|
2129
|
+
}
|
|
2130
|
+
|
|
2021
2131
|
// No `_$SC` bootstrap injection: the runtime's serialized
|
|
2022
2132
|
// server-component references self-bootstrap the registry (each
|
|
2023
2133
|
// hydration script's first reference carries it as an idempotent
|
|
@@ -2098,7 +2208,11 @@ function startServe(options, internal = {}) {
|
|
|
2098
2208
|
// flag, so external-host dispatch and preview stay render-always.
|
|
2099
2209
|
lines.push(` if (options.pageRequest === false) {`, ` return new Response(null, { status: 404, headers: { ${JSON.stringify(DEV_FALLTHROUGH_HEADER)}: '1' } });`, ` }`);
|
|
2100
2210
|
}
|
|
2101
|
-
lines.push(isBuild ? ` const clientEntry = options.clientEntry || resolveClientEntry();` : ` const clientEntry = options.clientEntry || ${JSON.stringify(devClientEntryUrl())};`,
|
|
2211
|
+
lines.push(isBuild ? ` const clientEntry = options.clientEntry || resolveClientEntry();` : ` const clientEntry = options.clientEntry || ${JSON.stringify(devClientEntryUrl())};`,
|
|
2212
|
+
// Decided before the render starts (the module form may be async),
|
|
2213
|
+
// inside the request scope and after the middleware chain, so a
|
|
2214
|
+
// per-request policy sees the decorated event.
|
|
2215
|
+
` const renderMode = await resolveRenderMode(event, options);`, ` let result = entry.render(request, { clientEntry, ...options.context });`,
|
|
2102
2216
|
// renderToStream results are thenables whose then() waits for the
|
|
2103
2217
|
// *complete* render — check for pipe first so streaming survives, and
|
|
2104
2218
|
// only await plain promises (async render functions).
|
|
@@ -2107,6 +2221,14 @@ function startServe(options, internal = {}) {
|
|
|
2107
2221
|
// entry): a bare promise resolution would adopt the stream's
|
|
2108
2222
|
// thenable and buffer the whole render.
|
|
2109
2223
|
` if (result && result.${STREAM_BOX}) result = result.${STREAM_BOX};`] : []),
|
|
2224
|
+
// Async mode adopts the thenable deliberately — the very thing the
|
|
2225
|
+
// pipe-first check and the setup box exist to avoid in stream mode.
|
|
2226
|
+
// It resolves with the full HTML once every boundary settled, each
|
|
2227
|
+
// spliced in place pre-flush (no fallbacks, no swap scripts; hydration
|
|
2228
|
+
// data still serialized), and the string then takes
|
|
2229
|
+
// createSSRResponse's string path below: stub commit, transformChunk
|
|
2230
|
+
// on the whole document, and a mid-render Location as a real 3xx.
|
|
2231
|
+
` if (renderMode === 'async' && result && typeof result.then === 'function') {`, ` result = await result;`, ` }`,
|
|
2110
2232
|
// Raw Responses fold at the handler edge (handleRequest), after the
|
|
2111
2233
|
// middleware chain unwinds — not here, where middleware above this
|
|
2112
2234
|
// frame could still legitimately mutate headers.
|
|
@@ -2145,8 +2267,8 @@ function startServe(options, internal = {}) {
|
|
|
2145
2267
|
config(userConfig, env) {
|
|
2146
2268
|
root = path.resolve(userConfig.root || process.cwd());
|
|
2147
2269
|
devtoolsEnabled = env.command === 'serve' && !env.isPreview && options.devtools !== false;
|
|
2148
|
-
|
|
2149
|
-
|
|
2270
|
+
devtoolsDetections = {};
|
|
2271
|
+
devtoolsImporters = {};
|
|
2150
2272
|
entries = resolveEntries(root, options, clientMode);
|
|
2151
2273
|
internal.onDocumentResolved?.(entries.document);
|
|
2152
2274
|
middlewarePath = options.middleware ? path.resolve(root, normalizeUserPath(root, options.middleware, 'middleware')) : null;
|
|
@@ -2158,6 +2280,17 @@ function startServe(options, internal = {}) {
|
|
|
2158
2280
|
// hook needs does not exist there.
|
|
2159
2281
|
throw new Error('[@solidjs/vite-plugin] start.setup only applies to generated entries: your ' + 'entry-server owns render() already, so call your setup step there instead ' + `(remove start.setup or the authored entry): ${options.setup}`);
|
|
2160
2282
|
}
|
|
2283
|
+
// Server-mode only as well: the client-mode shell renders no app,
|
|
2284
|
+
// so there is nothing to settle. Validated in every mode though —
|
|
2285
|
+
// a typo should not hide behind the `ssr` boolean.
|
|
2286
|
+
({
|
|
2287
|
+
mode: renderMode,
|
|
2288
|
+
path: renderModePath
|
|
2289
|
+
} = resolveRenderMode(root, options.renderMode));
|
|
2290
|
+
if (clientMode) {
|
|
2291
|
+
renderMode = 'stream';
|
|
2292
|
+
renderModePath = null;
|
|
2293
|
+
}
|
|
2161
2294
|
if (env.isPreview) {
|
|
2162
2295
|
if (clientMode) {
|
|
2163
2296
|
// Client-mode builds emit a real dist/client/index.html (the
|
|
@@ -2299,7 +2432,7 @@ function startServe(options, internal = {}) {
|
|
|
2299
2432
|
diagnostics = detectDiagnosticsPackage(root);
|
|
2300
2433
|
}
|
|
2301
2434
|
},
|
|
2302
|
-
resolveId(source, importer, opts) {
|
|
2435
|
+
async resolveId(source, importer, opts) {
|
|
2303
2436
|
if (source === HANDLER_ID) {
|
|
2304
2437
|
return {
|
|
2305
2438
|
id: HANDLER_ID,
|
|
@@ -2324,13 +2457,25 @@ function startServe(options, internal = {}) {
|
|
|
2324
2457
|
moduleSideEffects: true
|
|
2325
2458
|
};
|
|
2326
2459
|
}
|
|
2327
|
-
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
|
|
2331
|
-
|
|
2332
|
-
|
|
2333
|
-
|
|
2460
|
+
if (source === DEVTOOLS_PACKAGE && (importer === ENTRY_SERVER_ID || importer === ENTRY_CLIENT_ID || importer === DEVTOOLS_MOUNT_ID)) {
|
|
2461
|
+
// Generated modules have no directory for bare-package resolution:
|
|
2462
|
+
// resolve from the app importer detection probed. Resolve afresh on
|
|
2463
|
+
// every request rather than reusing detection's id — in the client
|
|
2464
|
+
// environment that id is the optimizer's pre-bundled URL, stamped
|
|
2465
|
+
// with the browserHash of the pass that produced it. Any dependency
|
|
2466
|
+
// discovered after the initial scan re-optimizes: the toolbar's
|
|
2467
|
+
// chunks are re-emitted under new names and the hash moves on, and
|
|
2468
|
+
// a frozen id would keep the entry on the previous pass — its lazy
|
|
2469
|
+
// chunks answer 504 (Outdated Optimize Dep) and the stale bundle
|
|
2470
|
+
// brings a second solid-js instance into the page.
|
|
2471
|
+
const from = devtoolsImporters[getEnvironmentConsumer(this.environment, opts)];
|
|
2472
|
+
if (!from) return null;
|
|
2473
|
+
const id = await resolveDevtoolsId((s, i) => this.resolve(s, i, {
|
|
2474
|
+
skipSelf: true
|
|
2475
|
+
}), from);
|
|
2476
|
+
return id ? {
|
|
2477
|
+
id
|
|
2478
|
+
} : null;
|
|
2334
2479
|
}
|
|
2335
2480
|
return null;
|
|
2336
2481
|
},
|
|
@@ -3382,7 +3527,69 @@ function combineSourcemaps(maps) {
|
|
|
3382
3527
|
// remapping expects most-recent-first.
|
|
3383
3528
|
return JSON.parse(remapping(chain.reverse(), () => null).toString());
|
|
3384
3529
|
}
|
|
3530
|
+
function toPosixPath(p) {
|
|
3531
|
+
return p.split(path.sep).join('/');
|
|
3532
|
+
}
|
|
3533
|
+
function tryRealpath(p) {
|
|
3534
|
+
try {
|
|
3535
|
+
return realpathSync.native(p);
|
|
3536
|
+
} catch {
|
|
3537
|
+
return null;
|
|
3538
|
+
}
|
|
3539
|
+
}
|
|
3540
|
+
|
|
3541
|
+
/** The `input` a build environment's config resolves to, in any spelling. */
|
|
3542
|
+
function configuredBuildInput(build) {
|
|
3543
|
+
if (!build) return undefined;
|
|
3544
|
+
return build.rolldownOptions?.input ?? build.rollupOptions?.input ?? build.lib?.entry;
|
|
3545
|
+
}
|
|
3385
3546
|
|
|
3547
|
+
/**
|
|
3548
|
+
* The genuine entries of a client build, derived from its configured input
|
|
3549
|
+
* (`build.rollupOptions.input` as a string / array / record, or Vite's
|
|
3550
|
+
* default `index.html`). Rollup and rolldown only ever flag two kinds of
|
|
3551
|
+
* chunk `isEntry`: those facades and chunks plugins emit with
|
|
3552
|
+
* `emitFile({ type: 'chunk' })` — so this is exactly the knowledge that
|
|
3553
|
+
* tells a real application entry apart from an emitted lazy facade.
|
|
3554
|
+
*
|
|
3555
|
+
* `moduleIds` — every spelling the entry's facade module id can take: as
|
|
3556
|
+
* written (virtual ids resolve to themselves), resolved against the root
|
|
3557
|
+
* (Vite resolves relative file inputs there), and the real path of either
|
|
3558
|
+
* (Vite's resolver follows symlinks).
|
|
3559
|
+
* `manifestKeys` — the manifest.json keys Vite derives from those facades
|
|
3560
|
+
* (root-relative, `\0` stripped), matching Vite's own `getChunkName`.
|
|
3561
|
+
*/
|
|
3562
|
+
function resolveConfiguredEntries(input, root) {
|
|
3563
|
+
const raw = input == null ? ['index.html'] : typeof input === 'string' ? [input] : Array.isArray(input) ? input : Object.values(input);
|
|
3564
|
+
const moduleIds = new Set();
|
|
3565
|
+
for (const id of raw) {
|
|
3566
|
+
if (typeof id !== 'string') continue;
|
|
3567
|
+
const clean = id.replace(/\0/g, '');
|
|
3568
|
+
const candidates = [clean, path.resolve(root, clean)];
|
|
3569
|
+
for (const candidate of candidates) {
|
|
3570
|
+
moduleIds.add(candidate);
|
|
3571
|
+
moduleIds.add(toPosixPath(candidate));
|
|
3572
|
+
const real = tryRealpath(candidate);
|
|
3573
|
+
if (real) {
|
|
3574
|
+
moduleIds.add(real);
|
|
3575
|
+
moduleIds.add(toPosixPath(real));
|
|
3576
|
+
}
|
|
3577
|
+
}
|
|
3578
|
+
}
|
|
3579
|
+
const manifestKeys = new Set();
|
|
3580
|
+
for (const id of moduleIds) manifestKeys.add(toPosixPath(path.relative(root, id)));
|
|
3581
|
+
return {
|
|
3582
|
+
moduleIds,
|
|
3583
|
+
manifestKeys,
|
|
3584
|
+
isEntryModule(id) {
|
|
3585
|
+
if (!id) return false;
|
|
3586
|
+
const clean = id.replace(/\0/g, '');
|
|
3587
|
+
if (moduleIds.has(clean) || moduleIds.has(toPosixPath(clean))) return true;
|
|
3588
|
+
const real = tryRealpath(clean);
|
|
3589
|
+
return !!real && (moduleIds.has(real) || moduleIds.has(toPosixPath(real)));
|
|
3590
|
+
}
|
|
3591
|
+
};
|
|
3592
|
+
}
|
|
3386
3593
|
/**
|
|
3387
3594
|
* Chunks emitted for lazy() targets are marked `isEntry` by Rollup even
|
|
3388
3595
|
* though they are semantically dynamic entries. Reclassify any entry that is
|
|
@@ -3391,18 +3598,57 @@ function combineSourcemaps(maps) {
|
|
|
3391
3598
|
* the real client entry. Works on both the Vite manifest.json shape and the
|
|
3392
3599
|
* raw Rollup output bundle — both key entries by name and expose
|
|
3393
3600
|
* `dynamicImports` / `isEntry` with the same meaning.
|
|
3601
|
+
*
|
|
3602
|
+
* Being a dynamic-import target alone does not make a chunk a lazy facade,
|
|
3603
|
+
* though: the real client entry becomes one whenever it absorbs a module
|
|
3604
|
+
* that is also dynamically imported somewhere else. Solid 2 produces that
|
|
3605
|
+
* shape on its own — `@solidjs/web/frames/client` lazily imports the
|
|
3606
|
+
* serialization decoder (`loadCodec()`), so a static import of
|
|
3607
|
+
* `@solidjs/web/serialization/decode` anywhere in the client graph merges
|
|
3608
|
+
* the decoder into the entry chunk, and the entry then lists itself (or is
|
|
3609
|
+
* listed by another lazy chunk) under `dynamicImports`. Stripping `isEntry`
|
|
3610
|
+
* there leaves the bundle with no entry at all ("No entry file found"
|
|
3611
|
+
* downstream, e.g. TanStack Start's manifest capture, #342). Genuine
|
|
3612
|
+
* configured entries are therefore never reclassified, and a chunk's
|
|
3613
|
+
* dynamic import of itself is not an edge worth acting on.
|
|
3614
|
+
*
|
|
3615
|
+
* Rolldown caveat: of the flags written here only `isEntry` is synced back
|
|
3616
|
+
* to the native bundle after the hook (rolldown's `update_output_chunk`
|
|
3617
|
+
* copies `code`, `map`, `imports`, `dynamicImports`, `isEntry` and the file
|
|
3618
|
+
* name; `isDynamicEntry` is kept from the original chunk). Later plugins
|
|
3619
|
+
* and Vite's manifest plugin therefore see reclassified facades as neither
|
|
3620
|
+
* entry nor dynamic entry under rolldown. The manifest `load` path repairs
|
|
3621
|
+
* `isDynamicEntry` on the plugin's own manifest module, the one place it
|
|
3622
|
+
* controls end to end.
|
|
3394
3623
|
*/
|
|
3395
|
-
function normalizeEmittedLazyEntries(manifest
|
|
3396
|
-
|
|
3624
|
+
function normalizeEmittedLazyEntries(manifest, {
|
|
3625
|
+
isConfiguredEntry,
|
|
3626
|
+
knownLazyKeys,
|
|
3627
|
+
warn,
|
|
3628
|
+
repairDynamicEntries
|
|
3629
|
+
}) {
|
|
3630
|
+
const dynamicKeys = new Map();
|
|
3397
3631
|
for (const key in manifest) {
|
|
3398
3632
|
const imports = manifest[key].dynamicImports;
|
|
3399
|
-
if (imports)
|
|
3633
|
+
if (!imports) continue;
|
|
3634
|
+
for (const dep of imports) {
|
|
3635
|
+
// A chunk that absorbed one of its own lazy targets imports itself;
|
|
3636
|
+
// that says nothing about whether it is an entry.
|
|
3637
|
+
if (dep !== key && !dynamicKeys.has(dep)) dynamicKeys.set(dep, key);
|
|
3638
|
+
}
|
|
3400
3639
|
}
|
|
3401
|
-
for (const key of dynamicKeys) {
|
|
3640
|
+
for (const [key, importer] of dynamicKeys) {
|
|
3402
3641
|
const entry = manifest[key];
|
|
3403
|
-
if (entry
|
|
3642
|
+
if (!entry || entry.type === 'asset') continue;
|
|
3643
|
+
if (isConfiguredEntry(key, entry)) continue;
|
|
3644
|
+
if (entry.isEntry) {
|
|
3404
3645
|
entry.isEntry = false;
|
|
3405
3646
|
entry.isDynamicEntry = true;
|
|
3647
|
+
if (warn && !knownLazyKeys?.has(key)) {
|
|
3648
|
+
warn(`[@solidjs/vite-plugin] Reclassified the entry chunk "${key}" as a dynamic entry ` + `because "${importer}" dynamically imports it and it does not match a configured ` + `build input. If "${key}" is the application entry, its chunk absorbed a module ` + 'that is also imported dynamically elsewhere (for example a static import of ' + '"@solidjs/web/serialization/decode" alongside Solid\'s own lazy import of it); ' + 'list the entry in `build.rollupOptions.input` so the plugin can recognize it.');
|
|
3649
|
+
}
|
|
3650
|
+
} else if (repairDynamicEntries && !entry.isDynamicEntry) {
|
|
3651
|
+
entry.isDynamicEntry = true;
|
|
3406
3652
|
}
|
|
3407
3653
|
}
|
|
3408
3654
|
}
|
|
@@ -3464,6 +3710,11 @@ function solidPlugin(options = {}) {
|
|
|
3464
3710
|
let isSsrBuild = false;
|
|
3465
3711
|
let base = '/';
|
|
3466
3712
|
let clientOutDir = null;
|
|
3713
|
+
// The client environment's resolved build options, for the configured
|
|
3714
|
+
// entry input. Read off the resolved config so the SSR half of a
|
|
3715
|
+
// two-invocation build (`vite build --ssr`) still knows the client's
|
|
3716
|
+
// entries when it bakes the client manifest in.
|
|
3717
|
+
let clientBuildConfig = null;
|
|
3467
3718
|
let solidPkgsConfig;
|
|
3468
3719
|
const tsrxCss = new Map();
|
|
3469
3720
|
|
|
@@ -3769,6 +4020,29 @@ function solidPlugin(options = {}) {
|
|
|
3769
4020
|
// So the dev flag has to reach both lists.
|
|
3770
4021
|
if (replaceDev && config.consumer !== 'client' && name !== 'client') {
|
|
3771
4022
|
config.resolve.externalConditions = ['development', ...(config.resolve.externalConditions ?? defaultExternalConditions)];
|
|
4023
|
+
|
|
4024
|
+
// `externalConditions` only reaches the imports the module runner
|
|
4025
|
+
// resolves itself. An externalized package's OWN imports are resolved
|
|
4026
|
+
// by Node, with Node's conditions — never `development`. Since
|
|
4027
|
+
// solid 2.0.0-rc.7 both `solid-js` and `@solidjs/web` ship a
|
|
4028
|
+
// `dist/server.dev.*` behind that condition, so leaving them external
|
|
4029
|
+
// splits the framework in two under `vite dev`: the app's `solid-js`
|
|
4030
|
+
// is the runner's dev copy while `@solidjs/web`'s `import "solid-js"`
|
|
4031
|
+
// lands on Node's prod copy. `renderToStream` then installs the asset
|
|
4032
|
+
// resolver on one `sharedConfig` and `lazy()` reads the other ("no
|
|
4033
|
+
// asset manifest is set"), with every other module-level singleton
|
|
4034
|
+
// (owner tracking, request events, hydration keys) split the same
|
|
4035
|
+
// way. Inlining the two core packages makes every resolution — theirs
|
|
4036
|
+
// included — go through the environment's conditions, so one dev
|
|
4037
|
+
// build is loaded end to end. Framework packages that declare the
|
|
4038
|
+
// `solid` export condition are already inlined via vitefu below and
|
|
4039
|
+
// reach the same copy. Vitest projects manage their own inlining
|
|
4040
|
+
// (`test.server.deps` above) and are left alone, as is a host that
|
|
4041
|
+
// set `noExternal: true` (everything is inlined already).
|
|
4042
|
+
if (!isTestMode && config.resolve.noExternal !== true) {
|
|
4043
|
+
const noExternal = config.resolve.noExternal;
|
|
4044
|
+
config.resolve.noExternal = [...(Array.isArray(noExternal) ? noExternal : noExternal ? [noExternal] : []), 'solid-js', '@solidjs/web'];
|
|
4045
|
+
}
|
|
3772
4046
|
}
|
|
3773
4047
|
|
|
3774
4048
|
// Set resolve.noExternal and resolve.external for the SSR environment.
|
|
@@ -3785,6 +4059,7 @@ function solidPlugin(options = {}) {
|
|
|
3785
4059
|
isSsrBuild = !!config.build.ssr;
|
|
3786
4060
|
base = config.base;
|
|
3787
4061
|
projectRoot = config.root;
|
|
4062
|
+
clientBuildConfig = config.environments?.client?.build ?? config.build;
|
|
3788
4063
|
filter = createFilter(options.include, options.exclude, {
|
|
3789
4064
|
resolve: projectRoot
|
|
3790
4065
|
});
|
|
@@ -3918,7 +4193,23 @@ function solidPlugin(options = {}) {
|
|
|
3918
4193
|
const manifestPath = clientManifestPath();
|
|
3919
4194
|
if (manifestPath) {
|
|
3920
4195
|
const manifest = JSON.parse(readFileSync(manifestPath, 'utf-8'));
|
|
3921
|
-
|
|
4196
|
+
// Manifest records are keyed the way Vite keys entry chunks (the
|
|
4197
|
+
// root-relative facade path, also carried as `src`), so the
|
|
4198
|
+
// configured client inputs identify the genuine entries here too —
|
|
4199
|
+
// independent of `isEntry`, which the serialized manifest may have
|
|
4200
|
+
// lost already (older plugin builds stripped it; see #342).
|
|
4201
|
+
const entries = resolveConfiguredEntries(configuredBuildInput(clientBuildConfig), projectRoot);
|
|
4202
|
+
const isConfiguredEntry = (key, record) => entries.manifestKeys.has(key) || typeof record.src === 'string' && entries.manifestKeys.has(record.src);
|
|
4203
|
+
for (const key in manifest) {
|
|
4204
|
+
if (isConfiguredEntry(key, manifest[key]) && manifest[key].file) {
|
|
4205
|
+
manifest[key].isEntry = true;
|
|
4206
|
+
}
|
|
4207
|
+
}
|
|
4208
|
+
normalizeEmittedLazyEntries(manifest, {
|
|
4209
|
+
isConfiguredEntry,
|
|
4210
|
+
warn: message => this.warn(message),
|
|
4211
|
+
repairDynamicEntries: true
|
|
4212
|
+
});
|
|
3922
4213
|
manifest._base = base;
|
|
3923
4214
|
return `export default ${JSON.stringify(manifest)};`;
|
|
3924
4215
|
}
|
|
@@ -3935,6 +4226,12 @@ function solidPlugin(options = {}) {
|
|
|
3935
4226
|
// the bundle don't mistake them for application entries. Must precede
|
|
3936
4227
|
// the client asset map build, which keys off dynamic entries.
|
|
3937
4228
|
if (options.ssr) {
|
|
4229
|
+
// The genuine entries are the configured inputs of this very
|
|
4230
|
+
// environment — the plugin injects the client entry itself in start
|
|
4231
|
+
// mode, and Vite's default is index.html — so their facade chunks
|
|
4232
|
+
// are recognizable regardless of what dynamically imports them.
|
|
4233
|
+
const entries = resolveConfiguredEntries(configuredBuildInput(this.environment?.config?.build ?? clientBuildConfig), projectRoot);
|
|
4234
|
+
const knownLazyKeys = new Set();
|
|
3938
4235
|
for (const ref of emittedLazyChunkRefs) {
|
|
3939
4236
|
let fileName;
|
|
3940
4237
|
try {
|
|
@@ -3945,10 +4242,17 @@ function solidPlugin(options = {}) {
|
|
|
3945
4242
|
}
|
|
3946
4243
|
const chunk = bundle[fileName];
|
|
3947
4244
|
if (!chunk || chunk.type !== 'chunk') continue;
|
|
4245
|
+
// An entry that is also lazily imported stays an entry.
|
|
4246
|
+
if (entries.isEntryModule(chunk.facadeModuleId)) continue;
|
|
4247
|
+
knownLazyKeys.add(fileName);
|
|
3948
4248
|
chunk.isEntry = false;
|
|
3949
4249
|
chunk.isDynamicEntry = true;
|
|
3950
4250
|
}
|
|
3951
|
-
normalizeEmittedLazyEntries(bundle
|
|
4251
|
+
normalizeEmittedLazyEntries(bundle, {
|
|
4252
|
+
isConfiguredEntry: (_key, chunk) => entries.isEntryModule(chunk.facadeModuleId),
|
|
4253
|
+
knownLazyKeys,
|
|
4254
|
+
warn: message => this.warn(message)
|
|
4255
|
+
});
|
|
3952
4256
|
}
|
|
3953
4257
|
},
|
|
3954
4258
|
async transform(source, id, transformOptions) {
|