@skgo/sveltekit-adapter 0.31.0 → 0.32.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 +1 -1
- package/skgo-adapter/env-private.js +1 -0
- package/skgo-adapter/env.js +50 -1
- package/skgo-adapter.js +2 -2
package/package.json
CHANGED
|
@@ -11,6 +11,7 @@ export function protectEnvironmentFiles({ root, kitOut, output, base = '/', toke
|
|
|
11
11
|
const files = [
|
|
12
12
|
resolve(root, '.svelte-kit/skgo-env-values.js'),
|
|
13
13
|
resolve(root, '.svelte-kit/skgo-env-runtime.json'),
|
|
14
|
+
resolve(root, '.svelte-kit/skgo-dev-supervisor.json'),
|
|
14
15
|
resolve(root, kitOut, 'generated/build/env/config.js'),
|
|
15
16
|
resolve(root, kitOut, 'generated/dev/env/config.js'),
|
|
16
17
|
resolve(root, output, 'env.json')
|
package/skgo-adapter/env.js
CHANGED
|
@@ -29,7 +29,7 @@ import { execFileSync } from 'node:child_process';
|
|
|
29
29
|
import { createHash, randomBytes } from 'node:crypto';
|
|
30
30
|
import { protectEnvironmentFiles } from './env-private.js';
|
|
31
31
|
import { existsSync, readdirSync, readFileSync, realpathSync, rmSync, statSync, mkdirSync, writeFileSync, chmodSync } from 'node:fs';
|
|
32
|
-
import { dirname, isAbsolute, join, relative, resolve } from 'node:path';
|
|
32
|
+
import { dirname, isAbsolute, join, posix as posixPath, relative, resolve } from 'node:path';
|
|
33
33
|
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -1268,6 +1268,55 @@ function errorText(e) {
|
|
|
1268
1268
|
// Values are validated by Go once before Kit loads its environment declaration.
|
|
1269
1269
|
// This must be a real file: Kit imports env.ts in a separate Vite server with
|
|
1270
1270
|
// configFile:false, where this adapter's virtual modules do not exist.
|
|
1271
|
+
// The Go supervisor publishes readiness through Vite's existing HMR protocol.
|
|
1272
|
+
// This is adapter glue: the browser keeps using Vite's own client and overlay.
|
|
1273
|
+
export function goSupervisorReload() {
|
|
1274
|
+
return {
|
|
1275
|
+
name: 'skgo-supervisor-reload',
|
|
1276
|
+
configureServer(server) {
|
|
1277
|
+
const token = randomBytes(32).toString('hex');
|
|
1278
|
+
const file = join(server.config.root, '.svelte-kit/skgo-dev-supervisor.json');
|
|
1279
|
+
// Vite's client imports @vite/env. Import analysis rewrites that to
|
|
1280
|
+
// its installed env.mjs, either under root or through /@fs/. Publish
|
|
1281
|
+
// only this exact bootstrap dependency, never an application prefix.
|
|
1282
|
+
const envFile = app.resolve('vite/dist/client/env.mjs').replaceAll('\\', '/');
|
|
1283
|
+
const root = server.config.root.replaceAll('\\', '/').replace(/\/$/, '');
|
|
1284
|
+
const envURL = envFile.startsWith(root + '/') ? envFile.slice(root.length) : posixPath.join('/@fs/', envFile);
|
|
1285
|
+
const clientFiles = [server.config.base.replace(/\/$/, '') + envURL];
|
|
1286
|
+
mkdirSync(dirname(file), { recursive: true });
|
|
1287
|
+
writeFileSync(file, JSON.stringify({ token, base: server.config.base, clientFiles }), { mode: 0o600 });
|
|
1288
|
+
chmodSync(file, 0o600);
|
|
1289
|
+
let failure;
|
|
1290
|
+
server.ws.on('vite:client:connect', (_, client) => {
|
|
1291
|
+
if (failure) client.send(failure);
|
|
1292
|
+
});
|
|
1293
|
+
server.middlewares.use((req, res, next) => {
|
|
1294
|
+
if ((req.url || '').split('?')[0] !== '/__skgo_dev/supervisor') return next();
|
|
1295
|
+
if (req.method !== 'POST' || req.headers['x-skgo-dev-token'] !== token) {
|
|
1296
|
+
res.statusCode = 403; res.end('Forbidden'); return;
|
|
1297
|
+
}
|
|
1298
|
+
let body = '', size = 0;
|
|
1299
|
+
req.setEncoding('utf8');
|
|
1300
|
+
req.on('data', chunk => {
|
|
1301
|
+
size += Buffer.byteLength(chunk);
|
|
1302
|
+
if (size <= 1048576) body += chunk;
|
|
1303
|
+
});
|
|
1304
|
+
req.on('end', () => {
|
|
1305
|
+
let message;
|
|
1306
|
+
try { message = JSON.parse(body); } catch {}
|
|
1307
|
+
if (size > 1048576 || !message || typeof message.diagnostic !== 'string') {
|
|
1308
|
+
res.statusCode = 400; res.end('Invalid supervisor status'); return;
|
|
1309
|
+
}
|
|
1310
|
+
failure = message.diagnostic ? { type: 'error', err: { message: message.diagnostic, stack: '', plugin: 'skgo' } } : undefined;
|
|
1311
|
+
// Kit also omits path for full-reload: app.html is not the page URL.
|
|
1312
|
+
server.ws.send(failure || { type: 'full-reload' });
|
|
1313
|
+
res.statusCode = 204; res.end();
|
|
1314
|
+
});
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1317
|
+
};
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1271
1320
|
export function goEnvironmentValues(output = 'build') {
|
|
1272
1321
|
let token = '';
|
|
1273
1322
|
let kitOut = '.svelte-kit';
|
package/skgo-adapter.js
CHANGED
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
remoteEndpoint,
|
|
22
22
|
remoteLoad
|
|
23
23
|
} from './skgo-adapter/prerender.js';
|
|
24
|
-
import { gojaDevEnvironment, gojaDevUnchangedFiles, gojaEnvironment, goEnvironmentValues, nodeTable, SSR_TARGET } from './skgo-adapter/env.js';
|
|
24
|
+
import { gojaDevEnvironment, gojaDevUnchangedFiles, gojaEnvironment, goEnvironmentValues, goSupervisorReload, nodeTable, SSR_TARGET } from './skgo-adapter/env.js';
|
|
25
25
|
import { prerenderModules } from './skgo-adapter/prerender-modules.js';
|
|
26
26
|
import { identity } from './skgo-adapter/identity.js';
|
|
27
27
|
import { checkEndpoints, validateGenerated } from './skgo-adapter/generated.js';
|
|
@@ -116,7 +116,7 @@ export default function skgo({ out = 'build', precompress = true, prerenderPacka
|
|
|
116
116
|
// compiles the SSR bundle in is also declared in `vite dev`, where Go
|
|
117
117
|
// pulls one transformed module at a time out of it instead. Each plugin
|
|
118
118
|
// states its own `apply`, so only one of them is ever live.
|
|
119
|
-
vite: { plugins: { pre: [prerenderOwnerPlugin, prerenderModules()], post: [environment.plugin, goja.plugin, gojaDevEnvironment(), gojaDevUnchangedFiles({ out })] } },
|
|
119
|
+
vite: { plugins: { pre: [prerenderOwnerPlugin, prerenderModules()], post: [environment.plugin, goSupervisorReload(), goja.plugin, gojaDevEnvironment(), gojaDevUnchangedFiles({ out })] } },
|
|
120
120
|
async adapt(builder) {
|
|
121
121
|
let failure;
|
|
122
122
|
try {
|