Comments (15)
Any updates on this? I want to use barrelsby for my project but since I'm using ESM modules I need the ".js" extension added to the end of imports/exports.
from barrelsby.
I had the problem that the output was missing a .js extension. So I worked around by doing:
barrelsby --config barrelsby.json && sed -i .bak 's/";/.js";/' script/mybarrel.ts && rm script/mybarrel.ts.bak
The sed command replaces "; with .js";
Maybe this helps someone else too.
from barrelsby.
Still would be nice if this had ESM support
from barrelsby.
I think this is a good plan but I'd recommend a couple tweaks.
- Look for package.json in the directory that it's being run in
- If none found, assume commonjs mode
I see where you're coming from with stepping up to find a package.json but I'm not sure it's worth the effort to try to figure out how high and where to stop so that you don't get the tool running outside the intended scope of the CWD
I think until some of the major frameworks start moving to ESM we should assume commonjs since that'll be the most common use case for now. I'd use a flag like -E to enable ESM support.
from barrelsby.
I had the problem that the output was missing a .js extension. So I worked around by doing:
barrelsby --config barrelsby.json && sed -i .bak 's/";/.js";/' script/mybarrel.ts && rm script/mybarrel.ts.bak
The sed command replaces "; with .js";
Maybe this helps someone else too.
For those of you using single quotes:
sed -i.bak 's/\\x27;/.js\\x27;/' src/index.ts && rm src/index.ts.bak
from barrelsby.
Also, it seems that ESM support isn't ready to go mainstream yet unless everyone decides to shift off TypeScript.
https://www.infoworld.com/article/3637149/typescript-delays-esm-support-for-nodejs.html
from barrelsby.
Waiting for official support from TypeScript sounds like a good plan to me 👍
I think I understand your point regarding looking outside the CWD - It does feel a bit funny. For me I think it would be useful to double check exactly what checks the TypeScript compiler would be performing and under what circumstances.
If the TypeScript compiler will traverse all the way up the directory tree anyway, then I don't think its egregious for us to replicate that and do the same check, and copying whatever they do would give a more consistent solution.
I haven't had chance to run it through completely myself, but would like to:
- Follow the code path through in the TypeScript compiler and see if there's any checks or caveats we've missed. Looks like this is where the check originates from: program.getImpliedNodeFormatForFile().
- Sanity check with an experiment using a TypeScript compiler with the ESM feature support, and see if the compiler behaviour really will change depending on the presence/absence of the
package.json
at the root of my filesystem.
Supporting a flag to manually set the behaviour also sounds like a good idea 👍 The opening post could be amended to:
If --input-type is not provided, assume we are using CommonJS modules (until some point in the future if/when we can detect the module type automatically).
--input-type=commonjs will force Barrelsby to create CommonJS modules.
--input-type=module will force Barrelsby to create ES modules.
Unfortuntely -E
has already been used for a different arg but happy to bikeshed alternatives 😉
from barrelsby.
Work has been started here: https://github.com/bencoveney/barrelsby/tree/v3
from barrelsby.
No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator
from barrelsby.
No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator
from barrelsby.
Any updates on this? I want to use barrelsby for my project but since I'm using ESM modules I need the ".js" extension added to the end of imports/exports.
It's mostly ported in the v3 branch. I haven't been able to get it to run correctly and have been working on getting the integration tests working. I don't have a timeline for you. Sorry
from barrelsby.
No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator
from barrelsby.
I really need this to fix
Relative import paths need explicit file extensions in EcmaScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './errors/index.js'?ts(2835)
from barrelsby.
No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator
from barrelsby.
please add ESM support, thanks
from barrelsby.
Related Issues (20)
- barrelsby prints "[Function: configParser]" to the console HOT 2
- Multiple directories not working as expected HOT 2
- Recursive barrels with defaults incorrect create defaults HOT 1
- tree shaking? HOT 4
- Drop support for Node 12 HOT 5
- Use folders instead of index HOT 2
- Adding a --check flag for ci HOT 6
- Allow customisation of header comment HOT 5
- Allow extensions other than .ts HOT 9
- Check file annotation before deleting the index.ts
- .svelte files support HOT 1
- Issues with `-s filesystem` HOT 4
- Hello HOT 1
- Recommended way for skipping typescript declaration files? HOT 2
- Barrels files updated with wrong content on repetitive run if `noHeader` flag enabled
- Support | in regex HOT 2
- Tests are failing HOT 1
- --exportDefault generates default exports eventhough there are none HOT 1
- Migration to vs code 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 barrelsby.