veryfront 0.1.626 → 0.1.627
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/esm/deno.js +1 -1
- package/esm/src/platform/adapters/runtime/deno/adapter.d.ts.map +1 -1
- package/esm/src/platform/adapters/runtime/deno/adapter.js +5 -2
- package/esm/src/platform/compat/http/websocket.js +9 -2
- package/esm/src/routing/api/module-loader/external-import-rewriter.d.ts +15 -1
- package/esm/src/routing/api/module-loader/external-import-rewriter.d.ts.map +1 -1
- package/esm/src/routing/api/module-loader/external-import-rewriter.js +106 -2
- package/esm/src/routing/api/module-loader/loader.d.ts +1 -1
- package/esm/src/routing/api/module-loader/loader.d.ts.map +1 -1
- package/esm/src/routing/api/module-loader/loader.js +1 -1
- package/esm/src/server/handlers/preview/hmr.handler.d.ts.map +1 -1
- package/esm/src/server/handlers/preview/hmr.handler.js +5 -0
- package/esm/src/utils/version-constant.d.ts +1 -1
- package/esm/src/utils/version-constant.js +1 -1
- package/package.json +1 -1
package/esm/deno.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../../../../src/src/platform/adapters/runtime/deno/adapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,QAAQ,EACR,kBAAkB,EAElB,QAAQ,EACR,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,MAAM,EACN,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,gBAAgB,EACjB,MAAM,eAAe,CAAC;AAyHvB,cAAM,qBAAsB,YAAW,iBAAiB;IAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKvC,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,UAAU,CAAC;IAKhD,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;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G,gBAAgB;CAYrD;AAED,cAAM,gBAAiB,YAAW,YAAY;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,WAAW,EAAE,OAAO,CAAA;KAAE;IAejE,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;CAanC;AAwBD,qBAAa,WAAY,YAAW,cAAc;IAChD,QAAQ,CAAC,EAAE,EAAG,MAAM,CAAU;IAC9B,QAAQ,CAAC,IAAI,UAAU;IACvB,QAAQ,CAAC,EAAE,wBAA+B;IAC1C,QAAQ,CAAC,GAAG,yBAAgC;IAC5C,QAAQ,CAAC,MAAM,oBAA2B;IAC1C,QAAQ,CAAC,KAAK,mBAA0B;IAExC,QAAQ,CAAC,YAAY;;;;;;;;;;MAUnB;IAEF,OAAO,CAAC,YAAY,CAA2B;IAE/C,KAAK,CACH,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,EAC3D,OAAO,GAAE,YAAiB,GACzB,OAAO,CAAC,MAAM,CAAC;IAuEZ,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAGhC;AAED,eAAO,MAAM,WAAW,aAAoB,CAAC"}
|
|
@@ -212,12 +212,15 @@ class DenoEnvironmentAdapter {
|
|
|
212
212
|
}
|
|
213
213
|
class DenoServerAdapter {
|
|
214
214
|
upgradeWebSocket(request) {
|
|
215
|
-
|
|
215
|
+
// Access native Deno via `self` to bypass dnt shim transform.
|
|
216
|
+
// dnt rewrites `globalThis.Deno` to @deno/shim-deno, which lacks upgradeWebSocket.
|
|
217
|
+
const nativeDeno = self["Deno"];
|
|
218
|
+
if (typeof nativeDeno?.upgradeWebSocket !== "function") {
|
|
216
219
|
throw NOT_SUPPORTED.create({
|
|
217
220
|
detail: "DenoServerAdapter.upgradeWebSocket() can only be used in Deno runtime",
|
|
218
221
|
});
|
|
219
222
|
}
|
|
220
|
-
const { socket, response } =
|
|
223
|
+
const { socket, response } = nativeDeno.upgradeWebSocket(request);
|
|
221
224
|
return { socket, response };
|
|
222
225
|
}
|
|
223
226
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
1
|
import { isDeno } from "../runtime.js";
|
|
3
2
|
import { NOT_SUPPORTED } from "../../../errors/index.js";
|
|
4
3
|
export function upgradeWebSocket(request, options) {
|
|
@@ -14,9 +13,17 @@ export function isWebSocketUpgrade(request) {
|
|
|
14
13
|
return request.headers.get("upgrade")?.toLowerCase() === "websocket";
|
|
15
14
|
}
|
|
16
15
|
function upgradeWebSocketDeno(request, options) {
|
|
16
|
+
// Access native Deno via `self` to bypass dnt shim transform.
|
|
17
|
+
// dnt rewrites `globalThis.Deno` to @deno/shim-deno, which lacks upgradeWebSocket.
|
|
18
|
+
const nativeDeno = self["Deno"];
|
|
19
|
+
if (typeof nativeDeno?.upgradeWebSocket !== "function") {
|
|
20
|
+
throw NOT_SUPPORTED.create({
|
|
21
|
+
detail: "Deno.upgradeWebSocket() is not available in this runtime.",
|
|
22
|
+
});
|
|
23
|
+
}
|
|
17
24
|
const denoOptions = options?.protocol
|
|
18
25
|
? { protocol: options.protocol }
|
|
19
26
|
: undefined;
|
|
20
|
-
const { socket, response } =
|
|
27
|
+
const { socket, response } = nativeDeno.upgradeWebSocket(request, denoOptions);
|
|
21
28
|
return { socket, response };
|
|
22
29
|
}
|
|
@@ -15,12 +15,26 @@ export declare function readProjectDependencies(projectDir: string, fs: FileSyst
|
|
|
15
15
|
export declare function generateCompiledBinaryRequireShim(projectDir: string): string;
|
|
16
16
|
export declare function getNodeExternalPackagesToResolve(userDeps: Map<string, string>): string[];
|
|
17
17
|
export declare function resolveNodePackageToFileUrl(projectDir: string, packageName: string, fs: FileSystem, pathToFileURL: typeof import("node:url").pathToFileURL): Promise<string | null>;
|
|
18
|
+
/** Location of an ESM-only user dependency, used to rewrite imports to real ES module URLs. */
|
|
19
|
+
export interface EsmDependencyLocation {
|
|
20
|
+
/** file:// URL of the package's ESM entry point. */
|
|
21
|
+
entryUrl: string;
|
|
22
|
+
/** Absolute path of the package's root directory (used to contain subpath imports). */
|
|
23
|
+
packageDir: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Identify the subset of user dependencies that are ESM-only and resolve each
|
|
27
|
+
* to file:// URLs so the compiled-binary loader can import them as real ES
|
|
28
|
+
* modules instead of transpiling them to CommonJS. CJS dependencies are omitted
|
|
29
|
+
* and continue to load through the `createRequire`-based shim.
|
|
30
|
+
*/
|
|
31
|
+
export declare function resolveEsmUserDependencies(projectDir: string, fs: FileSystem, userDeps: Map<string, string>): Promise<Map<string, EsmDependencyLocation>>;
|
|
18
32
|
export declare function loadVeryfrontExportsMap(projectDir: string, fs: FileSystem): Promise<Record<string, {
|
|
19
33
|
import?: string;
|
|
20
34
|
}>>;
|
|
21
35
|
export declare function rewriteNodeExternalImports(code: string, projectDir: string, fs: FileSystem, userDeps: Map<string, string>): Promise<string>;
|
|
22
36
|
export declare function rewriteCompiledBinaryVeryfrontImports(code: string): string;
|
|
23
|
-
export declare function rewriteCompiledBinaryUserDependencyImports(code: string, userDeps: Map<string, string>): string;
|
|
37
|
+
export declare function rewriteCompiledBinaryUserDependencyImports(code: string, userDeps: Map<string, string>, esmDeps?: Map<string, EsmDependencyLocation>): string;
|
|
24
38
|
export declare function rewriteDenoNpmDependencyImports(code: string, projectDir: string, fs: FileSystem, userDeps: Map<string, string>): Promise<string>;
|
|
25
39
|
export declare function rewriteDenoNodeBuiltinImports(code: string): string;
|
|
26
40
|
export declare function rewriteExternalImports(code: string, projectDir: string, fs: FileSystem, userDeps?: Map<string, string>): Promise<string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../../src/src/routing/api/module-loader/external-import-rewriter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"external-import-rewriter.d.ts","sourceRoot":"","sources":["../../../../../src/src/routing/api/module-loader/external-import-rewriter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AASjE,wGAAwG;AACxG,eAAO,MAAM,aAAa,mVAkChB,CAAC;AAEX,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,GACb,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAS9B;AAED;;;;;;;;;GASG;AACH,wBAAgB,iCAAiC,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CA+E5E;AAED,wBAAgB,gCAAgC,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,EAAE,CAUxF;AAED,wBAAsB,2BAA2B,CAC/C,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,EAAE,EAAE,UAAU,EACd,aAAa,EAAE,cAAc,UAAU,EAAE,aAAa,GACrD,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAoBxB;AAED,+FAA+F;AAC/F,MAAM,WAAW,qBAAqB;IACpC,oDAAoD;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,uFAAuF;IACvF,UAAU,EAAE,MAAM,CAAC;CACpB;AAoCD;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAmC7C;AAED,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,GACb,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC,CAW9C;AAED,wBAAsB,0BAA0B,CAC9C,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CA6EjB;AAED,wBAAgB,qCAAqC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAqB1E;AAED,wBAAgB,0CAA0C,CACxD,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7B,OAAO,GAAE,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAa,GACtD,MAAM,CAgGR;AAED,wBAAsB,+BAA+B,CACnD,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,EACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GAC5B,OAAO,CAAC,MAAM,CAAC,CA0BjB;AAED,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAgBlE;AAED,wBAAsB,sBAAsB,CAC1C,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,UAAU,EACd,QAAQ,GAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAa,GACxC,OAAO,CAAC,MAAM,CAAC,CAmCjB"}
|
|
@@ -2,6 +2,7 @@ import { isCompiledBinary, serverLogger } from "../../../utils/index.js";
|
|
|
2
2
|
import * as pathHelper from "../../../platform/compat/path/index.js";
|
|
3
3
|
import { isDeno, isNode } from "../../../platform/compat/runtime.js";
|
|
4
4
|
import { rewriteNpmImports } from "../../../transforms/npm-import-rewrites.js";
|
|
5
|
+
import { isWithinDirectory } from "../../../security/path-validation.js";
|
|
5
6
|
import { resolveExportEntry, toCjsDestructureBindings } from "./loader-helpers.js";
|
|
6
7
|
const logger = serverLogger.component("api");
|
|
7
8
|
/** Node.js built-in module names — shared across the CJS shim, esbuild externals, and Deno rewrites. */
|
|
@@ -168,6 +169,79 @@ export async function resolveNodePackageToFileUrl(projectDir, packageName, fs, p
|
|
|
168
169
|
return null;
|
|
169
170
|
}
|
|
170
171
|
}
|
|
172
|
+
/**
|
|
173
|
+
* Decide whether an installed package must be loaded as a real ES module.
|
|
174
|
+
*
|
|
175
|
+
* ESM-only packages (e.g. `"type": "module"` packages that use `import.meta` or
|
|
176
|
+
* top-level await) cannot be evaluated as CommonJS via the compiled-binary
|
|
177
|
+
* `new Function` shim. We treat a package as ESM when its package.json declares
|
|
178
|
+
* `"type": "module"` or its resolved entry point is a `.mjs` file.
|
|
179
|
+
*/
|
|
180
|
+
function isEsmPackage(pkgJson, entry) {
|
|
181
|
+
if (pkgJson.type === "module")
|
|
182
|
+
return true;
|
|
183
|
+
return entry.endsWith(".mjs");
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Resolve a package's ESM entry point, preferring the conditional `import`
|
|
187
|
+
* export, then the `module` field, then `main`.
|
|
188
|
+
*/
|
|
189
|
+
function resolveEsmEntry(pkgJson) {
|
|
190
|
+
const exportsField = pkgJson.exports;
|
|
191
|
+
if (exportsField && typeof exportsField === "object") {
|
|
192
|
+
const dot = exportsField["."];
|
|
193
|
+
const fromExports = resolveExportEntry(dot ?? exportsField);
|
|
194
|
+
if (fromExports)
|
|
195
|
+
return fromExports;
|
|
196
|
+
}
|
|
197
|
+
else if (typeof exportsField === "string") {
|
|
198
|
+
return exportsField;
|
|
199
|
+
}
|
|
200
|
+
const moduleField = pkgJson.module;
|
|
201
|
+
if (typeof moduleField === "string")
|
|
202
|
+
return moduleField;
|
|
203
|
+
const mainField = pkgJson.main;
|
|
204
|
+
if (typeof mainField === "string")
|
|
205
|
+
return mainField;
|
|
206
|
+
return "index.js";
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Identify the subset of user dependencies that are ESM-only and resolve each
|
|
210
|
+
* to file:// URLs so the compiled-binary loader can import them as real ES
|
|
211
|
+
* modules instead of transpiling them to CommonJS. CJS dependencies are omitted
|
|
212
|
+
* and continue to load through the `createRequire`-based shim.
|
|
213
|
+
*/
|
|
214
|
+
export async function resolveEsmUserDependencies(projectDir, fs, userDeps) {
|
|
215
|
+
const esmDeps = new Map();
|
|
216
|
+
for (const name of userDeps.keys()) {
|
|
217
|
+
const packageDir = pathHelper.resolve(pathHelper.join(projectDir, "node_modules", name));
|
|
218
|
+
try {
|
|
219
|
+
const pkgJson = JSON.parse(await fs.readTextFile(pathHelper.join(packageDir, "package.json")));
|
|
220
|
+
const entry = resolveEsmEntry(pkgJson);
|
|
221
|
+
if (!entry || !isEsmPackage(pkgJson, entry))
|
|
222
|
+
continue;
|
|
223
|
+
// The entry path comes from the dependency's own package.json, which is
|
|
224
|
+
// attacker-influenceable (a malicious/compromised package could set
|
|
225
|
+
// "main": "../../../etc/passwd"). Reject entries that resolve outside the
|
|
226
|
+
// package directory so a crafted package.json cannot turn into a file://
|
|
227
|
+
// import that escapes node_modules. This mirrors the containment guard the
|
|
228
|
+
// CJS loader shim enforces via __vf_assertContained.
|
|
229
|
+
const entryPath = pathHelper.resolve(pathHelper.join(packageDir, entry));
|
|
230
|
+
if (!isWithinDirectory(packageDir, entryPath)) {
|
|
231
|
+
logger.warn(`Skipping ESM dependency ${name}: entry escapes package directory (${entry})`);
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
esmDeps.set(name, {
|
|
235
|
+
entryUrl: pathHelper.toFileUrl(entryPath).href,
|
|
236
|
+
packageDir,
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
catch (_) {
|
|
240
|
+
/* expected: package.json missing/invalid → treat as CJS */
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return esmDeps;
|
|
244
|
+
}
|
|
171
245
|
export async function loadVeryfrontExportsMap(projectDir, fs) {
|
|
172
246
|
const vfPackagePath = pathHelper.join(projectDir, "node_modules", "veryfront");
|
|
173
247
|
const vfPackageJsonPath = pathHelper.join(vfPackagePath, "package.json");
|
|
@@ -251,10 +325,39 @@ export function rewriteCompiledBinaryVeryfrontImports(code) {
|
|
|
251
325
|
transformed = transformed.replace(/import\s*\(\s*["']veryfront\/([^"']+)["']\s*\)/g, (_match, subpath) => `import("./_vf_${subpath.replace(/\//g, "_")}.mjs")`);
|
|
252
326
|
return transformed;
|
|
253
327
|
}
|
|
254
|
-
export function rewriteCompiledBinaryUserDependencyImports(code, userDeps) {
|
|
328
|
+
export function rewriteCompiledBinaryUserDependencyImports(code, userDeps, esmDeps = new Map()) {
|
|
255
329
|
let transformed = code;
|
|
256
330
|
for (const name of userDeps.keys()) {
|
|
257
331
|
const escaped = name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
332
|
+
// ESM-only dependencies are rewritten to real ES module file:// URLs so that
|
|
333
|
+
// import.meta, top-level await, etc. work. They must NOT be transpiled to
|
|
334
|
+
// CommonJS and evaluated via the `new Function` shim (see __vf_loadCjs).
|
|
335
|
+
const esm = esmDeps.get(name);
|
|
336
|
+
if (esm) {
|
|
337
|
+
// Resolve a subpath import to a contained file:// URL. The subpath comes
|
|
338
|
+
// from the handler source; reject any that escape the package directory
|
|
339
|
+
// (e.g. "pkg/../../secret") by leaving the import untouched so it fails to
|
|
340
|
+
// resolve rather than reading outside node_modules.
|
|
341
|
+
const subpathUrl = (subpath, original) => {
|
|
342
|
+
const target = pathHelper.resolve(pathHelper.join(esm.packageDir, subpath));
|
|
343
|
+
if (!isWithinDirectory(esm.packageDir, target)) {
|
|
344
|
+
logger.warn(`Skipping ESM subpath import that escapes package directory: ${original}`);
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
return pathHelper.toFileUrl(target).href;
|
|
348
|
+
};
|
|
349
|
+
transformed = transformed.replace(new RegExp(`from\\s+["']${escaped}(/[^"']+)["']`, "g"), (match, subpath) => {
|
|
350
|
+
const url = subpathUrl(subpath, match);
|
|
351
|
+
return url ? `from "${url}"` : match;
|
|
352
|
+
});
|
|
353
|
+
transformed = transformed.replace(new RegExp(`from\\s+["']${escaped}["']`, "g"), () => `from "${esm.entryUrl}"`);
|
|
354
|
+
transformed = transformed.replace(new RegExp(`import\\s*\\(\\s*["']${escaped}(/[^"']+)["']\\s*\\)`, "g"), (match, subpath) => {
|
|
355
|
+
const url = subpathUrl(subpath, match);
|
|
356
|
+
return url ? `import("${url}")` : match;
|
|
357
|
+
});
|
|
358
|
+
transformed = transformed.replace(new RegExp(`import\\s*\\(\\s*["']${escaped}["']\\s*\\)`, "g"), () => `import("${esm.entryUrl}")`);
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
258
361
|
transformed = transformed.replace(new RegExp(`import\\s+(\\w+)\\s+from\\s+["']${escaped}["']`, "g"), (_, localName) => `const ${localName} = __vf_interopDefault(require("${name}"))`);
|
|
259
362
|
transformed = transformed.replace(new RegExp(`import\\s+(\\{[^}]+\\})\\s+from\\s+["']${escaped}["']`, "g"), (_, bindings) => `const ${toCjsDestructureBindings(bindings)} = require("${name}")`);
|
|
260
363
|
transformed = transformed.replace(new RegExp(`import\\s+\\*\\s+as\\s+(\\w+)\\s+from\\s+["']${escaped}["']`, "g"), (_, localName) => `const ${localName} = require("${name}")`);
|
|
@@ -324,7 +427,8 @@ export async function rewriteExternalImports(code, projectDir, fs, userDeps = ne
|
|
|
324
427
|
// injected by the esbuild banner) to load CJS packages from node_modules,
|
|
325
428
|
// since npm: specifiers only work for packages embedded at compile time.
|
|
326
429
|
if (isCompiledBinary()) {
|
|
327
|
-
|
|
430
|
+
const esmDeps = await resolveEsmUserDependencies(projectDir, fs, userDeps);
|
|
431
|
+
transformed = rewriteCompiledBinaryUserDependencyImports(transformed, userDeps, esmDeps);
|
|
328
432
|
}
|
|
329
433
|
else {
|
|
330
434
|
transformed = await rewriteDenoNpmDependencyImports(transformed, projectDir, fs, userDeps);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { APIRoute, LoadModuleOptions } from "./types.js";
|
|
2
|
-
export { generateCompiledBinaryRequireShim, getNodeExternalPackagesToResolve, loadVeryfrontExportsMap, resolveNodePackageToFileUrl, rewriteCompiledBinaryUserDependencyImports, rewriteCompiledBinaryVeryfrontImports, rewriteDenoNodeBuiltinImports, rewriteDenoNpmDependencyImports, rewriteNodeExternalImports, } from "./external-import-rewriter.js";
|
|
2
|
+
export { generateCompiledBinaryRequireShim, getNodeExternalPackagesToResolve, loadVeryfrontExportsMap, resolveEsmUserDependencies, resolveNodePackageToFileUrl, rewriteCompiledBinaryUserDependencyImports, rewriteCompiledBinaryVeryfrontImports, rewriteDenoNodeBuiltinImports, rewriteDenoNpmDependencyImports, rewriteNodeExternalImports, } from "./external-import-rewriter.js";
|
|
3
3
|
export { toCjsDestructureBindings } from "./loader-helpers.js";
|
|
4
4
|
export declare function loadHandlerModule(options: LoadModuleOptions): Promise<APIRoute | null>;
|
|
5
5
|
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/routing/api/module-loader/loader.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAkB9D,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAChC,uBAAuB,EACvB,2BAA2B,EAC3B,0CAA0C,EAC1C,qCAAqC,EACrC,6BAA6B,EAC7B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAyBtF"}
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../../../src/src/routing/api/module-loader/loader.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAkB9D,OAAO,EACL,iCAAiC,EACjC,gCAAgC,EAChC,uBAAuB,EACvB,0BAA0B,EAC1B,2BAA2B,EAC3B,0CAA0C,EAC1C,qCAAqC,EACrC,6BAA6B,EAC7B,+BAA+B,EAC/B,0BAA0B,GAC3B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAE/D,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAyBtF"}
|
|
@@ -14,7 +14,7 @@ import { isCompiledBinary } from "../../../utils/index.js";
|
|
|
14
14
|
import { wrapWithCurrentContext } from "../../../platform/adapters/fs/veryfront/multi-project-adapter.js";
|
|
15
15
|
import { isWithinDirectory } from "../../../security/path-validation.js";
|
|
16
16
|
import { generateCompiledBinaryRequireShim, NODE_BUILTINS, readProjectDependencies, rewriteExternalImports, } from "./external-import-rewriter.js";
|
|
17
|
-
export { generateCompiledBinaryRequireShim, getNodeExternalPackagesToResolve, loadVeryfrontExportsMap, resolveNodePackageToFileUrl, rewriteCompiledBinaryUserDependencyImports, rewriteCompiledBinaryVeryfrontImports, rewriteDenoNodeBuiltinImports, rewriteDenoNpmDependencyImports, rewriteNodeExternalImports, } from "./external-import-rewriter.js";
|
|
17
|
+
export { generateCompiledBinaryRequireShim, getNodeExternalPackagesToResolve, loadVeryfrontExportsMap, resolveEsmUserDependencies, resolveNodePackageToFileUrl, rewriteCompiledBinaryUserDependencyImports, rewriteCompiledBinaryVeryfrontImports, rewriteDenoNodeBuiltinImports, rewriteDenoNpmDependencyImports, rewriteNodeExternalImports, } from "./external-import-rewriter.js";
|
|
18
18
|
const logger = serverLogger.component("api");
|
|
19
19
|
export { toCjsDestructureBindings } from "./loader-helpers.js";
|
|
20
20
|
export function loadHandlerModule(options) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hmr.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/preview/hmr.handler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hmr.handler.d.ts","sourceRoot":"","sources":["../../../../../src/src/server/handlers/preview/hmr.handler.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,eAAe,EAEpB,KAAK,aAAa,EACnB,MAAM,aAAa,CAAC;AAuBrB,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAK7D,qBAAa,UAAW,SAAQ,WAAW;IACzC,OAAO,CAAC,MAAM,CAAC,WAAW,CAAgD;IAC1E,OAAO,CAAC,MAAM,CAAC,iBAAiB,CAA6B;IAC7D,OAAO,CAAC,MAAM,CAAC,4BAA4B,CAAK;IAChD,OAAO,CAAC,MAAM,CAAC,WAAW,CAAS;IAEnC,QAAQ,EAAE,eAAe,CAKvB;IAEF,OAAO,CAAC,MAAM,CAAC,UAAU;IAsCnB,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IA4IvE;;;;;OAKG;YACW,wBAAwB;IAuCtC,MAAM,CAAC,cAAc,IAAI,MAAM;IAI/B,MAAM,CAAC,UAAU,IAAI;QACnB,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,iBAAiB,EAAE,MAAM,CAAC;KAC3B;IAID,MAAM,CAAC,+BAA+B,IAAI,MAAM,IAAI;IAWpD,MAAM,CAAC,QAAQ,IAAI,IAAI;CAaxB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as dntShim from "../../../../_dnt.shims.js";
|
|
2
2
|
import { HMR_MAX_MESSAGES_PER_MINUTE, serverLogger } from "../../../utils/index.js";
|
|
3
3
|
import { RateLimiter } from "../../../modules/server/index.js";
|
|
4
|
+
import { VeryfrontError } from "../../../errors/index.js";
|
|
4
5
|
import { BaseHandler } from "../response/base.js";
|
|
5
6
|
import { HandlerPriority, } from "../types.js";
|
|
6
7
|
import { ReloadNotifier } from "../../reload-notifier.js";
|
|
@@ -173,6 +174,10 @@ export class HMRHandler extends BaseHandler {
|
|
|
173
174
|
return this.respond(response);
|
|
174
175
|
}
|
|
175
176
|
catch (error) {
|
|
177
|
+
if (error instanceof VeryfrontError && error.status === 501) {
|
|
178
|
+
logger.warn("WebSocket upgrade not supported by runtime", { error });
|
|
179
|
+
return this.respond(new Response("WebSocket not supported", { status: 501 }));
|
|
180
|
+
}
|
|
176
181
|
logger.error("WebSocket upgrade failed", { error });
|
|
177
182
|
return this.respond(new Response("WebSocket upgrade failed", { status: 500 }));
|
|
178
183
|
}
|