@netlify/zip-it-and-ship-it 4.26.0 → 4.28.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 (92) hide show
  1. package/dist/archive.d.ts +3 -2
  2. package/dist/bin.js +22 -9
  3. package/dist/config.d.ts +24 -4
  4. package/dist/config.js +11 -6
  5. package/dist/feature_flags.d.ts +6 -12
  6. package/dist/feature_flags.js +10 -6
  7. package/dist/function.d.ts +24 -0
  8. package/dist/function.js +3 -0
  9. package/dist/main.d.ts +25 -16
  10. package/dist/main.js +48 -50
  11. package/dist/manifest.d.ts +23 -4
  12. package/dist/manifest.js +16 -8
  13. package/dist/runtimes/detect_runtime.d.ts +7 -4
  14. package/dist/runtimes/detect_runtime.js +19 -11
  15. package/dist/runtimes/go/builder.d.ts +9 -8
  16. package/dist/runtimes/go/builder.js +11 -9
  17. package/dist/runtimes/go/index.d.ts +3 -18
  18. package/dist/runtimes/go/index.js +45 -24
  19. package/dist/runtimes/index.d.ts +10 -6
  20. package/dist/runtimes/index.js +18 -25
  21. package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +17 -16
  22. package/dist/runtimes/node/bundlers/esbuild/bundler.js +30 -26
  23. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +10 -1
  24. package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +7 -2
  25. package/dist/runtimes/node/bundlers/esbuild/index.d.ts +6 -21
  26. package/dist/runtimes/node/bundlers/esbuild/index.js +36 -19
  27. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.d.ts +9 -10
  28. package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +26 -21
  29. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +4 -4
  30. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +14 -9
  31. package/dist/runtimes/node/bundlers/esbuild/special_cases.d.ts +5 -4
  32. package/dist/runtimes/node/bundlers/esbuild/special_cases.js +5 -3
  33. package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +3 -6
  34. package/dist/runtimes/node/bundlers/esbuild/src_files.js +13 -11
  35. package/dist/runtimes/node/bundlers/index.d.ts +33 -4
  36. package/dist/runtimes/node/bundlers/index.js +16 -12
  37. package/dist/runtimes/node/bundlers/nft/index.d.ts +7 -22
  38. package/dist/runtimes/node/bundlers/nft/index.js +101 -21
  39. package/dist/runtimes/node/bundlers/nft/transpile.d.ts +3 -0
  40. package/dist/runtimes/node/bundlers/nft/transpile.js +46 -0
  41. package/dist/runtimes/node/bundlers/zisi/index.d.ts +6 -18
  42. package/dist/runtimes/node/bundlers/zisi/index.js +14 -8
  43. package/dist/runtimes/node/bundlers/zisi/list_imports.js +3 -2
  44. package/dist/runtimes/node/bundlers/zisi/resolve.d.ts +3 -2
  45. package/dist/runtimes/node/bundlers/zisi/resolve.js +17 -11
  46. package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +3 -10
  47. package/dist/runtimes/node/bundlers/zisi/src_files.js +38 -34
  48. package/dist/runtimes/node/bundlers/zisi/traverse.d.ts +1 -1
  49. package/dist/runtimes/node/bundlers/zisi/traverse.js +2 -1
  50. package/dist/runtimes/node/finder.d.ts +6 -12
  51. package/dist/runtimes/node/finder.js +35 -26
  52. package/dist/runtimes/node/index.d.ts +4 -42
  53. package/dist/runtimes/node/index.js +42 -28
  54. package/dist/runtimes/node/parser/index.d.ts +7 -6
  55. package/dist/runtimes/node/parser/index.js +33 -21
  56. package/dist/runtimes/node/utils/included_files.d.ts +1 -1
  57. package/dist/runtimes/node/utils/included_files.js +3 -0
  58. package/dist/runtimes/node/utils/package_json.d.ts +1 -0
  59. package/dist/runtimes/node/utils/zip.d.ts +2 -2
  60. package/dist/runtimes/runtime.d.ts +45 -0
  61. package/dist/runtimes/runtime.js +3 -0
  62. package/dist/runtimes/rust/builder.d.ts +7 -5
  63. package/dist/runtimes/rust/builder.js +31 -26
  64. package/dist/runtimes/rust/cargo_manifest.d.ts +6 -0
  65. package/dist/runtimes/rust/cargo_manifest.js +3 -0
  66. package/dist/runtimes/rust/constants.d.ts +3 -2
  67. package/dist/runtimes/rust/constants.js +4 -1
  68. package/dist/runtimes/rust/index.d.ts +3 -20
  69. package/dist/runtimes/rust/index.js +48 -30
  70. package/dist/utils/archive_size.d.ts +3 -1
  71. package/dist/utils/archive_size.js +7 -5
  72. package/dist/utils/format_result.d.ts +8 -1
  73. package/dist/utils/format_result.js +7 -18
  74. package/dist/utils/fs.d.ts +17 -12
  75. package/dist/utils/fs.js +36 -30
  76. package/dist/utils/non_nullable.d.ts +2 -0
  77. package/dist/utils/non_nullable.js +6 -0
  78. package/dist/utils/polyfills.d.ts +1 -1
  79. package/dist/utils/polyfills.js +2 -1
  80. package/dist/utils/remove_undefined.d.ts +2 -0
  81. package/dist/utils/remove_undefined.js +12 -0
  82. package/dist/utils/shell.d.ts +1 -1
  83. package/dist/utils/shell.js +7 -2
  84. package/dist/zip.d.ts +18 -17
  85. package/dist/zip.js +40 -32
  86. package/dist/zip_binary.d.ts +10 -7
  87. package/dist/zip_binary.js +9 -7
  88. package/package.json +7 -3
  89. package/dist/utils/consts.d.ts +0 -9
  90. package/dist/utils/consts.js +0 -13
  91. package/dist/utils/remove_falsy.d.ts +0 -1
  92. package/dist/utils/remove_falsy.js +0 -11
