@vesk/adapter 0.0.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/README.md +21 -0
- package/dist/api-function.d.ts +7 -0
- package/dist/api-function.d.ts.map +1 -0
- package/dist/api-function.js +187 -0
- package/dist/client-bundle.d.ts +19 -0
- package/dist/client-bundle.d.ts.map +1 -0
- package/dist/client-bundle.js +491 -0
- package/dist/dev-server.d.ts +4 -0
- package/dist/dev-server.d.ts.map +1 -0
- package/dist/dev-server.js +358 -0
- package/dist/esbuild-fallback.d.ts +3 -0
- package/dist/esbuild-fallback.d.ts.map +1 -0
- package/dist/esbuild-fallback.js +64 -0
- package/dist/hmr.d.ts +7 -0
- package/dist/hmr.d.ts.map +1 -0
- package/dist/hmr.js +411 -0
- package/dist/image-pipeline.d.ts +3 -0
- package/dist/image-pipeline.d.ts.map +1 -0
- package/dist/image-pipeline.js +120 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +291 -0
- package/dist/manifest.d.ts +3 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +47 -0
- package/dist/middleware.d.ts +4 -0
- package/dist/middleware.d.ts.map +1 -0
- package/dist/middleware.js +96 -0
- package/dist/package.json +15 -0
- package/dist/platform-deploy.d.ts +18 -0
- package/dist/platform-deploy.d.ts.map +1 -0
- package/dist/platform-deploy.js +354 -0
- package/dist/platform-handler.d.ts +32 -0
- package/dist/platform-handler.d.ts.map +1 -0
- package/dist/platform-handler.js +211 -0
- package/dist/platform-output.d.ts +30 -0
- package/dist/platform-output.d.ts.map +1 -0
- package/dist/platform-output.js +119 -0
- package/dist/platform.d.ts +17 -0
- package/dist/platform.d.ts.map +1 -0
- package/dist/platform.js +35 -0
- package/dist/prod-server.d.ts +5 -0
- package/dist/prod-server.d.ts.map +1 -0
- package/dist/prod-server.js +429 -0
- package/dist/runtime-bundle.d.ts +2 -0
- package/dist/runtime-bundle.d.ts.map +1 -0
- package/dist/runtime-bundle.js +140 -0
- package/dist/seo-audit.d.ts +3 -0
- package/dist/seo-audit.d.ts.map +1 -0
- package/dist/seo-audit.js +169 -0
- package/dist/ssr-function.d.ts +8 -0
- package/dist/ssr-function.d.ts.map +1 -0
- package/dist/ssr-function.js +415 -0
- package/dist/static.d.ts +8 -0
- package/dist/static.d.ts.map +1 -0
- package/dist/static.js +130 -0
- package/dist/types.d.ts +182 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,358 @@
|
|
|
1
|
+
import { readFileSync, existsSync, watch, statSync } from 'node:fs';
|
|
2
|
+
import { resolve, extname, dirname } from 'node:path';
|
|
3
|
+
import { createServer } from 'node:http';
|
|
4
|
+
import { fileURLToPath } from 'node:url';
|
|
5
|
+
import { transformSync } from './esbuild-fallback.js';
|
|
6
|
+
import { build } from '@vesk/adapter/src/index';
|
|
7
|
+
import { createHmrServer } from '@vesk/adapter/src/hmr';
|
|
8
|
+
import { buildRuntimeCode } from '@vesk/adapter/src/client-bundle';
|
|
9
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
10
|
+
async function readBody(req) {
|
|
11
|
+
const chunks = [];
|
|
12
|
+
for await (const chunk of req)
|
|
13
|
+
chunks.push(chunk);
|
|
14
|
+
return Buffer.concat(chunks);
|
|
15
|
+
}
|
|
16
|
+
function makeWebRequest(nodeReq, url) {
|
|
17
|
+
const parsedUrl = new URL(url, `http://${nodeReq.headers.host || 'localhost'}`);
|
|
18
|
+
const method = nodeReq.method || 'GET';
|
|
19
|
+
let _bodyBuffer = null;
|
|
20
|
+
async function getBody() {
|
|
21
|
+
if (_bodyBuffer)
|
|
22
|
+
return _bodyBuffer;
|
|
23
|
+
const chunks = [];
|
|
24
|
+
for await (const chunk of nodeReq)
|
|
25
|
+
chunks.push(Buffer.from(chunk));
|
|
26
|
+
_bodyBuffer = Buffer.concat(chunks);
|
|
27
|
+
return _bodyBuffer;
|
|
28
|
+
}
|
|
29
|
+
const webRequest = new Request(parsedUrl, { method, headers: nodeReq.headers, body: null });
|
|
30
|
+
webRequest.json = async () => { try {
|
|
31
|
+
return JSON.parse((await getBody()).toString());
|
|
32
|
+
}
|
|
33
|
+
catch {
|
|
34
|
+
return null;
|
|
35
|
+
} };
|
|
36
|
+
webRequest.text = async () => (await getBody()).toString('utf-8');
|
|
37
|
+
webRequest.formData = async () => {
|
|
38
|
+
const body = await getBody();
|
|
39
|
+
const ct = String(nodeReq.headers['content-type'] || '');
|
|
40
|
+
if (ct.includes('multipart/form-data')) {
|
|
41
|
+
const temp = new Request('http://localhost', { method: 'POST', headers: nodeReq.headers, body: body });
|
|
42
|
+
return temp.formData();
|
|
43
|
+
}
|
|
44
|
+
const fd = new FormData();
|
|
45
|
+
if (ct.includes('x-www-form-urlencoded')) {
|
|
46
|
+
for (const [k, v] of new URLSearchParams(body.toString()).entries())
|
|
47
|
+
fd.append(k, v);
|
|
48
|
+
}
|
|
49
|
+
return fd;
|
|
50
|
+
};
|
|
51
|
+
webRequest.clone = () => webRequest;
|
|
52
|
+
return webRequest;
|
|
53
|
+
}
|
|
54
|
+
const MIME = {
|
|
55
|
+
'.svg': 'image/svg+xml', '.css': 'text/css', '.js': 'application/javascript',
|
|
56
|
+
'.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg',
|
|
57
|
+
'.ico': 'image/x-icon', '.html': 'text/html', '.json': 'application/json',
|
|
58
|
+
'.woff': 'font/woff', '.woff2': 'font/woff2', '.wasm': 'application/wasm',
|
|
59
|
+
};
|
|
60
|
+
export async function startDevServer(appDir, options) {
|
|
61
|
+
const port = options?.port || 3000;
|
|
62
|
+
const devDir = resolve(appDir, '..', '.vesk', 'dev');
|
|
63
|
+
const publicDir = options?.publicDir || resolve(appDir, '..', 'public');
|
|
64
|
+
let componentMap = new Map();
|
|
65
|
+
const monorepoRouter = resolve(__dirname, '..', '..', 'compiler', 'dist', 'router.js');
|
|
66
|
+
const pkgRouter = resolve(appDir, '..', 'node_modules', '@vesk/compiler', 'router.js');
|
|
67
|
+
const routerPath = existsSync(monorepoRouter) ? monorepoRouter : (existsSync(pkgRouter) ? pkgRouter : null);
|
|
68
|
+
if (routerPath) {
|
|
69
|
+
const { scanComponents } = await import(routerPath);
|
|
70
|
+
const componentsDir = resolve(appDir, '..', 'components');
|
|
71
|
+
if (existsSync(componentsDir)) {
|
|
72
|
+
componentMap = scanComponents(componentsDir);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let config = null;
|
|
76
|
+
let lastBuild = 0;
|
|
77
|
+
let ssrVersion = Date.now();
|
|
78
|
+
let routeTree = [];
|
|
79
|
+
let runtimeBundle = '';
|
|
80
|
+
async function doBuild() {
|
|
81
|
+
const start = Date.now();
|
|
82
|
+
try {
|
|
83
|
+
const result = await build(appDir, { outDir: devDir, publicDir, hmr: true });
|
|
84
|
+
const configPath = resolve(devDir, 'config.json');
|
|
85
|
+
if (existsSync(configPath)) {
|
|
86
|
+
config = JSON.parse(readFileSync(configPath, 'utf-8'));
|
|
87
|
+
}
|
|
88
|
+
if (result)
|
|
89
|
+
routeTree = result.routeTree;
|
|
90
|
+
const monorepoRoot = resolve(__dirname, '..', '..', '..');
|
|
91
|
+
const runtimeDir = resolve(monorepoRoot, 'packages', 'runtime', 'dist');
|
|
92
|
+
runtimeBundle = buildRuntimeCode(runtimeDir);
|
|
93
|
+
lastBuild = Date.now();
|
|
94
|
+
console.error(`vesk dev: rebuilt in ${Date.now() - start}ms`);
|
|
95
|
+
}
|
|
96
|
+
catch (e) {
|
|
97
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
98
|
+
console.error(`vesk dev: build error: ${message}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
await doBuild();
|
|
102
|
+
const server = createServer(async (req, res) => {
|
|
103
|
+
const url = new URL(req.url || '/', `http://localhost:${port}`);
|
|
104
|
+
if (url.pathname === '/_vesk/hmr.js') {
|
|
105
|
+
const monorepoRoot = resolve(__dirname, '..', '..', '..');
|
|
106
|
+
const runtimeSrc = resolve(monorepoRoot, 'packages', 'runtime', 'dist');
|
|
107
|
+
const hmrJsPath = resolve(runtimeSrc, 'hmr-client.js');
|
|
108
|
+
const hmrTsPath = resolve(runtimeSrc, 'hmr-client.ts');
|
|
109
|
+
const hmrPath = existsSync(hmrJsPath) ? hmrJsPath : (existsSync(hmrTsPath) ? hmrTsPath : null);
|
|
110
|
+
if (hmrPath) {
|
|
111
|
+
let hmrContent = readFileSync(hmrPath, 'utf-8');
|
|
112
|
+
if (hmrPath.endsWith('.ts')) {
|
|
113
|
+
hmrContent = transformSync(hmrContent, { loader: 'ts' }).code;
|
|
114
|
+
}
|
|
115
|
+
res.writeHead(200, { 'Content-Type': 'application/javascript' });
|
|
116
|
+
res.end(hmrContent);
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
if (url.pathname === '/_vesk/runtime.js') {
|
|
121
|
+
res.writeHead(200, { 'Content-Type': 'application/javascript' });
|
|
122
|
+
res.end(runtimeBundle);
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
if (url.pathname.startsWith('/_vesk/static/')) {
|
|
126
|
+
const relPath = url.pathname.replace('/_vesk/static/', '').replace(/\.\./g, '');
|
|
127
|
+
const staticPath = resolve(devDir, 'static', relPath);
|
|
128
|
+
if (!staticPath.startsWith(resolve(devDir, 'static'))) {
|
|
129
|
+
res.writeHead(403);
|
|
130
|
+
res.end('Forbidden');
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (existsSync(staticPath) && statSync(staticPath).isFile()) {
|
|
134
|
+
const ext = extname(staticPath);
|
|
135
|
+
res.writeHead(200, { 'Content-Type': MIME[ext] || 'application/octet-stream' });
|
|
136
|
+
res.end(readFileSync(staticPath));
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (url.pathname !== '/') {
|
|
141
|
+
const sanitized = url.pathname.replace(/\.\./g, '');
|
|
142
|
+
const sourcePath = resolve(publicDir, sanitized.slice(1));
|
|
143
|
+
if (sourcePath.startsWith(publicDir) && existsSync(sourcePath) && statSync(sourcePath).isFile()) {
|
|
144
|
+
const ext = extname(sourcePath);
|
|
145
|
+
res.writeHead(200, { 'Content-Type': MIME[ext] || 'application/octet-stream' });
|
|
146
|
+
res.end(readFileSync(sourcePath));
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const buildPublicDir = resolve(devDir, 'static', 'public');
|
|
150
|
+
const buildPath = resolve(buildPublicDir, sanitized.slice(1));
|
|
151
|
+
if (buildPath.startsWith(buildPublicDir) && existsSync(buildPath) && statSync(buildPath).isFile()) {
|
|
152
|
+
const ext = extname(buildPath);
|
|
153
|
+
res.writeHead(200, { 'Content-Type': MIME[ext] || 'application/octet-stream' });
|
|
154
|
+
res.end(readFileSync(buildPath));
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
if (config && url.pathname.startsWith('/_vesk/action/')) {
|
|
159
|
+
const actionId = url.pathname.replace('/_vesk/action/', '');
|
|
160
|
+
const actionEntry = config.actions && config.actions.find(a => a.id === actionId);
|
|
161
|
+
if (actionEntry) {
|
|
162
|
+
const handlerPath = resolve(devDir, actionEntry.function);
|
|
163
|
+
if (existsSync(handlerPath)) {
|
|
164
|
+
try {
|
|
165
|
+
const mod = await import(`${handlerPath}?t=${ssrVersion}`);
|
|
166
|
+
if (mod.handleAction) {
|
|
167
|
+
const webRequest = makeWebRequest(req, url.href);
|
|
168
|
+
const response = await mod.handleAction(webRequest, actionId);
|
|
169
|
+
const body = await response.text();
|
|
170
|
+
const headers = Object.fromEntries(response.headers);
|
|
171
|
+
const contentType = headers['content-type'] || '';
|
|
172
|
+
let finalBody = body;
|
|
173
|
+
if (contentType.includes('text/html')) {
|
|
174
|
+
finalBody = body.replace('</body>', '\t<script type="module" src="/_vesk/hmr.js"></script>\n</body>');
|
|
175
|
+
}
|
|
176
|
+
res.writeHead(response.status, headers);
|
|
177
|
+
res.end(finalBody);
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
catch (e) {
|
|
182
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
183
|
+
res.end(JSON.stringify({ ok: false, error: e instanceof Error ? e.message : String(e) }));
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
res.writeHead(404, { 'Content-Type': 'application/json' });
|
|
189
|
+
res.end(JSON.stringify({ ok: false, error: 'Action not found' }));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (config && url.pathname.startsWith('/api')) {
|
|
193
|
+
const apiRoute = config.routes.find(r => r.type === 'api' && matchPath(r.path, url.pathname));
|
|
194
|
+
if (apiRoute) {
|
|
195
|
+
const handlerPath = resolve(devDir, apiRoute.function);
|
|
196
|
+
if (existsSync(handlerPath)) {
|
|
197
|
+
try {
|
|
198
|
+
const mod = await import(`${handlerPath}?t=${ssrVersion}`);
|
|
199
|
+
const webRequest = makeWebRequest(req, url.href);
|
|
200
|
+
const response = await mod.handle(webRequest);
|
|
201
|
+
const body = await response.text();
|
|
202
|
+
res.writeHead(response.status, Object.fromEntries(response.headers));
|
|
203
|
+
res.end(body);
|
|
204
|
+
}
|
|
205
|
+
catch (e) {
|
|
206
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
207
|
+
res.writeHead(500, { 'Content-Type': 'application/json' });
|
|
208
|
+
res.end(JSON.stringify({ error: message }));
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
if (config) {
|
|
215
|
+
const ssrRoute = config.routes.find(r => r.type === 'ssr' && matchPath(r.path, url.pathname));
|
|
216
|
+
if (ssrRoute) {
|
|
217
|
+
const handlerPath = resolve(devDir, ssrRoute.function);
|
|
218
|
+
if (existsSync(handlerPath)) {
|
|
219
|
+
try {
|
|
220
|
+
const mod = await import(`${handlerPath}?t=${ssrVersion}`);
|
|
221
|
+
const webRequest = makeWebRequest(req, url.href);
|
|
222
|
+
const response = await mod.handle(webRequest);
|
|
223
|
+
const body = await response.text();
|
|
224
|
+
const headers = Object.fromEntries(response.headers);
|
|
225
|
+
const contentType = headers['content-type'] || '';
|
|
226
|
+
let finalBody = body;
|
|
227
|
+
if (contentType.includes('text/html')) {
|
|
228
|
+
finalBody = body.replace('</body>', '\t<script type="module" src="/_vesk/hmr.js"></script>\n</body>');
|
|
229
|
+
}
|
|
230
|
+
res.writeHead(response.status, headers);
|
|
231
|
+
res.end(finalBody);
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
res.writeHead(500, { 'Content-Type': 'text/html' });
|
|
235
|
+
res.end('<!DOCTYPE html><html><body><h1>500</h1><pre>Internal Server Error</pre></body></html>');
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (config) {
|
|
242
|
+
const rootRoute = config.routes.find(r => r.type === 'ssr' && r.path === '/');
|
|
243
|
+
if (rootRoute) {
|
|
244
|
+
const handlerPath = resolve(devDir, rootRoute.function);
|
|
245
|
+
if (existsSync(handlerPath)) {
|
|
246
|
+
try {
|
|
247
|
+
const mod = await import(`${handlerPath}?t=${ssrVersion}`);
|
|
248
|
+
const webRequest = makeWebRequest(req, url.href);
|
|
249
|
+
const response = await mod.handle(webRequest);
|
|
250
|
+
const body = await response.text();
|
|
251
|
+
const headers = Object.fromEntries(response.headers);
|
|
252
|
+
const contentType = headers['content-type'] || '';
|
|
253
|
+
let finalBody = body;
|
|
254
|
+
if (contentType.includes('text/html')) {
|
|
255
|
+
finalBody = body.replace('</body>', '\t<script type="module" src="/_vesk/hmr.js"></script>\n</body>');
|
|
256
|
+
}
|
|
257
|
+
res.writeHead(200, headers);
|
|
258
|
+
res.end(finalBody);
|
|
259
|
+
}
|
|
260
|
+
catch (e) {
|
|
261
|
+
res.writeHead(500, { 'Content-Type': 'text/html' });
|
|
262
|
+
res.end('<!DOCTYPE html><html><body><h1>500</h1><pre>Internal Server Error</pre></body></html>');
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
res.writeHead(404, { 'Content-Type': 'text/html' });
|
|
269
|
+
res.end('<!DOCTYPE html><html><body><h1>404</h1><p>Not Found</p></body></html>');
|
|
270
|
+
});
|
|
271
|
+
const hmr = createHmrServer(server, appDir, devDir, componentMap);
|
|
272
|
+
const srcDir = resolve(appDir, '..', 'src');
|
|
273
|
+
try {
|
|
274
|
+
if (existsSync(srcDir)) {
|
|
275
|
+
watch(srcDir, { recursive: true }, (_eventType, filename) => {
|
|
276
|
+
if (!filename)
|
|
277
|
+
return;
|
|
278
|
+
if (filename.endsWith('.css')) {
|
|
279
|
+
doBuild();
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
catch {
|
|
285
|
+
// src/ dir not available
|
|
286
|
+
}
|
|
287
|
+
let debounceTimer = null;
|
|
288
|
+
let pendingFiles = new Set();
|
|
289
|
+
try {
|
|
290
|
+
watch(appDir, { recursive: true }, (_eventType, filename) => {
|
|
291
|
+
if (!filename)
|
|
292
|
+
return;
|
|
293
|
+
if (debounceTimer)
|
|
294
|
+
clearTimeout(debounceTimer);
|
|
295
|
+
pendingFiles.add(filename);
|
|
296
|
+
debounceTimer = setTimeout(() => {
|
|
297
|
+
const files = [...pendingFiles];
|
|
298
|
+
pendingFiles = new Set();
|
|
299
|
+
const configFiles = files.filter(f => f === 'vesk.config.ts' || f === 'vesk.config.js' ||
|
|
300
|
+
f === 'tsconfig.json' || f === 'package.json' ||
|
|
301
|
+
f.endsWith('/vesk.config.ts') || f.endsWith('/vesk.config.js') ||
|
|
302
|
+
f.endsWith('/tsconfig.json') || f.endsWith('/package.json'));
|
|
303
|
+
const apiMiddlewareFiles = files.filter(f => (f.includes('/api/') || f === 'middleware.ts' || f.endsWith('/middleware.ts')) &&
|
|
304
|
+
(f.endsWith('.ts') || f.endsWith('.js')));
|
|
305
|
+
const vskFiles = files.filter(f => f.endsWith('.vsk'));
|
|
306
|
+
if (configFiles.length > 0) {
|
|
307
|
+
hmr.handleFileChange(configFiles[0], doBuild, routeTree);
|
|
308
|
+
}
|
|
309
|
+
else if (apiMiddlewareFiles.length > 0) {
|
|
310
|
+
hmr.handleFileChange(apiMiddlewareFiles[0], doBuild, routeTree);
|
|
311
|
+
}
|
|
312
|
+
else if (vskFiles.length > 0) {
|
|
313
|
+
(async () => {
|
|
314
|
+
for (const f of vskFiles) {
|
|
315
|
+
await hmr.handleFileChange(f, doBuild, routeTree);
|
|
316
|
+
}
|
|
317
|
+
ssrVersion = Date.now();
|
|
318
|
+
})();
|
|
319
|
+
}
|
|
320
|
+
else if (files.length > 0) {
|
|
321
|
+
hmr.handleFileChange(files[0], doBuild, routeTree);
|
|
322
|
+
}
|
|
323
|
+
}, 200);
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
catch (e) {
|
|
327
|
+
console.error('vesk dev: file watching unavailable');
|
|
328
|
+
}
|
|
329
|
+
await new Promise(resolve => {
|
|
330
|
+
server.listen(port, () => {
|
|
331
|
+
console.error(`vesk dev server at http://localhost:${port}`);
|
|
332
|
+
resolve();
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
if (options?.block !== false) {
|
|
336
|
+
await new Promise(() => { });
|
|
337
|
+
}
|
|
338
|
+
return server;
|
|
339
|
+
}
|
|
340
|
+
function matchPath(pattern, pathname) {
|
|
341
|
+
const patternParts = pattern.split('/').filter(Boolean);
|
|
342
|
+
const pathParts = pathname.split('/').filter(Boolean);
|
|
343
|
+
let pi = 0, pp = 0;
|
|
344
|
+
while (pi < pathParts.length && pp < patternParts.length) {
|
|
345
|
+
if (patternParts[pp].startsWith(':')) {
|
|
346
|
+
pi++;
|
|
347
|
+
pp++;
|
|
348
|
+
}
|
|
349
|
+
else if (patternParts[pp] === pathParts[pi]) {
|
|
350
|
+
pi++;
|
|
351
|
+
pp++;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
return false;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
return pp === patternParts.length && pi === pathParts.length;
|
|
358
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild-fallback.d.ts","sourceRoot":"","sources":["../src/esbuild-fallback.ts"],"names":[],"mappings":"AA8BA,wBAAsB,KAAK,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,CAgBtD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,GAAG,GAAG,CAa9D"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
let _nativeBuild = null;
|
|
2
|
+
let _nativeTransform = null;
|
|
3
|
+
let _wasm = null;
|
|
4
|
+
let _wasmReady = null;
|
|
5
|
+
async function loadNative() {
|
|
6
|
+
if (_nativeBuild && _nativeTransform)
|
|
7
|
+
return;
|
|
8
|
+
try {
|
|
9
|
+
const m = await import('esbuild');
|
|
10
|
+
_nativeBuild = m.build.bind(m);
|
|
11
|
+
_nativeTransform = m.transformSync.bind(m);
|
|
12
|
+
}
|
|
13
|
+
catch {
|
|
14
|
+
// native esbuild not installed
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
async function getWasm() {
|
|
18
|
+
if (_wasm)
|
|
19
|
+
return _wasm;
|
|
20
|
+
if (!_wasmReady) {
|
|
21
|
+
_wasmReady = import('esbuild-wasm').then(m => {
|
|
22
|
+
_wasm = m;
|
|
23
|
+
return m;
|
|
24
|
+
}).catch(() => {
|
|
25
|
+
_wasmReady = null;
|
|
26
|
+
throw new Error('esbuild-wasm not available');
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return _wasmReady;
|
|
30
|
+
}
|
|
31
|
+
export async function build(options) {
|
|
32
|
+
await loadNative();
|
|
33
|
+
if (_nativeBuild) {
|
|
34
|
+
try {
|
|
35
|
+
return await _nativeBuild(options);
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
39
|
+
if (msg.includes('SIGILL') || msg.includes('illegal hardware instruction') || msg.includes('cannot execute binary file')) {
|
|
40
|
+
console.warn('vesk: native esbuild failed, falling back to esbuild-wasm:', msg);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
throw e;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const wasm = await getWasm();
|
|
48
|
+
return wasm.build(options);
|
|
49
|
+
}
|
|
50
|
+
export function transformSync(code, options) {
|
|
51
|
+
if (_nativeTransform) {
|
|
52
|
+
try {
|
|
53
|
+
return _nativeTransform(code, options);
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
const msg = e instanceof Error ? e.message : String(e);
|
|
57
|
+
if (msg.includes('SIGILL') || msg.includes('illegal hardware instruction') || msg.includes('cannot execute binary file')) {
|
|
58
|
+
throw new Error('esbuild-wasm fallback for transformSync not yet implemented — use native esbuild or convert to async transform');
|
|
59
|
+
}
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
throw new Error('esbuild not installed — run `npm install esbuild` or use `vesk build` which falls back to esbuild-wasm for bundling');
|
|
64
|
+
}
|
package/dist/hmr.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { Server } from 'node:http';
|
|
2
|
+
import type { RouteNode } from '@vesk/adapter/src/types';
|
|
3
|
+
export declare function createHmrServer(httpServer: Server, appDir: string, devDir: string, componentMap?: Map<string, string>): {
|
|
4
|
+
broadcast: (type: string, data?: Record<string, unknown>) => void;
|
|
5
|
+
handleFileChange: (filename: string | null, doFullBuild: () => Promise<void>, routeTree: RouteNode[]) => Promise<void>;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=hmr.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hmr.d.ts","sourceRoot":"","sources":["../src/hmr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAOxC,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,yBAAyB,CAAC;AA6RzE,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,YAAY,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACjC;IAAE,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IAAC,gBAAgB,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAAE,CAkH/L"}
|