Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request] Add documentation on how to use without the CLI interface #25

Closed
hydrosquall opened this issue Mar 7, 2020 · 4 comments

Comments

@hydrosquall
Copy link

hydrosquall commented Mar 7, 2020

Hi,

There's a project used by researchers which lets users provide a path to custom extensions, which sometimes contain non ES5 modules. However, these paths aren't known until runtime.

nextstrain/auspice#902

These paths are added here:

https://github.com/nextstrain/auspice/blob/2bd55502cb3b5dc94088a4ace3c377ba67f2d31f/webpack.config.js#L25-L33

I'd be interested in using this library to check those paths, and having the result added to the exclude used by babel-loader. It might be possible to do this already, but I wasn't sure how to do that just from skimming the README.

Thanks for any thoughts or advice!

@obahareth
Copy link
Owner

Hey @hydrosquall, so at the moment the behavior of this package is to either check dependencies defined in package.json, or you can pass a flag to check the entirety of the node_modules folder. I'm not sure if that serves your needs or not?

A nice (and a little bit cleaned up) example of usage can be taken from src/index.ts

import { getBabelLoaderIgnoreRegex } from './babel-loader-regex-builder'
import { ModulesChecker } from './modules-checker'
import IModuleCheckerConfig from './types/module-checker-config'

const config: IModuleCheckerConfig = {
  checkAllNodeModules: true,
  ignoreBabelAndWebpackPackages: true,
  logEs5Packages: true
}

// This should be a path to a directory containing both a 
// package.json file and node_modules directory
const path = "path/to/dir"

const checker = new ModulesChecker(path, config)
const nonEs5Dependencies = checker.checkModules()

console.log(getBabelLoaderIgnoreRegex(nonEs5Dependencies))

I'm not sure if this helps, let me know if it doesn't and I'll try to do my best to help out!

@hydrosquall
Copy link
Author

hydrosquall commented Mar 9, 2020

Hi @obahareth , this cleaned up code sample is very helpful for my original question, and will definitely be useful for ensuring cross-browser compatibility in a different project :).

I ended up closing my first attempt at a fix for this particular team, (nextstrain/auspice#928 (comment)) since the dependencies that were picked up were only relevant for the dev server, so they didn't need to be transpiled.

Is there a way to have the package check all the libraries that are imported given a particular entrypoint (e.g some src/index.js, rather than using node_modules or package.json)?

@obahareth
Copy link
Owner

Hi @hydrosquall, unfortunately that's not possible at the moment, but a pull request would be very welcome!

obahareth added a commit that referenced this issue May 11, 2020
In both #31 and #25 it's been requested to be able to use this package as a library instead of a CLI tool and this adds an example of how to do that in the README.

This resolves both #31 and #25.
@obahareth
Copy link
Owner

This has been fixed in #32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants