@netlify/zip-it-and-ship-it 5.12.0 → 5.13.2

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.
Files changed (30) hide show
  1. package/README.md +4 -3
  2. package/dist/config.d.ts +1 -1
  3. package/dist/main.js +1 -1
  4. package/dist/runtimes/go/builder.js +2 -3
  5. package/dist/runtimes/node/bundlers/esbuild/bundler.js +2 -7
  6. package/dist/runtimes/node/bundlers/esbuild/bundler_target.d.ts +1 -0
  7. package/dist/runtimes/node/bundlers/esbuild/bundler_target.js +1 -0
  8. package/dist/runtimes/node/bundlers/esbuild/index.d.ts +2 -2
  9. package/dist/runtimes/node/bundlers/esbuild/plugin_native_modules.d.ts +1 -1
  10. package/dist/runtimes/node/bundlers/esbuild/src_files.d.ts +1 -1
  11. package/dist/runtimes/node/bundlers/index.d.ts +2 -44
  12. package/dist/runtimes/node/bundlers/nft/index.d.ts +1 -1
  13. package/dist/runtimes/node/bundlers/nft/transpile.js +2 -7
  14. package/dist/runtimes/node/bundlers/types.d.ts +44 -0
  15. package/dist/runtimes/node/bundlers/types.js +3 -0
  16. package/dist/runtimes/node/bundlers/zisi/index.d.ts +2 -2
  17. package/dist/runtimes/node/bundlers/zisi/list_imports.js +2 -7
  18. package/dist/runtimes/node/bundlers/zisi/src_files.d.ts +1 -1
  19. package/dist/runtimes/node/in_source_config/index.d.ts +1 -1
  20. package/dist/runtimes/node/in_source_config/index.js +17 -6
  21. package/dist/runtimes/node/index.js +1 -1
  22. package/dist/runtimes/node/utils/node_version.d.ts +1 -1
  23. package/dist/runtimes/node/utils/node_version.js +1 -1
  24. package/dist/runtimes/runtime.d.ts +1 -1
  25. package/dist/runtimes/rust/builder.js +3 -5
  26. package/dist/utils/error.d.ts +19 -0
  27. package/dist/utils/error.js +22 -0
  28. package/dist/utils/fs.d.ts +0 -1
  29. package/dist/utils/fs.js +20 -19
  30. package/package.json +1 -1
package/README.md CHANGED
@@ -129,7 +129,7 @@ The following properties are accepted:
129
129
  - `nodeVersion`
130
130
 
131
131
  - _Type_: `string`\
132
- - _Default value_: `12.x`
132
+ - _Default value_: `16.x`
133
133
 
134
134
  The version of Node.js to use as the compilation target. Possible values:
135
135
 
@@ -137,6 +137,7 @@ The following properties are accepted:
137
137
  - `10.x` (or `nodejs10.x`)
138
138
  - `12.x` (or `nodejs12.x`)
139
139
  - `14.x` (or `nodejs14.x`)
140
+ - `16.x` (or `nodejs16.x`)
140
141
 
141
142
  - `rustTargetDirectory`
142
143
 
@@ -441,9 +442,9 @@ need to be the same as the one used when installing those native modules.
441
442
 
442
443
  In Netlify, this is done by ensuring that the following Node.js versions are the same:
443
444
 
