@vercel/node 2.4.5 → 2.5.2
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/dev-server.js +16 -12
- package/dist/edge-wasm-plugin.d.ts +21 -0
- package/dist/edge-wasm-plugin.js +82 -0
- package/dist/index.js +235 -22
- package/package.json +5 -5
package/dist/dev-server.js
CHANGED
@@ -70,7 +70,7 @@ const static_config_1 = require("@vercel/static-config");
|
|
70
70
|
const ts_morph_1 = require("ts-morph");
|
71
71
|
const esbuild_1 = __importDefault(require("esbuild"));
|
72
72
|
const node_fetch_1 = __importDefault(require("node-fetch"));
|
73
|
-
const
|
73
|
+
const edge_wasm_plugin_1 = require("./edge-wasm-plugin");
|
74
74
|
function logError(error) {
|
75
75
|
console.error(error.message);
|
76
76
|
if (error.stack) {
|
@@ -127,12 +127,14 @@ async function serializeRequest(message) {
|
|
127
127
|
});
|
128
128
|
}
|
129
129
|
async function compileUserCode(entrypointPath, entrypointLabel) {
|
130
|
+
const { wasmAssets, plugin: edgeWasmPlugin } = edge_wasm_plugin_1.createEdgeWasmPlugin();
|
130
131
|
try {
|
131
132
|
const result = await esbuild_1.default.build({
|
132
133
|
platform: 'node',
|
133
134
|
target: 'node14',
|
134
135
|
sourcemap: 'inline',
|
135
136
|
bundle: true,
|
137
|
+
plugins: [edgeWasmPlugin],
|
136
138
|
entryPoints: [entrypointPath],
|
137
139
|
write: false,
|
138
140
|
format: 'cjs',
|
@@ -141,9 +143,8 @@ async function compileUserCode(entrypointPath, entrypointLabel) {
|
|
141
143
|
if (!compiledFile) {
|
142
144
|
throw new Error(`Compilation of ${entrypointLabel} produced no output files.`);
|
143
145
|
}
|
144
|
-
const userCode =
|
145
|
-
|
146
|
-
${userCode};
|
146
|
+
const userCode = `
|
147
|
+
${compiledFile.text};
|
147
148
|
|
148
149
|
addEventListener('fetch', async (event) => {
|
149
150
|
try {
|
@@ -189,6 +190,7 @@ async function compileUserCode(entrypointPath, entrypointLabel) {
|
|
189
190
|
}));
|
190
191
|
}
|
191
192
|
})`;
|
193
|
+
return { userCode, wasmAssets };
|
192
194
|
}
|
193
195
|
catch (error) {
|
194
196
|
// We can't easily show a meaningful stack trace from ncc -> edge-runtime.
|
@@ -198,23 +200,25 @@ async function compileUserCode(entrypointPath, entrypointLabel) {
|
|
198
200
|
return undefined;
|
199
201
|
}
|
200
202
|
}
|
201
|
-
async function createEdgeRuntime(
|
203
|
+
async function createEdgeRuntime(params) {
|
202
204
|
try {
|
203
|
-
if (!
|
205
|
+
if (!params) {
|
204
206
|
return undefined;
|
205
207
|
}
|
208
|
+
const wasmBindings = await params.wasmAssets.getContext();
|
206
209
|
const edgeRuntime = new edge_runtime_1.EdgeRuntime({
|
207
|
-
initialCode: userCode,
|
210
|
+
initialCode: params.userCode,
|
208
211
|
extend: (context) => {
|
209
212
|
Object.assign(context, {
|
210
|
-
|
211
|
-
module: {
|
212
|
-
|
213
|
-
|
213
|
+
// This is required for esbuild wrapping logic to resolve
|
214
|
+
module: {},
|
215
|
+
// This is required for environment variable access.
|
216
|
+
// In production, env var access is provided by static analysis
|
217
|
+
// so that only the used values are available.
|
214
218
|
process: {
|
215
219
|
env: process.env,
|
216
220
|
},
|
217
|
-
});
|
221
|
+
}, wasmBindings);
|
218
222
|
return context;
|
219
223
|
},
|
220
224
|
});
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import type { Plugin } from 'esbuild';
|
2
|
+
export declare class WasmAssets {
|
3
|
+
private readonly assets;
|
4
|
+
/**
|
5
|
+
* Declare a WebAssembly binding
|
6
|
+
*/
|
7
|
+
declare(filePath: string): Promise<string>;
|
8
|
+
/**
|
9
|
+
* Get an object with the context needed to execute the code
|
10
|
+
* built with the plugin
|
11
|
+
*/
|
12
|
+
getContext(): Promise<Record<string, WebAssembly.Module>>;
|
13
|
+
/**
|
14
|
+
* Allow to iterate easily
|
15
|
+
*/
|
16
|
+
[Symbol.iterator](): IterableIterator<[string, string]>;
|
17
|
+
}
|
18
|
+
export declare function createEdgeWasmPlugin(): {
|
19
|
+
plugin: Plugin;
|
20
|
+
wasmAssets: WasmAssets;
|
21
|
+
};
|
@@ -0,0 +1,82 @@
|
|
1
|
+
"use strict";
|
2
|
+
// copied from `edge-functions-bridge`:
|
3
|
+
// https://github.com/vercel/runtimes/blob/c076db9e3ce5635f7c2690396e3d9f791a0fd808/packages/edge-functions-bridge/src/get-edge-function-source.ts#L282-L317
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
5
|
+
exports.createEdgeWasmPlugin = exports.WasmAssets = void 0;
|
6
|
+
const crypto_1 = require("crypto");
|
7
|
+
const fs_1 = require("fs");
|
8
|
+
class WasmAssets {
|
9
|
+
constructor() {
|
10
|
+
this.assets = new Map();
|
11
|
+
}
|
12
|
+
/**
|
13
|
+
* Declare a WebAssembly binding
|
14
|
+
*/
|
15
|
+
async declare(filePath) {
|
16
|
+
const hash = sha1(await fs_1.promises.readFile(filePath));
|
17
|
+
const name = `wasm_${hash}`;
|
18
|
+
this.assets.set(name, filePath);
|
19
|
+
return name;
|
20
|
+
}
|
21
|
+
/**
|
22
|
+
* Get an object with the context needed to execute the code
|
23
|
+
* built with the plugin
|
24
|
+
*/
|
25
|
+
async getContext() {
|
26
|
+
const promises = [];
|
27
|
+
const context = {};
|
28
|
+
for (const [name, filePath] of this.assets) {
|
29
|
+
promises.push((async () => {
|
30
|
+
const bytes = await fs_1.promises.readFile(filePath);
|
31
|
+
context[name] = await WebAssembly.compile(bytes);
|
32
|
+
})());
|
33
|
+
}
|
34
|
+
await Promise.all(promises);
|
35
|
+
return context;
|
36
|
+
}
|
37
|
+
/**
|
38
|
+
* Allow to iterate easily
|
39
|
+
*/
|
40
|
+
[Symbol.iterator]() {
|
41
|
+
return this.assets[Symbol.iterator]();
|
42
|
+
}
|
43
|
+
}
|
44
|
+
exports.WasmAssets = WasmAssets;
|
45
|
+
function createEdgeWasmPlugin() {
|
46
|
+
const wasmAssets = new WasmAssets();
|
47
|
+
const plugin = {
|
48
|
+
name: 'vercel-wasm',
|
49
|
+
setup(b) {
|
50
|
+
b.onResolve({ filter: /\.wasm\?module/i }, async (data) => {
|
51
|
+
const wasmFile = data.path.replace(/\?module$/, '');
|
52
|
+
const resolvedPath = await b.resolve(wasmFile, {
|
53
|
+
importer: data.importer,
|
54
|
+
resolveDir: data.resolveDir,
|
55
|
+
});
|
56
|
+
if (!resolvedPath.path) {
|
57
|
+
return {
|
58
|
+
errors: [
|
59
|
+
{ text: `WebAssembly file could not be located: ${wasmFile}` },
|
60
|
+
],
|
61
|
+
};
|
62
|
+
}
|
63
|
+
const name = await wasmAssets.declare(resolvedPath.path);
|
64
|
+
return {
|
65
|
+
path: name,
|
66
|
+
namespace: 'vercel-wasm',
|
67
|
+
};
|
68
|
+
});
|
69
|
+
b.onLoad({ namespace: 'vercel-wasm', filter: /.+/ }, args => {
|
70
|
+
return {
|
71
|
+
loader: 'js',
|
72
|
+
contents: `export default globalThis[${JSON.stringify(args.path)}]`,
|
73
|
+
};
|
74
|
+
});
|
75
|
+
},
|
76
|
+
};
|
77
|
+
return { plugin, wasmAssets };
|
78
|
+
}
|
79
|
+
exports.createEdgeWasmPlugin = createEdgeWasmPlugin;
|
80
|
+
function sha1(data) {
|
81
|
+
return crypto_1.createHash('sha1').update(data).digest('hex');
|
82
|
+
}
|
package/dist/index.js
CHANGED
@@ -225030,6 +225030,177 @@ module.exports = {useNative, useNativeSync}
|
|
225030
225030
|
}));
|
225031
225031
|
|
225032
225032
|
|
225033
|
+
/***/ }),
|
225034
|
+
|
225035
|
+
/***/ 76171:
|
225036
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
225037
|
+
|
225038
|
+
"use strict";
|
225039
|
+
|
225040
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
225041
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
225042
|
+
};
|
225043
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
225044
|
+
exports.RateLimit = exports.Sema = void 0;
|
225045
|
+
const events_1 = __importDefault(__webpack_require__(28614));
|
225046
|
+
function arrayMove(src, srcIndex, dst, dstIndex, len) {
|
225047
|
+
for (let j = 0; j < len; ++j) {
|
225048
|
+
dst[j + dstIndex] = src[j + srcIndex];
|
225049
|
+
src[j + srcIndex] = void 0;
|
225050
|
+
}
|
225051
|
+
}
|
225052
|
+
function pow2AtLeast(n) {
|
225053
|
+
n = n >>> 0;
|
225054
|
+
n = n - 1;
|
225055
|
+
n = n | (n >> 1);
|
225056
|
+
n = n | (n >> 2);
|
225057
|
+
n = n | (n >> 4);
|
225058
|
+
n = n | (n >> 8);
|
225059
|
+
n = n | (n >> 16);
|
225060
|
+
return n + 1;
|
225061
|
+
}
|
225062
|
+
function getCapacity(capacity) {
|
225063
|
+
return pow2AtLeast(Math.min(Math.max(16, capacity), 1073741824));
|
225064
|
+
}
|
225065
|
+
// Deque is based on https://github.com/petkaantonov/deque/blob/master/js/deque.js
|
225066
|
+
// Released under the MIT License: https://github.com/petkaantonov/deque/blob/6ef4b6400ad3ba82853fdcc6531a38eb4f78c18c/LICENSE
|
225067
|
+
class Deque {
|
225068
|
+
constructor(capacity) {
|
225069
|
+
this._capacity = getCapacity(capacity);
|
225070
|
+
this._length = 0;
|
225071
|
+
this._front = 0;
|
225072
|
+
this.arr = [];
|
225073
|
+
}
|
225074
|
+
push(item) {
|
225075
|
+
const length = this._length;
|
225076
|
+
this.checkCapacity(length + 1);
|
225077
|
+
const i = (this._front + length) & (this._capacity - 1);
|
225078
|
+
this.arr[i] = item;
|
225079
|
+
this._length = length + 1;
|
225080
|
+
return length + 1;
|
225081
|
+
}
|
225082
|
+
pop() {
|
225083
|
+
const length = this._length;
|
225084
|
+
if (length === 0) {
|
225085
|
+
return void 0;
|
225086
|
+
}
|
225087
|
+
const i = (this._front + length - 1) & (this._capacity - 1);
|
225088
|
+
const ret = this.arr[i];
|
225089
|
+
this.arr[i] = void 0;
|
225090
|
+
this._length = length - 1;
|
225091
|
+
return ret;
|
225092
|
+
}
|
225093
|
+
shift() {
|
225094
|
+
const length = this._length;
|
225095
|
+
if (length === 0) {
|
225096
|
+
return void 0;
|
225097
|
+
}
|
225098
|
+
const front = this._front;
|
225099
|
+
const ret = this.arr[front];
|
225100
|
+
this.arr[front] = void 0;
|
225101
|
+
this._front = (front + 1) & (this._capacity - 1);
|
225102
|
+
this._length = length - 1;
|
225103
|
+
return ret;
|
225104
|
+
}
|
225105
|
+
get length() {
|
225106
|
+
return this._length;
|
225107
|
+
}
|
225108
|
+
checkCapacity(size) {
|
225109
|
+
if (this._capacity < size) {
|
225110
|
+
this.resizeTo(getCapacity(this._capacity * 1.5 + 16));
|
225111
|
+
}
|
225112
|
+
}
|
225113
|
+
resizeTo(capacity) {
|
225114
|
+
const oldCapacity = this._capacity;
|
225115
|
+
this._capacity = capacity;
|
225116
|
+
const front = this._front;
|
225117
|
+
const length = this._length;
|
225118
|
+
if (front + length > oldCapacity) {
|
225119
|
+
const moveItemsCount = (front + length) & (oldCapacity - 1);
|
225120
|
+
arrayMove(this.arr, 0, this.arr, oldCapacity, moveItemsCount);
|
225121
|
+
}
|
225122
|
+
}
|
225123
|
+
}
|
225124
|
+
class ReleaseEmitter extends events_1.default {
|
225125
|
+
}
|
225126
|
+
function isFn(x) {
|
225127
|
+
return typeof x === 'function';
|
225128
|
+
}
|
225129
|
+
function defaultInit() {
|
225130
|
+
return '1';
|
225131
|
+
}
|
225132
|
+
class Sema {
|
225133
|
+
constructor(nr, { initFn = defaultInit, pauseFn, resumeFn, capacity = 10, } = {}) {
|
225134
|
+
if (isFn(pauseFn) !== isFn(resumeFn)) {
|
225135
|
+
throw new Error('pauseFn and resumeFn must be both set for pausing');
|
225136
|
+
}
|
225137
|
+
this.nrTokens = nr;
|
225138
|
+
this.free = new Deque(nr);
|
225139
|
+
this.waiting = new Deque(capacity);
|
225140
|
+
this.releaseEmitter = new ReleaseEmitter();
|
225141
|
+
this.noTokens = initFn === defaultInit;
|
225142
|
+
this.pauseFn = pauseFn;
|
225143
|
+
this.resumeFn = resumeFn;
|
225144
|
+
this.paused = false;
|
225145
|
+
this.releaseEmitter.on('release', (token) => {
|
225146
|
+
const p = this.waiting.shift();
|
225147
|
+
if (p) {
|
225148
|
+
p.resolve(token);
|
225149
|
+
}
|
225150
|
+
else {
|
225151
|
+
if (this.resumeFn && this.paused) {
|
225152
|
+
this.paused = false;
|
225153
|
+
this.resumeFn();
|
225154
|
+
}
|
225155
|
+
this.free.push(token);
|
225156
|
+
}
|
225157
|
+
});
|
225158
|
+
for (let i = 0; i < nr; i++) {
|
225159
|
+
this.free.push(initFn());
|
225160
|
+
}
|
225161
|
+
}
|
225162
|
+
tryAcquire() {
|
225163
|
+
return this.free.pop();
|
225164
|
+
}
|
225165
|
+
async acquire() {
|
225166
|
+
let token = this.tryAcquire();
|
225167
|
+
if (token !== void 0) {
|
225168
|
+
return token;
|
225169
|
+
}
|
225170
|
+
return new Promise((resolve, reject) => {
|
225171
|
+
if (this.pauseFn && !this.paused) {
|
225172
|
+
this.paused = true;
|
225173
|
+
this.pauseFn();
|
225174
|
+
}
|
225175
|
+
this.waiting.push({ resolve, reject });
|
225176
|
+
});
|
225177
|
+
}
|
225178
|
+
release(token) {
|
225179
|
+
this.releaseEmitter.emit('release', this.noTokens ? '1' : token);
|
225180
|
+
}
|
225181
|
+
drain() {
|
225182
|
+
const a = new Array(this.nrTokens);
|
225183
|
+
for (let i = 0; i < this.nrTokens; i++) {
|
225184
|
+
a[i] = this.acquire();
|
225185
|
+
}
|
225186
|
+
return Promise.all(a);
|
225187
|
+
}
|
225188
|
+
nrWaiting() {
|
225189
|
+
return this.waiting.length;
|
225190
|
+
}
|
225191
|
+
}
|
225192
|
+
exports.Sema = Sema;
|
225193
|
+
function RateLimit(rps, { timeUnit = 1000, uniformDistribution = false, } = {}) {
|
225194
|
+
const sema = new Sema(uniformDistribution ? 1 : rps);
|
225195
|
+
const delay = uniformDistribution ? timeUnit / rps : timeUnit;
|
225196
|
+
return async function rl() {
|
225197
|
+
await sema.acquire();
|
225198
|
+
setTimeout(() => sema.release(), delay);
|
225199
|
+
};
|
225200
|
+
}
|
225201
|
+
exports.RateLimit = RateLimit;
|
225202
|
+
|
225203
|
+
|
225033
225204
|
/***/ }),
|
225034
225205
|
|
225035
225206
|
/***/ 10031:
|
@@ -226530,6 +226701,7 @@ const fsSymbols = {
|
|
226530
226701
|
stat: FS_FN,
|
226531
226702
|
statSync: FS_FN
|
226532
226703
|
};
|
226704
|
+
const fsExtraSymbols = Object.assign(Object.assign({}, fsSymbols), { pathExists: FS_FN, pathExistsSync: FS_FN, readJson: FS_FN, readJSON: FS_FN, readJsonSync: FS_FN, readJSONSync: FS_FN });
|
226533
226705
|
const staticModules = Object.assign(Object.create(null), {
|
226534
226706
|
bindings: {
|
226535
226707
|
default: BINDINGS
|
@@ -226544,6 +226716,8 @@ const staticModules = Object.assign(Object.create(null), {
|
|
226544
226716
|
}
|
226545
226717
|
},
|
226546
226718
|
fs: Object.assign({ default: fsSymbols }, fsSymbols),
|
226719
|
+
'fs-extra': Object.assign({ default: fsExtraSymbols }, fsExtraSymbols),
|
226720
|
+
'graceful-fs': Object.assign({ default: fsSymbols }, fsSymbols),
|
226547
226721
|
process: Object.assign({ default: staticProcess }, staticProcess),
|
226548
226722
|
// populated below
|
226549
226723
|
path: {
|
@@ -227351,6 +227525,7 @@ const resolve_dependency_1 = __importDefault(__webpack_require__(62278));
|
|
227351
227525
|
const micromatch_1 = __webpack_require__(1189);
|
227352
227526
|
const sharedlib_emit_1 = __webpack_require__(62985);
|
227353
227527
|
const path_2 = __webpack_require__(85622);
|
227528
|
+
const async_sema_1 = __webpack_require__(76171);
|
227354
227529
|
const fsReadFile = graceful_fs_1.default.promises.readFile;
|
227355
227530
|
const fsReadlink = graceful_fs_1.default.promises.readlink;
|
227356
227531
|
const fsStat = graceful_fs_1.default.promises.stat;
|
@@ -227385,7 +227560,10 @@ async function nodeFileTrace(files, opts = {}) {
|
|
227385
227560
|
exports.nodeFileTrace = nodeFileTrace;
|
227386
227561
|
;
|
227387
227562
|
class Job {
|
227388
|
-
constructor({ base = process.cwd(), processCwd, exports, conditions = exports || ['node'], exportsOnly = false, paths = {}, ignore, log = false, mixedModules = false, ts = true, analysis = {}, cache,
|
227563
|
+
constructor({ base = process.cwd(), processCwd, exports, conditions = exports || ['node'], exportsOnly = false, paths = {}, ignore, log = false, mixedModules = false, ts = true, analysis = {}, cache,
|
227564
|
+
// we use a default of 1024 concurrency to balance
|
227565
|
+
// performance and memory usage for fs operations
|
227566
|
+
fileIOConcurrency = 1024, }) {
|
227389
227567
|
this.reasons = new Map();
|
227390
227568
|
this.ts = ts;
|
227391
227569
|
base = path_1.resolve(base);
|
@@ -227429,6 +227607,7 @@ class Job {
|
|
227429
227607
|
this.paths = resolvedPaths;
|
227430
227608
|
this.log = log;
|
227431
227609
|
this.mixedModules = mixedModules;
|
227610
|
+
this.fileIOQueue = new async_sema_1.Sema(fileIOConcurrency);
|
227432
227611
|
this.analysis = {};
|
227433
227612
|
if (analysis !== false) {
|
227434
227613
|
Object.assign(this.analysis, {
|
@@ -227461,6 +227640,7 @@ class Job {
|
|
227461
227640
|
const cached = this.symlinkCache.get(path);
|
227462
227641
|
if (cached !== undefined)
|
227463
227642
|
return cached;
|
227643
|
+
await this.fileIOQueue.acquire();
|
227464
227644
|
try {
|
227465
227645
|
const link = await fsReadlink(path);
|
227466
227646
|
// also copy stat cache to symlink
|
@@ -227476,6 +227656,9 @@ class Job {
|
|
227476
227656
|
this.symlinkCache.set(path, null);
|
227477
227657
|
return null;
|
227478
227658
|
}
|
227659
|
+
finally {
|
227660
|
+
this.fileIOQueue.release();
|
227661
|
+
}
|
227479
227662
|
}
|
227480
227663
|
async isFile(path) {
|
227481
227664
|
const stats = await this.stat(path);
|
@@ -227493,6 +227676,7 @@ class Job {
|
|
227493
227676
|
const cached = this.statCache.get(path);
|
227494
227677
|
if (cached)
|
227495
227678
|
return cached;
|
227679
|
+
await this.fileIOQueue.acquire();
|
227496
227680
|
try {
|
227497
227681
|
const stats = await fsStat(path);
|
227498
227682
|
this.statCache.set(path, stats);
|
@@ -227505,6 +227689,9 @@ class Job {
|
|
227505
227689
|
}
|
227506
227690
|
throw e;
|
227507
227691
|
}
|
227692
|
+
finally {
|
227693
|
+
this.fileIOQueue.release();
|
227694
|
+
}
|
227508
227695
|
}
|
227509
227696
|
async resolve(id, parent, job, cjsResolve) {
|
227510
227697
|
return resolve_dependency_1.default(id, parent, job, cjsResolve);
|
@@ -227513,6 +227700,7 @@ class Job {
|
|
227513
227700
|
const cached = this.fileCache.get(path);
|
227514
227701
|
if (cached !== undefined)
|
227515
227702
|
return cached;
|
227703
|
+
await this.fileIOQueue.acquire();
|
227516
227704
|
try {
|
227517
227705
|
const source = (await fsReadFile(path)).toString();
|
227518
227706
|
this.fileCache.set(path, source);
|
@@ -227525,6 +227713,9 @@ class Job {
|
|
227525
227713
|
}
|
227526
227714
|
throw e;
|
227527
227715
|
}
|
227716
|
+
finally {
|
227717
|
+
this.fileIOQueue.release();
|
227718
|
+
}
|
227528
227719
|
}
|
227529
227720
|
async realpath(path, parent, seen = new Set()) {
|
227530
227721
|
if (seen.has(path))
|
@@ -304518,6 +304709,7 @@ const path_1 = __webpack_require__(85622);
|
|
304518
304709
|
const ts_morph_1 = __webpack_require__(4490);
|
304519
304710
|
const once_1 = __importDefault(__webpack_require__(8478));
|
304520
304711
|
const nft_1 = __webpack_require__(39582);
|
304712
|
+
const resolve_dependency_1 = __importDefault(__webpack_require__(62278));
|
304521
304713
|
const build_utils_1 = __webpack_require__(63445);
|
304522
304714
|
Object.defineProperty(exports, "shouldServe", ({ enumerable: true, get: function () { return build_utils_1.shouldServe; } }));
|
304523
304715
|
const static_config_1 = __webpack_require__(76849);
|
@@ -304549,7 +304741,7 @@ function renameTStoJS(path) {
|
|
304549
304741
|
}
|
304550
304742
|
return path;
|
304551
304743
|
}
|
304552
|
-
async function compile(workPath, baseDir, entrypointPath, config, nodeVersion) {
|
304744
|
+
async function compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction) {
|
304553
304745
|
const inputFiles = new Set([entrypointPath]);
|
304554
304746
|
const preparedFiles = {};
|
304555
304747
|
const sourceCache = new Map();
|
@@ -304598,35 +304790,56 @@ async function compile(workPath, baseDir, entrypointPath, config, nodeVersion) {
|
|
304598
304790
|
processCwd: workPath,
|
304599
304791
|
ts: true,
|
304600
304792
|
mixedModules: true,
|
304793
|
+
resolve(id, parent, job, cjsResolve) {
|
304794
|
+
const normalizedWasmImports = id.replace(/\.wasm\?module$/i, '.wasm');
|
304795
|
+
return resolve_dependency_1.default(normalizedWasmImports, parent, job, cjsResolve);
|
304796
|
+
},
|
304601
304797
|
ignore: config.excludeFiles,
|
304602
304798
|
async readFile(fsPath) {
|
304603
304799
|
const relPath = path_1.relative(baseDir, fsPath);
|
304800
|
+
// If this file has already been read then return from the cache
|
304604
304801
|
const cached = sourceCache.get(relPath);
|
304605
|
-
if (cached)
|
304606
|
-
return cached
|
304607
|
-
// null represents a not found
|
304608
|
-
if (cached === null)
|
304609
|
-
return null;
|
304802
|
+
if (typeof cached !== 'undefined')
|
304803
|
+
return cached;
|
304610
304804
|
try {
|
304805
|
+
let entry;
|
304611
304806
|
let source = fs_1.readFileSync(fsPath);
|
304612
|
-
if ((fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) ||
|
304613
|
-
fsPath.endsWith('.tsx')) {
|
304614
|
-
source = compileTypeScript(fsPath, source.toString());
|
304615
|
-
}
|
304616
304807
|
const { mode } = fs_1.lstatSync(fsPath);
|
304617
|
-
let entry;
|
304618
304808
|
if (build_utils_1.isSymbolicLink(mode)) {
|
304619
304809
|
entry = new build_utils_1.FileFsRef({ fsPath, mode });
|
304620
304810
|
}
|
304621
|
-
|
304811
|
+
if (isEdgeFunction && path_1.basename(fsPath) === 'package.json') {
|
304812
|
+
// For Edge Functions, patch "main" field to prefer "browser" or "module"
|
304813
|
+
const pkgJson = JSON.parse(source.toString());
|
304814
|
+
for (const prop of ['browser', 'module']) {
|
304815
|
+
const val = pkgJson[prop];
|
304816
|
+
if (typeof val === 'string') {
|
304817
|
+
build_utils_1.debug(`Using "${prop}" field in ${fsPath}`);
|
304818
|
+
pkgJson.main = val;
|
304819
|
+
// Create the `entry` with the original so that the output is unmodified
|
304820
|
+
if (!entry) {
|
304821
|
+
entry = new build_utils_1.FileBlob({ data: source, mode });
|
304822
|
+
}
|
304823
|
+
// Return the modified `package.json` to nft
|
304824
|
+
source = JSON.stringify(pkgJson);
|
304825
|
+
break;
|
304826
|
+
}
|
304827
|
+
}
|
304828
|
+
}
|
304829
|
+
if ((fsPath.endsWith('.ts') && !fsPath.endsWith('.d.ts')) ||
|
304830
|
+
fsPath.endsWith('.tsx')) {
|
304831
|
+
source = compileTypeScript(fsPath, source.toString());
|
304832
|
+
}
|
304833
|
+
if (!entry) {
|
304622
304834
|
entry = new build_utils_1.FileBlob({ data: source, mode });
|
304623
304835
|
}
|
304624
304836
|
fsCache.set(relPath, entry);
|
304625
304837
|
sourceCache.set(relPath, source);
|
304626
|
-
return source
|
304838
|
+
return source;
|
304627
304839
|
}
|
304628
304840
|
catch (e) {
|
304629
304841
|
if (e.code === 'ENOENT' || e.code === 'EISDIR') {
|
304842
|
+
// `null` represents a not found
|
304630
304843
|
sourceCache.set(relPath, null);
|
304631
304844
|
return null;
|
304632
304845
|
}
|
@@ -304741,14 +304954,6 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
304741
304954
|
await build_utils_1.runPackageJsonScript(entrypointFsDirname,
|
304742
304955
|
// Don't consider "build" script since its intended for frontend code
|
304743
304956
|
['vercel-build', 'now-build'], spawnOpts);
|
304744
|
-
build_utils_1.debug('Tracing input files...');
|
304745
|
-
const traceTime = Date.now();
|
304746
|
-
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion);
|
304747
|
-
build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
|
304748
|
-
let routes;
|
304749
|
-
let output;
|
304750
|
-
const handler = renameTStoJS(path_1.relative(baseDir, entrypointPath));
|
304751
|
-
const outputPath = utils_1.entrypointToOutputPath(entrypoint, config.zeroConfig);
|
304752
304957
|
const isMiddleware = config.middleware === true;
|
304753
304958
|
// Will output an `EdgeFunction` for when `config.middleware = true`
|
304754
304959
|
// (i.e. for root-level "middleware" file) or if source code contains:
|
@@ -304762,6 +304967,14 @@ const build = async ({ files, entrypoint, workPath, repoRootPath, config = {}, m
|
|
304762
304967
|
}
|
304763
304968
|
isEdgeFunction = staticConfig.runtime === 'experimental-edge';
|
304764
304969
|
}
|
304970
|
+
build_utils_1.debug('Tracing input files...');
|
304971
|
+
const traceTime = Date.now();
|
304972
|
+
const { preparedFiles, shouldAddSourcemapSupport } = await compile(workPath, baseDir, entrypointPath, config, nodeVersion, isEdgeFunction);
|
304973
|
+
build_utils_1.debug(`Trace complete [${Date.now() - traceTime}ms]`);
|
304974
|
+
let routes;
|
304975
|
+
let output;
|
304976
|
+
const handler = renameTStoJS(path_1.relative(baseDir, entrypointPath));
|
304977
|
+
const outputPath = utils_1.entrypointToOutputPath(entrypoint, config.zeroConfig);
|
304765
304978
|
// Add a `route` for Middleware
|
304766
304979
|
if (isMiddleware) {
|
304767
304980
|
if (!isEdgeFunction) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vercel/node",
|
3
|
-
"version": "2.
|
3
|
+
"version": "2.5.2",
|
4
4
|
"license": "MIT",
|
5
5
|
"main": "./dist/index",
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/node-js",
|
@@ -11,9 +11,9 @@
|
|
11
11
|
},
|
12
12
|
"scripts": {
|
13
13
|
"build": "node build",
|
14
|
-
"test-integration-once": "yarn test test/integration.test.js",
|
15
14
|
"test": "jest --env node --verbose --bail --runInBand",
|
16
15
|
"test-unit": "yarn test test/prepare-cache.test.ts test/utils.test.ts",
|
16
|
+
"test-integration-once": "yarn test test/integration-*.test.js",
|
17
17
|
"prepublishOnly": "node build"
|
18
18
|
},
|
19
19
|
"files": [
|
@@ -31,7 +31,7 @@
|
|
31
31
|
},
|
32
32
|
"dependencies": {
|
33
33
|
"@types/node": "*",
|
34
|
-
"@vercel/build-utils": "5.0.
|
34
|
+
"@vercel/build-utils": "5.0.7",
|
35
35
|
"@vercel/node-bridge": "3.0.0",
|
36
36
|
"@vercel/static-config": "2.0.1",
|
37
37
|
"edge-runtime": "1.0.1",
|
@@ -53,7 +53,7 @@
|
|
53
53
|
"@types/node-fetch": "^2.6.1",
|
54
54
|
"@types/test-listen": "1.1.0",
|
55
55
|
"@vercel/ncc": "0.24.0",
|
56
|
-
"@vercel/nft": "0.
|
56
|
+
"@vercel/nft": "0.21.0",
|
57
57
|
"content-type": "1.0.4",
|
58
58
|
"cookie": "0.4.0",
|
59
59
|
"etag": "1.8.1",
|
@@ -61,5 +61,5 @@
|
|
61
61
|
"source-map-support": "0.5.12",
|
62
62
|
"test-listen": "1.1.0"
|
63
63
|
},
|
64
|
-
"gitHead": "
|
64
|
+
"gitHead": "e8c7db59cf2746422f1f7e14cc6b7f901c243d50"
|
65
65
|
}
|