@octanejs/vite-plugin 0.4.0 → 0.4.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@octanejs/vite-plugin",
3
- "version": "0.4.0",
3
+ "version": "0.4.1",
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.1.6",
49
+ "@octanejs/app-core": "0.1.7",
50
50
  "@ripple-ts/adapter": "^0.4.0"
51
51
  },
52
52
  "peerDependencies": {
53
- "octane": "^0.13.0",
53
+ "octane": "^0.13.2",
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.13.0",
59
+ "octane": "0.13.2",
60
60
  "playwright": "^1.61.1",
61
61
  "playwright-webkit": "1.63.0",
62
62
  "vite": "^8.1.5"
@@ -1,7 +1,15 @@
1
1
  // @ts-check
2
- import { randomUUID } from 'node:crypto';
2
+ import { createHash, randomUUID } from 'node:crypto';
3
3
  import path from 'node:path';
4
4
 
5
+ /**
6
+ * A production client entry embeds this until every chunk is rendered. It has
7
+ * the length of the content id `seal` returns, so the swap moves no mappings.
8
+ */
9
+ export const PENDING_CLIENT_BUILD_ID = '__octane_pending_client_build_id__'.padEnd(43, '_');
10
+ // Rolldown labels rendered modules with cwd-relative paths that minifying drops.
11
+ const REGION_COMMENT = /^\/\/#(?:end)?region\b.*$/gm;
12
+
5
13
  /**
6
14
  * One identity per actual Vite client generation. Discovery is replaceable per
7
15
  * source, so deleting a widget cannot leave an old activation record behind.
@@ -9,6 +17,7 @@ import path from 'node:path';
9
17
  * @param {(buildId: string) => void} [onIncompatibleDiscovery]
10
18
  */
11
19
  export function createClientBuildState(onIncompatibleDiscovery) {
20
+ /** @type {string} */
12
21
  let buildId = randomUUID();
13
22
  let hadHotUpdates = false;
14
23
  /** @type {Map<string, Map<string, { moduleId: string, styles: string[] }>>} */
@@ -22,7 +31,7 @@ export function createClientBuildState(onIncompatibleDiscovery) {
22
31
  return sources.size !== 0 || signalSources.size !== 0;
23
32
  },
24
33
  begin() {
25
- buildId = randomUUID();
34
+ buildId = PENDING_CLIENT_BUILD_ID;
26
35
  hadHotUpdates = false;
27
36
  sources.clear();
28
37
  signalSources.clear();
@@ -37,6 +46,25 @@ export function createClientBuildState(onIncompatibleDiscovery) {
37
46
  noteHotUpdate() {
38
47
  hadHotUpdates = true;
39
48
  },
49
+ /**
50
+ * Name a production generation by its rendered client graph, so identical
51
+ * inputs reproduce identical output. Rolldown hashes file names after
52
+ * renderChunk, so the entries that embed this id are named by it too.
53
+ * @param {Record<string, import('vite').Rollup.RenderedChunk>} chunks
54
+ */
55
+ seal(chunks) {
56
+ if (buildId !== PENDING_CLIENT_BUILD_ID) return buildId;
57
+ const graph = Object.keys(chunks)
58
+ .sort()
59
+ .map((file) => [
60
+ file,
61
+ Object.values(chunks[file].modules).map((module) =>
62
+ module.code?.replace(REGION_COMMENT, ''),
63
+ ),
64
+ ]);
65
+ buildId = createHash('sha256').update(JSON.stringify(graph)).digest('base64url');
66
+ return buildId;
67
+ },
40
68
  /** @param {string} root @param {string} id @param {any[]} templates @param {boolean} [streamedSignals] */
41
69
  record(root, id, templates, streamedSignals = false) {
42
70
  // Sliced activation modules have no children of their own. They must
package/src/index.js CHANGED
@@ -45,7 +45,7 @@ import {
45
45
  write_project_generated_file,
46
46
  } from './project-codegen.js';
47
47
  import { createClientAssetMap } from './client-assets.js';
48
- import { createClientBuildState } from './client-build.js';
48
+ import { PENDING_CLIENT_BUILD_ID, createClientBuildState } from './client-build.js';
49
49
 
50
50
  import { patch_global_fetch, is_rpc_request } from '@ripple-ts/adapter/rpc';
51
51
 
@@ -677,6 +677,14 @@ export function octane(inlineOptions = {}) {
677
677
  }
678
678
  },
679
679
 
680
+ renderChunk(code, _chunk, _options, meta) {
681
+ if (!code.includes(PENDING_CLIENT_BUILD_ID)) return null;
682
+ return {
683
+ code: code.replaceAll(PENDING_CLIENT_BUILD_ID, clientBuild.seal(meta.chunks)),
684
+ map: null,
685
+ };
686
+ },
687
+
680
688
  writeBundle() {
681
689
  clientBuildWritten = true;
682
690
  },