@netlify/zip-it-and-ship-it 5.3.0 → 5.4.0-isc-listfunctions

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.
@@ -1,6 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import { Stats } from 'fs';
3
3
  import type { FunctionConfig } from './config';
4
+ import { ISCValues } from './runtimes/node/in_source_config';
4
5
  import type { Runtime, ZipFunctionResult } from './runtimes/runtime';
5
6
  declare type FunctionArchive = ZipFunctionResult & {
6
7
  mainFile: string;
@@ -16,6 +17,7 @@ interface SourceFile {
16
17
  srcDir: string;
17
18
  srcPath: string;
18
19
  stat: Stats;
20
+ inSourceConfig?: ISCValues;
19
21
  }
20
22
  declare type FunctionSource = SourceFile & {
21
23
  config: FunctionConfig;
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;
@@ -15,9 +16,14 @@ interface ListFunctionsOptions {
15
16
  config?: Config;
16
17
  featureFlags?: FeatureFlags;
17
18
  }
18
- declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags }?: {
19
- featureFlags?: FeatureFlags;
19
+ declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags, config }?: {
20
+ featureFlags?: FeatureFlags | undefined;
21
+ config?: Config | undefined;
20
22
  }) => Promise<ListedFunction[]>;
23
+ declare const listFunction: (mainFile: string, { featureFlags: inputFeatureFlags, config }?: {
24
+ featureFlags?: FeatureFlags | undefined;
25
+ config?: Config | undefined;
26
+ }) => Promise<ListedFunction | undefined>;
21
27
  declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
22
- export { listFunctions, listFunctionsFiles };
28
+ export { listFunctions, listFunction, listFunctionsFiles };
23
29
  export { zipFunction, zipFunctions } from './zip';
package/dist/main.js CHANGED
@@ -20,23 +20,35 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  return t;
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
- exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunctions = void 0;
23
+ exports.zipFunctions = exports.zipFunction = exports.listFunctionsFiles = exports.listFunction = exports.listFunctions = void 0;
24
24
  const path_1 = require("path");
25
25
  const feature_flags_1 = require("./feature_flags");
26
26
  const runtimes_1 = require("./runtimes");
27
27
  const fs_1 = require("./utils/fs");
28
28
  // List all Netlify Functions main entry files for a specific directory
29
- const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags } = {}) {
29
+ const listFunctions = function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config } = {}) {
30
30
  return __awaiter(this, void 0, void 0, function* () {
31
31
  const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
32
32
  const srcFolders = (0, fs_1.resolveFunctionsDirectories)(relativeSrcFolders);
33
33
  const paths = yield (0, fs_1.listFunctionsDirectories)(srcFolders);
34
- const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags });
34
+ const functions = yield (0, runtimes_1.getFunctionsFromPaths)(paths, { featureFlags, config });
35
35
  const listedFunctions = [...functions.values()].map(getListedFunction);
36
36
  return listedFunctions;
37
37
  });
38
38
  };
39
39
  exports.listFunctions = listFunctions;
40
+ // List one Netlify Functions main entry file for a specific directory
41
+ const listFunction = function (mainFile, { featureFlags: inputFeatureFlags, config } = {}) {
42
+ return __awaiter(this, void 0, void 0, function* () {
43
+ const featureFlags = (0, feature_flags_1.getFlags)(inputFeatureFlags);
44
+ const func = yield (0, runtimes_1.getFunctionFromPath)(mainFile, { featureFlags, config });
45
+ if (!func) {
46
+ return;
47
+ }
48
+ return getListedFunction(func);
49
+ });
50
+ };
51
+ exports.listFunction = listFunction;
40
52
  // List all Netlify Functions files for a specific directory
41
53
  const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags } = {}) {
42
54
  return __awaiter(this, void 0, void 0, function* () {
@@ -49,14 +61,14 @@ const listFunctionsFiles = function (relativeSrcFolders, { basePath, config, fea
49
61
  });
50
62
  };
51
63
  exports.listFunctionsFiles = listFunctionsFiles;
52
- const getListedFunction = function ({ runtime, name, mainFile, extension }) {
53
- return { name, mainFile, runtime: runtime.name, extension };
64
+ const getListedFunction = function ({ runtime, name, mainFile, extension, config, inSourceConfig, }) {
65
+ var _a;
66
+ 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
67
  };
55
68
  const getListedFunctionFiles = function (func, options) {
56
69
  return __awaiter(this, void 0, void 0, function* () {
57
70
  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) }));
71
+ return srcFiles.map((srcFile) => (Object.assign(Object.assign({}, getListedFunction(func)), { srcFile, extension: (0, path_1.extname)(srcFile) })));
60
72
  });
