Support for import path rewriting
See original GitHub issueI use paths
in tsconfig.json
and tsc
doesn’t transform import
paths automatically.
Basically, just need a way to intercept import
statements (using the programmatic API) so I can change where they are pointing.
Alternatively, this package could respect paths
in tsconfig.json
and do the mapping for me, which could be opt-in if that’s a concern.
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
dropbox/ts-transform-import-path-rewrite - GitHub
This is a TypeScript AST Transformer that allows you to rewrite import path in output JS & d.ts files accordingly. The primary use...
Read more >import-path-rewrite - npm search
Babel plugin to dynamically rewrite the path in require() and ES6 import ... Rewrite TypeScript import paths to ES Modules import paths.
Read more >Rewriting import paths? - Google Groups
I'm currently in the process of importing some dependencies in to a local revision control server. That means I'll be needing to rewrite...
Read more >How to automatically rewrite relative import paths to absolute?
To be clear, the imports work as it is. I just need to rewrite all imports in the existing codebase automatically. – Henning...
Read more >"module": "node16" should support extension rewriting - Reddit
Well, the ESM specification requires imports to specify the full path, and it's my understanding Node will enforce this. So if TypeScript ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@igorpupkinable Sorry for late reply here.
The reason why this step makes the tool is working is that there are 2 “levels” of linking packages:
paths
, compiler-only “links”It looks like they are applying in opposite order, i.e.
paths
are first, then fs symlinks. By removingpaths
you let compiler to use fs symlinks and that’s why it is working.The original issue is the tool relies on fs path rather that import query (which obviously might be different across the project).
Relying on
paths
is kind of tricky, because if you’re usingpaths
it doesn’t mean that this folder (or a file) should be treated as an “external”. You could add one of your folders to thepaths
just to decrease level of exiting while writing a path in import statement ('../../../../../../../file'
vs'~root/file'
).Moreover, I’m not sure, but most likely ts compiler resolves a module’s name internally before accessing FS api (you said that enabling
disable-symlinks-following
doesn’t work, but all this flag does is preventing accessing FS to resolve a module path). Probably it should be handled inresolveModuleNames
to replace the file path with its request instead (but it might be tricky since it should be a path and ts could rely on it internally).Let me know if you’ll have any thoughts on it.
Just faced this issue in my monorepo. Having
"paths": { "@xxx/ui-core": ["../ui-core/src"], }
entry intsconfig.json
treats @xxx/ui-core as internal package thereby inlining its types even ifimportedLibraries: ['@xxx/ui-core']
is set.DTS is bundled properly if I remove
"paths": { "@xxx/ui-core": ["../ui-core/src"], }
fromtsconfig.json
. Unfortunately--disable-symlinks-following
does not help with TS paths.Does anyone have a solution for this issue?
Reproducible example: https://github.com/igorpupkinable/dts-bundle-generator-issues-50 Steps to reproduce:
lib/index.d.ts(10,35): error TS2304: Cannot find name 'ThisShouldNotBeInlined'.
paths
frompackages/fe-components/tsconfig.json
ThisShouldNotBeInlined
is imported as expected.@timocov please let me know if I can provide more information or where to start investigation.