@vercel/node 2.9.1 → 2.9.3
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.
@@ -1,4 +1,4 @@
|
|
1
1
|
/// <reference types="node" />
|
2
2
|
import { IncomingMessage } from 'http';
|
3
3
|
import { VercelProxyResponse } from '@vercel/node-bridge/types';
|
4
|
-
export declare function createEdgeEventHandler(
|
4
|
+
export declare function createEdgeEventHandler(entrypointFullPath: string, entrypointRelativePath: string, isMiddleware: boolean): Promise<(request: IncomingMessage) => Promise<VercelProxyResponse>>;
|
@@ -28,7 +28,7 @@ async function serializeRequest(message) {
|
|
28
28
|
body,
|
29
29
|
});
|
30
30
|
}
|
31
|
-
async function compileUserCode(
|
31
|
+
async function compileUserCode(entrypointFullPath, entrypointRelativePath, isMiddleware) {
|
32
32
|
const { wasmAssets, plugin: edgeWasmPlugin } = edge_wasm_plugin_1.createEdgeWasmPlugin();
|
33
33
|
try {
|
34
34
|
const result = await esbuild_1.default.build({
|
@@ -42,13 +42,13 @@ async function compileUserCode(entrypointPath, entrypointLabel, isMiddleware) {
|
|
42
42
|
legalComments: 'none',
|
43
43
|
bundle: true,
|
44
44
|
plugins: [edgeWasmPlugin],
|
45
|
-
entryPoints: [
|
45
|
+
entryPoints: [entrypointFullPath],
|
46
46
|
write: false,
|
47
47
|
format: 'cjs',
|
48
48
|
});
|
49
49
|
const compiledFile = result.outputFiles?.[0];
|
50
50
|
if (!compiledFile) {
|
51
|
-
throw new Error(`Compilation of ${
|
51
|
+
throw new Error(`Compilation of ${entrypointRelativePath} produced no output files.`);
|
52
52
|
}
|
53
53
|
const userCode = `
|
54
54
|
// strict mode
|
@@ -59,7 +59,7 @@ async function compileUserCode(entrypointPath, entrypointLabel, isMiddleware) {
|
|
59
59
|
|
60
60
|
// request metadata
|
61
61
|
const IS_MIDDLEWARE = ${isMiddleware};
|
62
|
-
const ENTRYPOINT_LABEL = '${
|
62
|
+
const ENTRYPOINT_LABEL = '${entrypointRelativePath}';
|
63
63
|
|
64
64
|
// edge handler
|
65
65
|
${edgeHandlerTemplate}
|
@@ -110,8 +110,8 @@ async function createEdgeRuntime(params) {
|
|
110
110
|
return undefined;
|
111
111
|
}
|
112
112
|
}
|
113
|
-
async function createEdgeEventHandler(
|
114
|
-
const userCode = await compileUserCode(
|
113
|
+
async function createEdgeEventHandler(entrypointFullPath, entrypointRelativePath, isMiddleware) {
|
114
|
+
const userCode = await compileUserCode(entrypointFullPath, entrypointRelativePath, isMiddleware);
|
115
115
|
const server = await createEdgeRuntime(userCode);
|
116
116
|
return async function (request) {
|
117
117
|
if (!server) {
|
@@ -128,8 +128,11 @@ async function createEdgeEventHandler(entrypointPath, entrypointLabel, isMiddlew
|
|
128
128
|
const body = await response.text();
|
129
129
|
const isUserError = response.headers.get('x-vercel-failed') === 'edge-wrapper';
|
130
130
|
if (isUserError && response.status >= 500) {
|
131
|
-
//
|
132
|
-
|
131
|
+
// We can't currently get a real stack trace from the Edge Function error,
|
132
|
+
// but we can fake a basic one that is still usefult to the user.
|
133
|
+
const fakeStackTrace = ` at (${entrypointRelativePath})`;
|
134
|
+
const urlPath = extractUrlPath(entrypointRelativePath);
|
135
|
+
console.log(`Error from API Route ${urlPath}: ${body}\n${fakeStackTrace}`);
|
133
136
|
// this matches the serverless function bridge launcher's behavior when
|
134
137
|
// an error is thrown in the function
|
135
138
|
process.exit(1);
|
@@ -143,3 +146,12 @@ async function createEdgeEventHandler(entrypointPath, entrypointLabel, isMiddlew
|
|
143
146
|
};
|
144
147
|
}
|
145
148
|
exports.createEdgeEventHandler = createEdgeEventHandler;
|
149
|
+
// turns "api/some.func.js" into "api/some.func"
|
150
|
+
function extractUrlPath(entrypointRelativePath) {
|
151
|
+
const parts = entrypointRelativePath.split('.');
|
152
|
+
if (parts.length === 1) {
|
153
|
+
return entrypointRelativePath;
|
154
|
+
}
|
155
|
+
parts.pop();
|
156
|
+
return parts.join('.');
|
157
|
+
}
|
package/dist/index.js
CHANGED
@@ -301632,21 +301632,17 @@ function register(opts = {}) {
|
|
301632
301632
|
getCurrentDirectory: () => cwd,
|
301633
301633
|
getCanonicalFileName: path => path,
|
301634
301634
|
};
|
301635
|
-
function createTSError(diagnostics) {
|
301636
|
-
const message = formatDiagnostics(diagnostics, diagnosticHost);
|
301637
|
-
return new build_utils_1.NowBuildError({ code: 'NODE_TYPESCRIPT_ERROR', message });
|
301638
|
-
}
|
301639
301635
|
function reportTSError(diagnostics, shouldExit) {
|
301640
301636
|
if (!diagnostics || diagnostics.length === 0) {
|
301641
301637
|
return;
|
301642
301638
|
}
|
301643
|
-
const
|
301639
|
+
const message = formatDiagnostics(diagnostics, diagnosticHost);
|
301644
301640
|
if (shouldExit) {
|
301645
|
-
throw
|
301641
|
+
throw new build_utils_1.NowBuildError({ code: 'NODE_TYPESCRIPT_ERROR', message });
|
301646
301642
|
}
|
301647
301643
|
else {
|
301648
301644
|
// Print error in red color and continue execution.
|
301649
|
-
console.error(
|
301645
|
+
console.error(message);
|
301650
301646
|
}
|
301651
301647
|
}
|
301652
301648
|
function getBuild(configFileName = '', skipTypeCheck) {
|
package/dist/typescript.js
CHANGED
@@ -123,21 +123,17 @@ function register(opts = {}) {
|
|
123
123
|
getCurrentDirectory: () => cwd,
|
124
124
|
getCanonicalFileName: path => path,
|
125
125
|
};
|
126
|
-
function createTSError(diagnostics) {
|
127
|
-
const message = formatDiagnostics(diagnostics, diagnosticHost);
|
128
|
-
return new build_utils_1.NowBuildError({ code: 'NODE_TYPESCRIPT_ERROR', message });
|
129
|
-
}
|
130
126
|
function reportTSError(diagnostics, shouldExit) {
|
131
127
|
if (!diagnostics || diagnostics.length === 0) {
|
132
128
|
return;
|
133
129
|
}
|
134
|
-
const
|
130
|
+
const message = formatDiagnostics(diagnostics, diagnosticHost);
|
135
131
|
if (shouldExit) {
|
136
|
-
throw
|
132
|
+
throw new build_utils_1.NowBuildError({ code: 'NODE_TYPESCRIPT_ERROR', message });
|
137
133
|
}
|
138
134
|
else {
|
139
135
|
// Print error in red color and continue execution.
|
140
|
-
console.error(
|
136
|
+
console.error(message);
|
141
137
|
}
|
142
138
|
}
|
143
139
|
function getBuild(configFileName = '', skipTypeCheck) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/node",
|
3
|
-
"version": "2.9.
|
3
|
+
"version": "2.9.3",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
@@ -31,8 +31,8 @@
|
|
31
31
|
"dependencies": {
|
32
32
|
"@edge-runtime/vm": "2.0.0",
|
33
33
|
"@types/node": "14.18.33",
|
34
|
-
"@vercel/build-utils": "6.2.
|
35
|
-
"@vercel/node-bridge": "3.1.
|
34
|
+
"@vercel/build-utils": "6.2.2",
|
35
|
+
"@vercel/node-bridge": "3.1.11",
|
36
36
|
"@vercel/static-config": "2.0.12",
|
37
37
|
"edge-runtime": "2.0.0",
|
38
38
|
"esbuild": "0.14.47",
|
@@ -64,5 +64,5 @@
|
|
64
64
|
"test-listen": "1.1.0",
|
65
65
|
"ts-morph": "12.0.0"
|
66
66
|
},
|
67
|
-
"gitHead": "
|
67
|
+
"gitHead": "95a4dcfb33d813f1a0ef18d766232d42c876ce69"
|
68
68
|
}
|