package/dist/archive.d.ts CHANGED
@@ -2,12 +2,13 @@ import { Buffer } from 'buffer';
2
2
  import { Stats } from 'fs';
3
3
  import { Writable } from 'stream';
4
4
  import { Archiver } from 'archiver';
5
+ declare type ArchiveFormat = 'none' | 'zip';
5
6
  declare const startZip: (destPath: string) => {
6
7
  archive: Archiver;
7
8
  output: Writable;
8
9
  };
9
10
  declare const addZipFile: (archive: Archiver, file: string, name: string, stat: Stats) => void;
10
- declare const addZipContent: (archive: Archiver, content: Buffer, name: string) => void;
11
+ declare const addZipContent: (archive: Archiver, content: Buffer | string, name: string) => void;
11
12
  declare const endZip: (archive: Archiver, output: Writable) => Promise<void>;
12
13
  export { startZip, addZipFile, addZipContent, endZip };
13
- export type { Archiver as ZipArchive };
14
+ export type { ArchiveFormat, Archiver as ZipArchive };
package/dist/bin.js CHANGED
@@ -20,32 +20,45 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  }
21
21
  return t;
22
22
  };
23
- const { exit } = require('process');
24
- const yargs = require('yargs');
25
- const zipIt = require('./main');
26
- const { ARCHIVE_FORMAT_NONE, ARCHIVE_FORMAT_ZIP } = require('./utils/consts');
23
+ var __importDefault = (this && this.__importDefault) || function (mod) {
24
+ return (mod && mod.__esModule) ? mod : { "default": mod };
25
+ };
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ const process_1 = require("process");
28
+ const yargs_1 = __importDefault(require("yargs"));
29
+ const main_1 = require("./main");
27
30
  // CLI entry point
