Skip to content

Commit 54dd347

Browse files
committed
refactor: resolve comments
1 parent dfe3589 commit 54dd347

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

packages/cli/src/util/load-plan.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ const importGlobals = async (
193193
) => {
194194
const fnStr = plan.workflow?.globals;
195195
if (fnStr && isPath(fnStr)) {
196-
// FIXME: fetchFile function isn't generic enough
197196
plan.workflow.globals = await fetchFile(
198197
{ id: '', fileType: 'globals', rootDir, filePath: fnStr },
199198
log

packages/lexicon/core.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type Workflow = {
3535
// (gets applied to every configuration object)
3636
credentials?: Record<string, any>;
3737

38-
// a path to a file where functions are defined!
38+
// a path to a file where functions are defined
3939
globals?: string;
4040
};
4141

packages/runtime/src/execute/expression.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,12 @@ export default (
5252
const timeout = plan.options?.timeout ?? ctx.opts.defaultRunTimeoutMs;
5353

5454
// prepare global functions to be injected into execution context
55-
let funcs = {};
56-
if (plan.workflow?.globals)
57-
funcs = await prepareGlobals(plan.workflow.globals);
58-
const globals = { ...opts.globals, ...funcs };
55+
const globals = {
56+
...opts.globals,
57+
...(plan.workflow?.globals
58+
? await prepareGlobals(plan.workflow.globals)
59+
: {}),
60+
};
5961

6062
// Setup an execution context
6163
const context = buildContext(input, { ...opts, globals });
@@ -255,15 +257,14 @@ const prepareGlobals = async (
255257
): Promise<GlobalsModule> => {
256258
if (typeof source === 'string' && !!source.trim()) {
257259
const context = vm.createContext({ console: opts.logger });
258-
const funcs = await loadModule(source || '', {
260+
return await loadModule(source || '', {
259261
context,
260262
}).catch((e) => {
261263
// mostly syntax errors
262264
// repackage errors and throw
263-
e.message = `(inside globals) ${e.message}`;
265+
e.message = `[globals] ${e.message}`;
264266
throw e;
265267
});
266-
return funcs;
267268
}
268269
return {};
269270
};

0 commit comments

Comments
 (0)