@vercel/go 2.1.1 → 2.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.
package/dist/index.js CHANGED
@@ -17875,6 +17875,9 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
17875
17875
  throw new Error('Please change `package main` to `package handler`');
17876
17876
  }
17877
17877
  const outDir = await build_utils_1.getWriteableDirectory();
17878
+ // in order to allow the user to have `main.go`,
17879
+ // we need our `main.go` to be called something else
17880
+ const mainGoFileName = 'main__vc__go__.go';
17878
17881
  if (packageName !== 'main') {
17879
17882
  const go = await go_helpers_1.createGo(workPath, goPath, process.platform, process.arch, {
17880
17883
  cwd: entrypointDirname,
@@ -17898,8 +17901,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
17898
17901
  throw err;
17899
17902
  }
17900
17903
  }
17901
- const mainModGoFileName = 'main__mod__.go';
17902
- const modMainGoContents = await fs_extra_1.readFile(__webpack_require__.ab + "main__mod__.go", 'utf8');
17904
+ const modMainGoContents = await fs_extra_1.readFile(__webpack_require__.ab + "main.go", 'utf8');
17903
17905
  let goPackageName = `${packageName}/${packageName}`;
17904
17906
  const goFuncName = `${packageName}.${handlerFunctionName}`;
17905
17907
  if (isGoModExist) {
@@ -17919,26 +17921,26 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
17919
17921
  .replace('__VC_HANDLER_FUNC_NAME', goFuncName);
17920
17922
  if (isGoModExist && isGoModInRootDir) {
17921
17923
  build_utils_1.debug('[mod-root] Write main file to ' + downloadPath);
17922
- await fs_extra_1.writeFile(path_1.join(downloadPath, mainModGoFileName), mainModGoContents);
17924
+ await fs_extra_1.writeFile(path_1.join(downloadPath, mainGoFileName), mainModGoContents);
17923
17925
  undoFileActions.push({
17924
17926
  to: undefined,
17925
- from: path_1.join(downloadPath, mainModGoFileName),
17927
+ from: path_1.join(downloadPath, mainGoFileName),
17926
17928
  });
17927
17929
  }
17928
17930
  else if (isGoModExist && !isGoModInRootDir) {
17929
17931
  build_utils_1.debug('[mod-other] Write main file to ' + goModPath);
17930
- await fs_extra_1.writeFile(path_1.join(goModPath, mainModGoFileName), mainModGoContents);
17932
+ await fs_extra_1.writeFile(path_1.join(goModPath, mainGoFileName), mainModGoContents);
17931
17933
  undoFileActions.push({
17932
17934
  to: undefined,
17933
- from: path_1.join(goModPath, mainModGoFileName),
17935
+ from: path_1.join(goModPath, mainGoFileName),
17934
17936
  });
17935
17937
  }
17936
17938
  else {
17937
17939
  build_utils_1.debug('[entrypoint] Write main file to ' + entrypointDirname);
17938
- await fs_extra_1.writeFile(path_1.join(entrypointDirname, mainModGoFileName), mainModGoContents);
17940
+ await fs_extra_1.writeFile(path_1.join(entrypointDirname, mainGoFileName), mainModGoContents);
17939
17941
  undoFileActions.push({
17940
17942
  to: undefined,
17941
- from: path_1.join(entrypointDirname, mainModGoFileName),
17943
+ from: path_1.join(entrypointDirname, mainGoFileName),
17942
17944
  });
17943
17945
  }
17944
17946
  // move user go file to folder
@@ -17985,7 +17987,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
17985
17987
  build_utils_1.debug('Running `go build`...');
17986
17988
  const destPath = path_1.join(outDir, handlerFileName);
17987
17989
  try {
17988
- const src = [path_1.join(baseGoModPath, mainModGoFileName)];
17990
+ const src = [path_1.join(baseGoModPath, mainGoFileName)];
17989
17991
  await go.build(src, destPath);
17990
17992
  }
17991
17993
  catch (err) {
@@ -18000,11 +18002,10 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
18000
18002
  const go = await go_helpers_1.createGo(workPath, goPath, process.platform, process.arch, {
18001
18003
  cwd: entrypointDirname,
18002
18004
  }, false);
18003
- const origianlMainGoContents = await fs_extra_1.readFile(__webpack_require__.ab + "main.go", 'utf8');
18004
- const mainGoContents = origianlMainGoContents.replace('__VC_HANDLER_FUNC_NAME', handlerFunctionName);
18005
- // in order to allow the user to have `main.go`,
18006
- // we need our `main.go` to be called something else
18007
- const mainGoFileName = 'main__vc__go__.go';
18005
+ const originalMainGoContents = await fs_extra_1.readFile(__webpack_require__.ab + "main.go", 'utf8');
18006
+ const mainGoContents = originalMainGoContents
18007
+ .replace('"__VC_HANDLER_PACKAGE_NAME"', '')
18008
+ .replace('__VC_HANDLER_FUNC_NAME', handlerFunctionName);
18008
18009
  // Go doesn't like to build files in different directories,
18009
18010
  // so now we place `main.go` together with the user code
18010
18011
  await fs_extra_1.writeFile(path_1.join(entrypointDirname, mainGoFileName), mainGoContents);
@@ -18040,6 +18041,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
18040
18041
  files: { ...(await build_utils_1.glob('**', outDir)), ...includedFiles },
18041
18042
  handler: handlerFileName,
18042
18043
  runtime: 'go1.x',
18044
+ supportsWrapper: true,
18043
18045
  environment: {},
18044
18046
  });
18045
18047
  const watch = parsedAnalyzed.watch;
package/dist/main.go CHANGED
@@ -1,10 +1,31 @@
1
1
  package main
2
2
 
3
3
  import (
4
- vc "github.com/vercel/go-bridge/go/bridge"
5
4
  "net/http"
5
+ "os"
6
+ "syscall"
7
+
8
+ "__VC_HANDLER_PACKAGE_NAME"
9
+ vc "github.com/vercel/go-bridge/go/bridge"
6
10
  )
7
11
 
12
+ func checkForLambdaWrapper() {
13
+ wrapper := os.Getenv("AWS_LAMBDA_EXEC_WRAPPER")
14
+ if wrapper == "" {
15
+ return
16
+ }
17
+
18
+ // Removing the env var doesn't work
19
+ // Set it to empty string to override the previous value
20
+ os.Setenv("AWS_LAMBDA_EXEC_WRAPPER", "")
21
+ argv := append([]string{wrapper}, os.Args...)
22
+ err := syscall.Exec(wrapper, argv, os.Environ())
23
+ if err != nil {
24
+ panic(err)
25
+ }
26
+ }
27
+
8
28
  func main() {
29
+ checkForLambdaWrapper()
9
30
  vc.Start(http.HandlerFunc(__VC_HANDLER_FUNC_NAME))
10
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -45,5 +45,5 @@
45
45
  "tar": "4.4.6",
46
46
  "typescript": "4.3.4"
47
47
  },
48
- "gitHead": "b52d01f809b80734ed1ab61df82f299f11a04720"
48
+ "gitHead": "09c85f63d2aa47c147260d343767f6eea60e352c"
49
49
  }
@@ -1,12 +0,0 @@
1
- package main
2
-
3
- import (
4
- "__VC_HANDLER_PACKAGE_NAME"
5
- "net/http"
6
-
7
- vc "github.com/vercel/go-bridge/go/bridge"
8
- )
9
-
10
- func main() {
11
- vc.Start(http.HandlerFunc(__VC_HANDLER_FUNC_NAME))
12
- }