444
- - Build-time Node.js version: this defaults to Node `12`, but can be
445
+ - Build-time Node.js version: this defaults to Node `16`, but can be
445
446
  [overridden with a `.nvmrc` or `NODE_VERSION` environment variable](https://docs.netlify.com/configure-builds/manage-dependencies/#node-js-and-javascript).
446
- - Function runtime Node.js version: this defaults to `nodejs12.x` but can be
447
+ - Function runtime Node.js version: this defaults to `nodejs16.x` but can be
447
448
  [overridden with a `AWS_LAMBDA_JS_RUNTIME` environment variable](https://docs.netlify.com/functions/build-with-javascript/#runtime-settings).
448
449
 
449
450
  Note that this problem might not apply for Node.js native modules using the [N-API](https://nodejs.org/api/n-api.html).
package/dist/config.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FunctionSource } from './function.js';
2
- import type { NodeBundlerName } from './runtimes/node/bundlers/index.js';
2
+ import type { NodeBundlerName } from './runtimes/node/bundlers/types.js';
3
3
  import type { NodeVersionString } from './runtimes/node/index.js';
4
4
  export interface FunctionConfig {
5
5
  externalNodeModules?: string[];
package/dist/main.js CHANGED
@@ -14,7 +14,7 @@ const augmentWithISC = async (func) => {
14
14
  if (func.runtime.name !== 'js') {
15
15
  return func;
16
16
  }
17
- const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(func.mainFile);
17
+ const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(func.mainFile, func.name);
18
18
  return { ...func, inSourceConfig };
19
19
  };
20
20
  // List all Netlify Functions main entry files for a specific directory
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.build = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
+ const error_js_1 = require("../../utils/error.js");
6
7
  const shell_js_1 = require("../../utils/shell.js");
7
8
  const build = async ({ destPath, mainFile, srcDir }) => {
8
9
  const functionName = (0, path_1.basename)(srcDir);
@@ -17,10 +18,8 @@ const build = async ({ destPath, mainFile, srcDir }) => {
17
18
  });
18
19
  }
19
20
  catch (error) {
20
- const runtime = 'go';
21
- error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime } };
22
21
  console.error(`Could not compile Go function ${functionName}:\n`);
23
- throw error;
22
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: 'go' });
24
23
  }
25
24
  const stat = await fs_1.promises.lstat(destPath);
26
25
  return {
@@ -4,6 +4,7 @@ exports.bundleJsFile = exports.ESBUILD_LOG_LIMIT = void 0;
4
4
  const path_1 = require("path");
5
5
  const esbuild_1 = require("@netlify/esbuild");
6
6
  const tmp_promise_1 = require("tmp-promise");
7
+ const error_js_1 = require("../../../../utils/error.js");
7
8
  const fs_js_1 = require("../../../../utils/fs.js");
8
9
  const bundler_target_js_1 = require("./bundler_target.js");
9
10
  const plugin_dynamic_imports_js_1 = require("./plugin_dynamic_imports.js");
@@ -94,13 +95,7 @@ const bundleJsFile = async function ({ additionalModulePaths, basePath, config,
94
95
  };
95
96
  }
96
97
  catch (error) {
97
- const bundler = 'esbuild';
98
- const runtime = 'js';
99
- error.customErrorInfo = {
100
- type: 'functionsBundling',
101
- location: { bundler, functionName: name, runtime },
102
- };
103
- throw error;
98
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName: name, runtime: 'js', bundler: 'esbuild' });
104
99
  }
105
100
  };
106
101
  exports.bundleJsFile = bundleJsFile;
@@ -5,6 +5,7 @@ declare const versionMap: {
5
5
  readonly '10.x': "node10";
6
6
  readonly '12.x': "node12";
7
7
  readonly '14.x': "node14";
8
+ readonly '16.x': "node16";
8
9
  };
9
10
  declare type VersionKeys = keyof typeof versionMap;
10
11
  declare type VersionValues = typeof versionMap[VersionKeys];
@@ -8,6 +8,7 @@ const versionMap = {
8
8
  '10.x': 'node10',
9
9
  '12.x': 'node12',
10
10
  '14.x': 'node14',
11
+ '16.x': 'node16',
11
12
  };
