From 717d759abcdf4290402719546534c4c99f33071c Mon Sep 17 00:00:00 2001 From: Stan Lewis Date: Fri, 27 Sep 2024 07:58:35 -0400 Subject: [PATCH] fix(cli): avoid packing "binary" packages This change updates the export-dynamic-plugin command's default behavior to widen the check used to determine if an embedded dependency needs to be built. If an embedded dependency is outside of the yarn workspace and does not appear to be a source package (where "main" is a file ending in ".ts") then it will not be rebuilt during export-dynamic-plugin. This caters for cases such as a backend plugin doing a runtime import of an ESM module, the ESM module can be built and embedded into the dynamic plugin and be available on the package path at runtime. Signed-off-by: Stan Lewis --- .../export-dynamic-plugin/backend-embed-as-dependencies.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts index e853f30f93..e63498ac10 100644 --- a/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts +++ b/packages/cli/src/commands/export-dynamic-plugin/backend-embed-as-dependencies.ts @@ -504,6 +504,7 @@ async function searchEmbedded( let resolvedPackage: BackstagePackageJson | undefined; let resolvedPackageDir: string; + let alreadyPacked = false; if (relatedMonoRepoPackages.length === 1) { const monoRepoPackage = relatedMonoRepoPackages[0]; @@ -552,6 +553,7 @@ async function searchEmbedded( `Resolved package named '${dep}' at '${resolvedPackageDir}' doesn't satisfy dependency version requirement in parent package '${pkg.name}': '${resolvedPackage.version}', '${dependencyVersion}'.`, ); } + alreadyPacked = !resolvedPackage.main?.endsWith('.ts'); } if (resolvedPackage.bundled) { @@ -570,7 +572,7 @@ async function searchEmbedded( packageName: resolvedPackage.name, version: resolvedPackage.version ?? '0.0.0', parentPackageName: pkg.name, - alreadyPacked: resolvedPackage.main?.endsWith('.cjs.js') || false, + alreadyPacked, }); resolved.push(