Open v4lentin1879 opened 5 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.
@alexdima This repo is referenced in VSCode’s src/vs/loader.js
:
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.
@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.
@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 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.
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