12
13
  const getBundlerTarget = (suppliedVersion) => {
13
14
  const version = normalizeVersion(suppliedVersion);
@@ -1,6 +1,6 @@
1
- import type { BundleFunction } from '../index.js';
1
+ import type { BundleFunction } from '../types.js';
2
2
  declare const bundler: {
3
3
  bundle: BundleFunction;
4
- getSrcFiles: import("../index.js").GetSrcFilesFunction;
4
+ getSrcFiles: import("../types.js").GetSrcFilesFunction;
5
5
  };
6
6
  export default bundler;
@@ -1,3 +1,3 @@
1
1
  import type { Plugin } from '@netlify/esbuild';
2
- import type { NativeNodeModules } from '../index.js';
2
+ import type { NativeNodeModules } from '../types.js';
3
3
  export declare const getNativeModulesPlugin: (externalizedModules: NativeNodeModules) => Plugin;
@@ -1,2 +1,2 @@
1
- import type { GetSrcFilesFunction } from '../index.js';
1
+ import type { GetSrcFilesFunction } from '../types.js';
2
2
  export declare const getSrcFiles: GetSrcFilesFunction;
@@ -1,50 +1,8 @@
1
- import type { Message } from '@netlify/esbuild';
2
- import { FunctionConfig } from '../../../config.js';
3
- import { FeatureFlag, FeatureFlags } from '../../../feature_flags.js';
4
- import { FunctionSource } from '../../../function.js';
5
- import { ModuleFormat } from '../utils/module_format.js';
6
- export declare type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi';
7
- declare type BundlerWarning = Message;
8
- declare type CleanupFunction = () => Promise<void>;
9
- export declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
10
- export declare type BundleFunction = (args: {
11
- basePath?: string;
12
- config: FunctionConfig;
13
- featureFlags: Record<FeatureFlag, boolean>;
14
- pluginsModulesPath?: string;
15
- repositoryRoot?: string;
16
- } & FunctionSource) => Promise<{
17
- aliases?: Map<string, string>;
18
- rewrites?: Map<string, string>;
19
- basePath: string;
20
- bundlerWarnings?: BundlerWarning[];
21
- cleanupFunction?: CleanupFunction;
22
- includedFiles: string[];
23
- inputs: string[];
24
- mainFile: string;
25
- moduleFormat: ModuleFormat;
26
- nativeNodeModules?: NativeNodeModules;
27
- nodeModulesWithDynamicImports?: string[];
28
- srcFiles: string[];
29
- }>;
30
- export declare type GetSrcFilesFunction = (args: {
31
- basePath?: string;
32
- config: FunctionConfig;
33
- featureFlags: FeatureFlags;
34
- pluginsModulesPath?: string;
35
- repositoryRoot?: string;
36
- } & FunctionSource) => Promise<{
37
- srcFiles: string[];
38
- includedFiles: string[];
39
- }>;
40
- interface NodeBundler {
41
- bundle: BundleFunction;
42
- getSrcFiles: GetSrcFilesFunction;
43
- }
1
+ import { FeatureFlags } from '../../../feature_flags.js';
2
+ import type { NodeBundler, NodeBundlerName } from './types.js';
44
3
  export declare const getBundler: (name: NodeBundlerName) => NodeBundler;
45
4
  export declare const getDefaultBundler: ({ extension, mainFile, featureFlags, }: {
46
5
  extension: string;
47
6
  mainFile: string;
48
7
  featureFlags: FeatureFlags;
49
8
  }) => Promise<NodeBundlerName>;
50
- export {};
@@ -1,4 +1,4 @@
1
- import type { GetSrcFilesFunction, BundleFunction } from '../index.js';
1
+ import type { GetSrcFilesFunction, BundleFunction } from '../types.js';
2
2
  declare const bundler: {
3
3
  bundle: BundleFunction;
4
4
  getSrcFiles: GetSrcFilesFunction;
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.transpile = void 0;
4
4
  const esbuild_1 = require("@netlify/esbuild");
5
+ const error_js_1 = require("../../../../utils/error.js");
5
6
  const bundler_target_js_1 = require("../esbuild/bundler_target.js");
6
7
  const transpile = async (path, config, functionName) => {
7
8
  // The version of ECMAScript to use as the build target. This will determine
@@ -21,13 +22,7 @@ const transpile = async (path, config, functionName) => {
21
22
  return transpiled.outputFiles[0].text;
22
23
  }
23
24
  catch (error) {
24
- const bundler = 'nft';
25
- const runtime = 'js';
26
- error.customErrorInfo = {
27
- type: 'functionsBundling',
28
- location: { bundler, functionName, runtime },
29
- };
30
- throw error;
25
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: 'js', bundler: 'nft' });
31
26
  }
32
27
  };
33
28
  exports.transpile = transpile;
@@ -0,0 +1,44 @@
1
+ import type { Message } from '@netlify/esbuild';
2
+ import type { FunctionConfig } from '../../../config.js';
3
+ import type { FeatureFlag, FeatureFlags } from '../../../feature_flags.js';
4
+ import type { FunctionSource } from '../../../function.js';
5
+ import type { ModuleFormat } from '../utils/module_format.js';
6
+ export declare type NodeBundlerName = 'esbuild' | 'esbuild_zisi' | 'nft' | 'zisi';
7
+ declare type BundlerWarning = Message;
8
+ declare type CleanupFunction = () => Promise<void>;
9
+ export declare type NativeNodeModules = Record<string, Record<string, string | undefined>>;
10
+ export declare type BundleFunction = (args: {
11
+ basePath?: string;
12
+ config: FunctionConfig;
13
+ featureFlags: Record<FeatureFlag, boolean>;
14
+ pluginsModulesPath?: string;
15
+ repositoryRoot?: string;
16
+ } & FunctionSource) => Promise<{
17
+ aliases?: Map<string, string>;
18
+ rewrites?: Map<string, string>;
19
+ basePath: string;
20
+ bundlerWarnings?: BundlerWarning[];
21
+ cleanupFunction?: CleanupFunction;
22
+ includedFiles: string[];
23
+ inputs: string[];
24
+ mainFile: string;
25
+ moduleFormat: ModuleFormat;
26
+ nativeNodeModules?: NativeNodeModules;
27
+ nodeModulesWithDynamicImports?: string[];
28
+ srcFiles: string[];
29
+ }>;
30
+ export declare type GetSrcFilesFunction = (args: {
31
+ basePath?: string;
32
+ config: FunctionConfig;
33
+ featureFlags: FeatureFlags;
34
+ pluginsModulesPath?: string;
35
+ repositoryRoot?: string;
36
+ } & FunctionSource) => Promise<{
37
+ srcFiles: string[];
38
+ includedFiles: string[];
39
+ }>;
40
+ export interface NodeBundler {
41
+ bundle: BundleFunction;
42
+ getSrcFiles: GetSrcFilesFunction;
43
+ }
44
+ export {};
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -1,6 +1,6 @@
1
- import type { BundleFunction } from '../index.js';
1
+ import type { BundleFunction } from '../types.js';
2
2
  declare const bundler: {
3
3
  bundle: BundleFunction;
4
- getSrcFiles: import("../index.js").GetSrcFilesFunction;
4
+ getSrcFiles: import("../types.js").GetSrcFilesFunction;
5
5
  };
6
6
  export default bundler;
@@ -30,6 +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 error_js_1 = require("../../../../utils/error.js");
33
34
  const fs_js_1 = require("../../../../utils/fs.js");
34
35
  // Maximum number of log messages that an esbuild instance will produce. This
35
36
  // limit is important to avoid out-of-memory errors due to too much data being
@@ -73,13 +74,7 @@ const listImports = async ({ functionName, path, }) => {
73
74
  });
74
75
  }
75
76
  catch (error) {
76
- const bundler = 'zisi';
77
- const runtime = 'js';
78
- error.customErrorInfo = {
79
- type: 'functionsBundling',
80
- location: { bundler, functionName, runtime },
81
- };
82
- throw error;
77
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: 'js', bundler: 'zisi' });
83
78
  }
