@openfn/describe-package
Utility for inspecting and describing an arbitrary npm package.
Usage
There is a demo project available in examples/compiler-worker.
Inspecting a module
import { Pack, Project, describeDts } from "@openfn/describe-package";
const project = new Project();
const pack = await Pack.fromUnpkg("@openfn/language-common@2.0.0-rc1");
const packageOrDts = /(?:package.json)|(?:\.d\.ts$)/i;
if (!pack.types) {
throw new Error(
`No 'types' field found for ${pack.specifier}`
);
}
const files = await pack.getFiles(
pack.fileListing.filter((path) => packageOrDts.test(path))
);
project.addToFS(files);
project.createFile(files.get(pack.types), pack.types);
const operations = describeDts(project, pack.types);
Project
The Project
object is a wrapper around the Typescript compiler, providing
the necessary hooks to interact with code and module type definitions.
Workers
⛔ Not working currently.
const { startWorker } = await import("@openfn/describe-package/worker");
const worker = await startWorker();
const results = await worker.describeAdaptor("a .d.ts as a string");
Building
There are three scripts:
pnpm test
Runs the testspnpm run build
Cleans up dist
and builds for packaging for npm.pnpm run watch
Rebuilds on changes.
The Worker is built in two phases:
- Bundle up the worker which includes the TypeScript compiler.
- Compile the entrypoint, which injects the worker as a string.
By splitting this up we can produce a single file that can be used in the browser.