@vercel/go 2.0.15 → 2.0.16
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 +38 -5
- package/package.json +14 -3
package/dist/index.js
CHANGED
|
@@ -17689,7 +17689,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
17689
17689
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
17690
17690
|
};
|
|
17691
17691
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
17692
|
-
exports.prepareCache = exports.startDevServer = exports.build = exports.version = exports.shouldServe = void 0;
|
|
17692
|
+
exports.prepareCache = exports.startDevServer = exports.getNewHandlerFunctionName = exports.build = exports.version = exports.shouldServe = void 0;
|
|
17693
17693
|
const execa_1 = __importDefault(__webpack_require__(580));
|
|
17694
17694
|
const async_retry_1 = __importDefault(__webpack_require__(8571));
|
|
17695
17695
|
const os_1 = __webpack_require__(2087);
|
|
@@ -17740,6 +17740,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
|
|
|
17740
17740
|
// in order to undo the action, not what the original action was
|
|
17741
17741
|
const undoFileActions = [];
|
|
17742
17742
|
const undoDirectoryCreation = [];
|
|
17743
|
+
const undoFunctionRenames = [];
|
|
17743
17744
|
try {
|
|
17744
17745
|
if (process.env.GIT_CREDENTIALS) {
|
|
17745
17746
|
build_utils_1.debug('Initialize Git credentials...');
|
|
@@ -17756,6 +17757,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
|
|
|
17756
17757
|
Learn more: https://github.com/golang/go/wiki/Modules
|
|
17757
17758
|
`);
|
|
17758
17759
|
}
|
|
17760
|
+
const originalEntrypointAbsolute = path_1.join(workPath, entrypoint);
|
|
17759
17761
|
const renamedEntrypoint = getRenamedEntrypoint(entrypoint);
|
|
17760
17762
|
if (renamedEntrypoint) {
|
|
17761
17763
|
await fs_extra_1.move(path_1.join(workPath, entrypoint), path_1.join(workPath, renamedEntrypoint));
|
|
@@ -17853,8 +17855,14 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
|
|
|
17853
17855
|
}
|
|
17854
17856
|
}
|
|
17855
17857
|
}
|
|
17856
|
-
const
|
|
17857
|
-
|
|
17858
|
+
const originalFunctionName = parsedAnalyzed.functionName;
|
|
17859
|
+
const handlerFunctionName = getNewHandlerFunctionName(originalFunctionName, entrypoint);
|
|
17860
|
+
await renameHandlerFunction(entrypointAbsolute, originalFunctionName, handlerFunctionName);
|
|
17861
|
+
undoFunctionRenames.push({
|
|
17862
|
+
fsPath: originalEntrypointAbsolute,
|
|
17863
|
+
from: handlerFunctionName,
|
|
17864
|
+
to: originalFunctionName,
|
|
17865
|
+
});
|
|
17858
17866
|
if (!isGoModExist) {
|
|
17859
17867
|
if (await fs_extra_1.pathExists(path_1.join(workPath, 'vendor'))) {
|
|
17860
17868
|
throw new Error('`go.mod` is required to use a `vendor` directory.');
|
|
@@ -18053,7 +18061,7 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
|
|
|
18053
18061
|
}
|
|
18054
18062
|
finally {
|
|
18055
18063
|
try {
|
|
18056
|
-
await cleanupFileSystem(undoFileActions, undoDirectoryCreation);
|
|
18064
|
+
await cleanupFileSystem(undoFileActions, undoDirectoryCreation, undoFunctionRenames);
|
|
18057
18065
|
}
|
|
18058
18066
|
catch (error) {
|
|
18059
18067
|
console.log(`Build cleanup failed: ${error.message}`);
|
|
@@ -18062,7 +18070,27 @@ async function build({ files, entrypoint, config, workPath, meta = {}, }) {
|
|
|
18062
18070
|
}
|
|
18063
18071
|
}
|
|
18064
18072
|
exports.build = build;
|
|
18065
|
-
async function
|
|
18073
|
+
async function renameHandlerFunction(fsPath, from, to) {
|
|
18074
|
+
let fileContents = await fs_extra_1.readFile(fsPath, 'utf8');
|
|
18075
|
+
const fromRegex = new RegExp(`\\b${from}\\b`, 'g');
|
|
18076
|
+
fileContents = fileContents.replace(fromRegex, to);
|
|
18077
|
+
await fs_extra_1.writeFile(fsPath, fileContents);
|
|
18078
|
+
}
|
|
18079
|
+
function getNewHandlerFunctionName(originalFunctionName, entrypoint) {
|
|
18080
|
+
if (!originalFunctionName) {
|
|
18081
|
+
throw new Error('Handler function renaming failed because original function name was empty.');
|
|
18082
|
+
}
|
|
18083
|
+
if (!entrypoint) {
|
|
18084
|
+
throw new Error('Handler function renaming failed because entrypoint was empty.');
|
|
18085
|
+
}
|
|
18086
|
+
build_utils_1.debug(`Found exported function "${originalFunctionName}" in "${entrypoint}"`);
|
|
18087
|
+
const pathSlug = entrypoint.replace(/(\s|\\|\/|\]|\[|-|\.)/g, '_');
|
|
18088
|
+
const newHandlerName = `${originalFunctionName}_${pathSlug}`;
|
|
18089
|
+
build_utils_1.debug(`Renaming handler function temporarily from "${originalFunctionName}" to "${newHandlerName}"`);
|
|
18090
|
+
return newHandlerName;
|
|
18091
|
+
}
|
|
18092
|
+
exports.getNewHandlerFunctionName = getNewHandlerFunctionName;
|
|
18093
|
+
async function cleanupFileSystem(undoFileActions, undoDirectoryCreation, undoFunctionRenames) {
|
|
18066
18094
|
// we have to undo the actions in reverse order in cases
|
|
18067
18095
|
// where one file was moved multiple times, which happens
|
|
18068
18096
|
// using files that start with brackets
|
|
@@ -18074,6 +18102,11 @@ async function cleanupFileSystem(undoFileActions, undoDirectoryCreation) {
|
|
|
18074
18102
|
await fs_extra_1.remove(action.from);
|
|
18075
18103
|
}
|
|
18076
18104
|
}
|
|
18105
|
+
// after files are moved back, we can undo function renames
|
|
18106
|
+
// these reference the original file location
|
|
18107
|
+
for (const rename of undoFunctionRenames) {
|
|
18108
|
+
await renameHandlerFunction(rename.fsPath, rename.from, rename.to);
|
|
18109
|
+
}
|
|
18077
18110
|
const undoDirectoryPromises = undoDirectoryCreation.map(async (directory) => {
|
|
18078
18111
|
const contents = await fs_extra_1.readdir(directory);
|
|
18079
18112
|
// only delete an empty directory
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/go",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index",
|
|
6
6
|
"homepage": "https://vercel.com/docs/runtimes#official-runtimes/go",
|
|
@@ -17,14 +17,25 @@
|
|
|
17
17
|
"files": [
|
|
18
18
|
"dist"
|
|
19
19
|
],
|
|
20
|
+
"jest": {
|
|
21
|
+
"preset": "ts-jest",
|
|
22
|
+
"testEnvironment": "node",
|
|
23
|
+
"globals": {
|
|
24
|
+
"ts-jest": {
|
|
25
|
+
"diagnostics": true,
|
|
26
|
+
"isolatedModules": true
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
20
30
|
"devDependencies": {
|
|
21
31
|
"@tootallnate/once": "1.1.2",
|
|
22
32
|
"@types/async-retry": "1.4.2",
|
|
23
33
|
"@types/execa": "^0.9.0",
|
|
24
34
|
"@types/fs-extra": "^5.0.5",
|
|
35
|
+
"@types/jest": "28.1.6",
|
|
25
36
|
"@types/node-fetch": "^2.3.0",
|
|
26
37
|
"@types/tar": "^4.0.0",
|
|
27
|
-
"@vercel/build-utils": "5.
|
|
38
|
+
"@vercel/build-utils": "5.3.0",
|
|
28
39
|
"@vercel/ncc": "0.24.0",
|
|
29
40
|
"async-retry": "1.3.1",
|
|
30
41
|
"execa": "^1.0.0",
|
|
@@ -34,5 +45,5 @@
|
|
|
34
45
|
"tar": "4.4.6",
|
|
35
46
|
"typescript": "4.3.4"
|
|
36
47
|
},
|
|
37
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "47e3381c6df661168e8be335cc58df03f3cf2414"
|
|
38
49
|
}
|