Skip to content

Commit

Permalink
feat(init): adds exception to not-to-dev-dep for type-only dependenci…
Browse files Browse the repository at this point in the history
…es (#874)

## Description

- adds an exception to the `not-to-dev-dep` for type-only dependencies
to ones in `@types` folders (which are _pretty_ likely to be type only
as well, even when not explicitly imported as such)
- does the same for dependency-cruiser's own configuration

## Motivation and Context

Implements the second suggestion from #873 

## How Has This Been Tested?

- [x] green ci
- [x] manually against a TS repo

## Types of changes

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] Documentation only change
- [ ] Refactor (non-breaking change which fixes an issue without
changing functionality)
- [x] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
  • Loading branch information
sverweij committed Nov 24, 2023
1 parent 41e01de commit 8aa2a3d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
8 changes: 6 additions & 2 deletions .dependency-cruiser.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,14 @@
"name": "not-to-dev-dep",
"severity": "error",
"comment": "In production code do not depend on external ('npm') modules not declared in your package.json's dependencies - otherwise a production only install (i.e. 'npm ci') will break. If this rule triggers on something that's only used during development, adapt the 'from' of the rule in the dependency-cruiser configuration.",
"from": { "path": "^(bin|src)" },
"from": {
"pathNot": ["^test/", "^tools/"]
},
"to": {
"dependencyTypes": ["npm-dev"],
"exoticallyRequired": false
"exoticallyRequired": false,
"dependencyTypesNot": ["type-only"],
"pathNot": ["node_modules/@types/"]
}
},
{
Expand Down
10 changes: 9 additions & 1 deletion src/cli/init-config/config-template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,15 @@ module.exports = {
},
to: {
dependencyTypes: [
'npm-dev'
'npm-dev',
],
// type only dependencies are not a problem as they don't end up in the
// production code or are ignored by the runtime.
dependencyTypesNot: [
'type-only'
],
pathNot: [
'node_modules/@types/'
]
}
},
Expand Down
2 changes: 1 addition & 1 deletion types/extract-ts-config.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ParsedCommandLine } from "typescript";
import type { ParsedCommandLine } from "typescript";

/**
* Reads the file with name `pTSConfigFileName` and returns its parsed
Expand Down

0 comments on commit 8aa2a3d

Please sign in to comment.