@netlify/zip-it-and-ship-it 7.1.2 → 8.0.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 +4 -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 +22 -31
- package/dist/manifest.js +7 -11
- package/dist/runtimes/detect_runtime.js +9 -13
- package/dist/runtimes/go/builder.d.ts +1 -1
- package/dist/runtimes/go/builder.js +9 -13
- package/dist/runtimes/go/index.js +29 -34
- package/dist/runtimes/index.js +13 -21
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +32 -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 +15 -22
- 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 +12 -16
- package/dist/runtimes/node/bundlers/index.js +13 -21
- package/dist/runtimes/node/bundlers/nft/es_modules.js +14 -18
- package/dist/runtimes/node/bundlers/nft/index.js +31 -32
- 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.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 +29 -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 +22 -27
- 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 +14 -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.js +17 -28
- 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.js +41 -48
- package/dist/runtimes/runtime.js +1 -2
- package/dist/runtimes/rust/builder.d.ts +1 -1
- package/dist/runtimes/rust/builder.js +21 -28
- package/dist/runtimes/rust/cargo_manifest.js +1 -2
- package/dist/runtimes/rust/constants.js +2 -5
- package/dist/runtimes/rust/index.js +29 -31
- package/dist/utils/archive_size.js +5 -9
- 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 +6 -8
- package/dist/utils/fs.js +19 -27
- package/dist/utils/matching.js +11 -19
- package/dist/utils/non_nullable.js +1 -5
- package/dist/utils/remove_undefined.js +3 -10
- package/dist/utils/shell.d.ts +1 -1
- package/dist/utils/shell.js +2 -8
- package/dist/zip.d.ts +3 -3
- package/dist/zip.js +26 -34
- package/dist/zip_binary.js +6 -10
- package/package.json +20 -28
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.
|
|
@@ -19,9 +16,8 @@ exports.defaultFlags = {
|
|
|
19
16
|
project_deploy_configuration_api_use_per_function_configuration_files: false,
|
|
20
17
|
};
|
|
21
18
|
// List of supported flags and their default value.
|
|
22
|
-
const getFlags = (input = {}, flags =
|
|
19
|
+
export const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
|
23
20
|
...result,
|
|
24
21
|
[key]: input[key] === undefined ? defaultValue : input[key],
|
|
25
22
|
}), {});
|
|
26
|
-
exports.getFlags = getFlags;
|
|
27
23
|
//# 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,54 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const index_js_2 = require("./runtimes/node/in_source_config/index.js");
|
|
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 { listFunctionsDirectories, resolveFunctionsDirectories } from './utils/fs.js';
|
|
6
|
+
export { zipFunction, zipFunctions } from './zip.js';
|
|
12
7
|
const augmentWithISC = async (func) => {
|
|
13
8
|
// ISC is currently only supported in JavaScript and TypeScript functions.
|
|
14
9
|
if (func.runtime.name !== "js" /* RuntimeType.JAVASCRIPT */) {
|
|
15
10
|
return func;
|
|
16
11
|
}
|
|
17
|
-
const inSourceConfig = await
|
|
12
|
+
const inSourceConfig = await findISCDeclarationsInPath(func.mainFile, func.name);
|
|
18
13
|
return { ...func, inSourceConfig };
|
|
19
14
|
};
|
|
20
15
|
// 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 functionsMap = await
|
|
16
|
+
export const listFunctions = async function (relativeSrcFolders, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
17
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
18
|
+
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
|
|
19
|
+
const paths = await listFunctionsDirectories(srcFolders);
|
|
20
|
+
const functionsMap = await getFunctionsFromPaths(paths, { featureFlags, config });
|
|
26
21
|
const functions = [...functionsMap.values()];
|
|
27
22
|
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
28
23
|
return augmentedFunctions.map(getListedFunction);
|
|
29
24
|
};
|
|
30
|
-
exports.listFunctions = listFunctions;
|
|
31
25
|
// Finds a function at a specific path.
|
|
32
|
-
const listFunction = async function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
33
|
-
const featureFlags =
|
|
34
|
-
const func = await
|
|
26
|
+
export const listFunction = async function (path, { featureFlags: inputFeatureFlags, config, parseISC = false, } = {}) {
|
|
27
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
28
|
+
const func = await getFunctionFromPath(path, { featureFlags, config });
|
|
35
29
|
if (!func) {
|
|
36
30
|
return;
|
|
37
31
|
}
|
|
38
32
|
const augmentedFunction = parseISC ? await augmentWithISC(func) : func;
|
|
39
33
|
return getListedFunction(augmentedFunction);
|
|
40
34
|
};
|
|
41
|
-
exports.listFunction = listFunction;
|
|
42
35
|
// 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 functionsMap = await
|
|
36
|
+
export const listFunctionsFiles = async function (relativeSrcFolders, { basePath, config, featureFlags: inputFeatureFlags, parseISC = false } = {}) {
|
|
37
|
+
const featureFlags = getFlags(inputFeatureFlags);
|
|
38
|
+
const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
|
|
39
|
+
const paths = await listFunctionsDirectories(srcFolders);
|
|
40
|
+
const functionsMap = await getFunctionsFromPaths(paths, { config, featureFlags });
|
|
48
41
|
const functions = [...functionsMap.values()];
|
|
49
42
|
const augmentedFunctions = parseISC ? await Promise.all(functions.map(augmentWithISC)) : functions;
|
|
50
43
|
const listedFunctionsFiles = await Promise.all(augmentedFunctions.map((func) => getListedFunctionFiles(func, { basePath, featureFlags })));
|
|
51
44
|
return listedFunctionsFiles.flat();
|
|
52
45
|
};
|
|
53
|
-
exports.listFunctionsFiles = listFunctionsFiles;
|
|
54
46
|
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 };
|
|
47
|
+
return { name, mainFile, runtime: runtime.name, extension, schedule: inSourceConfig?.schedule ?? config.schedule };
|
|
57
48
|
};
|
|
58
49
|
const getListedFunctionFiles = async function (func, options) {
|
|
59
50
|
const srcFiles = await getSrcFiles({ ...func, ...options });
|
|
60
|
-
return srcFiles.map((srcFile) => ({ ...getListedFunction(func), srcFile, extension:
|
|
51
|
+
return srcFiles.map((srcFile) => ({ ...getListedFunction(func), srcFile, extension: extname(srcFile) }));
|
|
61
52
|
};
|
|
62
53
|
const getSrcFiles = async function ({ extension, runtime, srcPath, ...args }) {
|
|
63
54
|
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,32 +1,29 @@
|
|
|
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 { detect, Runtime as BinaryRuntime, Arch, Platform } from '@netlify/binary-info';
|
|
2
|
+
import { cachedReadFile } from '../utils/fs.js';
|
|
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 ({ fsCache, path, }) {
|
|
13
|
+
export const detectBinaryRuntime = async function ({ fsCache, path, }) {
|
|
17
14
|
try {
|
|
18
|
-
const buffer = await
|
|
15
|
+
const buffer = await cachedReadFile(fsCache, path);
|
|
19
16
|
// We're using the Type Assertion because the `cachedReadFile` abstraction
|
|
20
17
|
// loses part of the return type information. We can safely say it's a
|
|
21
18
|
// Buffer in this case because we're not specifying an encoding.
|
|
22
|
-
const binaryInfo =
|
|
19
|
+
const binaryInfo = detect(buffer);
|
|
23
20
|
if (!isValidFunctionBinary(binaryInfo)) {
|
|
24
21
|
return warnIncompatibleBinary(path, binaryInfo);
|
|
25
22
|
}
|
|
26
23
|
switch (binaryInfo.runtime) {
|
|
27
|
-
case
|
|
24
|
+
case BinaryRuntime.Go:
|
|
28
25
|
return "go" /* RuntimeType.GO */;
|
|
29
|
-
case
|
|
26
|
+
case BinaryRuntime.Rust:
|
|
30
27
|
return "rs" /* RuntimeType.RUST */;
|
|
31
28
|
default:
|
|
32
29
|
return undefined;
|
|
@@ -36,5 +33,4 @@ const detectBinaryRuntime = async function ({ fsCache, path, }) {
|
|
|
36
33
|
// Possible errors are: non binary files, arch/platforms not supported by binary-info, path is directory
|
|
37
34
|
}
|
|
38
35
|
};
|
|
39
|
-
exports.detectBinaryRuntime = detectBinaryRuntime;
|
|
40
36
|
//# 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,24 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const fs_js_1 = require("../../utils/fs.js");
|
|
9
|
-
const non_nullable_js_1 = require("../../utils/non_nullable.js");
|
|
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");
|
|
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';
|
|
13
8
|
const detectGoFunction = async ({ fsCache, path }) => {
|
|
14
|
-
const stat = await
|
|
9
|
+
const stat = await cachedLstat(fsCache, path);
|
|
15
10
|
if (!stat.isDirectory()) {
|
|
16
11
|
return;
|
|
17
12
|
}
|
|
18
|
-
const directoryName =
|
|
13
|
+
const directoryName = basename(path);
|
|
19
14
|
// @ts-expect-error TODO: The `makeCachedFunction` abstraction is causing the
|
|
20
15
|
// return value of `readdir` to be incorrectly typed.
|
|
21
|
-
const files = (await
|
|
16
|
+
const files = (await cachedReaddir(fsCache, path));
|
|
22
17
|
const mainFileName = [`${directoryName}.go`, 'main.go'].find((name) => files.includes(name));
|
|
23
18
|
if (mainFileName === undefined) {
|
|
24
19
|
return;
|
|
@@ -27,10 +22,10 @@ const detectGoFunction = async ({ fsCache, path }) => {
|
|
|
27
22
|
};
|
|
28
23
|
const findFunctionsInPaths = async function ({ featureFlags, fsCache, paths }) {
|
|
29
24
|
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ featureFlags, fsCache, path })));
|
|
30
|
-
return functions.filter(
|
|
25
|
+
return functions.filter(nonNullable);
|
|
31
26
|
};
|
|
32
27
|
const findFunctionInPath = async function ({ fsCache, path }) {
|
|
33
|
-
const runtime = await
|
|
28
|
+
const runtime = await detectBinaryRuntime({ fsCache, path });
|
|
34
29
|
if (runtime === "go" /* RuntimeType.GO */) {
|
|
35
30
|
return processBinary({ fsCache, path });
|
|
36
31
|
}
|
|
@@ -40,16 +35,16 @@ const findFunctionInPath = async function ({ fsCache, path }) {
|
|
|
40
35
|
}
|
|
41
36
|
};
|
|
42
37
|
const processBinary = async ({ fsCache, path }) => {
|
|
43
|
-
const stat = (await
|
|
44
|
-
const extension =
|
|
45
|
-
const filename =
|
|
46
|
-
const name =
|
|
38
|
+
const stat = (await cachedLstat(fsCache, path));
|
|
39
|
+
const extension = extname(path);
|
|
40
|
+
const filename = basename(path);
|
|
41
|
+
const name = basename(path, extname(path));
|
|
47
42
|
return {
|
|
48
43
|
extension,
|
|
49
44
|
filename,
|
|
50
45
|
mainFile: path,
|
|
51
46
|
name,
|
|
52
|
-
srcDir:
|
|
47
|
+
srcDir: dirname(path),
|
|
53
48
|
srcPath: path,
|
|
54
49
|
stat,
|
|
55
50
|
};
|
|
@@ -59,14 +54,14 @@ const processSource = async ({ fsCache, mainFile, path, }) => {
|
|
|
59
54
|
// the `FunctionSource` interface. We should revisit whether `stat` should be
|
|
60
55
|
// part of that interface in the first place, or whether we could compute it
|
|
61
56
|
// downstream when needed (maybe using the FS cache as an optimisation).
|
|
62
|
-
const stat = (await
|
|
63
|
-
const filename =
|
|
64
|
-
const extension =
|
|
65
|
-
const name =
|
|
57
|
+
const stat = (await cachedLstat(fsCache, path));
|
|
58
|
+
const filename = basename(path);
|
|
59
|
+
const extension = extname(mainFile);
|
|
60
|
+
const name = basename(path, extname(path));
|
|
66
61
|
return {
|
|
67
62
|
extension,
|
|
68
63
|
filename,
|
|
69
|
-
mainFile:
|
|
64
|
+
mainFile: join(path, mainFile),
|
|
70
65
|
name,
|
|
71
66
|
srcDir: path,
|
|
72
67
|
srcPath: path,
|
|
@@ -74,8 +69,8 @@ const processSource = async ({ fsCache, mainFile, path, }) => {
|
|
|
74
69
|
};
|
|
75
70
|
};
|
|
76
71
|
const zipFunction = async function ({ config, destFolder, filename, mainFile, srcDir, srcPath, stat }) {
|
|
77
|
-
const destPath =
|
|
78
|
-
const isSource =
|
|
72
|
+
const destPath = join(destFolder, filename);
|
|
73
|
+
const isSource = extname(mainFile) === '.go';
|
|
79
74
|
let binary = {
|
|
80
75
|
path: srcPath,
|
|
81
76
|
stat,
|
|
@@ -83,7 +78,7 @@ const zipFunction = async function ({ config, destFolder, filename, mainFile, sr
|
|
|
83
78
|
// If we're building a Go function from source, we call the build method and
|
|
84
79
|
// update `binary` to point to the newly-created binary.
|
|
85
80
|
if (isSource) {
|
|
86
|
-
const { stat: binaryStat } = await
|
|
81
|
+
const { stat: binaryStat } = await build({ destPath, mainFile, srcDir });
|
|
87
82
|
binary = {
|
|
88
83
|
path: destPath,
|
|
89
84
|
stat: binaryStat,
|
|
@@ -95,20 +90,20 @@ const zipFunction = async function ({ config, destFolder, filename, mainFile, sr
|
|
|
95
90
|
const zipPath = `${destPath}.zip`;
|
|
96
91
|
const zipOptions = {
|
|
97
92
|
destPath: zipPath,
|
|
98
|
-
filename:
|
|
93
|
+
filename: basename(destPath),
|
|
99
94
|
runtime,
|
|
100
95
|
};
|
|
101
|
-
await
|
|
96
|
+
await zipBinary({ ...zipOptions, srcPath: binary.path, stat: binary.stat });
|
|
102
97
|
return { config, path: zipPath };
|
|
103
98
|
}
|
|
104
99
|
// We don't need to zip the binary, so we can just copy it to the right path.
|
|
105
100
|
// We do this only if we're not building from source, as otherwise the build
|
|
106
101
|
// step already handled that.
|
|
107
102
|
if (!isSource) {
|
|
108
|
-
await (
|
|
103
|
+
await copyFile(binary.path, destPath);
|
|
109
104
|
}
|
|
110
105
|
return { config, path: destPath };
|
|
111
106
|
};
|
|
112
107
|
const runtime = { findFunctionsInPaths, findFunctionInPath, name: "go" /* RuntimeType.GO */, zipFunction };
|
|
113
|
-
|
|
108
|
+
export default runtime;
|
|
114
109
|
//# sourceMappingURL=index.js.map
|