61
73
  };
62
74
  const getSrcFiles = function (_a) {
@@ -35,22 +35,25 @@ const detectGoFunction = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0
35
35
  });
36
36
  const findFunctionsInPaths = function ({ featureFlags, fsCache, paths }) {
37
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
- })));
38
+ const functions = yield Promise.all(paths.map((path) => getFunctionAtPath(path, { featureFlags, fsCache })));
51
39
  return functions.filter(non_nullable_1.nonNullable);
52
40
  });
53
41
  };
42
+ const getFunctionAtPath = function (path, { featureFlags, fsCache }) {
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
+ });
56
+ };
54
57
  const processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, function* () {
55
58
  const stat = (yield (0, fs_1.cachedLstat)(fsCache, path));
56
59
  const extension = (0, path_1.extname)(path);
@@ -96,6 +99,6 @@ const zipFunction = function ({ config, destFolder, filename, mainFile, srcDir,
96
99
  return { config, path: destPath };
97
100
  });
98
101
  };
99
- const runtime = { findFunctionsInPaths, name: 'go', zipFunction };
102
+ const runtime = { findFunctionsInPaths, getFunctionAtPath, name: 'go', zipFunction };
100
103
  exports.default = runtime;
101
104
  //# 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 };
@@ -12,7 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.getFunctionsFromPaths = void 0;
15
+ exports.getFunctionFromPath = exports.getFunctionsFromPaths = void 0;
16
16
  const path_1 = require("path");
17
17
  const config_1 = require("../config");
18
18
  const feature_flags_1 = require("../feature_flags");
@@ -42,23 +42,24 @@ const findFunctionsInRuntime = function ({ dedupe = false, featureFlags, fsCache
42
42
  return { functions: augmentedFunctions, remainingPaths };
43
43
  });
44
44
  };
45
+ // An object to cache filesystem operations. This allows different functions
46
+ // to perform IO operations on the same file (i.e. getting its stats or its
47
+ // contents) without duplicating work.
48
+ const makeFsCache = () => ({});
49
+ // The order of this array determines the priority of the runtimes. If a path
50
+ // is used by the first time, it won't be made available to the subsequent
51
+ // runtimes.
52
+ const RUNTIMES = [node_1.default, go_1.default, rust_1.default];
45
53
  /**
46
54
  * Gets a list of functions found in a list of paths.
47
55
  */
