Skip to content
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

Do you plan to support glob, alias & index imports? #1

Open
viT-1 opened this issue Dec 21, 2021 · 14 comments
Open

Do you plan to support glob, alias & index imports? #1

viT-1 opened this issue Dec 21, 2021 · 14 comments

Comments

@viT-1
Copy link

viT-1 commented Dec 21, 2021

For example: "fixpaths": "fix-esm-import-path dist/**/*.js"
or with file structure:

src/common.components/Greeter/index.js
src/common.components/GreeterUse/use.js 

GreeterUse/use.js has code with alias:
import * from '@common/Greeter'

@beenotung
Copy link
Owner

Thanks for the suggestion. The current design require a entry file to start the fixing.

I just known esm will/has support index import, will try to implement it.

I'm not sure if it worth to implement glob, you may use an index file as the entry file.
(And you may generate the index file with tools like gen-index)

@beenotung
Copy link
Owner

beenotung commented Dec 21, 2021

I seldom use alias import, but would be interested to implement it as well. PR is also welcomed :)

@viT-1
Copy link
Author

viT-1 commented Dec 23, 2021

In browser importmaps are not supported globs yet. That's why we forced to hardcode all aliased esm imports! =(

Node has new feature: subpath imports & patterns.

@viT-1
Copy link
Author

viT-1 commented Dec 23, 2021

For TypeScript I use tsconfig paths, and there no need for your module.
You can see my example project with esm for browser & SystemJS for browser support, also node (tsconfig) script run.

I'm looking solution for js-project only (without bundlers & their plugins, nodejs script utilites only).

@viT-1
Copy link
Author

viT-1 commented Dec 23, 2021

Also you can read my translated gist (original gist)

@beenotung
Copy link
Owner

Why would you need glob matching the files?

I'm thinking use case requiring that need to scan the js files that are not imported directly or indirectly by the entry file.
For lazy imported files whose path are constructed dynamically?

@viT-1
Copy link
Author

viT-1 commented Dec 24, 2021

Globs for matching alias-imports strings to solve them with mapping, like eslint does or webpack.

@beenotung
Copy link
Owner

I've encountered a use case that glob may help: when publishing a npm package that as multiple bin files, each file may need to be fixed.

@beenotung
Copy link
Owner

Workaround for above use case is to write an index js that imports each cli js files, then use this index js as the entry point for fix-esm-import-path to fix the files, but do not publish this index js, otherwise it will invoke all the cli. This is a sub-optimal solution.

I want to avoid direct support on glob to reduce the complexity. Maybe allow to use a directory as entry point will be enough for most use case? e.g. fix-esm-import-path dist/esm

@beenotung
Copy link
Owner

Just published fix-esm-import-path@1.2.0 which allows using directory as entry point, it recursively scan and fix all js and ts files under the given directory.

Will look into tsconfig alias support

@viT-1
Copy link
Author

viT-1 commented Jan 11, 2022

For tsconfig alias you can investigate tsconfig-paths.
My example of usage tsconfig-paths (for node & eslint). But folders with index files & file extensions I still replace manually by node script.

@viT-1
Copy link
Author

viT-1 commented Jan 11, 2022

You can also see tsc-alias which generates relative paths
and my configuration for it.

@nicholasio
Copy link

@beenotung Thanks for this great package, do you plan on supporting index imports? Or would you be able to point in the direction for me look into adding support to it in the current codebase?

@beenotung
Copy link
Owner

@nicholasio index imports support is discussed in #11 and released in fix-esm-import-path@1.8.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants