@netlify/zip-it-and-ship-it 12.2.1 → 13.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.ts CHANGED
@@ -4,7 +4,7 @@ import { ModuleFormat } from './runtimes/node/utils/module_format.js';
4
4
  import { RuntimeName } from './runtimes/runtime.js';
5
5
  import type { ExtendedRoute, Route } from './utils/routes.js';
6
6
  export { Config, FunctionConfig } from './config.js';
7
- export { zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
7
+ export { type FunctionsBag, zipFunction, zipFunctions, ZipFunctionOptions, ZipFunctionsOptions } from './zip.js';
8
8
  export { ArchiveFormat, ARCHIVE_FORMAT } from './archive.js';
9
9
  export type { TrafficRules } from './rate_limit.js';
10
10
  export type { ExtendedRoute, Route } from './utils/routes.js';
package/dist/utils/fs.js CHANGED
@@ -65,24 +65,8 @@ ${errorMessages.join('\n')}`);
65
65
  return validDirectories.flat();
66
66
  };
67
67
  const listFunctionsDirectory = async function (srcPath) {
68
- try {
69
- const filenames = await fs.readdir(srcPath);
70
- return filenames.map((name) => join(srcPath, name));
71
- }
72
- catch (error) {
73
- // We could move the `stat` call up and use its result to decide whether to
74
- // treat the path as a file or as a directory. We're doing it this way since
75
- // historically this method only supported directories, and only later we
76
- // made it accept files. To roll out that change as safely as possible, we
77
- // keep the directory flow untouched and look for files only as a fallback.
78
- if (error.code === 'ENOTDIR') {
79
- const stat = await fs.stat(srcPath);
80
- if (stat.isFile()) {
81
- return srcPath;
82
- }
83
- }
84
- throw error;
85
- }
68
+ const filenames = await fs.readdir(srcPath);
69
+ return filenames.map((name) => join(srcPath, name));
86
70
  };
87
71
  export const resolveFunctionsDirectories = (input) => {
88
72
  const directories = Array.isArray(input) ? input : [input];
package/dist/zip.d.ts CHANGED
@@ -19,7 +19,41 @@ export type ZipFunctionsOptions = ZipFunctionOptions & {
19
19
  configFileDirectories?: string[];
20
20
  manifest?: string;
21
21
  parallelLimit?: number;
22
- internalSrcFolder?: string;
23
22
  };
24
- export declare const zipFunctions: (relativeSrcFolders: string | string[], destFolder: string, { archiveFormat, basePath, branch, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, systemLog, debug, internalSrcFolder, }?: ZipFunctionsOptions) => Promise<FunctionResult[]>;
23
+ export interface FunctionsBag {
24
+ generated: FunctionsCategory;
25
+ user: FunctionsCategory;
26
+ }
27
+ export interface FunctionsCategory {
28
+ /**
29
+ * List of paths for directories containing one or more functions. Entries in
30
+ * these directories are considered functions when they are files that match
31
+ * one of the supported extensions or when they are sub-directories that
32
+ * contain a function following the sub-directory naming patterns.
33
+ * Paths can be relative.
34
+ */
35
+ directories: string[];
36
+ /**
37
+ * List of paths for specific functions. Paths can be files that match one
38
+ * of the supported extensions or sub-directories that contain a function
39
+ * following the sub-directory naming patterns. Paths can be relative.
40
+ */
41
+ functions: string[];
42
+ }
43
+ /**
44
+ * Normalizes the `zipFunctions` input into a `FunctionsBag` object.
45
+ */
46
+ export declare const getFunctionsBag: (input: ZipFunctionsPaths) => FunctionsBag;
47
+ export type ZipFunctionsPaths = string | string[] | {
48
+ /**
49
+ * Functions generated on behalf of the user by a build plugin, extension
50
+ * or a framework.
51
+ */
52
+ generated?: Partial<FunctionsCategory>;
53
+ /**
54
+ * Functions authored by the user.
55
+ */
56
+ user?: Partial<FunctionsCategory>;
57
+ };
58
+ export declare const zipFunctions: (input: ZipFunctionsPaths, destFolder: string, { archiveFormat, basePath, branch, config, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit, repositoryRoot, systemLog, debug, }?: ZipFunctionsOptions) => Promise<FunctionResult[]>;
25
59
  export declare const zipFunction: (relativeSrcPath: string, destFolder: string, { archiveFormat, basePath, config: inputConfig, featureFlags: inputFeatureFlags, repositoryRoot, systemLog, debug, internalSrcFolder, }?: ZipFunctionOptions) => Promise<FunctionResult | undefined>;
package/dist/zip.js CHANGED
@@ -19,17 +19,56 @@ const validateArchiveFormat = (archiveFormat) => {
19
19
  throw new Error(`Invalid archive format: ${archiveFormat}`);
20
20
  }
21
21
  };
22
+ /**
23
+ * Normalizes the `zipFunctions` input into a `FunctionsBag` object.
24
+ */
25
+ export const getFunctionsBag = (input) => {
26
+ if (typeof input === 'string') {
27
+ return {
28
+ generated: {
29
+ directories: [],
30
+ functions: [],
31
+ },
32
+ user: {
33
+ directories: [input],
34
+ functions: [],
35
+ },
36
+ };
37
+ }
38
+ if (Array.isArray(input)) {
39
+ return {
40
+ generated: {
41
+ directories: [],
42
+ functions: [],
43
+ },
44
+ user: {
45
+ directories: input,
46
+ functions: [],
47
+ },
48
+ };
49
+ }
50
+ return {
51
+ generated: {
52
+ directories: input.generated?.directories ?? [],
53
+ functions: input.generated?.functions ?? [],
54
+ },
55
+ user: {
56
+ directories: input.user?.directories ?? [],
57
+ functions: input.user?.functions ?? [],
58
+ },
59
+ };
60
+ };
22
61
  // Zip `srcFolder/*` (Node.js or Go files) to `destFolder/*.zip` so it can be
23
62
  // used by AWS Lambda
24
- export const zipFunctions = async function (relativeSrcFolders, destFolder, { archiveFormat = ARCHIVE_FORMAT.ZIP, basePath, branch, config = {}, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, systemLog, debug, internalSrcFolder, } = {}) {
63
+ export const zipFunctions = async function (input, destFolder, { archiveFormat = ARCHIVE_FORMAT.ZIP, basePath, branch, config = {}, configFileDirectories, featureFlags: inputFeatureFlags, manifest, parallelLimit = DEFAULT_PARALLEL_LIMIT, repositoryRoot = basePath, systemLog, debug, } = {}) {
25
64
  validateArchiveFormat(archiveFormat);
26
65
  const logger = getLogger(systemLog, debug);
27
66
  const cache = new RuntimeCache();
28
67
  const featureFlags = getFlags(inputFeatureFlags);
29
- const srcFolders = resolveFunctionsDirectories(relativeSrcFolders);
30
- const internalFunctionsPath = internalSrcFolder && resolve(internalSrcFolder);
68
+ const bag = getFunctionsBag(input);
69
+ const srcFolders = resolveFunctionsDirectories([...bag.generated.directories, ...bag.user.directories]);
31
70
  const [paths] = await Promise.all([listFunctionsDirectories(srcFolders), fs.mkdir(destFolder, { recursive: true })]);
32
- const functions = await getFunctionsFromPaths(paths, {
71
+ const functions = await getFunctionsFromPaths([...paths, ...bag.generated.functions, ...bag.user.functions], {
33
72
  cache,
34
73
  config,
35
74
  configFileDirectories,
@@ -43,6 +82,8 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
43
82
  // extend the feature flags with `zisi_pure_esm_mjs` enabled.
44
83
  ...(func.config.nodeModuleFormat === MODULE_FORMAT.ESM ? { zisi_pure_esm_mjs: true } : {}),
45
84
  };
85
+ const isInternal = bag.generated.functions.includes(func.srcPath) ||
86
+ bag.generated.directories.some((directory) => isPathInside(func.srcPath, directory));
46
87
  const zipResult = await func.runtime.zipFunction({
47
88
  archiveFormat,
48
89
  basePath,
@@ -53,7 +94,7 @@ export const zipFunctions = async function (relativeSrcFolders, destFolder, { ar
53
94
  extension: func.extension,
54
95
  featureFlags: functionFlags,
55
96
  filename: func.filename,
56
- isInternal: Boolean(internalFunctionsPath && isPathInside(func.srcPath, internalFunctionsPath)),
97
+ isInternal,
57
98
  logger,
58
99
  mainFile: func.mainFile,
59
100
  name: func.name,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "12.2.1",
3
+ "version": "13.0.0",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "type": "module",
@@ -100,5 +100,5 @@
100
100
  "engines": {
101
101
  "node": ">=18.14.0"
102
102
  },
103
- "gitHead": "a317a69700be1392b54976ef34b456ac47d75f5a"
103
+ "gitHead": "cc8bccf13040e0e43282845c5a3a6d17db659ce8"
104
104
  }