Giter VIP home page Giter VIP logo

Comments (15)

KevinNovak avatar KevinNovak commented on June 18, 2024 5

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.

mschering avatar mschering commented on June 18, 2024 4

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.

KevinNovak avatar KevinNovak commented on June 18, 2024 3

Still would be nice if this had ESM support

from barrelsby.

BitForger avatar BitForger commented on June 18, 2024 2

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.

alfonsoar avatar alfonsoar commented on June 18, 2024 2

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.

BitForger avatar BitForger commented on June 18, 2024 1

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.

bencoveney avatar bencoveney commented on June 18, 2024 1

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.

BitForger avatar BitForger commented on June 18, 2024 1

Work has been started here: https://github.com/bencoveney/barrelsby/tree/v3

from barrelsby.

github-actions avatar github-actions commented on June 18, 2024

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

from barrelsby.

github-actions avatar github-actions commented on June 18, 2024

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

from barrelsby.

BitForger avatar BitForger commented on June 18, 2024

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.

github-actions avatar github-actions commented on June 18, 2024

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

from barrelsby.

linonetwo avatar linonetwo commented on June 18, 2024

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.

github-actions avatar github-actions commented on June 18, 2024

No activity has been seen recently, marking as stale. If this is a mistake please reach out to a collaborator

from barrelsby.

phenomenal-hardy avatar phenomenal-hardy commented on June 18, 2024

please add ESM support, thanks

from barrelsby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.