@netlify/zip-it-and-ship-it 5.3.0 → 5.4.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.
Files changed (48) hide show
  1. package/README.md +1 -1
  2. package/dist/archive.js +16 -16
  3. package/dist/bin.js +13 -35
  4. package/dist/feature_flags.js +4 -1
  5. package/dist/main.d.ts +13 -4
  6. package/dist/main.js +54 -57
  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 +35 -47
  11. package/dist/runtimes/index.d.ts +8 -1
  12. package/dist/runtimes/index.js +54 -41
  13. package/dist/runtimes/node/bundlers/esbuild/bundler.js +81 -92
  14. package/dist/runtimes/node/bundlers/esbuild/index.js +14 -18
  15. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +13 -22
  16. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +3 -13
  17. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +8 -17
  18. package/dist/runtimes/node/bundlers/esbuild/src_files.js +28 -41
  19. package/dist/runtimes/node/bundlers/nft/es_modules.js +16 -22
  20. package/dist/runtimes/node/bundlers/nft/index.js +47 -60
  21. package/dist/runtimes/node/bundlers/nft/transpile.js +3 -12
  22. package/dist/runtimes/node/bundlers/zisi/index.js +7 -13
  23. package/dist/runtimes/node/bundlers/zisi/list_imports.js +5 -14
  24. package/dist/runtimes/node/bundlers/zisi/published.js +8 -19
  25. package/dist/runtimes/node/bundlers/zisi/resolve.js +37 -55
  26. package/dist/runtimes/node/bundlers/zisi/side_files.js +6 -17
  27. package/dist/runtimes/node/bundlers/zisi/src_files.js +58 -75
  28. package/dist/runtimes/node/bundlers/zisi/traverse.js +41 -56
  29. package/dist/runtimes/node/bundlers/zisi/tree_files.js +8 -19
  30. package/dist/runtimes/node/finder.d.ts +4 -6
  31. package/dist/runtimes/node/finder.js +48 -65
  32. package/dist/runtimes/node/in_source_config/index.js +5 -14
  33. package/dist/runtimes/node/index.js +65 -87
  34. package/dist/runtimes/node/parser/index.js +11 -20
  35. package/dist/runtimes/node/utils/detect_es_module.js +4 -15
  36. package/dist/runtimes/node/utils/included_files.js +3 -12
  37. package/dist/runtimes/node/utils/package_json.js +19 -27
  38. package/dist/runtimes/node/utils/zip.js +63 -94
  39. package/dist/runtimes/runtime.d.ts +7 -1
  40. package/dist/runtimes/rust/builder.js +23 -36
  41. package/dist/runtimes/rust/index.js +48 -60
  42. package/dist/utils/archive_size.js +5 -14
  43. package/dist/utils/format_result.js +6 -1
  44. package/dist/utils/fs.d.ts +6 -10
  45. package/dist/utils/fs.js +35 -63
  46. package/dist/zip.js +60 -73
  47. package/dist/zip_binary.js +5 -16
  48. package/package.json +7 -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
  };
@@ -28,8 +19,19 @@ const startZip = function (destPath) {
28
19
  exports.startZip = startZip;
29
20
  // Add new file to zip
30
21
  const addZipFile = function (archive, file, name, stat) {
31
- // Ensure sha256 stability regardless of mtime
32
- archive.file(file, { name, mode: stat.mode, date: new Date(0), stats: stat });
22
+ if (stat.isSymbolicLink()) {
23
+ const linkContent = (0, fs_1.readlinkSync)(file);
24
+ archive.symlink(name, linkContent, stat.mode);
25
+ }
26
+ else {
27
+ archive.file(file, {
28
+ name,
29
+ mode: stat.mode,
30
+ // Ensure sha256 stability regardless of mtime
31
+ date: new Date(0),
32
+ stats: stat,
33
+ });
34
+ }
33
35
  };
34
36
  exports.addZipFile = addZipFile;
35
37
  // Add new file content to zip
@@ -38,11 +40,9 @@ const addZipContent = function (archive, content, name) {
38
40
  };
39
41
  exports.addZipContent = addZipContent;
40
42
  // End zipping files
41
- const endZip = function (archive, output) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- archive.finalize();
44
- yield pEndOfStream(output);
45
- });
43
+ const endZip = async function (archive, output) {
44
+ archive.finalize();
45
+ await pEndOfStream(output);
46
46
  };
