-
Notifications
You must be signed in to change notification settings - Fork 48
Create an ESM build of this module #126
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
base: master
Are you sure you want to change the base?
Conversation
The old syntax is designed for CommonJS only. on-behalf-of: @Mermaid-Chart <[email protected]>
This allows us to avoid having a `cp ./src/**/*.d.ts` step, since TypeScript will now automatically create them for us.
Use `./node_modules/.bin/tsc` on Unix OSes that use `/` instead of `\`. This allows building the package on Linux/MacOS, as well as Windows.
a66be8e to
bd6ddcb
Compare
The `node buildpackage.js` script now creates a `./bin/esm` folder, which contains an ESM version of this package. I've disabled minification for this folder, since I don't think it's very useful, and it just makes the package larger. We use https://nodejs.org/api/packages.html#conditional-exports to automatically map files to the ESM version when appropriate. The ESM version will work with most bundlers. However, since it's missing file-extensions (e.g. it uses `export * from "./Client";` instead of `export * from "./Client.js";`), some stricter ESM programs will not yet work with it. Fixes: microsoft#109
bd6ddcb to
e1a8a25
Compare
|
@microsoft-github-policy-service agree [company="Mermaid Chart"] |
|
@microsoft-github-policy-service agree company="Mermaid Chart" |
|
any updates here? Still waiting for ESM support for Vite. for now referencing github:aloisklink/azure-devops-extension-api#2635bb031bb1870bf5de2c2ba31e858139543117 but I don't really want to keep doing that. |
|
Checking if any updates for this one. |
|
need this to work here too |
|
I also need this to work |
|
We are blocked on internal extension work because of lack of ESM support as well |
Create an ESM build of this module, so that it works with modern bundlers, such as Vite.
The
node buildpackage.jsscript now creates a./bin/esmfolder, which contains an ESM version of this package.I've disabled minification for this folder, since I don't think it's very useful, and it just makes the package larger.
The ESM version will work with most bundlers. However, since it's missing file-extensions (e.g. it uses
export * from "./Client";instead ofexport * from "./Client.js";), some stricter ESM programs will not yet work with it.Fixes: #109
Fixes: #29
Other changes in this PR
import Boards = require("../Boards/Boards");syntax, so I updated that toimport * as Boards from "../Boards/Boards";.src/Common/Context.d.tstosrc/Common/Context.ts, since that allows us to skip the# Copy declare files to binstep, astscwill automatically make a.d.tsfile for us.buildpackage.jsscript currently usesnode_modules\.bin\tscto call TypeScript, which doesn't work on my Unix machine. Instead, I've changed it to usepath.join("node_modules", ".bin", "tsc"), so that it should automatically use\on Windows, and/on Unix.package.json#exportsI've used https://nodejs.org/api/packages.html#conditional-exports in our
package.jsonfile to automatically map files to the ESM version when appropriate.It's pretty verbose, for backwards compatibility to support:
import {getClient} from 'azure-devops-extension-api/Common';import {getClient} from 'azure-devops-extension-api/Common/index';import {getClient} from 'azure-devops-extension-api/Common/index.js';A future breaking change can simplify this, if you're okay with dropping support for all of these imports.
Script I used to generate these
Testing
I've tested the
npm run buildscript on Linux only, I'd appreciate it if somebody would be able to test it on Windows to make sure it works there too!I've tested the ESM output of this on Vite.