@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.
Files changed (46) hide show
  1. package/README.md +1 -1
  2. package/dist/archive.js +3 -14
  3. package/dist/bin.js +13 -35
  4. package/dist/config.d.ts +1 -0
  5. package/dist/feature_flags.js +4 -1
  6. package/dist/main.js +42 -70
  7. package/dist/manifest.js +4 -13
  8. package/dist/runtimes/detect_runtime.js +16 -27
  9. package/dist/runtimes/go/builder.js +5 -14
  10. package/dist/runtimes/go/index.js +61 -48
  11. package/dist/runtimes/index.js +34 -37
  12. package/dist/runtimes/node/bundlers/esbuild/bundler.js +81 -92
  13. package/dist/runtimes/node/bundlers/esbuild/index.js +14 -18
  14. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +13 -22
  15. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +3 -13
  16. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +8 -17
  17. package/dist/runtimes/node/bundlers/esbuild/src_files.js +28 -41
  18. package/dist/runtimes/node/bundlers/nft/es_modules.js +16 -22
  19. package/dist/runtimes/node/bundlers/nft/index.js +47 -60
  20. package/dist/runtimes/node/bundlers/nft/transpile.js +3 -12
  21. package/dist/runtimes/node/bundlers/zisi/index.js +7 -13
  22. package/dist/runtimes/node/bundlers/zisi/list_imports.js +5 -14
  23. package/dist/runtimes/node/bundlers/zisi/published.js +8 -19
  24. package/dist/runtimes/node/bundlers/zisi/resolve.js +37 -55
  25. package/dist/runtimes/node/bundlers/zisi/side_files.js +6 -17
  26. package/dist/runtimes/node/bundlers/zisi/src_files.js +58 -75
  27. package/dist/runtimes/node/bundlers/zisi/traverse.js +41 -56
  28. package/dist/runtimes/node/bundlers/zisi/tree_files.js +8 -19
  29. package/dist/runtimes/node/finder.js +46 -63
  30. package/dist/runtimes/node/in_source_config/index.js +5 -14
  31. package/dist/runtimes/node/index.js +64 -87
  32. package/dist/runtimes/node/parser/index.js +11 -20
  33. package/dist/runtimes/node/utils/detect_es_module.js +4 -15
  34. package/dist/runtimes/node/utils/included_files.js +3 -12
  35. package/dist/runtimes/node/utils/package_json.js +19 -27
  36. package/dist/runtimes/node/utils/zip.js +63 -94
  37. package/dist/runtimes/rust/builder.js +23 -36
  38. package/dist/runtimes/rust/index.js +46 -61
  39. package/dist/utils/archive_size.js +5 -14
  40. package/dist/utils/format_result.js +6 -1
  41. package/dist/utils/fs.d.ts +6 -10
  42. package/dist/utils/fs.js +35 -63
  43. package/dist/zip.d.ts +1 -0
  44. package/dist/zip.js +59 -72
  45. package/dist/zip_binary.js +5 -16
  46. 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
