From e143b1358009a5657eccdeb158d8bfd5dfaa7bdb Mon Sep 17 00:00:00 2001 From: Colum Ferry Date: Wed, 24 Jul 2024 14:49:22 +0100 Subject: [PATCH] fix(bundling): get workspace package prefix length correctly #20817 --- .../executors/esbuild/lib/build-esbuild-options.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts index 79c13fa14fc8d..26ec6f2f14c72 100644 --- a/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts +++ b/packages/esbuild/src/executors/esbuild/lib/build-esbuild-options.ts @@ -291,7 +291,16 @@ require('${mainFile}'); } function getPrefixLength(pattern: string): number { - return pattern.substring(0, pattern.indexOf('*')).length; + const prefixIfWildcard = pattern.substring(0, pattern.indexOf('*')).length; + const prefixWithoutWildcard = pattern.substring( + 0, + pattern.lastIndexOf('/') + ).length; + // if the pattern doesn't contain '*', then the length is always 0 + // This causes issues when there are sub packages such as + // @nx/core + // @nx/core/testing + return prefixIfWildcard || prefixWithoutWildcard; } function getTsConfigCompilerPaths(context: ExecutorContext): {