-
Notifications
You must be signed in to change notification settings - Fork 27.9k
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
ESM support for VSCode and extensions #212727
base: main
Are you sure you want to change the base?
Conversation
Thanks for this huge effort! Haven't had the chance to drill into code-details yet but based on your description it seems that you have found the right places and are making good decisions. In the alex/esm branch we do some things similar and some different. You have also covered extensions (which we haven't) and that's something I would like to learn from you. How to continue is a very good question. Reviewing such a huge, cross-cutting PR is a big challenge for us. Also #166033 exists. It hasn't gotten much attention but our effort is not abandoned. For instance, this milestone we are looking into decoupling NLS from module-loading (#212542). That's one of the big remaining items of the todo-list and also outlines our strategy: whenever possible we try to make changes in So, that would be my general recommendation (sorry, without having looked into details yet):
I don't wanna make false promises but I have the slight hope that the NLS-work and me finishing some AI-APIs frees me up next month to get back into this. From the top of my head, there is left
Thanks and Happy Coding |
We are heavy users and fans on I have been thinking about |
I think const enums can still be used with typescript isolated modules, one would not need to change all
Yes, I think that would be great, also! |
Haven't tried it but this sounds like they would raise a compile error: https://www.typescriptlang.org/tsconfig/#references-to-const-enum-members? |
I finished the all changes now for isolated modules, 7 files changed: #212913 I'm looking forward to feedback! :) |
And a Pull Request for esModuleInterop: #213014 |
Some more ideas what (perhaps) could be done in the Using script type moduleUsing Using worker type moduleSimilar to above, this would enable using Moving src/buildfile.js into the build folderWith the src files being ESM, I encountered some issues with the AMD Loader error with ESMWhen using the AMD loader with ESM, Feedback and ideas are as always very welcome! |
This PR adds ESM support for VSCode and extensions. Fixes #160416. Fixes #130367
Try Out
A sample ESM extension is located at
extensions/hello-esm
. Running the commandhello esm
displays a hello world notification:Feedback / Next Steps
It is probably too large to review and would be good to split up into smaller PRs! Before continuing it seems it would be good to gather some feedback from the VSCode team!
Changes
Type Imports
Some imports are changed from
import { IDisposable } from 'vs/base/common/lifecycle';
toimport type { IDisposable } from 'vs/base/common/lifecycle';
to work with ESM.Assert imports
Most of the changes in this PR are due to the
assert
import. In ESM, when usingimport * as assert from 'assert'
,assert
cannot be a function. The change isimport assert from 'assert'
Xterm imports
import { Terminal } from '@xterm/headless'
is changed to
This makes the import work in ESM. It seems it could even be changed back when
@xterm/headless
is published as ESM.Css Imports
import 'vs/css!./actionbar'
is compiled intoimportCss('./actionbar.css', import.meta.url)
. TheimportCss
function usesdocument.createElement('link')
to create a stylesheet foractionbar.css
.`
AmdX Loader
The amdx loader is changed from loading scripts with
document.createElement('script');
orimportScripts
to load scripts usingimport
.ESM extensions
To support ESM extensions, the extension host is started with a custom loader
NODE_OPTIONS:
--import="vscode/src/extension-loader-register.js"`.The loader can change how ESM files are imported, so that
import vscode from "vscode"
works as expected:When importing
vscode
, thisfake-vscode.js
file is imported instead:vscodeFakeApi
is created byextensionApiFactory()
and provides the vscode api propertieswindow
,commands
and more.NodeJS Docs for module customization hooks: https://nodejs.org/api/module.html#customization-hooks
Tests
To support ESM for electron integration tests, import maps and preload require are used.
It's a lot of changes for every imported module (
assert
,child_process
,cookie
,crypto
,electron
,events
,fs
,graceful-fs
,istanbul-lib-coverage
,istanbul-lib-instrument
and more) but it makes the tests work with ESM.Other
No ESM support for web extensions yet
Making use of NodeJS loader hooks, the ESM support only applies to NodeJS extensions. There would be no ESM support for web extensions yet.