- [overriden with a `AWS_LAMBDA_JS_RUNTIME` environment variable](https://docs.netlify.com/functions/build-with-javascript/#runtime-settings).
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
- return __awaiter(this, void 0, void 0, function* () {
54
- archive.finalize();
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
- return __awaiter(this, void 0, void 0, function* () {
33
- // @ts-expect-error TODO: `destFolder` and `srcFolder` are not being passed
34
- // back from `parseArgs()`.
35
- const _a = parseArgs(), { destFolder, srcFolder } = _a, options = __rest(_a, ["destFolder", "srcFolder"]);
36
- try {
37
- // @ts-expect-error TODO: `options` is not getting the right types.
38
- const zipped = yield (0, main_1.zipFunctions)(srcFolder, destFolder, options);
39
- console.log(JSON.stringify(zipped, null, 2));
40
- }
41
- catch (error) {
42
- console.error(error.toString());
43
- (0, process_1.exit)(1);
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
@@ -13,6 +13,7 @@ interface FunctionConfig {
13
13
  processDynamicNodeImports?: boolean;
14
14
  rustTargetDirectory?: string;
15
15
  schedule?: string;
16
+ zipGo?: boolean;
16
17
  }
17
18
  declare type GlobPattern = string;
18
19
  declare type Config = Record<GlobPattern, FunctionConfig>;
@@ -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]) => (Object.assign(Object.assign({}, result), { [key]: input[key] === undefined ? defaultValue : input[key] })), {});
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) => __awaiter(void 0, void 0, void 0, function* () {
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 = yield (0, in_source_config_1.findISCDeclarationsInPath)(func.mainFile);
35
- return Object.assign(Object.assign({}, func), { inSourceConfig });
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
- return __awaiter(this, void 0, void 0, function* () {
40
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
41
- const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
42
- const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
43
- const functionsMap = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags, config });
44
- const functions = [...functionsMap.values()];
45
- const augmentedFunctions = parseISC ? yield Promise.all(functions.map(augmentWithISC)) : functions;
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
- return __awaiter(this, void 0, void 0, function* () {
53
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
54
- const func = yield (0, runtimes_1.getFunctionFromPath)(path, { featureFlags, config });
55
- if (!func) {
56
- return;
57
- }
58
- const augmentedFunction = parseISC ? yield augmentWithISC(func) : func;
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
- return __awaiter(this, void 0, void 0, function* () {
66
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
67
- const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
68
- const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
69
- const functionsMap = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { config, featureFlags });
70
- const functions = [...functionsMap.values()];
71
- const augmentedFunctions = parseISC ? yield Promise.all(functions.map(augmentWithISC)) : functions;
72
- const listedFunctionsFiles = yield Promise.all(augmentedFunctions.map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
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
- return __awaiter(this, void 0, void 0, function* () {
83
- const srcFiles = yield getSrcFiles(Object.assign(Object.assign({}, func), options));
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 (_a) {
88
- var { extension, runtime, srcPath } = _a, args = __rest(_a, ["extension", "runtime", "srcPath"]);
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const { getSrcFiles: getRuntimeSrcFiles } = runtime;
91
- if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
92
- return [srcPath];
93
- }
94
- return yield getRuntimeSrcFiles(Object.assign({ extension,
95
- runtime,
96
- srcPath }, args));
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 }) => __awaiter(void 0, void 0, void 0, function* () {
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
- yield (0, fs_1.writeFile)(path, JSON.stringify(payload));
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
- return __awaiter(this, void 0, void 0, function* () {
18
- try {
19
- const buffer = yield (0, fs_1.cachedReadFile)(fsCache, path);
20
- // We're using the Type Assertion because the `cachedReadFile` abstraction
21
- // loses part of the return type information. We can safely say it's a
22
- // Buffer in this case because we're not specifying an encoding.
23
- const binaryType = (0, elf_cam_1.detect)(buffer);
24
- switch (binaryType) {
25
- case elf_cam_1.Runtime.Go:
26
- return 'go';
27
- case elf_cam_1.Runtime.Rust:
28
- return 'rs';
29
- default:
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
- catch (error) { }
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 }) => __awaiter(void 0, void 0, void 0, function* () {
7
+ const build = async ({ destPath, mainFile, srcDir }) => {
17
8
  const functionName = (0, path_1.basename)(srcDir);
18
9
  try {
19
- yield (0, shell_1.runCommand)('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
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 = yield (0, fs_1.lstat)(destPath);
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 }) => __awaiter(void 0, void 0, void 0, function* () {
22
- const stat = yield (0, fs_1.cachedLstat)(fsCache, path);
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 = (yield (0, fs_1.cachedReaddir)(fsCache, path));
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 findFunctionInPath = function ({ featureFlags, fsCache, path }) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- const runtime = yield (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
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 processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, function* () {
58
- const stat = (yield (0, fs_1.cachedLstat)(fsCache, path));
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, }) => __awaiter(void 0, void 0, void 0, function* () {
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 = (yield (0, fs_1.cachedLstat)(fsCache, path));
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
- return __awaiter(this, void 0, void 0, function* () {
93
- const destPath = (0, path_1.join)(destFolder, filename);
94
- const isSource = (0, path_1.extname)(mainFile) === '.go';
95
- // If we're building a Go function from source, we call the build method and
96
- // it'll take care of placing the binary in the right location. If not, we
97
- // need to copy the existing binary file to the destination directory.
98
- yield (isSource ? (0, builder_1.build)({ destPath, mainFile, srcDir }) : (0, cp_file_1.default)(srcPath, destPath));
99
- return { config, path: destPath };
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;