Skip to content

Commit

Permalink
fix(bundling): get workspace package prefix length correctly #20817 (#…
Browse files Browse the repository at this point in the history
…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

(cherry picked from commit a8dc251)
  • Loading branch information
Coly010 authored and FrozenPandaz committed Jul 24, 2024
1 parent f6a6ba7 commit 2b2ff86
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,16 @@ module.exports = 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): {
Expand Down

0 comments on commit 2b2ff86

Please sign in to comment.