@vercel/go 3.4.7 → 3.5.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.
Files changed (2) hide show
  1. package/dist/index.js +51 -8
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -14283,8 +14283,15 @@ var GoWrapper = class {
14283
14283
  throw enrichGoCommandError(error);
14284
14284
  }
14285
14285
  }
14286
- mod() {
14287
- return this.execute("mod", "tidy");
14286
+ mod({ tolerateErrors = false } = {}) {
14287
+ const args = ["mod", "tidy"];
14288
+ if (tolerateErrors) {
14289
+ args.push("-e");
14290
+ }
14291
+ return this.execute(...args);
14292
+ }
14293
+ vendor() {
14294
+ return this.execute("mod", "vendor");
14288
14295
  }
14289
14296
  get(src) {
14290
14297
  const args = ["get"];
@@ -14296,11 +14303,14 @@ var GoWrapper = class {
14296
14303
  }
14297
14304
  return this.execute(...args);
14298
14305
  }
14299
- build(src, dest) {
14306
+ build(src, dest, { vendorMode = false } = {}) {
14300
14307
  (0, import_build_utils.debug)(`Building optimized 'go' binary ${src} -> ${dest}`);
14301
14308
  const sources = Array.isArray(src) ? src : [src];
14302
14309
  const envGoBuildFlags = (this.env || this.opts.env).GO_BUILD_FLAGS;
14303
- const flags = envGoBuildFlags ? (0, import_string_argv.default)(envGoBuildFlags) : GO_FLAGS;
14310
+ const flags = envGoBuildFlags ? (0, import_string_argv.default)(envGoBuildFlags) : [...GO_FLAGS];
14311
+ if (vendorMode && !envGoBuildFlags) {
14312
+ flags.push("-mod=vendor");
14313
+ }
14304
14314
  return this.execute("build", ...flags, "-o", dest, ...sources);
14305
14315
  }
14306
14316
  };
@@ -14593,12 +14603,17 @@ async function buildStandaloneServer({
14593
14603
  const outDir = await (0, import_build_utils3.getWriteableDirectory)();
14594
14604
  const userServerPath = (0, import_path6.join)(outDir, "user-server");
14595
14605
  const bootstrapPath = (0, import_path6.join)(outDir, "executable");
14606
+ const vendorModulesPath = (0, import_path6.join)(workPath, "vendor", "modules.txt");
14607
+ const isVendored = await (0, import_fs_extra3.pathExists)(vendorModulesPath);
14608
+ if (isVendored) {
14609
+ (0, import_build_utils3.debug)("Detected vendor directory, using -mod=vendor for build");
14610
+ }
14596
14611
  const buildTarget = entrypoint === "main.go" ? "." : "./" + (0, import_path6.dirname)(entrypoint);
14597
14612
  (0, import_build_utils3.debug)(
14598
14613
  `Building user Go server (${architecture}): go build ${buildTarget} -> ${userServerPath}`
14599
14614
  );
14600
14615
  try {
14601
- await go.build(buildTarget, userServerPath);
14616
+ await go.build(buildTarget, userServerPath, { vendorMode: isVendored });
14602
14617
  } catch (err) {
14603
14618
  console.error(`Failed to build standalone Go server: ${buildTarget}`);
14604
14619
  throw err;
@@ -14927,6 +14942,21 @@ async function buildHandlerWithGoMod({
14927
14942
  });
14928
14943
  }
14929
14944
  }
14945
+ const vendorModulesPath = (0, import_path7.join)(
14946
+ goModDirname || entrypointDirname,
14947
+ "vendor",
14948
+ "modules.txt"
14949
+ );
14950
+ const isVendored = await (0, import_fs_extra4.pathExists)(vendorModulesPath);
14951
+ if (isVendored) {
14952
+ (0, import_build_utils4.debug)("Detected vendor directory in project");
14953
+ const vendorModulesBackup = vendorModulesPath + ".bak";
14954
+ await (0, import_fs_extra4.copy)(vendorModulesPath, vendorModulesBackup);
14955
+ undo.fileActions.push({
14956
+ to: vendorModulesPath,
14957
+ from: vendorModulesBackup
14958
+ });
14959
+ }
14930
14960
  const entrypointArr = entrypoint.split(import_path7.posix.sep);
14931
14961
  let goPackageName = `${packageName}/${packageName}`;
14932
14962
  const goFuncName = `${packageName}.${handlerFunctionName}`;
@@ -14992,16 +15022,25 @@ async function buildHandlerWithGoMod({
14992
15022
  }
14993
15023
  (0, import_build_utils4.debug)("Tidy `go.mod` file...");
14994
15024
  try {
14995
- await go.mod();
15025
+ await go.mod({ tolerateErrors: isVendored });
14996
15026
  } catch (err) {
14997
15027
  console.error("failed to `go mod tidy`");
14998
15028
  throw err;
14999
15029
  }
15030
+ if (isVendored) {
15031
+ (0, import_build_utils4.debug)("Regenerating vendor directory after go.mod rewrite...");
15032
+ try {
15033
+ await go.vendor();
15034
+ } catch (err) {
15035
+ console.error("failed to `go mod vendor`");
15036
+ throw err;
15037
+ }
15038
+ }
15000
15039
  (0, import_build_utils4.debug)("Running `go build`...");
15001
15040
  const destPath = (0, import_path7.join)(outDir, HANDLER_FILENAME);
15002
15041
  try {
15003
15042
  const src = [(0, import_path7.join)(baseGoModPath, MAIN_GO_FILENAME)];
15004
- await go.build(src, destPath);
15043
+ await go.build(src, destPath, { vendorMode: isVendored });
15005
15044
  } catch (err) {
15006
15045
  console.error("failed to `go build`");
15007
15046
  throw err;
@@ -15151,7 +15190,11 @@ async function writeGoMod({
15151
15190
  /^(replace .+=>\s*)(.+)$/gm,
15152
15191
  (orig, replaceStmt, replacePath) => {
15153
15192
  if (replacePath.startsWith(".")) {
15154
- return replaceStmt + (0, import_path7.join)(goModRelPath, replacePath);
15193
+ let newPath = (0, import_path7.join)(goModRelPath, replacePath);
15194
+ if (!newPath.startsWith(".") && !newPath.startsWith("/")) {
15195
+ newPath = "./" + newPath;
15196
+ }
15197
+ return replaceStmt + newPath;
15155
15198
  }
15156
15199
  return orig;
15157
15200
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "3.4.7",
3
+ "version": "3.5.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -32,7 +32,7 @@
32
32
  "typescript": "4.9.5",
33
33
  "xdg-app-paths": "5.1.0",
34
34
  "yauzl-promise": "2.1.3",
35
- "@vercel/build-utils": "13.12.1"
35
+ "@vercel/build-utils": "13.14.2"
36
36
  },
37
37
  "scripts": {
38
38
  "build": "node ../../utils/build-builder.mjs",