@netlify/zip-it-and-ship-it 5.4.0 → 5.5.2
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/README.md +1 -1
- package/dist/archive.js +3 -14
- package/dist/bin.js +13 -35
- package/dist/config.d.ts +1 -0
- package/dist/feature_flags.js +4 -1
- package/dist/main.js +42 -70
- package/dist/manifest.js +4 -13
- package/dist/runtimes/detect_runtime.js +16 -27
- package/dist/runtimes/go/builder.js +5 -14
- package/dist/runtimes/go/index.js +61 -48
- package/dist/runtimes/index.js +34 -37
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +81 -92
- package/dist/runtimes/node/bundlers/esbuild/index.js +14 -18
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +13 -22
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +3 -13
- package/dist/runtimes/node/bundlers/esbuild/special_cases.js +8 -17
- package/dist/runtimes/node/bundlers/esbuild/src_files.js +28 -41
- package/dist/runtimes/node/bundlers/nft/es_modules.js +16 -22
- package/dist/runtimes/node/bundlers/nft/index.js +47 -60
- package/dist/runtimes/node/bundlers/nft/transpile.js +3 -12
- package/dist/runtimes/node/bundlers/zisi/index.js +7 -13
- package/dist/runtimes/node/bundlers/zisi/list_imports.js +5 -14
- package/dist/runtimes/node/bundlers/zisi/published.js +8 -19
- package/dist/runtimes/node/bundlers/zisi/resolve.js +37 -55
- package/dist/runtimes/node/bundlers/zisi/side_files.js +6 -17
- package/dist/runtimes/node/bundlers/zisi/src_files.js +58 -75
- package/dist/runtimes/node/bundlers/zisi/traverse.js +41 -56
- package/dist/runtimes/node/bundlers/zisi/tree_files.js +8 -19
- package/dist/runtimes/node/finder.js +46 -63
- package/dist/runtimes/node/in_source_config/index.js +5 -14
- package/dist/runtimes/node/index.js +64 -87
- package/dist/runtimes/node/parser/index.js +11 -20
- package/dist/runtimes/node/utils/detect_es_module.js +4 -15
- package/dist/runtimes/node/utils/included_files.js +3 -12
- package/dist/runtimes/node/utils/package_json.js +19 -27
- package/dist/runtimes/node/utils/zip.js +63 -94
- package/dist/runtimes/rust/builder.js +23 -36
- package/dist/runtimes/rust/index.js +46 -61
- package/dist/utils/archive_size.js +5 -14
- package/dist/utils/format_result.js +6 -1
- package/dist/utils/fs.d.ts +6 -10
- package/dist/utils/fs.js +35 -63
- package/dist/zip.d.ts +1 -0
- package/dist/zip.js +59 -72
- package/dist/zip_binary.js +5 -16
- package/package.json +8 -15
package/README.md
CHANGED
|
@@ -463,7 +463,7 @@ In Netlify, this is done by ensuring that the following Node.js versions are the
|
|
|
463
463
|
- Build-time Node.js version: this defaults to Node `12`, but can be
|
|
464
464
|
[overridden with a `.nvmrc` or `NODE_VERSION` environment variable](https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript).
|
|
465
465
|
- Function runtime Node.js version: this defaults to `nodejs12.x` but can be
|
|
466
|
-
[
|
|
466
|
+
[overridden with a `AWS_LAMBDA_JS_RUNTIME` environment variable](https://docs.netlify.com/functions/build-with-javascript/#runtime-settings).
|
|
467
467
|
|
|
468
468
|
Note that this problem might not apply for Node.js native modules using the [N-API](https://nodejs.org/api/n-api.html).
|
|
469
469
|
|
package/dist/archive.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -49,11 +40,9 @@ const addZipContent = function (archive, content, name) {
|
|
|
49
40
|
};
|
|
50
41
|
exports.addZipContent = addZipContent;
|
|
51
42
|
// End zipping files
|
|
52
|
-
const endZip = function (archive, output) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
yield pEndOfStream(output);
|
|
56
|
-
});
|
|
43
|
+
const endZip = async function (archive, output) {
|
|
44
|
+
archive.finalize();
|
|
45
|
+
await pEndOfStream(output);
|
|
57
46
|
};
|
|
58
47
|
exports.endZip = endZip;
|
|
59
48
|
//# sourceMappingURL=archive.js.map
|
package/dist/bin.js
CHANGED
|
@@ -1,25 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
13
|
-
var t = {};
|
|
14
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
15
|
-
t[p] = s[p];
|
|
16
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
17
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
18
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
19
|
-
t[p[i]] = s[p[i]];
|
|
20
|
-
}
|
|
21
|
-
return t;
|
|
22
|
-
};
|
|
23
3
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
24
4
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
25
5
|
};
|
|
@@ -28,21 +8,19 @@ const process_1 = require("process");
|
|
|
28
8
|
const yargs_1 = __importDefault(require("yargs"));
|
|
29
9
|
const main_1 = require("./main");
|
|
30
10
|
// CLI entry point
|
|
31
|
-
const runCli = function () {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
});
|
|
11
|
+
const runCli = async function () {
|
|
12
|
+
// @ts-expect-error TODO: `destFolder` and `srcFolder` are not being passed
|
|
13
|
+
// back from `parseArgs()`.
|
|
14
|
+
const { destFolder, srcFolder, ...options } = parseArgs();
|
|
15
|
+
try {
|
|
16
|
+
// @ts-expect-error TODO: `options` is not getting the right types.
|
|
17
|
+
const zipped = await (0, main_1.zipFunctions)(srcFolder, destFolder, options);
|
|
18
|
+
console.log(JSON.stringify(zipped, null, 2));
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
console.error(error.toString());
|
|
22
|
+
(0, process_1.exit)(1);
|
|
23
|
+
}
|
|
46
24
|
};
|
|
47
25
|
const parseArgs = function () {
|
|
48
26
|
return yargs_1.default
|
package/dist/config.d.ts
CHANGED
package/dist/feature_flags.js
CHANGED
|
@@ -11,6 +11,9 @@ const FLAGS = {
|
|
|
11
11
|
};
|
|
12
12
|
exports.defaultFlags = FLAGS;
|
|
13
13
|
// List of supported flags and their default value.
|
|
14
|
-
const getFlags = (input = {}, flags = FLAGS) => Object.entries(flags).reduce((result, [key, defaultValue]) => (
|
|
14
|
+
const getFlags = (input = {}, flags = FLAGS) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
15
|
+
...result,
|
|
16
|
+
[key]: input[key] === undefined ? defaultValue : input[key],
|
|
17
|
+
}), {});
|
|
15
18
|
exports.getFlags = getFlags;
|
|
16
19
|
//# sourceMappingURL=feature_flags.js.map
|
package/dist/main.js
CHANGED
|
@@ -1,24 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
-
var t = {};
|
|
13
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
-
t[p] = s[p];
|
|
15
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
-
t[p[i]] = s[p[i]];
|
|
19
|
-
}
|
|
20
|
-
return t;
|
|
21
|
-
};
|
|
22
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
3
|
exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunction = exports.listFunctions = void 0;
|
|
24
4
|
const path_1 = require("path");
|
|
@@ -26,74 +6,66 @@ const feature_flags_1 = require("./feature_flags");
|
|
|
26
6
|
const runtimes_1 = require("./runtimes");
|
|
27
7
|
const in_source_config_1 = require("./runtimes/node/in_source_config");
|
|
28
8
|
const fs_1 = require("./utils/fs");
|
|
29
|
-
const augmentWithISC = (func) =>
|
|
9
|
+
const augmentWithISC = async (func) => {
|
|
30
10
|
// ISC is currently only supported in JavaScript and TypeScript functions.
|
|
31
11
|
if (func.runtime.name !== 'js') {
|
|
32
12
|
return func;
|
|
33
13
|
}
|
|
34
|
-
const inSourceConfig =
|
|
35
|
-
return
|
|
36
|
-
}
|
|
14
|
+
const inSourceConfig = await (0, in_source_config_1.findISCDeclarationsInPath)(func.mainFile);
|
|
15
|
+
return { ...func, inSourceConfig };
|
|
16
|
+
};
|
|
37
17
|
// List all Netlify Functions main entry files for a specific directory
|
|
38
|
-
const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return augmentedFunctions.map(getListedFunction);
|
|
47
|
-
});
|
|
18
|
+
const listFunctions = async function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
19
|
+
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
20
|
+
const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
|
|
21
|
+
const paths = await (0, fs_1.listFunctionsDirectories)(srcFolders);
|
|
22
|
+
const functionsMap = await (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags, config });
|
|
23
|
+
const functions = [...functionsMap.values()];
|
|
24
|
+
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
25
|
+
return augmentedFunctions.map(getListedFunction);
|
|
48
26
|
};
|
|
49
27
|
exports.listFunctions = listFunctions;
|
|
50
28
|
// Finds a function at a specific path.
|
|
51
|
-
const listFunction = function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return getListedFunction(augmentedFunction);
|
|
60
|
-
});
|
|
29
|
+
const listFunction = async function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
30
|
+
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
31
|
+
const func = await (0, runtimes_1.getFunctionFromPath)(path, { featureFlags, config });
|
|
32
|
+
if (!func) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const augmentedFunction = parseISC ? await augmentWithISC(func) : func;
|
|
36
|
+
return getListedFunction(augmentedFunction);
|
|
61
37
|
};
|
|
62
38
|
exports.listFunction = listFunction;
|
|
63
39
|
// List all Netlify Functions files for a specific directory
|
|
64
|
-
const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags, parseISC = false } = {}) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return listedFunctionsFiles.flat();
|
|
74
|
-
});
|
|
40
|
+
const listFunctionsFiles = async function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags, parseISC = false } = {}) {
|
|
41
|
+
const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
|
|
42
|
+
const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
|
|
43
|
+
const paths = await (0, fs_1.listFunctionsDirectories)(srcFolders);
|
|
44
|
+
const functionsMap = await (0, runtimes_1.getFunctionsFromPaths)(paths, { config, featureFlags });
|
|
45
|
+
const functions = [...functionsMap.values()];
|
|
46
|
+
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
47
|
+
const listedFunctionsFiles = await Promise.all(augmentedFunctions.map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
|
|
48
|
+
return listedFunctionsFiles.flat();
|
|
75
49
|
};
|
|
76
50
|
exports.listFunctionsFiles = listFunctionsFiles;
|
|
77
51
|
const getListedFunction = function ({ runtime, name, mainFile, extension, config, inSourceConfig, }) {
|
|
78
52
|
var _a;
|
|
79
53
|
return { name, mainFile, runtime: runtime.name, extension, schedule: (_a = inSourceConfig === null || inSourceConfig === void 0 ? void 0 : inSourceConfig.schedule) !== null && _a !== void 0 ? _a : config.schedule };
|
|
80
54
|
};
|
|
81
|
-
const getListedFunctionFiles = function (func, options) {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
return srcFiles.map((srcFile) => (Object.assign(Object.assign({}, getListedFunction(func)), { srcFile, extension: (0, path_1.extname)(srcFile) })));
|
|
85
|
-
});
|
|
55
|
+
const getListedFunctionFiles = async function (func, options) {
|
|
56
|
+
const srcFiles = await getSrcFiles({ ...func, ...options });
|
|
57
|
+
return srcFiles.map((srcFile) => ({ ...getListedFunction(func), srcFile, extension: (0, path_1.extname)(srcFile) }));
|
|
86
58
|
};
|
|
87
|
-
const getSrcFiles = function (
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
59
|
+
const getSrcFiles = async function ({ extension, runtime, srcPath, ...args }) {
|
|
60
|
+
const { getSrcFiles: getRuntimeSrcFiles } = runtime;
|
|
61
|
+
if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
|
|
62
|
+
return [srcPath];
|
|
63
|
+
}
|
|
64
|
+
return await getRuntimeSrcFiles({
|
|
65
|
+
extension,
|
|
66
|
+
runtime,
|
|
67
|
+
srcPath,
|
|
68
|
+
...args,
|
|
97
69
|
});
|
|
98
70
|
};
|
|
99
71
|
var zip_1 = require("./zip");
|
package/dist/manifest.js
CHANGED
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.createManifest = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
13
5
|
const path_1 = require("path");
|
|
14
6
|
const process_1 = require("process");
|
|
15
|
-
const fs_1 = require("./utils/fs");
|
|
16
7
|
const MANIFEST_VERSION = 1;
|
|
17
|
-
const createManifest = ({ functions, path }) =>
|
|
8
|
+
const createManifest = async ({ functions, path }) => {
|
|
18
9
|
const formattedFunctions = functions.map(formatFunctionForManifest);
|
|
19
10
|
const payload = {
|
|
20
11
|
functions: formattedFunctions,
|
|
@@ -22,8 +13,8 @@ const createManifest = ({ functions, path }) => __awaiter(void 0, void 0, void 0
|
|
|
22
13
|
timestamp: Date.now(),
|
|
23
14
|
version: MANIFEST_VERSION,
|
|
24
15
|
};
|
|
25
|
-
|
|
26
|
-
}
|
|
16
|
+
await fs_1.promises.writeFile(path, JSON.stringify(payload));
|
|
17
|
+
};
|
|
27
18
|
exports.createManifest = createManifest;
|
|
28
19
|
const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }) => ({
|
|
29
20
|
mainFile,
|
|
@@ -1,37 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.detectBinaryRuntime = void 0;
|
|
13
4
|
const elf_cam_1 = require("elf-cam");
|
|
14
5
|
const fs_1 = require("../utils/fs");
|
|
15
6
|
// Try to guess the runtime by inspecting the binary file.
|
|
16
|
-
const detectBinaryRuntime = function ({ fsCache, path, }) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return undefined;
|
|
31
|
-
}
|
|
7
|
+
const detectBinaryRuntime = async function ({ fsCache, path, }) {
|
|
8
|
+
try {
|
|
9
|
+
const buffer = await (0, fs_1.cachedReadFile)(fsCache, path);
|
|
10
|
+
// We're using the Type Assertion because the `cachedReadFile` abstraction
|
|
11
|
+
// loses part of the return type information. We can safely say it's a
|
|
12
|
+
// Buffer in this case because we're not specifying an encoding.
|
|
13
|
+
const binaryType = (0, elf_cam_1.detect)(buffer);
|
|
14
|
+
switch (binaryType) {
|
|
15
|
+
case elf_cam_1.Runtime.Go:
|
|
16
|
+
return 'go';
|
|
17
|
+
case elf_cam_1.Runtime.Rust:
|
|
18
|
+
return 'rs';
|
|
19
|
+
default:
|
|
20
|
+
return undefined;
|
|
32
21
|
}
|
|
33
|
-
|
|
34
|
-
}
|
|
22
|
+
}
|
|
23
|
+
catch { }
|
|
35
24
|
};
|
|
36
25
|
exports.detectBinaryRuntime = detectBinaryRuntime;
|
|
37
26
|
//# sourceMappingURL=detect_runtime.js.map
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.build = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
13
5
|
const path_1 = require("path");
|
|
14
|
-
const fs_1 = require("../../utils/fs");
|
|
15
6
|
const shell_1 = require("../../utils/shell");
|
|
16
|
-
const build = ({ destPath, mainFile, srcDir }) =>
|
|
7
|
+
const build = async ({ destPath, mainFile, srcDir }) => {
|
|
17
8
|
const functionName = (0, path_1.basename)(srcDir);
|
|
18
9
|
try {
|
|
19
|
-
|
|
10
|
+
await (0, shell_1.runCommand)('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
|
|
20
11
|
cwd: srcDir,
|
|
21
12
|
env: {
|
|
22
13
|
CGO_ENABLED: '0',
|
|
@@ -30,7 +21,7 @@ const build = ({ destPath, mainFile, srcDir }) => __awaiter(void 0, void 0, void
|
|
|
30
21
|
console.error(`Could not compile Go function ${functionName}:\n`);
|
|
31
22
|
throw error;
|
|
32
23
|
}
|
|
33
|
-
const stat =
|
|
24
|
+
const stat = await fs_1.promises.lstat(destPath);
|
|
34
25
|
return {
|
|
35
26
|
mainFile,
|
|
36
27
|
name: functionName,
|
|
@@ -38,6 +29,6 @@ const build = ({ destPath, mainFile, srcDir }) => __awaiter(void 0, void 0, void
|
|
|
38
29
|
srcPath: destPath,
|
|
39
30
|
stat,
|
|
40
31
|
};
|
|
41
|
-
}
|
|
32
|
+
};
|
|
42
33
|
exports.build = build;
|
|
43
34
|
//# sourceMappingURL=builder.js.map
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,46 +7,43 @@ const path_1 = require("path");
|
|
|
16
7
|
const cp_file_1 = __importDefault(require("cp-file"));
|
|
17
8
|
const fs_1 = require("../../utils/fs");
|
|
18
9
|
const non_nullable_1 = require("../../utils/non_nullable");
|
|
10
|
+
const zip_binary_1 = require("../../zip_binary");
|
|
19
11
|
const detect_runtime_1 = require("../detect_runtime");
|
|
20
12
|
const builder_1 = require("./builder");
|
|
21
|
-
const detectGoFunction = ({ fsCache, path }) =>
|
|
22
|
-
const stat =
|
|
13
|
+
const detectGoFunction = async ({ fsCache, path }) => {
|
|
14
|
+
const stat = await (0, fs_1.cachedLstat)(fsCache, path);
|
|
23
15
|
if (!stat.isDirectory()) {
|
|
24
16
|
return;
|
|
25
17
|
}
|
|
26
18
|
const directoryName = (0, path_1.basename)(path);
|
|
27
19
|
// @ts-expect-error TODO: The `makeCachedFunction` abstraction is causing the
|
|
28
20
|
// return value of `readdir` to be incorrectly typed.
|
|
29
|
-
const files = (
|
|
21
|
+
const files = (await (0, fs_1.cachedReaddir)(fsCache, path));
|
|
30
22
|
const mainFileName = [`${directoryName}.go`, 'main.go'].find((name) => files.includes(name));
|
|
31
23
|
if (mainFileName === undefined) {
|
|
32
24
|
return;
|
|
33
25
|
}
|
|
34
26
|
return mainFileName;
|
|
35
|
-
});
|
|
36
|
-
const findFunctionsInPaths = function ({ featureFlags, fsCache, paths }) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
const functions = yield Promise.all(paths.map((path) => findFunctionInPath({ featureFlags, fsCache, path })));
|
|
39
|
-
return functions.filter(non_nullable_1.nonNullable);
|
|
40
|
-
});
|
|
41
27
|
};
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (runtime === 'go') {
|
|
46
|
-
return processBinary({ fsCache, path });
|
|
47
|
-
}
|
|
48
|
-
if (featureFlags.buildGoSource !== true) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
const goSourceFile = yield detectGoFunction({ fsCache, path });
|
|
52
|
-
if (goSourceFile) {
|
|
53
|
-
return processSource({ fsCache, mainFile: goSourceFile, path });
|
|
54
|
-
}
|
|
55
|
-
});
|
|
28
|
+
const findFunctionsInPaths = async function ({ featureFlags, fsCache, paths }) {
|
|
29
|
+
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ featureFlags, fsCache, path })));
|
|
30
|
+
return functions.filter(non_nullable_1.nonNullable);
|
|
56
31
|
};
|
|
57
|
-
const
|
|
58
|
-
const
|
|
32
|
+
const findFunctionInPath = async function ({ featureFlags, fsCache, path }) {
|
|
33
|
+
const runtime = await (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
|
|
34
|
+
if (runtime === 'go') {
|
|
35
|
+
return processBinary({ fsCache, path });
|
|
36
|
+
}
|
|
37
|
+
if (featureFlags.buildGoSource !== true) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const goSourceFile = await detectGoFunction({ fsCache, path });
|
|
41
|
+
if (goSourceFile) {
|
|
42
|
+
return processSource({ fsCache, mainFile: goSourceFile, path });
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
const processBinary = async ({ fsCache, path }) => {
|
|
46
|
+
const stat = (await (0, fs_1.cachedLstat)(fsCache, path));
|
|
59
47
|
const extension = (0, path_1.extname)(path);
|
|
60
48
|
const filename = (0, path_1.basename)(path);
|
|
61
49
|
const name = (0, path_1.basename)(path, (0, path_1.extname)(path));
|
|
@@ -68,13 +56,13 @@ const processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, f
|
|
|
68
56
|
srcPath: path,
|
|
69
57
|
stat,
|
|
70
58
|
};
|
|
71
|
-
}
|
|
72
|
-
const processSource = ({ fsCache, mainFile, path, }) =>
|
|
59
|
+
};
|
|
60
|
+
const processSource = async ({ fsCache, mainFile, path, }) => {
|
|
73
61
|
// TODO: This `stat` value is not going to be used, but we need it to satisfy
|
|
74
62
|
// the `FunctionSource` interface. We should revisit whether `stat` should be
|
|
75
63
|
// part of that interface in the first place, or whether we could compute it
|
|
76
64
|
// downstream when needed (maybe using the FS cache as an optimisation).
|
|
77
|
-
const stat = (
|
|
65
|
+
const stat = (await (0, fs_1.cachedLstat)(fsCache, path));
|
|
78
66
|
const filename = (0, path_1.basename)(path);
|
|
79
67
|
const extension = (0, path_1.extname)(mainFile);
|
|
80
68
|
const name = (0, path_1.basename)(path, (0, path_1.extname)(path));
|
|
@@ -87,17 +75,42 @@ const processSource = ({ fsCache, mainFile, path, }) => __awaiter(void 0, void 0
|
|
|
87
75
|
srcPath: path,
|
|
88
76
|
stat,
|
|
89
77
|
};
|
|
90
|
-
}
|
|
91
|
-
const zipFunction = function ({ config, destFolder, filename, mainFile, srcDir, srcPath }) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
78
|
+
};
|
|
79
|
+
const zipFunction = async function ({ config, destFolder, filename, mainFile, srcDir, srcPath, stat }) {
|
|
80
|
+
const destPath = (0, path_1.join)(destFolder, filename);
|
|
81
|
+
const isSource = (0, path_1.extname)(mainFile) === '.go';
|
|
82
|
+
let binary = {
|
|
83
|
+
path: srcPath,
|
|
84
|
+
stat,
|
|
85
|
+
};
|
|
86
|
+
// If we're building a Go function from source, we call the build method and
|
|
87
|
+
// update `binary` to point to the newly-created binary.
|
|
88
|
+
if (isSource) {
|
|
89
|
+
const { stat: binaryStat } = await (0, builder_1.build)({ destPath, mainFile, srcDir });
|
|
90
|
+
binary = {
|
|
91
|
+
path: destPath,
|
|
92
|
+
stat: binaryStat,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
// If `zipGo` is enabled, we create a zip archive with the Go binary and the
|
|
96
|
+
// toolchain file.
|
|
97
|
+
if (config.zipGo) {
|
|
98
|
+
const zipPath = `${destPath}.zip`;
|
|
99
|
+
const zipOptions = {
|
|
100
|
+
destPath: zipPath,
|
|
101
|
+
filename: (0, path_1.basename)(destPath),
|
|
102
|
+
runtime,
|
|
103
|
+
};
|
|
104
|
+
await (0, zip_binary_1.zipBinary)({ ...zipOptions, srcPath: binary.path, stat: binary.stat });
|
|
105
|
+
return { config, path: zipPath };
|
|
106
|
+
}
|
|
107
|
+
// We don't need to zip the binary, so we can just copy it to the right path.
|
|
108
|
+
// We do this only if we're not building from source, as otherwise the build
|
|
109
|
+
// step already handled that.
|
|
110
|
+
if (!isSource) {
|
|
111
|
+
await (0, cp_file_1.default)(binary.path, destPath);
|
|
112
|
+
}
|
|
113
|
+
return { config, path: destPath };
|
|
101
114
|
};
|
|
102
115
|
const runtime = { findFunctionsInPaths, findFunctionInPath, name: 'go', zipFunction };
|
|
103
116
|
exports.default = runtime;
|