@openfn/cli 1.12.0 → 1.13.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/README.md CHANGED
@@ -317,6 +317,7 @@ A workflow has a structure like this:
317
317
  {
318
318
  "workflow": {
319
319
  "name": "my-workflow", // human readable name used in logging
320
+ "globals": "./common-funcs.js", // code or path to functions that can be accessed in any step. globally scoped
320
321
  "steps": [
321
322
  {
322
323
  "name": "a", // human readable name used in logging
@@ -390,7 +390,10 @@ var list = async (options, logger) => {
390
390
  };
391
391
 
392
392
  // src/compile/compile.ts
393
- import compile, { preloadAdaptorExports } from "@openfn/compiler";
393
+ import compile, {
394
+ preloadAdaptorExports,
395
+ getExports
396
+ } from "@openfn/compiler";
394
397
  import { getModulePath } from "@openfn/runtime";
395
398
 
396
399
  // src/util/abort.ts
@@ -459,11 +462,13 @@ var compileJob = async (job, opts, log, jobName) => {
459
462
  }
460
463
  };
461
464
  var compileWorkflow = async (plan, opts, log) => {
465
+ let globalsIgnoreList = getExports(plan.workflow.globals);
462
466
  for (const step of plan.workflow.steps) {
463
467
  const job = step;
464
468
  const jobOpts = {
465
469
  ...opts,
466
- adaptors: job.adaptors ?? opts.adaptors
470
+ adaptors: job.adaptors ?? opts.adaptors,
471
+ ignoreImports: globalsIgnoreList
467
472
  };
468
473
  if (job.expression) {
469
474
  const { code, map } = await compileJob(
@@ -822,7 +827,8 @@ var loadExpression = async (options, logger) => {
822
827
  const plan = {
823
828
  workflow: {
824
829
  name,
825
- steps: [step]
830
+ steps: [step],
831
+ globals: options.globals
826
832
  },
827
833
  options: wfOptions
828
834
  };
@@ -854,7 +860,8 @@ var loadOldWorkflow = async (workflow, options, logger, defaultName = "") => {
854
860
  logger.warn(final);
855
861
  return final;
856
862
  };
857
- var fetchFile = async (jobId, rootDir = "", filePath, log) => {
863
+ var fetchFile = async (fileInfo, log) => {
864
+ const { rootDir = "", filePath, name } = fileInfo;
858
865
  try {
859
866
  const fullPath = filePath.startsWith("~") ? filePath : path4.resolve(rootDir, filePath);
860
867
  const result = await fs3.readFile(fullPath, "utf8");
@@ -863,7 +870,7 @@ var fetchFile = async (jobId, rootDir = "", filePath, log) => {
863
870
  } catch (e) {
864
871
  abort_default(
865
872
  log,
866
- `File not found for job ${jobId}: ${filePath}`,
873
+ `File not found for ${name}: ${filePath}`,
867
874
  void 0,
868
875
  `This workflow references a file which cannot be found at ${filePath}
869
876
 
@@ -872,6 +879,19 @@ Paths inside the workflow are relative to the workflow.json`
872
879
  return ".";
873
880
  }
874
881
  };
882
+ var importGlobals = async (plan, rootDir, log) => {
883
+ const fnStr = plan.workflow?.globals;
884
+ if (fnStr) {
885
+ if (isPath(fnStr)) {
886
+ plan.workflow.globals = await fetchFile(
887
+ { name: "globals", rootDir, filePath: fnStr },
888
+ log
889
+ );
890
+ } else {
891
+ plan.workflow.globals = fnStr;
892
+ }
893
+ }
894
+ };
875
895
  var importExpressions = async (plan, rootDir, log) => {
876
896
  let idx = 0;
877
897
  for (const step of plan.workflow.steps) {
@@ -885,26 +905,32 @@ var importExpressions = async (plan, rootDir, log) => {
885
905
  const stateStr = typeof job.state === "string" && job.state?.trim();
886
906
  if (expressionStr && isPath(expressionStr)) {
887
907
  job.expression = await fetchFile(
888
- job.id || `${idx}`,
889
- rootDir,
890
- expressionStr,
908
+ {
909
+ name: `job ${job.id || idx}`,
910
+ rootDir,
911
+ filePath: expressionStr
912
+ },
891
913
  log
892
914
  );
893
915
  }
894
916
  if (configurationStr && isPath(configurationStr)) {
895
917
  const configString = await fetchFile(
896
- job.id || `${idx}`,
897
- rootDir,
898
- configurationStr,
918
+ {
919
+ name: `job configuration ${job.id || idx}`,
920
+ rootDir,
921
+ filePath: configurationStr
922
+ },
899
923
  log
900
924
  );
901
925
  job.configuration = JSON.parse(configString);
902
926
  }
903
927
  if (stateStr && isPath(stateStr)) {
904
928
  const stateString = await fetchFile(
905
- job.id || `${idx}`,
906
- rootDir,
907
- stateStr,
929
+ {
930
+ name: `job state ${job.id || idx}`,
931
+ rootDir,
932
+ filePath: stateStr
933
+ },
908
934
  log
909
935
  );
910
936
  job.state = JSON.parse(stateString);
@@ -929,6 +955,9 @@ var loadXPlan = async (plan, options, logger, defaultName = "") => {
929
955
  plan.workflow.name = defaultName;
930
956
  }
931
957
  ensureAdaptors(plan);
958
+ if (options.globals)
959
+ plan.workflow.globals = options.globals;
960
+ await importGlobals(plan, options.baseDir, logger);
932
961
  await importExpressions(plan, options.baseDir, logger);
933
962
  if (options.expandAdaptors) {
934
963
  expand_adaptors_default(plan);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "CLI devtools for the openfn toolchain.",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -47,13 +47,13 @@
47
47
  "undici": "^7.1.0",
48
48
  "ws": "^8.18.0",
49
49
  "yargs": "^17.7.2",
50
- "@openfn/compiler": "1.0.4",
50
+ "@openfn/compiler": "1.1.0",
51
51
  "@openfn/describe-package": "0.1.4",
52
- "@openfn/deploy": "0.11.1",
52
+ "@openfn/deploy": "0.11.2",
53
53
  "@openfn/lexicon": "^1.2.2",
54
- "@openfn/project": "^0.1.0",
55
54
  "@openfn/logger": "1.0.5",
56
- "@openfn/runtime": "1.6.4"
55
+ "@openfn/project": "^0.1.0",
56
+ "@openfn/runtime": "1.7.0"
57
57
  },
58
58
  "files": [
59
59
  "dist",