-
Notifications
You must be signed in to change notification settings - Fork 37
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
Does not get correct dependencies when mixing es6 and cjs import syntax #26
Comments
Hey @pcardune! Thanks for filing the issue! Out of curiosity, for what purpose are you using precinct? I can think of a few ways of approaching the mixed import case:
While I'm happy to make this lib more robust, I'd prefer to find a decent workaround until more folks request support for this use case. Thoughts? |
I'm actually not using precinct directly. I'm using madge to generate svg dependency graph images. I'm also thinking about using I will check out |
Unfortunately
instead of
so converting all the code would require a lot of manual work :( :( Here is an example of a file that I am working with: https://github.com/code-dot-org/code-dot-org/blob/staging/apps/src/applab/applab.js |
Thanks so much for the details @pcardune! I'll pull down that repo and use it as a performance testbed for the change to run both the commonjs and es6 detectives for CJS or ES6 files. I'll also continue to think through some alternative solutions. I'm a big fan of what code.org is doing, so I'm happy to work on a solution. I'll keep you posted on the progress; though I foresee it taking a couple of nights of work to land on a fully tested solution that achieves a lot of the goals I've mentioned earlier. @pahen any additional thoughts on a path forward that doesn't introduce performance regressions? |
Hmm, that was a tricky one. I suppose it would involve a lot of work and changes to support mixed import syntaxes @mrjoelkemp ? I'm afraid I can't think of any easy fix for this that doesn't introduce performance regressions :( |
FWIW, I would be willing to take performance regressions to make this work. Perhaps it would be possible to add an option that explicitly enables mixed import syntaxes, which third parties could then choose to enable/disable depending on their needs? |
Fair point @pcardune! The goal of precinct is zero configuration, but i like the opt-in perf regression for transitionary codebases. Will work on that and support the option all the way up to madge. |
@pcardune I added an option You can get this with a fresh install of madge, but I'll still bump precinct within dependency-tree. Thanks again for suggesting the feature. Let me know if you run into any issues. |
Can we get the same mixed imports functionality for TS? I'm in a codebase that's migrating from JS to TS, and we have some cases where we still need to use CJS. |
This previously caused some modules to not resolve because they were referenced using relative paths. Example: ``` src/ a.js b.js feature/ c.js ``` ```js // c.js require('../b'); ``` ```js // b.js require('./a'); ``` ```js // a.js console.log("hello"); ``` In this example, trying to get the dependencies for `src/feature/c.js` would partially fail because it was trying to look up `./a` relative to `src/feature/` instead of `src`. Closes dependentsgh-26
I'm working on a rather large code base that is slowly transitioning from es5 to es6. There are a lot of files that have mixed imports: i.e. both
require()
statements andimport
statements.node-precinct
does not correctly extract all the dependencies.For example, given the file:
only the
foo
dependency will be recognized.If you flip it around, and have a file like:
only the
bar
dependency will be recognized.So in otherwords, precinct use looks at the first syntax it encounters and uses that for the rest of the file, even though the file may have a mix of cjs and es6.
The text was updated successfully, but these errors were encountered: