Skip to content

Commit

Permalink
Fix and simplify config hints
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Oct 8, 2023
1 parent c6e0aab commit 1dbc024
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
2 changes: 1 addition & 1 deletion fixtures/workspaces-nested/package.json
Expand Up @@ -24,7 +24,7 @@
"unused-ignored-dep-global"
],
"ignoreWorkspaces": [
"ignored-workspace"
"unused-ignored-workspace"
],
"workspaces": {
".": {},
Expand Down
16 changes: 9 additions & 7 deletions src/DependencyDeputy.ts
Expand Up @@ -324,9 +324,10 @@ export class DependencyDeputy {
referencedDependencies?.forEach(pkg => pkg in rootIgnoreDependencies && rootIgnoreDependencies[pkg]++);
referencedBinaries?.forEach(binaryName => binaryName in rootIgnoreBinaries && rootIgnoreBinaries[binaryName]++);

const dependencies = this.isStrict
? this.getProductionDependencies(workspaceName)
: [...this.getProductionDependencies(workspaceName), ...this.getDevDependencies(workspaceName)];
const dependencies = [
...this.getProductionDependencies(workspaceName),
...this.getDevDependencies(workspaceName),
];
const peerDependencies = this.getPeerDependencies(workspaceName);

const isReferencedDep = (name: string) => referencedDependencies?.has(name) && dependencies.includes(name);
Expand All @@ -353,9 +354,10 @@ export class DependencyDeputy {
}

const installedBinaries = this.getInstalledBinaries(ROOT_WORKSPACE_NAME);
const dependencies = this.isStrict
? this.getProductionDependencies(ROOT_WORKSPACE_NAME)
: [...this.getProductionDependencies(ROOT_WORKSPACE_NAME), ...this.getDevDependencies(ROOT_WORKSPACE_NAME)];
const dependencies = [
...this.getProductionDependencies(ROOT_WORKSPACE_NAME),
...this.getDevDependencies(ROOT_WORKSPACE_NAME),
];
const peerDependencies = this.getPeerDependencies(ROOT_WORKSPACE_NAME);

// Add configuration hint for dependencies/binaries in global ignores or when referenced + listed
Expand All @@ -371,7 +373,7 @@ export class DependencyDeputy {
.filter(
key =>
IGNORED_DEPENDENCIES.includes(key) ||
(rootIgnoreDependencies[key] !== 0 && !peerDependencies.includes(key) && dependencies.includes(key))
(rootIgnoreDependencies[key] === 0 && !peerDependencies.includes(key) && !dependencies.includes(key))
)
.forEach(identifier =>
configurationHints.add({ workspaceName: ROOT_WORKSPACE_NAME, identifier, type: 'ignoreDependencies' })
Expand Down
4 changes: 2 additions & 2 deletions tests/workspaces-nested.test.ts
Expand Up @@ -8,8 +8,8 @@ import baseCounters from './helpers/baseCounters.js';
const cwd = resolve('fixtures/workspaces-nested');

const expectedConfigurationHints = new Set([
{ type: 'ignoreDependencies', workspaceName: '.', identifier: 'ignored-dep-global' },
{ type: 'ignoreWorkspaces', identifier: 'ignored-workspace' },
{ type: 'ignoreDependencies', workspaceName: '.', identifier: 'unused-ignored-dep-global' },
{ type: 'ignoreWorkspaces', identifier: 'unused-ignored-workspace' },
]);

test('Find unused dependencies in nested workspaces with default config in production mode (loose)', async () => {
Expand Down

0 comments on commit 1dbc024

Please sign in to comment.