debian-mirror-gitlab/config/esbuild.config.js
2022-11-25 23:54:43 +05:30

59 lines
1.3 KiB
JavaScript

const browserslist = require('browserslist');
const esbuild = require('esbuild');
const ESBUILD_SUPPORTED_TARGETS = new Set([
'chrome',
'edge',
'firefox',
'hermes',
'ie',
'ios',
'node',
'opera',
'rhino',
'safari',
]);
const parseBrowserslist = (browserslistResult) => {
return browserslistResult.map((browsers) => {
const [family, version] = browsers.split(' ');
let normalizedVersion = version;
// browserslist can return a range: safari15.2-15.4
if (version.indexOf('-') >= -1) {
// we take the lowest version
[normalizedVersion] = version.split('-');
}
return {
family,
version: normalizedVersion,
};
});
};
const mapBrowserslistToESBuildTarget = (browsersList) => {
return parseBrowserslist(browsersList)
.filter(({ family, version }) => {
if (!ESBUILD_SUPPORTED_TARGETS.has(family)) {
console.warning('Unknown ESBuild target %s, version %s', family, version);
return false;
}
return true;
})
.map(({ family, version }) => {
return `${family}${version}`;
});
};
module.exports = {
target: mapBrowserslistToESBuildTarget(browserslist()),
supported: {
'optional-chain': false,
'nullish-coalescing': false,
'class-static-field': false,
'class-field': false,
},
implementation: esbuild,
};