48
56
  const getFunctionsFromPaths = (paths, { config, dedupe = false, featureFlags = feature_flags_1.defaultFlags, } = {}) => __awaiter(void 0, void 0, void 0, function* () {
49
- // An object to cache filesystem operations. This allows different functions
50
- // to perform IO operations on the same file (i.e. getting its stats or its
51
- // contents) without duplicating work.
52
- const fsCache = {};
53
- // The order of this array determines the priority of the runtimes. If a path
54
- // is used by the first time, it won't be made available to the subsequent
55
- // runtimes.
56
- const runtimes = [node_1.default, go_1.default, rust_1.default];
57
+ const fsCache = makeFsCache();
57
58
  // We cycle through the ordered array of runtimes, passing each one of them
58
59
  // through `findFunctionsInRuntime`. For each iteration, we collect all the
59
60
  // functions found plus the list of paths that still need to be evaluated,
60
61
  // using them as the input for the next iteration until the last runtime.
61
- const { functions } = yield runtimes.reduce((aggregate, runtime) => __awaiter(void 0, void 0, void 0, function* () {
62
+ const { functions } = yield RUNTIMES.reduce((aggregate, runtime) => __awaiter(void 0, void 0, void 0, function* () {
62
63
  const { functions: aggregateFunctions, remainingPaths: aggregatePaths } = yield aggregate;
63
64
  const { functions: runtimeFunctions, remainingPaths: runtimePaths } = yield findFunctionsInRuntime({
64
65
  dedupe,
@@ -79,4 +80,19 @@ const getFunctionsFromPaths = (paths, { config, dedupe = false, featureFlags = f
79
80
  return new Map(functionsWithConfig);
80
81
  });
81
82
  exports.getFunctionsFromPaths = getFunctionsFromPaths;
83
+ /**
84
+ * Gets a list of functions found in a list of paths.
85
+ */
86
+ const getFunctionFromPath = (path, { config, featureFlags = feature_flags_1.defaultFlags } = {}) => __awaiter(void 0, void 0, void 0, function* () {
87
+ const fsCache = makeFsCache();
88
+ for (const runtime of RUNTIMES) {
89
+ // eslint-disable-next-line no-await-in-loop
90
+ const func = yield runtime.getFunctionAtPath(path, { fsCache, featureFlags });
91
+ if (func) {
92
+ return Object.assign(Object.assign({}, func), { runtime, config: (0, config_1.getConfigForFunction)({ config, func: Object.assign(Object.assign({}, func), { runtime }) }) });
93
+ }
94
+ }
95
+ return undefined;
96
+ });
97
+ exports.getFunctionFromPath = getFunctionFromPath;
82
98
  //# sourceMappingURL=index.js.map
@@ -1,6 +1,4 @@
1
- import { SourceFile } from '../../function';
2
- declare const findFunctionsInPaths: ({ paths }: {
3
- paths: string[];
4
- }) => Promise<SourceFile[]>;
5
- declare const getFunctionAtPath: (srcPath: string) => Promise<SourceFile | undefined>;
1
+ import { FindFunctionsInPathsFunction, GetFunctionAtPathFunction } from '../runtime';
2
+ declare const findFunctionsInPaths: FindFunctionsInPathsFunction;
3
+ declare const getFunctionAtPath: GetFunctionAtPathFunction;
6
4
  export { findFunctionsInPaths, getFunctionAtPath };
@@ -18,6 +18,7 @@ const path_1 = require("path");
18
18
  const util_1 = require("util");
19
19
  const locate_path_1 = __importDefault(require("locate-path"));
20
20
  const non_nullable_1 = require("../../utils/non_nullable");
21
+ const in_source_config_1 = require("./in_source_config");
21
22
  const pLstat = (0, util_1.promisify)(fs_1.lstat);
22
23
  // List of extensions that this runtime will look for, in order of precedence.
23
24
  const allowedExtensions = ['.js', '.zip', '.cjs', '.mjs', '.ts'];
@@ -30,9 +31,9 @@ const sortByExtension = (fA, fB) => {
30
31
  const indexB = allowedExtensions.indexOf(fB.extension);
31
32
  return indexB - indexA;
32
33
  };
33
- const findFunctionsInPaths = function ({ paths }) {
34
+ const findFunctionsInPaths = function ({ paths, fsCache, featureFlags }) {
34
35
  return __awaiter(this, void 0, void 0, function* () {
35
- const functions = yield Promise.all(paths.map(getFunctionAtPath));
36
+ const functions = yield Promise.all(paths.map((path) => getFunctionAtPath(path, { fsCache, featureFlags })));
36
37
  // It's fine to mutate the array since its scope is local to this function.
37
38
  const sortedFunctions = functions.filter(non_nullable_1.nonNullable).sort((fA, fB) => {
38
39
  // We first sort the functions array to put directories first. This is so
@@ -63,10 +64,11 @@ const getFunctionAtPath = function (srcPath) {
63
64
  if (mainFile === undefined) {
64
65
  return;
65
66
  }
67
+ const iscValues = yield (0, in_source_config_1.findISCDeclarationsInPath)(mainFile);
66
68
  const extension = (0, path_1.extname)(srcPath);
67
69
  const srcDir = stat.isDirectory() ? srcPath : (0, path_1.dirname)(srcPath);
68
70
  const name = (0, path_1.basename)(srcPath, (0, path_1.extname)(srcPath));
69
- return { extension, filename, mainFile, name, srcDir, srcPath, stat };
71
+ return { extension, filename, mainFile, name, srcDir, srcPath, stat, inSourceConfig: iscValues };
70
72
  });
71
73
  };
72
74
  exports.getFunctionAtPath = getFunctionAtPath;
@@ -138,6 +138,7 @@ const zipWithFunctionWithFallback = (_a) => __awaiter(void 0, void 0, void 0, fu
138
138
  });
139
139
  const runtime = {
140
140
  findFunctionsInPaths: finder_1.findFunctionsInPaths,
141
+ getFunctionAtPath: finder_1.getFunctionAtPath,
141
142
  getSrcFiles: getSrcFilesWithBundler,
142
143
  name: 'js',
143
144
  zipFunction: zipWithFunctionWithFallback,
@@ -11,6 +11,10 @@ declare type FindFunctionsInPathsFunction = (args: {
11
11
  fsCache: FsCache;
12
12
  paths: string[];
13
13
  }) => Promise<SourceFile[]>;
14
+ declare type GetFunctionAtPathFunction = (path: string, args: {
15
+ featureFlags: FeatureFlags;
16
+ fsCache: FsCache;
17
+ }) => Promise<SourceFile | undefined>;
14
18
  declare type GetSrcFilesFunction = (args: {
15
19
  basePath?: string;
16
20
  config: FunctionConfig;
@@ -38,8 +42,9 @@ declare type ZipFunction = (args: {
38
42
  } & FunctionSource) => Promise<ZipFunctionResult>;
39
43
  interface Runtime {
40
44
  findFunctionsInPaths: FindFunctionsInPathsFunction;
45
+ getFunctionAtPath: GetFunctionAtPathFunction;
41
46
  getSrcFiles?: GetSrcFilesFunction;
42
47
  name: RuntimeName;
43
48
  zipFunction: ZipFunction;
44
49
  }
45
- export { FindFunctionsInPathsFunction, GetSrcFilesFunction, Runtime, RuntimeName, ZipFunction, ZipFunctionResult };
50
+ export { FindFunctionsInPathsFunction, GetSrcFilesFunction, Runtime, RuntimeName, ZipFunction, ZipFunctionResult, GetFunctionAtPathFunction, };
@@ -41,22 +41,28 @@ const detectRustFunction = ({ fsCache, path }) => __awaiter(void 0, void 0, void
41
41
  });
42
42
  const findFunctionsInPaths = function ({ featureFlags, fsCache, paths, }) {
43
43
  return __awaiter(this, void 0, void 0, function* () {
44
- const functions = yield Promise.all(paths.map((path) => __awaiter(this, void 0, void 0, function* () {
45
- const runtime = yield (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
46
- if (runtime === 'rs') {
47
- return processBinary({ fsCache, path });
48
- }
49
- if (featureFlags.buildRustSource !== true) {
50
- return;
51
- }
52
- const rustSourceFile = yield detectRustFunction({ fsCache, path });
53
- if (rustSourceFile) {
54
- return processSource({ fsCache, mainFile: rustSourceFile, path });
55
- }
44
+ const functions = yield Promise.all(paths.map((path) => getFunctionAtPath(path, {
45
+ featureFlags,
46
+ fsCache,
56
47
  })));
57
48
  return functions.filter(non_nullable_1.nonNullable);
58
49
  });
59
50
  };
51
+ const getFunctionAtPath = function (path, { featureFlags, fsCache, }) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ const runtime = yield (0, detect_runtime_1.detectBinaryRuntime)({ fsCache, path });
54
+ if (runtime === 'rs') {
55
+ return processBinary({ fsCache, path });
56
+ }
57
+ if (featureFlags.buildRustSource !== true) {
58
+ return;
59
+ }
60
+ const rustSourceFile = yield detectRustFunction({ fsCache, path });
61
+ if (rustSourceFile) {
62
+ return processSource({ fsCache, mainFile: rustSourceFile, path });
63
+ }
64
+ });
65
+ };
60
66
  const processBinary = ({ fsCache, path }) => __awaiter(void 0, void 0, void 0, function* () {
61
67
  const stat = (yield (0, fs_1.cachedLstat)(fsCache, path));
62
68
  const filename = (0, path_1.basename)(path);
@@ -116,6 +122,6 @@ const zipFunction = function ({ config, destFolder, filename, mainFile, runtime,
116
122
  return { config, path: destPath };
117
123
  });
118
124
  };
119
- const runtime = { findFunctionsInPaths, name: 'rs', zipFunction };
125
+ const runtime = { findFunctionsInPaths, getFunctionAtPath, name: 'rs', zipFunction };
120
126
  exports.default = runtime;
121
127
  //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "5.3.0",
3
+ "version": "5.4.0-isc-listfunctions",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {
@@ -93,7 +93,7 @@
93
93
  },
94
94
  "devDependencies": {
95
95
  "@babel/types": "^7.15.6",
96
- "@netlify/eslint-config-node": "^4.0.0",
96
+ "@netlify/eslint-config-node": "^4.0.1",
97
97
  "@types/archiver": "^5.1.1",
98
98
  "@types/end-of-stream": "^1.4.1",
99
99
  "@types/resolve": "^1.20.1",