Skip to content

Commit

Permalink
clarify new field name
Browse files Browse the repository at this point in the history
  • Loading branch information
jmvtrinidad committed Mar 18, 2024
1 parent cf637cd commit 2938232
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 82 deletions.
2 changes: 1 addition & 1 deletion packages/nx-sonarqube/src/executors/scan/executor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ describe('Scan Executor', (): void => {
hostUrl: 'url',
projectKey: 'key',
qualityGate: true,
skipTypeDefs: [DependencyType.implicit],
skipDependencyTypes: ['implicit'],
},
context
);
Expand Down
2 changes: 1 addition & 1 deletion packages/nx-sonarqube/src/executors/scan/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export interface ScanExecutorSchema {
projectVersion?: string;
qualityGate?: boolean;
qualityGateTimeout?: string;
skipTypeDeps?: string[];
skipDependencyTypes?: Array<'implicit' | 'static' | 'dynamic'>;
skipProjects?: string[];
skipPaths?: string[];
testInclusions?: string;
Expand Down
9 changes: 6 additions & 3 deletions packages/nx-sonarqube/src/executors/scan/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
"type": "string",
"default": "300"
},
"skipTypeDeps": {
"description": "Skips adding implicit or dynamic dependencies to the project graph analysis",
"skipDependencyTypes": {
"type": "array",
"default": []
"items": {
"type": "string",
"enum": ["implicit", "static", "dynamic"]
},
"description": "Skips specified dependency types from the dependency graph. More info: https://nx.dev/nx-api/devkit/documents/DependencyType#enumeration-dependencytype"
},
"skipProjects": {
"description": "Skips projects to the project graph analysis",
Expand Down
170 changes: 93 additions & 77 deletions packages/nx-sonarqube/src/executors/scan/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,105 +84,121 @@ export async function determinePaths(
testTarget: projectConfiguration.targets.test,
});

deps.workspaceLibraries
.filter((project) =>
context.projectName === project.name || (options.skipPaths.length ? options.skipPaths.some(path => project.sourceRoot.includes(path)) : true)
const workspaceLibraries = deps.workspaceLibraries
.filter(
(project) =>
context.projectName === project.name ||
(options.skipPaths?.length
? options.skipPaths.some((path) => project.sourceRoot.includes(path))
: true)
)
.filter((project) =>
context.projectName === project.name || (options.skipProjects.length ? options.skipProjects.includes(project.name) : true)
.filter(
(project) =>
context.projectName === project.name ||
(options.skipProjects?.length
? options.skipProjects.includes(project.name)
: true)
)
.filter((project) =>
context.projectName === project.name || (options.skipTypeDeps.length ? options.skipTypeDeps.includes(project.type) : true)
)
.forEach((dep) => {
sources.push(dep.sourceRoot);
.filter((project) => {
if (
context.projectName === project.name ||
!options.skipDependencyTypes?.length
) {
return true;
}
return options.skipDependencyTypes.includes(
project.type as 'implicit' | 'static' | 'dynamic'
);
});
workspaceLibraries.forEach((dep) => {
sources.push(dep.sourceRoot);

if (dep.testTarget) {
const executor: Executor = getExecutor(dep.testTarget.executor);
const coverageDirectoryName: CoverageDirectoryName =
getCoverageDirectoryName(executor);
if (dep.testTarget) {
const executor: Executor = getExecutor(dep.testTarget.executor);
const coverageDirectoryName: CoverageDirectoryName =
getCoverageDirectoryName(executor);

if (dep.testTarget.options?.[coverageDirectoryName]) {
if (dep.testTarget.options?.[coverageDirectoryName]) {
lcovPaths.push(
joinPathFragments(
dep.testTarget.options[coverageDirectoryName]
.replace(new RegExp(/'/g), '')
.replace(/^(?:\.\.\/)+/, ''),
'lcov.info'
)
);
} else if (
executor === '@nx/jest:jest' &&
dep.testTarget.options?.jestConfig
) {
const jestConfigPath = dep.testTarget.options.jestConfig;
const jestConfig = readFileSync(jestConfigPath, 'utf-8');
const ast = tsquery.ast(jestConfig);
const nodes = tsquery(
ast,
'Identifier[name="coverageDirectory"] ~ StringLiteral',
{ visitAllChildren: true }
);

if (nodes.length) {
lcovPaths.push(
joinPathFragments(
dep.testTarget.options[coverageDirectoryName]
nodes[0]
.getText()
.replace(new RegExp(/'/g), '')
.replace(/^(?:\.\.\/)+/, ''),
'lcov.info'
)
);
} else if (
executor === '@nx/jest:jest' &&
dep.testTarget.options?.jestConfig
) {
const jestConfigPath = dep.testTarget.options.jestConfig;
const jestConfig = readFileSync(jestConfigPath, 'utf-8');
const ast = tsquery.ast(jestConfig);
const nodes = tsquery(
ast,
'Identifier[name="coverageDirectory"] ~ StringLiteral',
{ visitAllChildren: true }
} else {
logger.warn(
`Skipping ${dep.name} as it does not have a coverageDirectory in ${jestConfigPath}`
);
}
} else if (executor === '@nx/vite:test') {
const configPath: string | undefined = getViteConfigPath(
context.root,
dep
);

if (nodes.length) {
lcovPaths.push(
joinPathFragments(
nodes[0]
.getText()
.replace(new RegExp(/'/g), '')
.replace(/^(?:\.\.\/)+/, ''),
'lcov.info'
)
);
} else {
logger.warn(
`Skipping ${dep.name} as it does not have a coverageDirectory in ${jestConfigPath}`
);
}
} else if (executor === '@nx/vite:test') {
const configPath: string | undefined = getViteConfigPath(
context.root,
dep
if (configPath === undefined) {
logger.warn(
`Skipping ${dep.name} as we cannot find a vite config file`
);

if (configPath === undefined) {
logger.warn(
`Skipping ${dep.name} as we cannot find a vite config file`
);
return;
}

return;
}
const config = readFileSync(configPath, 'utf-8');
const ast = tsquery.ast(config);
const nodes = tsquery(
ast,
'Identifier[name="reportsDirectory"] ~ StringLiteral',
{ visitAllChildren: true }
);

const config = readFileSync(configPath, 'utf-8');
const ast = tsquery.ast(config);
const nodes = tsquery(
ast,
'Identifier[name="reportsDirectory"] ~ StringLiteral',
{ visitAllChildren: true }
if (nodes.length) {
lcovPaths.push(
joinPathFragments(
nodes[0]
.getText()
.replace(new RegExp(/'/g), '')
.replace(/^(?:\.\.\/)+/, ''),
'lcov.info'
)
);

if (nodes.length) {
lcovPaths.push(
joinPathFragments(
nodes[0]
.getText()
.replace(new RegExp(/'/g), '')
.replace(/^(?:\.\.\/)+/, ''),
'lcov.info'
)
);
} else {
logger.warn(
`Skipping ${dep.name} as it does not have a reportsDirectory in ${configPath}`
);
}
} else {
logger.warn(`Skipping ${dep.name} as it does not have a jestConfig`);
logger.warn(
`Skipping ${dep.name} as it does not have a reportsDirectory in ${configPath}`
);
}
} else {
logger.warn(`Skipping ${dep.name} as it does not have a test target`);
logger.warn(`Skipping ${dep.name} as it does not have a jestConfig`);
}
});
} else {
logger.warn(`Skipping ${dep.name} as it does not have a test target`);
}
});

return Promise.resolve({
lcovPaths: lcovPaths.join(','),
Expand Down

0 comments on commit 2938232

Please sign in to comment.