Skip to content

Host uses getDirectories from System#3165

Merged
jakebailey merged 3 commits into
microsoft:v2from
edemaine:getDirectories
Jul 8, 2024
Merged

Host uses getDirectories from System#3165
jakebailey merged 3 commits into
microsoft:v2from
edemaine:getDirectories

Conversation

@edemaine

Copy link
Copy Markdown
Contributor

I found that a Host created from createVirtualCompilerHost/createVirtualTypeScriptEnvironment ignores the getDirectories provided by the System, despite getDirectories being a required component of System. Instead it forces a function that returns [] in all cases.

This is problematic for fs-based systems. The end result in my application is that TypeScript fails to preload all the types in node_modules/@types because it's unable to list that directory.

This one-line fix works for my application, and I added a somewhat realistic test (via existing jest definitions in node_modules/@types) that works only with this change.

Comment thread packages/typescript-vfs/src/index.ts
@jakebailey jakebailey added the deploy-preview Enables automatic deployments to preview environments on a PR label Jun 25, 2024
@jakebailey

Copy link
Copy Markdown
Member

The playground still works, though the test failures have shown the effect of this on twoslash; now it's falling back to the disk and we're getting more info, it seeems?

@edemaine

Copy link
Copy Markdown
Contributor Author

Yes, it seems it was getting extra documentation for console from @types/node. I think for repeatability independent of that library, it's best to add types: [] to avoid any of this reading. I've modified accordingly.

@github-actions

Copy link
Copy Markdown
Contributor

Azure Static Web Apps: Your stage site is ready! Visit it here: https://victorious-plant-05c166c10-3165.centralus.5.azurestaticapps.net

@edemaine

Copy link
Copy Markdown
Contributor Author

@jakebailey Let me know if there's anything I should do on this PR. Happy to make any changes you'd like!

@jakebailey

Copy link
Copy Markdown
Member

I think the main concern is breaking people who depended on this behavior (e.g. shiki?) but I serious doubt it's a problem.

@edemaine

edemaine commented Jul 2, 2024

Copy link
Copy Markdown
Contributor Author

Understood. FWIW, this shouldn't affect any browser uses; it's only in Node where additional type definitions would get picked up, which could break type checking but could be fixed with a types: [] specifier.

On the other hand, from our perspective (building our own CLI for typechecking in the style of tsc, but for another language), the current system is pretty broken. Of course, I could work around the issue by overriding the output, but this PR seems to bring expected behavior.

But I understand compatibility is a tricky issue; let me know if there's anything I can do to help investigate.

@jakebailey
jakebailey merged commit 441338c into microsoft:v2 Jul 8, 2024
@typescript-bot typescript-bot mentioned this pull request Jul 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deploy-preview Enables automatic deployments to preview environments on a PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants