@netlify/zip-it-and-ship-it 9.2.1 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/feature_flags.d.ts +2 -2
- package/dist/feature_flags.js +2 -2
- package/dist/main.d.ts +2 -2
- package/dist/runtimes/index.d.ts +2 -2
- package/dist/runtimes/index.js +1 -1
- package/dist/runtimes/node/bundlers/index.js +2 -1
- package/dist/runtimes/node/utils/entry_file.d.ts +3 -2
- package/dist/runtimes/node/utils/entry_file.js +22 -8
- package/dist/runtimes/node/utils/zip.js +4 -1
- package/package.json +4 -4
package/dist/feature_flags.d.ts
CHANGED
|
@@ -6,8 +6,8 @@ export declare const defaultFlags: {
|
|
|
6
6
|
readonly zisi_pure_esm: false;
|
|
7
7
|
readonly zisi_pure_esm_mjs: false;
|
|
8
8
|
readonly zisi_output_cjs_extension: false;
|
|
9
|
-
readonly zisi_disallow_new_entry_name: false;
|
|
10
9
|
readonly zisi_functions_api_v2: false;
|
|
10
|
+
readonly zisi_unique_entry_file: false;
|
|
11
11
|
};
|
|
12
12
|
export type FeatureFlags = Partial<Record<keyof typeof defaultFlags, boolean>>;
|
|
13
13
|
export declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
@@ -18,6 +18,6 @@ export declare const getFlags: (input?: Record<string, boolean>, flags?: {
|
|
|
18
18
|
readonly zisi_pure_esm: false;
|
|
19
19
|
readonly zisi_pure_esm_mjs: false;
|
|
20
20
|
readonly zisi_output_cjs_extension: false;
|
|
21
|
-
readonly zisi_disallow_new_entry_name: false;
|
|
22
21
|
readonly zisi_functions_api_v2: false;
|
|
22
|
+
readonly zisi_unique_entry_file: false;
|
|
23
23
|
}) => FeatureFlags;
|
package/dist/feature_flags.js
CHANGED
|
@@ -16,10 +16,10 @@ export const defaultFlags = {
|
|
|
16
16
|
zisi_pure_esm_mjs: false,
|
|
17
17
|
// Output CJS file extension.
|
|
18
18
|
zisi_output_cjs_extension: false,
|
|
19
|
-
// Do not allow ___netlify-entry-point as function or file name.
|
|
20
|
-
zisi_disallow_new_entry_name: false,
|
|
21
19
|
// Inject the compatibility layer required for the v2 runtime API to work.
|
|
22
20
|
zisi_functions_api_v2: false,
|
|
21
|
+
// Create unique entry file instead of a file that is based on the function name.
|
|
22
|
+
zisi_unique_entry_file: false,
|
|
23
23
|
};
|
|
24
24
|
// List of supported flags and their default value.
|
|
25
25
|
export const getFlags = (input = {}, flags = defaultFlags) => Object.entries(flags).reduce((result, [key, defaultValue]) => ({
|
package/dist/main.d.ts
CHANGED
|
@@ -27,13 +27,13 @@ interface ListFunctionsOptions {
|
|
|
27
27
|
parseISC?: boolean;
|
|
28
28
|
}
|
|
29
29
|
export declare const listFunctions: (relativeSrcFolders: string | string[], { featureFlags: inputFeatureFlags, config, configFileDirectories, parseISC, }?: {
|
|
30
|
-
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "
|
|
30
|
+
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "zisi_functions_api_v2" | "zisi_unique_entry_file", boolean>> | undefined;
|
|
31
31
|
config?: Config | undefined;
|
|
32
32
|
configFileDirectories?: string[] | undefined;
|
|
33
33
|
parseISC?: boolean | undefined;
|
|
34
34
|
}) => Promise<ListedFunction[]>;
|
|
35
35
|
export declare const listFunction: (path: string, { featureFlags: inputFeatureFlags, config, configFileDirectories, parseISC, }?: {
|
|
36
|
-
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "
|
|
36
|
+
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "zisi_functions_api_v2" | "zisi_unique_entry_file", boolean>> | undefined;
|
|
37
37
|
config?: Config | undefined;
|
|
38
38
|
configFileDirectories?: string[] | undefined;
|
|
39
39
|
parseISC?: boolean | undefined;
|
package/dist/runtimes/index.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export declare const getFunctionsFromPaths: (paths: string[], { cache, config, c
|
|
|
11
11
|
config?: Config | undefined;
|
|
12
12
|
configFileDirectories?: string[] | undefined;
|
|
13
13
|
dedupe?: boolean | undefined;
|
|
14
|
-
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "
|
|
14
|
+
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "zisi_functions_api_v2" | "zisi_unique_entry_file", boolean>> | undefined;
|
|
15
15
|
}) => Promise<FunctionMap>;
|
|
16
16
|
/**
|
|
17
17
|
* Gets a list of functions found in a list of paths.
|
|
@@ -20,6 +20,6 @@ export declare const getFunctionFromPath: (path: string, { cache, config, config
|
|
|
20
20
|
cache: RuntimeCache;
|
|
21
21
|
config?: Config | undefined;
|
|
22
22
|
configFileDirectories?: string[] | undefined;
|
|
23
|
-
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "
|
|
23
|
+
featureFlags?: Partial<Record<"buildRustSource" | "parseWithEsbuild" | "traceWithNft" | "functions_inherit_build_nodejs_version" | "zisi_pure_esm" | "zisi_pure_esm_mjs" | "zisi_output_cjs_extension" | "zisi_functions_api_v2" | "zisi_unique_entry_file", boolean>> | undefined;
|
|
24
24
|
}) => Promise<FunctionSource | undefined>;
|
|
25
25
|
export {};
|
package/dist/runtimes/index.js
CHANGED
|
@@ -20,7 +20,7 @@ const findFunctionsInRuntime = async function ({ cache, dedupe = false, featureF
|
|
|
20
20
|
const key = dedupe ? 'name' : 'srcPath';
|
|
21
21
|
// Augmenting the function objects with additional information.
|
|
22
22
|
const augmentedFunctions = functions.map((func) => {
|
|
23
|
-
if (
|
|
23
|
+
if (func.name === ENTRY_FILE_NAME) {
|
|
24
24
|
throw new FunctionBundlingUserError(`'${ENTRY_FILE_NAME}' is a reserved word and cannot be used as a function name.`, {
|
|
25
25
|
functionName: func.name,
|
|
26
26
|
runtime: runtime.name,
|
|
@@ -31,7 +31,8 @@ const ESBUILD_EXTENSIONS = new Set(['.mjs', '.ts', '.tsx', '.cts', '.mts']);
|
|
|
31
31
|
// We use ZISI as the default bundler, except for certain extensions, for which
|
|
32
32
|
// esbuild is the only option.
|
|
33
33
|
const getDefaultBundler = async ({ extension, featureFlags, mainFile, }) => {
|
|
34
|
-
if (extension === MODULE_FILE_EXTENSION.MJS && featureFlags.zisi_pure_esm_mjs)
|
|
34
|
+
if ((extension === MODULE_FILE_EXTENSION.MJS && featureFlags.zisi_pure_esm_mjs) ||
|
|
35
|
+
featureFlags.zisi_functions_api_v2) {
|
|
35
36
|
return NODE_BUNDLER.NFT;
|
|
36
37
|
}
|
|
37
38
|
if (ESBUILD_EXTENSIONS.has(extension)) {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import type { FeatureFlags } from '../../../feature_flags.js';
|
|
2
2
|
import { ModuleFormat } from './module_format.js';
|
|
3
3
|
export declare const ENTRY_FILE_NAME = "___netlify-entry-point";
|
|
4
|
-
export declare const BOOTSTRAP_FILE_NAME = "___netlify-bootstrap.
|
|
4
|
+
export declare const BOOTSTRAP_FILE_NAME = "___netlify-bootstrap.mjs";
|
|
5
5
|
export interface EntryFile {
|
|
6
6
|
contents: string;
|
|
7
7
|
filename: string;
|
|
8
8
|
}
|
|
9
|
-
export declare const isNamedLikeEntryFile: (file: string, { basePath, filename, }: {
|
|
9
|
+
export declare const isNamedLikeEntryFile: (file: string, { basePath, featureFlags, filename, }: {
|
|
10
10
|
basePath: string;
|
|
11
|
+
featureFlags: FeatureFlags;
|
|
11
12
|
filename: string;
|
|
12
13
|
}) => boolean;
|
|
13
14
|
export declare const conflictsWithEntryFile: (srcFiles: string[], { basePath, extension, featureFlags, filename, mainFile, }: {
|
|
@@ -4,7 +4,7 @@ import { RUNTIME } from '../../runtime.js';
|
|
|
4
4
|
import { getFileExtensionForFormat, MODULE_FILE_EXTENSION, MODULE_FORMAT, } from './module_format.js';
|
|
5
5
|
import { normalizeFilePath } from './normalize_path.js';
|
|
6
6
|
export const ENTRY_FILE_NAME = '___netlify-entry-point';
|
|
7
|
-
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.
|
|
7
|
+
export const BOOTSTRAP_FILE_NAME = '___netlify-bootstrap.mjs';
|
|
8
8
|
const getEntryFileContents = (mainPath, moduleFormat, featureFlags) => {
|
|
9
9
|
const importPath = `.${mainPath.startsWith('/') ? mainPath : `/${mainPath}`}`;
|
|
10
10
|
if (featureFlags.zisi_functions_api_v2) {
|
|
@@ -12,7 +12,11 @@ const getEntryFileContents = (mainPath, moduleFormat, featureFlags) => {
|
|
|
12
12
|
`import func from '${importPath}'`,
|
|
13
13
|
`import { getLambdaHandler } from './${BOOTSTRAP_FILE_NAME}'`,
|
|
14
14
|
`export const handler = getLambdaHandler(func)`,
|
|
15
|
-
].join('
|
|
15
|
+
].join(';');
|
|
16
|
+
}
|
|
17
|
+
if (featureFlags.zisi_unique_entry_file) {
|
|
18
|
+
// we use dynamic import because we do not know if the user code is cjs or esm
|
|
19
|
+
return [`const { handler } = await import('${importPath}')`, 'export { handler }'].join(';');
|
|
16
20
|
}
|
|
17
21
|
if (moduleFormat === MODULE_FORMAT.COMMONJS) {
|
|
18
22
|
return `module.exports = require('${importPath}')`;
|
|
@@ -26,8 +30,8 @@ const POSSIBLE_LAMBDA_ENTRY_EXTENSIONS = [
|
|
|
26
30
|
MODULE_FILE_EXTENSION.CJS,
|
|
27
31
|
];
|
|
28
32
|
// checks if the file is considered a entry-file in AWS Lambda
|
|
29
|
-
export const isNamedLikeEntryFile = (file, { basePath, filename, }) => POSSIBLE_LAMBDA_ENTRY_EXTENSIONS.some((extension) => {
|
|
30
|
-
const entryFilename = getEntryFileName({ extension, filename });
|
|
33
|
+
export const isNamedLikeEntryFile = (file, { basePath, featureFlags, filename, }) => POSSIBLE_LAMBDA_ENTRY_EXTENSIONS.some((extension) => {
|
|
34
|
+
const entryFilename = getEntryFileName({ extension, featureFlags, filename });
|
|
31
35
|
const entryFilePath = resolve(basePath, entryFilename);
|
|
32
36
|
return entryFilePath === file;
|
|
33
37
|
});
|
|
@@ -35,13 +39,18 @@ export const isNamedLikeEntryFile = (file, { basePath, filename, }) => POSSIBLE_
|
|
|
35
39
|
export const conflictsWithEntryFile = (srcFiles, { basePath, extension, featureFlags, filename, mainFile, }) => {
|
|
36
40
|
let hasConflict = false;
|
|
37
41
|
srcFiles.forEach((srcFile) => {
|
|
38
|
-
if (
|
|
42
|
+
if (srcFile.includes(ENTRY_FILE_NAME)) {
|
|
39
43
|
throw new FunctionBundlingUserError(`'${ENTRY_FILE_NAME}' is a reserved word and cannot be used as a file or directory name.`, {
|
|
40
44
|
functionName: basename(filename, extension),
|
|
41
45
|
runtime: RUNTIME.JAVASCRIPT,
|
|
42
46
|
});
|
|
43
47
|
}
|
|
44
|
-
|
|
48
|
+
// If we're generating a unique entry file, we know we don't have a conflict
|
|
49
|
+
// at this point.
|
|
50
|
+
if (featureFlags.zisi_unique_entry_file || featureFlags.zisi_functions_api_v2) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!hasConflict && isNamedLikeEntryFile(srcFile, { basePath, featureFlags, filename }) && srcFile !== mainFile) {
|
|
45
54
|
hasConflict = true;
|
|
46
55
|
}
|
|
47
56
|
});
|
|
@@ -50,11 +59,16 @@ export const conflictsWithEntryFile = (srcFiles, { basePath, extension, featureF
|
|
|
50
59
|
// Returns the name for the AWS Lambda entry file
|
|
51
60
|
// We do set the handler in AWS Lambda to `<func-name>.handler` and because of
|
|
52
61
|
// this it considers `<func-name>.(c|m)?js` as possible entry-points
|
|
53
|
-
const getEntryFileName = ({ extension, filename }) =>
|
|
62
|
+
const getEntryFileName = ({ extension, featureFlags, filename, }) => {
|
|
63
|
+
if (featureFlags.zisi_unique_entry_file || featureFlags.zisi_functions_api_v2) {
|
|
64
|
+
return `${ENTRY_FILE_NAME}.mjs`;
|
|
65
|
+
}
|
|
66
|
+
return `${basename(filename, extname(filename))}${extension}`;
|
|
67
|
+
};
|
|
54
68
|
export const getEntryFile = ({ commonPrefix, featureFlags, filename, mainFile, moduleFormat, userNamespace, }) => {
|
|
55
69
|
const mainPath = normalizeFilePath({ commonPrefix, path: mainFile, userNamespace });
|
|
56
70
|
const extension = getFileExtensionForFormat(moduleFormat, featureFlags);
|
|
57
|
-
const entryFilename = getEntryFileName({ extension, filename });
|
|
71
|
+
const entryFilename = getEntryFileName({ extension, featureFlags, filename });
|
|
58
72
|
const contents = getEntryFileContents(mainPath, moduleFormat, featureFlags);
|
|
59
73
|
return {
|
|
60
74
|
contents,
|
|
@@ -61,7 +61,10 @@ const createZipArchive = async function ({ aliases = new Map(), basePath, cache,
|
|
|
61
61
|
});
|
|
62
62
|
// We don't need an entry file if it would end up with the same path as the
|
|
63
63
|
// function's main file. Unless we have a file conflict and need to move everything into a subfolder
|
|
64
|
-
const needsEntryFile =
|
|
64
|
+
const needsEntryFile = featureFlags.zisi_unique_entry_file ||
|
|
65
|
+
featureFlags.zisi_functions_api_v2 ||
|
|
66
|
+
hasEntryFileConflict ||
|
|
67
|
+
!isNamedLikeEntryFile(mainFile, { basePath, featureFlags, filename });
|
|
65
68
|
// If there is a naming conflict, we move all user files (everything other
|
|
66
69
|
// than the entry file) to its own sub-directory.
|
|
67
70
|
const userNamespace = hasEntryFileConflict ? DEFAULT_USER_SUBDIRECTORY : '';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/zip-it-and-ship-it",
|
|
3
|
-
"version": "9.
|
|
3
|
+
"version": "9.3.0",
|
|
4
4
|
"description": "Zip it and ship it",
|
|
5
5
|
"main": "./dist/main.js",
|
|
6
6
|
"type": "module",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@babel/parser": "7.16.8",
|
|
58
58
|
"@netlify/binary-info": "^1.0.0",
|
|
59
59
|
"@netlify/esbuild": "0.14.39",
|
|
60
|
-
"@netlify/serverless-functions-api": "^1.
|
|
60
|
+
"@netlify/serverless-functions-api": "^1.3.0",
|
|
61
61
|
"@vercel/nft": "^0.22.0",
|
|
62
62
|
"archiver": "^5.3.0",
|
|
63
63
|
"common-path-prefix": "^3.0.0",
|
|
@@ -100,7 +100,7 @@
|
|
|
100
100
|
"@types/tmp": "^0.2.3",
|
|
101
101
|
"@types/unixify": "^1.0.0",
|
|
102
102
|
"@types/yargs": "^17.0.4",
|
|
103
|
-
"@vitest/coverage-c8": "^0.
|
|
103
|
+
"@vitest/coverage-c8": "^0.31.0",
|
|
104
104
|
"cpy": "^9.0.0",
|
|
105
105
|
"deepmerge": "^4.2.2",
|
|
106
106
|
"get-stream": "^6.0.0",
|
|
@@ -112,7 +112,7 @@
|
|
|
112
112
|
"throat": "^6.0.1",
|
|
113
113
|
"typescript": "^5.0.0",
|
|
114
114
|
"vite": "^4.0.0",
|
|
115
|
-
"vitest": "^0.
|
|
115
|
+
"vitest": "^0.31.0"
|
|
116
116
|
},
|
|
117
117
|
"engines": {
|
|
118
118
|
"node": "^14.18.0 || >=16.0.0"
|