47
47
  exports.endZip = endZip;
48
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
@@ -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.d.ts CHANGED
@@ -6,6 +6,7 @@ interface ListedFunction {
6
6
  mainFile: string;
7
7
  runtime: RuntimeName;
8
8
  extension: string;
9
+ schedule?: string;
9
10
  }
10
11
  declare type ListedFunctionFile = ListedFunction & {
11
12
  srcFile: string;
@@ -14,10 +15,18 @@ interface ListFunctionsOptions {
14
15
  basePath?: string;
15
16
  config?: Config;
16
17
  featureFlags?: FeatureFlags;
18
+ parseISC?: boolean;
17
19
  }
18
- declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags }?: {
19
- featureFlags?: FeatureFlags;
20
+ declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags, config, parseISC, }?: {
21
+ featureFlags?: FeatureFlags | undefined;
22
+ config?: Config | undefined;
23
+ parseISC?: boolean | undefined;
20
24
  }) => Promise<ListedFunction[]>;
21
- declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
22
- export { listFunctions, listFunctionsFiles };
25
+ declare const listFunction: (path: string, { featureFlags: inputFeatureFlags, config, parseISC, }?: {
26
+ featureFlags?: FeatureFlags | undefined;
27
+ config?: Config | undefined;
28
+ parseISC?: boolean | undefined;
29
+ }) => Promise<ListedFunction | undefined>;
30
+ declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags, parseISC }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
31
+ export { listFunctions, listFunction, listFunctionsFiles };
23
32
  export { zipFunction, zipFunctions } from './zip';
package/dist/main.js CHANGED
@@ -1,74 +1,71 @@
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
- exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunctions = void 0;
3
+ exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunction = exports.listFunctions = void 0;
24
4
  const path_1 = require("path");
25
5
  const feature_flags_1 = require("./feature_flags");
26
6
  const runtimes_1 = require("./runtimes");
7
+ const in_source_config_1 = require("./runtimes/node/in_source_config");
27
8
  const fs_1 = require("./utils/fs");
9
+ const augmentWithISC = async (func) => {
10
+ // ISC is currently only supported in JavaScript and TypeScript functions.
11
+ if (func.runtime.name !== 'js') {
12
+ return func;
13
+ }
14
+ const inSourceConfig = await (0, in_source_config_1.findISCDeclarationsInPath)(func.mainFile);
15
+ return { ...func, inSourceConfig };
16
+ };
28
17
  // List all Netlify Functions main entry files for a specific directory
29
- const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
32
- const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
33
- const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
34
- const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags });
35
- const listedFunctions = [...functions.values()].map(getListedFunction);
36
- return listedFunctions;
37
- });
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);
38
26
  };
39
27
  exports.listFunctions = listFunctions;
28
+ // Finds a function at a specific path.
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);
37
+ };
38
+ exports.listFunction = listFunction;
40
39
  // List all Netlify Functions files for a specific directory
41
- const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags } = {}) {
42
- return __awaiter(this, void 0, void 0, function* () {
43
- const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
44
- const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
45
- const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
46
- const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { config, featureFlags });
47
- const listedFunctionsFiles = yield Promise.all([...functions.values()].map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
48
- return listedFunctionsFiles.flat();
49
- });
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();
50
49
  };
51
50
  exports.listFunctionsFiles = listFunctionsFiles;
