Skip to content

Commit b6ee69a

Browse files
committed
feat: add 'replace_output' props to plugin, allowing plugins to modify resource's output.
Signed-off-by: zxypro1 <1018995004@qq.com>
1 parent f92df00 commit b6ee69a

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

packages/engine/src/actions/index.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { IAction, IActionLevel, IActionType, IAllowFailure, IComponentAction, IHookType, IPluginAction, IRunAction, getInputs } from '@serverless-devs/parse-spec';
2-
import { isEmpty, filter, includes, set, get } from 'lodash';
2+
import { isEmpty, filter, includes, set, get, cloneDeep } from 'lodash';
33
import * as utils from '@serverless-devs/utils';
44
import { DevsError, ETrackerType } from '@serverless-devs/utils';
55
import fs from 'fs-extra';
@@ -23,6 +23,7 @@ interface IRecord {
2323
allowFailure: boolean | IAllowFailure; // step allow_failure > action allow_failure
2424
command: string; // 记录当前执行的command
2525
startTime: number; // 记录开始时间
26+
replaceOutput: boolean;
2627
}
2728

2829
interface IOptions {
@@ -248,6 +249,10 @@ You can still use them now, but we suggest to modify them.`)
248249
const inputs = isEmpty(this.record.pluginOutput) ? this.inputs : this.record.pluginOutput;
249250
// Execute the plugin with the determined inputs and provided arguments.
250251
this.record.pluginOutput = await instance(inputs, hook.args, this.logger);
252+
// If prop 'replace_output' is true, replace the record's step output with the plugin output.
253+
if (hook.replace_output) {
254+
this.record.step.output = cloneDeep(this.record.pluginOutput);
255+
}
251256
} catch (e) {
252257
const error = e as Error;
253258
// Check if the failure is allowed based on the record's allowFailure setting.

packages/parse-spec/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export interface IPluginAction {
4141
level: `${IActionLevel}`;
4242
projectName: string;
4343
allow_failure?: boolean | IAllowFailure;
44+
replace_output?: boolean;
4445
}
4546
export interface IComponentAction {
4647
hookType: `${IHookType}`;

0 commit comments

Comments
 (0)