@repometry/core 0.1.0 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@repometry/core",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "The Repometry plugin API and inspection engine",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,7 +38,7 @@ function writeFinding(value, id, dimension) {
38
38
  }
39
39
  export function readStructure(value) {
40
40
  const { observations, ...fields } = value;
41
- return observations === undefined ? fields : { ...fields, observations: observations.map(({ rule, ...entry }) => ({ ...entry, check: rule })) };
41
+ return observations === undefined ? fields : { ...value, observations: observations.map(({ rule, ...entry }) => ({ ...entry, check: rule })) };
42
42
  }
43
43
  export function readFindings(value) {
44
44
  return { ...value, findings: value.findings.map(({ tool, rule, category, ...entry }) => ({ ...entry, plugin: tool, check: rule })) };
@@ -0,0 +1,3 @@
1
+ import type { PluginCategory } from '../model/inspection-category.js';
2
+ import type { Operation } from './plugin.js';
3
+ export declare function authorOperation(id: string, category: PluginCategory, operation: Operation): Operation;
@@ -0,0 +1,34 @@
1
+ import { readFindings, readStructure, writeFindings, writeStructure } from './author-contracts.js';
2
+ import { findingResult } from '../model/finding.js';
3
+ import { codeStructure, codeStructures } from '../model/code-structure.js';
4
+ export function authorOperation(id, category, operation) {
5
+ const { output } = operation;
6
+ const inputs = Object.fromEntries(Object.entries(operation.inputs).map(([port, contract]) => [port, storedContract(contract)]));
7
+ return { ...operation, inputs, output: storedContract(output), async execute(context) {
8
+ const result = await operation.execute({ ...context, read: (port, contract) => readValue(context, port, contract) });
9
+ return authorResult(id, category, output.id, result);
10
+ } };
11
+ }
12
+ function authorResult(id, category, output, result) {
13
+ if (output === findingResult.id)
14
+ return writeFindings(result, id, category);
15
+ if (output === codeStructure.id)
16
+ return writeStructure(result);
17
+ if (output === codeStructures.id && Array.isArray(result))
18
+ return result.map(writeStructure);
19
+ return result;
20
+ }
21
+ const stored = new Map([codeStructure, codeStructures, findingResult].map(contract => [contract.id, contract]));
22
+ function storedContract(contract) {
23
+ return stored.get(contract.id) ?? contract;
24
+ }
25
+ function readValue(inputs, port, contract) {
26
+ if (contract.id === codeStructure.id)
27
+ return readStructure(inputs.read(port, codeStructure));
28
+ if (contract.id === codeStructures.id)
29
+ return inputs.read(port, codeStructures).map(readStructure);
30
+ if (contract.id === findingResult.id)
31
+ return readFindings(inputs.read(port, findingResult));
32
+ return inputs.read(port, contract);
33
+ }
34
+ //# sourceMappingURL=author-operation.js.map
@@ -22,6 +22,7 @@ export interface PluginManifest<Options = JsonValue> {
22
22
  readonly include?: readonly string[];
23
23
  readonly exclude?: readonly string[];
24
24
  readonly languages?: readonly Language[];
25
+ readonly tools?: Readonly<Record<string, string>>;
25
26
  readonly optionsSchema?: boolean | Readonly<Record<string, unknown>>;
26
27
  readonly requires?: {
27
28
  readonly node?: string;
@@ -38,3 +39,4 @@ interface PluginOperations {
38
39
  readonly produces: readonly ProductOutput[];
39
40
  }
40
41
  export declare function pluginCategory(plugin: Plugin): PluginCategory;
42
+ export declare function manifestPlugin({ id, category, languages, optionsSchema, tools, checks }: Omit<PluginManifest, 'create'>, version: string): Omit<Plugin, 'operations' | 'produces' | 'settings'>;
@@ -1,7 +1,18 @@
1
1
  import { category } from '../model/inspection-category.js';
2
+ import { findingCategory } from './author-contracts.js';
3
+ import { pluginApi } from './plugin.js';
2
4
  export const pluginManifestSchema = 'urn:repometry:schema:plugin:1';
3
5
  export function pluginCategory(plugin) {
4
6
  const categories = [category.language, category.source, category.security, category.coverage];
5
7
  return categories.find(value => plugin.kinds.includes(value)) ?? category.maintainability;
6
8
  }
9
+ const kindsByCategory = {
10
+ language: 'language', source: 'source', maintainability: 'analysis', coverage: 'coverage', security: 'security',
11
+ };
12
+ export function manifestPlugin({ id, category, languages, optionsSchema, tools, checks }, version) {
13
+ return { id, version, api: pluginApi, kinds: [kindsByCategory[category]], config: optionsSchema, tools,
14
+ ...(checks === undefined ? {} : { rules: checks.map(check => ({ ...check, category: findingCategory(category, check.defaults?.cost !== undefined) })) }),
15
+ ...(languages === undefined ? {} : { providesLanguages: languages.map(({ include, measures, ...language }) => ({ ...language, globs: include,
16
+ ...(measures === undefined ? {} : { measures: measures.map(measure => measure === 'checks' ? 'structuralRules' : measure) }) })) }) };
17
+ }
7
18
  //# sourceMappingURL=plugin-manifest.js.map
@@ -67,5 +67,7 @@ export interface Plugin {
67
67
  readonly kinds: readonly PluginKind[];
68
68
  readonly claims?: FileClaims;
69
69
  readonly providesLanguages?: readonly ProvidedLanguage[];
70
+ /** Publish parser selectors and display metadata only when a snapshot contains its files. */
71
+ readonly languageProvenanceRequiresSource?: true;
70
72
  readonly produces: readonly ProductDeclaration[];
71
73
  }
@@ -17,4 +17,5 @@ export declare const typescriptType: {
17
17
  };
18
18
  export declare const fileTypes: readonly FileType[];
19
19
  export declare function fileTypeId(path: string, fallback?: string): string;
20
+ export declare function canonicalFileTypeId(id: string): string;
20
21
  export {};
@@ -22,7 +22,7 @@ export const fileTypes = [
22
22
  { id: 'kotlin', label: 'Kotlin', color: '#a97bff', extensions: ['.kt', '.kts'] },
23
23
  { id: 'ruby', label: 'Ruby', color: '#701516', extensions: ['.rb'] },
24
24
  { id: 'php', label: 'PHP', color: '#4f5d95', extensions: ['.php'] },
25
- { id: 'c-sharp', label: 'C#', color: '#178600', extensions: ['.cs'] },
25
+ { id: 'csharp', label: 'C#', color: '#178600', extensions: ['.cs'] },
26
26
  { id: 'c', label: 'C', color: '#555555', extensions: ['.c', '.h'] },
27
27
  { id: 'cpp', label: 'C++', color: '#f34b7d', extensions: ['.cc', '.cpp', '.cxx', '.hpp', '.hh'] },
28
28
  { id: 'swift', label: 'Swift', color: '#f05138', extensions: ['.swift'] },
@@ -47,4 +47,7 @@ export function fileTypeId(path, fallback) {
47
47
  return exactNames.get(basename) ?? names.get(name) ?? names.get(name.split('.', 1)[0]) ?? extensions.get(extension)
48
48
  ?? fallback ?? (extension.slice(1) || 'other');
49
49
  }
50
+ export function canonicalFileTypeId(id) {
51
+ return id === 'c-sharp' ? 'csharp' : id;
52
+ }
50
53
  //# sourceMappingURL=file-types.js.map
@@ -13,6 +13,8 @@ export interface SourceFile {
13
13
  export type SourceLineRange = readonly [first: number, last: number];
14
14
  export declare function isMergedLineRanges(value: unknown): value is readonly SourceLineRange[];
15
15
  export declare const maxClaimedFileBytes: number;
16
+ /** How much of a file's start is searched for the NUL byte that marks it as binary. */
17
+ export declare const binaryProbeBytes = 8192;
16
18
  export declare function isClaimedText(bytes: Uint8Array): boolean;
17
19
  export interface InventoryFile {
18
20
  readonly path: string;
@@ -14,7 +14,9 @@ export function isMergedLineRanges(value) {
14
14
  return true;
15
15
  }
16
16
  export const maxClaimedFileBytes = 1024 * 1024;
17
+ /** How much of a file's start is searched for the NUL byte that marks it as binary. */
18
+ export const binaryProbeBytes = 8192;
17
19
  export function isClaimedText(bytes) {
18
- return bytes.byteLength <= maxClaimedFileBytes && !bytes.subarray(0, 8192).includes(0);
20
+ return bytes.byteLength <= maxClaimedFileBytes && !bytes.subarray(0, binaryProbeBytes).includes(0);
19
21
  }
20
22
  //# sourceMappingURL=source.js.map