@openfn/cli 0.0.32 → 0.0.34

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
@@ -36,6 +36,14 @@ Get help:
36
36
  openfn help
37
37
  ```
38
38
 
39
+ ## Migrating from devtools
40
+
41
+ If you're coming to the CLI from the old openfn devtools, here are a couple of key points to be aware of:
42
+
43
+ * The CLI has a shorter, sleeker syntax, so your command should be much shorter
44
+ * The CLI will automatically install adaptors for you (with full version control)
45
+ * By default, the CLI will only write state.data to output. This is to encourage better state management. Pass `--no-strict-output` to save the entire state object.
46
+
39
47
  ## Basic Usage
40
48
 
41
49
  You're probably here to run jobs (expressions), which the CLI makes easy:
@@ -46,13 +54,13 @@ openfn path/to/job.js -ia adaptor-name
46
54
 
47
55
  You MUST specify which adaptor to use. Pass the `-i` flag to auto-install that adaptor (it's safe to do this redundantly).
48
56
 
49
- If output.json is not passed, the CLI will create an `output.json` next to the job file. You can pass a path to state by adding `-s path/to/state.json`, and output by passing `-o path/to/output.json`. You can use `-S` and `-O` to pass state through stdin and return the output through stdout.
57
+ When the job is finished, the CLI will write the `data` property of your state to disk. By default the CLI will create an `output.json` next to the job file. You can pass a path to output by passing `-o path/to/output.json` and state by adding `-s path/to/state.json`. You can use `-S` and `-O` to pass state through stdin and return the output through stdout. To write the entire state object (not just `data`), pass `--no-strict-output`.
50
58
 
51
- The CLI can auto-install language adaptors to its own privately maintained repo. Run `openfn repo list` to see where the repo is, and what's in it. Set the `OPENFN_REPO_DIR` env var to specify the repo folder. When autoinstalling, the CLI will check to see if a matching version is found in the repo.
59
+ The CLI can auto-install language adaptors to its own privately maintained repo, just include the `-i` flag in the command and your adaptors will be forever fully managed. Run `openfn repo list` to see where the repo is, and what's in it. Set the `OPENFN_REPO_DIR` env var to specify the repo folder. When autoinstalling, the CLI will check to see if a matching version is found in the repo.
52
60
 
53
61
  You can specify adaptors with a shorthand (`http`) or use the full package name (`@openfn/language-http`). You can add a specific version like `http@2.0.0`. You can pass a path to a locally installed adaptor like `http=/repo/openfn/adaptors/my-http-build`.
54
62
 
55
- If you have the adaptors monorepo set up on your machine, you can also run from that. Pass the `-m` flag to load from the monorepo. Set the monorepo location by setting the OPENFN_ADAPTORS_REPO env var to a valid path. This runs from the built package, so remember to build an adaptor before running!
63
+ If you have the adaptors monorepo set up on your machine, you can also run adaptors straight from source. Pass the `-m <path>` flag to load from the monorepo. You can also set the monorepo location by setting the `OPENFN_ADAPTORS_REPO` env var to a valid path. After that just include `-m` to load from the monorepo. Remember that adaptors will be loaded from the BUILT package in `dist`, so remember to build an adaptor before running!
56
64
 
57
65
  You can pass `--log info` to get more feedback about what's happening, or `--log debug` for more details than you could ever use.
58
66
 
@@ -119,9 +127,11 @@ The CLI uses openfn's own runtime to execute jobs in a safe environment.
119
127
 
120
128
  All jobs which work against `@openfn/core` will work in the new CLI and runtime environment (note: although this is a work in progress and we are actively looking for help to test this!).
121
129
 
130
+ If you want to see how the compiler is changing your job, run `openfn compile path/to/job -a <adaptor>` to return the compiled code to stdout. Add `-o path/to/output.js` to save the result to disk.
131
+
122
132
  ## New Runtime notes
123
133
 
124
- The new openfunction runtime basically does one thing: load a Javascript Module, find the default export, and execute the functions it holds.
134
+ The new OpenFn runtime will create a secure sandboxed environemtn which loads a Javascript Module, finds the default export, and execute the functions held within it.
125
135
 
126
136
  So long as your job has an array of functions as its default export, it will run in the new runtime.
127
137
 
package/dist/index.js CHANGED
@@ -180,6 +180,17 @@ var immutable = {
180
180
  default: false
181
181
  }
182
182
  };
183
+ var ignoreImports = {
184
+ name: "ignore-imports",
185
+ yargs: {
186
+ description: "Don't auto-import references in compiled code. Can take a list of names to ignore."
187
+ },
188
+ ensure: (opts2) => {
189
+ if (typeof opts2.ignoreImports === "string") {
190
+ opts2.ignoreImports = opts2.ignoreImports.split(",").map((s) => s.trim());
191
+ }
192
+ }
193
+ };
183
194
  var getBaseDir = (opts2) => {
184
195
  const basePath = opts2.path ?? ".";
185
196
  if (basePath.endsWith(".js")) {
@@ -313,6 +324,7 @@ var options = [
313
324
  autoinstall,
314
325
  compile,
315
326
  immutable,
327
+ ignoreImports,
316
328
  jobPath,
317
329
  logJson,
318
330
  outputPath,
@@ -327,7 +339,13 @@ var options = [
327
339
  ];
328
340
  var executeCommand = {
329
341
  command: "execute [path]",
330
- desc: `Run an openfn job. Get more help by running openfn <command> help`,
342
+ desc: `Run an openfn job. Get more help by running openfn <command> help.
343
+
344
+ Execute will run a job/expression and write the output state to disk (to ./state.json unless otherwise specified)
345
+
346
+ By default only state.data will be written to the output. Include --no-strict-output to write the entire state object.
347
+
348
+ Remember to include the adaptor name with -a. Auto install adaptors with the -i flag.`,
331
349
  aliases: ["$0"],
332
350
  handler: ensure("execute", options),
333
351
  builder: (yargs2) => build(options, yargs2).positional("path", {
@@ -335,13 +353,16 @@ var executeCommand = {
335
353
  demandOption: true
336
354
  }).example(
337
355
  "openfn foo/job.js",
338
- "Reads foo/job.js, looks for state and output in foo"
356
+ "Execute foo/job.js with no adaptor and write the final state to foo/job.json"
339
357
  ).example(
340
- "openfn job.js -a common",
341
- "Run job.js using @openfn/language-common"
358
+ "openfn job.js -ia common",
359
+ "Execute job.js using @openfn/language-commom , with autoinstall enabled)"
342
360
  ).example(
343
- "openfn install -a common",
344
- "Install the latest version of language-common to the repo"
361
+ "openfn job.js -a common --log info",
362
+ "Execute job.js with common adaptor and info-level logging"
363
+ ).example(
364
+ "openfn compile job.js -a http",
365
+ "Compile job.js with the http adaptor and print the code to stdout"
345
366
  )
346
367
  };
347
368
  var command_default = executeCommand;
@@ -350,12 +371,14 @@ var command_default = executeCommand;
350
371
  var options2 = [
351
372
  expandAdaptors,
352
373
  adaptors,
374
+ ignoreImports,
353
375
  jobPath,
354
376
  logJson,
355
377
  override(outputStdout, {
356
378
  default: true
357
379
  }),
358
380
  outputPath,
381
+ repoDir,
359
382
  useAdaptorsMonorepo
360
383
  ];
361
384
  var compileCommand = {
@@ -433,7 +456,8 @@ var command_default6 = {
433
456
  };
434
457
 
435
458
  // src/cli.ts
436
- var cmd = yargs(hideBin(process.argv)).command(command_default).command(command_default2).command(install).command(repo).command(command_default3).command(command_default5).command(command_default6).command(command_default4).option("log", {
459
+ var y = yargs(hideBin(process.argv));
460
+ var cmd = y.command(command_default).command(command_default2).command(install).command(repo).command(command_default3).command(command_default5).command(command_default6).command(command_default4).option("log", {
437
461
  alias: ["l"],
438
462
  description: "Set the default log level to none, default, info or debug",
439
463
  array: true
@@ -448,7 +472,7 @@ var cmd = yargs(hideBin(process.argv)).command(command_default).command(command_
448
472
  handler: (argv) => {
449
473
  argv.command = "version";
450
474
  }
451
- }).help();
475
+ }).wrap(y.terminalWidth()).help();
452
476
 
453
477
  // src/index.ts
454
478
  var opts = cmd.parse();
@@ -92,7 +92,6 @@ import { getModulePath } from "@openfn/runtime";
92
92
  var compile_default = async (opts, log) => {
93
93
  log.debug("Loading job...");
94
94
  const compilerOptions = await loadTransformOptions(opts, log);
95
- compilerOptions.logger = logger_default(COMPILER, opts);
96
95
  const job = compile(opts.jobSource || opts.jobPath, compilerOptions);
97
96
  if (opts.jobPath) {
98
97
  log.success(`Compiled job from ${opts.jobPath}`);
@@ -122,20 +121,17 @@ var resolveSpecifierPath = async (pattern, repoDir, log) => {
122
121
  };
123
122
  var loadTransformOptions = async (opts, log) => {
124
123
  const options = {
125
- logger: log
124
+ logger: log || logger_default(COMPILER, opts)
126
125
  };
127
- if (opts.adaptors?.length) {
126
+ if (opts.adaptors?.length && opts.ignoreImports != true) {
128
127
  let exports;
129
128
  const [pattern] = opts.adaptors;
130
129
  const [specifier] = pattern.split("=");
131
- log.debug(`Attempting to preload typedefs for ${specifier}`);
130
+ log.debug(`Attempting to preload types for ${specifier}`);
132
131
  const path5 = await resolveSpecifierPath(pattern, opts.repoDir, log);
133
132
  if (path5) {
134
133
  try {
135
- exports = await preloadAdaptorExports(path5);
136
- if (exports) {
137
- log.info(`Loaded typedefs for ${specifier}`);
138
- }
134
+ exports = await preloadAdaptorExports(path5, log);
139
135
  } catch (e) {
140
136
  log.error(`Failed to load adaptor typedefs from path ${path5}`);
141
137
  log.error(e);
@@ -145,6 +141,7 @@ var loadTransformOptions = async (opts, log) => {
145
141
  log.debug(`No module exports found for ${pattern}`);
146
142
  }
147
143
  options["add-imports"] = {
144
+ ignore: opts.ignoreImports,
148
145
  adaptor: {
149
146
  name: stripVersionSpecifier(specifier),
150
147
  exports,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfn/cli",
3
- "version": "0.0.32",
3
+ "version": "0.0.34",
4
4
  "description": "CLI devtools for the openfn toolchain.",
5
5
  "engines": {
6
6
  "node": ">=18",
@@ -41,10 +41,10 @@
41
41
  "rimraf": "^3.0.2",
42
42
  "treeify": "^1.1.0",
43
43
  "yargs": "^17.5.1",
44
- "@openfn/compiler": "0.0.26",
45
- "@openfn/describe-package": "0.0.14",
46
- "@openfn/logger": "0.0.11",
47
- "@openfn/runtime": "0.0.20"
44
+ "@openfn/compiler": "0.0.28",
45
+ "@openfn/describe-package": "0.0.15",
46
+ "@openfn/logger": "0.0.12",
47
+ "@openfn/runtime": "0.0.21"
48
48
  },
49
49
  "files": [
50
50
  "dist",