@netlify/zip-it-and-ship-it 7.1.2 → 8.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/archive.js +12 -22
- package/dist/bin.js +7 -12
- package/dist/config.js +13 -18
- package/dist/feature_flags.js +10 -8
- package/dist/function.d.ts +1 -1
- package/dist/function.js +1 -2
- package/dist/main.d.ts +3 -3
- package/dist/main.js +26 -31
- package/dist/manifest.js +7 -11
- package/dist/runtimes/detect_runtime.d.ts +1 -3
- package/dist/runtimes/detect_runtime.js +9 -16
- package/dist/runtimes/go/builder.d.ts +1 -1
- package/dist/runtimes/go/builder.js +9 -13
- package/dist/runtimes/go/index.js +38 -45
- package/dist/runtimes/index.d.ts +5 -2
- package/dist/runtimes/index.js +17 -31
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +43 -36
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +3 -3
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +7 -11
- package/dist/runtimes/node/bundlers/esbuild/index.js +16 -18
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +20 -25
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +9 -16
- package/dist/runtimes/node/bundlers/esbuild/plugin_node_builtin.js +1 -5
- package/dist/runtimes/node/bundlers/esbuild/special_cases.js +3 -7
- package/dist/runtimes/node/bundlers/esbuild/src_files.js +13 -17
- package/dist/runtimes/node/bundlers/index.js +13 -21
- package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +3 -3
- package/dist/runtimes/node/bundlers/nft/es_modules.js +23 -26
- package/dist/runtimes/node/bundlers/nft/index.js +38 -36
- package/dist/runtimes/node/bundlers/nft/transpile.js +7 -11
- package/dist/runtimes/node/bundlers/none/index.js +18 -22
- package/dist/runtimes/node/bundlers/types.d.ts +2 -0
- package/dist/runtimes/node/bundlers/types.js +1 -2
- package/dist/runtimes/node/bundlers/zisi/index.js +8 -10
- package/dist/runtimes/node/bundlers/zisi/list_imports.js +10 -40
- package/dist/runtimes/node/bundlers/zisi/nested.js +7 -15
- package/dist/runtimes/node/bundlers/zisi/published.js +3 -7
- package/dist/runtimes/node/bundlers/zisi/resolve.js +17 -20
- package/dist/runtimes/node/bundlers/zisi/side_files.js +3 -7
- package/dist/runtimes/node/bundlers/zisi/src_files.js +29 -36
- package/dist/runtimes/node/bundlers/zisi/traverse.js +18 -22
- package/dist/runtimes/node/bundlers/zisi/tree_files.js +3 -7
- package/dist/runtimes/node/bundlers/zisi/tree_shake.js +3 -7
- package/dist/runtimes/node/finder.js +31 -37
- package/dist/runtimes/node/in_source_config/index.d.ts +1 -1
- package/dist/runtimes/node/in_source_config/index.js +17 -21
- package/dist/runtimes/node/in_source_config/properties/schedule.js +1 -5
- package/dist/runtimes/node/index.js +25 -28
- package/dist/runtimes/node/parser/bindings.js +2 -7
- package/dist/runtimes/node/parser/exports.js +7 -11
- package/dist/runtimes/node/parser/helpers.d.ts +1 -1
- package/dist/runtimes/node/parser/helpers.js +4 -11
- package/dist/runtimes/node/parser/imports.d.ts +1 -1
- package/dist/runtimes/node/parser/imports.js +7 -11
- package/dist/runtimes/node/parser/index.d.ts +1 -1
- package/dist/runtimes/node/parser/index.js +18 -19
- package/dist/runtimes/node/utils/base_path.js +3 -10
- package/dist/runtimes/node/utils/detect_es_module.js +5 -9
- package/dist/runtimes/node/utils/detect_native_module.js +3 -7
- package/dist/runtimes/node/utils/entry_file.js +3 -7
- package/dist/runtimes/node/utils/included_files.js +8 -13
- package/dist/runtimes/node/utils/module.js +3 -10
- package/dist/runtimes/node/utils/module_format.js +1 -5
- package/dist/runtimes/node/utils/node_version.js +5 -12
- package/dist/runtimes/node/utils/normalize_path.js +6 -13
- package/dist/runtimes/node/utils/package_json.d.ts +2 -1
- package/dist/runtimes/node/utils/package_json.js +20 -31
- package/dist/runtimes/node/utils/plugin_modules_path.js +6 -14
- package/dist/runtimes/node/utils/traversal_cache.js +1 -5
- package/dist/runtimes/node/utils/zip.d.ts +2 -0
- package/dist/runtimes/node/utils/zip.js +44 -51
- package/dist/runtimes/runtime.d.ts +8 -7
- package/dist/runtimes/runtime.js +1 -2
- package/dist/runtimes/rust/builder.d.ts +5 -3
- package/dist/runtimes/rust/builder.js +22 -28
- package/dist/runtimes/rust/cargo_manifest.js +1 -2
- package/dist/runtimes/rust/constants.js +2 -5
- package/dist/runtimes/rust/index.js +39 -43
- package/dist/utils/archive_size.js +5 -9
- package/dist/utils/cache.d.ts +16 -0
- package/dist/utils/cache.js +10 -0
- package/dist/utils/error.d.ts +1 -1
- package/dist/utils/error.js +1 -5
- package/dist/utils/format_result.js +4 -9
- package/dist/utils/fs.d.ts +5 -13
- package/dist/utils/fs.js +42 -39
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +15 -0
- package/dist/utils/matching.js +11 -19
- package/dist/utils/non_nullable.js +1 -5
- package/dist/utils/remove_undefined.js +4 -10
- package/dist/utils/shell.d.ts +1 -1
- package/dist/utils/shell.js +2 -8
- package/dist/utils/timer.d.ts +2 -0
- package/dist/utils/timer.js +12 -0
- package/dist/zip.d.ts +6 -3
- package/dist/zip.js +60 -34
- package/dist/zip_binary.js +6 -10
- package/package.json +23 -32
package/dist/archive.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.endZip = exports.addZipContent = exports.addZipFile = exports.startZip = void 0;
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const util_1 = require("util");
|
|
9
|
-
const archiver_1 = __importDefault(require("archiver"));
|
|
10
|
-
const end_of_stream_1 = __importDefault(require("end-of-stream"));
|
|
11
|
-
const pEndOfStream = (0, util_1.promisify)(end_of_stream_1.default);
|
|
1
|
+
import { createWriteStream, readlinkSync } from 'fs';
|
|
2
|
+
import { promisify } from 'util';
|
|
3
|
+
import archiver from 'archiver';
|
|
4
|
+
import endOfStream from 'end-of-stream';
|
|
5
|
+
const pEndOfStream = promisify(endOfStream);
|
|
12
6
|
// Start zipping files
|
|
13
|
-
const startZip = function (destPath) {
|
|
14
|
-
const output =
|
|
15
|
-
const archive = (
|
|
7
|
+
export const startZip = function (destPath) {
|
|
8
|
+
const output = createWriteStream(destPath);
|
|
9
|
+
const archive = archiver('zip');
|
|
16
10
|
archive.pipe(output);
|
|
17
11
|
return { archive, output };
|
|
18
12
|
};
|
|
19
|
-
exports.startZip = startZip;
|
|
20
13
|
// Add new file to zip
|
|
21
|
-
const addZipFile = function (archive, file, name, stat) {
|
|
14
|
+
export const addZipFile = function (archive, file, name, stat) {
|
|
22
15
|
if (stat.isSymbolicLink()) {
|
|
23
|
-
const linkContent =
|
|
16
|
+
const linkContent = readlinkSync(file);
|
|
24
17
|
archive.symlink(name, linkContent, stat.mode);
|
|
25
18
|
}
|
|
26
19
|
else {
|
|
@@ -33,16 +26,13 @@ const addZipFile = function (archive, file, name, stat) {
|
|
|
33
26
|
});
|
|
34
27
|
}
|
|
35
28
|
};
|
|
36
|
-
exports.addZipFile = addZipFile;
|
|
37
29
|
// Add new file content to zip
|
|
38
|
-
const addZipContent = function (archive, content, name) {
|
|
30
|
+
export const addZipContent = function (archive, content, name) {
|
|
39
31
|
archive.append(content, { name, date: new Date(0) });
|
|
40
32
|
};
|
|
41
|
-
exports.addZipContent = addZipContent;
|
|
42
33
|
// End zipping files
|
|
43
|
-
const endZip = async function (archive, output) {
|
|
34
|
+
export const endZip = async function (archive, output) {
|
|
44
35
|
archive.finalize();
|
|
45
36
|
await pEndOfStream(output);
|
|
46
37
|
};
|
|
47
|
-
exports.endZip = endZip;
|
|
48
38
|
//# sourceMappingURL=archive.js.map
|
package/dist/bin.js
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const process_1 = require("process");
|
|
8
|
-
const yargs_1 = __importDefault(require("yargs"));
|
|
9
|
-
const helpers_1 = require("yargs/helpers");
|
|
10
|
-
const main_js_1 = require("./main.js");
|
|
2
|
+
import { argv, exit } from 'process';
|
|
3
|
+
import yargs from 'yargs';
|
|
4
|
+
import { hideBin } from 'yargs/helpers';
|
|
5
|
+
import { zipFunctions } from './main.js';
|
|
11
6
|
// CLI entry point
|
|
12
7
|
const runCli = async function () {
|
|
13
8
|
// @ts-expect-error TODO: `destFolder` and `srcFolder` are not being passed
|
|
@@ -16,16 +11,16 @@ const runCli = async function () {
|
|
|
16
11
|
try {
|
|
17
12
|
global.ZISI_CLI = true;
|
|
18
13
|
// @ts-expect-error TODO: `options` is not getting the right types.
|
|
19
|
-
const zipped = await
|
|
14
|
+
const zipped = await zipFunctions(srcFolder, destFolder, options);
|
|
20
15
|
console.log(JSON.stringify(zipped, null, 2));
|
|
21
16
|
}
|
|
22
17
|
catch (error) {
|
|
23
18
|
console.error(error.toString());
|
|
24
|
-
|
|
19
|
+
exit(1);
|
|
25
20
|
}
|
|
26
21
|
};
|
|
27
22
|
const parseArgs = function () {
|
|
28
|
-
return (
|
|
23
|
+
return yargs(hideBin(argv))
|
|
29
24
|
.command('* <srcFolder> <destFolder>', 'Create ZIP archives from a directory')
|
|
30
25
|
.options(OPTIONS)
|
|
31
26
|
.usage(USAGE)
|
package/dist/config.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const fs_1 = require("fs");
|
|
8
|
-
const path_1 = require("path");
|
|
9
|
-
const is_path_inside_1 = __importDefault(require("is-path-inside"));
|
|
10
|
-
const merge_options_1 = __importDefault(require("merge-options"));
|
|
11
|
-
const matching_js_1 = require("./utils/matching.js");
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { basename, extname, dirname, join } from 'path';
|
|
3
|
+
import isPathInside from 'is-path-inside';
|
|
4
|
+
// @ts-expect-error Typescript cannot find definition
|
|
5
|
+
import mergeOptions from 'merge-options';
|
|
6
|
+
import { minimatch } from './utils/matching.js';
|
|
12
7
|
const getConfigForFunction = async ({ config, configFileDirectories, func, featureFlags, }) => {
|
|
13
8
|
const fromConfig = getFromMainConfig({ config, func });
|
|
14
9
|
// We try to read from a function config file if the function directory is
|
|
15
10
|
// inside one of `configFileDirectories`.
|
|
16
11
|
const shouldReadConfigFile = featureFlags.project_deploy_configuration_api_use_per_function_configuration_files &&
|
|
17
|
-
|
|
12
|
+
configFileDirectories?.some((directory) => isPathInside(func.mainFile, directory));
|
|
18
13
|
if (!shouldReadConfigFile) {
|
|
19
14
|
return fromConfig;
|
|
20
15
|
}
|
|
@@ -24,14 +19,13 @@ const getConfigForFunction = async ({ config, configFileDirectories, func, featu
|
|
|
24
19
|
...fromFile,
|
|
25
20
|
};
|
|
26
21
|
};
|
|
27
|
-
exports.getConfigForFunction = getConfigForFunction;
|
|
28
22
|
const getFromMainConfig = ({ config, func, }) => {
|
|
29
23
|
if (!config) {
|
|
30
24
|
return {};
|
|
31
25
|
}
|
|
32
26
|
// It's safe to mutate the array because it's local to this function.
|
|
33
27
|
const matches = Object.keys(config)
|
|
34
|
-
.filter((expression) =>
|
|
28
|
+
.filter((expression) => minimatch(func.name, expression))
|
|
35
29
|
.map((expression) => {
|
|
36
30
|
const wildcardCount = [...expression].filter((char) => char === '*').length;
|
|
37
31
|
// The weight increases with the number of hardcoded (i.e. non-wildcard)
|
|
@@ -46,13 +40,13 @@ const getFromMainConfig = ({ config, func, }) => {
|
|
|
46
40
|
})
|
|
47
41
|
.sort(({ weight: weightA }, { weight: weightB }) => weightA - weightB)
|
|
48
42
|
.map(({ expression }) => config[expression]);
|
|
49
|
-
return
|
|
43
|
+
return mergeOptions.apply({ concatArrays: true, ignoreUndefined: true }, matches);
|
|
50
44
|
};
|
|
51
45
|
const getFromFile = async (func) => {
|
|
52
|
-
const filename = `${
|
|
53
|
-
const configFilePath =
|
|
46
|
+
const filename = `${basename(func.mainFile, extname(func.mainFile))}.json`;
|
|
47
|
+
const configFilePath = join(dirname(func.mainFile), filename);
|
|
54
48
|
try {
|
|
55
|
-
const data = await
|
|
49
|
+
const data = await fs.readFile(configFilePath, 'utf8');
|
|
56
50
|
const configFile = JSON.parse(data);
|
|
57
51
|
if (configFile.version === 1) {
|
|
58
52
|
return configFile.config;
|
|
@@ -63,4 +57,5 @@ const getFromFile = async (func) => {
|
|
|
63
57
|
}
|
|
64
58
|
return {};
|
|
65
59
|
};
|
|
60
|
+
export { getConfigForFunction };
|
|
66
61
|
//# sourceMappingURL=config.js.map
|
package/dist/feature_flags.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.getFlags = exports.defaultFlags = void 0;
|
|
4
|
-
const process_1 = require("process");
|
|
5
|
-
exports.defaultFlags = {
|
|
1
|
+
import { env } from 'process';
|
|
2
|
+
export const defaultFlags = {
|
|
6
3
|
// Build Rust functions from source.
|
|
7
|
-
buildRustSource: Boolean(
|
|
4
|
+
buildRustSource: Boolean(env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
8
5
|
// Use esbuild to trace dependencies in the legacy bundler.
|
|
9
6
|
parseWithEsbuild: false,
|
|
10
7
|
// Use NFT as the default bundler.
|
|
@@ -17,11 +14,16 @@ exports.defaultFlags = {
|
|
|
17
14
|
zisi_pure_esm_mjs: false,
|
|
18
15
|
// Load configuration from per-function JSON files.
|
|
19
16
|
project_deploy_configuration_api_use_per_function_configuration_files: false,
|
|
17
|
+
// Enable runtime cache for NFT
|
|
18
|
+
zisi_nft_use_cache: false,
|
|
19
|
+
// Raise file IO limit for NFT
|
|
20
|
+
zisi_nft_higher_fileio_limit: false,
|
|
21
|
+
// Provide banner to esbuild which allows requires in ESM output
|
|
22
|
+
zisi_esbuild_require_banner: false,
|
|
20
23
|
};
|
|
21
24
|
// List of supported flags and their default value.
|
|
22
|
-
const getFlags = (input = {}, flags =
|
|
25
|
+
export const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
23
26
|
...result,
|
|
24
27
|
[key]: input[key] === undefined ? defaultValue : input[key],
|
|
25
28
|
}), {});
|
|
26
|
-
exports.getFlags = getFlags;
|
|
27
29
|
//# sourceMappingURL=feature_flags.js.map
|
package/dist/function.d.ts
CHANGED
package/dist/function.js
CHANGED
package/dist/main.d.ts
CHANGED
|
@@ -21,14 +21,14 @@ interface ListFunctionsOptions {
|
|
|
21
21
|
featureFlags?: FeatureFlags;
|
|
22
22
|
parseISC?: boolean;
|
|
23
23
|
}
|
|
24
|
-
export declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags, config, parseISC, }?: {
|
|
24
|
+
export declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags, config, parseISC, }?: {
|
|
25
25
|
featureFlags?: FeatureFlags | undefined;
|
|
26
26
|
config?: Config | undefined;
|
|
27
27
|
parseISC?: boolean | undefined;
|
|
28
28
|
}) => Promise<ListedFunction[]>;
|
|
29
|
-
export declare const listFunction: (path: string, { featureFlags, config, parseISC, }?: {
|
|
29
|
+
export declare const listFunction: (path: string, { featureFlags: inputFeatureFlags, config, parseISC, }?: {
|
|
30
30
|
featureFlags?: FeatureFlags | undefined;
|
|
31
31
|
config?: Config | undefined;
|
|
32
32
|
parseISC?: boolean | undefined;
|
|
33
33
|
}) => Promise<ListedFunction | undefined>;
|
|
34
|
-
export declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags, parseISC }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
|
|
34
|
+
export declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags: inputFeatureFlags, parseISC }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
|
package/dist/main.js
CHANGED
|
@@ -1,63 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_js_1 = require("./utils/fs.js");
|
|
9
|
-
var zip_js_1 = require("./zip.js");
|
|
10
|
-
Object.defineProperty(exports, "zipFunction", { enumerable: true, get: function () { return zip_js_1.zipFunction; } });
|
|
11
|
-
Object.defineProperty(exports, "zipFunctions", { enumerable: true, get: function () { return zip_js_1.zipFunctions; } });
|
|
1
|
+
import { extname } from 'path';
|
|
2
|
+
import { getFlags } from './feature_flags.js';
|
|
3
|
+
import { getFunctionFromPath, getFunctionsFromPaths } from './runtimes/index.js';
|
|
4
|
+
import { findISCDeclarationsInPath } from './runtimes/node/in_source_config/index.js';
|
|
5
|
+
import { RuntimeCache } from './utils/cache.js';
|
|
6
|
+
import { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js';
|
|
7
|
+
export { zipFunction, zipFunctions } from './zip.js';
|
|
12
8
|
const augmentWithISC = async (func) => {
|
|
13
9
|
// ISC is currently only supported in JavaScript and TypeScript functions.
|
|
14
10
|
if (func.runtime.name !== "js" /* RuntimeType.JAVASCRIPT */) {
|
|
15
11
|
return func;
|
|
16
12
|
}
|
|
17
|
-
const inSourceConfig = await
|
|
13
|
+
const inSourceConfig = await findISCDeclarationsInPath(func.mainFile, func.name);
|
|
18
14
|
return { ...func, inSourceConfig };
|
|
19
15
|
};
|
|
20
16
|
// List all Netlify Functions main entry files for a specific directory
|
|
21
|
-
const listFunctions = async function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
22
|
-
const featureFlags =
|
|
23
|
-
const srcFolders =
|
|
24
|
-
const paths = await
|
|
25
|
-
const
|
|
17
|
+
export const listFunctions = async function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
18
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
19
|
+
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
|
|
20
|
+
const paths = await listFunctionsDirectories(srcFolders);
|
|
21
|
+
const cache = new RuntimeCache();
|
|
22
|
+
const functionsMap = await getFunctionsFromPaths(paths, { cache, config, featureFlags });
|
|
26
23
|
const functions = [...functionsMap.values()];
|
|
27
24
|
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
28
25
|
return augmentedFunctions.map(getListedFunction);
|
|
29
26
|
};
|
|
30
|
-
exports.listFunctions = listFunctions;
|
|
31
27
|
// Finds a function at a specific path.
|
|
32
|
-
const listFunction = async function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
33
|
-
const featureFlags =
|
|
34
|
-
const
|
|
28
|
+
export const listFunction = async function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
29
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
30
|
+
const cache = new RuntimeCache();
|
|
31
|
+
const func = await getFunctionFromPath(path, { cache, config, featureFlags });
|
|
35
32
|
if (!func) {
|
|
36
33
|
return;
|
|
37
34
|
}
|
|
38
35
|
const augmentedFunction = parseISC ? await augmentWithISC(func) : func;
|
|
39
36
|
return getListedFunction(augmentedFunction);
|
|
40
37
|
};
|
|
41
|
-
exports.listFunction = listFunction;
|
|
42
38
|
// List all Netlify Functions files for a specific directory
|
|
43
|
-
const listFunctionsFiles = async function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags, parseISC = false } = {}) {
|
|
44
|
-
const featureFlags =
|
|
45
|
-
const srcFolders =
|
|
46
|
-
const paths = await
|
|
47
|
-
const
|
|
39
|
+
export const listFunctionsFiles = async function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags, parseISC = false } = {}) {
|
|
40
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
41
|
+
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
|
|
42
|
+
const paths = await listFunctionsDirectories(srcFolders);
|
|
43
|
+
const cache = new RuntimeCache();
|
|
44
|
+
const functionsMap = await getFunctionsFromPaths(paths, { cache, config, featureFlags });
|
|
48
45
|
const functions = [...functionsMap.values()];
|
|
49
46
|
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
50
47
|
const listedFunctionsFiles = await Promise.all(augmentedFunctions.map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
|
|
51
48
|
return listedFunctionsFiles.flat();
|
|
52
49
|
};
|
|
53
|
-
exports.listFunctionsFiles = listFunctionsFiles;
|
|
54
50
|
const getListedFunction = function ({ runtime, name, mainFile, extension, config, inSourceConfig, }) {
|
|
55
|
-
|
|
56
|
-
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 };
|
|
51
|
+
return { name, mainFile, runtime: runtime.name, extension, schedule: inSourceConfig?.schedule ?? config.schedule };
|
|
57
52
|
};
|
|
58
53
|
const getListedFunctionFiles = async function (func, options) {
|
|
59
54
|
const srcFiles = await getSrcFiles({ ...func, ...options });
|
|
60
|
-
return srcFiles.map((srcFile) => ({ ...getListedFunction(func), srcFile, extension:
|
|
55
|
+
return srcFiles.map((srcFile) => ({ ...getListedFunction(func), srcFile, extension: extname(srcFile) }));
|
|
61
56
|
};
|
|
62
57
|
const getSrcFiles = async function ({ extension, runtime, srcPath, ...args }) {
|
|
63
58
|
const { getSrcFiles: getRuntimeSrcFiles } = runtime;
|
package/dist/manifest.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const fs_1 = require("fs");
|
|
5
|
-
const path_1 = require("path");
|
|
6
|
-
const process_1 = require("process");
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { resolve } from 'path';
|
|
3
|
+
import { arch, platform } from 'process';
|
|
7
4
|
const MANIFEST_VERSION = 1;
|
|
8
|
-
const createManifest = async ({ functions, path }) => {
|
|
5
|
+
export const createManifest = async ({ functions, path }) => {
|
|
9
6
|
const formattedFunctions = functions.map(formatFunctionForManifest);
|
|
10
7
|
const payload = {
|
|
11
8
|
functions: formattedFunctions,
|
|
12
|
-
system: { arch
|
|
9
|
+
system: { arch, platform },
|
|
13
10
|
timestamp: Date.now(),
|
|
14
11
|
version: MANIFEST_VERSION,
|
|
15
12
|
};
|
|
16
|
-
await
|
|
13
|
+
await fs.writeFile(path, JSON.stringify(payload));
|
|
17
14
|
};
|
|
18
|
-
exports.createManifest = createManifest;
|
|
19
15
|
const formatFunctionForManifest = ({ mainFile, name, path, runtime, schedule }) => ({
|
|
20
16
|
mainFile,
|
|
21
17
|
name,
|
|
22
|
-
path:
|
|
18
|
+
path: resolve(path),
|
|
23
19
|
runtime,
|
|
24
20
|
schedule,
|
|
25
21
|
});
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { FsCache } from '../utils/fs.js';
|
|
2
1
|
import { RuntimeType } from './runtime.js';
|
|
3
|
-
export declare const detectBinaryRuntime: ({
|
|
4
|
-
fsCache: FsCache;
|
|
2
|
+
export declare const detectBinaryRuntime: ({ path }: {
|
|
5
3
|
path: string;
|
|
6
4
|
}) => Promise<RuntimeType | undefined>;
|
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const binary_info_1 = require("@netlify/binary-info");
|
|
5
|
-
const fs_js_1 = require("../utils/fs.js");
|
|
6
|
-
const isValidFunctionBinary = (info) => info.arch === binary_info_1.Arch.Amd64 && info.platform === binary_info_1.Platform.Linux;
|
|
1
|
+
import { readFile } from 'fs/promises';
|
|
2
|
+
import { detect, Runtime as BinaryRuntime, Arch, Platform } from '@netlify/binary-info';
|
|
3
|
+
const isValidFunctionBinary = (info) => info.arch === Arch.Amd64 && info.platform === Platform.Linux;
|
|
7
4
|
const warnIncompatibleBinary = function (path, binaryInfo) {
|
|
8
5
|
if (!global.ZISI_CLI) {
|
|
9
6
|
console.warn(`
|
|
10
7
|
Found incompatible prebuilt function binary in ${path}.
|
|
11
|
-
The binary needs to be built for Linux/Amd64, but it was built for ${
|
|
8
|
+
The binary needs to be built for Linux/Amd64, but it was built for ${Platform[binaryInfo.platform]}/${Arch[binaryInfo.arch]}`);
|
|
12
9
|
}
|
|
13
10
|
return undefined;
|
|
14
11
|
};
|
|
15
12
|
// Try to guess the runtime by inspecting the binary file.
|
|
16
|
-
const detectBinaryRuntime = async function ({
|
|
13
|
+
export const detectBinaryRuntime = async function ({ path }) {
|
|
17
14
|
try {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
// loses part of the return type information. We can safely say it's a
|
|
21
|
-
// Buffer in this case because we're not specifying an encoding.
|
|
22
|
-
const binaryInfo = (0, binary_info_1.detect)(buffer);
|
|
15
|
+
const fileContents = await readFile(path);
|
|
16
|
+
const binaryInfo = detect(fileContents);
|
|
23
17
|
if (!isValidFunctionBinary(binaryInfo)) {
|
|
24
18
|
return warnIncompatibleBinary(path, binaryInfo);
|
|
25
19
|
}
|
|
26
20
|
switch (binaryInfo.runtime) {
|
|
27
|
-
case
|
|
21
|
+
case BinaryRuntime.Go:
|
|
28
22
|
return "go" /* RuntimeType.GO */;
|
|
29
|
-
case
|
|
23
|
+
case BinaryRuntime.Rust:
|
|
30
24
|
return "rs" /* RuntimeType.RUST */;
|
|
31
25
|
default:
|
|
32
26
|
return undefined;
|
|
@@ -36,5 +30,4 @@ const detectBinaryRuntime = async function ({ fsCache, path, }) {
|
|
|
36
30
|
// Possible errors are: non binary files, arch/platforms not supported by binary-info, path is directory
|
|
37
31
|
}
|
|
38
32
|
};
|
|
39
|
-
exports.detectBinaryRuntime = detectBinaryRuntime;
|
|
40
33
|
//# sourceMappingURL=detect_runtime.js.map
|
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const shell_js_1 = require("../../utils/shell.js");
|
|
8
|
-
const build = async ({ destPath, mainFile, srcDir }) => {
|
|
9
|
-
const functionName = (0, path_1.basename)(srcDir);
|
|
1
|
+
import { promises as fs } from 'fs';
|
|
2
|
+
import { basename } from 'path';
|
|
3
|
+
import { FunctionBundlingUserError } from '../../utils/error.js';
|
|
4
|
+
import { shellUtils } from '../../utils/shell.js';
|
|
5
|
+
export const build = async ({ destPath, mainFile, srcDir }) => {
|
|
6
|
+
const functionName = basename(srcDir);
|
|
10
7
|
try {
|
|
11
|
-
await
|
|
8
|
+
await shellUtils.runCommand('go', ['build', '-o', destPath, '-ldflags', '-s -w'], {
|
|
12
9
|
cwd: srcDir,
|
|
13
10
|
env: {
|
|
14
11
|
CGO_ENABLED: '0',
|
|
@@ -19,9 +16,9 @@ const build = async ({ destPath, mainFile, srcDir }) => {
|
|
|
19
16
|
}
|
|
20
17
|
catch (error) {
|
|
21
18
|
console.error(`Could not compile Go function ${functionName}:\n`);
|
|
22
|
-
throw
|
|
19
|
+
throw FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: "go" /* RuntimeType.GO */ });
|
|
23
20
|
}
|
|
24
|
-
const stat = await
|
|
21
|
+
const stat = await fs.lstat(destPath);
|
|
25
22
|
return {
|
|
26
23
|
mainFile,
|
|
27
24
|
name: functionName,
|
|
@@ -30,5 +27,4 @@ const build = async ({ destPath, mainFile, srcDir }) => {
|
|
|
30
27
|
stat,
|
|
31
28
|
};
|
|
32
29
|
};
|
|
33
|
-
exports.build = build;
|
|
34
30
|
//# sourceMappingURL=builder.js.map
|
|
@@ -1,72 +1,65 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const zip_binary_js_1 = require("../../zip_binary.js");
|
|
11
|
-
const detect_runtime_js_1 = require("../detect_runtime.js");
|
|
12
|
-
const builder_js_1 = require("./builder.js");
|
|
13
|
-
const detectGoFunction = async ({ fsCache, path }) => {
|
|
14
|
-
const stat = await (0, fs_js_1.cachedLstat)(fsCache, path);
|
|
1
|
+
import { basename, dirname, extname, join } from 'path';
|
|
2
|
+
import { copyFile } from 'cp-file';
|
|
3
|
+
import { cachedLstat, cachedReaddir } from '../../utils/fs.js';
|
|
4
|
+
import { nonNullable } from '../../utils/non_nullable.js';
|
|
5
|
+
import { zipBinary } from '../../zip_binary.js';
|
|
6
|
+
import { detectBinaryRuntime } from '../detect_runtime.js';
|
|
7
|
+
import { build } from './builder.js';
|
|
8
|
+
const detectGoFunction = async ({ cache, path }) => {
|
|
9
|
+
const stat = await cachedLstat(cache.lstatCache, path);
|
|
15
10
|
if (!stat.isDirectory()) {
|
|
16
11
|
return;
|
|
17
12
|
}
|
|
18
|
-
const directoryName =
|
|
19
|
-
|
|
20
|
-
// return value of `readdir` to be incorrectly typed.
|
|
21
|
-
const files = (await (0, fs_js_1.cachedReaddir)(fsCache, path));
|
|
13
|
+
const directoryName = basename(path);
|
|
14
|
+
const files = await cachedReaddir(cache.readdirCache, path);
|
|
22
15
|
const mainFileName = [`${directoryName}.go`, 'main.go'].find((name) => files.includes(name));
|
|
23
16
|
if (mainFileName === undefined) {
|
|
24
17
|
return;
|
|
25
18
|
}
|
|
26
19
|
return mainFileName;
|
|
27
20
|
};
|
|
28
|
-
const findFunctionsInPaths = async function ({
|
|
29
|
-
const functions = await Promise.all(paths.map((path) => findFunctionInPath({
|
|
30
|
-
return functions.filter(
|
|
21
|
+
const findFunctionsInPaths = async function ({ cache, featureFlags, paths }) {
|
|
22
|
+
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ cache, featureFlags, path })));
|
|
23
|
+
return functions.filter(nonNullable);
|
|
31
24
|
};
|
|
32
|
-
const findFunctionInPath = async function ({
|
|
33
|
-
const runtime = await
|
|
25
|
+
const findFunctionInPath = async function ({ cache, path }) {
|
|
26
|
+
const runtime = await detectBinaryRuntime({ path });
|
|
34
27
|
if (runtime === "go" /* RuntimeType.GO */) {
|
|
35
|
-
return processBinary({
|
|
28
|
+
return processBinary({ cache, path });
|
|
36
29
|
}
|
|
37
|
-
const goSourceFile = await detectGoFunction({
|
|
30
|
+
const goSourceFile = await detectGoFunction({ cache, path });
|
|
38
31
|
if (goSourceFile) {
|
|
39
|
-
return processSource({
|
|
32
|
+
return processSource({ cache, mainFile: goSourceFile, path });
|
|
40
33
|
}
|
|
41
34
|
};
|
|
42
|
-
const processBinary = async ({
|
|
43
|
-
const stat =
|
|
44
|
-
const extension =
|
|
45
|
-
const filename =
|
|
46
|
-
const name =
|
|
35
|
+
const processBinary = async ({ cache, path }) => {
|
|
36
|
+
const stat = await cachedLstat(cache.lstatCache, path);
|
|
37
|
+
const extension = extname(path);
|
|
38
|
+
const filename = basename(path);
|
|
39
|
+
const name = basename(path, extname(path));
|
|
47
40
|
return {
|
|
48
41
|
extension,
|
|
49
42
|
filename,
|
|
50
43
|
mainFile: path,
|
|
51
44
|
name,
|
|
52
|
-
srcDir:
|
|
45
|
+
srcDir: dirname(path),
|
|
53
46
|
srcPath: path,
|
|
54
47
|
stat,
|
|
55
48
|
};
|
|
56
49
|
};
|
|
57
|
-
const processSource = async ({
|
|
50
|
+
const processSource = async ({ cache, mainFile, path, }) => {
|
|
58
51
|
// TODO: This `stat` value is not going to be used, but we need it to satisfy
|
|
59
52
|
// the `FunctionSource` interface. We should revisit whether `stat` should be
|
|
60
53
|
// part of that interface in the first place, or whether we could compute it
|
|
61
54
|
// downstream when needed (maybe using the FS cache as an optimisation).
|
|
62
|
-
const stat = (await (
|
|
63
|
-
const filename =
|
|
64
|
-
const extension =
|
|
65
|
-
const name =
|
|
55
|
+
const stat = (await cachedLstat(cache.lstatCache, path));
|
|
56
|
+
const filename = basename(path);
|
|
57
|
+
const extension = extname(mainFile);
|
|
58
|
+
const name = basename(path, extname(path));
|
|
66
59
|
return {
|
|
67
60
|
extension,
|
|
68
61
|
filename,
|
|
69
|
-
mainFile:
|
|
62
|
+
mainFile: join(path, mainFile),
|
|
70
63
|
name,
|
|
71
64
|
srcDir: path,
|
|
72
65
|
srcPath: path,
|
|
@@ -74,8 +67,8 @@ const processSource = async ({ fsCache, mainFile, path, }) => {
|
|
|
74
67
|
};
|
|
75
68
|
};
|
|
76
69
|
const zipFunction = async function ({ config, destFolder, filename, mainFile, srcDir, srcPath, stat }) {
|
|
77
|
-
const destPath =
|
|
78
|
-
const isSource =
|
|
70
|
+
const destPath = join(destFolder, filename);
|
|
71
|
+
const isSource = extname(mainFile) === '.go';
|
|
79
72
|
let binary = {
|
|
80
73
|
path: srcPath,
|
|
81
74
|
stat,
|
|
@@ -83,7 +76,7 @@ const zipFunction = async function ({ config, destFolder, filename, mainFile, sr
|
|
|
83
76
|
// If we're building a Go function from source, we call the build method and
|
|
84
77
|
// update `binary` to point to the newly-created binary.
|
|
85
78
|
if (isSource) {
|
|
86
|
-
const { stat: binaryStat } = await
|
|
79
|
+
const { stat: binaryStat } = await build({ destPath, mainFile, srcDir });
|
|
87
80
|
binary = {
|
|
88
81
|
path: destPath,
|
|
89
82
|
stat: binaryStat,
|
|
@@ -95,20 +88,20 @@ const zipFunction = async function ({ config, destFolder, filename, mainFile, sr
|
|
|
95
88
|
const zipPath = `${destPath}.zip`;
|
|
96
89
|
const zipOptions = {
|
|
97
90
|
destPath: zipPath,
|
|
98
|
-
filename:
|
|
91
|
+
filename: basename(destPath),
|
|
99
92
|
runtime,
|
|
100
93
|
};
|
|
101
|
-
await
|
|
94
|
+
await zipBinary({ ...zipOptions, srcPath: binary.path, stat: binary.stat });
|
|
102
95
|
return { config, path: zipPath };
|
|
103
96
|
}
|
|
104
97
|
// We don't need to zip the binary, so we can just copy it to the right path.
|
|
105
98
|
// We do this only if we're not building from source, as otherwise the build
|
|
106
99
|
// step already handled that.
|
|
107
100
|
if (!isSource) {
|
|
108
|
-
await (
|
|
101
|
+
await copyFile(binary.path, destPath);
|
|
109
102
|
}
|
|
110
103
|
return { config, path: destPath };
|
|
111
104
|
};
|
|
112
105
|
const runtime = { findFunctionsInPaths, findFunctionInPath, name: "go" /* RuntimeType.GO */, zipFunction };
|
|
113
|
-
|
|
106
|
+
export default runtime;
|
|
114
107
|
//# sourceMappingURL=index.js.map
|
package/dist/runtimes/index.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Config } from '../config.js';
|
|
2
2
|
import { FeatureFlags } from '../feature_flags.js';
|
|
3
3
|
import { FunctionSource } from '../function.js';
|
|
4
|
+
import type { RuntimeCache } from '../utils/cache.js';
|
|
4
5
|
declare type FunctionMap = Map<string, FunctionSource>;
|
|
5
6
|
/**
|
|
6
7
|
* Gets a list of functions found in a list of paths.
|
|
7
8
|
*/
|
|
8
|
-
export declare const getFunctionsFromPaths: (paths: string[], { config, configFileDirectories, dedupe, featureFlags, }
|
|
9
|
+
export declare const getFunctionsFromPaths: (paths: string[], { cache, config, configFileDirectories, dedupe, featureFlags, }: {
|
|
10
|
+
cache: RuntimeCache;
|
|
9
11
|
config?: Config | undefined;
|
|
10
12
|
configFileDirectories?: string[] | undefined;
|
|
11
13
|
dedupe?: boolean | undefined;
|
|
@@ -14,7 +16,8 @@ export declare const getFunctionsFromPaths: (paths: string[], { config, configFi
|
|
|
14
16
|
/**
|
|
15
17
|
* Gets a list of functions found in a list of paths.
|
|
16
18
|
*/
|
|
17
|
-
export declare const getFunctionFromPath: (path: string, { config, featureFlags }
|
|
19
|
+
export declare const getFunctionFromPath: (path: string, { cache, config, featureFlags }: {
|
|
20
|
+
cache: RuntimeCache;
|
|
18
21
|
config?: Config | undefined;
|
|
19
22
|
featureFlags?: FeatureFlags | undefined;
|
|
20
23
|
}) => Promise<FunctionSource | undefined>;
|