microsoft / vscode-loader

An universal Asynchronous Module Definition (AMD) Loader developed primarily to load VSCode's sources.
Other
170 stars 55 forks source link

Add extension esm support #57

Open v4lentin1879 opened 5 months ago

v4lentin1879 commented 5 months ago

Currently, it is impossible to import ESM modules in a vscode extension as those require dynamic imports. This PR introduces the possibility of using dynamic imports in vscode. I'm looking forward to your feedback!

https://nodejs.org/api/vm.html#when-importmoduledynamically-is-a-function https://github.com/microsoft/vscode-loader/issues/36

alexdima commented 3 months ago

@v4lentin1879 Could you please help me understand how this PR helps with loading VS Code extensions? AFAIK extension code loading happens via nodejs' require here and does not involve the AMD loader.

NeatSketch commented 3 months ago

@alexdima This repo is referenced in VSCode’s src/vs/loader.js:

https://github.com/microsoft/vscode/blob/2811728ba106c9c2c47728fc862c00bf2d2fde84/src/vs/loader.js#L15

Please make sure to make edits in the .ts file at https://github.com/microsoft/vscode-loader/

Does that mean this repo is supposed to be updated before VSCode’s loader.js? I couldn’t find any explanation in VSCode’s documentation.

v4lentin1879 commented 3 months ago

@alexdima I am referring to the discussion in this thread: https://github.com/microsoft/vscode-loader/issues/36. The issue is that esm modules cannot be imported in a static way in commonjs. Since vscode is still based on commonjs, we have to make use of dynamic imports in extensions in order to use esm modules. This works perfectly fine in the development environment as there the vscode-loader is not used, yes. However, when packaging the extension, dynamic imports will stop to work because that's where the vscode-loader comes into play. My PR simply implements the importModuleDynamically option to enable dynamic imports.

alexdima commented 3 months ago

@v4lentin1879 Thank you for the extra context. We are working on supporting ESM, but we're taking a different approach. We will first move the core of VS Code from AMD to ESM, while maintaining that extensions load in commonjs. We have started exploring this 2 years ago, but are now in the final stretch of moving over thanks to excellent work from @jrieken and @bpasero . The VS Code core sources can currently be compiled to both AMD and ESM as we're preparing the final switch. Once we finish the VS Code core migration (will probably still take a couple milestones to iron all the wrinkles and get on par performance wise etc), we can begin looking at an easier path towards loading extensions as ESM.

We have exploration builds of VS Code which run as ESM if you'd like to try them out and help us discover issues:

VS Code Exploration Build links VS Code Build: e1db90f81da28c0994b5d50dc2b51e964359e62d cli-alpine-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_alpine_arm64_cli.tar.gz cli-alpine-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_alpine_x64_cli.tar.gz cli-darwin-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_darwin_arm64_cli.zip cli-darwin-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_darwin_x64_cli.zip cli-linux-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_linux_arm64_cli.tar.gz cli-linux-armhf: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_linux_armhf_cli.tar.gz cli-linux-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_linux_x64_cli.tar.gz cli-win32-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_win32_arm64_cli.zip cli-win32-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/vscode_cli_win32_x64_cli.zip darwin: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCode-darwin.zip darwin-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCode-darwin-arm64.zip darwin-universal: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCode-darwin-universal.zip linux-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-arm64-1724216611.tar.gz linux-armhf: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-armhf-1724216526.tar.gz linux-deb-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration_1.93.0-1724216689_arm64.deb linux-deb-armhf: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration_1.93.0-1724216600_armhf.deb linux-deb-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration_1.93.0-1724217479_amd64.deb linux-rpm-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-1.93.0-1724216777.el8.aarch64.rpm linux-rpm-armhf: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-1.93.0-1724216679.el8.armv7hl.rpm linux-rpm-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-1.93.0-1724217564.el8.x86_64.rpm linux-snap-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-x64-1724219617.snap linux-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/code-exploration-x64-1724216269.tar.gz win32-arm64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCodeSetup-arm64-1.93.0-exploration.exe win32-arm64-archive: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCode-win32-arm64-1.93.0-exploration.zip win32-arm64-user: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCodeUserSetup-arm64-1.93.0-exploration.exe win32-x64: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCodeSetup-x64-1.93.0-exploration.exe win32-x64-archive: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCode-win32-x64-1.93.0-exploration.zip win32-x64-user: https://vscode.download.prss.microsoft.com/dbazure/download/exploration/e1db90f81da28c0994b5d50dc2b51e964359e62d/VSCodeUserSetup-x64-1.93.0-exploration.exe
TomasHubelbauer commented 1 month ago

VS Code 1.94 now ships the ESM build in the stable channel: https://code.visualstudio.com/updates/v1_94#_esm-is-shipping-for-vs-code

I tested using ESM in extensiom code and that still appears to be unsupported, but hopefully VS Code now shipping ESM means this limitation will be lifted, soon.