import-runner

1.23.0 • Public • Published

👟 Import Runner

Low code control flow using dynamic imports

⚙️ Install

npm install import-runner

🏃 Run

Import runner provides a shorthand for executing complex control flows using dynamic imports:

import importRunner from "import-runner"

export default async (input: {
  someOption: boolean
}): Promise<any> => {
  return await importRunner({
    input,
    each: [
      import("./myFunction"),
      import("./thatFunction"),
      {
        all: [
          import("./otherFunction"),
          import("./andAnotherFunction"),
          {
            route: [
              import("./wowAnotherFunction"),
              import("./enoughFunction"),
            ],
          },
        ],
      },
    ],
  })
}

ℹ️ Import runner calls the default function of the dynamic import (export default)

ℹ️ If a function call returns an object, it is assigned to the final output (Object.assign)

Option Description
input Input object
all Concurrent execution
each Sequential execution
route Concurrent conditional execution (uses "or" on input types)

🤖 Low code

Wait a second! What is up with the any output of the importRunner call? Did I just lose all my types? How do the child functions know what their inputs will be?

Because we have a somewhat formal structure, we can programmatically parse importRunner calls and generate input and output types for the runner function and its component functions.

Example code to process source files with chokidar, eslint, prettier, file-replacer, and fs-extra:

import chokidar from "chokidar"
import { ESLint } from "eslint"
import fileReplacer from "file-replacer"
import fsExtra from "fs-extra"
import prettier from "prettier"
import sourceProcessor from "import-runner/dist/cjs/sourceProcessor"

chokidar.watch("./**/*.ts").on("change", (event, path) => {
  sourceProcessor({
    eslint: new ESLint({ fix: true }),
    fileReplacer,
    fsExtra,
    path,
    prettier,
    srcRootPath: __dirname,
  })
})

/import-runner/

    Package Sidebar

    Install

    npm i import-runner

    Weekly Downloads

    1

    Version

    1.23.0

    License

    MIT

    Unpacked Size

    295 kB

    Total Files

    254

    Last publish

    Collaborators

    • winton