-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): prefer project specific external deps
- Loading branch information
1 parent
fd71b6b
commit fb21b87
Showing
5 changed files
with
245 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,19 @@ import { buildExplicitPackageJsonDependencies } from './explicit-package-json-de | |
import { CreateDependenciesContext } from '../../../../project-graph/plugins'; | ||
import { RawProjectGraphDependency } from '../../../../project-graph/project-graph-builder'; | ||
|
||
/** | ||
* When processing external dependencies, we need to keep track of which version of that dependency | ||
* is most appropriate for each source project. A workspace may contain multiple copies of a dependency | ||
* but we should base the graph on the version that is most relevant to the source project, otherwise | ||
* things like the dependency-check lint rule will not work as expected. | ||
* | ||
* We need to track this in this separate cache because the project file map that lives on the ctx will | ||
* only be updated at the very end. | ||
* | ||
* sourceProject => resolved external node names (e.g. 'npm:[email protected]') | ||
*/ | ||
export type ExternalDependenciesCache = Map<string, Set<string>>; | ||
|
||
export function buildExplicitDependencies( | ||
jsPluginConfig: { | ||
analyzeSourceFiles?: boolean; | ||
|
@@ -12,8 +25,23 @@ export function buildExplicitDependencies( | |
): RawProjectGraphDependency[] { | ||
if (totalNumberOfFilesToProcess(ctx) === 0) return []; | ||
|
||
const externalDependenciesCache: ExternalDependenciesCache = new Map(); | ||
let dependencies: RawProjectGraphDependency[] = []; | ||
|
||
/** | ||
* NOTE: It is important that we process package.json files first so that accurate versions for | ||
* external dependencies are captured in the ExternalDependenciesCache before converting | ||
* imports within TS files. | ||
*/ | ||
if ( | ||
jsPluginConfig.analyzePackageJson === undefined || | ||
jsPluginConfig.analyzePackageJson === true | ||
) { | ||
dependencies = dependencies.concat( | ||
buildExplicitPackageJsonDependencies(ctx, externalDependenciesCache) | ||
); | ||
} | ||
|
||
if ( | ||
jsPluginConfig.analyzeSourceFiles === undefined || | ||
jsPluginConfig.analyzeSourceFiles === true | ||
|
@@ -25,18 +53,10 @@ export function buildExplicitDependencies( | |
} catch {} | ||
if (tsExists) { | ||
dependencies = dependencies.concat( | ||
buildExplicitTypeScriptDependencies(ctx) | ||
buildExplicitTypeScriptDependencies(ctx, externalDependenciesCache) | ||
); | ||
} | ||
} | ||
if ( | ||
jsPluginConfig.analyzePackageJson === undefined || | ||
jsPluginConfig.analyzePackageJson === true | ||
) { | ||
dependencies = dependencies.concat( | ||
buildExplicitPackageJsonDependencies(ctx) | ||
); | ||
} | ||
|
||
return dependencies; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.