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.
Create an ESM build of this module, so that it works with modern bundlers, such as Vite.
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.
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.ts
tosrc/Common/Context.ts
, since that allows us to skip the# Copy declare files to bin
step, astsc
will automatically make a.d.ts
file for us.buildpackage.js
script currently usesnode_modules\.bin\tsc
to 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#exports
I've used https://nodejs.org/api/packages.html#conditional-exports in our
package.json
file 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 build
script 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.