@vercel/go 3.3.5 → 3.4.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/dist/index.js +387 -209
- 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,206 @@ 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", "inherit", "inherit"]
|
|
17266
|
+
});
|
|
17267
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
17268
|
+
return {
|
|
17269
|
+
port,
|
|
17270
|
+
pid: child.pid
|
|
17271
|
+
};
|
|
17272
|
+
}
|
|
17273
|
+
|
|
17117
17274
|
// src/index.ts
|
|
17118
17275
|
var TMP = (0, import_os2.tmpdir)();
|
|
17119
17276
|
var MAIN_GO_FILENAME = "main__vc__go__.go";
|
|
17120
17277
|
var HANDLER_FILENAME = `bootstrap${OUT_EXTENSION}`;
|
|
17121
17278
|
async function initPrivateGit(credentials) {
|
|
17122
|
-
const gitCredentialsPath = (0,
|
|
17279
|
+
const gitCredentialsPath = (0, import_path7.join)((0, import_os2.homedir)(), ".git-credentials");
|
|
17123
17280
|
await (0, import_execa2.default)("git", [
|
|
17124
17281
|
"config",
|
|
17125
17282
|
"--global",
|
|
17126
17283
|
"credential.helper",
|
|
17127
17284
|
`store --file ${gitCredentialsPath}`
|
|
17128
17285
|
]);
|
|
17129
|
-
await (0,
|
|
17286
|
+
await (0, import_fs_extra4.writeFile)(gitCredentialsPath, credentials);
|
|
17130
17287
|
}
|
|
17131
17288
|
function getRenamedEntrypoint(entrypoint) {
|
|
17132
|
-
const filename = (0,
|
|
17289
|
+
const filename = (0, import_path7.basename)(entrypoint);
|
|
17133
17290
|
if (filename.startsWith("[")) {
|
|
17134
17291
|
const newEntrypoint = entrypoint.replace("/[", "/now-bracket[");
|
|
17135
|
-
(0,
|
|
17292
|
+
(0, import_build_utils4.debug)(`Renamed entrypoint from ${entrypoint} to ${newEntrypoint}`);
|
|
17136
17293
|
return newEntrypoint;
|
|
17137
17294
|
}
|
|
17138
17295
|
return void 0;
|
|
17139
17296
|
}
|
|
17140
17297
|
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");
|
|
17298
|
+
async function build(options) {
|
|
17299
|
+
const { files, config, workPath, meta = {} } = options;
|
|
17300
|
+
let { entrypoint } = options;
|
|
17301
|
+
const goPath = await (0, import_build_utils4.getWriteableDirectory)();
|
|
17302
|
+
const srcPath = (0, import_path7.join)(goPath, "src", "lambda");
|
|
17150
17303
|
const downloadPath = meta.skipDownload ? workPath : srcPath;
|
|
17151
|
-
await (0,
|
|
17304
|
+
await (0, import_build_utils4.download)(files, downloadPath, meta);
|
|
17152
17305
|
const undo = {
|
|
17153
17306
|
fileActions: [],
|
|
17154
17307
|
directoryCreation: [],
|
|
17155
17308
|
functionRenames: []
|
|
17156
17309
|
};
|
|
17157
|
-
const env = (0,
|
|
17310
|
+
const env = (0, import_build_utils4.cloneEnv)(process.env, meta.env, {
|
|
17158
17311
|
GOARCH: "amd64",
|
|
17159
17312
|
GOOS: "linux"
|
|
17160
17313
|
});
|
|
17161
17314
|
try {
|
|
17162
17315
|
if (env.GIT_CREDENTIALS) {
|
|
17163
|
-
(0,
|
|
17316
|
+
(0, import_build_utils4.debug)("Initialize Git credentials...");
|
|
17164
17317
|
await initPrivateGit(env.GIT_CREDENTIALS);
|
|
17165
17318
|
}
|
|
17166
17319
|
if (env.GO111MODULE) {
|
|
@@ -17175,28 +17328,41 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17175
17328
|
Learn more: https://github.com/golang/go/wiki/Modules
|
|
17176
17329
|
`);
|
|
17177
17330
|
}
|
|
17178
|
-
|
|
17331
|
+
if (config?.framework === "go" || config?.framework === "services") {
|
|
17332
|
+
const resolvedEntrypoint = await detectGoEntrypoint(workPath, entrypoint);
|
|
17333
|
+
if (!resolvedEntrypoint) {
|
|
17334
|
+
throw new Error(
|
|
17335
|
+
`No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(", ")}`
|
|
17336
|
+
);
|
|
17337
|
+
}
|
|
17338
|
+
(0, import_build_utils4.debug)(`Using standalone Go server mode for ${resolvedEntrypoint}`);
|
|
17339
|
+
return buildStandaloneServer({
|
|
17340
|
+
...options,
|
|
17341
|
+
entrypoint: resolvedEntrypoint
|
|
17342
|
+
});
|
|
17343
|
+
}
|
|
17344
|
+
const originalEntrypointAbsolute = (0, import_path7.join)(workPath, entrypoint);
|
|
17179
17345
|
const renamedEntrypoint = getRenamedEntrypoint(entrypoint);
|
|
17180
17346
|
if (renamedEntrypoint) {
|
|
17181
|
-
await (0,
|
|
17347
|
+
await (0, import_fs_extra4.move)((0, import_path7.join)(workPath, entrypoint), (0, import_path7.join)(workPath, renamedEntrypoint));
|
|
17182
17348
|
undo.fileActions.push({
|
|
17183
|
-
to: (0,
|
|
17184
|
-
from: (0,
|
|
17349
|
+
to: (0, import_path7.join)(workPath, entrypoint),
|
|
17350
|
+
from: (0, import_path7.join)(workPath, renamedEntrypoint)
|
|
17185
17351
|
});
|
|
17186
17352
|
entrypoint = renamedEntrypoint;
|
|
17187
17353
|
}
|
|
17188
|
-
const entrypointAbsolute = (0,
|
|
17189
|
-
const entrypointDirname = (0,
|
|
17190
|
-
const { goModPath, isGoModInRootDir } = await
|
|
17354
|
+
const entrypointAbsolute = (0, import_path7.join)(workPath, entrypoint);
|
|
17355
|
+
const entrypointDirname = (0, import_path7.dirname)(entrypointAbsolute);
|
|
17356
|
+
const { goModPath, isGoModInRootDir } = await findGoModPath2(
|
|
17191
17357
|
entrypointDirname,
|
|
17192
17358
|
workPath
|
|
17193
17359
|
);
|
|
17194
|
-
if (!goModPath && await (0,
|
|
17360
|
+
if (!goModPath && await (0, import_fs_extra4.pathExists)((0, import_path7.join)(workPath, "vendor"))) {
|
|
17195
17361
|
throw new Error("`go.mod` is required to use a `vendor` directory.");
|
|
17196
17362
|
}
|
|
17197
17363
|
const analyzed = await getAnalyzedEntrypoint({
|
|
17198
17364
|
entrypoint,
|
|
17199
|
-
modulePath: goModPath ? (0,
|
|
17365
|
+
modulePath: goModPath ? (0, import_path7.dirname)(goModPath) : void 0,
|
|
17200
17366
|
workPath
|
|
17201
17367
|
});
|
|
17202
17368
|
const packageName = analyzed.packageName;
|
|
@@ -17222,13 +17388,13 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17222
17388
|
if (config && config.includeFiles) {
|
|
17223
17389
|
const patterns = Array.isArray(config.includeFiles) ? config.includeFiles : [config.includeFiles];
|
|
17224
17390
|
for (const pattern of patterns) {
|
|
17225
|
-
const fsFiles = await (0,
|
|
17391
|
+
const fsFiles = await (0, import_build_utils4.glob)(pattern, entrypointDirname);
|
|
17226
17392
|
for (const [assetName, asset] of Object.entries(fsFiles)) {
|
|
17227
17393
|
includedFiles[assetName] = asset;
|
|
17228
17394
|
}
|
|
17229
17395
|
}
|
|
17230
17396
|
}
|
|
17231
|
-
const modulePath = goModPath ? (0,
|
|
17397
|
+
const modulePath = goModPath ? (0, import_path7.dirname)(goModPath) : void 0;
|
|
17232
17398
|
const go = await createGo({
|
|
17233
17399
|
modulePath,
|
|
17234
17400
|
opts: {
|
|
@@ -17237,7 +17403,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17237
17403
|
},
|
|
17238
17404
|
workPath
|
|
17239
17405
|
});
|
|
17240
|
-
const outDir = await (0,
|
|
17406
|
+
const outDir = await (0, import_build_utils4.getWriteableDirectory)();
|
|
17241
17407
|
const buildOptions = {
|
|
17242
17408
|
downloadPath,
|
|
17243
17409
|
entrypoint,
|
|
@@ -17256,9 +17422,9 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17256
17422
|
} else {
|
|
17257
17423
|
await buildHandlerWithGoMod(buildOptions);
|
|
17258
17424
|
}
|
|
17259
|
-
const runtime = await (0,
|
|
17260
|
-
const lambda = new
|
|
17261
|
-
files: { ...await (0,
|
|
17425
|
+
const runtime = await (0, import_build_utils4.getProvidedRuntime)();
|
|
17426
|
+
const lambda = new import_build_utils4.Lambda({
|
|
17427
|
+
files: { ...await (0, import_build_utils4.glob)("**", outDir), ...includedFiles },
|
|
17262
17428
|
handler: HANDLER_FILENAME,
|
|
17263
17429
|
runtime,
|
|
17264
17430
|
runtimeLanguage: "go",
|
|
@@ -17269,7 +17435,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17269
17435
|
output: lambda
|
|
17270
17436
|
};
|
|
17271
17437
|
} catch (error) {
|
|
17272
|
-
(0,
|
|
17438
|
+
(0, import_build_utils4.debug)(`Go Builder Error: ${error}`);
|
|
17273
17439
|
throw error;
|
|
17274
17440
|
} finally {
|
|
17275
17441
|
try {
|
|
@@ -17278,7 +17444,7 @@ Manually assigning 'GO111MODULE' is not recommended.
|
|
|
17278
17444
|
if (error instanceof Error) {
|
|
17279
17445
|
console.error(`Build cleanup failed: ${error.message}`);
|
|
17280
17446
|
}
|
|
17281
|
-
(0,
|
|
17447
|
+
(0, import_build_utils4.debug)("Cleanup Error: " + error);
|
|
17282
17448
|
}
|
|
17283
17449
|
}
|
|
17284
17450
|
}
|
|
@@ -17295,20 +17461,20 @@ async function buildHandlerWithGoMod({
|
|
|
17295
17461
|
packageName,
|
|
17296
17462
|
undo
|
|
17297
17463
|
}) {
|
|
17298
|
-
(0,
|
|
17464
|
+
(0, import_build_utils4.debug)(
|
|
17299
17465
|
`Building Go handler as package "${packageName}" (with${goModPath ? "" : "out"} go.mod)`
|
|
17300
17466
|
);
|
|
17301
17467
|
let goModDirname;
|
|
17302
17468
|
if (goModPath !== void 0) {
|
|
17303
|
-
goModDirname = (0,
|
|
17304
|
-
const backupFile = (0,
|
|
17305
|
-
await (0,
|
|
17469
|
+
goModDirname = (0, import_path7.dirname)(goModPath);
|
|
17470
|
+
const backupFile = (0, import_path7.join)(goModDirname, `__vc_go.mod.bak`);
|
|
17471
|
+
await (0, import_fs_extra4.copy)(goModPath, backupFile);
|
|
17306
17472
|
undo.fileActions.push({
|
|
17307
17473
|
to: goModPath,
|
|
17308
17474
|
from: backupFile
|
|
17309
17475
|
});
|
|
17310
|
-
const goSumPath = (0,
|
|
17311
|
-
const isGoSumExists = await (0,
|
|
17476
|
+
const goSumPath = (0, import_path7.join)(goModDirname, "go.sum");
|
|
17477
|
+
const isGoSumExists = await (0, import_fs_extra4.pathExists)(goSumPath);
|
|
17312
17478
|
if (!isGoSumExists) {
|
|
17313
17479
|
undo.fileActions.push({
|
|
17314
17480
|
to: void 0,
|
|
@@ -17317,23 +17483,23 @@ async function buildHandlerWithGoMod({
|
|
|
17317
17483
|
});
|
|
17318
17484
|
}
|
|
17319
17485
|
}
|
|
17320
|
-
const entrypointArr = entrypoint.split(
|
|
17486
|
+
const entrypointArr = entrypoint.split(import_path7.posix.sep);
|
|
17321
17487
|
let goPackageName = `${packageName}/${packageName}`;
|
|
17322
17488
|
const goFuncName = `${packageName}.${handlerFunctionName}`;
|
|
17323
|
-
const relPackagePath = goModDirname ?
|
|
17489
|
+
const relPackagePath = goModDirname ? import_path7.posix.relative(goModDirname, entrypointDirname) : "";
|
|
17324
17490
|
if (relPackagePath) {
|
|
17325
|
-
goPackageName =
|
|
17491
|
+
goPackageName = import_path7.posix.join(packageName, relPackagePath);
|
|
17326
17492
|
}
|
|
17327
17493
|
let mainGoFile;
|
|
17328
17494
|
if (goModPath && isGoModInRootDir) {
|
|
17329
|
-
(0,
|
|
17330
|
-
mainGoFile = (0,
|
|
17495
|
+
(0, import_build_utils4.debug)(`[mod-root] Write main file to ${downloadPath}`);
|
|
17496
|
+
mainGoFile = (0, import_path7.join)(downloadPath, MAIN_GO_FILENAME);
|
|
17331
17497
|
} else if (goModDirname && !isGoModInRootDir) {
|
|
17332
|
-
(0,
|
|
17333
|
-
mainGoFile = (0,
|
|
17498
|
+
(0, import_build_utils4.debug)(`[mod-other] Write main file to ${goModDirname}`);
|
|
17499
|
+
mainGoFile = (0, import_path7.join)(goModDirname, MAIN_GO_FILENAME);
|
|
17334
17500
|
} else {
|
|
17335
|
-
(0,
|
|
17336
|
-
mainGoFile = (0,
|
|
17501
|
+
(0, import_build_utils4.debug)(`[entrypoint] Write main file to ${entrypointDirname}`);
|
|
17502
|
+
mainGoFile = (0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME);
|
|
17337
17503
|
}
|
|
17338
17504
|
await Promise.all([
|
|
17339
17505
|
writeEntrypoint(mainGoFile, goPackageName, goFuncName),
|
|
@@ -17349,24 +17515,24 @@ async function buildHandlerWithGoMod({
|
|
|
17349
17515
|
from: mainGoFile
|
|
17350
17516
|
});
|
|
17351
17517
|
try {
|
|
17352
|
-
let finalDestination = (0,
|
|
17518
|
+
let finalDestination = (0, import_path7.join)(entrypointDirname, packageName, entrypoint);
|
|
17353
17519
|
if (entrypointArr.length > 1) {
|
|
17354
|
-
finalDestination = (0,
|
|
17520
|
+
finalDestination = (0, import_path7.join)(
|
|
17355
17521
|
entrypointDirname,
|
|
17356
17522
|
packageName,
|
|
17357
17523
|
entrypointArr[entrypointArr.length - 1]
|
|
17358
17524
|
);
|
|
17359
17525
|
}
|
|
17360
|
-
if (!goModPath || (0,
|
|
17361
|
-
(0,
|
|
17526
|
+
if (!goModPath || (0, import_path7.dirname)(entrypointAbsolute) === (0, import_path7.dirname)(goModPath)) {
|
|
17527
|
+
(0, import_build_utils4.debug)(
|
|
17362
17528
|
`moving entrypoint "${entrypointAbsolute}" to "${finalDestination}"`
|
|
17363
17529
|
);
|
|
17364
|
-
await (0,
|
|
17530
|
+
await (0, import_fs_extra4.move)(entrypointAbsolute, finalDestination);
|
|
17365
17531
|
undo.fileActions.push({
|
|
17366
17532
|
to: entrypointAbsolute,
|
|
17367
17533
|
from: finalDestination
|
|
17368
17534
|
});
|
|
17369
|
-
undo.directoryCreation.push((0,
|
|
17535
|
+
undo.directoryCreation.push((0, import_path7.dirname)(finalDestination));
|
|
17370
17536
|
}
|
|
17371
17537
|
} catch (err) {
|
|
17372
17538
|
console.error("Failed to move entry to package folder");
|
|
@@ -17376,21 +17542,21 @@ async function buildHandlerWithGoMod({
|
|
|
17376
17542
|
if (goModPath && isGoModInRootDir) {
|
|
17377
17543
|
baseGoModPath = downloadPath;
|
|
17378
17544
|
} else if (goModPath && !isGoModInRootDir) {
|
|
17379
|
-
baseGoModPath = (0,
|
|
17545
|
+
baseGoModPath = (0, import_path7.dirname)(goModPath);
|
|
17380
17546
|
} else {
|
|
17381
17547
|
baseGoModPath = entrypointDirname;
|
|
17382
17548
|
}
|
|
17383
|
-
(0,
|
|
17549
|
+
(0, import_build_utils4.debug)("Tidy `go.mod` file...");
|
|
17384
17550
|
try {
|
|
17385
17551
|
await go.mod();
|
|
17386
17552
|
} catch (err) {
|
|
17387
17553
|
console.error("failed to `go mod tidy`");
|
|
17388
17554
|
throw err;
|
|
17389
17555
|
}
|
|
17390
|
-
(0,
|
|
17391
|
-
const destPath = (0,
|
|
17556
|
+
(0, import_build_utils4.debug)("Running `go build`...");
|
|
17557
|
+
const destPath = (0, import_path7.join)(outDir, HANDLER_FILENAME);
|
|
17392
17558
|
try {
|
|
17393
|
-
const src = [(0,
|
|
17559
|
+
const src = [(0, import_path7.join)(baseGoModPath, MAIN_GO_FILENAME)];
|
|
17394
17560
|
await go.build(src, destPath);
|
|
17395
17561
|
} catch (err) {
|
|
17396
17562
|
console.error("failed to `go build`");
|
|
@@ -17405,31 +17571,31 @@ async function buildHandlerAsPackageMain({
|
|
|
17405
17571
|
outDir,
|
|
17406
17572
|
undo
|
|
17407
17573
|
}) {
|
|
17408
|
-
(0,
|
|
17574
|
+
(0, import_build_utils4.debug)('Building Go handler as package "main" (legacy)');
|
|
17409
17575
|
await writeEntrypoint(
|
|
17410
|
-
(0,
|
|
17576
|
+
(0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME),
|
|
17411
17577
|
"",
|
|
17412
17578
|
handlerFunctionName
|
|
17413
17579
|
);
|
|
17414
17580
|
undo.fileActions.push({
|
|
17415
17581
|
to: void 0,
|
|
17416
17582
|
// delete
|
|
17417
|
-
from: (0,
|
|
17583
|
+
from: (0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME)
|
|
17418
17584
|
});
|
|
17419
|
-
(0,
|
|
17585
|
+
(0, import_build_utils4.debug)("Running `go get`...");
|
|
17420
17586
|
try {
|
|
17421
17587
|
await go.get();
|
|
17422
17588
|
} catch (err) {
|
|
17423
17589
|
console.error("Failed to `go get`");
|
|
17424
17590
|
throw err;
|
|
17425
17591
|
}
|
|
17426
|
-
(0,
|
|
17427
|
-
const destPath = (0,
|
|
17592
|
+
(0, import_build_utils4.debug)("Running `go build`...");
|
|
17593
|
+
const destPath = (0, import_path7.join)(outDir, HANDLER_FILENAME);
|
|
17428
17594
|
try {
|
|
17429
17595
|
const src = [
|
|
17430
|
-
(0,
|
|
17596
|
+
(0, import_path7.join)(entrypointDirname, MAIN_GO_FILENAME),
|
|
17431
17597
|
entrypointAbsolute
|
|
17432
|
-
].map((file) => (0,
|
|
17598
|
+
].map((file) => (0, import_path7.normalize)(file));
|
|
17433
17599
|
await go.build(src, destPath);
|
|
17434
17600
|
} catch (err) {
|
|
17435
17601
|
console.error("failed to `go build`");
|
|
@@ -17437,10 +17603,10 @@ async function buildHandlerAsPackageMain({
|
|
|
17437
17603
|
}
|
|
17438
17604
|
}
|
|
17439
17605
|
async function renameHandlerFunction(fsPath, from, to) {
|
|
17440
|
-
let fileContents = await (0,
|
|
17606
|
+
let fileContents = await (0, import_fs_extra4.readFile)(fsPath, "utf8");
|
|
17441
17607
|
const fromRegex = new RegExp(String.raw` ${from}\b`, "g");
|
|
17442
17608
|
fileContents = fileContents.replace(fromRegex, ` ${to}`);
|
|
17443
|
-
await (0,
|
|
17609
|
+
await (0, import_fs_extra4.writeFile)(fsPath, fileContents);
|
|
17444
17610
|
}
|
|
17445
17611
|
function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
|
|
17446
17612
|
if (!originalFunctionName) {
|
|
@@ -17453,10 +17619,10 @@ function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
|
|
|
17453
17619
|
"Handler function renaming failed because entrypoint was empty."
|
|
17454
17620
|
);
|
|
17455
17621
|
}
|
|
17456
|
-
(0,
|
|
17622
|
+
(0, import_build_utils4.debug)(`Found exported function "${originalFunctionName}" in "${entrypoint}"`);
|
|
17457
17623
|
const pathSlug = entrypoint.replace(/(\s|\\|\/|\]|\[|-|\.)/g, "_");
|
|
17458
17624
|
const newHandlerName = `${originalFunctionName}_${pathSlug}`;
|
|
17459
|
-
(0,
|
|
17625
|
+
(0, import_build_utils4.debug)(
|
|
17460
17626
|
`Renaming handler function temporarily from "${originalFunctionName}" to "${newHandlerName}"`
|
|
17461
17627
|
);
|
|
17462
17628
|
return newHandlerName;
|
|
@@ -17468,36 +17634,36 @@ async function cleanupFileSystem({
|
|
|
17468
17634
|
}) {
|
|
17469
17635
|
for (const action of fileActions.reverse()) {
|
|
17470
17636
|
if (action.to) {
|
|
17471
|
-
await (0,
|
|
17637
|
+
await (0, import_fs_extra4.move)(action.from, action.to, { overwrite: true });
|
|
17472
17638
|
} else {
|
|
17473
|
-
await (0,
|
|
17639
|
+
await (0, import_fs_extra4.remove)(action.from);
|
|
17474
17640
|
}
|
|
17475
17641
|
}
|
|
17476
17642
|
for (const rename of functionRenames) {
|
|
17477
17643
|
await renameHandlerFunction(rename.fsPath, rename.from, rename.to);
|
|
17478
17644
|
}
|
|
17479
17645
|
const undoDirectoryPromises = directoryCreation.map(async (directory) => {
|
|
17480
|
-
const contents = await (0,
|
|
17646
|
+
const contents = await (0, import_fs_extra4.readdir)(directory);
|
|
17481
17647
|
if (!contents.length) {
|
|
17482
|
-
return (0,
|
|
17648
|
+
return (0, import_fs_extra4.rmdir)(directory);
|
|
17483
17649
|
}
|
|
17484
17650
|
return void 0;
|
|
17485
17651
|
});
|
|
17486
17652
|
await Promise.all(undoDirectoryPromises);
|
|
17487
17653
|
}
|
|
17488
|
-
async function
|
|
17654
|
+
async function findGoModPath2(entrypointDir, workPath) {
|
|
17489
17655
|
let goModPath = void 0;
|
|
17490
17656
|
let isGoModInRootDir = false;
|
|
17491
17657
|
let dir = entrypointDir;
|
|
17492
17658
|
while (!isGoModInRootDir) {
|
|
17493
17659
|
isGoModInRootDir = dir === workPath;
|
|
17494
|
-
const goMod = (0,
|
|
17495
|
-
if (await (0,
|
|
17660
|
+
const goMod = (0, import_path7.join)(dir, "go.mod");
|
|
17661
|
+
if (await (0, import_fs_extra4.pathExists)(goMod)) {
|
|
17496
17662
|
goModPath = goMod;
|
|
17497
|
-
(0,
|
|
17663
|
+
(0, import_build_utils4.debug)(`Found ${goModPath}"`);
|
|
17498
17664
|
break;
|
|
17499
17665
|
}
|
|
17500
|
-
dir = (0,
|
|
17666
|
+
dir = (0, import_path7.dirname)(dir);
|
|
17501
17667
|
}
|
|
17502
17668
|
return {
|
|
17503
17669
|
goModPath,
|
|
@@ -17511,22 +17677,22 @@ function isReadable2(v) {
|
|
|
17511
17677
|
return v && v.readable === true;
|
|
17512
17678
|
}
|
|
17513
17679
|
async function copyEntrypoint(entrypoint, dest) {
|
|
17514
|
-
const data = await (0,
|
|
17680
|
+
const data = await (0, import_fs_extra4.readFile)(entrypoint, "utf8");
|
|
17515
17681
|
const patched = data.replace(/\bpackage\W+\S+\b/, "package main");
|
|
17516
|
-
await (0,
|
|
17682
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(dest, "entrypoint.go"), patched);
|
|
17517
17683
|
}
|
|
17518
17684
|
async function copyDevServer(functionName, dest) {
|
|
17519
|
-
const data = await (0,
|
|
17685
|
+
const data = await (0, import_fs_extra4.readFile)((0, import_path7.join)(__dirname, "../dev-server.go"), "utf8");
|
|
17520
17686
|
const patched = data.replace("__HANDLER_FUNC_NAME", functionName);
|
|
17521
|
-
await (0,
|
|
17687
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(dest, "vercel-dev-server-main.go"), patched);
|
|
17522
17688
|
}
|
|
17523
17689
|
async function writeEntrypoint(dest, goPackageName, goFuncName) {
|
|
17524
|
-
const modMainGoContents = await (0,
|
|
17525
|
-
(0,
|
|
17690
|
+
const modMainGoContents = await (0, import_fs_extra4.readFile)(
|
|
17691
|
+
(0, import_path7.join)(__dirname, "../main.go"),
|
|
17526
17692
|
"utf8"
|
|
17527
17693
|
);
|
|
17528
17694
|
const mainModGoContents = modMainGoContents.replace("__VC_HANDLER_PACKAGE_NAME", goPackageName).replace("__VC_HANDLER_FUNC_NAME", goFuncName);
|
|
17529
|
-
await (0,
|
|
17695
|
+
await (0, import_fs_extra4.writeFile)(dest, mainModGoContents, "utf-8");
|
|
17530
17696
|
}
|
|
17531
17697
|
async function writeGoMod({
|
|
17532
17698
|
destDir,
|
|
@@ -17535,13 +17701,13 @@ async function writeGoMod({
|
|
|
17535
17701
|
}) {
|
|
17536
17702
|
let contents = `module ${packageName}`;
|
|
17537
17703
|
if (goModPath) {
|
|
17538
|
-
const goModRelPath = (0,
|
|
17539
|
-
const goModContents = await (0,
|
|
17704
|
+
const goModRelPath = (0, import_path7.relative)(destDir, (0, import_path7.dirname)(goModPath));
|
|
17705
|
+
const goModContents = await (0, import_fs_extra4.readFile)(goModPath, "utf-8");
|
|
17540
17706
|
contents = goModContents.replace(/^module\s+.+$/m, contents).replace(
|
|
17541
17707
|
/^(replace .+=>\s*)(.+)$/gm,
|
|
17542
17708
|
(orig, replaceStmt, replacePath) => {
|
|
17543
17709
|
if (replacePath.startsWith(".")) {
|
|
17544
|
-
return replaceStmt + (0,
|
|
17710
|
+
return replaceStmt + (0, import_path7.join)(goModRelPath, replacePath);
|
|
17545
17711
|
}
|
|
17546
17712
|
return orig;
|
|
17547
17713
|
}
|
|
@@ -17549,7 +17715,7 @@ async function writeGoMod({
|
|
|
17549
17715
|
const matches = goModContents.match(/module\s+(.+)/);
|
|
17550
17716
|
const moduleName = matches ? matches[1] : null;
|
|
17551
17717
|
if (moduleName) {
|
|
17552
|
-
let relPath = (0,
|
|
17718
|
+
let relPath = (0, import_path7.normalize)(goModRelPath);
|
|
17553
17719
|
if (!relPath.endsWith("/")) {
|
|
17554
17720
|
relPath += "/";
|
|
17555
17721
|
}
|
|
@@ -17569,25 +17735,25 @@ async function writeGoMod({
|
|
|
17569
17735
|
}
|
|
17570
17736
|
}
|
|
17571
17737
|
}
|
|
17572
|
-
const destGoModPath = (0,
|
|
17573
|
-
(0,
|
|
17574
|
-
await (0,
|
|
17738
|
+
const destGoModPath = (0, import_path7.join)(destDir, "go.mod");
|
|
17739
|
+
(0, import_build_utils4.debug)(`Writing ${destGoModPath}`);
|
|
17740
|
+
await (0, import_fs_extra4.writeFile)(destGoModPath, contents, "utf-8");
|
|
17575
17741
|
}
|
|
17576
17742
|
async function findGoWorkFile(goWorkDir, workPath) {
|
|
17577
|
-
while (!await (0,
|
|
17743
|
+
while (!await (0, import_fs_extra4.pathExists)((0, import_path7.join)(goWorkDir, "go.work"))) {
|
|
17578
17744
|
if (goWorkDir === workPath) {
|
|
17579
17745
|
return;
|
|
17580
17746
|
}
|
|
17581
|
-
goWorkDir = (0,
|
|
17747
|
+
goWorkDir = (0, import_path7.dirname)(goWorkDir);
|
|
17582
17748
|
}
|
|
17583
|
-
return (0,
|
|
17749
|
+
return (0, import_path7.join)(goWorkDir, "go.work");
|
|
17584
17750
|
}
|
|
17585
17751
|
async function writeGoWork(destDir, workPath, modulePath) {
|
|
17586
17752
|
const workspaces = /* @__PURE__ */ new Set(["."]);
|
|
17587
17753
|
const goWorkPath = await findGoWorkFile(modulePath || workPath, workPath);
|
|
17588
17754
|
let goVersion;
|
|
17589
17755
|
if (goWorkPath) {
|
|
17590
|
-
const contents2 = await (0,
|
|
17756
|
+
const contents2 = await (0, import_fs_extra4.readFile)(goWorkPath, "utf-8");
|
|
17591
17757
|
const goVersionMatch = contents2.match(/^go\s+(\d+\.\d+(\.\d+)?)/m);
|
|
17592
17758
|
if (goVersionMatch) {
|
|
17593
17759
|
goVersion = goVersionMatch[1];
|
|
@@ -17595,7 +17761,7 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17595
17761
|
const addPath = (path8) => {
|
|
17596
17762
|
if (path8) {
|
|
17597
17763
|
if (path8.startsWith(".")) {
|
|
17598
|
-
workspaces.add((0,
|
|
17764
|
+
workspaces.add((0, import_path7.relative)(destDir, (0, import_path7.join)(workPath, path8)));
|
|
17599
17765
|
} else {
|
|
17600
17766
|
workspaces.add(path8);
|
|
17601
17767
|
}
|
|
@@ -17618,10 +17784,10 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17618
17784
|
match = singleRE.exec(contents2);
|
|
17619
17785
|
}
|
|
17620
17786
|
} else if (modulePath) {
|
|
17621
|
-
workspaces.add((0,
|
|
17622
|
-
const goModPath = (0,
|
|
17623
|
-
if (await (0,
|
|
17624
|
-
const goModContents = await (0,
|
|
17787
|
+
workspaces.add((0, import_path7.relative)(destDir, modulePath));
|
|
17788
|
+
const goModPath = (0, import_path7.join)(modulePath, "go.mod");
|
|
17789
|
+
if (await (0, import_fs_extra4.pathExists)(goModPath)) {
|
|
17790
|
+
const goModContents = await (0, import_fs_extra4.readFile)(goModPath, "utf-8");
|
|
17625
17791
|
const goVersionMatch = goModContents.match(/^go\s+(\d+\.\d+(\.\d+)?)/m);
|
|
17626
17792
|
if (goVersionMatch) {
|
|
17627
17793
|
goVersion = goVersionMatch[1];
|
|
@@ -17638,24 +17804,36 @@ async function writeGoWork(destDir, workPath, modulePath) {
|
|
|
17638
17804
|
${Array.from(workspaces).map((w) => ` ${w}
|
|
17639
17805
|
`).join("")})
|
|
17640
17806
|
`;
|
|
17641
|
-
await (0,
|
|
17807
|
+
await (0, import_fs_extra4.writeFile)((0, import_path7.join)(destDir, "go.work"), contents, "utf-8");
|
|
17642
17808
|
}
|
|
17643
17809
|
async function startDevServer(opts) {
|
|
17644
|
-
const { entrypoint, workPath, meta = {} } = opts;
|
|
17645
|
-
const { devCacheDir = (0,
|
|
17646
|
-
const entrypointDir = (0, import_path5.dirname)(entrypoint);
|
|
17810
|
+
const { entrypoint, workPath, config, meta = {} } = opts;
|
|
17811
|
+
const { devCacheDir = (0, import_path7.join)(workPath, ".vercel", "cache") } = meta;
|
|
17647
17812
|
let entrypointWithExt = entrypoint;
|
|
17648
17813
|
if (!entrypoint.endsWith(".go")) {
|
|
17649
17814
|
entrypointWithExt += ".go";
|
|
17650
17815
|
}
|
|
17651
|
-
|
|
17652
|
-
|
|
17653
|
-
|
|
17654
|
-
|
|
17655
|
-
|
|
17816
|
+
if (config?.framework === "go" || config?.framework === "services") {
|
|
17817
|
+
const resolvedEntrypoint = await detectGoEntrypoint(
|
|
17818
|
+
workPath,
|
|
17819
|
+
entrypointWithExt
|
|
17820
|
+
);
|
|
17821
|
+
if (!resolvedEntrypoint) {
|
|
17822
|
+
throw new Error(
|
|
17823
|
+
`No Go entrypoint found. Expected one of: ${GO_CANDIDATE_ENTRYPOINTS.join(", ")}`
|
|
17824
|
+
);
|
|
17825
|
+
}
|
|
17826
|
+
return startStandaloneDevServer(opts, resolvedEntrypoint);
|
|
17827
|
+
}
|
|
17828
|
+
const entrypointDir = (0, import_path7.dirname)(entrypointWithExt);
|
|
17829
|
+
const tmp = (0, import_path7.join)(devCacheDir, "go", Math.random().toString(32).substring(2));
|
|
17830
|
+
const tmpPackage = (0, import_path7.join)(tmp, entrypointDir);
|
|
17831
|
+
await (0, import_fs_extra4.mkdirp)(tmpPackage);
|
|
17832
|
+
const { goModPath } = await findGoModPath2(
|
|
17833
|
+
(0, import_path7.join)(workPath, entrypointDir),
|
|
17656
17834
|
workPath
|
|
17657
17835
|
);
|
|
17658
|
-
const modulePath = goModPath ? (0,
|
|
17836
|
+
const modulePath = goModPath ? (0, import_path7.dirname)(goModPath) : void 0;
|
|
17659
17837
|
const analyzed = await getAnalyzedEntrypoint({
|
|
17660
17838
|
entrypoint: entrypointWithExt,
|
|
17661
17839
|
modulePath,
|
|
@@ -17671,11 +17849,11 @@ async function startDevServer(opts) {
|
|
|
17671
17849
|
}),
|
|
17672
17850
|
writeGoWork(tmp, workPath, modulePath)
|
|
17673
17851
|
]);
|
|
17674
|
-
const portFile = (0,
|
|
17852
|
+
const portFile = (0, import_path7.join)(
|
|
17675
17853
|
TMP,
|
|
17676
17854
|
`vercel-dev-port-${Math.random().toString(32).substring(2)}`
|
|
17677
17855
|
);
|
|
17678
|
-
const env = (0,
|
|
17856
|
+
const env = (0, import_build_utils4.cloneEnv)(process.env, meta.env, {
|
|
17679
17857
|
VERCEL_DEV_PORT_FILE: portFile
|
|
17680
17858
|
});
|
|
17681
17859
|
const executable = `./vercel-dev-server-go${process.platform === "win32" ? ".exe" : ""}`;
|
|
@@ -17688,15 +17866,15 @@ async function startDevServer(opts) {
|
|
|
17688
17866
|
workPath
|
|
17689
17867
|
});
|
|
17690
17868
|
await go.build("./...", executable);
|
|
17691
|
-
(0,
|
|
17692
|
-
const child = (0,
|
|
17869
|
+
(0, import_build_utils4.debug)(`SPAWNING ${executable} CWD=${tmp}`);
|
|
17870
|
+
const child = (0, import_child_process2.spawn)(executable, [], {
|
|
17693
17871
|
cwd: tmp,
|
|
17694
17872
|
env,
|
|
17695
17873
|
stdio: ["ignore", "inherit", "inherit", "pipe"]
|
|
17696
17874
|
});
|
|
17697
17875
|
child.on("close", async () => {
|
|
17698
17876
|
try {
|
|
17699
|
-
await (0, import_async_retry.default)(() => (0,
|
|
17877
|
+
await (0, import_async_retry.default)(() => (0, import_fs_extra4.remove)(tmp));
|
|
17700
17878
|
} catch (err) {
|
|
17701
17879
|
console.error(`Could not delete tmp directory: ${tmp}: ${err}`);
|
|
17702
17880
|
}
|
|
@@ -17741,8 +17919,8 @@ async function waitForPortFile_(opts) {
|
|
|
17741
17919
|
while (!opts.canceled) {
|
|
17742
17920
|
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17743
17921
|
try {
|
|
17744
|
-
const port = Number(await (0,
|
|
17745
|
-
(0, import_async_retry.default)(() => (0,
|
|
17922
|
+
const port = Number(await (0, import_fs_extra4.readFile)(opts.portFile, "ascii"));
|
|
17923
|
+
(0, import_async_retry.default)(() => (0, import_fs_extra4.remove)(opts.portFile)).catch((err) => {
|
|
17746
17924
|
console.error(`Could not delete port file: ${opts.portFile}: ${err}`);
|
|
17747
17925
|
});
|
|
17748
17926
|
return { port };
|
|
@@ -17756,15 +17934,15 @@ async function waitForPortFile_(opts) {
|
|
|
17756
17934
|
async function prepareCache({
|
|
17757
17935
|
workPath
|
|
17758
17936
|
}) {
|
|
17759
|
-
const goCacheDir = (0,
|
|
17760
|
-
const stat = await (0,
|
|
17937
|
+
const goCacheDir = (0, import_path7.join)(workPath, localCacheDir);
|
|
17938
|
+
const stat = await (0, import_fs_extra4.lstat)(goCacheDir);
|
|
17761
17939
|
if (stat.isSymbolicLink()) {
|
|
17762
|
-
const goGlobalCacheDir = await (0,
|
|
17763
|
-
(0,
|
|
17764
|
-
await (0,
|
|
17765
|
-
await (0,
|
|
17940
|
+
const goGlobalCacheDir = await (0, import_fs_extra4.readlink)(goCacheDir);
|
|
17941
|
+
(0, import_build_utils4.debug)(`Preparing cache by moving ${goGlobalCacheDir} -> ${goCacheDir}`);
|
|
17942
|
+
await (0, import_fs_extra4.unlink)(goCacheDir);
|
|
17943
|
+
await (0, import_fs_extra4.move)(goGlobalCacheDir, goCacheDir);
|
|
17766
17944
|
}
|
|
17767
|
-
const cache2 = await (0,
|
|
17945
|
+
const cache2 = await (0, import_build_utils4.glob)(`${localCacheDir}/**`, workPath);
|
|
17768
17946
|
return cache2;
|
|
17769
17947
|
}
|
|
17770
17948
|
// Annotate the CommonJS export names for ESM import in node:
|