Comments (9)
@pcardune I added an option es6.mixedImports
that will chain the es6 and cjs detectives. See the usage docs for the syntax.
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.
from node-precinct.
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.
from node-precinct.
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?
from node-precinct.
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:
- You could use Lebab's
commonjs
transform to turn CJS requires into ES6 imports https://github.com/lebab/lebab#safe-transforms. - I could look into extending detective-es6 with the functionality detective-cjs (since mixed codebases are likely until we have a proper es6 loader). This is hairy since I need to juggle a few things: preserving the separation of import concerns, avoiding double traversals of an ast, and finding a sane runtime extension point to combine the checks for es6 and cjs.
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?
from node-precinct.
I'm actually not using precinct directly. I'm using madge to generate svg dependency graph images. madge
uses dependency-tree
, which uses precinct
, which lead me to this repo :)
I'm also thinking about using dependency-tree
to power a linter that enforces rules about how modules in different directories can depend on each other.
I will check out lebab
and get back to you. I previously tried using some transforms for jscodeshift
to convert require()
calls, but alas, we have some nested require()
calls and the transform doesn't handle them properly :( :(. Hopefully lebab works better...
from node-precinct.
Unfortunately lebab
does not manage to figure out when to use
import * as foo from './foo-module'
instead of
import foo from './foo-module'
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
from node-precinct.
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 :(
from node-precinct.
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?
from node-precinct.
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.
from node-precinct.
Related Issues (20)
- Remove rewire
- Type Definitions missing HOT 3
- Please add support for precss HOT 1
- Webpack's `require.context` not being employed HOT 3
- require.resolve not being listed as a dependency HOT 2
- svelte-style html files HOT 3
- require.main.require not being parsed HOT 8
- detective-typescript uses an unsupported version of typescript HOT 1
- Allow fs to be passed in options (for paperwork)
- Dynamic imports javascript not being detected HOT 1
- Dynamic Imports in ES6 module without export are not detected HOT 4
- Keep a changelog (at least for breaking changes) HOT 1
- Update detective-typescript's parser HOT 1
- TypeScript file with a cast fails to find any dependencies HOT 2
- Missing `mixedImports` for TypeScript files HOT 1
- Support customizing options for walker HOT 2
- Export regular text instead of array in cli HOT 1
- bug
- Add recursive support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-precinct.