@vercel/go 3.2.4 → 3.3.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 +63 -36
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -17027,7 +17027,7 @@ __export(src_exports, {
17027
17027
  build: () => build,
17028
17028
  getNewHandlerFunctionName: () => getNewHandlerFunctionName,
17029
17029
  prepareCache: () => prepareCache,
17030
- shouldServe: () => import_build_utils2.shouldServe,
17030
+ shouldServe: () => import_build_utils3.shouldServe,
17031
17031
  startDevServer: () => startDevServer,
17032
17032
  version: () => version
17033
17033
  });
@@ -17039,7 +17039,7 @@ var import_child_process = require("child_process");
17039
17039
  var import_once = __toESM(require_dist());
17040
17040
  var import_path2 = require("path");
17041
17041
  var import_fs_extra2 = __toESM(require_lib2());
17042
- var import_build_utils2 = require("@vercel/build-utils");
17042
+ var import_build_utils3 = require("@vercel/build-utils");
17043
17043
 
17044
17044
  // src/go-helpers.ts
17045
17045
  var import_tar = __toESM(require_tar());
@@ -17054,6 +17054,7 @@ var import_util = require("util");
17054
17054
  var import_os = require("os");
17055
17055
  var import_yauzl_promise = __toESM(require_lib6());
17056
17056
  var import_xdg_app_paths = __toESM(require_xdg_app_paths());
17057
+ var import_build_utils2 = require("@vercel/build-utils");
17057
17058
  var streamPipeline = (0, import_util.promisify)(import_stream.pipeline);
