@netlify/zip-it-and-ship-it 6.0.0 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/config.d.ts +2 -0
- package/dist/feature_flags.d.ts +1 -1
- package/dist/feature_flags.js +9 -0
- package/dist/main.d.ts +3 -3
- package/dist/runtimes/node/bundlers/esbuild/bundler.d.ts +5 -2
- package/dist/runtimes/node/bundlers/esbuild/bundler.js +16 -8
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +1 -1
- package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +7 -1
- package/dist/runtimes/node/bundlers/esbuild/index.js +3 -2
- package/dist/runtimes/node/bundlers/index.js +7 -2
- package/dist/runtimes/node/bundlers/nft/es_modules.js +8 -0
- package/dist/runtimes/node/bundlers/zisi/resolve.js +1 -3
- package/dist/runtimes/node/bundlers/zisi/src_files.js +0 -2
- package/dist/runtimes/node/finder.js +9 -1
- package/dist/runtimes/node/index.js +1 -0
- package/dist/runtimes/node/parser/index.d.ts +1 -1
- package/dist/runtimes/node/parser/index.js +0 -2
- package/dist/runtimes/node/utils/entry_file.d.ts +2 -7
- package/dist/runtimes/node/utils/entry_file.js +2 -12
- package/dist/runtimes/node/utils/module_format.d.ts +7 -0
- package/dist/runtimes/node/utils/module_format.js +8 -0
- package/dist/runtimes/node/utils/zip.d.ts +3 -1
- package/dist/runtimes/node/utils/zip.js +13 -9
- package/dist/utils/fs.d.ts +6 -5
- package/dist/utils/remove_undefined.d.ts +3 -1
- package/dist/zip.d.ts +2 -2
- package/dist/zip.js +14 -2
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -51,9 +51,8 @@ In Netlify, this directory is the
|
|
|
51
51
|
|
|
52
52
|
A source folder can contain:
|
|
53
53
|
|
|
54
|
-
- Sub-directories with a main file called `index.js
|
|
55
|
-
|
|
56
|
-
- `.js` or `.ts` files (Node.js)
|
|
54
|
+
- Sub-directories with a main file called `index.js` or `{dir}.js` where `{dir}` is the sub-directory name.
|
|
55
|
+
- `.js`, `.mjs`, `.cjs`, `.ts`, `.tsx`, `.mts` or `.cts` files (Node.js)
|
|
57
56
|
- `.zip` archives with Node.js already ready to upload to AWS Lambda.
|
|
58
57
|
- Go programs already compiled. Those are copied as is.
|
|
59
58
|
- Rust programs already compiled. Those are zipped.
|
package/dist/config.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { FeatureFlags } from './feature_flags.js';
|
|
|
2
2
|
import { FunctionSource } from './function.js';
|
|
3
3
|
import type { NodeBundlerType } from './runtimes/node/bundlers/types.js';
|
|
4
4
|
import type { NodeVersionString } from './runtimes/node/index.js';
|
|
5
|
+
import type { ModuleFormat } from './runtimes/node/utils/module_format.js';
|
|
5
6
|
interface FunctionConfig {
|
|
6
7
|
externalNodeModules?: string[];
|
|
7
8
|
includedFiles?: string[];
|
|
@@ -14,6 +15,7 @@ interface FunctionConfig {
|
|
|
14
15
|
rustTargetDirectory?: string;
|
|
15
16
|
schedule?: string;
|
|
16
17
|
zipGo?: boolean;
|
|
18
|
+
nodeModuleFormat?: ModuleFormat;
|
|
17
19
|
}
|
|
18
20
|
declare type GlobPattern = string;
|
|
19
21
|
declare type Config = Record<GlobPattern, FunctionConfig>;
|
package/dist/feature_flags.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare const defaultFlags: Record<string, boolean>;
|
|
2
2
|
export declare type FeatureFlag = keyof typeof defaultFlags;
|
|
3
3
|
export declare type FeatureFlags = Record<FeatureFlag, boolean>;
|
|
4
|
-
export declare const getFlags: (input?: Record<string, boolean>, flags?: Record<string, boolean>) =>
|
|
4
|
+
export declare const getFlags: (input?: Record<string, boolean>, flags?: Record<string, boolean>) => FeatureFlags;
|
package/dist/feature_flags.js
CHANGED
|
@@ -3,10 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getFlags = exports.defaultFlags = void 0;
|
|
4
4
|
const process_1 = require("process");
|
|
5
5
|
exports.defaultFlags = {
|
|
6
|
+
// Build Rust functions from source.
|
|
6
7
|
buildRustSource: Boolean(process_1.env.NETLIFY_EXPERIMENTAL_BUILD_RUST_SOURCE),
|
|
8
|
+
// Use esbuild to trace dependencies in the legacy bundler.
|
|
7
9
|
parseWithEsbuild: false,
|
|
10
|
+
// Use NFT as the default bundler.
|
|
8
11
|
traceWithNft: false,
|
|
12
|
+
// Output pure (i.e. untranspiled) ESM files when the function file has ESM
|
|
13
|
+
// syntax and the parent `package.json` file has `{"type": "module"}`.
|
|
9
14
|
zisi_pure_esm: false,
|
|
15
|
+
// Output pure (i.e. untranspiled) ESM files when the function file has a
|
|
16
|
+
// `.mjs` extension.
|
|
17
|
+
zisi_pure_esm_mjs: false,
|
|
18
|
+
// Load configuration from per-function JSON files.
|
|
10
19
|
project_deploy_configuration_api_use_per_function_configuration_files: false,
|
|
11
20
|
};
|
|
12
21
|
// List of supported flags and their default value.
|
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
|
|
24
|
+
export declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags, 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
|
|
29
|
+
export declare const listFunction: (path: string, { featureFlags, 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
|
|
34
|
+
export declare const listFunctionsFiles: (relativeSrcFolders: string | string[], { basePath, config, featureFlags, parseISC }?: ListFunctionsOptions) => Promise<ListedFunctionFile[]>;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { FunctionConfig } from '../../../../config.js';
|
|
2
2
|
import { FeatureFlags } from '../../../../feature_flags.js';
|
|
3
|
+
import { ModuleFileExtension, ModuleFormat } from '../../utils/module_format.js';
|
|
3
4
|
export declare const ESBUILD_LOG_LIMIT = 10;
|
|
4
|
-
export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, externalModules, featureFlags, ignoredModules, name, srcDir, srcFile, }: {
|
|
5
|
+
export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, externalModules, featureFlags, ignoredModules, mainFile, name, srcDir, srcFile, }: {
|
|
5
6
|
additionalModulePaths?: string[] | undefined;
|
|
6
7
|
basePath?: string | undefined;
|
|
7
8
|
config: FunctionConfig;
|
|
8
9
|
externalModules: string[];
|
|
9
10
|
featureFlags: FeatureFlags;
|
|
10
11
|
ignoredModules: string[];
|
|
12
|
+
mainFile: string;
|
|
11
13
|
name: string;
|
|
12
14
|
srcDir: string;
|
|
13
15
|
srcFile: string;
|
|
@@ -15,8 +17,9 @@ export declare const bundleJsFile: ({ additionalModulePaths, basePath, config, e
|
|
|
15
17
|
additionalPaths: string[];
|
|
16
18
|
bundlePaths: Map<string, string>;
|
|
17
19
|
cleanTempFiles: () => Promise<void>;
|
|
20
|
+
extension: ModuleFileExtension;
|
|
18
21
|
inputs: string[];
|
|
19
|
-
moduleFormat:
|
|
22
|
+
moduleFormat: ModuleFormat;
|
|
20
23
|
nativeNodeModules: {};
|
|
21
24
|
nodeModulesWithDynamicImports: string[];
|
|
22
25
|
warnings: import("@netlify/esbuild").Message[];
|
|
@@ -6,6 +6,7 @@ const esbuild_1 = require("@netlify/esbuild");
|
|
|
6
6
|
const tmp_promise_1 = require("tmp-promise");
|
|
7
7
|
const error_js_1 = require("../../../../utils/error.js");
|
|
8
8
|
const fs_js_1 = require("../../../../utils/fs.js");
|
|
9
|
+
const module_format_js_1 = require("../../utils/module_format.js");
|
|
9
10
|
const bundler_target_js_1 = require("./bundler_target.js");
|
|
10
11
|
const plugin_dynamic_imports_js_1 = require("./plugin_dynamic_imports.js");
|
|
11
12
|
const plugin_native_modules_js_1 = require("./plugin_native_modules.js");
|
|
@@ -16,9 +17,9 @@ const plugin_node_builtin_js_1 = require("./plugin_node_builtin.js");
|
|
|
16
17
|
exports.ESBUILD_LOG_LIMIT = 10;
|
|
17
18
|
// When resolving imports with no extension (e.g. require('./foo')), these are
|
|
18
19
|
// the extensions that esbuild will look for, in this order.
|
|
19
|
-
const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.json'];
|
|
20
|
+
const RESOLVE_EXTENSIONS = ['.js', '.jsx', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts', '.json'];
|
|
20
21
|
// eslint-disable-next-line max-statements
|
|
21
|
-
const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], featureFlags, ignoredModules = [], name, srcDir, srcFile, }) {
|
|
22
|
+
const bundleJsFile = async function ({ additionalModulePaths, basePath, config, externalModules = [], featureFlags, ignoredModules = [], mainFile, name, srcDir, srcFile, }) {
|
|
22
23
|
// We use a temporary directory as the destination for esbuild files to avoid
|
|
23
24
|
// any naming conflicts with files generated by other functions.
|
|
24
25
|
const targetDirectory = await (0, tmp_promise_1.tmpName)();
|
|
@@ -56,7 +57,11 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
56
57
|
// Configuring the output format of esbuild. The `includedFiles` array we get
|
|
57
58
|
// here contains additional paths to include with the bundle, like the path
|
|
58
59
|
// to a `package.json` with {"type": "module"} in case of an ESM function.
|
|
59
|
-
const { includedFiles: includedFilesFromModuleDetection, moduleFormat } = await (0, bundler_target_js_1.getModuleFormat)(srcDir, featureFlags, config.nodeVersion);
|
|
60
|
+
const { includedFiles: includedFilesFromModuleDetection, moduleFormat } = await (0, bundler_target_js_1.getModuleFormat)(srcDir, featureFlags, (0, path_1.extname)(mainFile), config.nodeVersion);
|
|
61
|
+
// The extension of the output file.
|
|
62
|
+
const extension = (0, module_format_js_1.getFileExtensionForFormat)(moduleFormat, featureFlags);
|
|
63
|
+
// When outputting an ESM file, configure esbuild to produce a `.mjs` file.
|
|
64
|
+
const outExtension = moduleFormat === "esm" /* ModuleFormat.ESM */ ? { [".js" /* ModuleFileExtension.JS */]: ".mjs" /* ModuleFileExtension.MJS */ } : undefined;
|
|
60
65
|
try {
|
|
61
66
|
const { metafile = { inputs: {}, outputs: {} }, warnings } = await (0, esbuild_1.build)({
|
|
62
67
|
bundle: true,
|
|
@@ -67,6 +72,7 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
67
72
|
logLimit: exports.ESBUILD_LOG_LIMIT,
|
|
68
73
|
metafile: true,
|
|
69
74
|
nodePaths: additionalModulePaths,
|
|
75
|
+
outExtension,
|
|
70
76
|
outdir: targetDirectory,
|
|
71
77
|
platform: 'node',
|
|
72
78
|
plugins,
|
|
@@ -77,6 +83,7 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
77
83
|
});
|
|
78
84
|
const bundlePaths = getBundlePaths({
|
|
79
85
|
destFolder: targetDirectory,
|
|
86
|
+
extension,
|
|
80
87
|
outputs: metafile.outputs,
|
|
81
88
|
srcFile,
|
|
82
89
|
});
|
|
@@ -87,6 +94,7 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
|
|
|
87
94
|
additionalPaths,
|
|
88
95
|
bundlePaths,
|
|
89
96
|
cleanTempFiles,
|
|
97
|
+
extension,
|
|
90
98
|
inputs,
|
|
91
99
|
moduleFormat,
|
|
92
100
|
nativeNodeModules,
|
|
@@ -107,8 +115,8 @@ exports.bundleJsFile = bundleJsFile;
|
|
|
107
115
|
// absolute paths of the generated files as keys, and the paths that those
|
|
108
116
|
// files should take in the generated bundle as values. This is compatible
|
|
109
117
|
// with the `aliases` format used upstream.
|
|
110
|
-
const getBundlePaths = ({ destFolder, outputs, srcFile, }) => {
|
|
111
|
-
const bundleFilename =
|
|
118
|
+
const getBundlePaths = ({ destFolder, extension: outputExtension, outputs, srcFile, }) => {
|
|
119
|
+
const bundleFilename = (0, path_1.basename)(srcFile, (0, path_1.extname)(srcFile)) + outputExtension;
|
|
112
120
|
const mainFileDirectory = (0, path_1.dirname)(srcFile);
|
|
113
121
|
const bundlePaths = new Map();
|
|
114
122
|
// The paths returned by esbuild are relative to the current directory, which
|
|
@@ -121,11 +129,11 @@ const getBundlePaths = ({ destFolder, outputs, srcFile, }) => {
|
|
|
121
129
|
const extension = (0, path_1.extname)(path);
|
|
122
130
|
const absolutePath = (0, path_1.join)(destFolder, filename);
|
|
123
131
|
if (output.entryPoint && (0, path_1.basename)(output.entryPoint) === (0, path_1.basename)(srcFile)) {
|
|
124
|
-
// Ensuring the main file has
|
|
125
|
-
const normalizedSrcFile = (0, fs_js_1.getPathWithExtension)(srcFile,
|
|
132
|
+
// Ensuring the main file has the right extension.
|
|
133
|
+
const normalizedSrcFile = (0, fs_js_1.getPathWithExtension)(srcFile, outputExtension);
|
|
126
134
|
bundlePaths.set(absolutePath, normalizedSrcFile);
|
|
127
135
|
}
|
|
128
|
-
else if (extension ===
|
|
136
|
+
else if (extension === outputExtension || filename === `${bundleFilename}.map`) {
|
|
129
137
|
bundlePaths.set(absolutePath, (0, path_1.join)(mainFileDirectory, filename));
|
|
130
138
|
}
|
|
131
139
|
});
|
|
@@ -10,7 +10,7 @@ declare const versionMap: {
|
|
|
10
10
|
};
|
|
11
11
|
declare type VersionValues = typeof versionMap[keyof typeof versionMap];
|
|
12
12
|
declare const getBundlerTarget: (suppliedVersion?: NodeVersionString) => VersionValues;
|
|
13
|
-
declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, configVersion?: string) => Promise<{
|
|
13
|
+
declare const getModuleFormat: (srcDir: string, featureFlags: FeatureFlags, extension: string, configVersion?: string) => Promise<{
|
|
14
14
|
includedFiles: string[];
|
|
15
15
|
moduleFormat: ModuleFormat;
|
|
16
16
|
}>;
|
|
@@ -18,7 +18,13 @@ const getBundlerTarget = (suppliedVersion) => {
|
|
|
18
18
|
return versionMap[`${node_version_1.DEFAULT_NODE_VERSION}.x`];
|
|
19
19
|
};
|
|
20
20
|
exports.getBundlerTarget = getBundlerTarget;
|
|
21
|
-
const getModuleFormat = async (srcDir, featureFlags, configVersion) => {
|
|
21
|
+
const getModuleFormat = async (srcDir, featureFlags, extension, configVersion) => {
|
|
22
|
+
if (extension === ".mjs" /* ModuleFileExtension.MJS */ && featureFlags.zisi_pure_esm_mjs) {
|
|
23
|
+
return {
|
|
24
|
+
includedFiles: [],
|
|
25
|
+
moduleFormat: "esm" /* ModuleFormat.ESM */,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
22
28
|
const packageJsonFile = await (0, package_json_1.getClosestPackageJson)(srcDir);
|
|
23
29
|
const nodeSupport = (0, node_version_1.getNodeSupportMatrix)(configVersion);
|
|
24
30
|
if (featureFlags.zisi_pure_esm && (packageJsonFile === null || packageJsonFile === void 0 ? void 0 : packageJsonFile.contents.type) === 'module' && nodeSupport.esm) {
|
|
@@ -30,13 +30,14 @@ const getExternalAndIgnoredModules = async ({ config, srcDir }) => {
|
|
|
30
30
|
};
|
|
31
31
|
const bundle = async ({ basePath, config = {}, extension, featureFlags, filename, mainFile, name, pluginsModulesPath, repositoryRoot, runtime, srcDir, srcPath, stat, }) => {
|
|
32
32
|
const { externalModules, ignoredModules } = await getExternalAndIgnoredModules({ config, srcDir });
|
|
33
|
-
const { additionalPaths, bundlePaths, cleanTempFiles, inputs, moduleFormat, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_js_1.bundleJsFile)({
|
|
33
|
+
const { additionalPaths, bundlePaths, cleanTempFiles, extension: outputExtension, inputs, moduleFormat, nativeNodeModules = {}, nodeModulesWithDynamicImports, warnings, } = await (0, bundler_js_1.bundleJsFile)({
|
|
34
34
|
additionalModulePaths: pluginsModulesPath ? [pluginsModulesPath] : [],
|
|
35
35
|
basePath,
|
|
36
36
|
config,
|
|
37
37
|
externalModules,
|
|
38
38
|
featureFlags,
|
|
39
39
|
ignoredModules,
|
|
40
|
+
mainFile,
|
|
40
41
|
name,
|
|
41
42
|
srcDir,
|
|
42
43
|
srcFile: mainFile,
|
|
@@ -65,7 +66,7 @@ const bundle = async ({ basePath, config = {}, extension, featureFlags, filename
|
|
|
65
66
|
// path of the original, pre-bundling function file. We'll add the actual
|
|
66
67
|
// bundled file further below.
|
|
67
68
|
const supportingSrcFiles = srcFiles.filter((path) => path !== mainFile);
|
|
68
|
-
const normalizedMainFile = (0, fs_js_1.getPathWithExtension)(mainFile,
|
|
69
|
+
const normalizedMainFile = (0, fs_js_1.getPathWithExtension)(mainFile, outputExtension);
|
|
69
70
|
const functionBasePath = getFunctionBasePath({
|
|
70
71
|
basePathFromConfig: basePath,
|
|
71
72
|
mainFile,
|
|
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getBundlerName = exports.getBundler = void 0;
|
|
7
|
+
const path_1 = require("path");
|
|
7
8
|
const detect_es_module_js_1 = require("../utils/detect_es_module.js");
|
|
8
9
|
const index_js_1 = __importDefault(require("./esbuild/index.js"));
|
|
9
10
|
const index_js_2 = __importDefault(require("./nft/index.js"));
|
|
@@ -32,16 +33,20 @@ const getBundlerName = async ({ config: { nodeBundler }, extension, featureFlags
|
|
|
32
33
|
return await getDefaultBundler({ extension, featureFlags, mainFile });
|
|
33
34
|
};
|
|
34
35
|
exports.getBundlerName = getBundlerName;
|
|
36
|
+
const ESBUILD_EXTENSIONS = new Set(['.mjs', '.ts', '.tsx', '.cts', '.mts']);
|
|
35
37
|
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
36
38
|
// esbuild is the only option.
|
|
37
39
|
const getDefaultBundler = async ({ extension, featureFlags, mainFile, }) => {
|
|
38
|
-
if (
|
|
40
|
+
if (extension === ".mjs" /* ModuleFileExtension.MJS */ && featureFlags.zisi_pure_esm_mjs) {
|
|
41
|
+
return "nft" /* NodeBundlerType.NFT */;
|
|
42
|
+
}
|
|
43
|
+
if (ESBUILD_EXTENSIONS.has(extension)) {
|
|
39
44
|
return "esbuild" /* NodeBundlerType.ESBUILD */;
|
|
40
45
|
}
|
|
41
46
|
if (featureFlags.traceWithNft) {
|
|
42
47
|
return "nft" /* NodeBundlerType.NFT */;
|
|
43
48
|
}
|
|
44
|
-
const functionIsESM = await (0, detect_es_module_js_1.detectEsModule)({ mainFile });
|
|
49
|
+
const functionIsESM = (0, path_1.extname)(mainFile) !== ".cjs" /* ModuleFileExtension.CJS */ && (await (0, detect_es_module_js_1.detectEsModule)({ mainFile }));
|
|
45
50
|
return functionIsESM ? "nft" /* NodeBundlerType.NFT */ : "zisi" /* NodeBundlerType.ZISI */;
|
|
46
51
|
};
|
|
47
52
|
//# sourceMappingURL=index.js.map
|
|
@@ -29,6 +29,14 @@ const patchESMPackage = async (path, fsCache) => {
|
|
|
29
29
|
return JSON.stringify(patchedPackageJson);
|
|
30
30
|
};
|
|
31
31
|
const processESM = async ({ basePath, config, esmPaths, featureFlags, fsCache, mainFile, reasons, name, }) => {
|
|
32
|
+
const extension = (0, path_1.extname)(mainFile);
|
|
33
|
+
// If this is a .mjs file and we want to output pure ESM files, we don't need
|
|
34
|
+
// to transpile anything.
|
|
35
|
+
if (extension === ".mjs" /* ModuleFileExtension.MJS */ && featureFlags.zisi_pure_esm_mjs) {
|
|
36
|
+
return {
|
|
37
|
+
moduleFormat: "esm" /* ModuleFormat.ESM */,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
32
40
|
const entrypointIsESM = isEntrypointESM({ basePath, esmPaths, mainFile });
|
|
33
41
|
if (!entrypointIsESM) {
|
|
34
42
|
return {
|
|
@@ -4,13 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolvePathPreserveSymlinks = exports.resolvePackage = void 0;
|
|
7
|
-
const module_1 = require("module");
|
|
8
7
|
const process_1 = require("process");
|
|
9
8
|
const find_up_1 = __importDefault(require("find-up"));
|
|
10
9
|
const path_exists_1 = __importDefault(require("path-exists"));
|
|
11
10
|
const resolve_1 = __importDefault(require("resolve"));
|
|
12
11
|
const semver_1 = __importDefault(require("semver"));
|
|
13
|
-
const requireLib = (0, module_1.createRequire)(__filename);
|
|
14
12
|
const BACKSLASH_REGEXP = /\\/g;
|
|
15
13
|
// Find the path to a module's `package.json`
|
|
16
14
|
// We need to use `resolve` instead of `require.resolve()` because:
|
|
@@ -77,7 +75,7 @@ const resolvePathPreserveSymlinks = async function (path, baseDirs) {
|
|
|
77
75
|
};
|
|
78
76
|
exports.resolvePathPreserveSymlinks = resolvePathPreserveSymlinks;
|
|
79
77
|
const resolvePathFollowSymlinks = function (path, baseDirs) {
|
|
80
|
-
return
|
|
78
|
+
return require.resolve(path, { paths: baseDirs });
|
|
81
79
|
};
|
|
82
80
|
// `require.resolve()` on a module's specific file (like `package.json`)
|
|
83
81
|
// can be forbidden by the package author by using an `exports` field in
|
|
@@ -4,7 +4,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getSrcFiles = void 0;
|
|
7
|
-
/* eslint-disable max-lines */
|
|
8
7
|
const path_1 = require("path");
|
|
9
8
|
const junk_1 = require("junk");
|
|
10
9
|
const precinct_1 = __importDefault(require("precinct"));
|
|
@@ -114,5 +113,4 @@ const getTreeShakedDependencies = async function ({ dependency, basedir, feature
|
|
|
114
113
|
});
|
|
115
114
|
return [path, ...depsPath];
|
|
116
115
|
};
|
|
117
|
-
/* eslint-enable max-lines */
|
|
118
116
|
//# sourceMappingURL=src_files.js.map
|
|
@@ -9,7 +9,7 @@ const path_1 = require("path");
|
|
|
9
9
|
const locate_path_1 = __importDefault(require("locate-path"));
|
|
10
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
|
-
const allowedExtensions = ['.js', '.zip', '.
|
|
12
|
+
const allowedExtensions = ['.js', '.zip', '.mjs', '.cjs', '.ts', '.tsx', '.mts', '.cts'];
|
|
13
13
|
// Sorting function, compatible with the callback of Array.sort, which sorts
|
|
14
14
|
// entries by extension according to their position in `allowedExtensions`.
|
|
15
15
|
// It places extensions with a higher precedence last in the array, so that
|
|
@@ -64,8 +64,16 @@ const getMainFile = async function (srcPath, filename, stat) {
|
|
|
64
64
|
(0, path_1.join)(srcPath, 'index.js'),
|
|
65
65
|
(0, path_1.join)(srcPath, `${filename}.mjs`),
|
|
66
66
|
(0, path_1.join)(srcPath, 'index.mjs'),
|
|
67
|
+
(0, path_1.join)(srcPath, `${filename}.cjs`),
|
|
68
|
+
(0, path_1.join)(srcPath, 'index.cjs'),
|
|
67
69
|
(0, path_1.join)(srcPath, `${filename}.ts`),
|
|
68
70
|
(0, path_1.join)(srcPath, 'index.ts'),
|
|
71
|
+
(0, path_1.join)(srcPath, `${filename}.tsx`),
|
|
72
|
+
(0, path_1.join)(srcPath, 'index.tsx'),
|
|
73
|
+
(0, path_1.join)(srcPath, `${filename}.mts`),
|
|
74
|
+
(0, path_1.join)(srcPath, 'index.mts'),
|
|
75
|
+
(0, path_1.join)(srcPath, `${filename}.cts`),
|
|
76
|
+
(0, path_1.join)(srcPath, 'index.cts'),
|
|
69
77
|
], { type: 'file' });
|
|
70
78
|
}
|
|
71
79
|
const extension = (0, path_1.extname)(srcPath);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.safelyParseFile = exports.parseExpression = void 0;
|
|
4
|
-
/* eslint-disable max-lines */
|
|
5
4
|
const fs_1 = require("fs");
|
|
6
5
|
const path_1 = require("path");
|
|
7
6
|
const parser_1 = require("@babel/parser");
|
|
@@ -170,5 +169,4 @@ const validateGlobNodes = (globNodes) => {
|
|
|
170
169
|
const hasStaticHead = globNodes[0] !== GLOB_WILDCARD;
|
|
171
170
|
return hasStrings && hasStaticHead;
|
|
172
171
|
};
|
|
173
|
-
/* eslint-enable max-lines */
|
|
174
172
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { ModuleFormat } from './module_format.js';
|
|
2
|
-
export
|
|
3
|
-
contents: string;
|
|
4
|
-
filename: string;
|
|
5
|
-
}
|
|
6
|
-
export declare const getEntryFile: ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }: {
|
|
2
|
+
export declare const getEntryFile: ({ commonPrefix, mainFile, moduleFormat, userNamespace, }: {
|
|
7
3
|
commonPrefix: string;
|
|
8
|
-
filename: string;
|
|
9
4
|
mainFile: string;
|
|
10
5
|
moduleFormat: ModuleFormat;
|
|
11
6
|
userNamespace: string;
|
|
12
|
-
}) =>
|
|
7
|
+
}) => string;
|
|
@@ -1,24 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.getEntryFile = void 0;
|
|
4
|
-
const path_1 = require("path");
|
|
5
4
|
const normalize_path_js_1 = require("./normalize_path.js");
|
|
6
|
-
const
|
|
5
|
+
const getEntryFile = ({ commonPrefix, mainFile, moduleFormat, userNamespace, }) => {
|
|
6
|
+
const mainPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
|
|
7
7
|
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
8
8
|
if (moduleFormat === "cjs" /* ModuleFormat.COMMONJS */) {
|
|
9
9
|
return `module.exports = require('${importPath}')`;
|
|
10
10
|
}
|
|
11
11
|
return `export { handler } from '${importPath}'`;
|
|
12
12
|
};
|
|
13
|
-
const getEntryFile = ({ commonPrefix, filename, mainFile, moduleFormat, userNamespace, }) => {
|
|
14
|
-
const mainPath = (0, normalize_path_js_1.normalizeFilePath)({ commonPrefix, path: mainFile, userNamespace });
|
|
15
|
-
const extension = (0, path_1.extname)(filename);
|
|
16
|
-
const entryFilename = `${(0, path_1.basename)(filename, extension)}.js`;
|
|
17
|
-
const contents = getEntryFileContents(mainPath, moduleFormat);
|
|
18
|
-
return {
|
|
19
|
-
contents,
|
|
20
|
-
filename: entryFilename,
|
|
21
|
-
};
|
|
22
|
-
};
|
|
23
13
|
exports.getEntryFile = getEntryFile;
|
|
24
14
|
//# sourceMappingURL=entry_file.js.map
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import type { FeatureFlags } from '../../../feature_flags.js';
|
|
1
2
|
export declare const enum ModuleFormat {
|
|
2
3
|
COMMONJS = "cjs",
|
|
3
4
|
ESM = "esm"
|
|
4
5
|
}
|
|
6
|
+
export declare const enum ModuleFileExtension {
|
|
7
|
+
CJS = ".cjs",
|
|
8
|
+
JS = ".js",
|
|
9
|
+
MJS = ".mjs"
|
|
10
|
+
}
|
|
11
|
+
export declare const getFileExtensionForFormat: (moduleFormat: ModuleFormat, featureFlags: FeatureFlags) => ModuleFileExtension;
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getFileExtensionForFormat = void 0;
|
|
4
|
+
const getFileExtensionForFormat = (moduleFormat, featureFlags) => {
|
|
5
|
+
if (moduleFormat === "esm" /* ModuleFormat.ESM */ && featureFlags.zisi_pure_esm_mjs) {
|
|
6
|
+
return ".mjs" /* ModuleFileExtension.MJS */;
|
|
7
|
+
}
|
|
8
|
+
return ".js" /* ModuleFileExtension.JS */;
|
|
9
|
+
};
|
|
10
|
+
exports.getFileExtensionForFormat = getFileExtensionForFormat;
|
|
3
11
|
//# sourceMappingURL=module_format.js.map
|
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FeatureFlags } from '../../../feature_flags.js';
|
|
2
|
+
import { ModuleFormat } from './module_format.js';
|
|
2
3
|
export declare type ArchiveFormat = 'none' | 'zip';
|
|
3
4
|
interface ZipNodeParameters {
|
|
4
5
|
aliases?: Map<string, string>;
|
|
5
6
|
basePath: string;
|
|
6
7
|
destFolder: string;
|
|
7
8
|
extension: string;
|
|
9
|
+
featureFlags: FeatureFlags;
|
|
8
10
|
filename: string;
|
|
9
11
|
mainFile: string;
|
|
10
12
|
moduleFormat: ModuleFormat;
|
|
@@ -14,26 +14,29 @@ const p_map_1 = __importDefault(require("p-map"));
|
|
|
14
14
|
const archive_js_1 = require("../../../archive.js");
|
|
15
15
|
const fs_js_1 = require("../../../utils/fs.js");
|
|
16
16
|
const entry_file_js_1 = require("./entry_file.js");
|
|
17
|
+
const module_format_js_1 = require("./module_format.js");
|
|
17
18
|
const normalize_path_js_1 = require("./normalize_path.js");
|
|
18
19
|
// Taken from https://www.npmjs.com/package/cpy.
|
|
19
20
|
const COPY_FILE_CONCURRENCY = os_1.default.cpus().length === 0 ? 2 : os_1.default.cpus().length * 2;
|
|
20
21
|
// Sub-directory to place all user-defined files (i.e. everything other than
|
|
21
22
|
// the entry file generated by zip-it-and-ship-it).
|
|
22
23
|
const DEFAULT_USER_SUBDIRECTORY = 'src';
|
|
23
|
-
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
|
|
24
|
-
const
|
|
24
|
+
const createDirectory = async function ({ aliases = new Map(), basePath, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites = new Map(), srcFiles, }) {
|
|
25
|
+
const entryFile = (0, entry_file_js_1.getEntryFile)({
|
|
25
26
|
commonPrefix: basePath,
|
|
26
|
-
filename,
|
|
27
27
|
mainFile,
|
|
28
28
|
moduleFormat,
|
|
29
29
|
userNamespace: DEFAULT_USER_SUBDIRECTORY,
|
|
30
30
|
});
|
|
31
|
+
const entryFileExtension = (0, module_format_js_1.getFileExtensionForFormat)(moduleFormat, featureFlags);
|
|
32
|
+
const entryFilename = (0, path_1.basename)(filename, extension) + entryFileExtension;
|
|
31
33
|
const functionFolder = (0, path_1.join)(destFolder, (0, path_1.basename)(filename, extension));
|
|
34
|
+
const entryFilePath = (0, path_1.resolve)(functionFolder, entryFilename);
|
|
32
35
|
// Deleting the functions directory in case it exists before creating it.
|
|
33
36
|
await (0, del_1.default)(functionFolder, { force: true });
|
|
34
37
|
await fs_1.promises.mkdir(functionFolder, { recursive: true });
|
|
35
38
|
// Writing entry file.
|
|
36
|
-
await fs_1.promises.writeFile(
|
|
39
|
+
await fs_1.promises.writeFile(entryFilePath, entryFile);
|
|
37
40
|
// Copying source files.
|
|
38
41
|
await (0, p_map_1.default)(srcFiles, (srcFile) => {
|
|
39
42
|
const destPath = aliases.get(srcFile) || srcFile;
|
|
@@ -50,10 +53,11 @@ const createDirectory = async function ({ aliases = new Map(), basePath, destFol
|
|
|
50
53
|
}, { concurrency: COPY_FILE_CONCURRENCY });
|
|
51
54
|
return functionFolder;
|
|
52
55
|
};
|
|
53
|
-
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
|
|
56
|
+
const createZipArchive = async function ({ aliases, basePath, destFolder, extension, featureFlags, filename, mainFile, moduleFormat, rewrites, srcFiles, }) {
|
|
54
57
|
const destPath = (0, path_1.join)(destFolder, `${(0, path_1.basename)(filename, extension)}.zip`);
|
|
55
58
|
const { archive, output } = (0, archive_js_1.startZip)(destPath);
|
|
56
|
-
const
|
|
59
|
+
const entryFileExtension = (0, module_format_js_1.getFileExtensionForFormat)(moduleFormat, featureFlags);
|
|
60
|
+
const entryFilename = (0, path_1.basename)(filename, extension) + entryFileExtension;
|
|
57
61
|
const entryFilePath = (0, path_1.resolve)(basePath, entryFilename);
|
|
58
62
|
// We don't need an entry file if it would end up with the same path as the
|
|
59
63
|
// function's main file.
|
|
@@ -66,8 +70,8 @@ const createZipArchive = async function ({ aliases, basePath, destFolder, extens
|
|
|
66
70
|
// than the entry file) to its own sub-directory.
|
|
67
71
|
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
|
68
72
|
if (needsEntryFile) {
|
|
69
|
-
const entryFile = (0, entry_file_js_1.getEntryFile)({ commonPrefix: basePath,
|
|
70
|
-
addEntryFileToZip(archive, entryFile);
|
|
73
|
+
const entryFile = (0, entry_file_js_1.getEntryFile)({ commonPrefix: basePath, mainFile, moduleFormat, userNamespace });
|
|
74
|
+
addEntryFileToZip(archive, entryFile, (0, path_1.basename)(entryFilePath));
|
|
71
75
|
}
|
|
72
76
|
const srcFilesInfos = await Promise.all(srcFiles.map(addStat));
|
|
73
77
|
// We ensure this is not async, so that the archive's checksum is
|
|
@@ -93,7 +97,7 @@ const zipNodeJs = function ({ archiveFormat, ...options }) {
|
|
|
93
97
|
return createDirectory(options);
|
|
94
98
|
};
|
|
95
99
|
exports.zipNodeJs = zipNodeJs;
|
|
96
|
-
const addEntryFileToZip = function (archive,
|
|
100
|
+
const addEntryFileToZip = function (archive, contents, filename) {
|
|
97
101
|
const contentBuffer = buffer_1.Buffer.from(contents);
|
|
98
102
|
(0, archive_js_1.addZipContent)(archive, contentBuffer, filename);
|
|
99
103
|
};
|
package/dist/utils/fs.d.ts
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="node" />
|
|
3
|
-
/// <reference types="node" />
|
|
4
3
|
import { promises as fs } from 'fs';
|
|
5
4
|
export declare type FsCache = Record<string, unknown>;
|
|
6
5
|
export declare const cachedLstat: (cache: FsCache, path: string, opts?: import("fs").StatOptions | undefined) => Promise<import("fs").Stats | import("fs").BigIntStats>;
|
|
7
|
-
export declare const cachedReaddir: (cache: FsCache, path: string, options:
|
|
6
|
+
export declare const cachedReaddir: (cache: FsCache, path: string, options: {
|
|
7
|
+
encoding?: string | null | undefined;
|
|
8
8
|
withFileTypes: true;
|
|
9
9
|
}) => Promise<import("fs").Dirent[]>;
|
|
10
|
-
export declare const cachedReadFile: (cache: FsCache, path: string, options?:
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export declare const cachedReadFile: (cache: FsCache, path: string, options?: string | {
|
|
11
|
+
encoding?: string | null | undefined;
|
|
12
|
+
flag?: string | number | undefined;
|
|
13
|
+
} | null | undefined) => Promise<string | Buffer>;
|
|
13
14
|
export declare const getPathWithExtension: (path: string, extension: string) => string;
|
|
14
15
|
export declare const safeUnlink: (path: string) => Promise<void>;
|
|
15
16
|
export declare const listFunctionsDirectories: (srcFolders: string[]) => Promise<string[]>;
|
package/dist/zip.d.ts
CHANGED
|
@@ -14,9 +14,9 @@ declare type ZipFunctionsOptions = ZipFunctionOptions & {
|
|
|
14
14
|
manifest?: string;
|
|
15
15
|
parallelLimit?: number;
|
|
16
16
|
};
|
|
17
|
-
export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, configFileDirectories, featureFlags
|
|
17
|
+
export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, config, configFileDirectories, featureFlags, manifest, parallelLimit, repositoryRoot, }?: ZipFunctionsOptions) => Promise<(Omit<import("./function.js").FunctionArchive, "runtime"> & {
|
|
18
18
|
runtime: import("./main.js").RuntimeType;
|
|
19
19
|
schedule?: string | undefined;
|
|
20
20
|
})[]>;
|
|
21
|
-
export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config
|
|
21
|
+
export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config, featureFlags, repositoryRoot, }?: ZipFunctionOptions) => Promise<import("./utils/format_result.js").FunctionResult | undefined>;
|
|
22
22
|
export {};
|
package/dist/zip.js
CHANGED
|
@@ -30,13 +30,19 @@ const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFo
|
|
|
30
30
|
const [paths] = await Promise.all([(0, fs_js_1.listFunctionsDirectories)(srcFolders), fs_1.promises.mkdir(destFolder, { recursive: true })]);
|
|
31
31
|
const functions = await (0, index_js_1.getFunctionsFromPaths)(paths, { config, configFileDirectories, dedupe: true, featureFlags });
|
|
32
32
|
const results = await (0, p_map_1.default)(functions.values(), async (func) => {
|
|
33
|
+
const functionFlags = {
|
|
34
|
+
...featureFlags,
|
|
35
|
+
// If there's a `nodeModuleFormat` configuration property set to `esm`,
|
|
36
|
+
// extend the feature flags with `zisi_pure_esm_mjs` enabled.
|
|
37
|
+
...(func.config.nodeModuleFormat === "esm" /* ModuleFormat.ESM */ ? { zisi_pure_esm_mjs: true } : {}),
|
|
38
|
+
};
|
|
33
39
|
const zipResult = await func.runtime.zipFunction({
|
|
34
40
|
archiveFormat,
|
|
35
41
|
basePath,
|
|
36
42
|
config: func.config,
|
|
37
43
|
destFolder,
|
|
38
44
|
extension: func.extension,
|
|
39
|
-
featureFlags,
|
|
45
|
+
featureFlags: functionFlags,
|
|
40
46
|
filename: func.filename,
|
|
41
47
|
mainFile: func.mainFile,
|
|
42
48
|
name: func.name,
|
|
@@ -70,13 +76,19 @@ const zipFunction = async function (relativeSrcPath, destFolder, { archiveFormat
|
|
|
70
76
|
}
|
|
71
77
|
const { config, extension, filename, mainFile, name, runtime, srcDir, stat: stats, } = functions.values().next().value;
|
|
72
78
|
await fs_1.promises.mkdir(destFolder, { recursive: true });
|
|
79
|
+
const functionFlags = {
|
|
80
|
+
...featureFlags,
|
|
81
|
+
// If there's a `nodeModuleFormat` configuration property set to `esm`,
|
|
82
|
+
// extend the feature flags with `zisi_pure_esm_mjs` enabled.
|
|
83
|
+
...(config.nodeModuleFormat === "esm" /* ModuleFormat.ESM */ ? { zisi_pure_esm_mjs: true } : {}),
|
|
84
|
+
};
|
|
73
85
|
const zipResult = await runtime.zipFunction({
|
|
74
86
|
archiveFormat,
|
|
75
87
|
basePath,
|
|
76
88
|
config,
|
|
77
89
|
destFolder,
|
|
78
90
|
extension,
|
|
79
|
-
featureFlags,
|
|
91
|
+
featureFlags: functionFlags,
|
|
80
92
|
filename,
|
|
81
93
|
mainFile,
|
|
82
94
|
name,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"@babel/parser": "7.16.8",
|
|
56
56
|
"@netlify/binary-info": "^1.0.0",
|
|
57
57
|
"@netlify/esbuild": "0.14.25",
|
|
58
|
-
"@vercel/nft": "^0.
|
|
58
|
+
"@vercel/nft": "^0.22.0",
|
|
59
59
|
"archiver": "^5.3.0",
|
|
60
60
|
"common-path-prefix": "^3.0.0",
|
|
61
61
|
"cp-file": "^9.0.0",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"@netlify/eslint-config-node": "^7.0.0",
|
|
91
91
|
"@types/archiver": "^5.1.1",
|
|
92
92
|
"@types/end-of-stream": "^1.4.1",
|
|
93
|
+
"@types/node": "^12.20.55",
|
|
93
94
|
"@types/normalize-path": "^3.0.0",
|
|
94
95
|
"@types/resolve": "^1.20.1",
|
|
95
96
|
"@types/semver": "^7.3.8",
|