@open-automaton/traverse-dependencies

0.0.3 • Public • Published

@open-automaton/traverse-dependencies

Sometimes you need to traverse the tree of dependencies to do some work, this lets you do that and can do it in a browser or on a server without compile

Usage

If you want to traverse the dependency graph and mutate the state:

import { traverse } from '@open-automaton/traverse-dependencies';
const result = await traverse('.', (pkg, state)=>{
    if(pkg.name === 'my-root-package-name'){
        return {
            ...(pkg.dependencies || {}),
            ...(pkg.devDependencies || {}),
            ...(pkg.peerDependencies || {})
        };
    }else{
        return {
            ...(pkg.dependencies || {}),
            ...(pkg.peerDependencies || {})
        };
    }
});

If you want to build an importmap from your node_modules directory, then:

import { 
    currentDirectoryImportMap 
} from '@open-automaton/traverse-dependencies';
const importMap = await currentDirectoryImportMap(
    'my-root-package-name'
);

Testing

Run the es module tests to test the root modules

npm run import-test

to run the same test inside the browser:

npm run browser-test

to run the same test headless in chrome:

npm run headless-browser-test

to run the same test inside docker:

npm run container-test

Run the commonjs tests against the /dist commonjs source (generated with the build-commonjs target).

npm run require-test

Development

All work is done in the .mjs files and will be transpiled on commit to commonjs and tested.

If the above tests pass, then attempt a commit which will generate .d.ts files alongside the src files and commonjs classes in dist

Readme

Keywords

none

Package Sidebar

Install

npm i @open-automaton/traverse-dependencies

Weekly Downloads

7

Version

0.0.3

License

MIT

Unpacked Size

35 kB

Total Files

15

Last publish

Collaborators

  • khrome