From 4af4923c363701a24b8d84b17f373e3cd10c2f97 Mon Sep 17 00:00:00 2001 From: Will Temple Date: Fri, 7 Jul 2023 13:17:15 -0400 Subject: [PATCH] [dev-tool] Honor exports when bundling. (#26432) This package modifies the bundling logic slightly so that after checking for a package.json `main` field it will also look at the package.json `exports["."].require` field. --- common/tools/dev-tool/src/commands/run/bundle.ts | 2 +- common/tools/dev-tool/src/util/resolveProject.ts | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/tools/dev-tool/src/commands/run/bundle.ts b/common/tools/dev-tool/src/commands/run/bundle.ts index 3e69039ccec8..8590470b173e 100644 --- a/common/tools/dev-tool/src/commands/run/bundle.ts +++ b/common/tools/dev-tool/src/commands/run/bundle.ts @@ -70,7 +70,7 @@ export default leafCommand(commandInfo, async (options) => { try { const bundle = await rollup.rollup(baseConfig); - const cjsOutput = info.packageJson.main; + const cjsOutput = info.packageJson.main ?? info.packageJson.exports?.["."]?.require; if (!cjsOutput) { throw new Error("Expecting valid main entry"); } diff --git a/common/tools/dev-tool/src/util/resolveProject.ts b/common/tools/dev-tool/src/util/resolveProject.ts index cbd2ad8418ed..7a094703d8d9 100644 --- a/common/tools/dev-tool/src/util/resolveProject.ts +++ b/common/tools/dev-tool/src/util/resolveProject.ts @@ -31,6 +31,14 @@ declare global { description: string; main: string; types: string; + exports?: { + [path: string]: { + import?: string; + require?: string; + types?: string; + [extraTypes: `types@${string}`]: string; + } + }, typesVersions?: { [k: string]: { [k: string]: string[];