28
31
  const runCli = function () {
29
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()`.
30
35
  const _a = parseArgs(), { destFolder, srcFolder } = _a, options = __rest(_a, ["destFolder", "srcFolder"]);
31
36
  try {
32
- const zipped = yield zipIt.zipFunctions(srcFolder, destFolder, options);
37
+ // @ts-expect-error TODO: `options` is not getting the right types.
38
+ const zipped = yield (0, main_1.zipFunctions)(srcFolder, destFolder, options);
33
39
  console.log(JSON.stringify(zipped, null, 2));
34
40
  }
35
41
  catch (error) {
36
42
  console.error(error.toString());
37
- exit(1);
43
+ (0, process_1.exit)(1);
38
44
  }
39
45
  });
40
46
  };
41
47
  const parseArgs = function () {
42
- return yargs.command('* <srcFolder> <destFolder>').options(OPTIONS).usage(USAGE).strict().parse();
48
+ return yargs_1.default
49
+ .command('* <srcFolder> <destFolder>', 'Create ZIP archives from a directory')
50
+ .options(OPTIONS)
51
+ .usage(USAGE)
52
+ .strict()
53
+ .parse();
43
54
  };
55
+ const archiveFormats = ['none', 'zip'];
56
+ const defaultArchiveFormat = 'zip';
44
57
  const OPTIONS = {
45
58
  'archive-format': {
46
59
  string: true,
47
- choices: [ARCHIVE_FORMAT_NONE, ARCHIVE_FORMAT_ZIP],
48
- default: ARCHIVE_FORMAT_ZIP,
60
+ choices: archiveFormats,
61
+ default: defaultArchiveFormat,
49
62
  describe: 'Format of the archive created for each function',
50
63
  },
51
64
  config: {
package/dist/config.d.ts CHANGED
@@ -1,4 +1,24 @@
1
- export function getConfigForFunction({ config, func }: {
2
- config: any;
3
- func: any;
4
- }): any;
1
+ import { FunctionSource } from './function';
2
+ import type { NodeBundlerName } from './runtimes/node';
3
+ declare type SupportedVersionNumbers = 8 | 10 | 12 | 14;
4
+ declare type NodeVersion = `${SupportedVersionNumbers}.x` | `nodejs${SupportedVersionNumbers}.x`;
5
+ interface FunctionConfig {
6
+ externalNodeModules?: string[];
7
+ includedFiles?: string[];
8
+ includedFilesBasePath?: string;
9
+ ignoredNodeModules?: string[];
10
+ nodeBundler?: NodeBundlerName;
11
+ nodeSourcemap?: boolean;
12
+ nodeVersion?: NodeVersion;
13
+ processDynamicNodeImports?: boolean;
14
+ rustTargetDirectory?: string;
15
+ schedule?: string;
16
+ }
17
+ declare type GlobPattern = string;
18
+ declare type Config = Record<GlobPattern, FunctionConfig>;
19
+ declare const getConfigForFunction: ({ config, func, }: {
20
+ config?: Config | undefined;
21
+ func: Omit<FunctionSource, 'config'>;
22
+ }) => FunctionConfig;
23
+ export { getConfigForFunction };
24
+ export type { Config, FunctionConfig };
package/dist/config.js CHANGED
@@ -1,13 +1,18 @@
1
1
  "use strict";
2
- const mergeOptions = require('merge-options');
3
- const minimatch = require('minimatch');
4
- const getConfigForFunction = ({ config, func }) => {
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getConfigForFunction = void 0;
7
+ const merge_options_1 = __importDefault(require("merge-options"));
8
+ const minimatch_1 = __importDefault(require("minimatch"));
9
+ const getConfigForFunction = ({ config, func, }) => {
5
10
  if (!config) {
6
11
  return {};
7
12
  }
8
13
  // It's safe to mutate the array because it's local to this function.
9
14
  const matches = Object.keys(config)
10
- .filter((expression) => minimatch(func.name, expression))
15
+ .filter((expression) => (0, minimatch_1.default)(func.name, expression))
11
16
  .map((expression) => {
12
17
  const wildcardCount = [...expression].filter((char) => char === '*').length;
13
18
  // The weight increases with the number of hardcoded (i.e. non-wildcard)
@@ -22,7 +27,7 @@ const getConfigForFunction = ({ config, func }) => {
22
27
  })
23
28
  .sort(({ weight: weightA }, { weight: weightB }) => weightA - weightB)
24
29
  .map(({ expression }) => config[expression]);
25
- return mergeOptions.apply({ concatArrays: true, ignoreUndefined: true }, matches);
30
+ return merge_options_1.default.apply({ concatArrays: true, ignoreUndefined: true }, matches);
26
31
  };
27
- module.exports = { getConfigForFunction };
32
+ exports.getConfigForFunction = getConfigForFunction;
28
33
  //# sourceMappingURL=config.js.map
@@ -1,12 +1,6 @@
1
- export namespace FLAGS {
2
- const buildGoSource: boolean;
3
- const buildRustSource: boolean;
4
- const defaultEsModulesToEsbuild: boolean;
5
- const parseWithEsbuild: boolean;
6
- }
7
- export function getFlags(input?: {}, flags?: {
8
- buildGoSource: boolean;
9
- buildRustSource: boolean;
10
- defaultEsModulesToEsbuild: boolean;
11
- parseWithEsbuild: boolean;
12
- }): {};
1
+ declare const FLAGS: Record<string, boolean>;
2
+ declare type FeatureFlag = keyof typeof FLAGS;
3
+ declare type FeatureFlags = Record<FeatureFlag, boolean>;
4
+ declare const getFlags: (input?: Record<string, boolean>, flags?: Record<string, boolean>) => {};
5
+ export { FLAGS as defaultFlags, getFlags };
6
+ export type { FeatureFlag, FeatureFlags };
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
- const { env } = require('process');
3
- // List of supported flags and their default value.
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFlags = exports.defaultFlags = void 0;
4
+ const process_1 = require("process");
4
5
  const FLAGS = {
5
- buildGoSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
6
- buildRustSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
7
- defaultEsModulesToEsbuild: Boolean(env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
6
+ buildGoSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_GO_SOURCE),
7
+ buildRustSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
8
+ defaultEsModulesToEsbuild: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_DEFAULT_ES_MODULES_TO_ESBUILD),
8
9
  parseWithEsbuild: false,
10
+ traceWithNft: false,
9
11
  };
12
+ exports.defaultFlags = FLAGS;
13
+ // List of supported flags and their default value.
10
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] })), {});
11
- module.exports = { FLAGS, getFlags };
15
+ exports.getFlags = getFlags;
12
16
  //# sourceMappingURL=feature_flags.js.map
@@ -0,0 +1,24 @@
1
+ /// <reference types="node" />
2
+ import { Stats } from 'fs';
3
+ import type { FunctionConfig } from './config';
4
+ import type { Runtime, ZipFunctionResult } from './runtimes/runtime';
5
+ declare type FunctionArchive = ZipFunctionResult & {
6
+ mainFile: string;
7
+ name: string;
8
+ runtime: Runtime;
9
+ size?: number;
10
+ };
11
+ interface SourceFile {
12
+ extension: string;
13
+ filename: string;
14
+ mainFile: string;
15
+ name: string;
16
+ srcDir: string;
17
+ srcPath: string;
18
+ stat: Stats;
19
+ }
20
+ declare type FunctionSource = SourceFile & {
21
+ config: FunctionConfig;
22
+ runtime: Runtime;
23
+ };
24
+ export { FunctionArchive, FunctionSource, SourceFile };
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=function.js.map
package/dist/main.d.ts CHANGED
@@ -1,16 +1,25 @@
1
- import { zipFunctions } from "./zip";
2
- import { zipFunction } from "./zip";
3
- export function listFunctions(relativeSrcFolders: any, { featureFlags: inputFeatureFlags }?: {
4
- featureFlags: any;
5
- }): Promise<{
6
- name: any;
7
- mainFile: any;
8
- runtime: any;
9
- extension: any;
10
- }[]>;
11
- export function listFunctionsFiles(relativeSrcFolders: any, { basePath, config, featureFlags: inputFeatureFlags }?: {
12
- basePath: any;
13
- config: any;
14
- featureFlags: any;
15
- }): Promise<never[]>;
16
- export { zipFunctions, zipFunction };
1
+ import './utils/polyfills';
2
+ import { Config } from './config';
3
+ import { FeatureFlags } from './feature_flags';
4
+ import { RuntimeName } from './runtimes/runtime';
5
+ import { zipFunction, zipFunctions } from './zip';
6
+ interface ListedFunction {
7
+ name: string;
8
+ mainFile: string;
9
+ runtime: RuntimeName;
10
+ extension: string;
11
+ }
12
+ declare type ListedFunctionFile = ListedFunction & {
13
+ srcFile: string;
14
+ };
15
+ interface ListFunctionsOptions {
16
+ basePath?: string;
17
+ config?: Config;
18
+ featureFlags?: FeatureFlags;
19
+ pluginsModulesPath?: string;
20
+ }
21
+ declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags }?: {
22
+ featureFlags?: FeatureFlags;
23
+ }) => Promise<ListedFunction[]>;
24
+ declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
25
+ export { zipFunctions, zipFunction, listFunctions, listFunctionsFiles };
package/dist/main.js CHANGED
@@ -8,77 +8,75 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { extname } = require('path');
12
- require('./utils/polyfills');
13
- const { getFlags } = require('./feature_flags');
14
- const { getFunctionsFromPaths } = require('./runtimes');
15
- const { getPluginsModulesPath } = require('./runtimes/node/utils/plugin_modules_path');
16
- const { listFunctionsDirectories, resolveFunctionsDirectories } = require('./utils/fs');
17
- const { zipFunction, zipFunctions } = require('./zip');
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
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ exports.listFunctionsFiles = exports.listFunctions = exports.zipFunction = exports.zipFunctions = void 0;
24
+ const path_1 = require("path");
25
+ require("./utils/polyfills");
26
+ const feature_flags_1 = require("./feature_flags");
27
+ const runtimes_1 = require("./runtimes");
28
+ const plugin_modules_path_1 = require("./runtimes/node/utils/plugin_modules_path");
29
+ const fs_1 = require("./utils/fs");
30
+ const zip_1 = require("./zip");
31
+ Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_1.zipFunction; } });
32
+ Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_1.zipFunctions; } });
18
33
  // List all Netlify Functions main entry files for a specific directory
19
34
  const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
20
35
  return __awaiter(this, void 0, void 0, function* () {
21
- const featureFlags = getFlags(inputFeatureFlags);
22
- const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
23
- const paths = yield listFunctionsDirectories(srcFolders);
24
- const functions = yield getFunctionsFromPaths(paths, { featureFlags });
36
+ const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
37
+ const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
38
+ const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
39
+ const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags });
25
40
  const listedFunctions = [...functions.values()].map(getListedFunction);
26
41
  return listedFunctions;
27
42
  });
28
43
  };
44
+ exports.listFunctions = listFunctions;
29
45
  // List all Netlify Functions files for a specific directory
30
46
  const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags } = {}) {
31
47
  return __awaiter(this, void 0, void 0, function* () {
32
- const featureFlags = getFlags(inputFeatureFlags);
33
- const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
34
- const paths = yield listFunctionsDirectories(srcFolders);
48
+ const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
49
+ const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
50
+ const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
35
51
  const [functions, pluginsModulesPath] = yield Promise.all([
36
- getFunctionsFromPaths(paths, { config, featureFlags }),
37
- getPluginsModulesPath(srcFolders[0]),
52
+ (0, runtimes_1.getFunctionsFromPaths)(paths, { config, featureFlags }),
53
+ (0, plugin_modules_path_1.getPluginsModulesPath)(srcFolders[0]),
38
54
  ]);
39
55
  const listedFunctionsFiles = yield Promise.all([...functions.values()].map((func) => getListedFunctionFiles(func, { basePath, featureFlags, pluginsModulesPath })));
40
- // TODO: switch to Array.flat() once we drop support for Node.js < 11.0.0
41
- // eslint-disable-next-line unicorn/prefer-spread
42
- return [].concat(...listedFunctionsFiles);
56
+ return listedFunctionsFiles.flat();
43
57
  });
44
58
  };
59
+ exports.listFunctionsFiles = listFunctionsFiles;
45
60
  const getListedFunction = function ({ runtime, name, mainFile, extension }) {
46
61
  return { name, mainFile, runtime: runtime.name, extension };
47
62
  };
48
- const getListedFunctionFiles = function ({ config, runtime, name, stat, mainFile, extension, srcPath, srcDir }, { basePath, featureFlags, pluginsModulesPath }) {
63
+ const getListedFunctionFiles = function (func, options) {
49
64
  return __awaiter(this, void 0, void 0, function* () {
50
- const srcFiles = yield getSrcFiles({
51
- basePath,
52
- featureFlags,
53
- runtime,
54
- stat,
55
- mainFile,
56
- extension,
57
- srcPath,
58
- srcDir,
59
- pluginsModulesPath,
60
- config,
61
- });
62
- return srcFiles.map((srcFile) => ({ srcFile, name, mainFile, runtime: runtime.name, extension: extname(srcFile) }));
65
+ const srcFiles = yield getSrcFiles(Object.assign(Object.assign({}, func), options));
66
+ const { name, mainFile, runtime } = func;
67
+ return srcFiles.map((srcFile) => ({ srcFile, name, mainFile, runtime: runtime.name, extension: (0, path_1.extname)(srcFile) }));
63
68
  });
64
69
  };
65
- const getSrcFiles = function ({ basePath, bundler, config, featureFlags, runtime, stat, mainFile, extension, srcPath, srcDir, pluginsModulesPath, }) {
66
- const { getSrcFiles: getRuntimeSrcFiles } = runtime;
67
- if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
68
- return [srcPath];
69
- }
70
- return getRuntimeSrcFiles({
71
- basePath,
72
- bundler,
73
- config,
74
- extension,
75
- featureFlags,
76
- srcPath,
77
- mainFile,
78
- srcDir,
79
- stat,
80
- pluginsModulesPath,
70
+ const getSrcFiles = function (_a) {
71
+ var { extension, runtime, srcPath } = _a, args = __rest(_a, ["extension", "runtime", "srcPath"]);
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ const { getSrcFiles: getRuntimeSrcFiles } = runtime;
74
+ if (extension === '.zip' || typeof getRuntimeSrcFiles !== 'function') {
75
+ return [srcPath];
76
+ }
77
+ return yield getRuntimeSrcFiles(Object.assign({ extension,
78
+ runtime,
79
+ srcPath }, args));
81
80
  });
82
81
  };
83
- module.exports = { zipFunctions, zipFunction, listFunctions, listFunctionsFiles };
84
82
  //# sourceMappingURL=main.js.map
@@ -1,4 +1,23 @@
1
- export function createManifest({ functions, path }: {
2
- functions: any;
3
- path: any;
4
- }): Promise<void>;
1
+ import { FunctionResult } from './utils/format_result';
2
+ interface ManifestFunction {
3
+ mainFile: string;
4
+ name: string;
5
+ path: string;
6
+ runtime: string;
7
+ schedule?: string;
8
+ }
9
+ interface Manifest {
10
+ functions: ManifestFunction[];
11
+ system: {
12
+ arch: string;
13
+ platform: string;
14
+ };
15
+ timestamp: number;
16
+ version: number;
17
+ }
18
+ declare const createManifest: ({ functions, path }: {
19
+ functions: FunctionResult[];
20
+ path: string;
21
+ }) => Promise<void>;
22
+ export { createManifest };
23
+ export type { Manifest };
package/dist/manifest.js CHANGED
@@ -8,20 +8,28 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { resolve } = require('path');
12
- const { arch, platform } = require('process');
13
- const { writeFile } = require('./utils/fs');
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.createManifest = void 0;
13
+ const path_1 = require("path");
14
+ const process_1 = require("process");
15
+ const fs_1 = require("./utils/fs");
14
16
  const MANIFEST_VERSION = 1;
15
17
  const createManifest = ({ functions, path }) => __awaiter(void 0, void 0, void 0, function* () {
16
- const formattedFunctions = functions.map(formatFunction);
18
+ const formattedFunctions = functions.map(formatFunctionForManifest);
17
19
  const payload = {
18
20
  functions: formattedFunctions,
19
- system: { arch, platform },
21
+ system: { arch: process_1.arch, platform: process_1.platform },
20
22
  timestamp: Date.now(),
21
23
  version: MANIFEST_VERSION,
22
24
  };
23
- yield writeFile(path, JSON.stringify(payload));
25
+ yield (0, fs_1.writeFile)(path, JSON.stringify(payload));
26
+ });
27
+ exports.createManifest = createManifest;
28
+ const formatFunctionForManifest = ({ config, mainFile, name, path, runtime }) => ({
29
+ mainFile,
30
+ name,
31
+ path: (0, path_1.resolve)(path),
32
+ runtime,
33
+ schedule: config.schedule,
24
34
  });
25
- const formatFunction = ({ mainFile, name, path, runtime }) => ({ mainFile, name, path: resolve(path), runtime });
26
- module.exports = { createManifest };
27
35
  //# sourceMappingURL=manifest.js.map
@@ -1,4 +1,7 @@
1
- export function detectBinaryRuntime({ fsCache, path }: {
2
- fsCache: any;
3
- path: any;
4
- }): Promise<any>;
1
+ import { FsCache } from '../utils/fs';
2
+ import type { RuntimeName } from './runtime';
3
+ declare const detectBinaryRuntime: ({ fsCache, path, }: {
4
+ fsCache: FsCache;
5
+ path: string;
6
+ }) => Promise<RuntimeName | undefined>;
7
+ export { detectBinaryRuntime };
@@ -8,22 +8,30 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { detect, Runtime } = require('elf-cam');
12
- const { RUNTIME_GO, RUNTIME_RUST } = require('../utils/consts');
13
- const { cachedReadFile } = require('../utils/fs');
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.detectBinaryRuntime = void 0;
13
+ const elf_cam_1 = require("elf-cam");
14
+ const fs_1 = require("../utils/fs");
14
15
  // Try to guess the runtime by inspecting the binary file.
15
- const detectBinaryRuntime = function ({ fsCache, path }) {
16
+ const detectBinaryRuntime = function ({ fsCache, path, }) {
16
17
  return __awaiter(this, void 0, void 0, function* () {
17
18
  try {
18
- const buffer = yield cachedReadFile(fsCache, path);
19
- return RUNTIMES[detect(buffer)];
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
+ }
20
32
  }
21
33
  catch (error) { }
22
34
  });
23
35
  };
24
- const RUNTIMES = {
25
- [Runtime.Go]: RUNTIME_GO,
26
- [Runtime.Rust]: RUNTIME_RUST,
27
- };
28
- module.exports = { detectBinaryRuntime };
36
+ exports.detectBinaryRuntime = detectBinaryRuntime;
29
37
  //# sourceMappingURL=detect_runtime.js.map
@@ -1,12 +1,13 @@
1
1
  /// <reference types="node" />
2
- export function build({ destPath, mainFile, srcDir }: {
3
- destPath: any;
4
- mainFile: any;
5
- srcDir: any;
6
- }): Promise<{
7
- mainFile: any;
2
+ declare const build: ({ destPath, mainFile, srcDir }: {
3
+ destPath: string;
4
+ mainFile: string;
5
+ srcDir: string;
6
+ }) => Promise<{
7
+ mainFile: string;
8
8
  name: string;
9
- srcDir: any;
10
- srcPath: any;
9
+ srcDir: string;
10
+ srcPath: string;
11
11
  stat: import("fs").Stats;
12
12
  }>;
13
+ export { build };
@@ -8,14 +8,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- const { basename } = require('path');
12
- const { RUNTIME_GO } = require('../../utils/consts');
13
- const { lstat } = require('../../utils/fs');
14
- const { runCommand } = require('../../utils/shell');
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.build = void 0;
13
+ const path_1 = require("path");
14
+ const fs_1 = require("../../utils/fs");
15
+ const shell_1 = require("../../utils/shell");
15
16
  const build = ({ destPath, mainFile, srcDir }) => __awaiter(void 0, void 0, void 0, function* () {
16
- const functionName = basename(srcDir);
17
+ const functionName = (0, path_1.basename)(srcDir);
17
18
  try {
18
- yield runCommand('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
19
+ yield (0, shell_1.runCommand)('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
19
20
  cwd: srcDir,
20
21
  env: {
21
22
  CGO_ENABLED: '0',
@@ -24,11 +25,12 @@ const build = ({ destPath, mainFile, srcDir }) => __awaiter(void 0, void 0, void
24
25
  });
25
26
  }
26
27
  catch (error) {
27
- error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime: RUNTIME_GO } };
28
+ const runtime = 'go';
29
+ error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime } };
28
30
  console.error(`Could not compile Go function ${functionName}:\n`);
29
31
  throw error;
30
32
  }
31
- const stat = yield lstat(destPath);
33
+ const stat = yield (0, fs_1.lstat)(destPath);
32
34
  return {
33
35
  mainFile,
34
36
  name: functionName,
@@ -37,5 +39,5 @@ const build = ({ destPath, mainFile, srcDir }) => __awaiter(void 0, void 0, void
37
39
  stat,
38
40
  };
39
41
  });
40
- module.exports = { build };
42
+ exports.build = build;
41
43
  //# sourceMappingURL=builder.js.map
@@ -1,18 +1,3 @@
1
- export function findFunctionsInPaths({ featureFlags, fsCache, paths }: {
2
- featureFlags: any;
3
- fsCache: any;
4
- paths: any;
5
- }): Promise<any[]>;
6
- import { RUNTIME_GO } from "../../utils/consts";
7
- export function zipFunction({ config, destFolder, filename, mainFile, srcDir, srcPath }: {
8
- config: any;
9
- destFolder: any;
10
- filename: any;
11
- mainFile: any;
12
- srcDir: any;
13
- srcPath: any;
14
- }): Promise<{
15
- config: any;
16
- path: string;
17
- }>;
18
- export { RUNTIME_GO as name };
1
+ import { Runtime } from '../runtime';
2
+ declare const runtime: Runtime;
3
+ export default runtime;