@netlify/zip-it-and-ship-it 5.7.3 → 5.7.4
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/bin.js +2 -2
- package/dist/config.d.ts +3 -3
- package/dist/function.d.ts +2 -2
- package/dist/main.d.ts +4 -4
- package/dist/main.js +18 -18
- package/dist/manifest.d.ts +1 -1
- package/dist/runtimes/detect_runtime.d.ts +2 -2
- package/dist/runtimes/detect_runtime.js +2 -2
- package/dist/runtimes/go/builder.js +2 -2
- package/dist/runtimes/go/index.d.ts +1 -1
- package/dist/runtimes/go/index.js +13 -13
- package/dist/runtimes/index.d.ts +3 -3
- package/dist/runtimes/index.js +10 -10
- package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +1 -1
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +11 -11
- package/dist/runtimes/node/bundlers/esbuild/index.d.ts +2 -2
- package/dist/runtimes/node/bundlers/esbuild/index.js +13 -13
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +1 -1
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/special_cases.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +1 -1
- package/dist/runtimes/node/bundlers/esbuild/src_files.js +10 -10
- package/dist/runtimes/node/bundlers/index.d.ts +4 -4
- package/dist/runtimes/node/bundlers/index.js +8 -8
- package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +4 -4
- package/dist/runtimes/node/bundlers/nft/es_modules.js +8 -8
- package/dist/runtimes/node/bundlers/nft/index.d.ts +2 -2
- package/dist/runtimes/node/bundlers/nft/index.js +14 -14
- package/dist/runtimes/node/bundlers/nft/transpile.d.ts +1 -1
- package/dist/runtimes/node/bundlers/nft/transpile.js +2 -2
- package/dist/runtimes/node/bundlers/zisi/index.d.ts +2 -2
- package/dist/runtimes/node/bundlers/zisi/index.js +5 -5
- package/dist/runtimes/node/bundlers/zisi/list_imports.js +2 -2
- package/dist/runtimes/node/bundlers/zisi/nested.d.ts +1 -1
- package/dist/runtimes/node/bundlers/zisi/side_files.js +2 -2
- package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +1 -1
- package/dist/runtimes/node/bundlers/zisi/src_files.js +19 -19
- package/dist/runtimes/node/bundlers/zisi/traverse.d.ts +2 -2
- package/dist/runtimes/node/bundlers/zisi/traverse.js +12 -12
- package/dist/runtimes/node/bundlers/zisi/tree_shake.js +2 -2
- package/dist/runtimes/node/finder.d.ts +1 -1
- package/dist/runtimes/node/finder.js +2 -2
- package/dist/runtimes/node/in_source_config/index.d.ts +1 -1
- package/dist/runtimes/node/in_source_config/index.js +10 -10
- package/dist/runtimes/node/in_source_config/properties/schedule.d.ts +1 -1
- package/dist/runtimes/node/index.d.ts +2 -2
- package/dist/runtimes/node/index.js +16 -16
- package/dist/runtimes/node/parser/exports.d.ts +1 -1
- package/dist/runtimes/node/parser/exports.js +2 -2
- package/dist/runtimes/node/parser/imports.js +6 -6
- package/dist/runtimes/node/parser/index.js +2 -2
- package/dist/runtimes/node/utils/detect_native_module.d.ts +1 -1
- package/dist/runtimes/node/utils/entry_file.d.ts +1 -1
- package/dist/runtimes/node/utils/entry_file.js +2 -2
- package/dist/runtimes/node/utils/zip.d.ts +1 -1
- package/dist/runtimes/node/utils/zip.js +14 -14
- package/dist/runtimes/runtime.d.ts +7 -7
- package/dist/runtimes/rust/builder.d.ts +1 -1
- package/dist/runtimes/rust/builder.js +8 -8
- package/dist/runtimes/rust/index.d.ts +1 -1
- package/dist/runtimes/rust/index.js +17 -17
- package/dist/utils/archive_size.d.ts +1 -1
- package/dist/utils/format_result.d.ts +2 -2
- package/dist/utils/format_result.js +2 -2
- package/dist/utils/fs.js +2 -2
- package/dist/zip.d.ts +6 -6
- package/dist/zip.js +18 -18
- package/dist/zip_binary.d.ts +1 -1
- package/dist/zip_binary.js +5 -5
- package/package.json +1 -1
|
@@ -5,28 +5,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const cp_file_1 = __importDefault(require("cp-file"));
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
8
|
+
const index_js_1 = require("./bundlers/index.js");
|
|
9
|
+
const finder_js_1 = require("./finder.js");
|
|
10
|
+
const index_js_2 = require("./in_source_config/index.js");
|
|
11
|
+
const plugin_modules_path_js_1 = require("./utils/plugin_modules_path.js");
|
|
12
|
+
const zip_js_1 = require("./utils/zip.js");
|
|
13
13
|
// A proxy for the `getSrcFiles` function which adds a default `bundler` using
|
|
14
14
|
// the `getDefaultBundler` function.
|
|
15
15
|
const getSrcFilesWithBundler = async (parameters) => {
|
|
16
|
-
const pluginsModulesPath = await (0,
|
|
16
|
+
const pluginsModulesPath = await (0, plugin_modules_path_js_1.getPluginsModulesPath)(parameters.srcDir);
|
|
17
17
|
const bundlerName = parameters.config.nodeBundler ||
|
|
18
|
-
(await (0,
|
|
18
|
+
(await (0, index_js_1.getDefaultBundler)({
|
|
19
19
|
extension: parameters.extension,
|
|
20
20
|
featureFlags: parameters.featureFlags,
|
|
21
21
|
mainFile: parameters.mainFile,
|
|
22
22
|
}));
|
|
23
|
-
const bundler = (0,
|
|
23
|
+
const bundler = (0, index_js_1.getBundler)(bundlerName);
|
|
24
24
|
return bundler.getSrcFiles({ ...parameters, pluginsModulesPath });
|
|
25
25
|
};
|
|
26
26
|
const zipFunction = async function ({ archiveFormat, basePath, config = {}, destFolder, extension, featureFlags, filename, mainFile, name, repositoryRoot, runtime, srcDir, srcPath, stat, }) {
|
|
27
|
-
const pluginsModulesPath = await (0,
|
|
28
|
-
const bundlerName = config.nodeBundler || (await (0,
|
|
29
|
-
const bundler = (0,
|
|
27
|
+
const pluginsModulesPath = await (0, plugin_modules_path_js_1.getPluginsModulesPath)(srcDir);
|
|
28
|
+
const bundlerName = config.nodeBundler || (await (0, index_js_1.getDefaultBundler)({ extension, mainFile, featureFlags }));
|
|
29
|
+
const bundler = (0, index_js_1.getBundler)(bundlerName);
|
|
30
30
|
// If the file is a zip, we assume the function is bundled and ready to go.
|
|
31
31
|
// We simply copy it to the destination path with no further processing.
|
|
32
32
|
if (extension === '.zip') {
|
|
@@ -49,9 +49,9 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
|
|
|
49
49
|
srcPath,
|
|
50
50
|
stat,
|
|
51
51
|
});
|
|
52
|
-
const inSourceConfig = await (0,
|
|
53
|
-
(0,
|
|
54
|
-
const zipPath = await (0,
|
|
52
|
+
const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(mainFile);
|
|
53
|
+
(0, plugin_modules_path_js_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
|
|
54
|
+
const zipPath = await (0, zip_js_1.zipNodeJs)({
|
|
55
55
|
aliases,
|
|
56
56
|
archiveFormat,
|
|
57
57
|
basePath: finalBasePath,
|
|
@@ -96,8 +96,8 @@ const zipWithFunctionWithFallback = async ({ config = {}, ...parameters }) => {
|
|
|
96
96
|
}
|
|
97
97
|
};
|
|
98
98
|
const runtime = {
|
|
99
|
-
findFunctionsInPaths:
|
|
100
|
-
findFunctionInPath:
|
|
99
|
+
findFunctionsInPaths: finder_js_1.findFunctionsInPaths,
|
|
100
|
+
findFunctionInPath: finder_js_1.findFunctionInPath,
|
|
101
101
|
getSrcFiles: getSrcFilesWithBundler,
|
|
102
102
|
name: 'js',
|
|
103
103
|
zipFunction: zipWithFunctionWithFallback,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getMainExport = void 0;
|
|
4
|
-
const
|
|
4
|
+
const helpers_js_1 = require("./helpers.js");
|
|
5
5
|
// Finds the main handler export in an AST.
|
|
6
6
|
const getMainExport = (nodes) => {
|
|
7
7
|
let handlerExport = [];
|
|
@@ -28,7 +28,7 @@ const getMainExportFromCJS = (node) => {
|
|
|
28
28
|
['exports', 'handler'],
|
|
29
29
|
];
|
|
30
30
|
return handlerPaths.flatMap((handlerPath) => {
|
|
31
|
-
if (!(0,
|
|
31
|
+
if (!(0, helpers_js_1.isModuleExports)(node, handlerPath) || node.expression.right.type !== 'CallExpression') {
|
|
32
32
|
return [];
|
|
33
33
|
}
|
|
34
34
|
return getExportsFromCallExpression(node.expression.right);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getImports = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const non_nullable_js_1 = require("../../../utils/non_nullable.js");
|
|
5
|
+
const helpers_js_1 = require("./helpers.js");
|
|
6
6
|
// Finds import/require statements of a given path in an AST.
|
|
7
7
|
const getImports = (node, importPath) => {
|
|
8
8
|
const esmImports = getImportsFromESM(node, importPath);
|
|
@@ -19,7 +19,7 @@ const getImportsFromCJS = (node, importPath) => {
|
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
21
21
|
const { declarations } = node;
|
|
22
|
-
const requireDeclaration = declarations.find((declaration) => declaration.type === 'VariableDeclarator' && (0,
|
|
22
|
+
const requireDeclaration = declarations.find((declaration) => declaration.type === 'VariableDeclarator' && (0, helpers_js_1.isRequire)(declaration.init, importPath));
|
|
23
23
|
if (requireDeclaration === undefined || requireDeclaration.id.type !== 'ObjectPattern') {
|
|
24
24
|
return [];
|
|
25
25
|
}
|
|
@@ -34,12 +34,12 @@ const getImportsFromCJS = (node, importPath) => {
|
|
|
34
34
|
}
|
|
35
35
|
return { imported: key.name, local: value.name };
|
|
36
36
|
})
|
|
37
|
-
.filter(
|
|
37
|
+
.filter(non_nullable_js_1.nonNullable);
|
|
38
38
|
return imports;
|
|
39
39
|
};
|
|
40
40
|
// Finds import/require statements of a given path in an ESM AST.
|
|
41
41
|
const getImportsFromESM = (node, importPath) => {
|
|
42
|
-
if (!(0,
|
|
42
|
+
if (!(0, helpers_js_1.isImport)(node, importPath)) {
|
|
43
43
|
return [];
|
|
44
44
|
}
|
|
45
45
|
const { specifiers } = node;
|
|
@@ -54,7 +54,7 @@ const getImportsFromESM = (node, importPath) => {
|
|
|
54
54
|
}
|
|
55
55
|
return { imported: imported.name, local: local.name };
|
|
56
56
|
})
|
|
57
|
-
.filter(
|
|
57
|
+
.filter(non_nullable_js_1.nonNullable);
|
|
58
58
|
return imports;
|
|
59
59
|
};
|
|
60
60
|
//# sourceMappingURL=imports.js.map
|
|
@@ -5,7 +5,7 @@ exports.safelyParseFile = exports.parseExpression = void 0;
|
|
|
5
5
|
const fs_1 = require("fs");
|
|
6
6
|
const path_1 = require("path");
|
|
7
7
|
const parser_1 = require("@babel/parser");
|
|
8
|
-
const
|
|
8
|
+
const non_nullable_js_1 = require("../../../utils/non_nullable.js");
|
|
9
9
|
const GLOB_WILDCARD = '**';
|
|
10
10
|
// Transforms an array of glob nodes into a glob string including an absolute
|
|
11
11
|
// path.
|
|
@@ -159,7 +159,7 @@ const parseTemplateLiteral = (expression) => {
|
|
|
159
159
|
return getWildcardFromASTNode(part);
|
|
160
160
|
}
|
|
161
161
|
});
|
|
162
|
-
return globNodes.filter(
|
|
162
|
+
return globNodes.filter(non_nullable_js_1.nonNullable);
|
|
163
163
|
};
|
|
164
164
|
// For our purposes, we consider a glob to be valid if all the nodes are
|
|
165
165
|
// strings and the first node is static (i.e. not a wildcard character).
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { PackageJson } from './package_json';
|
|
1
|
+
import { PackageJson } from './package_json.js';
|
|
2
2
|
export declare const isNativeModule: ({ binary, dependencies, devDependencies, files, gypfile, }: PackageJson) => boolean;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEntryFile = void 0;
|
|
4
4
|
const path_1 = require("path");
|
|
5
|
-
const
|
|
5
|
+
const normalize_path_js_1 = require("./normalize_path.js");
|
|
6
6
|
const getEntryFileContents = (mainPath, moduleFormat) => {
|
|
7
7
|
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
8
8
|
if (moduleFormat === 'cjs') {
|
|
@@ -11,7 +11,7 @@ const getEntryFileContents = (mainPath, moduleFormat) => {
|
|
|
11
11
|
return `export { handler } from '${importPath}'`;
|
|
12
12
|
};
|
|
13
13
|
const getEntryFile = ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }) => {
|
|
14
|
-
const mainPath = (0,
|
|
14
|
+
const mainPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
|
|
15
15
|
const extension = (0, path_1.extname)(filename);
|
|
16
16
|
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
17
17
|
const contents = getEntryFileContents(mainPath, moduleFormat);
|
|
@@ -11,17 +11,17 @@ const path_1 = require("path");
|
|
|
11
11
|
const cp_file_1 = __importDefault(require("cp-file"));
|
|
12
12
|
const del_1 = __importDefault(require("del"));
|
|
13
13
|
const p_map_1 = __importDefault(require("p-map"));
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
14
|
+
const archive_js_1 = require("../../../archive.js");
|
|
15
|
+
const fs_js_1 = require("../../../utils/fs.js");
|
|
16
|
+
const entry_file_js_1 = require("./entry_file.js");
|
|
17
|
+
const normalize_path_js_1 = require("./normalize_path.js");
|
|
18
18
|
// Taken from https://www.npmjs.com/package/cpy.
|
|
19
19
|
const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.default.cpus().length * 2;
|
|
20
20
|
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
21
21
|
// the entry file generated by zip-it-and-ship-it).
|
|
22
22
|
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
23
23
|
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
|
|
24
|
-
const { contents: entryContents, filename: entryFilename } = (0,
|
|
24
|
+
const { contents: entryContents, filename: entryFilename } = (0, entry_file_js_1.getEntryFile)({
|
|
25
25
|
commonPrefix: basePath,
|
|
26
26
|
filename,
|
|
27
27
|
mainFile,
|
|
@@ -37,14 +37,14 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
|
|
|
37
37
|
// Copying source files.
|
|
38
38
|
await (0, p_map_1.default)(srcFiles, (srcFile) => {
|
|
39
39
|
const destPath = aliases.get(srcFile) || srcFile;
|
|
40
|
-
const normalizedDestPath = (0,
|
|
40
|
+
const normalizedDestPath = (0, normalize_path_js_1.normalizeFilePath)({
|
|
41
41
|
commonPrefix: basePath,
|
|
42
42
|
path: destPath,
|
|
43
43
|
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
44
44
|
});
|
|
45
45
|
const absoluteDestPath = (0, path_1.join)(functionFolder, normalizedDestPath);
|
|
46
46
|
if (rewrites.has(srcFile)) {
|
|
47
|
-
return (0,
|
|
47
|
+
return (0, fs_js_1.mkdirAndWriteFile)(absoluteDestPath, rewrites.get(srcFile));
|
|
48
48
|
}
|
|
49
49
|
return (0, cp_file_1.default)(srcFile, absoluteDestPath);
|
|
50
50
|
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
@@ -52,7 +52,7 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
|
|
|
52
52
|
};
|
|
53
53
|
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
|
|
54
54
|
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
55
|
-
const { archive, output } = (0,
|
|
55
|
+
const { archive, output } = (0, archive_js_1.startZip)(destPath);
|
|
56
56
|
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
57
57
|
const entryFilePath = (0, path_1.resolve)(basePath, entryFilename);
|
|
58
58
|
// We don't need an entry file if it would end up with the same path as the
|
|
@@ -66,7 +66,7 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
|
|
|
66
66
|
// than the entry file) to its own sub-directory.
|
|
67
67
|
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
68
68
|
if (needsEntryFile) {
|
|
69
|
-
const entryFile = (0,
|
|
69
|
+
const entryFile = (0, entry_file_js_1.getEntryFile)({ commonPrefix: basePath, filename, mainFile, moduleFormat, userNamespace });
|
|
70
70
|
addEntryFileToZip(archive, entryFile);
|
|
71
71
|
}
|
|
72
72
|
const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
|
|
@@ -83,7 +83,7 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
|
|
|
83
83
|
userNamespace,
|
|
84
84
|
});
|
|
85
85
|
});
|
|
86
|
-
await (0,
|
|
86
|
+
await (0, archive_js_1.endZip)(archive, output);
|
|
87
87
|
return destPath;
|
|
88
88
|
};
|
|
89
89
|
const zipNodeJs = function ({ archiveFormat, ...options }) {
|
|
@@ -95,7 +95,7 @@ const zipNodeJs = function ({ archiveFormat, ...options }) {
|
|
|
95
95
|
exports.zipNodeJs = zipNodeJs;
|
|
96
96
|
const addEntryFileToZip = function (archive, { contents, filename }) {
|
|
97
97
|
const contentBuffer = buffer_1.Buffer.from(contents);
|
|
98
|
-
(0,
|
|
98
|
+
(0, archive_js_1.addZipContent)(archive, contentBuffer, filename);
|
|
99
99
|
};
|
|
100
100
|
const addStat = async function (srcFile) {
|
|
101
101
|
const stat = await fs_1.promises.lstat(srcFile);
|
|
@@ -103,12 +103,12 @@ const addStat = async function (srcFile) {
|
|
|
103
103
|
};
|
|
104
104
|
const zipJsFile = function ({ aliases = new Map(), archive, commonPrefix, rewrites = new Map(), stat, srcFile, userNamespace, }) {
|
|
105
105
|
const destPath = aliases.get(srcFile) || srcFile;
|
|
106
|
-
const normalizedDestPath = (0,
|
|
106
|
+
const normalizedDestPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: destPath, userNamespace });
|
|
107
107
|
if (rewrites.has(srcFile)) {
|
|
108
|
-
(0,
|
|
108
|
+
(0, archive_js_1.addZipContent)(archive, rewrites.get(srcFile), normalizedDestPath);
|
|
109
109
|
}
|
|
110
110
|
else {
|
|
111
|
-
(0,
|
|
111
|
+
(0, archive_js_1.addZipFile)(archive, srcFile, normalizedDestPath, stat);
|
|
112
112
|
}
|
|
113
113
|
};
|
|
114
114
|
//# sourceMappingURL=zip.js.map
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ArchiveFormat } from '../archive';
|
|
2
|
-
import { FunctionConfig } from '../config';
|
|
3
|
-
import { FeatureFlags } from '../feature_flags';
|
|
4
|
-
import { FunctionSource, SourceFile } from '../function';
|
|
5
|
-
import { FsCache } from '../utils/fs';
|
|
6
|
-
import type { NodeBundlerName } from './node/bundlers';
|
|
7
|
-
import type { ISCValues } from './node/in_source_config';
|
|
1
|
+
import { ArchiveFormat } from '../archive.js';
|
|
2
|
+
import { FunctionConfig } from '../config.js';
|
|
3
|
+
import { FeatureFlags } from '../feature_flags.js';
|
|
4
|
+
import { FunctionSource, SourceFile } from '../function.js';
|
|
5
|
+
import { FsCache } from '../utils/fs.js';
|
|
6
|
+
import type { NodeBundlerName } from './node/bundlers/index.js';
|
|
7
|
+
import type { ISCValues } from './node/in_source_config/index.js';
|
|
8
8
|
export declare type RuntimeName = 'go' | 'js' | 'rs';
|
|
9
9
|
export declare type FindFunctionsInPathsFunction = (args: {
|
|
10
10
|
featureFlags: FeatureFlags;
|
|
@@ -8,8 +8,8 @@ const fs_1 = require("fs");
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const tmp_promise_1 = __importDefault(require("tmp-promise"));
|
|
10
10
|
const toml_1 = __importDefault(require("toml"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
11
|
+
const shell_js_1 = require("../../utils/shell.js");
|
|
12
|
+
const constants_js_1 = require("./constants.js");
|
|
13
13
|
const runtimeName = 'rs';
|
|
14
14
|
const build = async ({ config, name, srcDir }) => {
|
|
15
15
|
const functionName = (0, path_1.basename)(srcDir);
|
|
@@ -26,9 +26,9 @@ const build = async ({ config, name, srcDir }) => {
|
|
|
26
26
|
// way to override it (https://github.com/rust-lang/cargo/issues/1706). We
|
|
27
27
|
// must extract the crate name from the manifest and use it to form the path
|
|
28
28
|
// to the binary.
|
|
29
|
-
const manifest = await fs_1.promises.readFile((0, path_1.join)(srcDir,
|
|
29
|
+
const manifest = await fs_1.promises.readFile((0, path_1.join)(srcDir, constants_js_1.MANIFEST_NAME), 'utf8');
|
|
30
30
|
const { package: { name: packageName }, } = toml_1.default.parse(manifest);
|
|
31
|
-
const binaryPath = (0, path_1.join)(targetDirectory,
|
|
31
|
+
const binaryPath = (0, path_1.join)(targetDirectory, constants_js_1.BUILD_TARGET, 'release', packageName);
|
|
32
32
|
const stat = await fs_1.promises.lstat(binaryPath);
|
|
33
33
|
return {
|
|
34
34
|
path: binaryPath,
|
|
@@ -38,7 +38,7 @@ const build = async ({ config, name, srcDir }) => {
|
|
|
38
38
|
exports.build = build;
|
|
39
39
|
const cargoBuild = async ({ functionName, srcDir, targetDirectory, }) => {
|
|
40
40
|
try {
|
|
41
|
-
await
|
|
41
|
+
await shell_js_1.shellUtils.runCommand('cargo', ['build', '--target', constants_js_1.BUILD_TARGET, '--release'], {
|
|
42
42
|
cwd: srcDir,
|
|
43
43
|
env: {
|
|
44
44
|
CARGO_TARGET_DIR: targetDirectory,
|
|
@@ -60,7 +60,7 @@ const cargoBuild = async ({ functionName, srcDir, targetDirectory, }) => {
|
|
|
60
60
|
};
|
|
61
61
|
const checkRustToolchain = async () => {
|
|
62
62
|
try {
|
|
63
|
-
await
|
|
63
|
+
await shell_js_1.shellUtils.runCommand('cargo', ['-V']);
|
|
64
64
|
return true;
|
|
65
65
|
}
|
|
66
66
|
catch {
|
|
@@ -86,8 +86,8 @@ let toolchainInstallation;
|
|
|
86
86
|
// `BUILD_TARGET`. The Promise is saved to `toolchainInstallation`, so
|
|
87
87
|
// that we run the command just once for multiple Rust functions.
|
|
88
88
|
const installToolchain = async () => {
|
|
89
|
-
await
|
|
90
|
-
await
|
|
89
|
+
await shell_js_1.shellUtils.runCommand('rustup', ['default', 'stable']);
|
|
90
|
+
await shell_js_1.shellUtils.runCommand('rustup', ['target', 'add', constants_js_1.BUILD_TARGET]);
|
|
91
91
|
};
|
|
92
92
|
const installToolchainOnce = () => {
|
|
93
93
|
if (toolchainInstallation === undefined) {
|
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path_1 = require("path");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
4
|
+
const fs_js_1 = require("../../utils/fs.js");
|
|
5
|
+
const non_nullable_js_1 = require("../../utils/non_nullable.js");
|
|
6
|
+
const zip_binary_js_1 = require("../../zip_binary.js");
|
|
7
|
+
const detect_runtime_js_1 = require("../detect_runtime.js");
|
|
8
|
+
const builder_js_1 = require("./builder.js");
|
|
9
|
+
const constants_js_1 = require("./constants.js");
|
|
10
10
|
const detectRustFunction = async ({ fsCache, path }) => {
|
|
11
|
-
const stat = await (0,
|
|
11
|
+
const stat = await (0, fs_js_1.cachedLstat)(fsCache, path);
|
|
12
12
|
if (!stat.isDirectory()) {
|
|
13
13
|
return;
|
|
14
14
|
}
|
|
15
15
|
// @ts-expect-error TODO: The `makeCachedFunction` abstraction is causing the
|
|
16
16
|
// return value of `readdir` to be incorrectly typed.
|
|
17
|
-
const files = (await (0,
|
|
18
|
-
const hasCargoManifest = files.includes(
|
|
17
|
+
const files = (await (0, fs_js_1.cachedReaddir)(fsCache, path));
|
|
18
|
+
const hasCargoManifest = files.includes(constants_js_1.MANIFEST_NAME);
|
|
19
19
|
if (!hasCargoManifest) {
|
|
20
20
|
return;
|
|
21
21
|
}
|
|
22
22
|
const mainFilePath = (0, path_1.join)(path, 'src', 'main.rs');
|
|
23
23
|
try {
|
|
24
|
-
const mainFile = await (0,
|
|
24
|
+
const mainFile = await (0, fs_js_1.cachedLstat)(fsCache, mainFilePath);
|
|
25
25
|
if (mainFile.isFile()) {
|
|
26
26
|
return mainFilePath;
|
|
27
27
|
}
|
|
@@ -32,10 +32,10 @@ const detectRustFunction = async ({ fsCache, path }) => {
|
|
|
32
32
|
};
|
|
33
33
|
const findFunctionsInPaths = async function ({ featureFlags, fsCache, paths, }) {
|
|
34
34
|
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ path, featureFlags, fsCache })));
|
|
35
|
-
return functions.filter(
|
|
35
|
+
return functions.filter(non_nullable_js_1.nonNullable);
|
|
36
36
|
};
|
|
37
37
|
const findFunctionInPath = async function ({ path, featureFlags, fsCache }) {
|
|
38
|
-
const runtime = await (0,
|
|
38
|
+
const runtime = await (0, detect_runtime_js_1.detectBinaryRuntime)({ fsCache, path });
|
|
39
39
|
if (runtime === 'rs') {
|
|
40
40
|
return processBinary({ fsCache, path });
|
|
41
41
|
}
|
|
@@ -48,7 +48,7 @@ const findFunctionInPath = async function ({ path, featureFlags, fsCache }) {
|
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
50
|
const processBinary = async ({ fsCache, path }) => {
|
|
51
|
-
const stat = (await (0,
|
|
51
|
+
const stat = (await (0, fs_js_1.cachedLstat)(fsCache, path));
|
|
52
52
|
const filename = (0, path_1.basename)(path);
|
|
53
53
|
const extension = (0, path_1.extname)(path);
|
|
54
54
|
const name = (0, path_1.basename)(path, extension);
|
|
@@ -67,7 +67,7 @@ const processSource = async ({ fsCache, mainFile, path, }) => {
|
|
|
67
67
|
// the `FunctionSource` interface. We should revisit whether `stat` should be
|
|
68
68
|
// part of that interface in the first place, or whether we could compute it
|
|
69
69
|
// downstream when needed (maybe using the FS cache as an optimisation).
|
|
70
|
-
const stat = (await (0,
|
|
70
|
+
const stat = (await (0, fs_js_1.cachedLstat)(fsCache, path));
|
|
71
71
|
const filename = (0, path_1.basename)(path);
|
|
72
72
|
const extension = (0, path_1.extname)(path);
|
|
73
73
|
const name = (0, path_1.basename)(path, extension);
|
|
@@ -96,11 +96,11 @@ const zipFunction = async function ({ config, destFolder, filename, mainFile, ru
|
|
|
96
96
|
// the resulting binary. Otherwise, we're dealing with a binary so we zip it
|
|
97
97
|
// directly.
|
|
98
98
|
if (isSource) {
|
|
99
|
-
const { path: binaryPath, stat: binaryStat } = await (0,
|
|
100
|
-
await (0,
|
|
99
|
+
const { path: binaryPath, stat: binaryStat } = await (0, builder_js_1.build)({ config, name: filename, srcDir });
|
|
100
|
+
await (0, zip_binary_js_1.zipBinary)({ ...zipOptions, srcPath: binaryPath, stat: binaryStat });
|
|
101
101
|
}
|
|
102
102
|
else {
|
|
103
|
-
await (0,
|
|
103
|
+
await (0, zip_binary_js_1.zipBinary)({ ...zipOptions, srcPath, stat });
|
|
104
104
|
}
|
|
105
105
|
return { config, path: destPath };
|
|
106
106
|
};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { FunctionArchive } from '../function';
|
|
1
|
+
import type { FunctionArchive } from '../function.js';
|
|
2
2
|
export declare const addArchiveSize: (result: FunctionArchive) => Promise<FunctionArchive>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FunctionArchive } from '../function';
|
|
2
|
-
import { RuntimeName } from '../runtimes/runtime';
|
|
1
|
+
import { FunctionArchive } from '../function.js';
|
|
2
|
+
import { RuntimeName } from '../runtimes/runtime.js';
|
|
3
3
|
export declare type FunctionResult = Omit<FunctionArchive, 'runtime'> & {
|
|
4
4
|
runtime: RuntimeName;
|
|
5
5
|
schedule?: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formatZipResult = void 0;
|
|
4
|
-
const
|
|
4
|
+
const remove_undefined_js_1 = require("./remove_undefined.js");
|
|
5
5
|
// Takes the result of zipping a function and formats it for output.
|
|
6
6
|
const formatZipResult = (archive) => {
|
|
7
7
|
var _a, _b, _c;
|
|
@@ -11,7 +11,7 @@ const formatZipResult = (archive) => {
|
|
|
11
11
|
runtime: archive.runtime.name,
|
|
12
12
|
schedule: (_b = (_a = archive.inSourceConfig) === null || _a === void 0 ? void 0 : _a.schedule) !== null && _b !== void 0 ? _b : (_c = archive === null || archive === void 0 ? void 0 : archive.config) === null || _c === void 0 ? void 0 : _c.schedule,
|
|
13
13
|
};
|
|
14
|
-
return (0,
|
|
14
|
+
return (0, remove_undefined_js_1.removeUndefined)(functionResult);
|
|
15
15
|
};
|
|
16
16
|
exports.formatZipResult = formatZipResult;
|
|
17
17
|
//# sourceMappingURL=format_result.js.map
|
package/dist/utils/fs.js
CHANGED
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mkdirAndWriteFile = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.safeUnlink = exports.getPathWithExtension = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
const path_1 = require("path");
|
|
6
|
-
const
|
|
6
|
+
const non_nullable_js_1 = require("./non_nullable.js");
|
|
7
7
|
// This caches multiple FS calls to the same path. It creates a cache key with
|
|
8
8
|
// the name of the function and the path (e.g. "readdir:/some/directory").
|
|
9
9
|
//
|
|
@@ -43,7 +43,7 @@ const listFunctionsDirectories = async function (srcFolders) {
|
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
45
|
}));
|
|
46
|
-
const validDirectories = filenamesByDirectory.filter(
|
|
46
|
+
const validDirectories = filenamesByDirectory.filter(non_nullable_js_1.nonNullable);
|
|
47
47
|
if (validDirectories.length === 0) {
|
|
48
48
|
throw new Error(`Functions folder does not exist: ${srcFolders.join(', ')}`);
|
|
49
49
|
}
|
package/dist/zip.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArchiveFormat } from './archive';
|
|
2
|
-
import { Config } from './config';
|
|
3
|
-
import { FeatureFlags } from './feature_flags';
|
|
1
|
+
import { ArchiveFormat } from './archive.js';
|
|
2
|
+
import { Config } from './config.js';
|
|
3
|
+
import { FeatureFlags } from './feature_flags.js';
|
|
4
4
|
interface ZipFunctionOptions {
|
|
5
5
|
archiveFormat?: ArchiveFormat;
|
|
6
6
|
basePath?: string;
|
|
@@ -13,9 +13,9 @@ declare type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
|
13
13
|
manifest?: string;
|
|
14
14
|
parallelLimit?: number;
|
|
15
15
|
};
|
|
16
|
-
export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function").FunctionArchive, "runtime"> & {
|
|
17
|
-
runtime: import("./runtimes/runtime").RuntimeName;
|
|
16
|
+
export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function.js").FunctionArchive, "runtime"> & {
|
|
17
|
+
runtime: import("./runtimes/runtime.js").RuntimeName;
|
|
18
18
|
schedule?: string | undefined;
|
|
19
19
|
})[]>;
|
|
20
|
-
export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, }?: ZipFunctionOptions) => Promise<import("./utils/format_result").FunctionResult | undefined>;
|
|
20
|
+
export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, }?: ZipFunctionOptions) => Promise<import("./utils/format_result.js").FunctionResult | undefined>;
|
|
21
21
|
export {};
|
package/dist/zip.js
CHANGED
|
@@ -7,13 +7,13 @@ exports.zipFunction = exports.zipFunctions = void 0;
|
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const p_map_1 = __importDefault(require("p-map"));
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
10
|
+
const feature_flags_js_1 = require("./feature_flags.js");
|
|
11
|
+
const manifest_js_1 = require("./manifest.js");
|
|
12
|
+
const index_js_1 = require("./runtimes/index.js");
|
|
13
|
+
const archive_size_js_1 = require("./utils/archive_size.js");
|
|
14
|
+
const format_result_js_1 = require("./utils/format_result.js");
|
|
15
|
+
const fs_js_1 = require("./utils/fs.js");
|
|
16
|
+
const non_nullable_js_1 = require("./utils/non_nullable.js");
|
|
17
17
|
const DEFAULT_PARALLEL_LIMIT = 5;
|
|
18
18
|
// TODO: now that we have types, do we still need runtime validation?
|
|
19
19
|
const validateArchiveFormat = (archiveFormat) => {
|
|
@@ -25,10 +25,10 @@ const validateArchiveFormat = (archiveFormat) => {
|
|
|
25
25
|
// used by AWS Lambda
|
|
26
26
|
const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFormat = 'zip', basePath, config = {}, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, } = {}) {
|
|
27
27
|
validateArchiveFormat(archiveFormat);
|
|
28
|
-
const featureFlags = (0,
|
|
29
|
-
const srcFolders = (0,
|
|
30
|
-
const [paths] = await Promise.all([(0,
|
|
31
|
-
const functions = await (0,
|
|
28
|
+
const featureFlags = (0, feature_flags_js_1.getFlags)(inputFeatureFlags);
|
|
29
|
+
const srcFolders = (0, fs_js_1.resolveFunctionsDirectories)(relativeSrcFolders);
|
|
30
|
+
const [paths] = await Promise.all([(0, fs_js_1.listFunctionsDirectories)(srcFolders), fs_1.promises.mkdir(destFolder, { recursive: true })]);
|
|
31
|
+
const functions = await (0, index_js_1.getFunctionsFromPaths)(paths, { config, dedupe: true, featureFlags });
|
|
32
32
|
const results = await (0, p_map_1.default)(functions.values(), async (func) => {
|
|
33
33
|
const zipResult = await func.runtime.zipFunction({
|
|
34
34
|
archiveFormat,
|
|
@@ -50,21 +50,21 @@ const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFo
|
|
|
50
50
|
}, {
|
|
51
51
|
concurrency: parallelLimit,
|
|
52
52
|
});
|
|
53
|
-
const formattedResults = await Promise.all(results.filter(
|
|
54
|
-
const resultWithSize = await (0,
|
|
55
|
-
return (0,
|
|
53
|
+
const formattedResults = await Promise.all(results.filter(non_nullable_js_1.nonNullable).map(async (result) => {
|
|
54
|
+
const resultWithSize = await (0, archive_size_js_1.addArchiveSize)(result);
|
|
55
|
+
return (0, format_result_js_1.formatZipResult)(resultWithSize);
|
|
56
56
|
}));
|
|
57
57
|
if (manifest !== undefined) {
|
|
58
|
-
await (0,
|
|
58
|
+
await (0, manifest_js_1.createManifest)({ functions: formattedResults, path: (0, path_1.resolve)(manifest) });
|
|
59
59
|
}
|
|
60
60
|
return formattedResults;
|
|
61
61
|
};
|
|
62
62
|
exports.zipFunctions = zipFunctions;
|
|
63
63
|
const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat = 'zip', basePath, config: inputConfig = {}, featureFlags: inputFeatureFlags, repositoryRoot = basePath, } = {}) {
|
|
64
64
|
validateArchiveFormat(archiveFormat);
|
|
65
|
-
const featureFlags = (0,
|
|
65
|
+
const featureFlags = (0, feature_flags_js_1.getFlags)(inputFeatureFlags);
|
|
66
66
|
const srcPath = (0, path_1.resolve)(relativeSrcPath);
|
|
67
|
-
const functions = await (0,
|
|
67
|
+
const functions = await (0, index_js_1.getFunctionsFromPaths)([srcPath], { config: inputConfig, dedupe: true, featureFlags });
|
|
68
68
|
if (functions.size === 0) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
@@ -86,7 +86,7 @@ const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat
|
|
|
86
86
|
srcPath,
|
|
87
87
|
stat: stats,
|
|
88
88
|
});
|
|
89
|
-
return (0,
|
|
89
|
+
return (0, format_result_js_1.formatZipResult)({ ...zipResult, mainFile, name, runtime });
|
|
90
90
|
};
|
|
91
91
|
exports.zipFunction = zipFunction;
|
|
92
92
|
//# sourceMappingURL=zip.js.map
|
package/dist/zip_binary.d.ts
CHANGED
package/dist/zip_binary.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.zipBinary = void 0;
|
|
4
|
-
const
|
|
4
|
+
const archive_js_1 = require("./archive.js");
|
|
5
5
|
// Zip a binary function file
|
|
6
6
|
const zipBinary = async function ({ destPath, filename, runtime, srcPath, stat, }) {
|
|
7
|
-
const { archive, output } = (0,
|
|
8
|
-
(0,
|
|
9
|
-
(0,
|
|
10
|
-
await (0,
|
|
7
|
+
const { archive, output } = (0, archive_js_1.startZip)(destPath);
|
|
8
|
+
(0, archive_js_1.addZipFile)(archive, srcPath, filename, stat);
|
|
9
|
+
(0, archive_js_1.addZipContent)(archive, JSON.stringify({ runtime: runtime.name }), 'netlify-toolchain');
|
|
10
|
+
await (0, archive_js_1.endZip)(archive, output);
|
|
11
11
|
};
|
|
12
12
|
exports.zipBinary = zipBinary;
|
|
13
13
|
//# sourceMappingURL=zip_binary.js.map
|