castle-web-cli 0.4.207 → 0.4.208
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/ide.d.ts +18 -0
- package/dist/ide.js +44 -1
- package/package.json +1 -1
package/dist/ide.d.ts
CHANGED
|
@@ -4,6 +4,24 @@ import { COVER_FILE } from './localPaths.js';
|
|
|
4
4
|
import { type TuneLedger } from './paramsTunes.js';
|
|
5
5
|
/** Cache only Vite's content-fingerprinted executable, style, and font output. */
|
|
6
6
|
export declare function shellAssetCacheControl(asset: string): string;
|
|
7
|
+
/**
|
|
8
|
+
* The CDN origin that carries this CLI's fingerprinted shell assets, when the
|
|
9
|
+
* environment names one (the sandbox image sets CASTLE_SHELL_ASSET_ORIGIN; its
|
|
10
|
+
* build uploads the assets there first). Only a bare https origin counts.
|
|
11
|
+
*/
|
|
12
|
+
export declare function shellAssetOrigin(value: string | undefined): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Point the shell's fingerprinted script and stylesheet at the CDN, falling back
|
|
15
|
+
* to this serve's own copy if the CDN copy fails to load.
|
|
16
|
+
*
|
|
17
|
+
* Each deck serve is its own origin (`<port>-<sandbox>`), so without this the
|
|
18
|
+
* browser caches the 1.5 MB bundle once per deck port and downloads it again on
|
|
19
|
+
* the first open of every deck: 2.0 s vs 0.83 s to shell load on mobile. The CDN
|
|
20
|
+
* URL is the same for every deck and sandbox, and it is keyed by content hash, so
|
|
21
|
+
* a CLI release that leaves the shell alone keeps the cached copy too. Only names
|
|
22
|
+
* the immutable-asset rule accepts are moved; everything else stays local.
|
|
23
|
+
*/
|
|
24
|
+
export declare function withShellAssetOrigin(html: string, origin: string | null): string;
|
|
7
25
|
export declare const IDE_ASSET_PREFIX = "/__castle/ide/";
|
|
8
26
|
export declare const PTY_WS_PATH = "/__castle/pty";
|
|
9
27
|
export declare const VENDOR_PREFIX = "/__castle/vendor/";
|
package/dist/ide.js
CHANGED
|
@@ -58,6 +58,49 @@ const IMMUTABLE_SHELL_ASSET = /^assets\/[^/\\]+-[A-Za-z0-9_-]{8}\.(?:css|js|woff
|
|
|
58
58
|
export function shellAssetCacheControl(asset) {
|
|
59
59
|
return IMMUTABLE_SHELL_ASSET.test(asset) ? 'public, max-age=31536000, immutable' : 'no-store';
|
|
60
60
|
}
|
|
61
|
+
/**
|
|
62
|
+
* The CDN origin that carries this CLI's fingerprinted shell assets, when the
|
|
63
|
+
* environment names one (the sandbox image sets CASTLE_SHELL_ASSET_ORIGIN; its
|
|
64
|
+
* build uploads the assets there first). Only a bare https origin counts.
|
|
65
|
+
*/
|
|
66
|
+
export function shellAssetOrigin(value) {
|
|
67
|
+
if (!value)
|
|
68
|
+
return null;
|
|
69
|
+
try {
|
|
70
|
+
const url = new URL(value);
|
|
71
|
+
if (url.protocol !== 'https:' || url.pathname !== '/' || url.search || url.hash)
|
|
72
|
+
return null;
|
|
73
|
+
if (url.username || url.password)
|
|
74
|
+
return null;
|
|
75
|
+
return url.origin;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Point the shell's fingerprinted script and stylesheet at the CDN, falling back
|
|
83
|
+
* to this serve's own copy if the CDN copy fails to load.
|
|
84
|
+
*
|
|
85
|
+
* Each deck serve is its own origin (`<port>-<sandbox>`), so without this the
|
|
86
|
+
* browser caches the 1.5 MB bundle once per deck port and downloads it again on
|
|
87
|
+
* the first open of every deck: 2.0 s vs 0.83 s to shell load on mobile. The CDN
|
|
88
|
+
* URL is the same for every deck and sandbox, and it is keyed by content hash, so
|
|
89
|
+
* a CLI release that leaves the shell alone keeps the cached copy too. Only names
|
|
90
|
+
* the immutable-asset rule accepts are moved; everything else stays local.
|
|
91
|
+
*/
|
|
92
|
+
export function withShellAssetOrigin(html, origin) {
|
|
93
|
+
if (!origin)
|
|
94
|
+
return html;
|
|
95
|
+
const local = (name) => `${IDE_ASSET_PREFIX}assets/${name}`;
|
|
96
|
+
const isMovable = (name) => IMMUTABLE_SHELL_ASSET.test(`assets/${name}`);
|
|
97
|
+
html = html.replace(/<script type="module" crossorigin src="\/__castle\/ide\/assets\/([^"\/]+)"><\/script>/g, (tag, name) => isMovable(name) && name.endsWith('.js')
|
|
98
|
+
? `<script type="module" crossorigin src="${origin}${local(name)}" onerror="var s=document.createElement('script');s.type='module';s.src='${local(name)}';document.head.appendChild(s)"></script>`
|
|
99
|
+
: tag);
|
|
100
|
+
return html.replace(/<link rel="stylesheet" crossorigin href="\/__castle\/ide\/assets\/([^"\/]+)">/g, (tag, name) => isMovable(name) && name.endsWith('.css')
|
|
101
|
+
? `<link rel="stylesheet" crossorigin href="${origin}${local(name)}" onerror="this.onerror=null;this.href='${local(name)}'">`
|
|
102
|
+
: tag);
|
|
103
|
+
}
|
|
61
104
|
// Does the deck serve this root-level file itself? Vite serves both the deck
|
|
62
105
|
// root and its `public/` dir at `/`, so either location counts.
|
|
63
106
|
function deckHasFile(deckDir, name) {
|
|
@@ -118,7 +161,7 @@ function serveShellIndex(req, res, bootstrap) {
|
|
|
118
161
|
res.writeHead(404).end();
|
|
119
162
|
return true;
|
|
120
163
|
}
|
|
121
|
-
let html = fs.readFileSync(filePath, 'utf8');
|
|
164
|
+
let html = withShellAssetOrigin(fs.readFileSync(filePath, 'utf8'), shellAssetOrigin(process.env.CASTLE_SHELL_ASSET_ORIGIN));
|
|
122
165
|
if (bootstrap)
|
|
123
166
|
html = html.replace(/<head(\s[^>]*)?>/i, (head) => `${head}${bootstrap(req)}`);
|
|
124
167
|
res.writeHead(200, {
|