@vercel/go 2.1.0 → 2.2.1

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/analyze.go CHANGED
@@ -197,7 +197,9 @@ func main() {
197
197
  // find a valid `http.HandlerFunc` handler function
198
198
  params := rf[fn.Type.Params.Pos()-offset : fn.Type.Params.End()-offset]
199
199
  validHandlerFunc := (strings.Contains(string(params), "http.ResponseWriter") &&
200
- strings.Contains(string(params), "*http.Request") && len(fn.Type.Params.List) == 2)
200
+ strings.Contains(string(params), "*http.Request") &&
201
+ len(fn.Type.Params.List) == 2 &&
202
+ (fn.Recv == nil || len(fn.Recv.List) == 0))
201
203
 
202
204
  if validHandlerFunc {
203
205
  // we found the first exported function with `http.HandlerFunc`
@@ -223,7 +225,7 @@ func main() {
223
225
  if fn.Name.IsExported() == true {
224
226
  for _, param := range fn.Type.Params.List {
225
227
  paramStr := fmt.Sprintf("%s", param.Type)
226
- if strings.Contains(string(paramStr), "http ResponseWriter") && len(fn.Type.Params.List) == 2 {
228
+ if strings.Contains(string(paramStr), "http ResponseWriter") && len(fn.Type.Params.List) == 2 && (fn.Recv == nil || len(fn.Recv.List) == 0) {
227
229
  analyzed := analyze{
228
230
  PackageName: parsed.Name.Name,
229
231
  FuncName: fn.Name.Name,
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,7 +17901,6 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
17898
17901
  throw err;
17899
17902
  }
17900
17903
  }
17901
- const mainModGoFileName = 'main.go';
17902
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}`;
@@ -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) {
@@ -18004,9 +18006,6 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
18004
18006
  const mainGoContents = originalMainGoContents
18005
18007
  .replace('"__VC_HANDLER_PACKAGE_NAME"', '')
18006
18008
  .replace('__VC_HANDLER_FUNC_NAME', handlerFunctionName);
18007
- // in order to allow the user to have `main.go`,
18008
- // we need our `main.go` to be called something else
18009
- const mainGoFileName = 'main__vc__go__.go';
18010
18009
  // Go doesn't like to build files in different directories,
18011
18010
  // so now we place `main.go` together with the user code
18012
18011
  await fs_extra_1.writeFile(path_1.join(entrypointDirname, mainGoFileName), mainGoContents);
@@ -18075,8 +18074,14 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
18075
18074
  exports.build = build;
18076
18075
  async function renameHandlerFunction(fsPath, from, to) {
18077
18076
  let fileContents = await fs_extra_1.readFile(fsPath, 'utf8');
18078
- const fromRegex = new RegExp(`\\b${from}\\b`, 'g');
18079
- fileContents = fileContents.replace(fromRegex, to);
18077
+ // This regex has to walk a fine line where it replaces the most-likely occurrences
18078
+ // of the handler's identifier without clobbering other syntax.
18079
+ // Left-hand Side: A single space was chosen because it can catch `func Handler`
18080
+ // as well as `var _ http.HandlerFunc = Index`.
18081
+ // Right-hand Side: a word boundary was chosen because this can be an end of line
18082
+ // or an open paren (as in `func Handler(`).
18083
+ const fromRegex = new RegExp(String.raw ` ${from}\b`, 'g');
18084
+ fileContents = fileContents.replace(fromRegex, ` ${to}`);
18080
18085
  await fs_extra_1.writeFile(fsPath, fileContents);
18081
18086
  }
18082
18087
  function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/go",
3
- "version": "2.1.0",
3
+ "version": "2.2.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
@@ -35,7 +35,7 @@
35
35
  "@types/jest": "28.1.6",
36
36
  "@types/node-fetch": "^2.3.0",
37
37
  "@types/tar": "^4.0.0",
38
- "@vercel/build-utils": "5.3.0",
38
+ "@vercel/build-utils": "5.3.1",
39
39
  "@vercel/ncc": "0.24.0",
40
40
  "async-retry": "1.3.1",
41
41
  "execa": "^1.0.0",
@@ -45,5 +45,5 @@
45
45
  "tar": "4.4.6",
46
46
  "typescript": "4.3.4"
47
47
  },
48
- "gitHead": "31f79c7de1944420b1f6fa5be9235c9b3f1d62b6"
48
+ "gitHead": "352cd00ef093be6549ddc260803aca1c2ecdc63c"
49
49
  }