@octanejs/vite-plugin 0.4.3 → 0.5.0
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/package.json +4 -4
- package/src/client-build.js +3 -0
- package/src/index.js +69 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octanejs/vite-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -46,17 +46,17 @@
|
|
|
46
46
|
}
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@octanejs/app-core": "0.
|
|
49
|
+
"@octanejs/app-core": "0.2.0",
|
|
50
50
|
"@ripple-ts/adapter": "^0.4.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"octane": "^0.
|
|
53
|
+
"octane": "^0.16.0",
|
|
54
54
|
"vite": "^8.0.16"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@types/jsdom": "30.0.0",
|
|
58
58
|
"@types/node": "^24.13.3",
|
|
59
|
-
"octane": "0.
|
|
59
|
+
"octane": "0.16.0",
|
|
60
60
|
"playwright": "^1.61.1",
|
|
61
61
|
"playwright-webkit": "1.63.0",
|
|
62
62
|
"vite": "^8.1.5"
|
package/src/client-build.js
CHANGED
|
@@ -30,6 +30,9 @@ export function createClientBuildState(onIncompatibleDiscovery) {
|
|
|
30
30
|
get hasStatefulModules() {
|
|
31
31
|
return sources.size !== 0 || signalSources.size !== 0;
|
|
32
32
|
},
|
|
33
|
+
get hasStreamedSignals() {
|
|
34
|
+
return signalSources.size !== 0;
|
|
35
|
+
},
|
|
33
36
|
begin() {
|
|
34
37
|
buildId = PENDING_CLIENT_BUILD_ID;
|
|
35
38
|
hadHotUpdates = false;
|
package/src/index.js
CHANGED
|
@@ -404,6 +404,59 @@ function collect_hydrate_module_paths(config) {
|
|
|
404
404
|
return [...new Set(entries.filter((e) => typeof e === 'string'))];
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
+
/**
|
|
408
|
+
* Narrow the production hydrate entry to the features its client graph uses.
|
|
409
|
+
* Loading that graph first runs every compiled transform, so independent
|
|
410
|
+
* islands and streamed signals are recorded before the entry's own lazy
|
|
411
|
+
* imports reach chunking. A void root needs every page and layout the entry can
|
|
412
|
+
* render proven a void `@{}` body, by the compiler's own final-code proof.
|
|
413
|
+
*
|
|
414
|
+
* @param {import('vite').Rollup.PluginContext} context
|
|
415
|
+
* @param {ResolvedOctaneConfig} config
|
|
416
|
+
* @param {string[]} entries
|
|
417
|
+
* @param {ReturnType<typeof createClientBuildState>} clientBuild
|
|
418
|
+
* @param {(context: any, importer: string, imports: Array<{ request: string, imported: string }>) => Promise<unknown[]>} provenVoidImports
|
|
419
|
+
*/
|
|
420
|
+
async function hydrate_entry_features(context, config, entries, clientBuild, provenVoidImports) {
|
|
421
|
+
const seen = new Set();
|
|
422
|
+
// Rolldown's ModuleInfo cannot tell an external import apart, and loading
|
|
423
|
+
// one never settles, so each import is resolved again from its importer.
|
|
424
|
+
/** @param {string} request @param {string} importer @returns {Promise<void>} */
|
|
425
|
+
const visit = async (request, importer) => {
|
|
426
|
+
const resolved = await context.resolve(request, importer);
|
|
427
|
+
if (!resolved || resolved.external || seen.has(resolved.id)) return;
|
|
428
|
+
seen.add(resolved.id);
|
|
429
|
+
const info = await context.load({ id: resolved.id, resolveDependencies: true });
|
|
430
|
+
await Promise.all(
|
|
431
|
+
[...info.importedIds, ...info.dynamicallyImportedIds].map((id) => visit(id, resolved.id)),
|
|
432
|
+
);
|
|
433
|
+
};
|
|
434
|
+
await Promise.all(entries.map((entry) => visit(entry, RESOLVED_VIRTUAL_HYDRATE_ID)));
|
|
435
|
+
const rootBoundary = !!(config.rootBoundary.pending || config.rootBoundary.catch);
|
|
436
|
+
const imports = config.router.routes
|
|
437
|
+
.filter(
|
|
438
|
+
/** @returns {route is RenderRoute} */
|
|
439
|
+
(route) => route.type === 'render' && route.hydrate !== 'islands',
|
|
440
|
+
)
|
|
441
|
+
.flatMap((route) => [
|
|
442
|
+
{
|
|
443
|
+
request: /** @type {string} */ (get_route_entry_path(route.entry)),
|
|
444
|
+
imported: get_route_entry_export_name(route.entry) ?? 'default',
|
|
445
|
+
},
|
|
446
|
+
...(route.layout ? [{ request: route.layout, imported: 'default' }] : []),
|
|
447
|
+
]);
|
|
448
|
+
return {
|
|
449
|
+
rootBoundary,
|
|
450
|
+
independentHydration: clientBuild.metadata().capabilities.independentHydration,
|
|
451
|
+
streamedSignals: clientBuild.hasStreamedSignals,
|
|
452
|
+
voidRoot:
|
|
453
|
+
!rootBoundary &&
|
|
454
|
+
imports.length > 0 &&
|
|
455
|
+
(await provenVoidImports(context, RESOLVED_VIRTUAL_HYDRATE_ID, imports)).length ===
|
|
456
|
+
imports.length,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
|
|
407
460
|
/**
|
|
408
461
|
* The recommended Octane Vite integration. With no octane.config.ts it behaves
|
|
409
462
|
* as a compiler plugin inside a normal Vite SPA; configured routes activate the
|
|
@@ -833,6 +886,17 @@ export function octane(inlineOptions = {}) {
|
|
|
833
886
|
// restarts. Literal `import('/src/…')` entries go through import
|
|
834
887
|
// analysis and share url identity with every other importer.
|
|
835
888
|
let entries = staticEntries;
|
|
889
|
+
// A watch rebuild can add a feature after this entry has loaded.
|
|
890
|
+
const features =
|
|
891
|
+
isBuild && config.build.watch == null && buildOctaneConfig
|
|
892
|
+
? await hydrate_entry_features(
|
|
893
|
+
this,
|
|
894
|
+
buildOctaneConfig,
|
|
895
|
+
entries,
|
|
896
|
+
clientBuild,
|
|
897
|
+
compilerPlugin.api.provenVoidImports,
|
|
898
|
+
)
|
|
899
|
+
: null;
|
|
836
900
|
if (!isBuild) {
|
|
837
901
|
const loaded = octaneConfig ?? (await loadStartupConfig(root))?.config ?? null;
|
|
838
902
|
entries = collect_hydrate_module_paths(loaded);
|
|
@@ -845,6 +909,7 @@ export function octane(inlineOptions = {}) {
|
|
|
845
909
|
staticEntries: entries,
|
|
846
910
|
clientBuildId: clientBuild.buildId,
|
|
847
911
|
devClientBuild: !isBuild,
|
|
912
|
+
...features,
|
|
848
913
|
}),
|
|
849
914
|
);
|
|
850
915
|
return fs.readFileSync(file, 'utf-8');
|
|
@@ -873,12 +938,13 @@ export function octane(inlineOptions = {}) {
|
|
|
873
938
|
|
|
874
939
|
/**
|
|
875
940
|
* Observe the compiler's client output after the pre-transform. A generated
|
|
876
|
-
* __serverRpc call is an exact, syntax-level signal that
|
|
877
|
-
* `module server`; production uses the collected paths as
|
|
941
|
+
* __serverRpc or __serverRpcStream call is an exact, syntax-level signal that
|
|
942
|
+
* this source owns a `module server`; production uses the collected paths as
|
|
943
|
+
* static SSR imports.
|
|
878
944
|
*/
|
|
879
945
|
transform(code, id, options) {
|
|
880
946
|
if (!isBuild || options?.ssr || !is_octane_module_path(id.split('?')[0])) return null;
|
|
881
|
-
if (!code.includes('_$__serverRpc
|
|
947
|
+
if (!code.includes('_$__serverRpc')) return null;
|
|
882
948
|
const file = id.split('?')[0];
|
|
883
949
|
const relative = path.relative(root, file);
|
|
884
950
|
const isWithinRoot =
|