-
Notifications
You must be signed in to change notification settings - Fork 29.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
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…nit/requestQueue.test.ts
…sueReporter-dev.html
Closing in favor of #166033. Parts of this PR have now been implemented in VSCode like isolatedModules and esModuleInterop. Additionally, the prototype for ESM extensions implemented here could maybe be used in the future as a starting point for proper ESM support in VSCode extensions (once the VSCode core supports ESM). Thanks! |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.