@pkgr/es-modules
Version:
Union collections of es modules mappings for pkgs without or with incorrect `module` field
43 lines (40 loc) • 1.01 kB
JavaScript
;
const MODULE_DEFINITIONS = {
dayjs: {
target: "dayjs/esm",
exact: false
},
lodash: {
target: "lodash-es",
exact: false
}
};
const defEntries = Object.entries(MODULE_DEFINITIONS);
const entries = defEntries.reduce((acc, [module, definition]) => {
const { target, exact } = typeof definition === "string" ? { target: definition, exact: true } : definition;
acc.push({
find: module,
replacement: target
});
if (!exact) {
acc.push({
find: new RegExp("^" + module + "/(.*)$"),
replacement: target + "/$1"
});
}
return acc;
}, []);
const alias = defEntries.reduce(
(acc, [module, definition]) => {
const { target, exact } = typeof definition === "string" ? { target: definition, exact: true } : definition;
acc[
/* istanbul ignore next */
exact ? module + "$" : module
] = target;
return acc;
},
{}
);
exports.MODULE_DEFINITIONS = MODULE_DEFINITIONS;
exports.alias = alias;
exports.entries = entries;