@repometry/core 0.1.0 → 0.3.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 +1 -1
- package/target/main/ts/engine/author-contracts.js +1 -1
- package/target/main/ts/engine/author-operation.d.ts +3 -0
- package/target/main/ts/engine/author-operation.js +34 -0
- package/target/main/ts/engine/plugin-manifest.d.ts +20 -0
- package/target/main/ts/engine/plugin-manifest.js +19 -0
- package/target/main/ts/engine/plugin.d.ts +2 -0
- package/target/main/ts/engine/report-products.d.ts +2 -0
- package/target/main/ts/engine/report-products.js +18 -10
- package/target/main/ts/model/code-structure.d.ts +2 -0
- package/target/main/ts/model/code-structure.js +1 -1
- package/target/main/ts/model/file-type-syntax.d.ts +6 -0
- package/target/main/ts/model/file-type-syntax.js +50 -0
- package/target/main/ts/model/file-types.d.ts +1 -0
- package/target/main/ts/model/file-types.js +12 -6
- package/target/main/ts/model/source.d.ts +2 -0
- package/target/main/ts/model/source.js +3 -1
package/package.json
CHANGED
|
@@ -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 : { ...
|
|
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,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;
|
|
@@ -37,4 +38,23 @@ interface PluginOperations {
|
|
|
37
38
|
readonly operations: readonly Operation[];
|
|
38
39
|
readonly produces: readonly ProductOutput[];
|
|
39
40
|
}
|
|
41
|
+
export declare function manifestOperations({ id, category }: Pick<PluginManifest, 'id' | 'category'>, { operations, produces }: PluginOperations): {
|
|
42
|
+
operations: Operation[];
|
|
43
|
+
produces: ({
|
|
44
|
+
contract: string;
|
|
45
|
+
persistence: 'report' | 'cache' | 'transient';
|
|
46
|
+
metrics?: readonly import("./plugin.js").MetricDescriptor[];
|
|
47
|
+
} | {
|
|
48
|
+
contract: string;
|
|
49
|
+
persistence: 'report' | 'cache' | 'transient';
|
|
50
|
+
metrics?: readonly import("./plugin.js").MetricDescriptor[];
|
|
51
|
+
schema: boolean | Readonly<Record<string, unknown>>;
|
|
52
|
+
})[];
|
|
53
|
+
};
|
|
54
|
+
export type BundledManifest = PluginManifest & {
|
|
55
|
+
readonly version: string;
|
|
56
|
+
create(): PluginOperations;
|
|
57
|
+
};
|
|
58
|
+
export declare function bundledPlugin(manifest: BundledManifest): Plugin;
|
|
40
59
|
export declare function pluginCategory(plugin: Plugin): PluginCategory;
|
|
60
|
+
export declare function manifestPlugin({ id, category, languages, optionsSchema, tools, checks }: Omit<PluginManifest, 'create'>, version: string): Omit<Plugin, 'operations' | 'produces' | 'settings'>;
|
|
@@ -1,7 +1,26 @@
|
|
|
1
1
|
import { category } from '../model/inspection-category.js';
|
|
2
|
+
import { findingCategory } from './author-contracts.js';
|
|
3
|
+
import { authorOperation } from './author-operation.js';
|
|
4
|
+
import { pluginApi } from './plugin.js';
|
|
2
5
|
export const pluginManifestSchema = 'urn:repometry:schema:plugin:1';
|
|
6
|
+
export function manifestOperations({ id, category }, { operations, produces }) {
|
|
7
|
+
return { operations: operations.map(operation => authorOperation(id, category, operation)),
|
|
8
|
+
produces: produces.map(({ valueSchema, ...product }) => valueSchema === undefined ? product : { ...product, schema: valueSchema }) };
|
|
9
|
+
}
|
|
10
|
+
export function bundledPlugin(manifest) {
|
|
11
|
+
return { ...manifestPlugin(manifest, manifest.version), ...manifestOperations(manifest, manifest.create()) };
|
|
12
|
+
}
|
|
3
13
|
export function pluginCategory(plugin) {
|
|
4
14
|
const categories = [category.language, category.source, category.security, category.coverage];
|
|
5
15
|
return categories.find(value => plugin.kinds.includes(value)) ?? category.maintainability;
|
|
6
16
|
}
|
|
17
|
+
const kindsByCategory = {
|
|
18
|
+
language: 'language', source: 'source', maintainability: 'analysis', coverage: 'coverage', security: 'security',
|
|
19
|
+
};
|
|
20
|
+
export function manifestPlugin({ id, category, languages, optionsSchema, tools, checks }, version) {
|
|
21
|
+
return { id, version, api: pluginApi, kinds: [kindsByCategory[category]], config: optionsSchema, tools,
|
|
22
|
+
...(checks === undefined ? {} : { rules: checks.map(check => ({ ...check, category: findingCategory(category, check.defaults?.cost !== undefined) })) }),
|
|
23
|
+
...(languages === undefined ? {} : { providesLanguages: languages.map(({ include, measures, ...language }) => ({ ...language, globs: include,
|
|
24
|
+
...(measures === undefined ? {} : { measures: measures.map(measure => measure === 'checks' ? 'structuralRules' : measure) }) })) }) };
|
|
25
|
+
}
|
|
7
26
|
//# 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
|
}
|
|
@@ -5,12 +5,14 @@ import type { PlannedOperation } from './plan.js';
|
|
|
5
5
|
export declare class ReportProducts {
|
|
6
6
|
private readonly metrics;
|
|
7
7
|
private readonly measured;
|
|
8
|
+
private readonly alwaysReport;
|
|
8
9
|
private readonly privateMetrics;
|
|
9
10
|
private readonly products;
|
|
10
11
|
private readonly contracts;
|
|
11
12
|
private readonly rules;
|
|
12
13
|
private readonly declared;
|
|
13
14
|
constructor(plugins: readonly Plugin[]);
|
|
15
|
+
private registerMetric;
|
|
14
16
|
record(task: PlannedOperation, { contract, value }: Product, path?: string): FindingResult | undefined;
|
|
15
17
|
result(): PluginData | undefined;
|
|
16
18
|
}
|
|
@@ -6,6 +6,7 @@ import { isRecord } from './plugin.js';
|
|
|
6
6
|
export class ReportProducts {
|
|
7
7
|
metrics = new Map();
|
|
8
8
|
measured = new Set();
|
|
9
|
+
alwaysReport = new Set();
|
|
9
10
|
privateMetrics = new Set();
|
|
10
11
|
products = new Map();
|
|
11
12
|
contracts = new Map();
|
|
@@ -25,17 +26,21 @@ export class ReportProducts {
|
|
|
25
26
|
}
|
|
26
27
|
this.contracts.set(product.contract, product.schema);
|
|
27
28
|
}
|
|
28
|
-
for (const metric of product.metrics ?? [])
|
|
29
|
-
|
|
30
|
-
if (existing && !isDeepStrictEqual(existing, metric))
|
|
31
|
-
throw new Error(`Conflicting metric declaration: ${metric.id}`);
|
|
32
|
-
this.metrics.set(metric.id, metric);
|
|
33
|
-
if (plugin.kinds?.includes('security'))
|
|
34
|
-
this.privateMetrics.add(metric.id);
|
|
35
|
-
}
|
|
29
|
+
for (const metric of product.metrics ?? [])
|
|
30
|
+
this.registerMetric(plugin, metric);
|
|
36
31
|
}
|
|
37
32
|
}
|
|
38
33
|
}
|
|
34
|
+
registerMetric(plugin, metric) {
|
|
35
|
+
const existing = this.metrics.get(metric.id);
|
|
36
|
+
if (existing && !isDeepStrictEqual(existing, metric))
|
|
37
|
+
throw new Error(`Conflicting metric declaration: ${metric.id}`);
|
|
38
|
+
this.metrics.set(metric.id, metric);
|
|
39
|
+
if (!plugin.languageProvenanceRequiresSource)
|
|
40
|
+
this.alwaysReport.add(metric.id);
|
|
41
|
+
if (plugin.kinds?.includes('security'))
|
|
42
|
+
this.privateMetrics.add(metric.id);
|
|
43
|
+
}
|
|
39
44
|
record(task, { contract, value }, path) {
|
|
40
45
|
if (task.declaration?.persistence !== 'report')
|
|
41
46
|
return undefined;
|
|
@@ -67,8 +72,11 @@ export class ReportProducts {
|
|
|
67
72
|
result() {
|
|
68
73
|
if (!this.declared)
|
|
69
74
|
return undefined;
|
|
70
|
-
|
|
71
|
-
|
|
75
|
+
const visible = (id) => this.alwaysReport.has(id) || this.measured.has(id);
|
|
76
|
+
const metrics = [...this.metrics.values()].filter(({ id }) => visible(id));
|
|
77
|
+
const privateMetrics = [...this.privateMetrics].filter(visible);
|
|
78
|
+
return { metrics, measured: [...this.measured],
|
|
79
|
+
...(privateMetrics.length ? { privateMetrics } : {}),
|
|
72
80
|
...(this.contracts.size ? { contracts: Object.fromEntries(this.contracts) } : {}),
|
|
73
81
|
rules: this.rules, products: Object.fromEntries(this.products) };
|
|
74
82
|
}
|
|
@@ -26,6 +26,8 @@ export interface CodeStructure {
|
|
|
26
26
|
readonly lines: number;
|
|
27
27
|
readonly functions?: number;
|
|
28
28
|
readonly classes?: number;
|
|
29
|
+
/** Named or unnamed declarations counted by the language provider. */
|
|
30
|
+
readonly declarations?: number;
|
|
29
31
|
readonly cognitiveComplexity?: number;
|
|
30
32
|
readonly commentLines?: number;
|
|
31
33
|
readonly cyclomaticFunctions?: readonly FunctionComplexity[];
|
|
@@ -32,7 +32,7 @@ export const codeStructure = {
|
|
|
32
32
|
id: 'repometry.code-structure/v1',
|
|
33
33
|
accepts: (value) => isRecord(value)
|
|
34
34
|
&& typeof value.path === 'string' && isCount(value.lines)
|
|
35
|
-
&& [value.functions, value.classes, value.cognitiveComplexity, value.commentLines].every(count => count === undefined || isCount(count))
|
|
35
|
+
&& [value.functions, value.classes, value.declarations, value.cognitiveComplexity, value.commentLines].every(count => count === undefined || isCount(count))
|
|
36
36
|
&& (value.cyclomaticFunctions === undefined || Array.isArray(value.cyclomaticFunctions) && value.cyclomaticFunctions.every(isFunctionComplexity))
|
|
37
37
|
&& (value.cognitiveFunctions === undefined || Array.isArray(value.cognitiveFunctions) && value.cognitiveFunctions.every(isFunctionComplexity))
|
|
38
38
|
&& (value.functionBodies === undefined || isMergedLineRanges(value.functionBodies) && (value.functionBodies.at(-1)?.[1] ?? 0) <= value.lines)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { LanguageSyntax } from './language.js';
|
|
2
|
+
export declare const cSyntax: LanguageSyntax;
|
|
3
|
+
export declare const cppSyntax: LanguageSyntax;
|
|
4
|
+
export declare const jsonSyntax: LanguageSyntax;
|
|
5
|
+
export declare const cssSyntax: LanguageSyntax;
|
|
6
|
+
export declare const dockerfileSyntax: LanguageSyntax;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
const cFamily = {
|
|
2
|
+
lineComments: ['//'],
|
|
3
|
+
strings: [{ quote: '"' }, { quote: "'" }],
|
|
4
|
+
stringPrefixes: ['L', 'u', 'U', 'u8'],
|
|
5
|
+
};
|
|
6
|
+
// WG14 N3096 §6.4.1, including the alternative spellings. Line splices can hide block markers.
|
|
7
|
+
export const cSyntax = {
|
|
8
|
+
...cFamily,
|
|
9
|
+
keywords: [
|
|
10
|
+
'alignas', 'alignof', 'auto', 'bool', 'break', 'case', 'char', 'const', 'constexpr', 'continue', 'default',
|
|
11
|
+
'do', 'double', 'else', 'enum', 'extern', 'false', 'float', 'for', 'goto', 'if', 'inline', 'int', 'long',
|
|
12
|
+
'nullptr', 'register', 'restrict', 'return', 'short', 'signed', 'sizeof', 'static', 'static_assert', 'struct',
|
|
13
|
+
'switch', 'thread_local', 'true', 'typedef', 'typeof', 'typeof_unqual', 'union', 'unsigned', 'void',
|
|
14
|
+
'volatile', 'while', '_Alignas', '_Alignof', '_Atomic', '_BitInt', '_Bool', '_Complex', '_Decimal128',
|
|
15
|
+
'_Decimal32', '_Decimal64', '_Generic', '_Imaginary', '_Noreturn', '_Static_assert', '_Thread_local',
|
|
16
|
+
],
|
|
17
|
+
};
|
|
18
|
+
// WG21 N4950 §5.11. Delimited raw strings can contain unbalanced block markers.
|
|
19
|
+
export const cppSyntax = {
|
|
20
|
+
...cFamily,
|
|
21
|
+
keywords: [
|
|
22
|
+
'alignas', 'alignof', 'and', 'and_eq', 'asm', 'auto', 'bitand', 'bitor', 'bool', 'break', 'case', 'catch',
|
|
23
|
+
'char', 'char8_t', 'char16_t', 'char32_t', 'class', 'compl', 'concept', 'const', 'consteval', 'constexpr',
|
|
24
|
+
'constinit', 'const_cast', 'continue', 'co_await', 'co_return', 'co_yield', 'decltype', 'default', 'delete',
|
|
25
|
+
'do', 'double', 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern', 'false', 'float', 'for',
|
|
26
|
+
'friend', 'goto', 'if', 'inline', 'int', 'long', 'mutable', 'namespace', 'new', 'noexcept', 'not', 'not_eq',
|
|
27
|
+
'nullptr', 'operator', 'or', 'or_eq', 'private', 'protected', 'public', 'register', 'reinterpret_cast',
|
|
28
|
+
'requires', 'return', 'short', 'signed', 'sizeof', 'static', 'static_assert', 'static_cast', 'struct',
|
|
29
|
+
'switch', 'template', 'this', 'thread_local', 'throw', 'true', 'try', 'typedef', 'typeid', 'typename', 'union',
|
|
30
|
+
'unsigned', 'using', 'virtual', 'void', 'volatile', 'wchar_t', 'while', 'xor', 'xor_eq',
|
|
31
|
+
],
|
|
32
|
+
};
|
|
33
|
+
// RFC 8259 §§3 and 7.
|
|
34
|
+
export const jsonSyntax = {
|
|
35
|
+
strings: [{ quote: '"' }],
|
|
36
|
+
keywords: ['false', 'null', 'true'],
|
|
37
|
+
};
|
|
38
|
+
// CSS Syntax Level 3 §4.3.5. Unquoted URL tokens can contain block markers.
|
|
39
|
+
export const cssSyntax = {
|
|
40
|
+
strings: [{ quote: '"' }, { quote: "'" }],
|
|
41
|
+
};
|
|
42
|
+
// Dockerfile reference: conventional uppercase instructions and the FROM stage marker.
|
|
43
|
+
export const dockerfileSyntax = {
|
|
44
|
+
strings: [{ quote: '"' }, { quote: "'" }],
|
|
45
|
+
keywords: [
|
|
46
|
+
'ADD', 'ARG', 'CMD', 'COPY', 'ENTRYPOINT', 'ENV', 'EXPOSE', 'FROM', 'HEALTHCHECK', 'LABEL', 'MAINTAINER',
|
|
47
|
+
'ONBUILD', 'RUN', 'SHELL', 'STOPSIGNAL', 'USER', 'VOLUME', 'WORKDIR', 'AS',
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=file-type-syntax.js.map
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import { posix } from 'node:path';
|
|
2
|
+
import { cppSyntax, cssSyntax, cSyntax, dockerfileSyntax, jsonSyntax } from './file-type-syntax.js';
|
|
2
3
|
export const javascriptType = { id: 'javascript', label: 'JavaScript', color: '#f1e05a', extensions: ['.js', '.mjs', '.cjs', '.jsx'] };
|
|
3
4
|
export const typescriptType = { id: 'typescript', label: 'TypeScript', color: '#3178c6', extensions: ['.ts', '.mts', '.cts', '.tsx'] };
|
|
4
5
|
export const fileTypes = [
|
|
5
6
|
javascriptType, typescriptType,
|
|
6
7
|
{ id: 'markdown', label: 'Markdown', color: '#768390', extensions: ['.md', '.mdx', '.markdown'] },
|
|
7
8
|
{ id: 'yaml', label: 'YAML', color: '#c47d84', extensions: ['.yaml', '.yml'] },
|
|
8
|
-
{ id: 'json', label: 'JSON', color: '#9b86b5', extensions: ['.json'] },
|
|
9
|
-
{ id: 'css', label: 'CSS', color: '#663399', extensions: ['.css'] },
|
|
9
|
+
{ id: 'json', label: 'JSON', color: '#9b86b5', extensions: ['.json'], syntax: jsonSyntax },
|
|
10
|
+
{ id: 'css', label: 'CSS', color: '#663399', extensions: ['.css'], syntax: cssSyntax },
|
|
10
11
|
{ id: 'scss', label: 'SCSS', color: '#c6538c', extensions: ['.scss'] },
|
|
11
12
|
{ id: 'less', label: 'Less', color: '#1d365d', extensions: ['.less'] },
|
|
12
13
|
{ id: 'html', label: 'HTML', color: '#e34c26', extensions: ['.html', '.htm'] },
|
|
13
14
|
{ id: 'shell', label: 'Shell', color: '#89e051', extensions: ['.sh', '.bash', '.zsh', '.fish'], names: ['.bashrc', '.bash_profile'] },
|
|
14
15
|
{ id: 'batch', label: 'Batch', color: '#788f32', extensions: ['.bat'] },
|
|
15
|
-
{ id: 'dockerfile', label: 'Dockerfile', color: '#4f9a94', names: ['dockerfile', 'containerfile'],
|
|
16
|
+
{ id: 'dockerfile', label: 'Dockerfile', color: '#4f9a94', names: ['dockerfile', 'containerfile'],
|
|
17
|
+
extensions: ['.dockerfile'], syntax: dockerfileSyntax },
|
|
16
18
|
{ id: 'python', label: 'Python', color: '#3572a5', extensions: ['.py'] },
|
|
17
19
|
{ id: 'go', label: 'Go', color: '#00add8', extensions: ['.go'] },
|
|
18
20
|
{ id: 'go-module', label: 'Go module', color: '#008ba8', exactNames: ['go.mod'] },
|
|
@@ -22,9 +24,10 @@ export const fileTypes = [
|
|
|
22
24
|
{ id: 'kotlin', label: 'Kotlin', color: '#a97bff', extensions: ['.kt', '.kts'] },
|
|
23
25
|
{ id: 'ruby', label: 'Ruby', color: '#701516', extensions: ['.rb'] },
|
|
24
26
|
{ id: 'php', label: 'PHP', color: '#4f5d95', extensions: ['.php'] },
|
|
25
|
-
{ id: '
|
|
26
|
-
{ id: '
|
|
27
|
-
{ id: '
|
|
27
|
+
{ id: 'hcl', label: 'HCL', color: '#844fba', extensions: ['.hcl', '.tf', '.tfvars'] },
|
|
28
|
+
{ id: 'csharp', label: 'C#', color: '#178600', extensions: ['.cs'] },
|
|
29
|
+
{ id: 'c', label: 'C', color: '#555555', extensions: ['.c', '.h'], syntax: cSyntax },
|
|
30
|
+
{ id: 'cpp', label: 'C++', color: '#f34b7d', extensions: ['.cc', '.cpp', '.cxx', '.hpp', '.hh'], syntax: cppSyntax },
|
|
28
31
|
{ id: 'swift', label: 'Swift', color: '#f05138', extensions: ['.swift'] },
|
|
29
32
|
{ id: 'scala', label: 'Scala', color: '#c22d40', extensions: ['.scala'] },
|
|
30
33
|
{ id: 'vue', label: 'Vue', color: '#41b883', extensions: ['.vue'] },
|
|
@@ -47,4 +50,7 @@ export function fileTypeId(path, fallback) {
|
|
|
47
50
|
return exactNames.get(basename) ?? names.get(name) ?? names.get(name.split('.', 1)[0]) ?? extensions.get(extension)
|
|
48
51
|
?? fallback ?? (extension.slice(1) || 'other');
|
|
49
52
|
}
|
|
53
|
+
export function canonicalFileTypeId(id) {
|
|
54
|
+
return id === 'c-sharp' ? 'csharp' : id;
|
|
55
|
+
}
|
|
50
56
|
//# 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,
|
|
20
|
+
return bytes.byteLength <= maxClaimedFileBytes && !bytes.subarray(0, binaryProbeBytes).includes(0);
|
|
19
21
|
}
|
|
20
22
|
//# sourceMappingURL=source.js.map
|