@netlify/zip-it-and-ship-it 5.7.2 → 5.8.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/README.md +19 -38
- package/dist/archive.d.ts +6 -8
- package/dist/bin.js +2 -2
- package/dist/config.d.ts +7 -8
- package/dist/feature_flags.d.ts +4 -6
- package/dist/feature_flags.js +3 -4
- package/dist/function.d.ts +5 -6
- package/dist/main.d.ts +7 -8
- package/dist/main.js +19 -19
- package/dist/manifest.d.ts +4 -5
- package/dist/runtimes/detect_runtime.d.ts +3 -4
- package/dist/runtimes/detect_runtime.js +2 -2
- package/dist/runtimes/go/builder.d.ts +1 -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 +6 -6
- package/dist/runtimes/index.js +10 -10
- package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +6 -4
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +23 -17
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +7 -1
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +19 -3
- package/dist/runtimes/node/bundlers/esbuild/index.d.ts +2 -2
- package/dist/runtimes/node/bundlers/esbuild/index.js +15 -14
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.d.ts +1 -2
- package/dist/runtimes/node/bundlers/esbuild/plugin_dynamic_imports.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +2 -3
- package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/plugin_node_builtin.d.ts +1 -2
- package/dist/runtimes/node/bundlers/esbuild/special_cases.d.ts +1 -2
- package/dist/runtimes/node/bundlers/esbuild/special_cases.js +2 -2
- package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +2 -3
- package/dist/runtimes/node/bundlers/esbuild/src_files.js +10 -10
- package/dist/runtimes/node/bundlers/index.d.ts +10 -11
- package/dist/runtimes/node/bundlers/index.js +12 -13
- package/dist/runtimes/node/bundlers/nft/es_modules.d.ts +5 -6
- 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 +2 -3
- 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.d.ts +1 -2
- package/dist/runtimes/node/bundlers/zisi/list_imports.js +3 -3
- package/dist/runtimes/node/bundlers/zisi/nested.d.ts +3 -4
- package/dist/runtimes/node/bundlers/zisi/published.d.ts +1 -2
- package/dist/runtimes/node/bundlers/zisi/resolve.d.ts +2 -3
- package/dist/runtimes/node/bundlers/zisi/resolve.js +1 -1
- package/dist/runtimes/node/bundlers/zisi/side_files.d.ts +1 -2
- package/dist/runtimes/node/bundlers/zisi/side_files.js +2 -2
- package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +2 -3
- package/dist/runtimes/node/bundlers/zisi/src_files.js +19 -19
- package/dist/runtimes/node/bundlers/zisi/traverse.d.ts +3 -4
- package/dist/runtimes/node/bundlers/zisi/traverse.js +15 -15
- package/dist/runtimes/node/bundlers/zisi/tree_files.d.ts +1 -2
- package/dist/runtimes/node/bundlers/zisi/tree_shake.d.ts +1 -2
- package/dist/runtimes/node/bundlers/zisi/tree_shake.js +2 -2
- package/dist/runtimes/node/finder.d.ts +3 -4
- package/dist/runtimes/node/finder.js +3 -3
- package/dist/runtimes/node/in_source_config/index.d.ts +6 -8
- package/dist/runtimes/node/in_source_config/index.js +13 -14
- 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 +2 -3
- package/dist/runtimes/node/parser/exports.js +2 -2
- package/dist/runtimes/node/parser/helpers.d.ts +3 -4
- package/dist/runtimes/node/parser/imports.d.ts +1 -2
- package/dist/runtimes/node/parser/imports.js +6 -6
- package/dist/runtimes/node/parser/index.d.ts +2 -3
- package/dist/runtimes/node/parser/index.js +2 -2
- package/dist/runtimes/node/utils/base_path.d.ts +1 -2
- package/dist/runtimes/node/utils/detect_es_module.d.ts +1 -2
- package/dist/runtimes/node/utils/detect_native_module.d.ts +2 -3
- package/dist/runtimes/node/utils/entry_file.d.ts +3 -4
- package/dist/runtimes/node/utils/entry_file.js +2 -2
- package/dist/runtimes/node/utils/included_files.d.ts +2 -3
- package/dist/runtimes/node/utils/module.d.ts +1 -2
- package/dist/runtimes/node/utils/node_version.d.ts +7 -7
- package/dist/runtimes/node/utils/node_version.js +4 -5
- package/dist/runtimes/node/utils/normalize_path.d.ts +1 -2
- package/dist/runtimes/node/utils/package_json.d.ts +9 -5
- package/dist/runtimes/node/utils/package_json.js +46 -21
- package/dist/runtimes/node/utils/plugin_modules_path.d.ts +2 -3
- package/dist/runtimes/node/utils/traversal_cache.d.ts +2 -3
- package/dist/runtimes/node/utils/zip.d.ts +4 -4
- package/dist/runtimes/node/utils/zip.js +14 -14
- package/dist/runtimes/runtime.d.ts +14 -15
- package/dist/runtimes/rust/builder.d.ts +2 -3
- package/dist/runtimes/rust/builder.js +8 -8
- package/dist/runtimes/rust/cargo_manifest.d.ts +1 -2
- package/dist/runtimes/rust/constants.d.ts +2 -3
- package/dist/runtimes/rust/constants.js +2 -4
- package/dist/runtimes/rust/index.d.ts +1 -1
- package/dist/runtimes/rust/index.js +17 -17
- package/dist/utils/archive_size.d.ts +2 -3
- package/dist/utils/format_result.d.ts +4 -6
- package/dist/utils/format_result.js +2 -2
- package/dist/utils/fs.d.ts +10 -12
- package/dist/utils/fs.js +7 -10
- package/dist/utils/non_nullable.d.ts +1 -2
- package/dist/utils/remove_undefined.d.ts +1 -2
- package/dist/zip.d.ts +7 -7
- package/dist/zip.js +19 -19
- package/dist/zip_binary.d.ts +2 -3
- package/dist/zip_binary.js +5 -5
- package/package.json +4 -4
|
@@ -5,19 +5,19 @@ 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 nft_1 = require("@vercel/nft");
|
|
8
|
-
const
|
|
8
|
+
const resolve_dependency_js_1 = __importDefault(require("@vercel/nft/out/resolve-dependency.js"));
|
|
9
9
|
const minimatch_1 = __importDefault(require("minimatch"));
|
|
10
10
|
const unixify_1 = __importDefault(require("unixify"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
11
|
+
const fs_js_1 = require("../../../../utils/fs.js");
|
|
12
|
+
const base_path_js_1 = require("../../utils/base_path.js");
|
|
13
|
+
const included_files_js_1 = require("../../utils/included_files.js");
|
|
14
|
+
const es_modules_js_1 = require("./es_modules.js");
|
|
15
15
|
// Paths that will be excluded from the tracing process.
|
|
16
16
|
const ignore = ['node_modules/aws-sdk/**'];
|
|
17
17
|
const appearsToBeModuleName = (name) => !name.startsWith('.');
|
|
18
18
|
const bundle = async ({ basePath, config, featureFlags, mainFile, pluginsModulesPath, repositoryRoot = basePath, }) => {
|
|
19
19
|
const { includedFiles = [], includedFilesBasePath } = config;
|
|
20
|
-
const { exclude: excludedPaths, paths: includedFilePaths } = await (0,
|
|
20
|
+
const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath || basePath);
|
|
21
21
|
const { moduleFormat, paths: dependencyPaths, rewrites, } = await traceFilesAndTranspile({
|
|
22
22
|
basePath: repositoryRoot,
|
|
23
23
|
config,
|
|
@@ -25,12 +25,12 @@ const bundle = async ({ basePath, config, featureFlags, mainFile, pluginsModules
|
|
|
25
25
|
mainFile,
|
|
26
26
|
pluginsModulesPath,
|
|
27
27
|
});
|
|
28
|
-
const filteredIncludedPaths = (0,
|
|
28
|
+
const filteredIncludedPaths = (0, included_files_js_1.filterExcludedPaths)([...dependencyPaths, ...includedFilePaths], excludedPaths);
|
|
29
29
|
const dirnames = filteredIncludedPaths.map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath))).sort();
|
|
30
30
|
// Sorting the array to make the checksum deterministic.
|
|
31
31
|
const srcFiles = [...filteredIncludedPaths].sort();
|
|
32
32
|
return {
|
|
33
|
-
basePath: (0,
|
|
33
|
+
basePath: (0, base_path_js_1.getBasePath)(dirnames),
|
|
34
34
|
inputs: dependencyPaths,
|
|
35
35
|
mainFile,
|
|
36
36
|
moduleFormat,
|
|
@@ -50,7 +50,7 @@ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags,
|
|
|
50
50
|
ignore: ignoreFunction,
|
|
51
51
|
readFile: async (path) => {
|
|
52
52
|
try {
|
|
53
|
-
const source = (await (0,
|
|
53
|
+
const source = (await (0, fs_js_1.cachedReadFile)(fsCache, path, 'utf8'));
|
|
54
54
|
return source;
|
|
55
55
|
}
|
|
56
56
|
catch (error) {
|
|
@@ -62,7 +62,7 @@ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags,
|
|
|
62
62
|
},
|
|
63
63
|
resolve: async (specifier, parent, ...args) => {
|
|
64
64
|
try {
|
|
65
|
-
return await (0,
|
|
65
|
+
return await (0, resolve_dependency_js_1.default)(specifier, parent, ...args);
|
|
66
66
|
}
|
|
67
67
|
catch (error) {
|
|
68
68
|
// If we get a `MODULE_NOT_FOUND` error for what appears to be a module
|
|
@@ -70,14 +70,14 @@ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags,
|
|
|
70
70
|
// as the base directory.
|
|
71
71
|
if (error.code === 'MODULE_NOT_FOUND' && pluginsModulesPath && appearsToBeModuleName(specifier)) {
|
|
72
72
|
const newParent = (0, path_1.join)(pluginsModulesPath, (0, path_1.basename)(parent));
|
|
73
|
-
return await (0,
|
|
73
|
+
return await (0, resolve_dependency_js_1.default)(specifier, newParent, ...args);
|
|
74
74
|
}
|
|
75
75
|
throw error;
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
});
|
|
79
79
|
const normalizedDependencyPaths = [...dependencyPaths].map((path) => basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path));
|
|
80
|
-
const { moduleFormat, rewrites } = await (0,
|
|
80
|
+
const { moduleFormat, rewrites } = await (0, es_modules_js_1.processESM)({
|
|
81
81
|
basePath,
|
|
82
82
|
config,
|
|
83
83
|
esmPaths: esmFileList,
|
|
@@ -94,10 +94,10 @@ const traceFilesAndTranspile = async function ({ basePath, config, featureFlags,
|
|
|
94
94
|
};
|
|
95
95
|
const getSrcFiles = async function ({ basePath, config, mainFile }) {
|
|
96
96
|
const { includedFiles = [], includedFilesBasePath } = config;
|
|
97
|
-
const { exclude: excludedPaths, paths: includedFilePaths } = await (0,
|
|
97
|
+
const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
|
|
98
98
|
const { fileList: dependencyPaths } = await (0, nft_1.nodeFileTrace)([mainFile], { base: basePath, ignore: ignoreFunction });
|
|
99
99
|
const normalizedDependencyPaths = [...dependencyPaths].map((path) => basePath ? (0, path_1.resolve)(basePath, path) : (0, path_1.resolve)(path));
|
|
100
|
-
const includedPaths = (0,
|
|
100
|
+
const includedPaths = (0, included_files_js_1.filterExcludedPaths)([...normalizedDependencyPaths, ...includedFilePaths], excludedPaths);
|
|
101
101
|
return includedPaths;
|
|
102
102
|
};
|
|
103
103
|
const bundler = { bundle, getSrcFiles };
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { FunctionConfig } from '../../../../config';
|
|
2
|
-
declare const transpile: (path: string, config: FunctionConfig) => Promise<string>;
|
|
3
|
-
export { transpile };
|
|
1
|
+
import type { FunctionConfig } from '../../../../config.js';
|
|
2
|
+
export declare const transpile: (path: string, config: FunctionConfig) => Promise<string>;
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.transpile = void 0;
|
|
4
4
|
const esbuild_1 = require("@netlify/esbuild");
|
|
5
|
-
const
|
|
5
|
+
const bundler_target_js_1 = require("../esbuild/bundler_target.js");
|
|
6
6
|
const transpile = async (path, config) => {
|
|
7
7
|
// The version of ECMAScript to use as the build target. This will determine
|
|
8
8
|
// whether certain features are transpiled down or left untransformed.
|
|
9
|
-
const nodeTarget = (0,
|
|
9
|
+
const nodeTarget = (0, bundler_target_js_1.getBundlerTarget)(config.nodeVersion);
|
|
10
10
|
const transpiled = await (0, esbuild_1.build)({
|
|
11
11
|
bundle: false,
|
|
12
12
|
entryPoints: [path],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { BundleFunction } from '
|
|
1
|
+
import type { BundleFunction } from '../index.js';
|
|
2
2
|
declare const bundler: {
|
|
3
3
|
bundle: BundleFunction;
|
|
4
|
-
getSrcFiles: import("
|
|
4
|
+
getSrcFiles: import("../index.js").GetSrcFilesFunction;
|
|
5
5
|
};
|
|
6
6
|
export default bundler;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const path_1 = require("path");
|
|
4
|
-
const
|
|
5
|
-
const
|
|
4
|
+
const base_path_js_1 = require("../../utils/base_path.js");
|
|
5
|
+
const src_files_js_1 = require("./src_files.js");
|
|
6
6
|
const bundle = async ({ basePath, config, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, runtime, srcDir, srcPath, stat, }) => {
|
|
7
|
-
const srcFiles = await (0,
|
|
7
|
+
const srcFiles = await (0, src_files_js_1.getSrcFiles)({
|
|
8
8
|
basePath,
|
|
9
9
|
config: {
|
|
10
10
|
...config,
|
|
@@ -23,13 +23,13 @@ const bundle = async ({ basePath, config, extension, featureFlags, filename, mai
|
|
|
23
23
|
});
|
|
24
24
|
const dirnames = srcFiles.map((filePath) => (0, path_1.normalize)((0, path_1.dirname)(filePath)));
|
|
25
25
|
return {
|
|
26
|
-
basePath: (0,
|
|
26
|
+
basePath: (0, base_path_js_1.getBasePath)(dirnames),
|
|
27
27
|
inputs: srcFiles,
|
|
28
28
|
mainFile,
|
|
29
29
|
moduleFormat: 'cjs',
|
|
30
30
|
srcFiles,
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
|
-
const bundler = { bundle, getSrcFiles:
|
|
33
|
+
const bundler = { bundle, getSrcFiles: src_files_js_1.getSrcFiles };
|
|
34
34
|
exports.default = bundler;
|
|
35
35
|
//# sourceMappingURL=index.js.map
|
|
@@ -30,7 +30,7 @@ exports.listImports = void 0;
|
|
|
30
30
|
const esbuild = __importStar(require("@netlify/esbuild"));
|
|
31
31
|
const is_builtin_module_1 = __importDefault(require("is-builtin-module"));
|
|
32
32
|
const tmp_promise_1 = require("tmp-promise");
|
|
33
|
-
const
|
|
33
|
+
const fs_js_1 = require("../../../../utils/fs.js");
|
|
34
34
|
// Maximum number of log messages that an esbuild instance will produce. This
|
|
35
35
|
// limit is important to avoid out-of-memory errors due to too much data being
|
|
36
36
|
// sent in the Go<>Node IPC channel.
|
|
@@ -51,7 +51,7 @@ const getListImportsPlugin = ({ imports, path }) => ({
|
|
|
51
51
|
});
|
|
52
52
|
},
|
|
53
53
|
});
|
|
54
|
-
const listImports = async ({ functionName, path }) => {
|
|
54
|
+
const listImports = async ({ functionName, path, }) => {
|
|
55
55
|
// We're not interested in the output that esbuild generates, we're just
|
|
56
56
|
// using it for its parsing capabilities in order to find import/require
|
|
57
57
|
// statements. However, if we don't give esbuild a path in `outfile`, it
|
|
@@ -82,7 +82,7 @@ const listImports = async ({ functionName, path }) => {
|
|
|
82
82
|
throw error;
|
|
83
83
|
}
|
|
84
84
|
finally {
|
|
85
|
-
await (0,
|
|
85
|
+
await (0, fs_js_1.safeUnlink)(targetPath);
|
|
86
86
|
}
|
|
87
87
|
return [...imports];
|
|
88
88
|
};
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { PackageJson } from '../../utils/package_json';
|
|
2
|
-
declare const getNestedDependencies: ({ dependencies, peerDependencies, optionalDependencies, }: PackageJson) => string[];
|
|
3
|
-
declare const handleModuleNotFound: ({ error, moduleName, packageJson, }: {
|
|
1
|
+
import { PackageJson } from '../../utils/package_json.js';
|
|
2
|
+
export declare const getNestedDependencies: ({ dependencies, peerDependencies, optionalDependencies, }: PackageJson) => string[];
|
|
3
|
+
export declare const handleModuleNotFound: ({ error, moduleName, packageJson, }: {
|
|
4
4
|
error: Error & {
|
|
5
5
|
code: string;
|
|
6
6
|
};
|
|
7
7
|
moduleName: string;
|
|
8
8
|
packageJson: PackageJson;
|
|
9
9
|
}) => [] | never;
|
|
10
|
-
export { getNestedDependencies, handleModuleNotFound };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const getPublishedFiles: (modulePath: string) => Promise<string[]>;
|
|
2
|
-
export { getPublishedFiles };
|
|
1
|
+
export declare const getPublishedFiles: (modulePath: string) => Promise<string[]>;
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
declare const resolvePackage: (moduleName: string, baseDirs: string[]) => Promise<string>;
|
|
2
|
-
declare const resolvePathPreserveSymlinks: (path: string, baseDirs: string[]) => Promise<string>;
|
|
3
|
-
export { resolvePackage, resolvePathPreserveSymlinks };
|
|
1
|
+
export declare const resolvePackage: (moduleName: string, baseDirs: string[]) => Promise<string>;
|
|
2
|
+
export declare const resolvePathPreserveSymlinks: (path: string, baseDirs: string[]) => Promise<string>;
|
|
@@ -28,7 +28,7 @@ const BACKSLASH_REGEXP = /\\/g;
|
|
|
28
28
|
// So, on errors, we fallback to `require.resolve()`
|
|
29
29
|
const resolvePackage = async function (moduleName, baseDirs) {
|
|
30
30
|
try {
|
|
31
|
-
return await resolvePathPreserveSymlinks(`${moduleName}/package.json`, baseDirs);
|
|
31
|
+
return await (0, exports.resolvePathPreserveSymlinks)(`${moduleName}/package.json`, baseDirs);
|
|
32
32
|
}
|
|
33
33
|
catch (error) {
|
|
34
34
|
if (semver_1.default.lt(process_1.version, REQUEST_RESOLVE_MIN_VERSION)) {
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const getSideFiles: (modulePath: string, moduleName: string) => Promise<string[]>;
|
|
2
|
-
export { getSideFiles };
|
|
1
|
+
export declare const getSideFiles: (modulePath: string, moduleName: string) => Promise<string[]>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getSideFiles = void 0;
|
|
4
|
-
const
|
|
4
|
+
const published_js_1 = require("./published.js");
|
|
5
5
|
// Some modules generate source files on `postinstall` that are not located
|
|
6
6
|
// inside the module's directory itself.
|
|
7
7
|
const getSideFiles = async function (modulePath, moduleName) {
|
|
@@ -9,7 +9,7 @@ const getSideFiles = async function (modulePath, moduleName) {
|
|
|
9
9
|
if (sideFiles === undefined) {
|
|
10
10
|
return [];
|
|
11
11
|
}
|
|
12
|
-
return await (0,
|
|
12
|
+
return await (0, published_js_1.getPublishedFiles)(`${modulePath}/${sideFiles}`);
|
|
13
13
|
};
|
|
14
14
|
exports.getSideFiles = getSideFiles;
|
|
15
15
|
const SIDE_FILES = {
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { GetSrcFilesFunction } from '
|
|
2
|
-
declare const getSrcFiles: GetSrcFilesFunction;
|
|
3
|
-
export { getSrcFiles };
|
|
1
|
+
import type { GetSrcFilesFunction } from '../index.js';
|
|
2
|
+
export declare const getSrcFiles: GetSrcFilesFunction;
|
|
@@ -8,23 +8,23 @@ exports.getSrcFiles = void 0;
|
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const junk_1 = require("junk");
|
|
10
10
|
const precinct_1 = __importDefault(require("precinct"));
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
11
|
+
const non_nullable_js_1 = require("../../../../utils/non_nullable.js");
|
|
12
|
+
const included_files_js_1 = require("../../utils/included_files.js");
|
|
13
|
+
const package_json_js_1 = require("../../utils/package_json.js");
|
|
14
|
+
const traversal_cache_js_1 = require("../../utils/traversal_cache.js");
|
|
15
|
+
const list_imports_js_1 = require("./list_imports.js");
|
|
16
|
+
const resolve_js_1 = require("./resolve.js");
|
|
17
|
+
const traverse_js_1 = require("./traverse.js");
|
|
18
|
+
const tree_files_js_1 = require("./tree_files.js");
|
|
19
|
+
const tree_shake_js_1 = require("./tree_shake.js");
|
|
20
20
|
// Retrieve the paths to the Node.js files to zip.
|
|
21
21
|
// We only include the files actually needed by the function because AWS Lambda
|
|
22
22
|
// has a size limit for the zipped file. It also makes cold starts faster.
|
|
23
23
|
const getSrcFiles = async function ({ config, featureFlags, mainFile, name, pluginsModulesPath, srcDir, srcPath, stat, }) {
|
|
24
24
|
const { includedFiles = [], includedFilesBasePath } = config;
|
|
25
|
-
const { exclude: excludedPaths, paths: includedFilePaths } = await (0,
|
|
25
|
+
const { exclude: excludedPaths, paths: includedFilePaths } = await (0, included_files_js_1.getPathsOfIncludedFiles)(includedFiles, includedFilesBasePath);
|
|
26
26
|
const [treeFiles, depFiles] = await Promise.all([
|
|
27
|
-
(0,
|
|
27
|
+
(0, tree_files_js_1.getTreeFiles)(srcPath, stat),
|
|
28
28
|
getDependencies({ featureFlags, functionName: name, mainFile, pluginsModulesPath, srcDir }),
|
|
29
29
|
]);
|
|
30
30
|
const files = [...treeFiles, ...depFiles].map(path_1.normalize);
|
|
@@ -32,7 +32,7 @@ const getSrcFiles = async function ({ config, featureFlags, mainFile, name, plug
|
|
|
32
32
|
// We sort so that the archive's checksum is deterministic.
|
|
33
33
|
// Mutating is fine since `Array.filter()` returns a shallow copy
|
|
34
34
|
const filteredFiles = uniqueFiles.filter(isNotJunk).sort();
|
|
35
|
-
const includedPaths = (0,
|
|
35
|
+
const includedPaths = (0, included_files_js_1.filterExcludedPaths)([...filteredFiles, ...includedFilePaths], excludedPaths);
|
|
36
36
|
return includedPaths;
|
|
37
37
|
};
|
|
38
38
|
exports.getSrcFiles = getSrcFiles;
|
|
@@ -42,8 +42,8 @@ const isNotJunk = function (file) {
|
|
|
42
42
|
};
|
|
43
43
|
// Retrieve all the files recursively required by a Node.js file
|
|
44
44
|
const getDependencies = async function ({ featureFlags, functionName, mainFile, pluginsModulesPath, srcDir, }) {
|
|
45
|
-
const packageJson = await (0,
|
|
46
|
-
const state = (0,
|
|
45
|
+
const packageJson = await (0, package_json_js_1.getPackageJson)(srcDir);
|
|
46
|
+
const state = (0, traversal_cache_js_1.getNewCache)();
|
|
47
47
|
try {
|
|
48
48
|
return await getFileDependencies({
|
|
49
49
|
featureFlags,
|
|
@@ -66,9 +66,9 @@ const getFileDependencies = async function ({ featureFlags, functionName, path,
|
|
|
66
66
|
state.localFiles.add(path);
|
|
67
67
|
const basedir = (0, path_1.dirname)(path);
|
|
68
68
|
const dependencies = featureFlags.parseWithEsbuild
|
|
69
|
-
? await (0,
|
|
69
|
+
? await (0, list_imports_js_1.listImports)({ functionName, path })
|
|
70
70
|
: await precinct_1.default.paperwork(path, { includeCore: false });
|
|
71
|
-
const depsPaths = await Promise.all(dependencies.filter(
|
|
71
|
+
const depsPaths = await Promise.all(dependencies.filter(non_nullable_js_1.nonNullable).map((dependency) => getImportDependencies({
|
|
72
72
|
dependency,
|
|
73
73
|
basedir,
|
|
74
74
|
featureFlags,
|
|
@@ -82,7 +82,7 @@ const getFileDependencies = async function ({ featureFlags, functionName, path,
|
|
|
82
82
|
};
|
|
83
83
|
const getImportDependencies = function ({ dependency, basedir, featureFlags, functionName, packageJson, pluginsModulesPath, state, treeShakeNext, }) {
|
|
84
84
|
const shouldTreeShakeNext = treeShakeNext || isNextOnNetlify(dependency);
|
|
85
|
-
if ((0,
|
|
85
|
+
if ((0, tree_shake_js_1.shouldTreeShake)(dependency, shouldTreeShakeNext)) {
|
|
86
86
|
return getTreeShakedDependencies({
|
|
87
87
|
dependency,
|
|
88
88
|
basedir,
|
|
@@ -94,14 +94,14 @@ const getImportDependencies = function ({ dependency, basedir, featureFlags, fun
|
|
|
94
94
|
treeShakeNext: shouldTreeShakeNext,
|
|
95
95
|
});
|
|
96
96
|
}
|
|
97
|
-
return (0,
|
|
97
|
+
return (0, traverse_js_1.getDependencyPathsForDependency)({ dependency, basedir, state, packageJson, pluginsModulesPath });
|
|
98
98
|
};
|
|
99
99
|
const isNextOnNetlify = function (dependency) {
|
|
100
100
|
return (0, path_1.basename)(dependency, '.js') === 'renderNextPage';
|
|
101
101
|
};
|
|
102
102
|
// When a file requires another one, we apply the top-level logic recursively
|
|
103
103
|
const getTreeShakedDependencies = async function ({ dependency, basedir, featureFlags, functionName, packageJson, pluginsModulesPath, state, treeShakeNext, }) {
|
|
104
|
-
const path = await (0,
|
|
104
|
+
const path = await (0, resolve_js_1.resolvePathPreserveSymlinks)(dependency, [basedir, pluginsModulesPath].filter(non_nullable_js_1.nonNullable));
|
|
105
105
|
const depsPath = await getFileDependencies({
|
|
106
106
|
featureFlags,
|
|
107
107
|
functionName,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { PackageJson } from '../../utils/package_json';
|
|
2
|
-
import { TraversalCache } from '../../utils/traversal_cache';
|
|
3
|
-
declare const getDependencyPathsForDependency: ({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
|
|
1
|
+
import { PackageJson } from '../../utils/package_json.js';
|
|
2
|
+
import { TraversalCache } from '../../utils/traversal_cache.js';
|
|
3
|
+
export declare const getDependencyPathsForDependency: ({ dependency, basedir, state, packageJson, pluginsModulesPath, }: {
|
|
4
4
|
dependency: string;
|
|
5
5
|
basedir: string;
|
|
6
6
|
state: TraversalCache;
|
|
7
7
|
packageJson: PackageJson;
|
|
8
8
|
pluginsModulesPath?: string | undefined;
|
|
9
9
|
}) => Promise<string[]>;
|
|
10
|
-
export { getDependencyPathsForDependency };
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getDependencyPathsForDependency = void 0;
|
|
4
|
+
const fs_1 = require("fs");
|
|
4
5
|
const path_1 = require("path");
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
6
|
+
const non_nullable_js_1 = require("../../../../utils/non_nullable.js");
|
|
7
|
+
const module_js_1 = require("../../utils/module.js");
|
|
8
|
+
const nested_js_1 = require("./nested.js");
|
|
9
|
+
const published_js_1 = require("./published.js");
|
|
10
|
+
const resolve_js_1 = require("./resolve.js");
|
|
11
|
+
const side_files_js_1 = require("./side_files.js");
|
|
11
12
|
const EXCLUDED_MODULES = new Set(['aws-sdk']);
|
|
12
13
|
// When a file requires a module, we find its path inside `node_modules` and
|
|
13
14
|
// use all its published files. We also recurse on the module's dependencies.
|
|
14
15
|
const getDependencyPathsForDependency = async function ({ dependency, basedir, state, packageJson, pluginsModulesPath, }) {
|
|
15
|
-
const moduleName = (0,
|
|
16
|
+
const moduleName = (0, module_js_1.getModuleName)(dependency);
|
|
16
17
|
// Happens when doing require("@scope") (not "@scope/name") or other oddities
|
|
17
18
|
// Ignore those.
|
|
18
19
|
if (moduleName === null) {
|
|
@@ -22,7 +23,7 @@ const getDependencyPathsForDependency = async function ({ dependency, basedir, s
|
|
|
22
23
|
return await getDependenciesForModuleName({ moduleName, basedir, state, pluginsModulesPath });
|
|
23
24
|
}
|
|
24
25
|
catch (error) {
|
|
25
|
-
return (0,
|
|
26
|
+
return (0, nested_js_1.handleModuleNotFound)({ error, moduleName, packageJson });
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
exports.getDependencyPathsForDependency = getDependencyPathsForDependency;
|
|
@@ -31,7 +32,7 @@ const getDependenciesForModuleName = async function ({ moduleName, basedir, stat
|
|
|
31
32
|
return [];
|
|
32
33
|
}
|
|
33
34
|
// Find the Node.js module directory path
|
|
34
|
-
const packagePath = await (0,
|
|
35
|
+
const packagePath = await (0, resolve_js_1.resolvePackage)(moduleName, [basedir, pluginsModulesPath].filter(non_nullable_js_1.nonNullable));
|
|
35
36
|
if (packagePath === undefined) {
|
|
36
37
|
return [];
|
|
37
38
|
}
|
|
@@ -42,11 +43,10 @@ const getDependenciesForModuleName = async function ({ moduleName, basedir, stat
|
|
|
42
43
|
state.moduleNames.add(moduleName);
|
|
43
44
|
state.modulePaths.add(modulePath);
|
|
44
45
|
// The path depends on the user's build, i.e. must be dynamic
|
|
45
|
-
|
|
46
|
-
const packageJson = require(packagePath);
|
|
46
|
+
const packageJson = JSON.parse(await fs_1.promises.readFile(packagePath, 'utf8'));
|
|
47
47
|
const [publishedFiles, sideFiles, depsPaths] = await Promise.all([
|
|
48
|
-
(0,
|
|
49
|
-
(0,
|
|
48
|
+
(0, published_js_1.getPublishedFiles)(modulePath),
|
|
49
|
+
(0, side_files_js_1.getSideFiles)(modulePath, moduleName),
|
|
50
50
|
getNestedModules({ modulePath, state, packageJson, pluginsModulesPath }),
|
|
51
51
|
]);
|
|
52
52
|
return [...publishedFiles, ...sideFiles, ...depsPaths];
|
|
@@ -55,8 +55,8 @@ const isExcludedModule = function (moduleName) {
|
|
|
55
55
|
return EXCLUDED_MODULES.has(moduleName) || moduleName.startsWith('@types/');
|
|
56
56
|
};
|
|
57
57
|
const getNestedModules = async function ({ modulePath, state, packageJson, pluginsModulesPath, }) {
|
|
58
|
-
const dependencies = (0,
|
|
59
|
-
const depsPaths = await Promise.all(dependencies.map((dependency) => getDependencyPathsForDependency({ dependency, basedir: modulePath, state, packageJson, pluginsModulesPath })));
|
|
58
|
+
const dependencies = (0, nested_js_1.getNestedDependencies)(packageJson);
|
|
59
|
+
const depsPaths = await Promise.all(dependencies.map((dependency) => (0, exports.getDependencyPathsForDependency)({ dependency, basedir: modulePath, state, packageJson, pluginsModulesPath })));
|
|
60
60
|
return depsPaths.flat();
|
|
61
61
|
};
|
|
62
62
|
//# sourceMappingURL=traverse.js.map
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
declare const shouldTreeShake: (dependency: string, treeShakeNext: boolean) => boolean;
|
|
2
|
-
export { shouldTreeShake };
|
|
1
|
+
export declare const shouldTreeShake: (dependency: string, treeShakeNext: boolean) => boolean;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.shouldTreeShake = void 0;
|
|
4
|
-
const
|
|
4
|
+
const module_js_1 = require("../../utils/module.js");
|
|
5
5
|
const LOCAL_IMPORT_REGEXP = /^(\.|\/)/;
|
|
6
6
|
// we tree shake direct local requires to bundle only relevant code
|
|
7
7
|
// we don't tree shake external dependencies since they can break our tree shaking logic by:
|
|
@@ -12,7 +12,7 @@ const shouldTreeShake = function (dependency, treeShakeNext) {
|
|
|
12
12
|
if (LOCAL_IMPORT_REGEXP.test(dependency)) {
|
|
13
13
|
return true;
|
|
14
14
|
}
|
|
15
|
-
return treeShakeNext && (0,
|
|
15
|
+
return treeShakeNext && (0, module_js_1.getModuleName)(dependency) === 'next';
|
|
16
16
|
};
|
|
17
17
|
exports.shouldTreeShake = shouldTreeShake;
|
|
18
18
|
//# sourceMappingURL=tree_shake.js.map
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { FindFunctionsInPathsFunction, FindFunctionInPathFunction } from '../runtime';
|
|
2
|
-
declare const findFunctionsInPaths: FindFunctionsInPathsFunction;
|
|
3
|
-
declare const findFunctionInPath: FindFunctionInPathFunction;
|
|
4
|
-
export { findFunctionsInPaths, findFunctionInPath };
|
|
1
|
+
import { FindFunctionsInPathsFunction, FindFunctionInPathFunction } from '../runtime.js';
|
|
2
|
+
export declare const findFunctionsInPaths: FindFunctionsInPathsFunction;
|
|
3
|
+
export declare const findFunctionInPath: FindFunctionInPathFunction;
|
|
@@ -7,7 +7,7 @@ exports.findFunctionInPath = exports.findFunctionsInPaths = void 0;
|
|
|
7
7
|
const fs_1 = require("fs");
|
|
8
8
|
const path_1 = require("path");
|
|
9
9
|
const locate_path_1 = __importDefault(require("locate-path"));
|
|
10
|
-
const
|
|
10
|
+
const non_nullable_js_1 = require("../../utils/non_nullable.js");
|
|
11
11
|
// List of extensions that this runtime will look for, in order of precedence.
|
|
12
12
|
const allowedExtensions = ['.js', '.zip', '.cjs', '.mjs', '.ts'];
|
|
13
13
|
// Sorting function, compatible with the callback of Array.sort, which sorts
|
|
@@ -20,9 +20,9 @@ const sortByExtension = (fA, fB) => {
|
|
|
20
20
|
return indexB - indexA;
|
|
21
21
|
};
|
|
22
22
|
const findFunctionsInPaths = async function ({ paths, fsCache, featureFlags }) {
|
|
23
|
-
const functions = await Promise.all(paths.map((path) => findFunctionInPath({ path, fsCache, featureFlags })));
|
|
23
|
+
const functions = await Promise.all(paths.map((path) => (0, exports.findFunctionInPath)({ path, fsCache, featureFlags })));
|
|
24
24
|
// It's fine to mutate the array since its scope is local to this function.
|
|
25
|
-
const sortedFunctions = functions.filter(
|
|
25
|
+
const sortedFunctions = functions.filter(non_nullable_js_1.nonNullable).sort((fA, fB) => {
|
|
26
26
|
// We first sort the functions array to put directories first. This is so
|
|
27
27
|
// that `{name}/{name}.js` takes precedence over `{name}.js`.
|
|
28
28
|
const directorySort = Number(fA.stat.isDirectory()) - Number(fB.stat.isDirectory());
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName } from '@babel/types';
|
|
2
|
-
import { parse as parseSchedule } from './properties/schedule';
|
|
3
|
-
declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
|
|
4
|
-
declare type ISCValues = Partial<ReturnType<typeof parseSchedule>>;
|
|
5
|
-
declare const findISCDeclarationsInPath: (sourcePath: string) => Promise<ISCValues>;
|
|
6
|
-
declare type ISCHandlerArg = ArgumentPlaceholder | Expression | SpreadElement | JSXNamespacedName;
|
|
7
|
-
interface ISCExport {
|
|
2
|
+
import { parse as parseSchedule } from './properties/schedule.js';
|
|
3
|
+
export declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
|
|
4
|
+
export declare type ISCValues = Partial<ReturnType<typeof parseSchedule>>;
|
|
5
|
+
export declare const findISCDeclarationsInPath: (sourcePath: string) => Promise<ISCValues>;
|
|
6
|
+
export declare type ISCHandlerArg = ArgumentPlaceholder | Expression | SpreadElement | JSXNamespacedName;
|
|
7
|
+
export interface ISCExport {
|
|
8
8
|
local: string;
|
|
9
9
|
args: ISCHandlerArg[];
|
|
10
10
|
}
|
|
11
|
-
export { findISCDeclarationsInPath, IN_SOURCE_CONFIG_MODULE };
|
|
12
|
-
export type { ISCExport, ISCHandlerArg, ISCValues };
|
|
@@ -1,24 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
exports.IN_SOURCE_CONFIG_MODULE = IN_SOURCE_CONFIG_MODULE;
|
|
3
|
+
exports.findISCDeclarationsInPath = exports.IN_SOURCE_CONFIG_MODULE = void 0;
|
|
4
|
+
const non_nullable_js_1 = require("../../../utils/non_nullable.js");
|
|
5
|
+
const exports_js_1 = require("../parser/exports.js");
|
|
6
|
+
const imports_js_1 = require("../parser/imports.js");
|
|
7
|
+
const index_js_1 = require("../parser/index.js");
|
|
8
|
+
const schedule_js_1 = require("./properties/schedule.js");
|
|
9
|
+
exports.IN_SOURCE_CONFIG_MODULE = '@netlify/functions';
|
|
11
10
|
// Parses a JS/TS file and looks for in-source config declarations. It returns
|
|
12
11
|
// an array of all declarations found, with `property` indicating the name of
|
|
13
12
|
// the property and `data` its value.
|
|
14
13
|
const findISCDeclarationsInPath = async (sourcePath) => {
|
|
15
|
-
const ast = await (0,
|
|
14
|
+
const ast = await (0, index_js_1.safelyParseFile)(sourcePath);
|
|
16
15
|
if (ast === null) {
|
|
17
16
|
return {};
|
|
18
17
|
}
|
|
19
|
-
const imports = ast.body.flatMap((node) => (0,
|
|
20
|
-
const
|
|
21
|
-
const iscExports =
|
|
18
|
+
const imports = ast.body.flatMap((node) => (0, imports_js_1.getImports)(node, exports.IN_SOURCE_CONFIG_MODULE));
|
|
19
|
+
const mainExports = (0, exports_js_1.getMainExport)(ast.body);
|
|
20
|
+
const iscExports = mainExports
|
|
22
21
|
.map(({ args, local: exportName }) => {
|
|
23
22
|
const matchingImport = imports.find(({ local: importName }) => importName === exportName);
|
|
24
23
|
if (matchingImport === undefined) {
|
|
@@ -26,13 +25,13 @@ const findISCDeclarationsInPath = async (sourcePath) => {
|
|
|
26
25
|
}
|
|
27
26
|
switch (matchingImport.imported) {
|
|
28
27
|
case 'schedule':
|
|
29
|
-
return (0,
|
|
28
|
+
return (0, schedule_js_1.parse)({ args });
|
|
30
29
|
default:
|
|
31
30
|
// no-op
|
|
32
31
|
}
|
|
33
32
|
return null;
|
|
34
33
|
})
|
|
35
|
-
.filter(
|
|
34
|
+
.filter(non_nullable_js_1.nonNullable);
|
|
36
35
|
const mergedExports = iscExports.reduce((acc, obj) => ({ ...acc, ...obj }), {});
|
|
37
36
|
return mergedExports;
|
|
38
37
|
};
|