@vercel/go 3.3.5 → 3.4.1
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.js +420 -210
- package/package.json +2 -2
- package/vc-init.go +259 -0
package/dist/index.js
CHANGED
|
@@ -450,15 +450,15 @@ var require_readShebang = __commonJS({
|
|
|
450
450
|
var require_semver = __commonJS({
|
|
451
451
|
"../../node_modules/.pnpm/semver@5.7.2/node_modules/semver/semver.js"(exports, module2) {
|
|
452
452
|
exports = module2.exports = SemVer;
|
|
453
|
-
var
|
|
453
|
+
var debug5;
|
|
454
454
|
if (typeof process === "object" && process.env && process.env.NODE_DEBUG && /\bsemver\b/i.test(process.env.NODE_DEBUG)) {
|
|
455
|
-
|
|
455
|
+
debug5 = function() {
|
|
456
456
|
var args = Array.prototype.slice.call(arguments, 0);
|
|
457
457
|
args.unshift("SEMVER");
|
|
458
458
|
console.log.apply(console, args);
|
|
459
459
|
};
|
|
460
460
|
} else {
|
|
461
|
-
|
|
461
|
+
debug5 = function() {
|
|
462
462
|
};
|
|
463
463
|
}
|
|
464
464
|
exports.SEMVER_SPEC_VERSION = "2.0.0";
|
|
@@ -567,7 +567,7 @@ var require_semver = __commonJS({
|
|
|
567
567
|
var STAR = R++;
|
|
568
568
|
src[STAR] = "(<|>)?=?\\s*\\*";
|
|
569
569
|
for (i = 0; i < R; i++) {
|
|
570
|
-
|
|
570
|
+
debug5(i, src[i]);
|
|
571
571
|
if (!re[i]) {
|
|
572
572
|
re[i] = new RegExp(src[i]);
|
|
573
573
|
safeRe[i] = new RegExp(makeSafeRe(src[i]));
|
|
@@ -634,7 +634,7 @@ var require_semver = __commonJS({
|
|
|
634
634
|
if (!(this instanceof SemVer)) {
|
|
635
635
|
return new SemVer(version2, options);
|
|
636
636
|
}
|
|
637
|
-
|
|
637
|
+
debug5("SemVer", version2, options);
|
|
638
638
|
this.options = options;
|
|
639
639
|
this.loose = !!options.loose;
|
|
640
640
|
var m = version2.trim().match(options.loose ? safeRe[LOOSE] : safeRe[FULL]);
|
|
@@ -681,7 +681,7 @@ var require_semver = __commonJS({
|
|
|
681
681
|
return this.version;
|
|
682
682
|
};
|
|
683
683
|
SemVer.prototype.compare = function(other) {
|
|
684
|
-
|
|
684
|
+
debug5("SemVer.compare", this.version, this.options, other);
|
|
685
685
|
if (!(other instanceof SemVer)) {
|
|
686
686
|
other = new SemVer(other, this.options);
|
|
687
687
|
}
|
|
@@ -708,7 +708,7 @@ var require_semver = __commonJS({
|
|
|
708
708
|
do {
|
|
709
709
|
var a = this.prerelease[i2];
|
|
710
710
|
var b = other.prerelease[i2];
|
|
711
|
-
|
|
711
|
+
debug5("prerelease compare", i2, a, b);
|
|
712
712
|
if (a === void 0 && b === void 0) {
|
|
713
713
|
return 0;
|
|
714
714
|
} else if (b === void 0) {
|
|
@@ -962,7 +962,7 @@ var require_semver = __commonJS({
|
|
|
962
962
|
return new Comparator(comp, options);
|
|
963
963
|
}
|
|
964
964
|
comp = comp.trim().split(/\s+/).join(" ");
|
|
965
|
-
|
|
965
|
+
debug5("comparator", comp, options);
|
|
966
966
|
this.options = options;
|
|
967
967
|
this.loose = !!options.loose;
|
|
968
968
|
this.parse(comp);
|
|
@@ -971,7 +971,7 @@ var require_semver = __commonJS({
|
|
|
971
971
|
} else {
|
|
972
972
|
this.value = this.operator + this.semver.version;
|
|
973
973
|
}
|
|
974
|
-
|
|
974
|
+
debug5("comp", this);
|
|
975
975
|
}
|
|
976
976
|
var ANY = {};
|
|
977
977
|
Comparator.prototype.parse = function(comp) {
|
|
@@ -994,7 +994,7 @@ var require_semver = __commonJS({
|
|
|
994
994
|
return this.value;
|
|
995
995
|
};
|
|
996
996
|
Comparator.prototype.test = function(version2) {
|
|
997
|
-
|
|
997
|
+
debug5("Comparator.test", version2, this.options.loose);
|
|
998
998
|
if (this.semver === ANY) {
|
|
999
999
|
return true;
|
|
1000
1000
|
}
|
|
@@ -1077,9 +1077,9 @@ var require_semver = __commonJS({
|
|
|
1077
1077
|
var loose = this.options.loose;
|
|
1078
1078
|
var hr = loose ? safeRe[HYPHENRANGELOOSE] : safeRe[HYPHENRANGE];
|
|
1079
1079
|
range = range.replace(hr, hyphenReplace);
|
|
1080
|
-
|
|
1080
|
+
debug5("hyphen replace", range);
|
|
1081
1081
|
range = range.replace(safeRe[COMPARATORTRIM], comparatorTrimReplace);
|
|
1082
|
-
|
|
1082
|
+
debug5("comparator trim", range, safeRe[COMPARATORTRIM]);
|
|
1083
1083
|
range = range.replace(safeRe[TILDETRIM], tildeTrimReplace);
|
|
1084
1084
|
range = range.replace(safeRe[CARETTRIM], caretTrimReplace);
|
|
1085
1085
|
var compRe = loose ? safeRe[COMPARATORLOOSE] : safeRe[COMPARATOR];
|
|
@@ -1119,15 +1119,15 @@ var require_semver = __commonJS({
|
|
|
1119
1119
|
});
|
|
1120
1120
|
}
|
|
1121
1121
|
function parseComparator(comp, options) {
|
|
1122
|
-
|
|
1122
|
+
debug5("comp", comp, options);
|
|
1123
1123
|
comp = replaceCarets(comp, options);
|
|
1124
|
-
|
|
1124
|
+
debug5("caret", comp);
|
|
1125
1125
|
comp = replaceTildes(comp, options);
|
|
1126
|
-
|
|
1126
|
+
debug5("tildes", comp);
|
|
1127
1127
|
comp = replaceXRanges(comp, options);
|
|
1128
|
-
|
|
1128
|
+
debug5("xrange", comp);
|
|
1129
1129
|
comp = replaceStars(comp, options);
|
|
1130
|
-
|
|
1130
|
+
debug5("stars", comp);
|
|
1131
1131
|
return comp;
|
|
1132
1132
|
}
|
|
1133
1133
|
function isX(id) {
|
|
@@ -1141,7 +1141,7 @@ var require_semver = __commonJS({
|
|
|
1141
1141
|
function replaceTilde(comp, options) {
|
|
1142
1142
|
var r = options.loose ? safeRe[TILDELOOSE] : safeRe[TILDE];
|
|
1143
1143
|
return comp.replace(r, function(_, M, m, p, pr) {
|
|
1144
|
-
|
|
1144
|
+
debug5("tilde", comp, _, M, m, p, pr);
|
|
1145
1145
|
var ret;
|
|
1146
1146
|
if (isX(M)) {
|
|
1147
1147
|
ret = "";
|
|
@@ -1150,12 +1150,12 @@ var require_semver = __commonJS({
|
|
|
1150
1150
|
} else if (isX(p)) {
|
|
1151
1151
|
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
1152
1152
|
} else if (pr) {
|
|
1153
|
-
|
|
1153
|
+
debug5("replaceTilde pr", pr);
|
|
1154
1154
|
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + (+m + 1) + ".0";
|
|
1155
1155
|
} else {
|
|
1156
1156
|
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + (+m + 1) + ".0";
|
|
1157
1157
|
}
|
|
1158
|
-
|
|
1158
|
+
debug5("tilde return", ret);
|
|
1159
1159
|
return ret;
|
|
1160
1160
|
});
|
|
1161
1161
|
}
|
|
@@ -1165,10 +1165,10 @@ var require_semver = __commonJS({
|
|
|
1165
1165
|
}).join(" ");
|
|
1166
1166
|
}
|
|
1167
1167
|
function replaceCaret(comp, options) {
|
|
1168
|
-
|
|
1168
|
+
debug5("caret", comp, options);
|
|
1169
1169
|
var r = options.loose ? safeRe[CARETLOOSE] : safeRe[CARET];
|
|
1170
1170
|
return comp.replace(r, function(_, M, m, p, pr) {
|
|
1171
|
-
|
|
1171
|
+
debug5("caret", comp, _, M, m, p, pr);
|
|
1172
1172
|
var ret;
|
|
1173
1173
|
if (isX(M)) {
|
|
1174
1174
|
ret = "";
|
|
@@ -1181,7 +1181,7 @@ var require_semver = __commonJS({
|
|
|
1181
1181
|
ret = ">=" + M + "." + m + ".0 <" + (+M + 1) + ".0.0";
|
|
1182
1182
|
}
|
|
1183
1183
|
} else if (pr) {
|
|
1184
|
-
|
|
1184
|
+
debug5("replaceCaret pr", pr);
|
|
1185
1185
|
if (M === "0") {
|
|
1186
1186
|
if (m === "0") {
|
|
1187
1187
|
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + M + "." + m + "." + (+p + 1);
|
|
@@ -1192,7 +1192,7 @@ var require_semver = __commonJS({
|
|
|
1192
1192
|
ret = ">=" + M + "." + m + "." + p + "-" + pr + " <" + (+M + 1) + ".0.0";
|
|
1193
1193
|
}
|
|
1194
1194
|
} else {
|
|
1195
|
-
|
|
1195
|
+
debug5("no pr");
|
|
1196
1196
|
if (M === "0") {
|
|
1197
1197
|
if (m === "0") {
|
|
1198
1198
|
ret = ">=" + M + "." + m + "." + p + " <" + M + "." + m + "." + (+p + 1);
|
|
@@ -1203,12 +1203,12 @@ var require_semver = __commonJS({
|
|
|
1203
1203
|
ret = ">=" + M + "." + m + "." + p + " <" + (+M + 1) + ".0.0";
|
|
1204
1204
|
}
|
|
1205
1205
|
}
|
|
1206
|
-
|
|
1206
|
+
debug5("caret return", ret);
|
|
1207
1207
|
return ret;
|
|
1208
1208
|
});
|
|
1209
1209
|
}
|
|
1210
1210
|
function replaceXRanges(comp, options) {
|
|
1211
|
-
|
|
1211
|
+
debug5("replaceXRanges", comp, options);
|
|
1212
1212
|
return comp.split(/\s+/).map(function(comp2) {
|
|
1213
1213
|
return replaceXRange(comp2, options);
|
|
1214
1214
|
}).join(" ");
|
|
@@ -1217,7 +1217,7 @@ var require_semver = __commonJS({
|
|
|
1217
1217
|
comp = comp.trim();
|
|
1218
1218
|
var r = options.loose ? safeRe[XRANGELOOSE] : safeRe[XRANGE];
|
|
1219
1219
|
return comp.replace(r, function(ret, gtlt, M, m, p, pr) {
|
|
1220
|
-
|
|
1220
|
+
debug5("xRange", comp, ret, gtlt, M, m, p, pr);
|
|
1221
1221
|
var xM = isX(M);
|
|
1222
1222
|
var xm = xM || isX(m);
|
|
1223
1223
|
var xp = xm || isX(p);
|
|
@@ -1260,12 +1260,12 @@ var require_semver = __commonJS({
|
|
|
1260
1260
|
} else if (xp) {
|
|
1261
1261
|
ret = ">=" + M + "." + m + ".0 <" + M + "." + (+m + 1) + ".0";
|
|
1262
1262
|
}
|
|
1263
|
-
|
|
1263
|
+
debug5("xRange return", ret);
|
|
1264
1264
|
return ret;
|
|
1265
1265
|
});
|
|
1266
1266
|
}
|
|
1267
1267
|
function replaceStars(comp, options) {
|
|
1268
|
-
|
|
1268
|
+
debug5("replaceStars", comp, options);
|
|
1269
1269
|
return comp.trim().replace(safeRe[STAR], "");
|
|
1270
1270
|
}
|
|
1271
1271
|
function hyphenReplace($0, from, fM, fm, fp, fpr, fb, to, tM, tm, tp, tpr, tb) {
|
|
@@ -1313,7 +1313,7 @@ var require_semver = __commonJS({
|
|
|
1313
1313
|
}
|
|
1314
1314
|
if (version2.prerelease.length && !options.includePrerelease) {
|
|
1315
1315
|
for (i2 = 0; i2 < set.length; i2++) {
|
|
1316
|
-
|
|
1316
|
+
debug5(set[i2].semver);
|
|
1317
1317
|
if (set[i2].semver === ANY) {
|
|
1318
1318
|
continue;
|
|
1319
1319
|
}
|
|
@@ -1658,7 +1658,7 @@ var require_cross_spawn = __commonJS({
|
|
|
1658
1658
|
var cp = require("child_process");
|
|
1659
1659
|
var parse4 = require_parse();
|
|
1660
1660
|
var enoent = require_enoent();
|
|
1661
|
-
function
|
|
1661
|
+
function spawn3(command, args, options) {
|
|
1662
1662
|
const parsed = parse4(command, args, options);
|
|
1663
1663
|
const spawned = cp.spawn(parsed.command, parsed.args, parsed.options);
|
|
1664
1664
|
enoent.hookChildProcess(spawned, parsed);
|
|
@@ -1670,8 +1670,8 @@ var require_cross_spawn = __commonJS({
|
|
|
1670
1670
|
result.error = result.error || enoent.verifyENOENTSync(result.status, parsed);
|
|
1671
1671
|
return result;
|
|
1672
1672
|
}
|
|
1673
|
-
module2.exports =
|
|
1674
|
-
module2.exports.spawn =
|
|
1673
|
+
module2.exports = spawn3;
|
|
1674
|
+
module2.exports.spawn = spawn3;
|
|
1675
1675
|
module2.exports.sync = spawnSync;
|
|
1676
1676
|
module2.exports._parse = parse4;
|
|
1677
1677
|
module2.exports._enoent = enoent;
|
|
@@ -3453,13 +3453,13 @@ var require_clone = __commonJS({
|
|
|
3453
3453
|
if (obj === null || typeof obj !== "object")
|
|
3454
3454
|
return obj;
|
|
3455
3455
|
if (obj instanceof Object)
|
|
3456
|
-
var
|
|
3456
|
+
var copy3 = { __proto__: getPrototypeOf(obj) };
|
|
3457
3457
|
else
|
|
3458
|
-
var
|
|
3458
|
+
var copy3 = /* @__PURE__ */ Object.create(null);
|
|
3459
3459
|
Object.getOwnPropertyNames(obj).forEach(function(key) {
|
|
3460
|
-
Object.defineProperty(
|
|
3460
|
+
Object.defineProperty(copy3, key, Object.getOwnPropertyDescriptor(obj, key));
|
|
3461
3461
|
});
|
|
3462
|
-
return
|
|
3462
|
+
return copy3;
|
|
3463
3463
|
}
|
|
3464
3464
|
}
|
|
3465
3465
|
});
|
|
@@ -3490,11 +3490,11 @@ var require_graceful_fs = __commonJS({
|
|
|
3490
3490
|
}
|
|
3491
3491
|
});
|
|
3492
3492
|
}
|
|
3493
|
-
var
|
|
3493
|
+
var debug5 = noop3;
|
|
3494
3494
|
if (util.debuglog)
|
|
3495
|
-
|
|
3495
|
+
debug5 = util.debuglog("gfs4");
|
|
3496
3496
|
else if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || ""))
|
|
3497
|
-
|
|
3497
|
+
debug5 = function() {
|
|
3498
3498
|
var m = util.format.apply(util, arguments);
|
|
3499
3499
|
m = "GFS4: " + m.split(/\n/).join("\nGFS4: ");
|
|
3500
3500
|
console.error(m);
|
|
@@ -3529,7 +3529,7 @@ var require_graceful_fs = __commonJS({
|
|
|
3529
3529
|
}(fs11.closeSync);
|
|
3530
3530
|
if (/\bgfs4\b/i.test(process.env.NODE_DEBUG || "")) {
|
|
3531
3531
|
process.on("exit", function() {
|
|
3532
|
-
|
|
3532
|
+
debug5(fs11[gracefulQueue]);
|
|
3533
3533
|
require("assert").equal(fs11[gracefulQueue].length, 0);
|
|
3534
3534
|
});
|
|
3535
3535
|
}
|
|
@@ -3549,8 +3549,8 @@ var require_graceful_fs = __commonJS({
|
|
|
3549
3549
|
fs12.createReadStream = createReadStream;
|
|
3550
3550
|
fs12.createWriteStream = createWriteStream2;
|
|
3551
3551
|
var fs$readFile = fs12.readFile;
|
|
3552
|
-
fs12.readFile =
|
|
3553
|
-
function
|
|
3552
|
+
fs12.readFile = readFile4;
|
|
3553
|
+
function readFile4(path8, options, cb) {
|
|
3554
3554
|
if (typeof options === "function")
|
|
3555
3555
|
cb = options, options = null;
|
|
3556
3556
|
return go$readFile(path8, options, cb);
|
|
@@ -3566,8 +3566,8 @@ var require_graceful_fs = __commonJS({
|
|
|
3566
3566
|
}
|
|
3567
3567
|
}
|
|
3568
3568
|
var fs$writeFile = fs12.writeFile;
|
|
3569
|
-
fs12.writeFile =
|
|
3570
|
-
function
|
|
3569
|
+
fs12.writeFile = writeFile3;
|
|
3570
|
+
function writeFile3(path8, data, options, cb) {
|
|
3571
3571
|
if (typeof options === "function")
|
|
3572
3572
|
cb = options, options = null;
|
|
3573
3573
|
return go$writeFile(path8, data, options, cb);
|
|
@@ -3782,7 +3782,7 @@ var require_graceful_fs = __commonJS({
|
|
|
3782
3782
|
return fs12;
|
|
3783
3783
|
}
|
|
3784
3784
|
function enqueue(elem) {
|
|
3785
|
-
|
|
3785
|
+
debug5("ENQUEUE", elem[0].name, elem[1]);
|
|
3786
3786
|
fs11[gracefulQueue].push(elem);
|
|
3787
3787
|
retry2();
|
|
3788
3788
|
}
|
|
@@ -3809,10 +3809,10 @@ var require_graceful_fs = __commonJS({
|
|
|
3809
3809
|
var startTime = elem[3];
|
|
3810
3810
|
var lastTime = elem[4];
|
|
3811
3811
|
if (startTime === void 0) {
|
|
3812
|
-
|
|
3812
|
+
debug5("RETRY", fn.name, args);
|
|
3813
3813
|
fn.apply(null, args);
|
|
3814
3814
|
} else if (Date.now() - startTime >= 6e4) {
|
|
3815
|
-
|
|
3815
|
+
debug5("TIMEOUT", fn.name, args);
|
|
3816
3816
|
var cb = args.pop();
|
|
3817
3817
|
if (typeof cb === "function")
|
|
3818
3818
|
cb.call(null, err);
|
|
@@ -3821,7 +3821,7 @@ var require_graceful_fs = __commonJS({
|
|
|
3821
3821
|
var sinceStart = Math.max(lastTime - startTime, 1);
|
|
3822
3822
|
var desiredDelay = Math.min(sinceStart * 1.2, 100);
|
|
3823
3823
|
if (sinceAttempt >= desiredDelay) {
|
|
3824
|
-
|
|
3824
|
+
debug5("RETRY", fn.name, args);
|
|
3825
3825
|
fn.apply(null, args.concat([startTime]));
|
|
3826
3826
|
} else {
|
|
3827
3827
|
fs11[gracefulQueue].push(elem);
|
|
@@ -4356,11 +4356,11 @@ var require_path_exists = __commonJS({
|
|
|
4356
4356
|
"use strict";
|
|
4357
4357
|
var u = require_universalify().fromPromise;
|
|
4358
4358
|
var fs11 = require_fs();
|
|
4359
|
-
function
|
|
4359
|
+
function pathExists5(path8) {
|
|
4360
4360
|
return fs11.access(path8).then(() => true).catch(() => false);
|
|
4361
4361
|
}
|
|
4362
4362
|
module2.exports = {
|
|
4363
|
-
pathExists: u(
|
|
4363
|
+
pathExists: u(pathExists5),
|
|
4364
4364
|
pathExistsSync: fs11.existsSync
|
|
4365
4365
|
};
|
|
4366
4366
|
}
|
|
@@ -4373,10 +4373,10 @@ var require_copy = __commonJS({
|
|
|
4373
4373
|
var fs11 = require_graceful_fs();
|
|
4374
4374
|
var path8 = require("path");
|
|
4375
4375
|
var mkdirp3 = require_mkdirs2().mkdirs;
|
|
4376
|
-
var
|
|
4376
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
4377
4377
|
var utimes = require_utimes().utimesMillis;
|
|
4378
4378
|
var notExist = Symbol("notExist");
|
|
4379
|
-
function
|
|
4379
|
+
function copy3(src, dest, opts, cb) {
|
|
4380
4380
|
if (typeof opts === "function" && !cb) {
|
|
4381
4381
|
cb = opts;
|
|
4382
4382
|
opts = {};
|
|
@@ -4403,7 +4403,7 @@ var require_copy = __commonJS({
|
|
|
4403
4403
|
}
|
|
4404
4404
|
function checkParentDir(destStat, src, dest, opts, cb) {
|
|
4405
4405
|
const destParent = path8.dirname(dest);
|
|
4406
|
-
|
|
4406
|
+
pathExists5(destParent, (err, dirExists) => {
|
|
4407
4407
|
if (err)
|
|
4408
4408
|
return cb(err);
|
|
4409
4409
|
if (dirExists)
|
|
@@ -4602,7 +4602,7 @@ var require_copy = __commonJS({
|
|
|
4602
4602
|
return cb(null, destStat);
|
|
4603
4603
|
});
|
|
4604
4604
|
}
|
|
4605
|
-
module2.exports =
|
|
4605
|
+
module2.exports = copy3;
|
|
4606
4606
|
}
|
|
4607
4607
|
});
|
|
4608
4608
|
|
|
@@ -4939,7 +4939,7 @@ var require_file = __commonJS({
|
|
|
4939
4939
|
var path8 = require("path");
|
|
4940
4940
|
var fs11 = require_graceful_fs();
|
|
4941
4941
|
var mkdir2 = require_mkdirs2();
|
|
4942
|
-
var
|
|
4942
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
4943
4943
|
function createFile2(file, callback) {
|
|
4944
4944
|
function makeFile() {
|
|
4945
4945
|
fs11.writeFile(file, "", (err) => {
|
|
@@ -4952,7 +4952,7 @@ var require_file = __commonJS({
|
|
|
4952
4952
|
if (!err && stats.isFile())
|
|
4953
4953
|
return callback();
|
|
4954
4954
|
const dir = path8.dirname(file);
|
|
4955
|
-
|
|
4955
|
+
pathExists5(dir, (err2, dirExists) => {
|
|
4956
4956
|
if (err2)
|
|
4957
4957
|
return callback(err2);
|
|
4958
4958
|
if (dirExists)
|
|
@@ -4994,7 +4994,7 @@ var require_link = __commonJS({
|
|
|
4994
4994
|
var path8 = require("path");
|
|
4995
4995
|
var fs11 = require_graceful_fs();
|
|
4996
4996
|
var mkdir2 = require_mkdirs2();
|
|
4997
|
-
var
|
|
4997
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
4998
4998
|
function createLink(srcpath, dstpath, callback) {
|
|
4999
4999
|
function makeLink(srcpath2, dstpath2) {
|
|
5000
5000
|
fs11.link(srcpath2, dstpath2, (err) => {
|
|
@@ -5003,7 +5003,7 @@ var require_link = __commonJS({
|
|
|
5003
5003
|
callback(null);
|
|
5004
5004
|
});
|
|
5005
5005
|
}
|
|
5006
|
-
|
|
5006
|
+
pathExists5(dstpath, (err, destinationExists) => {
|
|
5007
5007
|
if (err)
|
|
5008
5008
|
return callback(err);
|
|
5009
5009
|
if (destinationExists)
|
|
@@ -5014,7 +5014,7 @@ var require_link = __commonJS({
|
|
|
5014
5014
|
return callback(err2);
|
|
5015
5015
|
}
|
|
5016
5016
|
const dir = path8.dirname(dstpath);
|
|
5017
|
-
|
|
5017
|
+
pathExists5(dir, (err3, dirExists) => {
|
|
5018
5018
|
if (err3)
|
|
5019
5019
|
return callback(err3);
|
|
5020
5020
|
if (dirExists)
|
|
@@ -5058,7 +5058,7 @@ var require_symlink_paths = __commonJS({
|
|
|
5058
5058
|
"use strict";
|
|
5059
5059
|
var path8 = require("path");
|
|
5060
5060
|
var fs11 = require_graceful_fs();
|
|
5061
|
-
var
|
|
5061
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
5062
5062
|
function symlinkPaths(srcpath, dstpath, callback) {
|
|
5063
5063
|
if (path8.isAbsolute(srcpath)) {
|
|
5064
5064
|
return fs11.lstat(srcpath, (err) => {
|
|
@@ -5074,7 +5074,7 @@ var require_symlink_paths = __commonJS({
|
|
|
5074
5074
|
} else {
|
|
5075
5075
|
const dstdir = path8.dirname(dstpath);
|
|
5076
5076
|
const relativeToDst = path8.join(dstdir, srcpath);
|
|
5077
|
-
return
|
|
5077
|
+
return pathExists5(relativeToDst, (err, exists) => {
|
|
5078
5078
|
if (err)
|
|
5079
5079
|
return callback(err);
|
|
5080
5080
|
if (exists) {
|
|
@@ -5185,11 +5185,11 @@ var require_symlink = __commonJS({
|
|
|
5185
5185
|
var _symlinkType = require_symlink_type();
|
|
5186
5186
|
var symlinkType = _symlinkType.symlinkType;
|
|
5187
5187
|
var symlinkTypeSync = _symlinkType.symlinkTypeSync;
|
|
5188
|
-
var
|
|
5188
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
5189
5189
|
function createSymlink(srcpath, dstpath, type, callback) {
|
|
5190
5190
|
callback = typeof type === "function" ? type : callback;
|
|
5191
5191
|
type = typeof type === "function" ? false : type;
|
|
5192
|
-
|
|
5192
|
+
pathExists5(dstpath, (err, destinationExists) => {
|
|
5193
5193
|
if (err)
|
|
5194
5194
|
return callback(err);
|
|
5195
5195
|
if (destinationExists)
|
|
@@ -5202,7 +5202,7 @@ var require_symlink = __commonJS({
|
|
|
5202
5202
|
if (err3)
|
|
5203
5203
|
return callback(err3);
|
|
5204
5204
|
const dir = path8.dirname(dstpath);
|
|
5205
|
-
|
|
5205
|
+
pathExists5(dir, (err4, dirExists) => {
|
|
5206
5206
|
if (err4)
|
|
5207
5207
|
return callback(err4);
|
|
5208
5208
|
if (dirExists)
|
|
@@ -5274,7 +5274,7 @@ var require_jsonfile = __commonJS({
|
|
|
5274
5274
|
} catch (_) {
|
|
5275
5275
|
_fs = require("fs");
|
|
5276
5276
|
}
|
|
5277
|
-
function
|
|
5277
|
+
function readFile4(file, options, callback) {
|
|
5278
5278
|
if (callback == null) {
|
|
5279
5279
|
callback = options;
|
|
5280
5280
|
options = {};
|
|
@@ -5343,7 +5343,7 @@ var require_jsonfile = __commonJS({
|
|
|
5343
5343
|
var str = JSON.stringify(obj, options ? options.replacer : null, spaces);
|
|
5344
5344
|
return str.replace(/\n/g, EOL) + EOL;
|
|
5345
5345
|
}
|
|
5346
|
-
function
|
|
5346
|
+
function writeFile3(file, obj, options, callback) {
|
|
5347
5347
|
if (callback == null) {
|
|
5348
5348
|
callback = options;
|
|
5349
5349
|
options = {};
|
|
@@ -5373,9 +5373,9 @@ var require_jsonfile = __commonJS({
|
|
|
5373
5373
|
return content;
|
|
5374
5374
|
}
|
|
5375
5375
|
var jsonfile = {
|
|
5376
|
-
readFile:
|
|
5376
|
+
readFile: readFile4,
|
|
5377
5377
|
readFileSync,
|
|
5378
|
-
writeFile:
|
|
5378
|
+
writeFile: writeFile3,
|
|
5379
5379
|
writeFileSync
|
|
5380
5380
|
};
|
|
5381
5381
|
module2.exports = jsonfile;
|
|
@@ -5404,7 +5404,7 @@ var require_output_json = __commonJS({
|
|
|
5404
5404
|
"use strict";
|
|
5405
5405
|
var path8 = require("path");
|
|
5406
5406
|
var mkdir2 = require_mkdirs2();
|
|
5407
|
-
var
|
|
5407
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
5408
5408
|
var jsonFile = require_jsonfile2();
|
|
5409
5409
|
function outputJson(file, data, options, callback) {
|
|
5410
5410
|
if (typeof options === "function") {
|
|
@@ -5412,7 +5412,7 @@ var require_output_json = __commonJS({
|
|
|
5412
5412
|
options = {};
|
|
5413
5413
|
}
|
|
5414
5414
|
const dir = path8.dirname(file);
|
|
5415
|
-
|
|
5415
|
+
pathExists5(dir, (err, itDoes) => {
|
|
5416
5416
|
if (err)
|
|
5417
5417
|
return callback(err);
|
|
5418
5418
|
if (itDoes)
|
|
@@ -5573,10 +5573,10 @@ var require_move = __commonJS({
|
|
|
5573
5573
|
var u = require_universalify().fromCallback;
|
|
5574
5574
|
var fs11 = require_graceful_fs();
|
|
5575
5575
|
var path8 = require("path");
|
|
5576
|
-
var
|
|
5576
|
+
var copy3 = require_copy2().copy;
|
|
5577
5577
|
var remove3 = require_remove().remove;
|
|
5578
5578
|
var mkdirp3 = require_mkdirs2().mkdirp;
|
|
5579
|
-
var
|
|
5579
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
5580
5580
|
function move2(src, dest, opts, cb) {
|
|
5581
5581
|
if (typeof opts === "function") {
|
|
5582
5582
|
cb = opts;
|
|
@@ -5608,7 +5608,7 @@ var require_move = __commonJS({
|
|
|
5608
5608
|
return rename(src, dest, overwrite, cb);
|
|
5609
5609
|
});
|
|
5610
5610
|
}
|
|
5611
|
-
|
|
5611
|
+
pathExists5(dest, (err, destExists) => {
|
|
5612
5612
|
if (err)
|
|
5613
5613
|
return cb(err);
|
|
5614
5614
|
if (destExists)
|
|
@@ -5630,7 +5630,7 @@ var require_move = __commonJS({
|
|
|
5630
5630
|
overwrite,
|
|
5631
5631
|
errorOnExist: true
|
|
5632
5632
|
};
|
|
5633
|
-
|
|
5633
|
+
copy3(src, dest, opts, (err) => {
|
|
5634
5634
|
if (err)
|
|
5635
5635
|
return cb(err);
|
|
5636
5636
|
return remove3(src, cb);
|
|
@@ -5657,14 +5657,14 @@ var require_output = __commonJS({
|
|
|
5657
5657
|
var fs11 = require_graceful_fs();
|
|
5658
5658
|
var path8 = require("path");
|
|
5659
5659
|
var mkdir2 = require_mkdirs2();
|
|
5660
|
-
var
|
|
5660
|
+
var pathExists5 = require_path_exists().pathExists;
|
|
5661
5661
|
function outputFile(file, data, encoding, callback) {
|
|
5662
5662
|
if (typeof encoding === "function") {
|
|
5663
5663
|
callback = encoding;
|
|
5664
5664
|
encoding = "utf8";
|
|
5665
5665
|
}
|
|
5666
5666
|
const dir = path8.dirname(file);
|
|
5667
|
-
|
|
5667
|
+
pathExists5(dir, (err, itDoes) => {
|
|
5668
5668
|
if (err)
|
|
5669
5669
|
return callback(err);
|
|
5670
5670
|
if (itDoes)
|
|
@@ -10883,7 +10883,7 @@ __export(src_exports, {
|
|
|
10883
10883
|
build: () => build,
|
|
10884
10884
|
getNewHandlerFunctionName: () => getNewHandlerFunctionName,
|
|
10885
10885
|
prepareCache: () => prepareCache,
|
|
10886
|
-
shouldServe: () =>
|
|
10886
|
+
shouldServe: () => import_build_utils4.shouldServe,
|
|
10887
10887
|
startDevServer: () => startDevServer,
|
|
10888
10888
|
version: () => version
|
|
10889
10889
|
});
|
|
@@ -10891,11 +10891,11 @@ module.exports = __toCommonJS(src_exports);
|
|
|
10891
10891
|
var import_execa2 = __toESM(require_execa());
|
|
10892
10892
|
var import_async_retry = __toESM(require_lib());
|
|
10893
10893
|
var import_os2 = require("os");
|
|
10894
|
-
var
|
|
10894
|
+
var import_child_process2 = require("child_process");
|
|
10895
10895
|
var import_once = __toESM(require_dist());
|
|
10896
|
-
var
|
|
10897
|
-
var
|
|
10898
|
-
var
|
|
10896
|
+
var import_path7 = require("path");
|
|
10897
|
+
var import_fs_extra4 = __toESM(require_lib2());
|
|
10898
|
+
var import_build_utils4 = require("@vercel/build-utils");
|
|
10899
10899
|
|
|
10900
10900
|
// src/go-helpers.ts
|
|
10901
10901
|
var import_crypto = require("crypto");
|
|
@@ -17114,53 +17114,222 @@ function parseGoModVersion(content) {
|
|
|
17114
17114
|
throw err;
|
|
17115
17115
|
}
|
|
17116
17116
|
|
|
17117
|
+
// src/entrypoint.ts
|
|
17118
|
+
var import_path5 = require("path");
|
|
17119
|
+
var import_fs_extra2 = __toESM(require_lib2());
|
|
17120
|
+
var import_build_utils2 = require("@vercel/build-utils");
|
|
17121
|
+
var GO_CANDIDATE_ENTRYPOINTS = [
|
|
17122
|
+
"main.go",
|
|
17123
|
+
"cmd/api/main.go",
|
|
17124
|
+
"cmd/server/main.go"
|
|
17125
|
+
];
|
|
17126
|
+
async function detectGoEntrypoint(workPath, configuredEntrypoint) {
|
|
17127
|
+
if (await (0, import_fs_extra2.pathExists)((0, import_path5.join)(workPath, configuredEntrypoint))) {
|
|
17128
|
+
(0, import_build_utils2.debug)(`Using configured Go entrypoint: ${configuredEntrypoint}`);
|
|
17129
|
+
return configuredEntrypoint;
|
|
17130
|
+
}
|
|
17131
|
+
for (const candidate of GO_CANDIDATE_ENTRYPOINTS) {
|
|
17132
|
+
if (await (0, import_fs_extra2.pathExists)((0, import_path5.join)(workPath, candidate))) {
|
|
17133
|
+
(0, import_build_utils2.debug)(`Detected Go entrypoint: ${candidate}`);
|
|
17134
|
+
return candidate;
|
|
17135
|
+
}
|
|
17136
|
+
}
|
|
17137
|
+
return null;
|
|
17138
|
+
}
|
|
17139
|
+
|
|
17140
|
+
// src/standalone-server.ts
|
|
17141
|
+
var import_child_process = require("child_process");
|
|
17142
|
+
var import_path6 = require("path");
|
|
17143
|
+
var import_fs_extra3 = __toESM(require_lib2());
|
|
17144
|
+
var import_build_utils3 = require("@vercel/build-utils");
|
|
17145
|
+
async function findGoModPath(entrypointDir, workPath) {
|
|
17146
|
+
let goModPath = void 0;
|
|
17147
|
+
let isGoModInRootDir = false;
|
|
17148
|
+
let dir = entrypointDir;
|
|
17149
|
+
while (!isGoModInRootDir) {
|
|
17150
|
+
isGoModInRootDir = dir === workPath;
|
|
17151
|
+
const goMod = (0, import_path6.join)(dir, "go.mod");
|
|
17152
|
+
if (await (0, import_fs_extra3.pathExists)(goMod)) {
|
|
17153
|
+
goModPath = goMod;
|
|
17154
|
+
(0, import_build_utils3.debug)(`Found ${goModPath}"`);
|
|
17155
|
+
break;
|
|
17156
|
+
}
|
|
17157
|
+
dir = (0, import_path6.dirname)(dir);
|
|
17158
|
+
}
|
|
17159
|
+
return {
|
|
17160
|
+
goModPath,
|
|
17161
|
+
isGoModInRootDir
|
|
17162
|
+
};
|
|
17163
|
+
}
|
|
17164
|
+
async function buildStandaloneServer({
|
|
17165
|
+
files,
|
|
17166
|
+
entrypoint,
|
|
17167
|
+
config,
|
|
17168
|
+
workPath,
|
|
17169
|
+
meta = {}
|
|
17170
|
+
}) {
|
|
17171
|
+
(0, import_build_utils3.debug)(`Building standalone Go server: ${entrypoint}`);
|
|
17172
|
+
await (0, import_build_utils3.download)(files, workPath, meta);
|
|
17173
|
+
const lambdaOptions = await (0, import_build_utils3.getLambdaOptionsFromFunction)({
|
|
17174
|
+
sourceFile: entrypoint,
|
|
17175
|
+
config
|
|
17176
|
+
});
|
|
17177
|
+
const architecture = lambdaOptions?.architecture || "x86_64";
|
|
17178
|
+
const env = (0, import_build_utils3.cloneEnv)(process.env, meta.env, {
|
|
17179
|
+
GOARCH: architecture === "arm64" ? "arm64" : "amd64",
|
|
17180
|
+
GOOS: "linux",
|
|
17181
|
+
CGO_ENABLED: "0"
|
|
17182
|
+
});
|
|
17183
|
+
const { goModPath } = await findGoModPath(workPath, workPath);
|
|
17184
|
+
const modulePath = goModPath ? (0, import_path6.dirname)(goModPath) : workPath;
|
|
17185
|
+
const go = await createGo({
|
|
17186
|
+
modulePath,
|
|
17187
|
+
opts: { cwd: workPath, env },
|
|
17188
|
+
workPath
|
|
17189
|
+
});
|
|
17190
|
+
const outDir = await (0, import_build_utils3.getWriteableDirectory)();
|
|
17191
|
+
const userServerPath = (0, import_path6.join)(outDir, "user-server");
|
|
17192
|
+
const bootstrapPath = (0, import_path6.join)(outDir, "executable");
|
|
17193
|
+
const buildTarget = entrypoint === "main.go" ? "." : "./" + (0, import_path6.dirname)(entrypoint);
|
|
17194
|
+
(0, import_build_utils3.debug)(
|
|
17195
|
+
`Building user Go server (${architecture}): go build ${buildTarget} -> ${userServerPath}`
|
|
17196
|
+
);
|
|
17197
|
+
try {
|
|
17198
|
+
await go.build(buildTarget, userServerPath);
|
|
17199
|
+
} catch (err) {
|
|
17200
|
+
console.error(`Failed to build standalone Go server: ${buildTarget}`);
|
|
17201
|
+
throw err;
|
|
17202
|
+
}
|
|
17203
|
+
const bootstrapSrc = (0, import_path6.join)(__dirname, "../vc-init.go");
|
|
17204
|
+
(0, import_build_utils3.debug)(`Building bootstrap wrapper: ${bootstrapSrc} -> ${bootstrapPath}`);
|
|
17205
|
+
try {
|
|
17206
|
+
const bootstrapBuildDir = await (0, import_build_utils3.getWriteableDirectory)();
|
|
17207
|
+
const bootstrapGoFile = (0, import_path6.join)(bootstrapBuildDir, "main.go");
|
|
17208
|
+
await (0, import_fs_extra3.copy)(bootstrapSrc, bootstrapGoFile);
|
|
17209
|
+
const bootstrapGoMod = (0, import_path6.join)(bootstrapBuildDir, "go.mod");
|
|
17210
|
+
await (0, import_fs_extra3.writeFile)(bootstrapGoMod, "module vc-init\n\ngo 1.21\n");
|
|
17211
|
+
const bootstrapGo = await createGo({
|
|
17212
|
+
modulePath: bootstrapBuildDir,
|
|
17213
|
+
opts: { cwd: bootstrapBuildDir, env },
|
|
17214
|
+
workPath: bootstrapBuildDir
|
|
17215
|
+
});
|
|
17216
|
+
await bootstrapGo.build(".", bootstrapPath);
|
|
17217
|
+
} catch (err) {
|
|
17218
|
+
console.error("Failed to build bootstrap wrapper");
|
|
17219
|
+
throw err;
|
|
17220
|
+
}
|
|
17221
|
+
const includedFiles = {};
|
|
17222
|
+
if (config && config.includeFiles) {
|
|
17223
|
+
const patterns = Array.isArray(config.includeFiles) ? config.includeFiles : [config.includeFiles];
|
|
17224
|
+
for (const pattern of patterns) {
|
|
17225
|
+
const fsFiles = await (0, import_build_utils3.glob)(pattern, workPath);
|
|
17226
|
+
for (const [assetName, asset] of Object.entries(fsFiles)) {
|
|
17227
|
+
includedFiles[assetName] = asset;
|
|
17228
|
+
}
|
|
17229
|
+
}
|
|
17230
|
+
}
|
|
17231
|
+
const [userServerData, bootstrapData] = await Promise.all([
|
|
17232
|
+
(0, import_fs_extra3.readFile)(userServerPath),
|
|
17233
|
+
(0, import_fs_extra3.readFile)(bootstrapPath)
|
|
17234
|
+
]);
|
|
17235
|
+
const lambda = new import_build_utils3.Lambda({
|
|
17236
|
+
...lambdaOptions,
|
|
17237
|
+
files: {
|
|
17238
|
+
...includedFiles,
|
|
17239
|
+
// Bootstrap is the main entrypoint (handles IPC protocol)
|
|
17240
|
+
executable: new import_build_utils3.FileBlob({ mode: 493, data: bootstrapData }),
|
|
17241
|
+
// User's server is spawned by bootstrap
|
|
17242
|
+
"user-server": new import_build_utils3.FileBlob({ mode: 493, data: userServerData })
|
|
17243
|
+
},
|
|
17244
|
+
handler: "executable",
|
|
17245
|
+
runtime: "executable",
|
|
17246
|
+
supportsResponseStreaming: true,
|
|
17247
|
+
architecture,
|
|
17248
|
+
runtimeLanguage: "go"
|
|
17249
|
+
});
|
|
17250
|
+
return { output: lambda };
|
|
17251
|
+
}
|
|
17252
|
+
async function startStandaloneDevServer(opts, resolvedEntrypoint) {
|
|
17253
|
+
const { workPath, meta = {} } = opts;
|
|
17254
|
+
const port = Math.floor(Math.random() * (65535 - 49152) + 49152);
|
|
17255
|
+
const env = (0, import_build_utils3.cloneEnv)(process.env, meta.env, {
|
|
17256
|
+
PORT: String(port)
|
|
17257
|
+
});
|
|
17258
|
+
const runTarget = resolvedEntrypoint === "main.go" ? "." : "./" + (0, import_path6.dirname)(resolvedEntrypoint);
|
|
17259
|
+
(0, import_build_utils3.debug)(
|
|
17260
|
+
`Starting standalone Go dev server: go run ${runTarget} (port ${port})`
|
|
17261
|
+
);
|
|
17262
|
+
const child = (0, import_child_process.spawn)("go", ["run", runTarget], {
|
|
17263
|
+
cwd: workPath,
|
|
17264
|
+
env,
|
|
17265
|
+
stdio: ["ignore", "pipe", "pipe"]
|
|
17266
|
+
});
|
|
17267
|
+
child.stdout?.on("data", (data) => {
|
|
17268
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
17269
|
+
if (opts.onStdout) {
|
|
17270
|
+
opts.onStdout(chunk);
|
|
17271
|
+
} else {
|
|
17272
|
+
process.stdout.write(chunk.toString());
|
|
17273
|
+
}
|
|
17274
|
+
});
|
|
17275
|
+
child.stderr?.on("data", (data) => {
|
|
17276
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
17277
|
+
if (opts.onStderr) {
|
|
17278
|
+
opts.onStderr(chunk);
|
|
17279
|
+
} else {
|
|
17280
|
+
process.stderr.write(chunk.toString());
|
|
17281
|
+
}
|
|
17282
|
+
});
|
|
17283
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
17284
|
+
return {
|
|
17285
|
+
port,
|
|
17286
|
+
pid: child.pid
|
|
17287
|
+
};
|
|
17288
|
+
}
|
|
17289
|
+
|
|
17117
17290
|
// src/index.ts
|
|
17118
17291
|
var TMP = (0, import_os2.tmpdir)();
|
|
17119
17292
|
var MAIN_GO_FILENAME = "main__vc__go__.go";
|
|
17120
17293
|
var HANDLER_FILENAME = `bootstrap${OUT_EXTENSION}`;
|
|
17121
17294
|
async function initPrivateGit(credentials) {
|
|
17122
|
-
const gitCredentialsPath = (0,
|
|
17295
|
+
const gitCredentialsPath = (0, import_path7.join)((0, import_os2.homedir)(), ".git-credentials");
|
|
17123
17296
|
await (0, import_execa2.default)("git", [
|
|
17124
17297
|
"config",
|
|
17125
17298
|
"--global",
|
|
17126
17299
|
"credential.helper",
|
|
17127
17300
|
`store --file ${gitCredentialsPath}`
|
|
17128
17301
|
]);
|
|
17129
|
-
await (0,
|
|
17302
|
+
await (0, import_fs_extra4.writeFile)(gitCredentialsPath, credentials);
|
|
17130
17303
|
}
|
|
17131
17304
|
function getRenamedEntrypoint(entrypoint) {
|
|
17132
|
-
const filename = (0,
|
|
17305
|
+
const filename = (0, import_path7.basename)(entrypoint);
|
|
17133
17306
|
if (filename.startsWith("[")) {
|
|
17134
17307
|
const newEntrypoint = entrypoint.replace("/[", "/now-bracket[");
|
|
17135
|
-
(0,
|
|
17308
|
+
(0, import_build_utils4.debug)(`Renamed entrypoint from ${entrypoint} to ${newEntrypoint}`);
|
|
17136
17309
|
return newEntrypoint;
|
|
17137
17310
|
}
|
|
17138
17311
|
return void 0;
|
|
17139
17312
|
}
|
|
17140
17313
|
var version = 3;
|
|
17141
|
-
async function build({
|
|
17142
|
-
files,
|
|
17143
|
-
entrypoint
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
meta = {}
|
|
17147
|
-
}) {
|
|
17148
|
-
const goPath = await (0, import_build_utils2.getWriteableDirectory)();
|
|
17149
|
-
const srcPath = (0, import_path5.join)(goPath, "src", "lambda");
|
|
17314
|
+
async function build(options) {
|
|
17315
|
+
const { files, config, workPath, meta = {} } = options;
|
|
17316
|
+
let { entrypoint } = options;
|
|
17317
|
+
const goPath = await (0, import_build_utils4.getWriteableDirectory)();
|
|
17318
|
+
const srcPath = (0, import_path7.join)(goPath, "src", "lambda");
|
|
17150
17319
|
const downloadPath = meta.skipDownload ? workPath : srcPath;
|
|
17151
|
-
await (0,
|
|
17320
|
+
await (0, import_build_utils4.download)(files, downloadPath, meta);
|
|
17152
17321
|
const undo = {
|
|
17153
17322
|
fileActions: [],
|
|
17154
17323
|
directoryCreation: [],
|
|
17155
17324
|
functionRenames: []
|
|
17156
17325
|
};
|
|
17157
|
-
const env = (0,
|
|
17326
|
+
const env = (0, import_build_utils4.cloneEnv)(process.env, meta.env, {
|
|
17158
17327
|
GOARCH: "amd64",
|
|
17159
17328
|
GOOS: "linux"
|
|
17160
17329
|
});
|
|
17161
17330
|
try {
|
|
17162
17331
|
if (env.GIT_CREDENTIALS) {
|
|
17163
|
-
(0,
|
|
17332
|
+
(0, import_build_utils4.debug)("Initialize Git credentials...");
|
|
17164
17333
|
await initPrivateGit(env.GIT_CREDENTIALS);
|
|
17165
17334
|
}
|
|
17166
17335
|
if (env.GO111MODULE) {
|
|
@@ -17175,28 +17344,41 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17175
17344
|
Learn more: https://github.com/golang/go/wiki/Modules
|
|
17176
17345
|
`);
|
|
17177
17346
|
}
|
|
17178
|
-
|
|
17347
|
+
if (config?.framework === "go" || config?.framework === "services") {
|
|
17348
|
+
const resolvedEntrypoint = await detectGoEntrypoint(workPath, entrypoint);
|
|
17349
|
+
if (!resolvedEntrypoint) {
|
|
17350
|
+
throw new Error(
|
|
17351
|
+
`No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(", ")}`
|
|
17352
|
+
);
|
|
17353
|
+
}
|
|
17354
|
+
(0, import_build_utils4.debug)(`Using standalone Go server mode for ${resolvedEntrypoint}`);
|
|
17355
|
+
return buildStandaloneServer({
|
|
17356
|
+
...options,
|
|
17357
|
+
entrypoint: resolvedEntrypoint
|
|
17358
|
+
});
|
|
17359
|
+
}
|
|
17360
|
+
const originalEntrypointAbsolute = (0, import_path7.join)(workPath, entrypoint);
|
|
17179
17361
|
const renamedEntrypoint = getRenamedEntrypoint(entrypoint);
|
|
17180
17362
|
if (renamedEntrypoint) {
|
|
17181
|
-
await (0,
|
|
17363
|
+
await (0, import_fs_extra4.move)((0, import_path7.join)(workPath, entrypoint), (0, import_path7.join)(workPath, renamedEntrypoint));
|
|
17182
17364
|
undo.fileActions.push({
|
|
17183
|
-
to: (0,
|
|
17184
|
-
from: (0,
|
|
17365
|
+
to: (0, import_path7.join)(workPath, entrypoint),
|
|
17366
|
+
from: (0, import_path7.join)(workPath, renamedEntrypoint)
|
|
17185
17367
|
});
|
|
17186
17368
|
entrypoint = renamedEntrypoint;
|
|
17187
17369
|
}
|
|
17188
|
-
const entrypointAbsolute = (0,
|
|
17189
|
-
const entrypointDirname = (0,
|
|
17190
|
-
const { goModPath, isGoModInRootDir } = await
|
|
17370
|
+
const entrypointAbsolute = (0, import_path7.join)(workPath, entrypoint);
|
|
17371
|
+
const entrypointDirname = (0, import_path7.dirname)(entrypointAbsolute);
|
|
17372
|
+
const { goModPath, isGoModInRootDir } = await findGoModPath2(
|
|
17191
17373
|
entrypointDirname,
|
|
17192
17374
|
workPath
|
|
17193
17375
|
);
|
|
17194
|
-
if (!goModPath && await (0,
|
|
17376
|
+
if (!goModPath && await (0, import_fs_extra4.pathExists)((0, import_path7.join)(workPath, "vendor"))) {
|
|
17195
17377
|
throw new Error("`go.mod` is required to use a `vendor` directory.");
|
|
17196
17378
|
}
|
|
17197
17379
|
const analyzed = await getAnalyzedEntrypoint({
|
|
17198
17380
|
entrypoint,
|
|
17199
|
-
modulePath: goModPath ? (0,
|
|
17381
|
+
modulePath: goModPath ? (0, import_path7.dirname)(goModPath) : void 0,
|
|
17200
17382
|
workPath
|
|
17201
17383
|
});
|
|
17202
17384
|
const packageName = analyzed.packageName;
|
|
@@ -17222,13 +17404,13 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17222
17404
|
if (config && config.includeFiles) {
|
|
17223
17405
|
const patterns = Array.isArray(config.includeFiles) ? config.includeFiles : [config.includeFiles];
|
|
17224
17406
|
for (const pattern of patterns) {
|
|
17225
|
-
const fsFiles = await (0,
|
|
17407
|
+
const fsFiles = await (0, import_build_utils4.glob)(pattern, entrypointDirname);
|
|
17226
17408
|
for (const [assetName, asset] of Object.entries(fsFiles)) {
|
|
17227
17409
|
includedFiles[assetName] = asset;
|
|
17228
17410
|
}
|
|
17229
17411
|
}
|
|
17230
17412
|
}
|
|
17231
|
-
const modulePath = goModPath ? (0,
|
|
17413
|
+
const modulePath = goModPath ? (0, import_path7.dirname)(goModPath) : void 0;
|
|
17232
17414
|
const go = await createGo({
|
|
17233
17415
|
modulePath,
|
|
17234
17416
|
opts: {
|
|
@@ -17237,7 +17419,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17237
17419
|
},
|
|
17238
17420
|
workPath
|
|
17239
17421
|
});
|
|
17240
|
-
const outDir = await (0,
|
|
17422
|
+
const outDir = await (0, import_build_utils4.getWriteableDirectory)();
|
|
17241
17423
|
const buildOptions = {
|
|
17242
17424
|
downloadPath,
|
|
17243
17425
|
entrypoint,
|
|
@@ -17256,9 +17438,9 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17256
17438
|
} else {
|
|
17257
17439
|
await buildHandlerWithGoMod(buildOptions);
|
|
17258
17440
|
}
|
|
17259
|
-
const runtime = await (0,
|
|
17260
|
-
const lambda = new
|
|
17261
|
-
files: { ...await (0,
|
|
17441
|
+
const runtime = await (0, import_build_utils4.getProvidedRuntime)();
|
|
17442
|
+
const lambda = new import_build_utils4.Lambda({
|
|
17443
|
+
files: { ...await (0, import_build_utils4.glob)("**", outDir), ...includedFiles },
|
|
17262
17444
|
handler: HANDLER_FILENAME,
|
|
17263
17445
|
runtime,
|
|
17264
17446
|
runtimeLanguage: "go",
|
|
@@ -17269,7 +17451,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17269
17451
|
output: lambda
|
|
17270
17452
|
};
|
|
17271
17453
|
} catch (error) {
|
|
17272
|
-
(0,
|
|
17454
|
+
(0, import_build_utils4.debug)(`Go Builder Error: ${error}`);
|
|
17273
17455
|
throw error;
|
|
17274
17456
|
} finally {
|
|
17275
17457
|
try {
|
|
@@ -17278,7 +17460,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17278
17460
|
if (error instanceof Error) {
|
|
17279
17461
|
console.error(`Build cleanup failed: ${error.message}`);
|
|
17280
17462
|
}
|
|
17281
|
-
(0,
|
|
17463
|
+
(0, import_build_utils4.debug)("Cleanup Error: " + error);
|
|
17282
17464
|
}
|
|
17283
17465
|
}
|
|
17284
17466
|
}
|
|
@@ -17295,20 +17477,20 @@ async function buildHandlerWithGoMod({
|
|
|
17295
17477
|
packageName,
|
|
17296
17478
|
undo
|
|
17297
17479
|
}) {
|
|
17298
|
-
(0,
|
|
17480
|
+
(0, import_build_utils4.debug)(
|
|
17299
17481
|
`Building Go handler as package "${packageName}" (with${goModPath ? "" : "out"} go.mod)`
|
|
17300
17482
|
);
|
|
17301
17483
|
let goModDirname;
|
|
17302
17484
|
if (goModPath !== void 0) {
|
|
17303
|
-
goModDirname = (0,
|
|
17304
|
-
const backupFile = (0,
|
|
17305
|
-
await (0,
|
|
17485
|
+
goModDirname = (0, import_path7.dirname)(goModPath);
|
|
17486
|
+
const backupFile = (0, import_path7.join)(goModDirname, `__vc_go.mod.bak`);
|
|
17487
|
+
await (0, import_fs_extra4.copy)(goModPath, backupFile);
|
|
17306
17488
|
undo.fileActions.push({
|
|
17307
17489
|
to: goModPath,
|
|
17308
17490
|
from: backupFile
|
|
17309
17491
|
});
|
|
17310
|
-
const goSumPath = (0,
|
|
17311
|
-
const isGoSumExists = await (0,
|
|
17492
|
+
const goSumPath = (0, import_path7.join)(goModDirname, "go.sum");
|
|
17493
|
+
const isGoSumExists = await (0, import_fs_extra4.pathExists)(goSumPath);
|
|
17312
17494
|
if (!isGoSumExists) {
|
|
17313
17495
|
undo.fileActions.push({
|
|
17314
17496
|
to: void 0,
|
|
@@ -17317,23 +17499,23 @@ async function buildHandlerWithGoMod({
|
|
|
17317
17499
|
});
|
|
17318
17500
|
}
|
|
17319
17501
|
}
|
|
17320
|
-
const entrypointArr = entrypoint.split(
|
|
17502
|
+
const entrypointArr = entrypoint.split(import_path7.posix.sep);
|
|
17321
17503
|
let goPackageName = `${packageName}/${packageName}`;
|
|
17322
17504
|
const goFuncName = `${packageName}.${handlerFunctionName}`;
|
|
17323
|
-
const relPackagePath = goModDirname ?
|
|
17505
|
+
const relPackagePath = goModDirname ? import_path7.posix.relative(goModDirname, entrypointDirname) : "";
|
|
17324
17506
|
if (relPackagePath) {
|
|
17325
|
-
goPackageName =
|
|
17507
|
+
goPackageName = import_path7.posix.join(packageName, relPackagePath);
|
|
17326
17508
|
}
|
|
17327
17509
|
let mainGoFile;
|
|
17328
17510
|
if (goModPath && isGoModInRootDir) {
|
|
17329
|
-
(0,
|
|
17330
|
-
mainGoFile = (0,
|
|
17511
|
+
(0, import_build_utils4.debug)(`[mod-root] Write main file to ${downloadPath}`);
|
|
17512
|
+
mainGoFile = (0, import_path7.join)(downloadPath, MAIN_GO_FILENAME);
|
|
17331
17513
|
} else if (goModDirname && !isGoModInRootDir) {
|
|
17332
|
-
(0,
|
|
17333
|
-
mainGoFile = (0,
|
|
17514
|
+
(0, import_build_utils4.debug)(`[mod-other] Write main file to ${goModDirname}`);
|
|
17515
|
+
mainGoFile = (0, import_path7.join)(goModDirname, MAIN_GO_FILENAME);
|
|
17334
17516
|
} else {
|
|
17335
|
-
(0,
|
|
17336
|
-
mainGoFile = (0,
|
|
17517
|
+
(0, import_build_utils4.debug)(`[entrypoint] Write main file to ${entrypointDirname}`);
|
|
17518
|
+
mainGoFile = (0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME);
|
|
17337
17519
|
}
|
|
17338
17520
|
await Promise.all([
|
|
17339
17521
|
writeEntrypoint(mainGoFile, goPackageName, goFuncName),
|
|
@@ -17349,24 +17531,24 @@ async function buildHandlerWithGoMod({
|
|
|
17349
17531
|
from: mainGoFile
|
|
17350
17532
|
});
|
|
17351
17533
|
try {
|
|
17352
|
-
let finalDestination = (0,
|
|
17534
|
+
let finalDestination = (0, import_path7.join)(entrypointDirname, packageName, entrypoint);
|
|
17353
17535
|
if (entrypointArr.length > 1) {
|
|
17354
|
-
finalDestination = (0,
|
|
17536
|
+
finalDestination = (0, import_path7.join)(
|
|
17355
17537
|
entrypointDirname,
|
|
17356
17538
|
packageName,
|
|
17357
17539
|
entrypointArr[entrypointArr.length - 1]
|
|
17358
17540
|
);
|
|
17359
17541
|
}
|
|
17360
|
-
if (!goModPath || (0,
|
|
17361
|
-
(0,
|
|
17542
|
+
if (!goModPath || (0, import_path7.dirname)(entrypointAbsolute) === (0, import_path7.dirname)(goModPath)) {
|
|
17543
|
+
(0, import_build_utils4.debug)(
|
|
17362
17544
|
`moving entrypoint "${entrypointAbsolute}" to "${finalDestination}"`
|
|
17363
17545
|
);
|
|
17364
|
-
await (0,
|
|
17546
|
+
await (0, import_fs_extra4.move)(entrypointAbsolute, finalDestination);
|
|
17365
17547
|
undo.fileActions.push({
|
|
17366
17548
|
to: entrypointAbsolute,
|
|
17367
17549
|
from: finalDestination
|
|
17368
17550
|
});
|
|
17369
|
-
undo.directoryCreation.push((0,
|
|
17551
|
+
undo.directoryCreation.push((0, import_path7.dirname)(finalDestination));
|
|
17370
17552
|
}
|
|
17371
17553
|
} catch (err) {
|
|
17372
17554
|
console.error("Failed to move entry to package folder");
|
|
@@ -17376,21 +17558,21 @@ async function buildHandlerWithGoMod({
|
|
|
17376
17558
|
if (goModPath && isGoModInRootDir) {
|
|
17377
17559
|
baseGoModPath = downloadPath;
|
|
17378
17560
|
} else if (goModPath && !isGoModInRootDir) {
|
|
17379
|
-
baseGoModPath = (0,
|
|
17561
|
+
baseGoModPath = (0, import_path7.dirname)(goModPath);
|
|
17380
17562
|
} else {
|
|
17381
17563
|
baseGoModPath = entrypointDirname;
|
|
17382
17564
|
}
|
|
17383
|
-
(0,
|
|
17565
|
+
(0, import_build_utils4.debug)("Tidy `go.mod` file...");
|
|
17384
17566
|
try {
|
|
17385
17567
|
await go.mod();
|
|
17386
17568
|
} catch (err) {
|
|
17387
17569
|
console.error("failed to `go mod tidy`");
|
|
17388
17570
|
throw err;
|
|
17389
17571
|
}
|
|
17390
|
-
(0,
|
|
17391
|
-
const destPath = (0,
|
|
17572
|
+
(0, import_build_utils4.debug)("Running `go build`...");
|
|
17573
|
+
const destPath = (0, import_path7.join)(outDir, HANDLER_FILENAME);
|
|
17392
17574
|
try {
|
|
17393
|
-
const src = [(0,
|
|
17575
|
+
const src = [(0, import_path7.join)(baseGoModPath, MAIN_GO_FILENAME)];
|
|
17394
17576
|
await go.build(src, destPath);
|
|
17395
17577
|
} catch (err) {
|
|
17396
17578
|
console.error("failed to `go build`");
|
|
@@ -17405,31 +17587,31 @@ async function buildHandlerAsPackageMain({
|
|
|
17405
17587
|
outDir,
|
|
17406
17588
|
undo
|
|
17407
17589
|
}) {
|
|
17408
|
-
(0,
|
|
17590
|
+
(0, import_build_utils4.debug)('Building Go handler as package "main" (legacy)');
|
|
17409
17591
|
await writeEntrypoint(
|
|
17410
|
-
(0,
|
|
17592
|
+
(0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME),
|
|
17411
17593
|
"",
|
|
17412
17594
|
handlerFunctionName
|
|
17413
17595
|
);
|
|
17414
17596
|
undo.fileActions.push({
|
|
17415
17597
|
to: void 0,
|
|
17416
17598
|
// delete
|
|
17417
|
-
from: (0,
|
|
17599
|
+
from: (0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME)
|
|
17418
17600
|
});
|
|
17419
|
-
(0,
|
|
17601
|
+
(0, import_build_utils4.debug)("Running `go get`...");
|
|
17420
17602
|
try {
|
|
17421
17603
|
await go.get();
|
|
17422
17604
|
} catch (err) {
|
|
17423
17605
|
console.error("Failed to `go get`");
|
|
17424
17606
|
throw err;
|
|
17425
17607
|
}
|
|
17426
|
-
(0,
|
|
17427
|
-
const destPath = (0,
|
|
17608
|
+
(0, import_build_utils4.debug)("Running `go build`...");
|
|
17609
|
+
const destPath = (0, import_path7.join)(outDir, HANDLER_FILENAME);
|
|
17428
17610
|
try {
|
|
17429
17611
|
const src = [
|
|
17430
|
-
(0,
|
|
17612
|
+
(0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME),
|
|
17431
17613
|
entrypointAbsolute
|
|
17432
|
-
].map((file) => (0,
|
|
17614
|
+
].map((file) => (0, import_path7.normalize)(file));
|
|
17433
17615
|
await go.build(src, destPath);
|
|
17434
17616
|
} catch (err) {
|
|
17435
17617
|
console.error("failed to `go build`");
|
|
@@ -17437,10 +17619,10 @@ async function buildHandlerAsPackageMain({
|
|
|
17437
17619
|
}
|
|
17438
17620
|
}
|
|
17439
17621
|
async function renameHandlerFunction(fsPath, from, to) {
|
|
17440
|
-
let fileContents = await (0,
|
|
17622
|
+
let fileContents = await (0, import_fs_extra4.readFile)(fsPath, "utf8");
|
|
17441
17623
|
const fromRegex = new RegExp(String.raw` ${from}\b`, "g");
|
|
17442
17624
|
fileContents = fileContents.replace(fromRegex, ` ${to}`);
|
|
17443
|
-
await (0,
|
|
17625
|
+
await (0, import_fs_extra4.writeFile)(fsPath, fileContents);
|
|
17444
17626
|
}
|
|
17445
17627
|
function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
|
|
17446
17628
|
if (!originalFunctionName) {
|
|
@@ -17453,10 +17635,10 @@ function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
|
|
|
17453
17635
|
"Handler function renaming failed because entrypoint was empty."
|
|
17454
17636
|
);
|
|
17455
17637
|
}
|
|
17456
|
-
(0,
|
|
17638
|
+
(0, import_build_utils4.debug)(`Found exported function "${originalFunctionName}" in "${entrypoint}"`);
|
|
17457
17639
|
const pathSlug = entrypoint.replace(/(\s|\\|\/|\]|\[|-|\.)/g, "_");
|
|
17458
17640
|
const newHandlerName = `${originalFunctionName}_${pathSlug}`;
|
|
17459
|
-
(0,
|
|
17641
|
+
(0, import_build_utils4.debug)(
|
|
17460
17642
|
`Renaming handler function temporarily from "${originalFunctionName}" to "${newHandlerName}"`
|
|
17461
17643
|
);
|
|
17462
17644
|
return newHandlerName;
|
|
@@ -17468,36 +17650,36 @@ async function cleanupFileSystem({
|
|
|
17468
17650
|
}) {
|
|
17469
17651
|
for (const action of fileActions.reverse()) {
|
|
17470
17652
|
if (action.to) {
|
|
17471
|
-
await (0,
|
|
17653
|
+
await (0, import_fs_extra4.move)(action.from, action.to, { overwrite: true });
|
|
17472
17654
|
} else {
|
|
17473
|
-
await (0,
|
|
17655
|
+
await (0, import_fs_extra4.remove)(action.from);
|
|
17474
17656
|
}
|
|
17475
17657
|
}
|
|
17476
17658
|
for (const rename of functionRenames) {
|
|
17477
17659
|
await renameHandlerFunction(rename.fsPath, rename.from, rename.to);
|
|
17478
17660
|
}
|
|
17479
17661
|
const undoDirectoryPromises = directoryCreation.map(async (directory) => {
|
|
17480
|
-
const contents = await (0,
|
|
17662
|
+
const contents = await (0, import_fs_extra4.readdir)(directory);
|
|
17481
17663
|
if (!contents.length) {
|
|
17482
|
-
return (0,
|
|
17664
|
+
return (0, import_fs_extra4.rmdir)(directory);
|
|
17483
17665
|
}
|
|
17484
17666
|
return void 0;
|
|
17485
17667
|
});
|
|
17486
17668
|
await Promise.all(undoDirectoryPromises);
|
|
17487
17669
|
}
|
|
17488
|
-
async function
|
|
17670
|
+
async function findGoModPath2(entrypointDir, workPath) {
|
|
17489
17671
|
let goModPath = void 0;
|
|
17490
17672
|
let isGoModInRootDir = false;
|
|
17491
17673
|
let dir = entrypointDir;
|
|
17492
17674
|
while (!isGoModInRootDir) {
|
|
17493
17675
|
isGoModInRootDir = dir === workPath;
|
|
17494
|
-
const goMod = (0,
|
|
17495
|
-
if (await (0,
|
|
17676
|
+
const goMod = (0, import_path7.join)(dir, "go.mod");
|
|
17677
|
+
if (await (0, import_fs_extra4.pathExists)(goMod)) {
|
|
17496
17678
|
goModPath = goMod;
|
|
17497
|
-
(0,
|
|
17679
|
+
(0, import_build_utils4.debug)(`Found ${goModPath}"`);
|
|
17498
17680
|
break;
|
|
17499
17681
|
}
|
|
17500
|
-
dir = (0,
|
|
17682
|
+
dir = (0, import_path7.dirname)(dir);
|
|
17501
17683
|
}
|
|
17502
17684
|
return {
|
|
17503
17685
|
goModPath,
|
|
@@ -17511,22 +17693,22 @@ function isReadable2(v) {
|
|
|
17511
17693
|
return v && v.readable === true;
|
|
17512
17694
|
}
|
|
17513
17695
|
async function copyEntrypoint(entrypoint, dest) {
|
|
17514
|
-
const data = await (0,
|
|
17696
|
+
const data = await (0, import_fs_extra4.readFile)(entrypoint, "utf8");
|
|
17515
17697
|
const patched = data.replace(/\bpackage\W+\S+\b/, "package main");
|
|
17516
|
-
await (0,
|
|
17698
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(dest, "entrypoint.go"), patched);
|
|
17517
17699
|
}
|
|
17518
17700
|
async function copyDevServer(functionName, dest) {
|
|
17519
|
-
const data = await (0,
|
|
17701
|
+
const data = await (0, import_fs_extra4.readFile)((0, import_path7.join)(__dirname, "../dev-server.go"), "utf8");
|
|
17520
17702
|
const patched = data.replace("__HANDLER_FUNC_NAME", functionName);
|
|
17521
|
-
await (0,
|
|
17703
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(dest, "vercel-dev-server-main.go"), patched);
|
|
17522
17704
|
}
|
|
17523
17705
|
async function writeEntrypoint(dest, goPackageName, goFuncName) {
|
|
17524
|
-
const modMainGoContents = await (0,
|
|
17525
|
-
(0,
|
|
17706
|
+
const modMainGoContents = await (0, import_fs_extra4.readFile)(
|
|
17707
|
+
(0, import_path7.join)(__dirname, "../main.go"),
|
|
17526
17708
|
"utf8"
|
|
17527
17709
|
);
|
|
17528
17710
|
const mainModGoContents = modMainGoContents.replace("__VC_HANDLER_PACKAGE_NAME", goPackageName).replace("__VC_HANDLER_FUNC_NAME", goFuncName);
|
|
17529
|
-
await (0,
|
|
17711
|
+
await (0, import_fs_extra4.writeFile)(dest, mainModGoContents, "utf-8");
|
|
17530
17712
|
}
|
|
17531
17713
|
async function writeGoMod({
|
|
17532
17714
|
destDir,
|
|
@@ -17535,13 +17717,13 @@ async function writeGoMod({
|
|
|
17535
17717
|
}) {
|
|
17536
17718
|
let contents = `module ${packageName}`;
|
|
17537
17719
|
if (goModPath) {
|
|
17538
|
-
const goModRelPath = (0,
|
|
17539
|
-
const goModContents = await (0,
|
|
17720
|
+
const goModRelPath = (0, import_path7.relative)(destDir, (0, import_path7.dirname)(goModPath));
|
|
17721
|
+
const goModContents = await (0, import_fs_extra4.readFile)(goModPath, "utf-8");
|
|
17540
17722
|
contents = goModContents.replace(/^module\s+.+$/m, contents).replace(
|
|
17541
17723
|
/^(replace .+=>\s*)(.+)$/gm,
|
|
17542
17724
|
(orig, replaceStmt, replacePath) => {
|
|
17543
17725
|
if (replacePath.startsWith(".")) {
|
|
17544
|
-
return replaceStmt + (0,
|
|
17726
|
+
return replaceStmt + (0, import_path7.join)(goModRelPath, replacePath);
|
|
17545
17727
|
}
|
|
17546
17728
|
return orig;
|
|
17547
17729
|
}
|
|
@@ -17549,7 +17731,7 @@ async function writeGoMod({
|
|
|
17549
17731
|
const matches = goModContents.match(/module\s+(.+)/);
|
|
17550
17732
|
const moduleName = matches ? matches[1] : null;
|
|
17551
17733
|
if (moduleName) {
|
|
17552
|
-
let relPath = (0,
|
|
17734
|
+
let relPath = (0, import_path7.normalize)(goModRelPath);
|
|
17553
17735
|
if (!relPath.endsWith("/")) {
|
|
17554
17736
|
relPath += "/";
|
|
17555
17737
|
}
|
|
@@ -17569,25 +17751,25 @@ async function writeGoMod({
|
|
|
17569
17751
|
}
|
|
17570
17752
|
}
|
|
17571
17753
|
}
|
|
17572
|
-
const destGoModPath = (0,
|
|
17573
|
-
(0,
|
|
17574
|
-
await (0,
|
|
17754
|
+
const destGoModPath = (0, import_path7.join)(destDir, "go.mod");
|
|
17755
|
+
(0, import_build_utils4.debug)(`Writing ${destGoModPath}`);
|
|
17756
|
+
await (0, import_fs_extra4.writeFile)(destGoModPath, contents, "utf-8");
|
|
17575
17757
|
}
|
|
17576
17758
|
async function findGoWorkFile(goWorkDir, workPath) {
|
|
17577
|
-
while (!await (0,
|
|
17759
|
+
while (!await (0, import_fs_extra4.pathExists)((0, import_path7.join)(goWorkDir, "go.work"))) {
|
|
17578
17760
|
if (goWorkDir === workPath) {
|
|
17579
17761
|
return;
|
|
17580
17762
|
}
|
|
17581
|
-
goWorkDir = (0,
|
|
17763
|
+
goWorkDir = (0, import_path7.dirname)(goWorkDir);
|
|
17582
17764
|
}
|
|
17583
|
-
return (0,
|
|
17765
|
+
return (0, import_path7.join)(goWorkDir, "go.work");
|
|
17584
17766
|
}
|
|
17585
17767
|
async function writeGoWork(destDir, workPath, modulePath) {
|
|
17586
17768
|
const workspaces = /* @__PURE__ */ new Set(["."]);
|
|
17587
17769
|
const goWorkPath = await findGoWorkFile(modulePath || workPath, workPath);
|
|
17588
17770
|
let goVersion;
|
|
17589
17771
|
if (goWorkPath) {
|
|
17590
|
-
const contents2 = await (0,
|
|
17772
|
+
const contents2 = await (0, import_fs_extra4.readFile)(goWorkPath, "utf-8");
|
|
17591
17773
|
const goVersionMatch = contents2.match(/^go\s+(\d+\.\d+(\.\d+)?)/m);
|
|
17592
17774
|
if (goVersionMatch) {
|
|
17593
17775
|
goVersion = goVersionMatch[1];
|
|
@@ -17595,7 +17777,7 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17595
17777
|
const addPath = (path8) => {
|
|
17596
17778
|
if (path8) {
|
|
17597
17779
|
if (path8.startsWith(".")) {
|
|
17598
|
-
workspaces.add((0,
|
|
17780
|
+
workspaces.add((0, import_path7.relative)(destDir, (0, import_path7.join)(workPath, path8)));
|
|
17599
17781
|
} else {
|
|
17600
17782
|
workspaces.add(path8);
|
|
17601
17783
|
}
|
|
@@ -17618,10 +17800,10 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17618
17800
|
match = singleRE.exec(contents2);
|
|
17619
17801
|
}
|
|
17620
17802
|
} else if (modulePath) {
|
|
17621
|
-
workspaces.add((0,
|
|
17622
|
-
const goModPath = (0,
|
|
17623
|
-
if (await (0,
|
|
17624
|
-
const goModContents = await (0,
|
|
17803
|
+
workspaces.add((0, import_path7.relative)(destDir, modulePath));
|
|
17804
|
+
const goModPath = (0, import_path7.join)(modulePath, "go.mod");
|
|
17805
|
+
if (await (0, import_fs_extra4.pathExists)(goModPath)) {
|
|
17806
|
+
const goModContents = await (0, import_fs_extra4.readFile)(goModPath, "utf-8");
|
|
17625
17807
|
const goVersionMatch = goModContents.match(/^go\s+(\d+\.\d+(\.\d+)?)/m);
|
|
17626
17808
|
if (goVersionMatch) {
|
|
17627
17809
|
goVersion = goVersionMatch[1];
|
|
@@ -17638,24 +17820,36 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17638
17820
|
${Array.from(workspaces).map((w) => ` ${w}
|
|
17639
17821
|
`).join("")})
|
|
17640
17822
|
`;
|
|
17641
|
-
await (0,
|
|
17823
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(destDir, "go.work"), contents, "utf-8");
|
|
17642
17824
|
}
|
|
17643
17825
|
async function startDevServer(opts) {
|
|
17644
|
-
const { entrypoint, workPath, meta = {} } = opts;
|
|
17645
|
-
const { devCacheDir = (0,
|
|
17646
|
-
const entrypointDir = (0, import_path5.dirname)(entrypoint);
|
|
17826
|
+
const { entrypoint, workPath, config, meta = {} } = opts;
|
|
17827
|
+
const { devCacheDir = (0, import_path7.join)(workPath, ".vercel", "cache") } = meta;
|
|
17647
17828
|
let entrypointWithExt = entrypoint;
|
|
17648
17829
|
if (!entrypoint.endsWith(".go")) {
|
|
17649
17830
|
entrypointWithExt += ".go";
|
|
17650
17831
|
}
|
|
17651
|
-
|
|
17652
|
-
|
|
17653
|
-
|
|
17654
|
-
|
|
17655
|
-
|
|
17832
|
+
if (config?.framework === "go" || config?.framework === "services") {
|
|
17833
|
+
const resolvedEntrypoint = await detectGoEntrypoint(
|
|
17834
|
+
workPath,
|
|
17835
|
+
entrypointWithExt
|
|
17836
|
+
);
|
|
17837
|
+
if (!resolvedEntrypoint) {
|
|
17838
|
+
throw new Error(
|
|
17839
|
+
`No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(", ")}`
|
|
17840
|
+
);
|
|
17841
|
+
}
|
|
17842
|
+
return startStandaloneDevServer(opts, resolvedEntrypoint);
|
|
17843
|
+
}
|
|
17844
|
+
const entrypointDir = (0, import_path7.dirname)(entrypointWithExt);
|
|
17845
|
+
const tmp = (0, import_path7.join)(devCacheDir, "go", Math.random().toString(32).substring(2));
|
|
17846
|
+
const tmpPackage = (0, import_path7.join)(tmp, entrypointDir);
|
|
17847
|
+
await (0, import_fs_extra4.mkdirp)(tmpPackage);
|
|
17848
|
+
const { goModPath } = await findGoModPath2(
|
|
17849
|
+
(0, import_path7.join)(workPath, entrypointDir),
|
|
17656
17850
|
workPath
|
|
17657
17851
|
);
|
|
17658
|
-
const modulePath = goModPath ? (0,
|
|
17852
|
+
const modulePath = goModPath ? (0, import_path7.dirname)(goModPath) : void 0;
|
|
17659
17853
|
const analyzed = await getAnalyzedEntrypoint({
|
|
17660
17854
|
entrypoint: entrypointWithExt,
|
|
17661
17855
|
modulePath,
|
|
@@ -17671,11 +17865,11 @@ async function startDevServer(opts) {
|
|
|
17671
17865
|
}),
|
|
17672
17866
|
writeGoWork(tmp, workPath, modulePath)
|
|
17673
17867
|
]);
|
|
17674
|
-
const portFile = (0,
|
|
17868
|
+
const portFile = (0, import_path7.join)(
|
|
17675
17869
|
TMP,
|
|
17676
17870
|
`vercel-dev-port-${Math.random().toString(32).substring(2)}`
|
|
17677
17871
|
);
|
|
17678
|
-
const env = (0,
|
|
17872
|
+
const env = (0, import_build_utils4.cloneEnv)(process.env, meta.env, {
|
|
17679
17873
|
VERCEL_DEV_PORT_FILE: portFile
|
|
17680
17874
|
});
|
|
17681
17875
|
const executable = `./vercel-dev-server-go${process.platform === "win32" ? ".exe" : ""}`;
|
|
@@ -17688,15 +17882,31 @@ async function startDevServer(opts) {
|
|
|
17688
17882
|
workPath
|
|
17689
17883
|
});
|
|
17690
17884
|
await go.build("./...", executable);
|
|
17691
|
-
(0,
|
|
17692
|
-
const child = (0,
|
|
17885
|
+
(0, import_build_utils4.debug)(`SPAWNING ${executable} CWD=${tmp}`);
|
|
17886
|
+
const child = (0, import_child_process2.spawn)(executable, [], {
|
|
17693
17887
|
cwd: tmp,
|
|
17694
17888
|
env,
|
|
17695
|
-
stdio: ["ignore", "
|
|
17889
|
+
stdio: ["ignore", "pipe", "pipe", "pipe"]
|
|
17890
|
+
});
|
|
17891
|
+
child.stdout?.on("data", (data) => {
|
|
17892
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
17893
|
+
if (opts.onStdout) {
|
|
17894
|
+
opts.onStdout(chunk);
|
|
17895
|
+
} else {
|
|
17896
|
+
process.stdout.write(chunk.toString());
|
|
17897
|
+
}
|
|
17898
|
+
});
|
|
17899
|
+
child.stderr?.on("data", (data) => {
|
|
17900
|
+
const chunk = Buffer.isBuffer(data) ? data : Buffer.from(data);
|
|
17901
|
+
if (opts.onStderr) {
|
|
17902
|
+
opts.onStderr(chunk);
|
|
17903
|
+
} else {
|
|
17904
|
+
process.stderr.write(chunk.toString());
|
|
17905
|
+
}
|
|
17696
17906
|
});
|
|
17697
17907
|
child.on("close", async () => {
|
|
17698
17908
|
try {
|
|
17699
|
-
await (0, import_async_retry.default)(() => (0,
|
|
17909
|
+
await (0, import_async_retry.default)(() => (0, import_fs_extra4.remove)(tmp));
|
|
17700
17910
|
} catch (err) {
|
|
17701
17911
|
console.error(`Could not delete tmp directory: ${tmp}: ${err}`);
|
|
17702
17912
|
}
|
|
@@ -17741,8 +17951,8 @@ async function waitForPortFile_(opts) {
|
|
|
17741
17951
|
while (!opts.canceled) {
|
|
17742
17952
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17743
17953
|
try {
|
|
17744
|
-
const port = Number(await (0,
|
|
17745
|
-
(0, import_async_retry.default)(() => (0,
|
|
17954
|
+
const port = Number(await (0, import_fs_extra4.readFile)(opts.portFile, "ascii"));
|
|
17955
|
+
(0, import_async_retry.default)(() => (0, import_fs_extra4.remove)(opts.portFile)).catch((err) => {
|
|
17746
17956
|
console.error(`Could not delete port file: ${opts.portFile}: ${err}`);
|
|
17747
17957
|
});
|
|
17748
17958
|
return { port };
|
|
@@ -17756,15 +17966,15 @@ async function waitForPortFile_(opts) {
|
|
|
17756
17966
|
async function prepareCache({
|
|
17757
17967
|
workPath
|
|
17758
17968
|
}) {
|
|
17759
|
-
const goCacheDir = (0,
|
|
17760
|
-
const stat = await (0,
|
|
17969
|
+
const goCacheDir = (0, import_path7.join)(workPath, localCacheDir);
|
|
17970
|
+
const stat = await (0, import_fs_extra4.lstat)(goCacheDir);
|
|
17761
17971
|
if (stat.isSymbolicLink()) {
|
|
17762
|
-
const goGlobalCacheDir = await (0,
|
|
17763
|
-
(0,
|
|
17764
|
-
await (0,
|
|
17765
|
-
await (0,
|
|
17972
|
+
const goGlobalCacheDir = await (0, import_fs_extra4.readlink)(goCacheDir);
|
|
17973
|
+
(0, import_build_utils4.debug)(`Preparing cache by moving ${goGlobalCacheDir} -> ${goCacheDir}`);
|
|
17974
|
+
await (0, import_fs_extra4.unlink)(goCacheDir);
|
|
17975
|
+
await (0, import_fs_extra4.move)(goGlobalCacheDir, goCacheDir);
|
|
17766
17976
|
}
|
|
17767
|
-
const cache2 = await (0,
|
|
17977
|
+
const cache2 = await (0, import_build_utils4.glob)(`${localCacheDir}/**`, workPath);
|
|
17768
17978
|
return cache2;
|
|
17769
17979
|
}
|
|
17770
17980
|
// Annotate the CommonJS export names for ESM import in node:
|