52
- const getListedFunction = function ({ runtime, name, mainFile, extension }) {
53
- return { name, mainFile, runtime: runtime.name, extension };
51
+ const getListedFunction = function ({ runtime, name, mainFile, extension, config, inSourceConfig, }) {
52
+ var _a;
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 };
54
54
  };
55
- const getListedFunctionFiles = function (func, options) {
56
- return __awaiter(this, void 0, void 0, function* () {
57
- const srcFiles = yield getSrcFiles(Object.assign(Object.assign({}, func), options));
58
- const { name, mainFile, runtime } = func;
59
- return srcFiles.map((srcFile) => ({ srcFile, name, mainFile, runtime: runtime.name, extension: (0, path_1.extname)(srcFile) }));
60
- });
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) }));
61
58
  };
62
- const getSrcFiles = function (_a) {
63
- var { extension, runtime, srcPath } = _a, args = __rest(_a, ["extension", "runtime", "srcPath"]);
64
- return __awaiter(this, void 0, void 0, function* () {
65
- const { getSrcFiles: getRuntimeSrcFiles } = runtime;
66
- if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
67
- return [srcPath];
68
- }
69
- return yield getRuntimeSrcFiles(Object.assign({ extension,
70
- runtime,
71
- 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,
72
69
  });
73
70
  };
74
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
  };
@@ -18,41 +9,40 @@ const fs_1 = require("../../utils/fs");
18
9
  const non_nullable_1 = require("../../utils/non_nullable");
19
10
  const detect_runtime_1 = require("../detect_runtime");
20
11
  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);
12
+ const detectGoFunction = async ({ fsCache, path }) => {
13
+ const stat = await (0, fs_1.cachedLstat)(fsCache, path);
23
14
  if (!stat.isDirectory()) {
24
15
  return;
25
16
  }
26
17
  const directoryName = (0, path_1.basename)(path);
27
18
  // @ts-expect-error TODO: The `makeCachedFunction` abstraction is causing the
28
19
  // return value of `readdir` to be incorrectly typed.
29
- const files = (yield (0, fs_1.cachedReaddir)(fsCache, path));
20
+ const files = (await (0, fs_1.cachedReaddir)(fsCache, path));
30
21
  const mainFileName = [`${directoryName}.go`, 'main.go'].find((name) => files.includes(name));
31
22
  if (mainFileName === undefined) {
32
23
  return;
33
24
  }
34
25
  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) => __awaiter(this, void 0, void 0, function* () {
39
- const runtime = yield (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
40
- if (runtime === 'go') {
41
- return processBinary({ fsCache, path });
42
- }
43
- if (featureFlags.buildGoSource !== true) {
44
- return;
45
- }
46
- const goSourceFile = yield detectGoFunction({ fsCache, path });
47
- if (goSourceFile) {
48
- return processSource({ fsCache, mainFile: goSourceFile, path });
49
- }
50
- })));
51
- return functions.filter(non_nullable_1.nonNullable);
52
- });
53
26
  };
