obahareth/are-you-es5

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

Closed this issue · 4 comments

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!

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!

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)?

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

This has been fixed in #32.