84
79
  finally {
85
80
  await (0, fs_js_1.safeUnlink)(targetPath);
@@ -1,2 +1,2 @@
1
- import type { GetSrcFilesFunction } from '../index.js';
1
+ import type { GetSrcFilesFunction } from '../types.js';
2
2
  export declare const getSrcFiles: GetSrcFilesFunction;
@@ -2,7 +2,7 @@ import { ArgumentPlaceholder, Expression, SpreadElement, JSXNamespacedName } fro
2
2
  import { parse as parseSchedule } from './properties/schedule.js';
3
3
  export declare const IN_SOURCE_CONFIG_MODULE = "@netlify/functions";
4
4
  export declare type ISCValues = Partial<ReturnType<typeof parseSchedule>>;
5
- export declare const findISCDeclarationsInPath: (sourcePath: string) => Promise<ISCValues>;
5
+ export declare const findISCDeclarationsInPath: (sourcePath: string, functionName: string) => Promise<ISCValues>;
6
6
  export declare type ISCHandlerArg = ArgumentPlaceholder | Expression | SpreadElement | JSXNamespacedName;
7
7
  export interface ISCExport {
8
8
  local: string;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.findISCDeclarationsInPath = exports.IN_SOURCE_CONFIG_MODULE = void 0;
4
+ const error_js_1 = require("../../../utils/error.js");
4
5
  const non_nullable_js_1 = require("../../../utils/non_nullable.js");
5
6
  const bindings_js_1 = require("../parser/bindings.js");
6
7
  const exports_js_1 = require("../parser/exports.js");
@@ -8,17 +9,26 @@ const imports_js_1 = require("../parser/imports.js");
8
9
  const index_js_1 = require("../parser/index.js");
9
10
  const schedule_js_1 = require("./properties/schedule.js");
10
11
  exports.IN_SOURCE_CONFIG_MODULE = '@netlify/functions';
12
+ const validateScheduleFunction = (functionFound, scheduleFound, functionName) => {
13
+ if (!functionFound) {
14
+ throw new error_js_1.FunctionBundlingUserError("The `schedule` helper was imported but we couldn't find any usages. If you meant to schedule a function, please check that `schedule` is invoked and `handler` correctly exported.", { functionName, runtime: 'js' });
15
+ }
16
+ if (!scheduleFound) {
17
+ throw new error_js_1.FunctionBundlingUserError('Unable to find cron expression for scheduled function. The cron expression (first argument) for the `schedule` helper needs to be accessible inside the file and cannot be imported.', { functionName, runtime: 'js' });
18
+ }
19
+ };
11
20
  // Parses a JS/TS file and looks for in-source config declarations. It returns
12
21
  // an array of all declarations found, with `property` indicating the name of
13
22
  // the property and `data` its value.
14
- const findISCDeclarationsInPath = async (sourcePath) => {
23
+ const findISCDeclarationsInPath = async (sourcePath, functionName) => {
15
24
  const ast = await (0, index_js_1.safelyParseFile)(sourcePath);
16
25
  if (ast === null) {
17
26
  return {};
18
27
  }
19
28
  const imports = ast.body.flatMap((node) => (0, imports_js_1.getImports)(node, exports.IN_SOURCE_CONFIG_MODULE));
20
- const scheduledFuncsExpected = imports.filter(({ imported }) => imported === 'schedule').length;
21
- let scheduledFuncsFound = 0;
29
+ const scheduledFunctionExpected = imports.some(({ imported }) => imported === 'schedule');
30
+ let scheduledFunctionFound = false;
31
+ let scheduleFound = false;
22
32
  const getAllBindings = (0, bindings_js_1.createBindingsMethod)(ast.body);
23
33
  const mainExports = (0, exports_js_1.getMainExport)(ast.body, getAllBindings);
24
34
  const iscExports = mainExports
@@ -30,8 +40,9 @@ const findISCDeclarationsInPath = async (sourcePath) => {
30
40
  switch (matchingImport.imported) {
31
41
  case 'schedule': {
32
42
  const parsed = (0, schedule_js_1.parse)({ args }, getAllBindings);
43
+ scheduledFunctionFound = true;
33
44
  if (parsed.schedule) {
34
- scheduledFuncsFound += 1;
45
+ scheduleFound = true;
35
46
  }
36
47
  return parsed;
37
48
  }
@@ -41,8 +52,8 @@ const findISCDeclarationsInPath = async (sourcePath) => {
41
52
  return null;
42
53
  })
43
54
  .filter(non_nullable_js_1.nonNullable);
44
- if (scheduledFuncsFound < scheduledFuncsExpected) {
45
- throw new Error('Warning: unable to find cron expression for scheduled function. `schedule` imported but not called or exported. If you meant to schedule a function, please check that `schedule` is invoked with an appropriate cron expression.');
55
+ if (scheduledFunctionExpected) {
56
+ validateScheduleFunction(scheduledFunctionFound, scheduleFound, functionName);
46
57
  }
47
58
  const mergedExports = iscExports.reduce((acc, obj) => ({ ...acc, ...obj }), {});
48
59
  return mergedExports;
@@ -50,7 +50,7 @@ const zipFunction = async function ({ archiveFormat, basePath, config = {}, dest
50
50
  srcPath,
51
51
  stat,
52
52
  });
53
- const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(mainFile);
53
+ const inSourceConfig = await (0, index_js_2.findISCDeclarationsInPath)(mainFile, name);
54
54
  (0, plugin_modules_path_js_1.createAliases)(srcFiles, pluginsModulesPath, aliases, finalBasePath);
55
55
  const zipPath = await (0, zip_js_1.zipNodeJs)({
56
56
  aliases,
@@ -3,7 +3,7 @@ export declare type NodeVersionString = `${SupportedVersionNumbers}.x` | `nodejs
3
3
  export interface NodeVersionSupport {
4
4
  esm: boolean;
5
5
  }
6
- export declare const DEFAULT_NODE_VERSION = 14;
6
+ export declare const DEFAULT_NODE_VERSION = 16;
7
7
  export declare const getNodeVersion: (configVersion?: string) => number;
8
8
  export declare const getNodeSupportMatrix: (configVersion?: string) => NodeVersionSupport;
9
9
  export declare const parseVersion: (input: string | undefined) => number | undefined;
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseVersion = exports.getNodeSupportMatrix = exports.getNodeVersion = exports.DEFAULT_NODE_VERSION = void 0;
4
4
  // Must match the default version used in Bitballoon.
5
- exports.DEFAULT_NODE_VERSION = 14;
5
+ exports.DEFAULT_NODE_VERSION = 16;
6
6
  const VERSION_REGEX = /(nodejs)?(\d+)\.x/;
7
7
  const getNodeVersion = (configVersion) => { var _a; return (_a = (0, exports.parseVersion)(configVersion)) !== null && _a !== void 0 ? _a : exports.DEFAULT_NODE_VERSION; };
8
8
  exports.getNodeVersion = getNodeVersion;
@@ -3,7 +3,7 @@ import { FunctionConfig } from '../config.js';
3
3
  import { FeatureFlags } from '../feature_flags.js';
4
4
  import { FunctionSource, SourceFile } from '../function.js';
5
5
  import { FsCache } from '../utils/fs.js';
6
- import type { NodeBundlerName } from './node/bundlers/index.js';
6
+ import type { NodeBundlerName } from './node/bundlers/types.js';
7
7
  import type { ISCValues } from './node/in_source_config/index.js';
8
8
  export declare type RuntimeName = 'go' | 'js' | 'rs';
9
9
  export declare type FindFunctionsInPathsFunction = (args: {
@@ -8,17 +8,16 @@ const fs_1 = require("fs");
8
8
  const path_1 = require("path");
9
9
  const tmp_promise_1 = __importDefault(require("tmp-promise"));
10
10
  const toml_1 = __importDefault(require("toml"));
11
+ const error_js_1 = require("../../utils/error.js");
11
12
  const shell_js_1 = require("../../utils/shell.js");
12
13
  const constants_js_1 = require("./constants.js");
13
- const runtimeName = 'rs';
14
14
  const build = async ({ config, name, srcDir }) => {
15
15
  const functionName = (0, path_1.basename)(srcDir);
16
16
  try {
17
17
  await installToolchainOnce();
18
18
  }
19
19
  catch (error) {
20
- error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime: runtimeName } };
21
- throw error;
20
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: 'rs' });
22
21
  }
23
22
  const targetDirectory = await getTargetDirectory({ config, name });
24
23
  await cargoBuild({ functionName, srcDir, targetDirectory });
@@ -54,8 +53,7 @@ const cargoBuild = async ({ functionName, srcDir, targetDirectory, }) => {
54
53
  error.message =
55
54
  'There is no Rust toolchain installed. Visit https://ntl.fyi/missing-rust-toolchain for more information.';
56
55
  }
57
- error.customErrorInfo = { type: 'functionsBundling', location: { functionName, runtime: runtimeName } };
58
- throw error;
56
+ throw error_js_1.FunctionBundlingUserError.addCustomErrorInfo(error, { functionName, runtime: 'rs' });
59
57
  }
60
58
  };
61
59
  const checkRustToolchain = async () => {
@@ -0,0 +1,19 @@
1
+ import type { NodeBundlerName } from '../runtimes/node/bundlers/types.js';
2
+ import type { RuntimeName } from '../runtimes/runtime';
3
+ interface CustomErrorLocation {
4
+ functionName: string;
5
+ runtime: RuntimeName;
6
+ bundler?: NodeBundlerName;
7
+ }
8
+ interface CustomErrorInfo {
9
+ type: 'functionsBundling';
10
+ location: CustomErrorLocation;
11
+ }
12
+ declare type UserError = Error & {
13
+ customErrorInfo: CustomErrorInfo;
14
+ };
15
+ export declare class FunctionBundlingUserError extends Error {
16
+ constructor(message: string, customErrorInfo: CustomErrorLocation);
17
+ static addCustomErrorInfo(error: Error, customErrorInfo: CustomErrorLocation): UserError;
18
+ }
19
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FunctionBundlingUserError = void 0;
4
+ class FunctionBundlingUserError extends Error {
5
+ constructor(message, customErrorInfo) {
6
+ super(message);
7
+ Object.setPrototypeOf(this, new.target.prototype);
8
+ this.name = 'FunctionBundlingUserError';
9
+ Error.captureStackTrace(this, FunctionBundlingUserError);
10
+ FunctionBundlingUserError.addCustomErrorInfo(this, customErrorInfo);
11
+ }
12
+ static addCustomErrorInfo(error, customErrorInfo) {
13
+ const info = {
14
+ type: 'functionsBundling',
15
+ location: customErrorInfo,
16
+ };
17
+ error.customErrorInfo = info;
18
+ return error;
19
+ }
20
+ }
21
+ exports.FunctionBundlingUserError = FunctionBundlingUserError;
22
+ //# sourceMappingURL=error.js.map
@@ -13,6 +13,5 @@ export declare const cachedReadFile: (cache: FsCache, path: string, options?: Bu
13
13
  export declare const getPathWithExtension: (path: string, extension: string) => string;
14
14
  export declare const safeUnlink: (path: string) => Promise<void>;
15
15
  export declare const listFunctionsDirectories: (srcFolders: string[]) => Promise<string[]>;
16
- export declare const listFunctionsDirectory: (srcFolder: string) => Promise<string[]>;
17
16
  export declare const resolveFunctionsDirectories: (input: string | string[]) => string[];
18
17
  export declare const mkdirAndWriteFile: typeof fs.writeFile;
package/dist/utils/fs.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.mkdirAndWriteFile = exports.resolveFunctionsDirectories = exports.listFunctionsDirectory = exports.listFunctionsDirectories = exports.safeUnlink = exports.getPathWithExtension = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
3
+ exports.mkdirAndWriteFile = exports.resolveFunctionsDirectories = exports.listFunctionsDirectories = exports.safeUnlink = exports.getPathWithExtension = exports.cachedReadFile = exports.cachedReaddir = exports.cachedLstat = void 0;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const non_nullable_js_1 = require("./non_nullable.js");
@@ -34,32 +34,33 @@ exports.safeUnlink = safeUnlink;
34
34
  // filenames within those directories, if at least one of the directories
35
35
  // exists. If not, an error is thrown.
36
36
  const listFunctionsDirectories = async function (srcFolders) {
37
- const filenamesByDirectory = await Promise.all(srcFolders.map(async (srcFolder) => {
38
- try {
39
- const filenames = await (0, exports.listFunctionsDirectory)(srcFolder);
40
- return filenames;
37
+ const filenamesByDirectory = await Promise.allSettled(srcFolders.map((srcFolder) => listFunctionsDirectory(srcFolder)));
38
+ const errorMessages = [];
39
+ const validDirectories = filenamesByDirectory
40
+ .map((result) => {
41
+ if (result.status === 'rejected') {
42
+ // If the error is about `ENOENT` (FileNotFound) then we only throw later if this happens
43
+ // for all directories.
44
+ if (result.reason instanceof Error && result.reason.code === 'ENOENT') {
45
+ return null;
46
+ }
47
+ // In any other error case besides `ENOENT` throw immediately
48
+ throw result.reason;
41
49
  }
42
- catch {
43
- return null;
44
- }
45
- }));
46
- const validDirectories = filenamesByDirectory.filter(non_nullable_js_1.nonNullable);
50
+ return result.value;
51
+ })
52
+ .filter(non_nullable_js_1.nonNullable);
47
53
  if (validDirectories.length === 0) {
48
- throw new Error(`Functions folder does not exist: ${srcFolders.join(', ')}`);
54
+ throw new Error(`Functions folders do not exist: ${srcFolders.join(', ')}
55
+ ${errorMessages.join('\n')}`);
49
56
  }
50
57
  return validDirectories.flat();
51
58
  };
52
59
  exports.listFunctionsDirectories = listFunctionsDirectories;
53
60
  const listFunctionsDirectory = async function (srcFolder) {
54
- try {
55
- const filenames = await fs_1.promises.readdir(srcFolder);
56
- return filenames.map((name) => (0, path_1.join)(srcFolder, name));
57
- }
58
- catch {
59
- throw new Error(`Functions folder does not exist: ${srcFolder}`);
60
- }
61
+ const filenames = await fs_1.promises.readdir(srcFolder);
62
+ return filenames.map((name) => (0, path_1.join)(srcFolder, name));
61
63
  };
62
- exports.listFunctionsDirectory = listFunctionsDirectory;
63
64
  const resolveFunctionsDirectories = (input) => {
64
65
  const directories = Array.isArray(input) ? input : [input];
65
66
  const absoluteDirectories = directories.map((srcFolder) => (0, path_1.resolve)(srcFolder));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@netlify/zip-it-and-ship-it",
3
- "version": "5.12.0",
3
+ "version": "5.13.2",
4
4
  "description": "Zip it and ship it",
5
5
  "main": "./dist/main.js",
6
6
  "bin": {