Skip to content

Commit

Permalink
feat(init): adds question to enable detection of jsdoc imports (#970)
Browse files Browse the repository at this point in the history
## Description

- adds question to enable detection of jsdoc imports to the --init
command

## Motivation and Context

Improves discoverability 

## How Has This Been Tested?

- [x] green ci


## 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 authored Nov 30, 2024
1 parent 79e1aa1 commit fedead6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
9 changes: 9 additions & 0 deletions .dependency-cruiser-known-violations.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"type": "dependency",
"from": "src/cli/init-config/get-user-input.mjs",
"to": "src/extract/tsc/parse.mjs",
"rule": {
"severity": "error",
"name": "cli-to-main-only"
}
},
{
"type": "dependency",
"from": "test/utl/try-import.spec.mjs",
Expand Down
15 changes: 15 additions & 0 deletions src/cli/init-config/build-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ function buildTsPreCompilationDepsAttribute(pInitOptions) {
: "// tsPreCompilationDeps: false,";
}

/**
*
* @param {IInitConfig} pInitOptions
* @returns {string}
*/
function buildDetectJSDocumentImportsAttribute(pInitOptions) {
return pInitOptions.detectJSDocImports
? "detectJSDocImports: true,"
: "// detectJSDocImports: true,";
}

/**
* @param {IInitConfig} pInitOptions
* @returns {string}
Expand Down Expand Up @@ -168,6 +179,10 @@ export default function buildConfig(pInitOptions) {
extensionsToString(pInitOptions.resolutionExtensions),
)
.replace("{{notToTestRule}}", buildNotToTestRule(pInitOptions))
.replace(
"{{detectJSDocImportsAttribute}}",
buildDetectJSDocumentImportsAttribute(pInitOptions),
)
.replace(
"{{tsPreCompilationDepsAttribute}}",
buildTsPreCompilationDepsAttribute(pInitOptions),
Expand Down
4 changes: 2 additions & 2 deletions src/cli/init-config/config-template.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -229,15 +229,15 @@ module.exports = {
// moduleSystems: ['cjs', 'es6'],
/*
false: don't look at JSDoc imports
false: don't look at JSDoc imports (the default)
true: dependency-cruiser will detect dependencies in JSDoc-style
import statements. Implies "parser": "tsc", so the dependency-cruiser
will use the typescript parser for JavaScript files.
For this to work the typescript compiler will need to be installed in the
same spot as you're running dependency-cruiser from.
*/
// detectJSDocImports: true,
{{detectJSDocImportsAttribute}}
/* prefix for links in html and svg output (e.g. 'https://github.com/you/yourrepo/blob/main/'
to open it on your online repo or \`vscode://file/$\{process.cwd()}/\` to
Expand Down
7 changes: 7 additions & 0 deletions src/cli/init-config/get-user-input.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getWebpackConfigCandidates,
} from "./environment-helpers.mjs";
import { validateLocation } from "./validators.mjs";
import { isAvailable as tscIsAvailable } from "#extract/tsc/parse.mjs";

function toPromptChoice(pString) {
return {
Expand Down Expand Up @@ -108,6 +109,12 @@ const QUESTIONS = [
message: "Full path to your 'tsconfig.json",
choices: getTSConfigCandidates().map(toPromptChoice),
},
{
name: "detectJSDocImports",
type: () => (tscIsAvailable() ? "confirm" : false),
message: "Do you want to detect JSDoc imports as well (slower)?",
initial: false,
},
{
name: "tsPreCompilationDeps",
type: (_, pAnswers) => (pAnswers.useTsConfig ? "confirm" : false),
Expand Down
1 change: 1 addition & 0 deletions src/cli/init-config/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function getOneShotConfig(pOneShotConfigId) {
jsConfig: getJSConfigCandidates().shift(),
useTsConfig: hasTSConfigCandidates(),
tsConfig: getTSConfigCandidates().shift(),
detectJSDocImports: false,
tsPreCompilationDeps: hasTSConfigCandidates(),
useWebpackConfig: hasWebpackConfigCandidates(),
webpackConfig: getWebpackConfigCandidates().shift(),
Expand Down
4 changes: 4 additions & 0 deletions src/cli/init-config/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export interface IInitConfig {
* The file name of the TypeScript config to use
*/
tsConfig?: string;
/**
* Whether or not to detect JSDoc imports
*/
detectJSDocImports?: boolean;
/**
* Whether or not to take dependencies into account that only exist before
* compilation to javascript
Expand Down
5 changes: 0 additions & 5 deletions src/cli/init-config/write-run-scripts-to-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,6 @@ const EXPERIMENTAL_SCRIPT_DOC = [
EOL +
" to stdout - in simple text",
},
// {
// name: "depcruise:text",
// headline: "",
// description: "",
// },
];

/**
Expand Down

0 comments on commit fedead6

Please sign in to comment.