pnp / vscode-viva

With the SharePoint Framework Toolkit extension, you can create and manage your SharePoint Framework solutions on your tenant. All actions you need to perform during the development flow are at your fingertips.
https://marketplace.visualstudio.com/items?itemName=m365pnp.viva-connections-toolkit
MIT License
34 stars 14 forks source link

🤦VS Code extensions do not support esm #114

Open Adam-it opened 8 months ago

Adam-it commented 8 months ago

🎯 Aim

The aim of this issue is to track the support of es modules in VS Code extensions. Issues with more info:

Currently using CLI for Microsoft 365 directly from PnP builds is not possible due to that, so for now as a temporary workaround the CLI dependency is added from a local version of the package which was reverted to common js https://github.com/Adam-it/cli-microsoft365/tree/cli-cjs

Malix-off commented 7 months ago

Yep, that's a serious disappointment. Did you try using vite?

Adam-it commented 7 months ago

Yep, that's a serious disappointment. Did you try using vite?

Not sure how would that help for a dependency that is not used in webview but in the extension itself 🤔. Do you have any example I could check 👍?

Malix-off commented 7 months ago

Not sure how would that help for a dependency that is not used in webview but in the extension itself 🤔. Do you have any example I could check 👍?

Yep, I use vite to bundle my VSCode extension It's WIP, but the bundling part works; it bundles from my typescript source written in ESNext to a CJS build Here is the source code: https://github.com/Malix-off/VSC-Extension-StashFlow/tree/dev

Adam-it commented 7 months ago

Awesome. I need to check it for sure 🤩. Will it work also if one of the dependencies I use is already build in esm? As this is actually the problem I'm having

Malix-off commented 7 months ago

Will it work also if one of the dependencies I use is already build in esm? As this is actually the problem I'm having

Yes, it's the main point of bundler, fixing the dumbass cjs vs esm fight and optimize code output with minification and circular resolution, and library imports with tree-shaking There is theoretically no reason vite couldn't fix your problem in one way or another, I believe

Adam-it commented 7 months ago

this is awesome. I need to do a deep dive on this in the coming weekend. Thanks @Malix-off for sharing. You Rock 🤩

Malix-off commented 7 months ago

You're welcome ❤️

estruyf commented 7 months ago

@Malix-off, it is a great tip, also started using Vite a while ago, but now stepping away from it again as Vite dropped CJS support in v5 and will be completely removed in v6.

More information: https://vitejs.dev/guide/migration.html#deprecate-cjs-node-api

I stumbled on this issue as I had some issues with types that were incorrectly referenced during the build and made the extension fail.

It would be better to look at esbuild or tsup to be future-proof.

Malix-off commented 7 months ago

Vite dropped CJS support in v5

Nope, they dropped their own CJS Node API, which is a good thing imho because it would be kind of a non-sense to use a bundler in a non-ESM environment anyway (actually I'm a bit surprised they released a CJS Node API in the first place)

It means that to use Vite, you would need to use their ESM API (thus, to develop in ESM rather than CJS (I personally very much recommend that no matter what)), but vite will still be available to output CJS

See https://github.com/Malix-off/VSC-Extension-StashFlow/blob/master/vite.config.ts as an exemple

Edit

  1. Okay, I see what you meant because when I tested configs, I stumbled upon the deprecation message. That's a false positive because vite takes "module": "cjs" (required for vscode extensions) of package.json as "developing in cjs" rather than "outputing cjs". To make it clear that we aren't using cjs, you just have to use the .mjs/.mts extension (docs) Oh and btw, thanks for that article, I noticed during my research that you were also the author of it lol
Malix-off commented 7 months ago

@estruyf @Adam-it ⬆️

Adam-it commented 4 weeks ago

related issues and PRs https://github.com/microsoft/vscode-loader/pull/57 https://github.com/microsoft/vscode-loader/issues/36 https://github.com/microsoft/vscode-loader/issues/56