@depup/vercel 50.32.5-depup.0
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/LICENSE +202 -0
- package/README.md +38 -0
- package/changes.json +38 -0
- package/dist/chunks/chunk-2DLBVZWU.js +197 -0
- package/dist/chunks/chunk-2HSQ7YUK.js +93 -0
- package/dist/chunks/chunk-2IQTNMUG.js +86 -0
- package/dist/chunks/chunk-3FRG2XGZ.js +466 -0
- package/dist/chunks/chunk-3KMKI2FP.js +34 -0
- package/dist/chunks/chunk-3XFFP2BA.js +110 -0
- package/dist/chunks/chunk-4S3Y3ATR.js +5383 -0
- package/dist/chunks/chunk-7EHTK7LP.js +359 -0
- package/dist/chunks/chunk-7YHZDJ4G.js +116 -0
- package/dist/chunks/chunk-A3NYPUKZ.js +17 -0
- package/dist/chunks/chunk-AA7QEJFB.js +5204 -0
- package/dist/chunks/chunk-AHU7WNL2.js +24 -0
- package/dist/chunks/chunk-AKQZ7KG3.js +4172 -0
- package/dist/chunks/chunk-AQLVWVEN.js +39155 -0
- package/dist/chunks/chunk-BQ3DXZNT.js +968 -0
- package/dist/chunks/chunk-E65JE2CC.js +102 -0
- package/dist/chunks/chunk-EKPSCRJZ.js +26 -0
- package/dist/chunks/chunk-EOZFDJSY.js +18 -0
- package/dist/chunks/chunk-FDJURQMQ.js +4676 -0
- package/dist/chunks/chunk-FLKHKWZV.js +1854 -0
- package/dist/chunks/chunk-G6BUEBF5.js +192 -0
- package/dist/chunks/chunk-GBNIO3KP.js +771 -0
- package/dist/chunks/chunk-GGP5R3FU.js +129 -0
- package/dist/chunks/chunk-H5XJSH37.js +91 -0
- package/dist/chunks/chunk-IB5L4LKZ.js +1082 -0
- package/dist/chunks/chunk-IE7MNZ56.js +149 -0
- package/dist/chunks/chunk-IK7DLK2T.js +16112 -0
- package/dist/chunks/chunk-IUGPWINM.js +104 -0
- package/dist/chunks/chunk-J7HDA5GH.js +54 -0
- package/dist/chunks/chunk-JLYZNGYY.js +293 -0
- package/dist/chunks/chunk-JQ4NA5MX.js +250 -0
- package/dist/chunks/chunk-LL26LVRR.js +81 -0
- package/dist/chunks/chunk-LW5ZNGW7.js +127 -0
- package/dist/chunks/chunk-LWBSOTJP.js +1772 -0
- package/dist/chunks/chunk-MBGJBHYD.js +388 -0
- package/dist/chunks/chunk-NUKAG3YM.js +168 -0
- package/dist/chunks/chunk-O7I4ZOCC.js +58 -0
- package/dist/chunks/chunk-OWR3XNE3.js +48 -0
- package/dist/chunks/chunk-P3SKP5WM.js +27 -0
- package/dist/chunks/chunk-P4I4DMEU.js +342 -0
- package/dist/chunks/chunk-P5Q6F5IA.js +107 -0
- package/dist/chunks/chunk-PMSMUMUO.js +30 -0
- package/dist/chunks/chunk-QXRJ52T4.js +2977 -0
- package/dist/chunks/chunk-RQXPRFRM.js +90 -0
- package/dist/chunks/chunk-S7KYDPEM.js +1564 -0
- package/dist/chunks/chunk-SGGLJFUZ.js +68 -0
- package/dist/chunks/chunk-SOTR4CXR.js +34 -0
- package/dist/chunks/chunk-TEVP63TU.js +1717 -0
- package/dist/chunks/chunk-TNBMKNET.js +323 -0
- package/dist/chunks/chunk-TZ2YI2VH.js +87 -0
- package/dist/chunks/chunk-U6XOC6E4.js +903 -0
- package/dist/chunks/chunk-V5P25P7F.js +22 -0
- package/dist/chunks/chunk-WQ5CUZWR.js +333 -0
- package/dist/chunks/chunk-WU2BPWRP.js +12237 -0
- package/dist/chunks/chunk-XPKWKPWA.js +44 -0
- package/dist/chunks/chunk-XR53KVJD.js +33 -0
- package/dist/chunks/chunk-Y4JJYHUG.js +16 -0
- package/dist/chunks/chunk-YPQSDAEW.js +29 -0
- package/dist/chunks/chunk-ZB2UO4V2.js +135 -0
- package/dist/chunks/chunk-ZLCMHY2G.js +1528 -0
- package/dist/chunks/compile-vercel-config-XU3YY2CZ.js +32 -0
- package/dist/chunks/delete-EJ2V7KQO.js +144 -0
- package/dist/chunks/disable-BKRFMX4U.js +122 -0
- package/dist/chunks/discard-4WF34DXK.js +118 -0
- package/dist/chunks/edit-FQE7JGU3.js +509 -0
- package/dist/chunks/emit-flags-datafiles-QYKPNWPX.js +17 -0
- package/dist/chunks/enable-VCNMX63U.js +122 -0
- package/dist/chunks/export-3KNVJCQR.js +133 -0
- package/dist/chunks/list-43XQCGKH.js +382 -0
- package/dist/chunks/list-DUL6PHUR.js +394 -0
- package/dist/chunks/publish-CF7GVZK3.js +128 -0
- package/dist/chunks/query-KWKO7VWO.js +954 -0
- package/dist/chunks/reorder-GU65YMIN.js +259 -0
- package/dist/chunks/restore-Q7ENGWVJ.js +158 -0
- package/dist/chunks/routes-Q5CWG44T.js +20 -0
- package/dist/chunks/schema-PJKLO2K2.js +176 -0
- package/dist/chunks/stamp-RTPE2EBB.js +15 -0
- package/dist/chunks/types-563KUQRV.js +108 -0
- package/dist/chunks/update-route-version-E3V47KNI.js +13 -0
- package/dist/commands/build/index.js +1597 -0
- package/dist/commands/deploy/index.js +1711 -0
- package/dist/commands/dev/builder-worker.cjs +95 -0
- package/dist/commands/dev/index.js +20810 -0
- package/dist/commands/env/index.js +2154 -0
- package/dist/commands/link/index.js +225 -0
- package/dist/commands/list/index.js +528 -0
- package/dist/commands-bulk.js +29627 -0
- package/dist/get-latest-worker.cjs +272 -0
- package/dist/help.js +14 -0
- package/dist/index.js +24274 -0
- package/dist/vc.js +36 -0
- package/dist/version.mjs +1 -0
- package/package.json +254 -0
|
@@ -0,0 +1,388 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
VERCEL_DIR
|
|
9
|
+
} from "./chunk-AQLVWVEN.js";
|
|
10
|
+
import {
|
|
11
|
+
ConflictingConfigFiles
|
|
12
|
+
} from "./chunk-ZLCMHY2G.js";
|
|
13
|
+
import {
|
|
14
|
+
output_manager_default
|
|
15
|
+
} from "./chunk-FDJURQMQ.js";
|
|
16
|
+
import {
|
|
17
|
+
__commonJS,
|
|
18
|
+
__require,
|
|
19
|
+
__toESM
|
|
20
|
+
} from "./chunk-TZ2YI2VH.js";
|
|
21
|
+
|
|
22
|
+
// ../../node_modules/.pnpm/dotenv@4.0.0/node_modules/dotenv/lib/main.js
|
|
23
|
+
var require_main = __commonJS({
|
|
24
|
+
"../../node_modules/.pnpm/dotenv@4.0.0/node_modules/dotenv/lib/main.js"(exports, module) {
|
|
25
|
+
"use strict";
|
|
26
|
+
var fs = __require("fs");
|
|
27
|
+
function parse(src) {
|
|
28
|
+
var obj = {};
|
|
29
|
+
src.toString().split("\n").forEach(function(line) {
|
|
30
|
+
var keyValueArr = line.match(/^\s*([\w\.\-]+)\s*=\s*(.*)?\s*$/);
|
|
31
|
+
if (keyValueArr != null) {
|
|
32
|
+
var key = keyValueArr[1];
|
|
33
|
+
var value = keyValueArr[2] ? keyValueArr[2] : "";
|
|
34
|
+
var len = value ? value.length : 0;
|
|
35
|
+
if (len > 0 && value.charAt(0) === '"' && value.charAt(len - 1) === '"') {
|
|
36
|
+
value = value.replace(/\\n/gm, "\n");
|
|
37
|
+
}
|
|
38
|
+
value = value.replace(/(^['"]|['"]$)/g, "").trim();
|
|
39
|
+
obj[key] = value;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
return obj;
|
|
43
|
+
}
|
|
44
|
+
function config(options) {
|
|
45
|
+
var path = ".env";
|
|
46
|
+
var encoding = "utf8";
|
|
47
|
+
if (options) {
|
|
48
|
+
if (options.path) {
|
|
49
|
+
path = options.path;
|
|
50
|
+
}
|
|
51
|
+
if (options.encoding) {
|
|
52
|
+
encoding = options.encoding;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
var parsedObj = parse(fs.readFileSync(path, { encoding }));
|
|
57
|
+
Object.keys(parsedObj).forEach(function(key) {
|
|
58
|
+
process.env[key] = process.env[key] || parsedObj[key];
|
|
59
|
+
});
|
|
60
|
+
return { parsed: parsedObj };
|
|
61
|
+
} catch (e) {
|
|
62
|
+
return { error: e };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
module.exports.config = config;
|
|
66
|
+
module.exports.load = config;
|
|
67
|
+
module.exports.parse = parse;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// src/util/compile-vercel-config.ts
|
|
72
|
+
var import_dotenv = __toESM(require_main(), 1);
|
|
73
|
+
import { mkdir, writeFile, unlink, access } from "fs/promises";
|
|
74
|
+
import { join, basename } from "path";
|
|
75
|
+
import { fork } from "child_process";
|
|
76
|
+
import { NowBuildError } from "@vercel/build-utils";
|
|
77
|
+
function toRouteFormat(item) {
|
|
78
|
+
if ("src" in item)
|
|
79
|
+
return item;
|
|
80
|
+
const { source, destination, headers, statusCode, permanent, ...rest } = item;
|
|
81
|
+
const route = {
|
|
82
|
+
src: source,
|
|
83
|
+
...rest
|
|
84
|
+
};
|
|
85
|
+
if (destination)
|
|
86
|
+
route.dest = destination;
|
|
87
|
+
if (headers)
|
|
88
|
+
route.headers = Object.fromEntries(headers.map((h) => [h.key, h.value]));
|
|
89
|
+
if (statusCode !== void 0) {
|
|
90
|
+
route.status = statusCode;
|
|
91
|
+
} else if (permanent !== void 0) {
|
|
92
|
+
route.status = permanent ? 308 : 307;
|
|
93
|
+
}
|
|
94
|
+
return route;
|
|
95
|
+
}
|
|
96
|
+
function normalizeConfig(config) {
|
|
97
|
+
const normalized = { ...config };
|
|
98
|
+
const { rewrites, redirects, headers } = normalized;
|
|
99
|
+
let allRoutes = normalized.routes || [];
|
|
100
|
+
const hasRoutes = allRoutes.length > 0;
|
|
101
|
+
const hasRewrites = (rewrites?.length ?? 0) > 0;
|
|
102
|
+
const hasRedirects = (redirects?.length ?? 0) > 0;
|
|
103
|
+
const hasHeaders = (headers?.length ?? 0) > 0;
|
|
104
|
+
function hasRouteFormat(items) {
|
|
105
|
+
return items?.some((item) => "src" in item) ?? false;
|
|
106
|
+
}
|
|
107
|
+
if (hasRoutes && (hasRewrites || hasRedirects || hasHeaders)) {
|
|
108
|
+
return normalized;
|
|
109
|
+
}
|
|
110
|
+
const shouldConvertRewrites = hasRewrites && hasRouteFormat(rewrites);
|
|
111
|
+
const shouldConvertRedirects = hasRedirects && hasRouteFormat(redirects);
|
|
112
|
+
const shouldConvertHeaders = hasHeaders && hasRouteFormat(headers);
|
|
113
|
+
const someWillConvert = shouldConvertRewrites || shouldConvertRedirects || shouldConvertHeaders;
|
|
114
|
+
const someWontConvert = hasRewrites && !shouldConvertRewrites || hasRedirects && !shouldConvertRedirects || hasHeaders && !shouldConvertHeaders;
|
|
115
|
+
if (someWillConvert && someWontConvert) {
|
|
116
|
+
throw new NowBuildError({
|
|
117
|
+
code: "INVALID_VERCEL_CONFIG",
|
|
118
|
+
message: "Transforms (e.g., requestHeaders) require the `routes` format, which cannot be used alongside `rewrites`, `redirects`, or `headers`. Move everything into the `routes` array instead.",
|
|
119
|
+
link: "https://vercel.com/docs/projects/project-configuration#routes"
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
if (rewrites && shouldConvertRewrites) {
|
|
123
|
+
allRoutes = [...allRoutes, ...rewrites.map(toRouteFormat)];
|
|
124
|
+
delete normalized.rewrites;
|
|
125
|
+
}
|
|
126
|
+
if (redirects && shouldConvertRedirects) {
|
|
127
|
+
allRoutes = [...allRoutes, ...redirects.map(toRouteFormat)];
|
|
128
|
+
delete normalized.redirects;
|
|
129
|
+
}
|
|
130
|
+
if (headers && shouldConvertHeaders) {
|
|
131
|
+
allRoutes = [...allRoutes, ...headers.map(toRouteFormat)];
|
|
132
|
+
delete normalized.headers;
|
|
133
|
+
}
|
|
134
|
+
if (allRoutes.length > 0) {
|
|
135
|
+
normalized.routes = allRoutes.map(toRouteFormat);
|
|
136
|
+
}
|
|
137
|
+
return normalized;
|
|
138
|
+
}
|
|
139
|
+
var VERCEL_CONFIG_EXTENSIONS = [
|
|
140
|
+
"ts",
|
|
141
|
+
"mts",
|
|
142
|
+
"js",
|
|
143
|
+
"mjs",
|
|
144
|
+
"cjs"
|
|
145
|
+
];
|
|
146
|
+
var DEFAULT_VERCEL_CONFIG_FILENAME = "Vercel config";
|
|
147
|
+
async function fileExists(filePath) {
|
|
148
|
+
try {
|
|
149
|
+
await access(filePath);
|
|
150
|
+
return true;
|
|
151
|
+
} catch {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
async function findAllVercelConfigFiles(workPath) {
|
|
156
|
+
const foundFiles = [];
|
|
157
|
+
for (const ext of VERCEL_CONFIG_EXTENSIONS) {
|
|
158
|
+
const configPath = join(workPath, `vercel.${ext}`);
|
|
159
|
+
if (await fileExists(configPath)) {
|
|
160
|
+
foundFiles.push(configPath);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return foundFiles;
|
|
164
|
+
}
|
|
165
|
+
async function findSourceVercelConfigFile(workPath) {
|
|
166
|
+
for (const ext of VERCEL_CONFIG_EXTENSIONS) {
|
|
167
|
+
const configPath = join(workPath, `vercel.${ext}`);
|
|
168
|
+
if (await fileExists(configPath)) {
|
|
169
|
+
return basename(configPath);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
async function findVercelConfigFile(workPath) {
|
|
175
|
+
const foundFiles = await findAllVercelConfigFiles(workPath);
|
|
176
|
+
if (foundFiles.length > 1) {
|
|
177
|
+
throw new ConflictingConfigFiles(
|
|
178
|
+
foundFiles,
|
|
179
|
+
"Multiple vercel config files found. Please use only one configuration file.",
|
|
180
|
+
"https://vercel.com/docs/projects/project-configuration"
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
return foundFiles[0] || null;
|
|
184
|
+
}
|
|
185
|
+
function parseConfigLoaderError(stderr) {
|
|
186
|
+
if (!stderr.trim()) {
|
|
187
|
+
return "";
|
|
188
|
+
}
|
|
189
|
+
const moduleNotFoundMatch = stderr.match(
|
|
190
|
+
/Error \[ERR_MODULE_NOT_FOUND\]: Cannot find package '([^']+)'/
|
|
191
|
+
);
|
|
192
|
+
if (moduleNotFoundMatch) {
|
|
193
|
+
const packageName = moduleNotFoundMatch[1];
|
|
194
|
+
return `Cannot find package '${packageName}'. Make sure it's installed in your project dependencies.`;
|
|
195
|
+
}
|
|
196
|
+
const syntaxErrorMatch = stderr.match(/SyntaxError: (.+?)(?:\n|$)/);
|
|
197
|
+
if (syntaxErrorMatch) {
|
|
198
|
+
return `Syntax error: ${syntaxErrorMatch[1]}`;
|
|
199
|
+
}
|
|
200
|
+
const errorMatch = stderr.match(
|
|
201
|
+
/^(?:Error|TypeError|ReferenceError): (.+?)(?:\n|$)/m
|
|
202
|
+
);
|
|
203
|
+
if (errorMatch) {
|
|
204
|
+
return errorMatch[1];
|
|
205
|
+
}
|
|
206
|
+
return stderr.trim();
|
|
207
|
+
}
|
|
208
|
+
async function compileVercelConfig(workPath) {
|
|
209
|
+
const vercelJsonPath = join(workPath, "vercel.json");
|
|
210
|
+
const nowJsonPath = join(workPath, "now.json");
|
|
211
|
+
const hasVercelJson = await fileExists(vercelJsonPath);
|
|
212
|
+
const hasNowJson = await fileExists(nowJsonPath);
|
|
213
|
+
if (hasVercelJson && hasNowJson) {
|
|
214
|
+
throw new ConflictingConfigFiles([vercelJsonPath, nowJsonPath]);
|
|
215
|
+
}
|
|
216
|
+
const vercelConfigPath = await findVercelConfigFile(workPath);
|
|
217
|
+
const vercelDir = join(workPath, VERCEL_DIR);
|
|
218
|
+
const compiledConfigPath = join(vercelDir, "vercel.json");
|
|
219
|
+
if (vercelConfigPath && hasNowJson) {
|
|
220
|
+
throw new ConflictingConfigFiles(
|
|
221
|
+
[vercelConfigPath, nowJsonPath],
|
|
222
|
+
`Both ${basename(vercelConfigPath)} and now.json exist in your project. Please use only one configuration method.`,
|
|
223
|
+
"https://vercel.com/docs/projects/project-configuration"
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
if (vercelConfigPath && hasVercelJson) {
|
|
227
|
+
throw new ConflictingConfigFiles(
|
|
228
|
+
[vercelConfigPath, vercelJsonPath],
|
|
229
|
+
`Both ${basename(vercelConfigPath)} and vercel.json exist in your project. Please use only one configuration method.`,
|
|
230
|
+
"https://vercel.com/docs/projects/project-configuration"
|
|
231
|
+
);
|
|
232
|
+
}
|
|
233
|
+
if (!vercelConfigPath) {
|
|
234
|
+
if (hasVercelJson) {
|
|
235
|
+
return {
|
|
236
|
+
configPath: vercelJsonPath,
|
|
237
|
+
wasCompiled: false
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (hasNowJson) {
|
|
241
|
+
return {
|
|
242
|
+
configPath: nowJsonPath,
|
|
243
|
+
wasCompiled: false
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
if (await fileExists(compiledConfigPath)) {
|
|
247
|
+
return {
|
|
248
|
+
configPath: compiledConfigPath,
|
|
249
|
+
wasCompiled: true,
|
|
250
|
+
sourceFile: await findSourceVercelConfigFile(workPath) ?? void 0
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
configPath: null,
|
|
255
|
+
wasCompiled: false
|
|
256
|
+
};
|
|
257
|
+
}
|
|
258
|
+
(0, import_dotenv.config)({ path: join(workPath, ".env") });
|
|
259
|
+
(0, import_dotenv.config)({ path: join(workPath, ".env.local") });
|
|
260
|
+
const tempOutPath = join(vercelDir, "vercel-temp.mjs");
|
|
261
|
+
const loaderPath = join(vercelDir, "vercel-loader.mjs");
|
|
262
|
+
try {
|
|
263
|
+
const { build } = await import("esbuild");
|
|
264
|
+
await mkdir(vercelDir, { recursive: true });
|
|
265
|
+
await build({
|
|
266
|
+
entryPoints: [vercelConfigPath],
|
|
267
|
+
bundle: true,
|
|
268
|
+
platform: "node",
|
|
269
|
+
format: "esm",
|
|
270
|
+
outfile: tempOutPath,
|
|
271
|
+
packages: "external",
|
|
272
|
+
target: "node20",
|
|
273
|
+
sourcemap: "inline"
|
|
274
|
+
});
|
|
275
|
+
const loaderScript = `
|
|
276
|
+
import { pathToFileURL } from 'url';
|
|
277
|
+
const configModule = await import(pathToFileURL(process.argv[2]).href);
|
|
278
|
+
const config = ('default' in configModule) ? configModule.default : ('config' in configModule) ? configModule.config : configModule;
|
|
279
|
+
process.send(config);
|
|
280
|
+
`;
|
|
281
|
+
await writeFile(loaderPath, loaderScript, "utf-8");
|
|
282
|
+
const config = await new Promise((resolve, reject) => {
|
|
283
|
+
const child = fork(loaderPath, [tempOutPath], {
|
|
284
|
+
stdio: ["pipe", "pipe", "pipe", "ipc"]
|
|
285
|
+
});
|
|
286
|
+
let stderrOutput = "";
|
|
287
|
+
let stdoutOutput = "";
|
|
288
|
+
if (child.stderr) {
|
|
289
|
+
child.stderr.on("data", (data) => {
|
|
290
|
+
stderrOutput += data.toString();
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
if (child.stdout) {
|
|
294
|
+
child.stdout.on("data", (data) => {
|
|
295
|
+
stdoutOutput += data.toString();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
const timeout = setTimeout(() => {
|
|
299
|
+
child.kill();
|
|
300
|
+
reject(new Error("Config loader timed out after 10 seconds"));
|
|
301
|
+
}, 1e4);
|
|
302
|
+
child.on("message", (message) => {
|
|
303
|
+
clearTimeout(timeout);
|
|
304
|
+
child.kill();
|
|
305
|
+
resolve(message);
|
|
306
|
+
});
|
|
307
|
+
child.on("error", (err) => {
|
|
308
|
+
clearTimeout(timeout);
|
|
309
|
+
reject(err);
|
|
310
|
+
});
|
|
311
|
+
child.on("exit", (code) => {
|
|
312
|
+
clearTimeout(timeout);
|
|
313
|
+
if (code !== 0) {
|
|
314
|
+
if (stderrOutput.trim()) {
|
|
315
|
+
output_manager_default.log(stderrOutput);
|
|
316
|
+
}
|
|
317
|
+
if (stdoutOutput.trim()) {
|
|
318
|
+
output_manager_default.log(stdoutOutput);
|
|
319
|
+
}
|
|
320
|
+
const parsedError = parseConfigLoaderError(stderrOutput);
|
|
321
|
+
if (parsedError) {
|
|
322
|
+
reject(new Error(parsedError));
|
|
323
|
+
} else if (stdoutOutput.trim()) {
|
|
324
|
+
reject(new Error(stdoutOutput.trim()));
|
|
325
|
+
} else {
|
|
326
|
+
reject(new Error(`Config loader exited with code ${code}`));
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
const normalizedConfig = normalizeConfig(config);
|
|
332
|
+
await writeFile(
|
|
333
|
+
compiledConfigPath,
|
|
334
|
+
JSON.stringify(normalizedConfig, null, 2),
|
|
335
|
+
"utf-8"
|
|
336
|
+
);
|
|
337
|
+
output_manager_default.debug(`Compiled ${vercelConfigPath} -> ${compiledConfigPath}`);
|
|
338
|
+
return {
|
|
339
|
+
configPath: compiledConfigPath,
|
|
340
|
+
wasCompiled: true,
|
|
341
|
+
sourceFile: await findSourceVercelConfigFile(workPath) ?? void 0
|
|
342
|
+
};
|
|
343
|
+
} catch (error) {
|
|
344
|
+
throw new NowBuildError({
|
|
345
|
+
code: error.code ?? "vercel_ts_compilation_failed",
|
|
346
|
+
message: `Failed to compile ${basename(vercelConfigPath)}: ${error.message}`,
|
|
347
|
+
link: error.link ?? "https://vercel.com/docs/projects/project-configuration"
|
|
348
|
+
});
|
|
349
|
+
} finally {
|
|
350
|
+
await Promise.all([
|
|
351
|
+
unlink(tempOutPath).catch((err) => {
|
|
352
|
+
if (err.code !== "ENOENT") {
|
|
353
|
+
output_manager_default.debug(`Failed to cleanup temp file: ${err}`);
|
|
354
|
+
}
|
|
355
|
+
}),
|
|
356
|
+
unlink(loaderPath).catch((err) => {
|
|
357
|
+
if (err.code !== "ENOENT") {
|
|
358
|
+
output_manager_default.debug(`Failed to cleanup loader file: ${err}`);
|
|
359
|
+
}
|
|
360
|
+
})
|
|
361
|
+
]);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
async function getVercelConfigPath(workPath) {
|
|
365
|
+
const vercelJsonPath = join(workPath, "vercel.json");
|
|
366
|
+
const nowJsonPath = join(workPath, "now.json");
|
|
367
|
+
const compiledConfigPath = join(workPath, VERCEL_DIR, "vercel.json");
|
|
368
|
+
if (await fileExists(vercelJsonPath)) {
|
|
369
|
+
return vercelJsonPath;
|
|
370
|
+
}
|
|
371
|
+
if (await fileExists(nowJsonPath)) {
|
|
372
|
+
return nowJsonPath;
|
|
373
|
+
}
|
|
374
|
+
if (await fileExists(compiledConfigPath)) {
|
|
375
|
+
return compiledConfigPath;
|
|
376
|
+
}
|
|
377
|
+
return nowJsonPath;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
export {
|
|
381
|
+
require_main,
|
|
382
|
+
normalizeConfig,
|
|
383
|
+
VERCEL_CONFIG_EXTENSIONS,
|
|
384
|
+
DEFAULT_VERCEL_CONFIG_FILENAME,
|
|
385
|
+
findSourceVercelConfigFile,
|
|
386
|
+
compileVercelConfig,
|
|
387
|
+
getVercelConfigPath
|
|
388
|
+
};
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
require_lib
|
|
9
|
+
} from "./chunk-QXRJ52T4.js";
|
|
10
|
+
import {
|
|
11
|
+
init_pkg,
|
|
12
|
+
pkg_default
|
|
13
|
+
} from "./chunk-3XFFP2BA.js";
|
|
14
|
+
import {
|
|
15
|
+
output_manager_default
|
|
16
|
+
} from "./chunk-FDJURQMQ.js";
|
|
17
|
+
import {
|
|
18
|
+
__toESM
|
|
19
|
+
} from "./chunk-TZ2YI2VH.js";
|
|
20
|
+
|
|
21
|
+
// src/commands/build/emit-flags-datafiles.ts
|
|
22
|
+
var import_node_fetch = __toESM(require_lib(), 1);
|
|
23
|
+
import { createHash } from "crypto";
|
|
24
|
+
import { NowBuildError } from "@vercel/build-utils";
|
|
25
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
26
|
+
import { join } from "path";
|
|
27
|
+
init_pkg();
|
|
28
|
+
var FLAGS_HOST = "https://flags.vercel.com";
|
|
29
|
+
var FLAGS_DEFINITIONS_VERSION = "1.0.1";
|
|
30
|
+
function obfuscate(sdkKey, prefixLength = 18) {
|
|
31
|
+
if (prefixLength >= sdkKey.length)
|
|
32
|
+
return sdkKey;
|
|
33
|
+
return sdkKey.slice(0, prefixLength) + "*".repeat(sdkKey.length - prefixLength);
|
|
34
|
+
}
|
|
35
|
+
function hashSdkKey(sdkKey) {
|
|
36
|
+
return createHash("sha256").update(sdkKey).digest("hex");
|
|
37
|
+
}
|
|
38
|
+
function generateDefinitionsModule(sdkKeys, values) {
|
|
39
|
+
const stringified = sdkKeys.map((_, i) => JSON.stringify(values[i]));
|
|
40
|
+
const uniqueStrings = [];
|
|
41
|
+
const stringToIndex = /* @__PURE__ */ new Map();
|
|
42
|
+
for (const s of stringified) {
|
|
43
|
+
if (!stringToIndex.has(s)) {
|
|
44
|
+
stringToIndex.set(s, uniqueStrings.length);
|
|
45
|
+
uniqueStrings.push(s);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const keyToIndex = sdkKeys.map((_, i) => stringToIndex.get(stringified[i]));
|
|
49
|
+
const hashedKeys = sdkKeys.map(hashSdkKey);
|
|
50
|
+
const lines = [
|
|
51
|
+
"const memo = (fn) => { let cached; return () => (cached ??= fn()); };",
|
|
52
|
+
""
|
|
53
|
+
];
|
|
54
|
+
for (let i = 0; i < uniqueStrings.length; i++) {
|
|
55
|
+
lines.push(
|
|
56
|
+
`const _d${i} = memo(() => JSON.parse(${JSON.stringify(uniqueStrings[i])}));`
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
lines.push("");
|
|
60
|
+
lines.push("const map = {");
|
|
61
|
+
for (let i = 0; i < sdkKeys.length; i++) {
|
|
62
|
+
lines.push(` ${JSON.stringify(hashedKeys[i])}: _d${keyToIndex[i]},`);
|
|
63
|
+
}
|
|
64
|
+
lines.push("};");
|
|
65
|
+
lines.push("");
|
|
66
|
+
lines.push("export function get(hashedSdkKey) {");
|
|
67
|
+
lines.push(" return map[hashedSdkKey]?.() ?? null;");
|
|
68
|
+
lines.push("}");
|
|
69
|
+
lines.push("");
|
|
70
|
+
lines.push(
|
|
71
|
+
`export const version = ${JSON.stringify(FLAGS_DEFINITIONS_VERSION)};`
|
|
72
|
+
);
|
|
73
|
+
return lines.join("\n");
|
|
74
|
+
}
|
|
75
|
+
async function emitFlagsDatafiles(cwd, env) {
|
|
76
|
+
output_manager_default.debug("vercel-flags: checking env vars for SDK Keys");
|
|
77
|
+
const sdkKeys = Array.from(
|
|
78
|
+
Object.values(env).reduce((acc, value) => {
|
|
79
|
+
if (typeof value === "string") {
|
|
80
|
+
if (value.startsWith("vf_")) {
|
|
81
|
+
acc.add(value);
|
|
82
|
+
} else if (value.startsWith("flags:")) {
|
|
83
|
+
const params = new URLSearchParams(value.slice("flags:".length));
|
|
84
|
+
const sdkKey = params.get("sdkKey");
|
|
85
|
+
if (sdkKey?.startsWith("vf_")) {
|
|
86
|
+
acc.add(sdkKey);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return acc;
|
|
91
|
+
}, /* @__PURE__ */ new Set())
|
|
92
|
+
);
|
|
93
|
+
output_manager_default.debug(`vercel-flags: found ${sdkKeys.length} SDK keys`);
|
|
94
|
+
const fetchPromise = Promise.all(
|
|
95
|
+
sdkKeys.map(async (sdkKey) => {
|
|
96
|
+
const headers = {
|
|
97
|
+
authorization: `Bearer ${sdkKey}`,
|
|
98
|
+
"user-agent": `VercelCLI/${pkg_default.version}`
|
|
99
|
+
};
|
|
100
|
+
if (env.VERCEL_PROJECT_ID) {
|
|
101
|
+
headers["x-vercel-project-id"] = env.VERCEL_PROJECT_ID;
|
|
102
|
+
}
|
|
103
|
+
if (env.VERCEL_ENV) {
|
|
104
|
+
headers["x-vercel-env"] = env.VERCEL_ENV;
|
|
105
|
+
}
|
|
106
|
+
if (env.VERCEL_DEPLOYMENT_ID) {
|
|
107
|
+
headers["x-vercel-deployment-id"] = env.VERCEL_DEPLOYMENT_ID;
|
|
108
|
+
}
|
|
109
|
+
if (env.VERCEL_REGION) {
|
|
110
|
+
headers["x-vercel-region"] = env.VERCEL_REGION;
|
|
111
|
+
}
|
|
112
|
+
const res = await (0, import_node_fetch.default)(`${FLAGS_HOST}/v1/datafile`, { headers });
|
|
113
|
+
if (!res.ok) {
|
|
114
|
+
throw new NowBuildError({
|
|
115
|
+
code: "VERCEL_FLAGS_DEFINITIONS_FETCH_FAILED",
|
|
116
|
+
message: `Failed to fetch flag definitions for ${obfuscate(sdkKey)}: ${res.status} ${res.statusText}`,
|
|
117
|
+
link: "https://vercel.com/docs/flags"
|
|
118
|
+
// TODO replace with better link once we have a docs page
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
return res.json();
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
const values = await output_manager_default.time(
|
|
125
|
+
"vercel-flags: load datafiles",
|
|
126
|
+
fetchPromise
|
|
127
|
+
);
|
|
128
|
+
const definitionsJs = generateDefinitionsModule(sdkKeys, values);
|
|
129
|
+
const storageDir = join(cwd, "node_modules", "@vercel", "flags-definitions");
|
|
130
|
+
const indexPath = join(storageDir, "index.js");
|
|
131
|
+
const dtsPath = join(storageDir, "index.d.ts");
|
|
132
|
+
const packageJsonPath = join(storageDir, "package.json");
|
|
133
|
+
const dts = [
|
|
134
|
+
"export function get(hashedSdkKey: string): Record<string, unknown> | null;",
|
|
135
|
+
"export const version: string;",
|
|
136
|
+
""
|
|
137
|
+
].join("\n");
|
|
138
|
+
const packageJson = {
|
|
139
|
+
name: "@vercel/flags-definitions",
|
|
140
|
+
version: FLAGS_DEFINITIONS_VERSION,
|
|
141
|
+
type: "module",
|
|
142
|
+
main: "./index.js",
|
|
143
|
+
types: "./index.d.ts",
|
|
144
|
+
exports: {
|
|
145
|
+
".": {
|
|
146
|
+
types: "./index.d.ts",
|
|
147
|
+
import: "./index.js"
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
await mkdir(storageDir, { recursive: true });
|
|
152
|
+
await Promise.all([
|
|
153
|
+
writeFile(indexPath, definitionsJs),
|
|
154
|
+
writeFile(dtsPath, dts),
|
|
155
|
+
writeFile(packageJsonPath, JSON.stringify(packageJson, null, 2))
|
|
156
|
+
]);
|
|
157
|
+
output_manager_default.debug("vercel-flags: created module");
|
|
158
|
+
output_manager_default.debug(` \u2192 ${indexPath}`);
|
|
159
|
+
output_manager_default.debug(` \u2192 ${dtsPath}`);
|
|
160
|
+
output_manager_default.debug(` \u2192 ${packageJsonPath}`);
|
|
161
|
+
output_manager_default.debug(
|
|
162
|
+
` \u2192 included definitions for keys "${sdkKeys.map((key) => obfuscate(key)).join(", ")}"`
|
|
163
|
+
);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export {
|
|
167
|
+
emitFlagsDatafiles
|
|
168
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
confirmOption,
|
|
9
|
+
packageName,
|
|
10
|
+
yesOption
|
|
11
|
+
} from "./chunk-ZLCMHY2G.js";
|
|
12
|
+
|
|
13
|
+
// src/commands/dev/command.ts
|
|
14
|
+
var devCommand = {
|
|
15
|
+
name: "dev",
|
|
16
|
+
aliases: ["develop"],
|
|
17
|
+
description: `Starts the \`${packageName} dev\` server.`,
|
|
18
|
+
arguments: [
|
|
19
|
+
{
|
|
20
|
+
name: "dir",
|
|
21
|
+
required: false
|
|
22
|
+
}
|
|
23
|
+
],
|
|
24
|
+
options: [
|
|
25
|
+
{
|
|
26
|
+
name: "listen",
|
|
27
|
+
description: "Specify a URI endpoint on which to listen [0.0.0.0:3000]",
|
|
28
|
+
argument: "URI",
|
|
29
|
+
shorthand: "l",
|
|
30
|
+
type: String,
|
|
31
|
+
deprecated: false
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: "local",
|
|
35
|
+
shorthand: "L",
|
|
36
|
+
type: Boolean,
|
|
37
|
+
deprecated: false,
|
|
38
|
+
description: "Start the dev server without linking to a Vercel project"
|
|
39
|
+
},
|
|
40
|
+
yesOption,
|
|
41
|
+
{ name: "port", shorthand: "p", type: String, deprecated: true },
|
|
42
|
+
confirmOption
|
|
43
|
+
],
|
|
44
|
+
examples: [
|
|
45
|
+
{
|
|
46
|
+
name: `Start the \`${packageName} dev\` server on port 8080`,
|
|
47
|
+
value: `${packageName} dev --listen 8080`
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
name: "Make the `vercel dev` server bind to localhost on port 5000",
|
|
51
|
+
value: `${packageName} dev --listen 127.0.0.1:5000 `
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
export {
|
|
57
|
+
devCommand
|
|
58
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
import {
|
|
8
|
+
VERCEL_DIR
|
|
9
|
+
} from "./chunk-AQLVWVEN.js";
|
|
10
|
+
import {
|
|
11
|
+
ConflictingConfigFiles,
|
|
12
|
+
InvalidLocalConfig,
|
|
13
|
+
getArgs
|
|
14
|
+
} from "./chunk-ZLCMHY2G.js";
|
|
15
|
+
|
|
16
|
+
// src/util/config/local-path.ts
|
|
17
|
+
import path from "path";
|
|
18
|
+
import { existsSync } from "fs";
|
|
19
|
+
function getLocalPathConfig(prefix) {
|
|
20
|
+
const argv = getArgs(process.argv.slice(2), {}, { permissive: true });
|
|
21
|
+
const customPath = argv["--local-config"];
|
|
22
|
+
if (customPath) {
|
|
23
|
+
if (typeof customPath !== "string") {
|
|
24
|
+
throw new InvalidLocalConfig(customPath);
|
|
25
|
+
}
|
|
26
|
+
return path.resolve(prefix, customPath);
|
|
27
|
+
}
|
|
28
|
+
const vercelConfigPath = path.join(prefix, "vercel.json");
|
|
29
|
+
const nowConfigPath = path.join(prefix, "now.json");
|
|
30
|
+
const vercelConfigExists = existsSync(vercelConfigPath);
|
|
31
|
+
const nowConfigExists = existsSync(nowConfigPath);
|
|
32
|
+
if (nowConfigExists && vercelConfigExists) {
|
|
33
|
+
throw new ConflictingConfigFiles([vercelConfigPath, nowConfigPath]);
|
|
34
|
+
}
|
|
35
|
+
const compiledConfigPath = path.join(prefix, VERCEL_DIR, "vercel.json");
|
|
36
|
+
const compiledConfigExists = existsSync(compiledConfigPath);
|
|
37
|
+
if (compiledConfigExists) {
|
|
38
|
+
return compiledConfigPath;
|
|
39
|
+
}
|
|
40
|
+
if (nowConfigExists) {
|
|
41
|
+
return nowConfigPath;
|
|
42
|
+
}
|
|
43
|
+
return vercelConfigPath;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export {
|
|
47
|
+
getLocalPathConfig
|
|
48
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createRequire as __createRequire } from 'node:module';
|
|
2
|
+
import { fileURLToPath as __fileURLToPath } from 'node:url';
|
|
3
|
+
import { dirname as __dirname_ } from 'node:path';
|
|
4
|
+
const require = __createRequire(import.meta.url);
|
|
5
|
+
const __filename = __fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = __dirname_(__filename);
|
|
7
|
+
|
|
8
|
+
// src/util/routes/edit-route.ts
|
|
9
|
+
async function editRoute(client, projectId, routeId, input, options = {}) {
|
|
10
|
+
const { teamId } = options;
|
|
11
|
+
const query = new URLSearchParams();
|
|
12
|
+
if (teamId)
|
|
13
|
+
query.set("teamId", teamId);
|
|
14
|
+
const queryString = query.toString();
|
|
15
|
+
const url = `/v1/projects/${projectId}/routes/${routeId}${queryString ? `?${queryString}` : ""}`;
|
|
16
|
+
return await client.fetch(url, {
|
|
17
|
+
method: "PATCH",
|
|
18
|
+
headers: {
|
|
19
|
+
"Content-Type": "application/json"
|
|
20
|
+
},
|
|
21
|
+
body: JSON.stringify(input)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
editRoute
|
|
27
|
+
};
|