17058
17059
  var versionMap = /* @__PURE__ */ new Map([
17059
17060
  ["1.24", "1.24.5"],
@@ -17217,15 +17218,41 @@ async function createGo({
17217
17218
  );
17218
17219
  }
17219
17220
  const setGoEnv = async (goDir) => {
17220
- if (platform !== "win32" && goDir === goGlobalCacheDir) {
17221
+ if (!goDir) {
17222
+ env.GOROOT = void 0;
17223
+ env.PATH = PATH;
17224
+ return;
17225
+ }
17226
+ const isUnix = platform !== "win32";
17227
+ const setEnvPaths = (modCache, buildCache) => {
17228
+ env.GOMODCACHE = modCache;
17229
+ env.GOCACHE = buildCache;
17230
+ (0, import_build_utils.debug)(`Set GOMODCACHE to ${env.GOMODCACHE}`);
17231
+ (0, import_build_utils.debug)(`Set GOCACHE to ${env.GOCACHE}`);
17232
+ };
17233
+ if (isUnix && goDir === goGlobalCacheDir) {
17221
17234
  (0, import_build_utils.debug)(`Symlinking ${goDir} -> ${goCacheDir}`);
17222
17235
  await (0, import_fs_extra.remove)(goCacheDir);
17223
17236
  await (0, import_fs_extra.mkdirp)((0, import_path.dirname)(goCacheDir));
17224
17237
  await (0, import_fs_extra.symlink)(goDir, goCacheDir);
17238
+ const modCache = (0, import_path.join)(goDir, "pkg", "mod");
17239
+ const buildCache = (0, import_path.join)(goDir, "go-build");
17240
+ setEnvPaths(modCache, buildCache);
17225
17241
  goDir = goCacheDir;
17226
- }
17227
- env.GOROOT = goDir || void 0;
17228
- env.PATH = goDir ? `${(0, import_path.join)(goDir, "bin")}${import_path.delimiter}${PATH}` : PATH;
17242
+ } else if (isUnix && goDir === goCacheDir) {
17243
+ const tmpBase = await (0, import_build_utils2.getWriteableDirectory)();
17244
+ const tmpModCache = (0, import_path.join)(tmpBase, "pkg");
17245
+ const tmpBuildCache = (0, import_path.join)(tmpBase, ".cache");
17246
+ await Promise.all([
17247
+ (0, import_fs_extra.mkdirp)((0, import_path.join)(goDir, "pkg", "mod")),
17248
+ (0, import_fs_extra.mkdirp)((0, import_path.join)(goDir, ".cache", "go-build")),
17249
+ (0, import_fs_extra.symlink)((0, import_path.join)(goCacheDir, "pkg", "mod"), tmpModCache),
17250
+ (0, import_fs_extra.symlink)((0, import_path.join)(goCacheDir, ".cache", "go-build"), tmpBuildCache)
17251
+ ]);
17252
+ setEnvPaths(tmpModCache, tmpBuildCache);
17253
+ }
17254
+ env.GOROOT = goDir;
17255
+ env.PATH = `${(0, import_path.join)(goDir, "bin")}${import_path.delimiter}${PATH}`;
17229
17256
  };
17230
17257
  const goDirs = {
17231
17258
  "local cache": goCacheDir,
@@ -17393,7 +17420,7 @@ function getRenamedEntrypoint(entrypoint) {
17393
17420
  const filename = (0, import_path2.basename)(entrypoint);
17394
17421
  if (filename.startsWith("[")) {
17395
17422
  const newEntrypoint = entrypoint.replace("/[", "/now-bracket[");
17396
- (0, import_build_utils2.debug)(`Renamed entrypoint from ${entrypoint} to ${newEntrypoint}`);
17423
+ (0, import_build_utils3.debug)(`Renamed entrypoint from ${entrypoint} to ${newEntrypoint}`);
17397
17424
  return newEntrypoint;
17398
17425
  }
17399
17426
  return void 0;
@@ -17406,22 +17433,22 @@ async function build({
17406
17433
  workPath,
17407
17434
  meta = {}
17408
17435
  }) {
17409
- const goPath = await (0, import_build_utils2.getWriteableDirectory)();
17436
+ const goPath = await (0, import_build_utils3.getWriteableDirectory)();
17410
17437
  const srcPath = (0, import_path2.join)(goPath, "src", "lambda");
17411
17438
  const downloadPath = meta.skipDownload ? workPath : srcPath;
17412
- await (0, import_build_utils2.download)(files, downloadPath, meta);
17439
+ await (0, import_build_utils3.download)(files, downloadPath, meta);
17413
17440
  const undo = {
17414
17441
  fileActions: [],
17415
17442
  directoryCreation: [],
17416
17443
  functionRenames: []
17417
17444
  };
17418
- const env = (0, import_build_utils2.cloneEnv)(process.env, meta.env, {
17445
+ const env = (0, import_build_utils3.cloneEnv)(process.env, meta.env, {
17419
17446
  GOARCH: "amd64",
17420
17447
  GOOS: "linux"
17421
17448
  });
17422
17449
  try {
17423
17450
  if (env.GIT_CREDENTIALS) {
17424
- (0, import_build_utils2.debug)("Initialize Git credentials...");
17451
+ (0, import_build_utils3.debug)("Initialize Git credentials...");
17425
17452
  await initPrivateGit(env.GIT_CREDENTIALS);
17426
17453
  }
17427
17454
  if (env.GO111MODULE) {
@@ -17483,7 +17510,7 @@ Manually assigning 'GO111MODULE' is not recommended.
17483
17510
  if (config && config.includeFiles) {
17484
17511
  const patterns = Array.isArray(config.includeFiles) ? config.includeFiles : [config.includeFiles];
17485
17512
  for (const pattern of patterns) {
17486
- const fsFiles = await (0, import_build_utils2.glob)(pattern, entrypointDirname);
17513
+ const fsFiles = await (0, import_build_utils3.glob)(pattern, entrypointDirname);
17487
17514
  for (const [assetName, asset] of Object.entries(fsFiles)) {
17488
17515
  includedFiles[assetName] = asset;
17489
17516
  }
@@ -17498,7 +17525,7 @@ Manually assigning 'GO111MODULE' is not recommended.
17498
17525
  },
17499
17526
  workPath
17500
17527
  });
17501
- const outDir = await (0, import_build_utils2.getWriteableDirectory)();
17528
+ const outDir = await (0, import_build_utils3.getWriteableDirectory)();
17502
17529
  const buildOptions = {
17503
17530
  downloadPath,
17504
17531
  entrypoint,
@@ -17517,9 +17544,9 @@ Manually assigning 'GO111MODULE' is not recommended.
17517
17544
  } else {
17518
17545
  await buildHandlerWithGoMod(buildOptions);
17519
17546
  }
17520
- const runtime = await (0, import_build_utils2.getProvidedRuntime)();
17521
- const lambda = new import_build_utils2.Lambda({
17522
- files: { ...await (0, import_build_utils2.glob)("**", outDir), ...includedFiles },
17547
+ const runtime = await (0, import_build_utils3.getProvidedRuntime)();
17548
+ const lambda = new import_build_utils3.Lambda({
17549
+ files: { ...await (0, import_build_utils3.glob)("**", outDir), ...includedFiles },
17523
17550
  handler: HANDLER_FILENAME,
17524
17551
  runtime,
17525
17552
  supportsWrapper: true,
@@ -17529,7 +17556,7 @@ Manually assigning 'GO111MODULE' is not recommended.
17529
17556
  output: lambda
17530
17557
  };
17531
17558
  } catch (error) {
17532
- (0, import_build_utils2.debug)(`Go Builder Error: ${error}`);
17559
+ (0, import_build_utils3.debug)(`Go Builder Error: ${error}`);
17533
17560
  throw error;
17534
17561
  } finally {
17535
17562
  try {
@@ -17538,7 +17565,7 @@ Manually assigning 'GO111MODULE' is not recommended.
17538
17565
  if (error instanceof Error) {
17539
17566
  console.error(`Build cleanup failed: ${error.message}`);
17540
17567
  }
17541
- (0, import_build_utils2.debug)("Cleanup Error: " + error);
17568
+ (0, import_build_utils3.debug)("Cleanup Error: " + error);
17542
17569
  }
17543
17570
  }
17544
17571
  }
@@ -17555,7 +17582,7 @@ async function buildHandlerWithGoMod({
17555
17582
  packageName,
17556
17583
  undo
17557
17584
  }) {
17558
- (0, import_build_utils2.debug)(
17585
+ (0, import_build_utils3.debug)(
17559
17586
  `Building Go handler as package "${packageName}" (with${goModPath ? "" : "out"} go.mod)`
17560
17587
  );
17561
17588
  let goModDirname;
@@ -17586,13 +17613,13 @@ async function buildHandlerWithGoMod({
17586
17613
  }
17587
17614
  let mainGoFile;
17588
17615
  if (goModPath && isGoModInRootDir) {
17589
- (0, import_build_utils2.debug)(`[mod-root] Write main file to ${downloadPath}`);
17616
+ (0, import_build_utils3.debug)(`[mod-root] Write main file to ${downloadPath}`);
17590
17617
  mainGoFile = (0, import_path2.join)(downloadPath, MAIN_GO_FILENAME);
17591
17618
  } else if (goModDirname && !isGoModInRootDir) {
17592
- (0, import_build_utils2.debug)(`[mod-other] Write main file to ${goModDirname}`);
17619
+ (0, import_build_utils3.debug)(`[mod-other] Write main file to ${goModDirname}`);
17593
17620
  mainGoFile = (0, import_path2.join)(goModDirname, MAIN_GO_FILENAME);
17594
17621
  } else {
17595
- (0, import_build_utils2.debug)(`[entrypoint] Write main file to ${entrypointDirname}`);
17622
+ (0, import_build_utils3.debug)(`[entrypoint] Write main file to ${entrypointDirname}`);
17596
17623
  mainGoFile = (0, import_path2.join)(entrypointDirname, MAIN_GO_FILENAME);
17597
17624
  }
17598
17625
  await Promise.all([
@@ -17618,7 +17645,7 @@ async function buildHandlerWithGoMod({
17618
17645
  );
17619
17646
  }
17620
17647
  if (!goModPath || (0, import_path2.dirname)(entrypointAbsolute) === (0, import_path2.dirname)(goModPath)) {
17621
- (0, import_build_utils2.debug)(
17648
+ (0, import_build_utils3.debug)(
17622
17649
  `moving entrypoint "${entrypointAbsolute}" to "${finalDestination}"`
17623
17650
  );
17624
17651
  await (0, import_fs_extra2.move)(entrypointAbsolute, finalDestination);
@@ -17640,14 +17667,14 @@ async function buildHandlerWithGoMod({
17640
17667
  } else {
17641
17668
  baseGoModPath = entrypointDirname;
17642
17669
  }
17643
- (0, import_build_utils2.debug)("Tidy `go.mod` file...");
17670
+ (0, import_build_utils3.debug)("Tidy `go.mod` file...");
17644
17671
  try {
17645
17672
  await go.mod();
17646
17673
  } catch (err) {
17647
17674
  console.error("failed to `go mod tidy`");
17648
17675
  throw err;
17649
17676
  }
17650
- (0, import_build_utils2.debug)("Running `go build`...");
17677
+ (0, import_build_utils3.debug)("Running `go build`...");
17651
17678
  const destPath = (0, import_path2.join)(outDir, HANDLER_FILENAME);
17652
17679
  try {
17653
17680
  const src = [(0, import_path2.join)(baseGoModPath, MAIN_GO_FILENAME)];
@@ -17665,7 +17692,7 @@ async function buildHandlerAsPackageMain({
17665
17692
  outDir,
17666
17693
  undo
17667
17694
  }) {
17668
- (0, import_build_utils2.debug)('Building Go handler as package "main" (legacy)');
17695
+ (0, import_build_utils3.debug)('Building Go handler as package "main" (legacy)');
17669
17696
  await writeEntrypoint(
17670
17697
  (0, import_path2.join)(entrypointDirname, MAIN_GO_FILENAME),
17671
17698
  "",
@@ -17676,14 +17703,14 @@ async function buildHandlerAsPackageMain({
17676
17703
  // delete
17677
17704
  from: (0, import_path2.join)(entrypointDirname, MAIN_GO_FILENAME)
17678
17705
  });
17679
- (0, import_build_utils2.debug)("Running `go get`...");
17706
+ (0, import_build_utils3.debug)("Running `go get`...");
17680
17707
  try {
17681
17708
  await go.get();
17682
17709
  } catch (err) {
17683
17710
  console.error("Failed to `go get`");
17684
17711
  throw err;
17685
17712
  }
17686
- (0, import_build_utils2.debug)("Running `go build`...");
17713
+ (0, import_build_utils3.debug)("Running `go build`...");
17687
17714
  const destPath = (0, import_path2.join)(outDir, HANDLER_FILENAME);
17688
17715
  try {
17689
17716
  const src = [
@@ -17713,10 +17740,10 @@ function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
17713
17740
  "Handler function renaming failed because entrypoint was empty."
17714
17741
  );
17715
17742
  }
17716
- (0, import_build_utils2.debug)(`Found exported function "${originalFunctionName}" in "${entrypoint}"`);
17743
+ (0, import_build_utils3.debug)(`Found exported function "${originalFunctionName}" in "${entrypoint}"`);
17717
17744
  const pathSlug = entrypoint.replace(/(\s|\\|\/|\]|\[|-|\.)/g, "_");
17718
17745
  const newHandlerName = `${originalFunctionName}_${pathSlug}`;
17719
- (0, import_build_utils2.debug)(
17746
+ (0, import_build_utils3.debug)(
17720
17747
  `Renaming handler function temporarily from "${originalFunctionName}" to "${newHandlerName}"`
17721
17748
  );
17722
17749
  return newHandlerName;
@@ -17754,7 +17781,7 @@ async function findGoModPath(entrypointDir, workPath) {
17754
17781
  const goMod = (0, import_path2.join)(dir, "go.mod");
17755
17782
  if (await (0, import_fs_extra2.pathExists)(goMod)) {
17756
17783
  goModPath = goMod;
17757
- (0, import_build_utils2.debug)(`Found ${goModPath}"`);
17784
+ (0, import_build_utils3.debug)(`Found ${goModPath}"`);
17758
17785
  break;
17759
17786
  }
17760
17787
  dir = (0, import_path2.dirname)(dir);
@@ -17830,7 +17857,7 @@ async function writeGoMod({
17830
17857
  }
17831
17858
  }
17832
17859
  const destGoModPath = (0, import_path2.join)(destDir, "go.mod");
17833
- (0, import_build_utils2.debug)(`Writing ${destGoModPath}`);
17860
+ (0, import_build_utils3.debug)(`Writing ${destGoModPath}`);
17834
17861
  await (0, import_fs_extra2.writeFile)(destGoModPath, contents, "utf-8");
17835
17862
  }
17836
17863
  async function findGoWorkFile(goWorkDir, workPath) {
@@ -17935,7 +17962,7 @@ async function startDevServer(opts) {
17935
17962
  TMP,
17936
17963
  `vercel-dev-port-${Math.random().toString(32).substring(2)}`
17937
17964
  );
17938
- const env = (0, import_build_utils2.cloneEnv)(process.env, meta.env, {
17965
+ const env = (0, import_build_utils3.cloneEnv)(process.env, meta.env, {
17939
17966
  VERCEL_DEV_PORT_FILE: portFile
17940
17967
  });
17941
17968
  const executable = `./vercel-dev-server-go${process.platform === "win32" ? ".exe" : ""}`;
@@ -17948,7 +17975,7 @@ async function startDevServer(opts) {
17948
17975
  workPath
17949
17976
  });
17950
17977
  await go.build("./...", executable);
17951
- (0, import_build_utils2.debug)(`SPAWNING ${executable} CWD=${tmp}`);
17978
+ (0, import_build_utils3.debug)(`SPAWNING ${executable} CWD=${tmp}`);
17952
17979
  const child = (0, import_child_process.spawn)(executable, [], {
17953
17980
  cwd: tmp,
17954
17981
  env,
@@ -18020,11 +18047,11 @@ async function prepareCache({
18020
18047
  const stat = await (0, import_fs_extra2.lstat)(goCacheDir);
18021
18048
  if (stat.isSymbolicLink()) {
18022
18049
  const goGlobalCacheDir = await (0, import_fs_extra2.readlink)(goCacheDir);
18023
- (0, import_build_utils2.debug)(`Preparing cache by moving ${goGlobalCacheDir} -> ${goCacheDir}`);
18050
+ (0, import_build_utils3.debug)(`Preparing cache by moving ${goGlobalCacheDir} -> ${goCacheDir}`);
18024
18051
  await (0, import_fs_extra2.unlink)(goCacheDir);
18025
18052
  await (0, import_fs_extra2.move)(goGlobalCacheDir, goCacheDir);
18026
18053
  }
18027
- const cache = await (0, import_build_utils2.glob)(`${localCacheDir}/**`, workPath);
18054
+ const cache = await (0, import_build_utils3.glob)(`${localCacheDir}/**`, workPath);
18028
18055
  return cache;
18029
18056
  }
18030
18057
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "3.2.4",
3
+ "version": "3.3.0",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -33,7 +33,7 @@
33
33
  "typescript": "4.3.4",
34
34
  "xdg-app-paths": "5.1.0",
35
35
  "yauzl-promise": "2.1.3",
36
- "@vercel/build-utils": "13.2.3"
36
+ "@vercel/build-utils": "13.2.4"
37
37
  },
38
38
  "scripts": {
39
39
  "build": "node ../../utils/build-builder.mjs",