semantic-release 26.0.0-beta.6 → 26.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/lib/git.js DELETED
@@ -1,417 +0,0 @@
1
- import gitLogParser from "git-log-parser";
2
- import getStream from "get-stream";
3
- import { execa } from "execa";
4
- import debugGit from "debug";
5
- import { merge } from "lodash-es";
6
- import { GIT_NOTE_REF } from "./definitions/constants.js";
7
- import { extractGitLogTags } from "./utils.js";
8
-
9
- const debug = debugGit("semantic-release:git");
10
-
11
- Object.assign(gitLogParser.fields, { hash: "H", message: "B", gitTags: "d", committerDate: { key: "ci", type: Date } });
12
-
13
- /**
14
- * Get the commit sha for a given tag.
15
- *
16
- * @param {String} tagName Tag name for which to retrieve the commit sha.
17
- * @param {Object} [execaOpts] Options to pass to `execa`.
18
- *
19
- * @return {String} The commit sha of the tag in parameter or `null`.
20
- */
21
- export async function getTagHead(tagName, execaOptions) {
22
- return (await execa("git", ["rev-list", "-1", tagName], execaOptions)).stdout;
23
- }
24
-
25
- /**
26
- * Get all the tags for a given branch.
27
- *
28
- * @param {String} branch The branch for which to retrieve the tags.
29
- * @param {Object} [execaOpts] Options to pass to `execa`.
30
- *
31
- * @return {Array<String>} List of git tags.
32
- * @throws {Error} If the `git` command fails.
33
- */
34
- export async function getTags(branch, execaOptions) {
35
- return (await execa("git", ["tag", "--merged", branch], execaOptions)).stdout
36
- .split("\n")
37
- .map((tag) => tag.trim())
38
- .filter(Boolean);
39
- }
40
-
41
- /**
42
- * Retrieve a range of commits.
43
- *
44
- * @param {String} from to includes all commits made after this sha (does not include this sha).
45
- * @param {String} to to includes all commits made before this sha (also include this sha).
46
- * @param {Object} [execaOpts] Options to pass to `execa`.
47
- * @return {Promise<Array<Object>>} The list of commits between `from` and `to`.
48
- */
49
- export async function getCommits(from, to, execaOptions) {
50
- return (
51
- await getStream.array(
52
- gitLogParser.parse(
53
- { _: `${from ? from + ".." : ""}${to}` },
54
- { cwd: execaOptions.cwd, env: { ...process.env, ...execaOptions.env } }
55
- )
56
- )
57
- ).map(({ message, gitTags, ...commit }) => ({
58
- ...commit,
59
- message: (message ?? "").trim(),
60
- gitTags: (gitTags ?? "").trim(),
61
- }));
62
- }
63
-
64
- /**
65
- * Get all the repository branches.
66
- *
67
- * @param {String} repositoryUrl The remote repository URL.
68
- * @param {Object} [execaOpts] Options to pass to `execa`.
69
- *
70
- * @return {Array<String>} List of git branches.
71
- * @throws {Error} If the `git` command fails.
72
- */
73
- export async function getBranches(repositoryUrl, execaOptions) {
74
- return (await execa("git", ["ls-remote", "--heads", "--", repositoryUrl], execaOptions)).stdout
75
- .split("\n")
76
- .filter(Boolean)
77
- .map((branch) => branch.match(/^.+refs\/heads\/(?<branch>.+)$/)[1]);
78
- }
79
-
80
- /**
81
- * Verify if the `ref` exits
82
- *
83
- * @param {String} ref The reference to verify.
84
- * @param {Object} [execaOpts] Options to pass to `execa`.
85
- *
86
- * @return {Boolean} `true` if the reference exists, falsy otherwise.
87
- */
88
- export async function isRefExists(ref, execaOptions) {
89
- try {
90
- return (await execa("git", ["rev-parse", "--verify", ref], execaOptions)).exitCode === 0;
91
- } catch (error) {
92
- debug(error);
93
- }
94
- }
95
-
96
- /**
97
- * Fetch all the tags from a branch. Unshallow if necessary.
98
- * This will update the local branch from the latest on the remote if:
99
- * - The branch is not the one that triggered the CI
100
- * - The CI created a detached head
101
- *
102
- * Otherwise it just calls `git fetch` without specifying the `refspec` option to avoid overwritting the head commit set by the CI.
103
- *
104
- * The goal is to retrieve the informations on all the release branches without "disturbing" the CI, leaving the trigger branch or the detached head intact.
105
- *
106
- * @param {String} repositoryUrl The remote repository URL.
107
- * @param {String} branch The repository branch to fetch.
108
- * @param {Object} [execaOpts] Options to pass to `execa`.
109
- */
110
- export async function fetch(repositoryUrl, branch, ciBranch, execaOptions) {
111
- const isDetachedHead =
112
- (await execa("git", ["rev-parse", "--abbrev-ref", "HEAD"], { ...execaOptions, reject: false })).stdout === "HEAD";
113
-
114
- try {
115
- await execa(
116
- "git",
117
- [
118
- "fetch",
119
- "--unshallow",
120
- "--tags",
121
- ...(branch === ciBranch && !isDetachedHead
122
- ? ["--", repositoryUrl]
123
- : ["--update-head-ok", "--", repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
124
- ],
125
- execaOptions
126
- );
127
- } catch {
128
- await execa(
129
- "git",
130
- [
131
- "fetch",
132
- "--tags",
133
- ...(branch === ciBranch && !isDetachedHead
134
- ? ["--", repositoryUrl]
135
- : ["--update-head-ok", "--", repositoryUrl, `+refs/heads/${branch}:refs/heads/${branch}`]),
136
- ],
137
- execaOptions
138
- );
139
- }
140
- }
141
-
142
- /**
143
- * Unshallow the git repository if necessary and fetch all the notes.
144
- *
145
- * @param {String} repositoryUrl The remote repository URL.
146
- * @param {Object} [execaOpts] Options to pass to `execa`.
147
- */
148
- export async function fetchNotes(repositoryUrl, execaOptions) {
149
- try {
150
- await execa("git", ["fetch", "--unshallow", "--", repositoryUrl, `+refs/notes/*:refs/notes/*`], execaOptions);
151
- } catch {
152
- await execa("git", ["fetch", "--", repositoryUrl, `+refs/notes/*:refs/notes/*`], {
153
- ...execaOptions,
154
- reject: false,
155
- });
156
- }
157
- }
158
-
159
- /**
160
- * Get the HEAD sha.
161
- *
162
- * @param {Object} [execaOpts] Options to pass to `execa`.
163
- *
164
- * @return {String} the sha of the HEAD commit.
165
- */
166
- export async function getGitHead(execaOptions) {
167
- return (await execa("git", ["rev-parse", "HEAD"], execaOptions)).stdout;
168
- }
169
-
170
- /**
171
- * Get the repository remote URL.
172
- *
173
- * @param {Object} [execaOpts] Options to pass to `execa`.
174
- *
175
- * @return {string} The value of the remote git URL.
176
- */
177
- export async function repoUrl(execaOptions) {
178
- try {
179
- return (await execa("git", ["config", "--get", "remote.origin.url"], execaOptions)).stdout;
180
- } catch (error) {
181
- debug(error);
182
- }
183
- }
184
-
185
- /**
186
- * Test if the current working directory is a Git repository.
187
- *
188
- * @param {Object} [execaOpts] Options to pass to `execa`.
189
- *
190
- * @return {Boolean} `true` if the current working directory is in a git repository, falsy otherwise.
191
- */
192
- export async function isGitRepo(execaOptions) {
193
- try {
194
- return (await execa("git", ["rev-parse", "--git-dir"], execaOptions)).exitCode === 0;
195
- } catch (error) {
196
- debug(error);
197
- }
198
- }
199
-
200
- /**
201
- * Verify the write access authorization to remote repository with tags push dry-run.
202
- *
203
- * @param {String} repositoryUrl The remote repository URL.
204
- * @param {Object} [execaOpts] Options to pass to `execa`.
205
- *
206
- * @throws {Error} if not authorized to push.
207
- */
208
- export async function verifyAuth(repositoryUrl, execaOptions) {
209
- try {
210
- await execa("git", ["push", "--dry-run", "--no-verify", "--", repositoryUrl], execaOptions);
211
-
212
- const tags = (await execa("git", ["tag", "--list"], execaOptions)).stdout
213
- .split("\n")
214
- .map((tag) => tag.trim())
215
- .filter(Boolean);
216
-
217
- if (tags.length > 0) {
218
- await execa("git", ["push", "--dry-run", "--no-verify", "--tags", "--", repositoryUrl], execaOptions);
219
- }
220
- } catch (error) {
221
- const message = `${error.stderr ?? ""}\n${error.message ?? ""}`;
222
-
223
- if (/tip of your current branch is behind|rejected|non-fast-forward/i.test(message)) {
224
- return;
225
- }
226
-
227
- debug(error);
228
- throw error;
229
- }
230
- }
231
-
232
- /**
233
- * Tag the commit head on the local repository.
234
- *
235
- * @param {String} tagName The name of the tag.
236
- * @param {String} ref The Git reference to tag.
237
- * @param {Object} [execaOpts] Options to pass to `execa`.
238
- *
239
- * @throws {Error} if the tag creation failed.
240
- */
241
- export async function tag(tagName, ref, execaOptions) {
242
- await execa("git", ["tag", tagName, ref], execaOptions);
243
- }
244
-
245
- /**
246
- * Push to the remote repository.
247
- *
248
- * @param {String} repositoryUrl The remote repository URL.
249
- * @param {Object} [execaOpts] Options to pass to `execa`.
250
- *
251
- * @throws {Error} if the push failed.
252
- */
253
- export async function push(repositoryUrl, execaOptions) {
254
- await execa("git", ["push", "--tags", "--", repositoryUrl], execaOptions);
255
- }
256
-
257
- /**
258
- * Push notes to the remote repository.
259
- *
260
- * @param {String} repositoryUrl The remote repository URL.
261
- * @param {Object} [execaOpts] Options to pass to `execa`.
262
- *
263
- * @throws {Error} if the push failed.
264
- */
265
- export async function pushNotes(repositoryUrl, ref, execaOptions) {
266
- await execa("git", ["push", "--", repositoryUrl, `refs/notes/${GIT_NOTE_REF}-${ref}`], execaOptions);
267
- }
268
-
269
- /**
270
- * Verify a tag name is a valid Git reference.
271
- *
272
- * @param {String} tagName the tag name to verify.
273
- * @param {Object} [execaOpts] Options to pass to `execa`.
274
- *
275
- * @return {Boolean} `true` if valid, falsy otherwise.
276
- */
277
- export async function verifyTagName(tagName, execaOptions) {
278
- try {
279
- return (await execa("git", ["check-ref-format", `refs/tags/${tagName}`], execaOptions)).exitCode === 0;
280
- } catch (error) {
281
- debug(error);
282
- }
283
- }
284
-
285
- /**
286
- * Verify a branch name is a valid Git reference.
287
- *
288
- * @param {String} branch the branch name to verify.
289
- * @param {Object} [execaOpts] Options to pass to `execa`.
290
- *
291
- * @return {Boolean} `true` if valid, falsy otherwise.
292
- */
293
- export async function verifyBranchName(branch, execaOptions) {
294
- try {
295
- return (await execa("git", ["check-ref-format", `refs/heads/${branch}`], execaOptions)).exitCode === 0;
296
- } catch (error) {
297
- debug(error);
298
- }
299
- }
300
-
301
- /**
302
- * Verify the local branch is up to date with the remote one.
303
- *
304
- * @param {String} repositoryUrl The remote repository URL.
305
- * @param {String} branch The repository branch for which to verify status.
306
- * @param {Object} [execaOpts] Options to pass to `execa`.
307
- *
308
- * @return {Boolean} `true` only if the local branch is ahead of the remote branch, falsy otherwise.
309
- */
310
- export async function isBranchUpToDate(repositoryUrl, branch, execaOptions) {
311
- const localHead = await getGitHead(execaOptions);
312
- const { stdout } = await execa("git", ["ls-remote", "--heads", "--", repositoryUrl, branch], execaOptions);
313
- const remoteHead = stdout.match(/^(?<ref>\w+)/)?.[0];
314
-
315
- if (!remoteHead) return false;
316
- if (localHead === remoteHead) return true;
317
-
318
- try {
319
- const { exitCode } = await execa("git", ["merge-base", "--is-ancestor", "--", remoteHead, localHead], {
320
- ...execaOptions,
321
- reject: false,
322
- });
323
-
324
- /**
325
- * Exit code 0 means remote is BEHIND local (local is AHEAD) - return true
326
- * Any other exit code means local is either BEHIND or DIVERGED of remote - return false
327
- */
328
- return exitCode === 0;
329
- } catch (error) {
330
- debug(error);
331
- return false;
332
- }
333
- }
334
-
335
- /**
336
- * Retrieves a map of Git tags to their associated notes from the repository.
337
- *
338
- * Executes a `git log` command to list tags and their notes, then parses the output into a Map
339
- * where each key is a tag name (e.g., "v24.2.3") and the value is the parsed JSON note object.
340
- *
341
- * @async
342
- * @param {import('execa').Options} execaOptions - Options to pass to `execa`
343
- * @returns {Promise<Map<string, Object>>} A promise that resolves to a Map of tag names to their notes.
344
- */
345
- export async function getTagsNotes(execaOptions) {
346
- /**
347
- * git log --tags="*" --decorate-refs="refs/tags/*" --no-walk --format="%d%x09%N" --notes="refs/notes/semantic-release*"
348
- *
349
- * (tag: v1.2.3)
350
- * (tag: v2.0.0) {"channels":[null]}
351
- * (tag: v3.0.0, tag: 5833/merge) {"channels":[null]}
352
- * ...
353
- */
354
- const { stdout } = await execa(
355
- "git",
356
- [
357
- "log",
358
- "--tags=*",
359
- "--decorate-refs=refs/tags/*", // This filters the refs shown in the %d format specifier to only include tags matching refs/tags/*.
360
- "--no-walk", // This ensures that only the commits directly pointed to by the tags are shown, not their historical parents.
361
- "--format=%d%x09%N", // <refName><tab><notes> eg. (tag: v24.2.3) {"channels":[null]}
362
- `--notes=refs/notes/${GIT_NOTE_REF}*`, // handles both patterns for notes - `semantic-release` (old) and `semantic-release-<version>` (current)
363
- ],
364
- execaOptions
365
- );
366
-
367
- // drop empty lines
368
- const lines = stdout.split("\n").filter((line) => line.trim() !== "");
369
-
370
- // parse and create a map of tags to notes
371
- const tagNotesMap = new Map();
372
-
373
- for (const line of lines) {
374
- const [tagPart, notePart] = line.trim().split("\t"); // tab separator is defined in the git command above (%x09)
375
- const tags = extractGitLogTags(tagPart);
376
- if (tags.length === 0) {
377
- debug(`Cannot parse tags from line: ${line}`);
378
- continue;
379
- }
380
-
381
- try {
382
- const parsed = JSON.parse(notePart);
383
- tags.forEach((tag) => {
384
- tagNotesMap.set(tag, parsed);
385
- });
386
- } catch (error) {
387
- debug(error);
388
- }
389
- }
390
-
391
- return tagNotesMap;
392
- }
393
-
394
- /**
395
- * Add JSON note to a given reference.
396
- *
397
- * @param {Object} note The object to save in the reference note.
398
- * @param {String} ref The Git reference to add the note to.
399
- * @param {Object} [execaOpts] Options to pass to `execa`.
400
- */
401
- export async function addNote(note, ref, execaOptions) {
402
- await execa(
403
- "git",
404
- ["notes", "--ref", `${GIT_NOTE_REF}-${ref}`, "add", "-f", "-m", JSON.stringify(note), ref],
405
- execaOptions
406
- );
407
- }
408
-
409
- /**
410
- * Get the reference of a tag
411
- *
412
- * @param {String} tag The tag name to get the reference of.
413
- * @param {Object} [execaOpts] Options to pass to `execa`.
414
- **/
415
- export async function getTagRef(tag, execaOptions) {
416
- return (await execa("git", ["show-ref", tag, "--hash"], execaOptions)).stdout;
417
- }
@@ -1,103 +0,0 @@
1
- import { castArray, identity, isNil, isPlainObject, isString, omit } from "lodash-es";
2
- import AggregateError from "aggregate-error";
3
- import getError from "../get-error.js";
4
- import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
5
- import { loadPlugin, parseConfig, validatePlugin, validateStep } from "./utils.js";
6
- import pipeline from "./pipeline.js";
7
- import normalize from "./normalize.js";
8
-
9
- export default async (context, pluginsPath) => {
10
- let { options, logger } = context;
11
- const errors = [];
12
-
13
- const plugins = options.plugins
14
- ? await castArray(options.plugins).reduce(async (eventualPluginsList, plugin) => {
15
- const pluginsList = await eventualPluginsList;
16
- if (validatePlugin(plugin)) {
17
- const [name, config] = parseConfig(plugin);
18
- plugin = isString(name) ? await loadPlugin(context, name, pluginsPath) : name;
19
-
20
- if (isPlainObject(plugin)) {
21
- Object.entries(plugin).forEach(([type, func]) => {
22
- if (PLUGINS_DEFINITIONS[type]) {
23
- Reflect.defineProperty(func, "pluginName", {
24
- value: isPlainObject(name) ? "Inline plugin" : name,
25
- writable: false,
26
- enumerable: true,
27
- });
28
- pluginsList[type] = [...(pluginsList[type] || []), [func, config]];
29
- }
30
- });
31
- } else {
32
- errors.push(getError("EPLUGINSCONF", { plugin }));
33
- }
34
- } else {
35
- errors.push(getError("EPLUGINSCONF", { plugin }));
36
- }
37
-
38
- return pluginsList;
39
- }, {})
40
- : [];
41
-
42
- if (errors.length > 0) {
43
- throw new AggregateError(errors);
44
- }
45
-
46
- options = { ...plugins, ...options };
47
-
48
- const pluginsConfig = await Object.entries(PLUGINS_DEFINITIONS).reduce(
49
- async (
50
- eventualPluginsConfigAccumulator,
51
- [type, { required, default: def, pipelineConfig, postprocess = identity, preprocess = identity }]
52
- ) => {
53
- let pluginOptions;
54
- const pluginsConfigAccumulator = await eventualPluginsConfigAccumulator;
55
-
56
- if (isNil(options[type]) && def) {
57
- pluginOptions = def;
58
- } else {
59
- // If an object is passed and the path is missing, merge it with step options
60
- if (isPlainObject(options[type]) && !options[type].path) {
61
- options[type] = castArray(plugins[type]).map((plugin) =>
62
- plugin ? [plugin[0], Object.assign(plugin[1], options[type])] : plugin
63
- );
64
- }
65
-
66
- if (!validateStep({ required }, options[type])) {
67
- errors.push(getError("EPLUGINCONF", { type, required, pluginConf: options[type] }));
68
- return pluginsConfigAccumulator;
69
- }
70
-
71
- pluginOptions = options[type];
72
- }
73
-
74
- const steps = await Promise.all(
75
- castArray(pluginOptions).map(async (pluginOpt) =>
76
- normalize(
77
- { ...context, options: omit(options, Object.keys(PLUGINS_DEFINITIONS), "plugins") },
78
- type,
79
- pluginOpt,
80
- pluginsPath
81
- )
82
- )
83
- );
84
-
85
- pluginsConfigAccumulator[type] = async (input) =>
86
- postprocess(
87
- await pipeline(
88
- steps,
89
- pipelineConfig && pipelineConfig(pluginsConfigAccumulator, logger)
90
- )(await preprocess(input)),
91
- input
92
- );
93
-
94
- return pluginsConfigAccumulator;
95
- },
96
- plugins
97
- );
98
- if (errors.length > 0) {
99
- throw new AggregateError(errors);
100
- }
101
-
102
- return pluginsConfig;
103
- };
@@ -1,69 +0,0 @@
1
- import { cloneDeep, isFunction, isPlainObject, noop, omit } from "lodash-es";
2
- import debugPlugins from "debug";
3
- import getError from "../get-error.js";
4
- import { extractErrors } from "../utils.js";
5
- import PLUGINS_DEFINITIONS from "../definitions/plugins.js";
6
- import { loadPlugin, parseConfig } from "./utils.js";
7
-
8
- const debug = debugPlugins("semantic-release:plugins");
9
-
10
- export default async (context, type, pluginOpt, pluginsPath) => {
11
- const { stdout, stderr, options, logger } = context;
12
- if (!pluginOpt) {
13
- return noop;
14
- }
15
-
16
- const [name, config] = parseConfig(pluginOpt);
17
- const pluginName = name.pluginName ? name.pluginName : isFunction(name) ? `[Function: ${name.name}]` : name;
18
- const plugin = await loadPlugin(context, name, pluginsPath);
19
-
20
- debug(`options for ${pluginName}/${type}: %O`, config);
21
-
22
- let func;
23
- if (isFunction(plugin)) {
24
- func = plugin.bind(null, cloneDeep({ ...options, ...config }));
25
- } else if (isPlainObject(plugin) && plugin[type] && isFunction(plugin[type])) {
26
- func = plugin[type].bind(null, cloneDeep({ ...options, ...config }));
27
- } else {
28
- throw getError("EPLUGIN", { type, pluginName });
29
- }
30
-
31
- const validator = async (input) => {
32
- const { dryRun, outputValidator } = PLUGINS_DEFINITIONS[type] || {};
33
- try {
34
- if (!input.options.dryRun || dryRun) {
35
- logger.log(`Start step "${type}" of plugin "${pluginName}"`);
36
- const result = await func({
37
- ...cloneDeep(omit(input, ["stdout", "stderr", "logger"])),
38
- stdout,
39
- stderr,
40
- logger: logger.scope(logger.scopeName, pluginName),
41
- });
42
- if (outputValidator && !outputValidator(result)) {
43
- throw getError(`E${type.toUpperCase()}OUTPUT`, { result, pluginName });
44
- }
45
-
46
- logger.success(`Completed step "${type}" of plugin "${pluginName}"`);
47
- return result;
48
- }
49
-
50
- logger.warn(`Skip step "${type}" of plugin "${pluginName}" in dry-run mode`);
51
- } catch (error) {
52
- logger.error(`Failed step "${type}" of plugin "${pluginName}"`);
53
- extractErrors(error).forEach((err) => Object.assign(err, { pluginName }));
54
- throw error;
55
- }
56
- };
57
-
58
- Reflect.defineProperty(validator, "pluginName", { value: pluginName, writable: false, enumerable: true });
59
-
60
- if (!isFunction(pluginOpt)) {
61
- if (pluginsPath[name]) {
62
- logger.success(`Loaded plugin "${type}" from "${pluginName}" in shareable config "${pluginsPath[name]}"`);
63
- } else {
64
- logger.success(`Loaded plugin "${type}" from "${pluginName}"`);
65
- }
66
- }
67
-
68
- return validator;
69
- };
@@ -1,59 +0,0 @@
1
- import { identity } from "lodash-es";
2
- import pReduce from "p-reduce";
3
- import AggregateError from "aggregate-error";
4
- import { extractErrors } from "../utils.js";
5
-
6
- /**
7
- * A Function that execute a list of function sequencially. If at least one Function ins the pipeline throws an Error or rejects, the pipeline function rejects as well.
8
- *
9
- * @typedef {Function} Pipeline
10
- * @param {Any} input Argument to pass to the first step in the pipeline.
11
- *
12
- * @return {Array<*>|*} An Array with the result of each step in the pipeline; if there is only 1 step in the pipeline, the result of this step is returned directly.
13
- *
14
- * @throws {AggregateError|Error} An AggregateError with the errors of each step in the pipeline that rejected; if there is only 1 step in the pipeline, the error of this step is thrown directly.
15
- */
16
-
17
- /**
18
- * Create a Pipeline with a list of Functions.
19
- *
20
- * @param {Array<Function>} steps The list of Function to execute.
21
- * @param {Object} options Pipeline options.
22
- * @param {Boolean} [options.settleAll=false] If `true` all the steps in the pipeline are executed, even if one rejects, if `false` the execution stops after a steps rejects.
23
- * @param {Function} [options.getNextInput=identity] Function called after each step is executed, with the last step input and the current current step result; the returned value will be used as the input of the next step.
24
- * @param {Function} [options.transform=identity] Function called after each step is executed, with the current step result, the step function and the last step input; the returned value will be saved in the pipeline results.
25
- *
26
- * @return {Pipeline} A Function that execute the `steps` sequentially
27
- */
28
- export default (steps, { settleAll = false, getNextInput = identity, transform = identity } = {}) =>
29
- async (input) => {
30
- const results = [];
31
- const errors = [];
32
- await pReduce(
33
- steps,
34
- async (lastInput, step) => {
35
- let result;
36
- try {
37
- // Call the step with the input computed at the end of the previous iteration and save intermediary result
38
- result = await transform(await step(lastInput), step, lastInput);
39
- results.push(result);
40
- } catch (error) {
41
- if (settleAll) {
42
- errors.push(...extractErrors(error));
43
- result = error;
44
- } else {
45
- throw error;
46
- }
47
- }
48
-
49
- // Prepare input for the next step, passing the input of the last iteration (or initial parameter for the first iteration) and the result of the current one
50
- return getNextInput(lastInput, result);
51
- },
52
- input
53
- );
54
- if (errors.length > 0) {
55
- throw new AggregateError(errors);
56
- }
57
-
58
- return results;
59
- };