@codacy/analysis-runner 0.8.1 → 0.9.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.d.ts +87 -4
- package/dist/index.js +196 -11
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -46,6 +46,9 @@ interface AnalyzeOptions {
|
|
|
46
46
|
gitScope?: "staged" | {
|
|
47
47
|
diff: string | true;
|
|
48
48
|
} | "pr";
|
|
49
|
+
/** Custom path to the Codacy configuration file. Absolute, or relative to
|
|
50
|
+
* `repositoryRoot`. Defaults to `.codacy/codacy.config.json`. */
|
|
51
|
+
configFile?: string;
|
|
49
52
|
/** Logger for pipeline progress messages (install status, etc.). Defaults to no-op. */
|
|
50
53
|
logger?: Logger;
|
|
51
54
|
/** Called when a tool starts executing. */
|
|
@@ -150,14 +153,39 @@ declare function formatTextSummary(result: AnalysisResult, isInspect?: boolean):
|
|
|
150
153
|
* 3. Default (empty patterns, no local config)
|
|
151
154
|
*/
|
|
152
155
|
|
|
156
|
+
/**
|
|
157
|
+
* Resolves the absolute path to the Codacy configuration file.
|
|
158
|
+
*
|
|
159
|
+
* A custom `configFile` (absolute, or relative to `repositoryRoot`) overrides the
|
|
160
|
+
* default `.codacy/codacy.config.json` location. This lets callers keep one config
|
|
161
|
+
* (e.g. synced from Codacy Cloud) while testing a variant side-by-side.
|
|
162
|
+
*/
|
|
163
|
+
declare function resolveConfigPath(repositoryRoot: string, configFile?: string): string;
|
|
153
164
|
/**
|
|
154
165
|
* Reads a CodacyConfig from disk.
|
|
155
166
|
* Returns null if the file doesn't exist. Throws on parse/permission errors
|
|
156
167
|
* so callers can distinguish "no config" from "broken config".
|
|
168
|
+
*
|
|
169
|
+
* Pass `configFile` to read from a non-default location.
|
|
170
|
+
*/
|
|
171
|
+
declare function readCodacyConfig(repositoryRoot: string, configFile?: string): Promise<CodacyConfig | null>;
|
|
172
|
+
/**
|
|
173
|
+
* Writes a CodacyConfig to disk at the exact resolved path, creating only the
|
|
174
|
+
* parent directory. Unlike {@link writeCodacyConfig}, this has NO `.codacy/`
|
|
175
|
+
* side effects, so it is safe to write to an arbitrary location (e.g. a scratch
|
|
176
|
+
* config a user is experimenting with).
|
|
177
|
+
*
|
|
178
|
+
* Pass `configFile` to write to a non-default location.
|
|
179
|
+
*/
|
|
180
|
+
declare function writeCodacyConfigFile(repositoryRoot: string, config: CodacyConfig, configFile?: string): Promise<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Writes a CodacyConfig to disk, creating the target directory if needed.
|
|
183
|
+
*
|
|
184
|
+
* Pass `configFile` to write to a non-default location. Regardless of where the
|
|
185
|
+
* main config lives, `.codacy/.gitignore` is always ensured so generated tool
|
|
186
|
+
* configs (which always land under `.codacy/generated/`) stay untracked.
|
|
157
187
|
*/
|
|
158
|
-
declare function
|
|
159
|
-
/** Writes a CodacyConfig to disk, creating the .codacy/ directory if needed. */
|
|
160
|
-
declare function writeCodacyConfig(repositoryRoot: string, config: CodacyConfig): Promise<string>;
|
|
188
|
+
declare function writeCodacyConfig(repositoryRoot: string, config: CodacyConfig, configFile?: string): Promise<string>;
|
|
161
189
|
/**
|
|
162
190
|
* Assembles a CodacyToolConfig from the global CodacyConfig and a local config check.
|
|
163
191
|
*
|
|
@@ -184,6 +212,61 @@ declare function createCodacyConfig(params?: {
|
|
|
184
212
|
autoFilters?: string;
|
|
185
213
|
}): CodacyConfig;
|
|
186
214
|
|
|
215
|
+
/**
|
|
216
|
+
* Set operations on Codacy configuration files.
|
|
217
|
+
*
|
|
218
|
+
* Three operations combine the *tools* and *patterns* of two CodacyConfigs:
|
|
219
|
+
* - `merge` — union of tools, and per-tool union of patterns
|
|
220
|
+
* - `intersect` — tools present in both, and per-tool patterns present in both
|
|
221
|
+
* - `diff` — `dest − source`: tools/patterns in dest that are NOT in source
|
|
222
|
+
*
|
|
223
|
+
* The result is always built from `dest` (its `version`, `metadata`, and
|
|
224
|
+
* top-level `exclude`/`includeFiles` are preserved; only `tools` and
|
|
225
|
+
* `metadata.updatedAt` change), because callers write the result back to the
|
|
226
|
+
* destination file. Inputs are never mutated.
|
|
227
|
+
*
|
|
228
|
+
* Rules that span the operations:
|
|
229
|
+
* - If either side uses a tool's native config file
|
|
230
|
+
* (`useLocalConfigurationFile === true`), the merged/intersected result for
|
|
231
|
+
* that tool also uses a config file (patterns dropped). The path comes from
|
|
232
|
+
* source when source uses the file, otherwise dest.
|
|
233
|
+
* - On `diff`, if the *destination* tool uses a config file and source also has
|
|
234
|
+
* that tool (with or without a config file), the tool is removed entirely — a
|
|
235
|
+
* config file's enabled rules are opaque, so it cannot be subtracted.
|
|
236
|
+
* - When a pattern exists on both sides during merge/intersect, its parameters
|
|
237
|
+
* are taken from source.
|
|
238
|
+
* - On `intersect`/`diff`, a tool left with no patterns and no config file is a
|
|
239
|
+
* no-op and is dropped from the result. `merge` always preserves its inputs.
|
|
240
|
+
*/
|
|
241
|
+
|
|
242
|
+
/** The set operation to apply between two configs. */
|
|
243
|
+
type ConfigOperation = "merge" | "intersect" | "diff";
|
|
244
|
+
/**
|
|
245
|
+
* Union of source and dest at the tool and pattern level.
|
|
246
|
+
* Tools present on only one side are carried over as-is; tools on both sides are
|
|
247
|
+
* combined (config-file rule, then per-tool pattern union with source parameters
|
|
248
|
+
* winning). Never drops tools.
|
|
249
|
+
*/
|
|
250
|
+
declare function mergeConfigs(source: CodacyConfig, dest: CodacyConfig): CodacyConfig;
|
|
251
|
+
/**
|
|
252
|
+
* Intersection of source and dest: only tools present in both, and per-tool only
|
|
253
|
+
* the patterns present in both (config-file rule applies when either side uses a
|
|
254
|
+
* config file). Tools left empty (no patterns, no config file) are dropped.
|
|
255
|
+
*/
|
|
256
|
+
declare function intersectConfigs(source: CodacyConfig, dest: CodacyConfig): CodacyConfig;
|
|
257
|
+
/**
|
|
258
|
+
* `dest − source`: keeps tools/patterns in dest that are not in source.
|
|
259
|
+
* - A tool only in dest is kept whole.
|
|
260
|
+
* - A dest tool that uses a config file and is also present in source is removed
|
|
261
|
+
* entirely (its enabled rules are opaque and cannot be subtracted).
|
|
262
|
+
* - Otherwise dest's inline patterns minus source's patterns are kept (a source
|
|
263
|
+
* tool using a config file enumerates no patterns, so all dest patterns survive).
|
|
264
|
+
* - Tools left empty after subtraction are dropped.
|
|
265
|
+
*/
|
|
266
|
+
declare function diffConfigs(source: CodacyConfig, dest: CodacyConfig): CodacyConfig;
|
|
267
|
+
/** Dispatches to the {@link mergeConfigs}, {@link intersectConfigs}, or {@link diffConfigs}. */
|
|
268
|
+
declare function applyConfigOperation(op: ConfigOperation, source: CodacyConfig, dest: CodacyConfig): CodacyConfig;
|
|
269
|
+
|
|
187
270
|
/**
|
|
188
271
|
* auto-filters.ts — Parses and applies --auto filter syntax.
|
|
189
272
|
*
|
|
@@ -590,4 +673,4 @@ interface DiscoverOptions {
|
|
|
590
673
|
*/
|
|
591
674
|
declare function discover(repositoryRoot: string, options?: DiscoverOptions): Promise<DiscoveryResult>;
|
|
592
675
|
|
|
593
|
-
export { type AdapterFactory, type AnalyzeOptions, type AutoFilters, type CategoryFilter, type CodacyYamlConfig, type CodacyYamlEngineConfig, type DiscoverOptions, type ExecutionMode, type IgnoredFilesResult, type InitAutoStats, type InitDefaultStats, type InitLocalStats, type InitRemoteStats, type LoggerOptions, type PatternMetadataLookup, type SeverityFilter, analyze, applyCodacyYamlExcludes, buildToolConfig, clearAdapters, computePatternSummary, configureApiToken, createCodacyConfig, createLogger, detectLanguages, discover, formatOutput, formatTextSummary, getAdapter, getRegisteredAdapters, getRegisteredDescriptors, initAutoConfig, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, parseAutoFilters, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, resolveEngineToAdapter, rotateLogFiles, validateApiToken, writeCodacyConfig };
|
|
676
|
+
export { type AdapterFactory, type AnalyzeOptions, type AutoFilters, type CategoryFilter, type CodacyYamlConfig, type CodacyYamlEngineConfig, type ConfigOperation, type DiscoverOptions, type ExecutionMode, type IgnoredFilesResult, type InitAutoStats, type InitDefaultStats, type InitLocalStats, type InitRemoteStats, type LoggerOptions, type PatternMetadataLookup, type SeverityFilter, analyze, applyCodacyYamlExcludes, applyConfigOperation, buildToolConfig, clearAdapters, computePatternSummary, configureApiToken, createCodacyConfig, createLogger, detectLanguages, diffConfigs, discover, formatOutput, formatTextSummary, getAdapter, getRegisteredAdapters, getRegisteredDescriptors, initAutoConfig, initContainerConfig, initDefaultConfig, initLocalConfig, initRemoteConfig, intersectConfigs, listDiffFiles, listIgnoredFiles, listPrFiles, listStagedFiles, mergeConfigs, parseAutoFilters, readCodacyConfig, readCodacyYaml, registerAdapter, registerLazyAdapter, resolveConfigPath, resolveEngineToAdapter, rotateLogFiles, validateApiToken, writeCodacyConfig, writeCodacyConfigFile };
|
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var index_exports = {};
|
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
analyze: () => analyze,
|
|
34
34
|
applyCodacyYamlExcludes: () => applyCodacyYamlExcludes,
|
|
35
|
+
applyConfigOperation: () => applyConfigOperation,
|
|
35
36
|
buildToolConfig: () => buildToolConfig,
|
|
36
37
|
clearAdapters: () => clearAdapters,
|
|
37
38
|
computePatternSummary: () => computePatternSummary,
|
|
@@ -39,6 +40,7 @@ __export(index_exports, {
|
|
|
39
40
|
createCodacyConfig: () => createCodacyConfig,
|
|
40
41
|
createLogger: () => createLogger,
|
|
41
42
|
detectLanguages: () => detectLanguages,
|
|
43
|
+
diffConfigs: () => diffConfigs,
|
|
42
44
|
discover: () => discover,
|
|
43
45
|
formatOutput: () => formatOutput,
|
|
44
46
|
formatTextSummary: () => formatTextSummary,
|
|
@@ -50,19 +52,23 @@ __export(index_exports, {
|
|
|
50
52
|
initDefaultConfig: () => initDefaultConfig,
|
|
51
53
|
initLocalConfig: () => initLocalConfig,
|
|
52
54
|
initRemoteConfig: () => initRemoteConfig,
|
|
55
|
+
intersectConfigs: () => intersectConfigs,
|
|
53
56
|
listDiffFiles: () => listDiffFiles,
|
|
54
57
|
listIgnoredFiles: () => listIgnoredFiles,
|
|
55
58
|
listPrFiles: () => listPrFiles,
|
|
56
59
|
listStagedFiles: () => listStagedFiles,
|
|
60
|
+
mergeConfigs: () => mergeConfigs,
|
|
57
61
|
parseAutoFilters: () => parseAutoFilters,
|
|
58
62
|
readCodacyConfig: () => readCodacyConfig,
|
|
59
63
|
readCodacyYaml: () => readCodacyYaml,
|
|
60
64
|
registerAdapter: () => registerAdapter,
|
|
61
65
|
registerLazyAdapter: () => registerLazyAdapter,
|
|
66
|
+
resolveConfigPath: () => resolveConfigPath,
|
|
62
67
|
resolveEngineToAdapter: () => resolveEngineToAdapter,
|
|
63
68
|
rotateLogFiles: () => rotateLogFiles,
|
|
64
69
|
validateApiToken: () => validateApiToken,
|
|
65
|
-
writeCodacyConfig: () => writeCodacyConfig
|
|
70
|
+
writeCodacyConfig: () => writeCodacyConfig,
|
|
71
|
+
writeCodacyConfigFile: () => writeCodacyConfigFile
|
|
66
72
|
});
|
|
67
73
|
module.exports = __toCommonJS(index_exports);
|
|
68
74
|
|
|
@@ -127,8 +133,11 @@ var import_promises = __toESM(require("fs/promises"));
|
|
|
127
133
|
var import_path = __toESM(require("path"));
|
|
128
134
|
var CODACY_DIR = ".codacy";
|
|
129
135
|
var CONFIG_FILE = "codacy.config.json";
|
|
130
|
-
|
|
131
|
-
|
|
136
|
+
function resolveConfigPath(repositoryRoot, configFile) {
|
|
137
|
+
return configFile ? import_path.default.resolve(repositoryRoot, configFile) : import_path.default.join(repositoryRoot, CODACY_DIR, CONFIG_FILE);
|
|
138
|
+
}
|
|
139
|
+
async function readCodacyConfig(repositoryRoot, configFile) {
|
|
140
|
+
const configPath = resolveConfigPath(repositoryRoot, configFile);
|
|
132
141
|
let raw;
|
|
133
142
|
try {
|
|
134
143
|
raw = await import_promises.default.readFile(configPath, "utf-8");
|
|
@@ -154,13 +163,17 @@ function coerceParameterValues(config) {
|
|
|
154
163
|
}
|
|
155
164
|
}
|
|
156
165
|
}
|
|
157
|
-
async function
|
|
166
|
+
async function writeCodacyConfigFile(repositoryRoot, config, configFile) {
|
|
167
|
+
const configPath = resolveConfigPath(repositoryRoot, configFile);
|
|
168
|
+
await import_promises.default.mkdir(import_path.default.dirname(configPath), { recursive: true });
|
|
169
|
+
await import_promises.default.writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
170
|
+
return configPath;
|
|
171
|
+
}
|
|
172
|
+
async function writeCodacyConfig(repositoryRoot, config, configFile) {
|
|
158
173
|
const codacyDir = import_path.default.join(repositoryRoot, CODACY_DIR);
|
|
159
174
|
await import_promises.default.mkdir(codacyDir, { recursive: true });
|
|
160
175
|
await ensureGitignore(codacyDir);
|
|
161
|
-
|
|
162
|
-
await import_promises.default.writeFile(configPath, JSON.stringify(config, null, 2) + "\n");
|
|
163
|
-
return configPath;
|
|
176
|
+
return writeCodacyConfigFile(repositoryRoot, config, configFile);
|
|
164
177
|
}
|
|
165
178
|
async function ensureGitignore(codacyDir) {
|
|
166
179
|
const gitignorePath = import_path.default.join(codacyDir, ".gitignore");
|
|
@@ -657,9 +670,10 @@ async function analyze(options) {
|
|
|
657
670
|
[]
|
|
658
671
|
);
|
|
659
672
|
}
|
|
673
|
+
const configLabel = options.configFile ?? ".codacy/codacy.config.json";
|
|
660
674
|
let codacyConfig;
|
|
661
675
|
try {
|
|
662
|
-
codacyConfig = await readCodacyConfig(options.repositoryRoot);
|
|
676
|
+
codacyConfig = await readCodacyConfig(options.repositoryRoot, options.configFile);
|
|
663
677
|
} catch (err) {
|
|
664
678
|
return buildResult(
|
|
665
679
|
startedAt,
|
|
@@ -672,7 +686,7 @@ async function analyze(options) {
|
|
|
672
686
|
toolId: "runner",
|
|
673
687
|
phase: "toolConfig",
|
|
674
688
|
kind: "InvalidConfig",
|
|
675
|
-
message:
|
|
689
|
+
message: `${configLabel} is invalid: ${err instanceof Error ? err.message : String(err)}`,
|
|
676
690
|
level: "error"
|
|
677
691
|
}
|
|
678
692
|
],
|
|
@@ -691,7 +705,7 @@ async function analyze(options) {
|
|
|
691
705
|
toolId: "runner",
|
|
692
706
|
phase: "toolConfig",
|
|
693
707
|
kind: "MissingConfig",
|
|
694
|
-
message:
|
|
708
|
+
message: `No ${configLabel} found. ` + (options.configFile ? `Run \`codacy-analysis init --config-file ${options.configFile}\` to initialize the repository.` : "Run `codacy-analysis init` to initialize the repository."),
|
|
695
709
|
level: "error"
|
|
696
710
|
}
|
|
697
711
|
],
|
|
@@ -1563,6 +1577,171 @@ function formatPatternSummary(summary) {
|
|
|
1563
1577
|
return lines.join("\n");
|
|
1564
1578
|
}
|
|
1565
1579
|
|
|
1580
|
+
// src/config-ops.ts
|
|
1581
|
+
function usesConfigFile(tool) {
|
|
1582
|
+
return tool.useLocalConfigurationFile === true;
|
|
1583
|
+
}
|
|
1584
|
+
function isEmptyTool(tool) {
|
|
1585
|
+
return !usesConfigFile(tool) && tool.patterns.length === 0;
|
|
1586
|
+
}
|
|
1587
|
+
function indexByToolId(tools) {
|
|
1588
|
+
return new Map(tools.map((t) => [t.toolId, t]));
|
|
1589
|
+
}
|
|
1590
|
+
function indexByPatternId(patterns) {
|
|
1591
|
+
return new Map(patterns.map((p) => [p.patternId, p]));
|
|
1592
|
+
}
|
|
1593
|
+
function unionList(dest, source) {
|
|
1594
|
+
const result = [.../* @__PURE__ */ new Set([...dest ?? [], ...source ?? []])];
|
|
1595
|
+
return result.length > 0 ? result : void 0;
|
|
1596
|
+
}
|
|
1597
|
+
function intersectList(dest, source) {
|
|
1598
|
+
if (!dest || !source) return void 0;
|
|
1599
|
+
const sourceSet = new Set(source);
|
|
1600
|
+
const result = dest.filter((x) => sourceSet.has(x));
|
|
1601
|
+
return result.length > 0 ? result : void 0;
|
|
1602
|
+
}
|
|
1603
|
+
function clonePattern(pattern) {
|
|
1604
|
+
const result = { patternId: pattern.patternId };
|
|
1605
|
+
if (pattern.parameters !== void 0) result.parameters = { ...pattern.parameters };
|
|
1606
|
+
return result;
|
|
1607
|
+
}
|
|
1608
|
+
function cloneTool(tool) {
|
|
1609
|
+
return structuredClone(tool);
|
|
1610
|
+
}
|
|
1611
|
+
function applyToolLevelLists(tool, source, dest, listFn) {
|
|
1612
|
+
const exclude = listFn(dest.exclude, source.exclude);
|
|
1613
|
+
if (exclude) tool.exclude = exclude;
|
|
1614
|
+
const extraFilePatterns = listFn(dest.extraFilePatterns, source.extraFilePatterns);
|
|
1615
|
+
if (extraFilePatterns) tool.extraFilePatterns = extraFilePatterns;
|
|
1616
|
+
}
|
|
1617
|
+
function buildConfigFileTool(toolId, source, dest, listFn) {
|
|
1618
|
+
const localConfigurationFile = (usesConfigFile(source) ? source.localConfigurationFile : void 0) ?? dest.localConfigurationFile;
|
|
1619
|
+
const tool = {
|
|
1620
|
+
toolId,
|
|
1621
|
+
...localConfigurationFile !== void 0 ? { localConfigurationFile } : {},
|
|
1622
|
+
useLocalConfigurationFile: true,
|
|
1623
|
+
patterns: []
|
|
1624
|
+
};
|
|
1625
|
+
applyToolLevelLists(tool, source, dest, listFn);
|
|
1626
|
+
return tool;
|
|
1627
|
+
}
|
|
1628
|
+
function mergePatterns(source, dest) {
|
|
1629
|
+
const sourceMap = indexByPatternId(source);
|
|
1630
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1631
|
+
const result = [];
|
|
1632
|
+
for (const dp of dest) {
|
|
1633
|
+
const sp = sourceMap.get(dp.patternId);
|
|
1634
|
+
result.push(clonePattern(sp ?? dp));
|
|
1635
|
+
seen.add(dp.patternId);
|
|
1636
|
+
}
|
|
1637
|
+
for (const sp of source) {
|
|
1638
|
+
if (!seen.has(sp.patternId)) result.push(clonePattern(sp));
|
|
1639
|
+
}
|
|
1640
|
+
return result;
|
|
1641
|
+
}
|
|
1642
|
+
function intersectPatterns(source, dest) {
|
|
1643
|
+
const sourceMap = indexByPatternId(source);
|
|
1644
|
+
const result = [];
|
|
1645
|
+
for (const dp of dest) {
|
|
1646
|
+
const sp = sourceMap.get(dp.patternId);
|
|
1647
|
+
if (sp) result.push(clonePattern(sp));
|
|
1648
|
+
}
|
|
1649
|
+
return result;
|
|
1650
|
+
}
|
|
1651
|
+
function diffPatterns(source, dest) {
|
|
1652
|
+
const sourceIds = new Set(source.map((p) => p.patternId));
|
|
1653
|
+
return dest.filter((dp) => !sourceIds.has(dp.patternId)).map(clonePattern);
|
|
1654
|
+
}
|
|
1655
|
+
function combineTool(op, toolId, source, dest) {
|
|
1656
|
+
const listFn = op === "merge" ? unionList : intersectList;
|
|
1657
|
+
if (usesConfigFile(source) || usesConfigFile(dest)) {
|
|
1658
|
+
return buildConfigFileTool(toolId, source, dest, listFn);
|
|
1659
|
+
}
|
|
1660
|
+
const patterns = op === "merge" ? mergePatterns(source.patterns, dest.patterns) : intersectPatterns(source.patterns, dest.patterns);
|
|
1661
|
+
const tool = { toolId, patterns };
|
|
1662
|
+
if (dest.useLocalConfigurationFile !== void 0) {
|
|
1663
|
+
tool.useLocalConfigurationFile = dest.useLocalConfigurationFile;
|
|
1664
|
+
} else if (source.useLocalConfigurationFile !== void 0) {
|
|
1665
|
+
tool.useLocalConfigurationFile = source.useLocalConfigurationFile;
|
|
1666
|
+
}
|
|
1667
|
+
applyToolLevelLists(tool, source, dest, listFn);
|
|
1668
|
+
return tool;
|
|
1669
|
+
}
|
|
1670
|
+
function buildResultConfig(dest, tools) {
|
|
1671
|
+
const result = {
|
|
1672
|
+
version: dest.version,
|
|
1673
|
+
metadata: { ...structuredClone(dest.metadata), updatedAt: (/* @__PURE__ */ new Date()).toISOString() },
|
|
1674
|
+
tools
|
|
1675
|
+
};
|
|
1676
|
+
if (dest.exclude !== void 0) result.exclude = structuredClone(dest.exclude);
|
|
1677
|
+
if (dest.includeFiles !== void 0) result.includeFiles = structuredClone(dest.includeFiles);
|
|
1678
|
+
return result;
|
|
1679
|
+
}
|
|
1680
|
+
function mergeConfigs(source, dest) {
|
|
1681
|
+
const sourceMap = indexByToolId(source.tools);
|
|
1682
|
+
const seen = /* @__PURE__ */ new Set();
|
|
1683
|
+
const tools = [];
|
|
1684
|
+
for (const d of dest.tools) {
|
|
1685
|
+
const s = sourceMap.get(d.toolId);
|
|
1686
|
+
tools.push(s ? combineTool("merge", d.toolId, s, d) : cloneTool(d));
|
|
1687
|
+
seen.add(d.toolId);
|
|
1688
|
+
}
|
|
1689
|
+
for (const s of source.tools) {
|
|
1690
|
+
if (!seen.has(s.toolId)) tools.push(cloneTool(s));
|
|
1691
|
+
}
|
|
1692
|
+
return buildResultConfig(dest, tools);
|
|
1693
|
+
}
|
|
1694
|
+
function intersectConfigs(source, dest) {
|
|
1695
|
+
const sourceMap = indexByToolId(source.tools);
|
|
1696
|
+
const tools = [];
|
|
1697
|
+
for (const d of dest.tools) {
|
|
1698
|
+
const s = sourceMap.get(d.toolId);
|
|
1699
|
+
if (!s) continue;
|
|
1700
|
+
const tool = combineTool("intersect", d.toolId, s, d);
|
|
1701
|
+
if (isEmptyTool(tool)) continue;
|
|
1702
|
+
tools.push(tool);
|
|
1703
|
+
}
|
|
1704
|
+
return buildResultConfig(dest, tools);
|
|
1705
|
+
}
|
|
1706
|
+
function diffConfigs(source, dest) {
|
|
1707
|
+
const sourceMap = indexByToolId(source.tools);
|
|
1708
|
+
const tools = [];
|
|
1709
|
+
for (const d of dest.tools) {
|
|
1710
|
+
const s = sourceMap.get(d.toolId);
|
|
1711
|
+
if (!s) {
|
|
1712
|
+
tools.push(cloneTool(d));
|
|
1713
|
+
continue;
|
|
1714
|
+
}
|
|
1715
|
+
if (usesConfigFile(d)) continue;
|
|
1716
|
+
const tool = {
|
|
1717
|
+
toolId: d.toolId,
|
|
1718
|
+
patterns: diffPatterns(s.patterns, d.patterns)
|
|
1719
|
+
};
|
|
1720
|
+
if (d.useLocalConfigurationFile !== void 0) {
|
|
1721
|
+
tool.useLocalConfigurationFile = d.useLocalConfigurationFile;
|
|
1722
|
+
}
|
|
1723
|
+
if (d.exclude !== void 0) tool.exclude = [...d.exclude];
|
|
1724
|
+
if (d.extraFilePatterns !== void 0) tool.extraFilePatterns = [...d.extraFilePatterns];
|
|
1725
|
+
if (isEmptyTool(tool)) continue;
|
|
1726
|
+
tools.push(tool);
|
|
1727
|
+
}
|
|
1728
|
+
return buildResultConfig(dest, tools);
|
|
1729
|
+
}
|
|
1730
|
+
function applyConfigOperation(op, source, dest) {
|
|
1731
|
+
switch (op) {
|
|
1732
|
+
case "merge":
|
|
1733
|
+
return mergeConfigs(source, dest);
|
|
1734
|
+
case "intersect":
|
|
1735
|
+
return intersectConfigs(source, dest);
|
|
1736
|
+
case "diff":
|
|
1737
|
+
return diffConfigs(source, dest);
|
|
1738
|
+
default: {
|
|
1739
|
+
const exhaustive = op;
|
|
1740
|
+
throw new Error(`Unknown config operation: ${String(exhaustive)}`);
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1566
1745
|
// src/init.ts
|
|
1567
1746
|
var import_promises4 = __toESM(require("fs/promises"));
|
|
1568
1747
|
var import_path7 = __toESM(require("path"));
|
|
@@ -6549,6 +6728,7 @@ function createLogger(options = {}) {
|
|
|
6549
6728
|
0 && (module.exports = {
|
|
6550
6729
|
analyze,
|
|
6551
6730
|
applyCodacyYamlExcludes,
|
|
6731
|
+
applyConfigOperation,
|
|
6552
6732
|
buildToolConfig,
|
|
6553
6733
|
clearAdapters,
|
|
6554
6734
|
computePatternSummary,
|
|
@@ -6556,6 +6736,7 @@ function createLogger(options = {}) {
|
|
|
6556
6736
|
createCodacyConfig,
|
|
6557
6737
|
createLogger,
|
|
6558
6738
|
detectLanguages,
|
|
6739
|
+
diffConfigs,
|
|
6559
6740
|
discover,
|
|
6560
6741
|
formatOutput,
|
|
6561
6742
|
formatTextSummary,
|
|
@@ -6567,17 +6748,21 @@ function createLogger(options = {}) {
|
|
|
6567
6748
|
initDefaultConfig,
|
|
6568
6749
|
initLocalConfig,
|
|
6569
6750
|
initRemoteConfig,
|
|
6751
|
+
intersectConfigs,
|
|
6570
6752
|
listDiffFiles,
|
|
6571
6753
|
listIgnoredFiles,
|
|
6572
6754
|
listPrFiles,
|
|
6573
6755
|
listStagedFiles,
|
|
6756
|
+
mergeConfigs,
|
|
6574
6757
|
parseAutoFilters,
|
|
6575
6758
|
readCodacyConfig,
|
|
6576
6759
|
readCodacyYaml,
|
|
6577
6760
|
registerAdapter,
|
|
6578
6761
|
registerLazyAdapter,
|
|
6762
|
+
resolveConfigPath,
|
|
6579
6763
|
resolveEngineToAdapter,
|
|
6580
6764
|
rotateLogFiles,
|
|
6581
6765
|
validateApiToken,
|
|
6582
|
-
writeCodacyConfig
|
|
6766
|
+
writeCodacyConfig,
|
|
6767
|
+
writeCodacyConfigFile
|
|
6583
6768
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codacy/analysis-runner",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Core orchestration engine for Codacy analysis",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
"cli-table3": "^0.6",
|
|
13
13
|
"minimatch": "10.2.4",
|
|
14
14
|
"yaml": "^2.6.0",
|
|
15
|
-
"@codacy/tooling": "0.
|
|
15
|
+
"@codacy/tooling": "0.9.0"
|
|
16
16
|
},
|
|
17
17
|
"devDependencies": {
|
|
18
18
|
"@codacy/openapi-typescript-codegen": "0.0.9",
|
|
19
|
-
"@codacy/tools-dummy-1": "0.
|
|
19
|
+
"@codacy/tools-dummy-1": "0.9.0"
|
|
20
20
|
},
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "Codacy <support@codacy.com> (https://www.codacy.com)",
|