- Notifications
You must be signed in to change notification settings - Fork330
fix: correctly identify imports with resolution-mode (#582)#595
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Uh oh!
There was an error while loading.Please reload this page.
Conversation
| constvm=require("vm"); | ||
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(".*?"\)|".*?")\.|/g; | ||
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(".*?"(,\{assert:\{"resolution-mode":"(import|require)"\}\})?\)|".*?")\.|/g; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Hi@FoxxMD,
thank you for pointing in the right direction. I had to use a different regex when usingtypescript@22.14.0 andtypescript@5.8.3 withesm modules:
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(".*?"(,\{assert:\{"resolution-mode":"(import|require)"\}\})?\)|".*?")\.|/g; | |
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(.*?\)|".*?")\.|/g; |
I'm patching this line with the help ofpatch-package intotypescript-json-schema to make it working again.
@YousefED Thank you for this great package! I would like to politely ask if this regular expression could be updated to work with ESM packages.
edit:
as just discovered@puckey suggests this change:
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(".*?"(,\{assert:\{"resolution-mode":"(import|require)"\}\})?\)|".*?")\.|/g; | |
| constREGEX_FILE_NAME_OR_SPACE=/(\bimport\(".*?"(,[^)]+)?\)|".*?")\.|/g; |
Used fix provided by@jer-sen andcloses#582
Ibelieve this only occurs for ESM projects with
"moduleResolution": "NodeNext"intsconfig.jsonand introduced inTS 4.7. This fix is backwards compatible.