fix(bundling): get workspace package prefix length correctly #20817 (#27092)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->
When there are workspace libraries with the following import paths:

```
@org/core
@org/core/db
@org/core/acme
```

They need to be sorted for the manifest such that matching finds the
most specific first.
The logic for this is currently based off whether an `*` exists, which
doesn't work when the paths are specific.


## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->
Try to use `*` first and fallback to `/` to determine package prefix
length.


## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #20817
This commit is contained in:
Colum Ferry 2024-07-24 15:26:39 +01:00 committed by GitHub
parent 31f9d9ef11
commit a8dc251cce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -288,7 +288,16 @@ module.exports = require('${mainFile}');
} }
function getPrefixLength(pattern: string): number { 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): { function getTsConfigCompilerPaths(context: ExecutorContext): {