@vercel/backends 0.8.11 → 0.8.13

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/index.mjs CHANGED
@@ -204,7 +204,7 @@ const resolveEntrypointAndFormat = async (args) => {
204
204
  if (extensionInfo.format === "auto") if (pkg.type === "module") resolvedFormat = "esm";
205
205
  else resolvedFormat = "cjs";
206
206
  }
207
- if (!resolvedFormat) throw new Error(`Unable to resolve format for ${args.entrypoint}`);
207
+ if (!resolvedFormat) resolvedFormat = "esm";
208
208
  return {
209
209
  format: resolvedFormat,
210
210
  extension: resolvedFormat === "esm" ? "mjs" : "cjs"
@@ -979,7 +979,39 @@ const nft = async (args) => {
979
979
  virtualFiles.set(join(args.repoRootPath, relPath), typeof file.data === "string" ? file.data : Buffer.from(new Uint8Array(file.data)));
980
980
  }
981
981
  const ignorePatterns = [...args.ignoreNodeModules ? ["**/node_modules/**"] : [], ...args.ignore ? Array.isArray(args.ignore) ? args.ignore : [args.ignore] : []];
982
- const nftResult = await nodeFileTrace$1([...Array.from(args.localBuildFiles).filter((p) => existsSync(p) || virtualFiles.has(p)), ...virtualFiles.keys()], {
982
+ const traceRoots = [...Array.from(args.localBuildFiles).filter((p) => existsSync(p) || virtualFiles.has(p)), ...virtualFiles.keys()];
983
+ const statOverride = memoize(async (fsPath) => {
984
+ const virtual = virtualFiles.get(fsPath);
985
+ if (virtual !== void 0) return createVirtualFileStat(virtual);
986
+ try {
987
+ return await stat(fsPath);
988
+ } catch (error) {
989
+ if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
990
+ throw error;
991
+ }
992
+ });
993
+ const readlinkOverride = memoize(async (fsPath) => {
994
+ if (virtualFiles.has(fsPath)) return null;
995
+ try {
996
+ return await readlink(fsPath);
997
+ } catch (error) {
998
+ if (isNativeError(error) && "code" in error && (error.code === "EINVAL" || error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
999
+ throw error;
1000
+ }
1001
+ });
1002
+ const readFileOverride = memoize(async (fsPath) => {
1003
+ const virtual = virtualFiles.get(fsPath);
1004
+ if (virtual !== void 0) return virtual;
1005
+ try {
1006
+ let source = await readFile(fsPath);
1007
+ if (isTypeScriptFile(fsPath)) source = (await transform(fsPath, source.toString())).code;
1008
+ return source;
1009
+ } catch (error) {
1010
+ if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "EISDIR")) return null;
1011
+ throw error;
1012
+ }
1013
+ });
1014
+ const nftResult = await nodeFileTrace$1(traceRoots, {
983
1015
  base: args.repoRootPath,
984
1016
  processCwd: args.workPath,
985
1017
  ts: true,
@@ -987,35 +1019,11 @@ const nft = async (args) => {
987
1019
  moduleSyncCatchall: true,
988
1020
  conditions: args.conditions,
989
1021
  ignore: ignorePatterns.length > 0 ? ignorePatterns : void 0,
990
- async stat(fsPath) {
991
- if (virtualFiles.has(fsPath)) return createVirtualFileStat(virtualFiles.get(fsPath));
992
- try {
993
- return await stat(fsPath);
994
- } catch (error) {
995
- if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
996
- throw error;
997
- }
998
- },
999
- async readlink(fsPath) {
1000
- if (virtualFiles.has(fsPath)) return null;
1001
- try {
1002
- return await readlink(fsPath);
1003
- } catch (error) {
1004
- if (isNativeError(error) && "code" in error && (error.code === "EINVAL" || error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
1005
- throw error;
1006
- }
1007
- },
1008
- async readFile(fsPath) {
1009
- if (virtualFiles.has(fsPath)) return virtualFiles.get(fsPath);
1010
- try {
1011
- let source = await readFile(fsPath);
1012
- if (isTypeScriptFile(fsPath)) source = (await transform(fsPath, source.toString())).code;
1013
- return source;
1014
- } catch (error) {
1015
- if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "EISDIR")) return null;
1016
- throw error;
1017
- }
1018
- }
1022
+ readFile: readFileOverride,
1023
+ ...virtualFiles.size > 0 ? {
1024
+ stat: statOverride,
1025
+ readlink: readlinkOverride
1026
+ } : {}
1019
1027
  });
1020
1028
  for (const file of nftResult.fileList) {
1021
1029
  const absolutePath = join(args.repoRootPath, file);
@@ -1030,13 +1038,10 @@ const nft = async (args) => {
1030
1038
  const outputPath = file.split(sep).join("/");
1031
1039
  if (args.localBuildFiles.has(join(args.repoRootPath, outputPath))) continue;
1032
1040
  if (stats.isSymbolicLink() || stats.isFile()) if (args.ignoreNodeModules) {
1033
- if ((stats.isSymbolicLink() ? await stat(absolutePath) : stats).isFile()) {
1034
- const content = await readFile(absolutePath, "utf-8");
1035
- args.files[outputPath] = new FileBlob({
1036
- data: content,
1037
- mode: stats.mode
1038
- });
1039
- }
1041
+ if ((stats.isSymbolicLink() ? await stat(absolutePath) : stats).isFile()) args.files[outputPath] = new FileBlob({
1042
+ data: await readFile(absolutePath),
1043
+ mode: stats.mode
1044
+ });
1040
1045
  } else args.files[outputPath] = new FileFsRef({
1041
1046
  fsPath: absolutePath,
1042
1047
  mode: stats.mode
@@ -1045,6 +1050,18 @@ const nft = async (args) => {
1045
1050
  };
1046
1051
  await nftSpan.trace(runNft);
1047
1052
  };
1053
+ /** Memoizes an async fs lookup by path, caching negative/ENOENT results too. */
1054
+ const memoize = (fn) => {
1055
+ const cache = /* @__PURE__ */ new Map();
1056
+ return (path) => {
1057
+ let cached = cache.get(path);
1058
+ if (cached === void 0) {
1059
+ cached = fn(path);
1060
+ cache.set(path, cached);
1061
+ }
1062
+ return cached;
1063
+ };
1064
+ };
1048
1065
  const JS_LIKE_EXTENSIONS = new Set([
1049
1066
  ".js",
1050
1067
  ".cjs",
@@ -1335,10 +1352,10 @@ const introspection = async (args) => {
1335
1352
  const files = args.files;
1336
1353
  const tmpDir = mkdtempSync(join(tmpdir(), "vercel-introspection-"));
1337
1354
  for (const [key, value] of Object.entries(files)) {
1338
- if (!(value instanceof FileBlob) || typeof value.data !== "string") continue;
1355
+ if (!(value instanceof FileBlob)) continue;
1339
1356
  const filePath = join(tmpDir, key);
1340
1357
  mkdirSync(dirname(filePath), { recursive: true });
1341
- writeFileSync(filePath, value.data);
1358
+ writeFileSync(filePath, typeof value.data === "string" ? value.data : new Uint8Array(value.data));
1342
1359
  }
1343
1360
  let introspectionData;
1344
1361
  let introspectionError;
@@ -81,7 +81,7 @@ const resolveEntrypointAndFormat = async (args) => {
81
81
  if (extensionInfo.format === "auto") if (pkg.type === "module") resolvedFormat = "esm";
82
82
  else resolvedFormat = "cjs";
83
83
  }
84
- if (!resolvedFormat) throw new Error(`Unable to resolve format for ${args.entrypoint}`);
84
+ if (!resolvedFormat) resolvedFormat = "esm";
85
85
  return {
86
86
  format: resolvedFormat,
87
87
  extension: resolvedFormat === "esm" ? "mjs" : "cjs"
@@ -99,7 +99,39 @@ const nft = async (args) => {
99
99
  virtualFiles.set(join(args.repoRootPath, relPath), typeof file.data === "string" ? file.data : Buffer.from(new Uint8Array(file.data)));
100
100
  }
101
101
  const ignorePatterns = [...args.ignoreNodeModules ? ["**/node_modules/**"] : [], ...args.ignore ? Array.isArray(args.ignore) ? args.ignore : [args.ignore] : []];
102
- const nftResult = await nodeFileTrace([...Array.from(args.localBuildFiles).filter((p) => existsSync(p) || virtualFiles.has(p)), ...virtualFiles.keys()], {
102
+ const traceRoots = [...Array.from(args.localBuildFiles).filter((p) => existsSync(p) || virtualFiles.has(p)), ...virtualFiles.keys()];
103
+ const statOverride = memoize(async (fsPath) => {
104
+ const virtual = virtualFiles.get(fsPath);
105
+ if (virtual !== void 0) return createVirtualFileStat(virtual);
106
+ try {
107
+ return await stat(fsPath);
108
+ } catch (error) {
109
+ if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
110
+ throw error;
111
+ }
112
+ });
113
+ const readlinkOverride = memoize(async (fsPath) => {
114
+ if (virtualFiles.has(fsPath)) return null;
115
+ try {
116
+ return await readlink(fsPath);
117
+ } catch (error) {
118
+ if (isNativeError(error) && "code" in error && (error.code === "EINVAL" || error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
119
+ throw error;
120
+ }
121
+ });
122
+ const readFileOverride = memoize(async (fsPath) => {
123
+ const virtual = virtualFiles.get(fsPath);
124
+ if (virtual !== void 0) return virtual;
125
+ try {
126
+ let source = await readFile(fsPath);
127
+ if (isTypeScriptFile(fsPath)) source = (await transform(fsPath, source.toString())).code;
128
+ return source;
129
+ } catch (error) {
130
+ if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "EISDIR")) return null;
131
+ throw error;
132
+ }
133
+ });
134
+ const nftResult = await nodeFileTrace(traceRoots, {
103
135
  base: args.repoRootPath,
104
136
  processCwd: args.workPath,
105
137
  ts: true,
@@ -107,35 +139,11 @@ const nft = async (args) => {
107
139
  moduleSyncCatchall: true,
108
140
  conditions: args.conditions,
109
141
  ignore: ignorePatterns.length > 0 ? ignorePatterns : void 0,
110
- async stat(fsPath) {
111
- if (virtualFiles.has(fsPath)) return createVirtualFileStat(virtualFiles.get(fsPath));
112
- try {
113
- return await stat(fsPath);
114
- } catch (error) {
115
- if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
116
- throw error;
117
- }
118
- },
119
- async readlink(fsPath) {
120
- if (virtualFiles.has(fsPath)) return null;
121
- try {
122
- return await readlink(fsPath);
123
- } catch (error) {
124
- if (isNativeError(error) && "code" in error && (error.code === "EINVAL" || error.code === "ENOENT" || error.code === "ENOTDIR")) return null;
125
- throw error;
126
- }
127
- },
128
- async readFile(fsPath) {
129
- if (virtualFiles.has(fsPath)) return virtualFiles.get(fsPath);
130
- try {
131
- let source = await readFile(fsPath);
132
- if (isTypeScriptFile(fsPath)) source = (await transform(fsPath, source.toString())).code;
133
- return source;
134
- } catch (error) {
135
- if (isNativeError(error) && "code" in error && (error.code === "ENOENT" || error.code === "EISDIR")) return null;
136
- throw error;
137
- }
138
- }
142
+ readFile: readFileOverride,
143
+ ...virtualFiles.size > 0 ? {
144
+ stat: statOverride,
145
+ readlink: readlinkOverride
146
+ } : {}
139
147
  });
140
148
  for (const file of nftResult.fileList) {
141
149
  const absolutePath = join(args.repoRootPath, file);
@@ -150,13 +158,10 @@ const nft = async (args) => {
150
158
  const outputPath = file.split(sep).join("/");
151
159
  if (args.localBuildFiles.has(join(args.repoRootPath, outputPath))) continue;
152
160
  if (stats.isSymbolicLink() || stats.isFile()) if (args.ignoreNodeModules) {
153
- if ((stats.isSymbolicLink() ? await stat(absolutePath) : stats).isFile()) {
154
- const content = await readFile(absolutePath, "utf-8");
155
- args.files[outputPath] = new FileBlob({
156
- data: content,
157
- mode: stats.mode
158
- });
159
- }
161
+ if ((stats.isSymbolicLink() ? await stat(absolutePath) : stats).isFile()) args.files[outputPath] = new FileBlob({
162
+ data: await readFile(absolutePath),
163
+ mode: stats.mode
164
+ });
160
165
  } else args.files[outputPath] = new FileFsRef({
161
166
  fsPath: absolutePath,
162
167
  mode: stats.mode
@@ -165,6 +170,18 @@ const nft = async (args) => {
165
170
  };
166
171
  await nftSpan.trace(runNft);
167
172
  };
173
+ /** Memoizes an async fs lookup by path, caching negative/ENOENT results too. */
174
+ const memoize = (fn) => {
175
+ const cache = /* @__PURE__ */ new Map();
176
+ return (path) => {
177
+ let cached = cache.get(path);
178
+ if (cached === void 0) {
179
+ cached = fn(path);
180
+ cache.set(path, cached);
181
+ }
182
+ return cached;
183
+ };
184
+ };
168
185
  const JS_LIKE_EXTENSIONS = new Set([
169
186
  ".js",
170
187
  ".cjs",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/backends",
3
- "version": "0.8.11",
3
+ "version": "0.8.13",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index.mjs",
6
6
  "homepage": "https://vercel.com/docs",
@@ -36,7 +36,7 @@
36
36
  "srvx": "0.8.9",
37
37
  "tsx": "4.21.0",
38
38
  "zod": "3.22.4",
39
- "@vercel/build-utils": "13.29.1"
39
+ "@vercel/build-utils": "13.30.0"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@types/express": "5.0.3",