-
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
Draft
SimonSiefke
wants to merge
817
commits into
microsoft:main
Choose a base branch
from
SimonSiefke:simon/esm
base: main
Could not load branches
Branch not found: {{ refName }}
Could not load tags
Nothing to show
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
…umentLink.test.ts
…dationProvider.ts
…moke/fixAll.test.ts
…moke/quickFix.test.ts
…moke/referencesCodeLens.test.ts
…/notebook.kernel.test.ts
@lppedd Thanks for the comment! I agree it would be very useful to have ESM support in web extensions also. The issue for web extensions - which I haven't been able to solve - are these imports: import * as vscode from 'vscode' The vscode import would need to be mapped to a file, for example It seems import maps for webworkers could solve this problem, once they are supported by browsers. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.