Skip to content

Commit

Permalink
feat(extract): adds "pre-compilation-only" to the dependencyTypes as …
Browse files Browse the repository at this point in the history
…well, when detected (#892)

## Description

- when a dependency classifies as `preCompilationOnly: true` also add
`"pre-compilation-only"` to the `dependencyTypes` array for that
dependency
- in the default theme of the `dot` reporter 
- use the `dependencyTypes` array instead of the loose boolean
attributes
- also use the 'thin line' representation for things we can with high
likelihood
classify as pre-compilation only (type-only, type-import, tsd type
import)

## Motivation and Context

Consistency with other similar (derived or not) dependency types

## How Has This Been Tested?

- [x] green ci
- [x] updated automated non-regression tests

## 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 Dec 18, 2023
1 parent 7ddf2db commit 0278445
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 6 deletions.
1 change: 1 addition & 0 deletions doc/rules-reference.md
Expand Up @@ -963,6 +963,7 @@ dependency which resolves to a base url in a tsconfig.json you'll see `import`,
| triple-slash-file-reference | with a triple slash directive, specifically importing another module | `/// <reference path="./ts-thing" />` |
| triple-slash-type-reference | with a triple slash directive, specifically importing types | `/// <reference types="./ts-thing-types" />` |
| triple-slash-amd-dependency | with a triple slash directive, specifically declaring an AMD dependency | `/// <amd-dependency path="./ts-thing-types" />` |
| pre-compilation-only | but the dependency will disappear at runtime. See [preCompilationOnly](#preCompilationOnly) | `import { thing } from "./things"` // and continue to not use `thing` |

### `dynamic`

Expand Down
8 changes: 7 additions & 1 deletion src/extract/helpers.mjs
Expand Up @@ -16,7 +16,13 @@ export function detectPreCompilationNess(pTSDependencies, pJSDependencies) {
return pTSDependencies.map((pTSDependency) =>
pJSDependencies.some(dependenciesEqual(pTSDependency))
? { ...pTSDependency, preCompilationOnly: false }
: { ...pTSDependency, preCompilationOnly: true },
: {
...pTSDependency,
preCompilationOnly: true,
dependencyTypes: (pTSDependency.dependencyTypes || []).concat(
"pre-compilation-only",
),
},
);
}

Expand Down
13 changes: 10 additions & 3 deletions src/report/dot/default-theme.mjs
Expand Up @@ -128,15 +128,22 @@ export default {
attributes: { arrowhead: "normalnoneodot" },
},
{
criteria: { preCompilationOnly: true },
criteria: {
dependencyTypes: [
"pre-compilation-only",
"triple-slash-type-reference",
"type-import",
"type-only",
],
},
attributes: { arrowhead: "onormal", penwidth: "1.0" },
},
{
criteria: { coreModule: true },
criteria: { dependencyTypes: "core" },
attributes: { style: "dashed", penwidth: "1.0" },
},
{
criteria: { "dependencyTypes[0]": "npm" },
criteria: { dependencyTypes: "npm" },
attributes: { penwidth: "1.0" },
},
],
Expand Down
2 changes: 1 addition & 1 deletion test/extract/get-dependencies.odds-and-ends.spec.mjs
Expand Up @@ -250,7 +250,7 @@ describe("[I] extract/getDependencies - include", () => {
{
coreModule: false,
couldNotResolve: false,
dependencyTypes: ["local", "import"],
dependencyTypes: ["local", "import", "pre-compilation-only"],
dynamic: false,
followable: true,
exoticallyRequired: false,
Expand Down
9 changes: 8 additions & 1 deletion test/extract/helpers-detect-pre-compilation-ness.spec.mjs
Expand Up @@ -9,7 +9,14 @@ describe("[U] extract/helpers - detectPreCompilationNess", () => {
it("deps in the first not in the second get the isPreCompilationOnly attribute", () => {
deepEqual(
detectPreCompilationNess([{ module: "foo", moduleSystem: "es6" }], []),
[{ module: "foo", moduleSystem: "es6", preCompilationOnly: true }],
[
{
module: "foo",
moduleSystem: "es6",
preCompilationOnly: true,
dependencyTypes: ["pre-compilation-only"],
},
],
);
});

Expand Down
1 change: 1 addition & 0 deletions tools/schema/dependency-type.mjs
Expand Up @@ -29,6 +29,7 @@ export default {
"npm-peer",
"npm-unknown",
"npm",
"pre-compilation-only",
"require",
"triple-slash-amd-dependency",
"triple-slash-directive",
Expand Down
1 change: 1 addition & 0 deletions types/shared-types.d.mts
Expand Up @@ -61,6 +61,7 @@ export type DependencyType =
| "npm-peer"
| "npm-unknown"
| "npm"
| "pre-compilation-only"
| "require"
| "triple-slash-amd-dependency"
| "triple-slash-directive"
Expand Down

0 comments on commit 0278445

Please sign in to comment.