Skip to content

Commit

Permalink
chore: emit helper/core-js exports to package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Jun 24, 2020
1 parent 6591114 commit e65c7a2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions packages/babel-plugin-transform-runtime/scripts/build-dist.js
Expand Up @@ -84,13 +84,44 @@ function writeCoreJS({
`module.exports = require("${corejsRoot}/${corejsPath}");`
);
});

writeCorejsExports(pkgDirname, runtimeRoot, paths);
}

function writeCorejsExports(pkgDirname, runtimeRoot, paths) {
const pkgJsonPath = require.resolve(`${pkgDirname}/package.json`);
const pkgJson = require(pkgJsonPath);
const exports = pkgJson.exports || {};
const exportEntries = new Set();
for (const corejsPath of paths) {
exportEntries.add(`./${path.dirname(path.join(runtimeRoot, corejsPath))}/`);
}
for (const entry of exportEntries) {
exports[entry] = entry;
}
pkgJson.exports = exports;
outputFile(pkgJsonPath, JSON.stringify(pkgJson, undefined, 2) + "\n");
}

function writeHelpers(runtimeName, { corejs } = {}) {
writeHelperFiles(runtimeName, { corejs, esm: false });
writeHelperFiles(runtimeName, { corejs, esm: true });
writeHelperExports(runtimeName);
}

function writeHelperExports(runtimeName) {
const pkgDirname = getRuntimeRoot(runtimeName);
const pkgJsonPath = require.resolve(`${pkgDirname}/package.json`);
const pkgJson = require(pkgJsonPath);
pkgJson.exports = {
"./": "./",
"./helpers/": "./helpers/",
"./helpers/esm/": "./helpers/esm/",
"./regenerator": "./regenerator/index.js",
"./regenerator/": "./regenerator/",
};
outputFile(pkgJsonPath, JSON.stringify(pkgJson, undefined, 2) + "\n");
}
function writeHelperFiles(runtimeName, { esm, corejs }) {
const pkgDirname = getRuntimeRoot(runtimeName);

Expand Down

0 comments on commit e65c7a2

Please sign in to comment.