opencode-sonarqube 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +84 -15
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4284,14 +4284,17 @@ function getTestPatterns(languages) {
|
|
|
4284
4284
|
}
|
|
4285
4285
|
return patterns.join(",");
|
|
4286
4286
|
}
|
|
4287
|
-
var SOURCE_DIRECTORY_PATTERNS;
|
|
4287
|
+
var MONOREPO_PATTERNS, SOURCE_SUBDIR_PATTERNS, SOURCE_DIRECTORY_PATTERNS;
|
|
4288
4288
|
var init_patterns = __esm(() => {
|
|
4289
|
-
|
|
4289
|
+
MONOREPO_PATTERNS = [
|
|
4290
4290
|
"apps",
|
|
4291
4291
|
"packages",
|
|
4292
4292
|
"modules",
|
|
4293
4293
|
"services",
|
|
4294
|
-
"libs"
|
|
4294
|
+
"libs"
|
|
4295
|
+
];
|
|
4296
|
+
SOURCE_SUBDIR_PATTERNS = ["src", "source", "lib"];
|
|
4297
|
+
SOURCE_DIRECTORY_PATTERNS = [
|
|
4295
4298
|
"src",
|
|
4296
4299
|
"source",
|
|
4297
4300
|
"lib",
|
|
@@ -4404,19 +4407,83 @@ function detectLanguages(checks3) {
|
|
|
4404
4407
|
}
|
|
4405
4408
|
return languages.length > 0 ? languages : ["generic"];
|
|
4406
4409
|
}
|
|
4407
|
-
function
|
|
4408
|
-
|
|
4409
|
-
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
4410
|
+
function directoryExists(path) {
|
|
4411
|
+
try {
|
|
4412
|
+
return Bun.spawnSync(["test", "-d", path]).exitCode === 0;
|
|
4413
|
+
} catch {
|
|
4414
|
+
return false;
|
|
4415
|
+
}
|
|
4416
|
+
}
|
|
4417
|
+
function getSubdirectories(path) {
|
|
4418
|
+
try {
|
|
4419
|
+
const result = Bun.spawnSync(["ls", "-1", path]);
|
|
4420
|
+
if (result.exitCode !== 0)
|
|
4421
|
+
return [];
|
|
4422
|
+
const output = result.stdout.toString().trim();
|
|
4423
|
+
if (!output)
|
|
4424
|
+
return [];
|
|
4425
|
+
return output.split(`
|
|
4426
|
+
`).filter((name) => {
|
|
4427
|
+
if (name.startsWith("."))
|
|
4428
|
+
return false;
|
|
4429
|
+
if (name === "node_modules")
|
|
4430
|
+
return false;
|
|
4431
|
+
return directoryExists(`${path}/${name}`);
|
|
4432
|
+
});
|
|
4433
|
+
} catch {
|
|
4434
|
+
return [];
|
|
4435
|
+
}
|
|
4436
|
+
}
|
|
4437
|
+
function findSourcesInMonorepoContainer(directory, monoPattern) {
|
|
4438
|
+
const sources = [];
|
|
4439
|
+
const monoPath = `${directory}/${monoPattern}`;
|
|
4440
|
+
if (!directoryExists(monoPath))
|
|
4441
|
+
return sources;
|
|
4442
|
+
const subdirs = getSubdirectories(monoPath);
|
|
4443
|
+
let foundSrcSubdirs = false;
|
|
4444
|
+
for (const subdir of subdirs) {
|
|
4445
|
+
for (const srcPattern of SOURCE_SUBDIR_PATTERNS) {
|
|
4446
|
+
const srcPath = `${monoPattern}/${subdir}/${srcPattern}`;
|
|
4447
|
+
if (directoryExists(`${directory}/${srcPath}`)) {
|
|
4448
|
+
sources.push(srcPath);
|
|
4449
|
+
foundSrcSubdirs = true;
|
|
4414
4450
|
}
|
|
4415
|
-
}
|
|
4451
|
+
}
|
|
4452
|
+
}
|
|
4453
|
+
if (!foundSrcSubdirs && subdirs.length > 0) {
|
|
4454
|
+
for (const subdir of subdirs) {
|
|
4455
|
+
sources.push(`${monoPattern}/${subdir}`);
|
|
4456
|
+
}
|
|
4457
|
+
}
|
|
4458
|
+
return sources;
|
|
4459
|
+
}
|
|
4460
|
+
function detectMonorepoSources(directory) {
|
|
4461
|
+
const sources = [];
|
|
4462
|
+
for (const monoPattern of MONOREPO_PATTERNS) {
|
|
4463
|
+
const found = findSourcesInMonorepoContainer(directory, monoPattern);
|
|
4464
|
+
sources.push(...found);
|
|
4465
|
+
}
|
|
4466
|
+
return sources;
|
|
4467
|
+
}
|
|
4468
|
+
function detectStandardSources(directory) {
|
|
4469
|
+
const sources = [];
|
|
4470
|
+
for (const pattern of SOURCE_DIRECTORY_PATTERNS) {
|
|
4471
|
+
if (directoryExists(`${directory}/${pattern}`)) {
|
|
4472
|
+
sources.push(pattern);
|
|
4473
|
+
}
|
|
4474
|
+
}
|
|
4475
|
+
return sources;
|
|
4476
|
+
}
|
|
4477
|
+
function detectSourceDirectories(directory) {
|
|
4478
|
+
const monoSources = detectMonorepoSources(directory);
|
|
4479
|
+
if (monoSources.length > 0) {
|
|
4480
|
+
logger2.info("Detected monorepo source directories", { directories: monoSources });
|
|
4481
|
+
return monoSources.join(",");
|
|
4416
4482
|
}
|
|
4417
|
-
|
|
4418
|
-
|
|
4419
|
-
|
|
4483
|
+
const standardSources = detectStandardSources(directory);
|
|
4484
|
+
if (standardSources.length > 0) {
|
|
4485
|
+
logger2.info("Detected source directories", { directories: standardSources });
|
|
4486
|
+
return standardSources.join(",");
|
|
4420
4487
|
}
|
|
4421
4488
|
logger2.info("No common source directories found, scanning entire project");
|
|
4422
4489
|
return ".";
|
|
@@ -19851,6 +19918,7 @@ function createHandlerContext(config3, state, projectKey, directory) {
|
|
|
19851
19918
|
}
|
|
19852
19919
|
// src/tools/handlers/setup.ts
|
|
19853
19920
|
init_bootstrap();
|
|
19921
|
+
init_detection();
|
|
19854
19922
|
init_logger();
|
|
19855
19923
|
import { mkdir } from "node:fs/promises";
|
|
19856
19924
|
var logger8 = new Logger("sonarqube-handler-setup");
|
|
@@ -19866,10 +19934,11 @@ ${result.message}`;
|
|
|
19866
19934
|
const configExists = await Bun.file(configPath).exists();
|
|
19867
19935
|
if (!configExists) {
|
|
19868
19936
|
await mkdir(sonarqubeDir, { recursive: true });
|
|
19937
|
+
const detectedSources = detectSourceDirectories(directory);
|
|
19869
19938
|
const defaultConfig = {
|
|
19870
19939
|
level: config3.level || "enterprise",
|
|
19871
19940
|
autoAnalyze: true,
|
|
19872
|
-
sources: config3.sources ||
|
|
19941
|
+
sources: config3.sources || detectedSources,
|
|
19873
19942
|
newCodeDefinition: "previous_version"
|
|
19874
19943
|
};
|
|
19875
19944
|
await Bun.write(configPath, JSON.stringify(defaultConfig, null, 2));
|