54
- const processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, function* () {
55
- const stat = (yield (0, fs_1.cachedLstat)(fsCache, path));
27
+ const findFunctionsInPaths = async function ({ featureFlags, fsCache, paths }) {
28
+ const functions = await Promise.all(paths.map((path) => findFunctionInPath({ featureFlags, fsCache, path })));
29
+ return functions.filter(non_nullable_1.nonNullable);
30
+ };
31
+ const findFunctionInPath = async function ({ featureFlags, fsCache, path }) {
32
+ const runtime = await (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
33
+ if (runtime === 'go') {
34
+ return processBinary({ fsCache, path });
35
+ }
36
+ if (featureFlags.buildGoSource !== true) {
37
+ return;
38
+ }
39
+ const goSourceFile = await detectGoFunction({ fsCache, path });
40
+ if (goSourceFile) {
41
+ return processSource({ fsCache, mainFile: goSourceFile, path });
42
+ }
43
+ };
44
+ const processBinary = async ({ fsCache, path }) => {
45
+ const stat = (await (0, fs_1.cachedLstat)(fsCache, path));
56
46
  const extension = (0, path_1.extname)(path);
57
47
  const filename = (0, path_1.basename)(path);
58
48
  const name = (0, path_1.basename)(path, (0, path_1.extname)(path));
@@ -65,13 +55,13 @@ const processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, f
65
55
  srcPath: path,
66
56
  stat,
67
57
  };
68
- });
69
- const processSource = ({ fsCache, mainFile, path, }) => __awaiter(void 0, void 0, void 0, function* () {
58
+ };
59
+ const processSource = async ({ fsCache, mainFile, path, }) => {
70
60
  // TODO: This `stat` value is not going to be used, but we need it to satisfy
71
61
  // the `FunctionSource` interface. We should revisit whether `stat` should be
72
62
  // part of that interface in the first place, or whether we could compute it
73
63
  // downstream when needed (maybe using the FS cache as an optimisation).
74
- const stat = (yield (0, fs_1.cachedLstat)(fsCache, path));
64
+ const stat = (await (0, fs_1.cachedLstat)(fsCache, path));
75
65
  const filename = (0, path_1.basename)(path);
76
66
  const extension = (0, path_1.extname)(mainFile);
77
67
  const name = (0, path_1.basename)(path, (0, path_1.extname)(path));
@@ -84,18 +74,16 @@ const processSource = ({ fsCache, mainFile, path, }) => __awaiter(void 0, void 0
84
74
  srcPath: path,
85
75
  stat,
86
76
  };
87
- });
88
- const zipFunction = function ({ config, destFolder, filename, mainFile, srcDir, srcPath }) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const destPath = (0, path_1.join)(destFolder, filename);
91
- const isSource = (0, path_1.extname)(mainFile) === '.go';
92
- // If we're building a Go function from source, we call the build method and
93
- // it'll take care of placing the binary in the right location. If not, we
94
- // need to copy the existing binary file to the destination directory.
95
- yield (isSource ? (0, builder_1.build)({ destPath, mainFile, srcDir }) : (0, cp_file_1.default)(srcPath, destPath));
96
- return { config, path: destPath };
97
- });
98
77
  };
99
- const runtime = { findFunctionsInPaths, name: 'go', zipFunction };
78
+ const zipFunction = async function ({ config, destFolder, filename, mainFile, srcDir, srcPath }) {
79
+ const destPath = (0, path_1.join)(destFolder, filename);
80
+ const isSource = (0, path_1.extname)(mainFile) === '.go';
81
+ // If we're building a Go function from source, we call the build method and
82
+ // it'll take care of placing the binary in the right location. If not, we
83
+ // need to copy the existing binary file to the destination directory.
84
+ await (isSource ? (0, builder_1.build)({ destPath, mainFile, srcDir }) : (0, cp_file_1.default)(srcPath, destPath));
85
+ return { config, path: destPath };
86
+ };
87
+ const runtime = { findFunctionsInPaths, findFunctionInPath, name: 'go', zipFunction };
100
88
  exports.default = runtime;
101
89
  //# sourceMappingURL=index.js.map
@@ -10,4 +10,11 @@ declare const getFunctionsFromPaths: (paths: string[], { config, dedupe, feature
10
10
  dedupe?: boolean | undefined;
11
11
  featureFlags?: FeatureFlags | undefined;
12
12
  }) => Promise<FunctionMap>;
13
- export { getFunctionsFromPaths };
13
+ /**
14
+ * Gets a list of functions found in a list of paths.
15
+ */
16
+ declare const getFunctionFromPath: (path: string, { config, featureFlags }?: {
17
+ config?: Config | undefined;
18
+ featureFlags?: FeatureFlags | undefined;
19
+ }) => Promise<FunctionSource | undefined>;
20
+ export { getFunctionsFromPaths, getFunctionFromPath };