@vercel/go 3.1.2 → 3.2.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 +48 -24
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -17908,8 +17908,8 @@ var import_yauzl_promise = __toESM(require_lib6());
17908
17908
  var import_xdg_app_paths = __toESM(require_xdg_app_paths());
17909
17909
  var streamPipeline = (0, import_util.promisify)(import_stream.pipeline);
17910
17910
  var versionMap = /* @__PURE__ */ new Map([
17911
- ["1.23", "1.23.0"],
17912
- ["1.22", "1.22.6"],
17911
+ ["1.23", "1.23.2"],
17912
+ ["1.22", "1.22.8"],
17913
17913
  ["1.21", "1.21.13"],
17914
17914
  ["1.20", "1.20.14"],
17915
17915
  ["1.19", "1.19.13"],
@@ -17927,13 +17927,14 @@ var archMap = /* @__PURE__ */ new Map([
17927
17927
  var platformMap = /* @__PURE__ */ new Map([["win32", "windows"]]);
17928
17928
  var localCacheDir = (0, import_path.join)(".vercel", "cache", "golang");
17929
17929
  var GO_FLAGS = process.platform === "win32" ? [] : ["-ldflags", "-s -w"];
17930
- var GO_MIN_VERSION = 13;
17930
+ var GO_MIN_MAJOR_VERSION = 1;
17931
+ var GO_MIN_MINOR_VERSION = 13;
17931
17932
  function getGoUrl(version2) {
17932
17933
  const { arch, platform } = process;
17933
17934
  const ext = platform === "win32" ? "zip" : "tar.gz";
17934
17935
  const goPlatform = platformMap.get(platform) || platform;
17935
17936
  let goArch = archMap.get(arch) || arch;
17936
- if (platform === "darwin" && goArch === "arm64" && parseInt(version2.split(".")[1], 10) < 16) {
17937
+ if (platform === "darwin" && goArch === "arm64" && parseInt(/^\d+.(\d+)/.exec(version2)[1], 10) < 16) {
17937
17938
  goArch = "amd64";
17938
17939
  }
17939
17940
  const filename = `go${version2}.${goPlatform}-${goArch}.${ext}`;
@@ -18047,9 +18048,9 @@ async function createGo({
18047
18048
  }) {
18048
18049
  let goPreferredVersion;
18049
18050
  if (modulePath) {
18050
- goPreferredVersion = await parseGoModVersion(modulePath);
18051
+ goPreferredVersion = await parseGoModVersionFromModule(modulePath);
18051
18052
  }
18052
- const goSelectedVersion = goPreferredVersion || Array.from(versionMap.values())[0];
18053
+ const goSelectedVersion = goPreferredVersion ? goPreferredVersion.toolchain || goPreferredVersion.go : Array.from(versionMap.values())[0];
18053
18054
  const env = (0, import_build_utils.cloneEnv)(process.env, opts.env);
18054
18055
  const { PATH } = env;
18055
18056
  const { platform } = process;
@@ -18059,7 +18060,7 @@ async function createGo({
18059
18060
  );
18060
18061
  const goCacheDir = (0, import_path.join)(workPath, localCacheDir);
18061
18062
  if (goPreferredVersion) {
18062
- (0, import_build_utils.debug)(`Preferred go version ${goPreferredVersion} (from go.mod)`);
18063
+ (0, import_build_utils.debug)(`Preferred go version ${goSelectedVersion} (from go.mod)`);
18063
18064
  env.GO111MODULE = "on";
18064
18065
  } else {
18065
18066
  (0, import_build_utils.debug)(
@@ -18092,8 +18093,8 @@ async function createGo({
18092
18093
  env.GOROOT = goDir || void 0;
18093
18094
  env.PATH = goBinDir || PATH;
18094
18095
  const { stdout } = await (0, import_execa.default)("go", ["version"], { env });
18095
- const { minor, short, version: version2 } = parseGoVersionString(stdout);
18096
- if (minor < GO_MIN_VERSION) {
18096
+ const { major, minor, short, version: version2 } = parseGoVersionString(stdout);
18097
+ if (major < GO_MIN_MAJOR_VERSION || major === GO_MIN_MAJOR_VERSION && minor < GO_MIN_MINOR_VERSION) {
18097
18098
  (0, import_build_utils.debug)(`Found go ${version2} in ${label}, but version is unsupported`);
18098
18099
  }
18099
18100
  if (version2 === goSelectedVersion || short === goSelectedVersion) {
@@ -18172,35 +18173,58 @@ function parseGoVersionString(goVersionOutput) {
18172
18173
  }
18173
18174
  var GoError = class extends Error {
18174
18175
  };
18175
- async function parseGoModVersion(modulePath) {
18176
+ async function parseGoModVersionFromModule(modulePath) {
18176
18177
  let version2;
18177
18178
  const file = (0, import_path.join)(modulePath, "go.mod");
18178
18179
  try {
18179
18180
  const content = await (0, import_fs_extra.readFile)(file, "utf8");
18180
- const matches = /^go (\d+)\.(\d+)\.?$/gm.exec(content) || [];
18181
- const major = parseInt(matches[1], 10);
18182
- const minor = parseInt(matches[2], 10);
18183
- const full = versionMap.get(`${major}.${minor}`);
18184
- if (major === 1 && minor >= GO_MIN_VERSION && full) {
18185
- version2 = full;
18186
- } else if (!isNaN(minor)) {
18187
- const err = new GoError(
18188
- `Unsupported Go version ${major}.${minor} in ${file}`
18189
- );
18190
- err.code = "ERR_UNSUPPORTED_GO_VERSION";
18191
- throw err;
18192
- } else {
18181
+ version2 = parseGoModVersion(content);
18182
+ if (!version2) {
18193
18183
  console.log(`Warning: Unknown Go version in ${file}`);
18194
18184
  }
18195
18185
  } catch (err) {
18196
- if (err.code === "ENOENT") {
18186
+ if (typeof err === "object" && err.code === "ENOENT") {
18197
18187
  (0, import_build_utils.debug)(`File not found: ${file}`);
18188
+ return void 0;
18198
18189
  } else {
18199
18190
  throw err;
18200
18191
  }
18201
18192
  }
18202
18193
  return version2;
18203
18194
  }
18195
+ function parseGoModVersion(content) {
18196
+ const goMatches = /^\s*go\s+(\d+)\.(\d+)(?:\.(\d+))?\s*(?:\/\/.*)?$/gm.exec(
18197
+ content
18198
+ );
18199
+ if (!goMatches) {
18200
+ return void 0;
18201
+ }
18202
+ const major = parseInt(goMatches[1], 10);
18203
+ const minor = parseInt(goMatches[2], 10);
18204
+ const patch = goMatches[3] && parseInt(goMatches[3], 10);
18205
+ const toolchainMatches = /^\s*toolchain\s+go((\d+)\.(\d+)(?:\.(\d+)|\w+\d+)?)\s*(?:\/\/.*)?$/gm.exec(
18206
+ content
18207
+ );
18208
+ const toolchain = toolchainMatches ? toolchainMatches[1] : void 0;
18209
+ if (major >= GO_MIN_MAJOR_VERSION && minor >= GO_MIN_MINOR_VERSION) {
18210
+ if (patch) {
18211
+ return {
18212
+ go: `${major}.${minor}.${patch}`,
18213
+ toolchain
18214
+ };
18215
+ }
18216
+ const full = versionMap.get(`${major}.${minor}`);
18217
+ if (full) {
18218
+ return {
18219
+ go: full,
18220
+ toolchain
18221
+ };
18222
+ }
18223
+ }
18224
+ const err = new GoError(`Unsupported Go version ${major}.${minor}`);
18225
+ err.code = "ERR_UNSUPPORTED_GO_VERSION";
18226
+ throw err;
18227
+ }
18204
18228
 
18205
18229
  // src/index.ts
18206
18230
  var TMP = (0, import_os2.tmpdir)();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "3.1.2",
3
+ "version": "3.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -23,7 +23,7 @@
23
23
  "@types/node-fetch": "^2.3.0",
24
24
  "@types/tar": "6.1.5",
25
25
  "@types/yauzl-promise": "2.1.0",
26
- "@vercel/build-utils": "8.3.9",
26
+ "@vercel/build-utils": "8.4.10",
27
27
  "async-retry": "1.3.3",
28
28
  "execa": "^1.0.0",
29
29
  "fs-extra": "^7.0.0",