From 8a3d8ecde05134782b5b9b4bf1c56a64d5495ee3 Mon Sep 17 00:00:00 2001 From: Patrik Oldsberg Date: Tue, 17 Jan 2023 23:32:20 +0100 Subject: [PATCH] cli: make migrate package-exports add ./package.json Signed-off-by: Patrik Oldsberg --- .../src/commands/migrate/packageExports.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/cli/src/commands/migrate/packageExports.ts b/packages/cli/src/commands/migrate/packageExports.ts index 754a25e32b..9d5c6d6339 100644 --- a/packages/cli/src/commands/migrate/packageExports.ts +++ b/packages/cli/src/commands/migrate/packageExports.ts @@ -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 = {};