cli: make migrate package-exports add ./package.json

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2023-01-17 23:32:20 +01:00
parent b5c1b48d17
commit 8a3d8ecde0
@@ -30,14 +30,31 @@ export async function command() {
await Promise.all(
packages.map(async ({ dir, packageJson }) => {
const { exports: exp } = packageJson;
if (!exp || typeof exp !== 'object' || Array.isArray(exp)) {
let { exports: exp } = packageJson;
if (!exp) {
return;
}
if (Array.isArray(exp)) {
throw new Error('Unexpected array in package.json exports field');
}
let changed = false;
let newPackageJson = packageJson;
// If exports is a string we rewrite it to an object to add package.json
if (typeof exp === 'string') {
changed = true;
exp = { '.': exp };
newPackageJson.exports = exp;
} else if (typeof exp !== 'object') {
return;
}
if (!exp['./package.json']) {
changed = true;
exp['./package.json'] = './package.json';
}
const existingTypesVersions = JSON.stringify(packageJson.typesVersions);
const typeEntries: Record<string, [string]> = {};