@produtype/core 0.27.0 → 0.29.1
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/analyzer/analyzeProject.js +9 -0
- package/dist/analyzer/readingDepth.d.ts +45 -0
- package/dist/analyzer/readingDepth.js +60 -0
- package/dist/report/buildReport.js +7 -0
- package/dist/report/markdownReport.js +11 -0
- package/dist/report/types.d.ts +9 -0
- package/dist/utils/fileScanner.d.ts +0 -3
- package/dist/utils/fileScanner.js +33 -1
- package/package.json +1 -1
|
@@ -144,6 +144,15 @@ function isTestOrExamplePath(file) {
|
|
|
144
144
|
// as a marketplace taking a cut. A field set to null is evidence of absence.
|
|
145
145
|
return /(^|\/)(__tests__|__mocks__|mocks?|tests?|test-data|fixtures|frontend-example)(\/|$)/i.test(file)
|
|
146
146
|
|| /(^|\/)test[-_][^/]+\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file)
|
|
147
|
+
/**
|
|
148
|
+
* The other half of the convention.
|
|
149
|
+
*
|
|
150
|
+
* `test_settings.py` was recognised and `settings_tests.py` was not, so a Django
|
|
151
|
+
* project's test configuration was read as production and its `STRIPE_SECRET_KEY =
|
|
152
|
+
* "sk_test_fake"` raised a critical — the severity that bars a report from the top
|
|
153
|
+
* band — against a line written to be fake.
|
|
154
|
+
*/
|
|
155
|
+
|| /[-_]tests?\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file)
|
|
147
156
|
|| /\.(test|spec)\.(ts|tsx|js|jsx|mjs|cjs|py)$/i.test(file);
|
|
148
157
|
}
|
|
149
158
|
/**
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How closely this analyzer read each language it found.
|
|
3
|
+
*
|
|
4
|
+
* The product's whole argument is that it says only what it can show. It has been
|
|
5
|
+
* saying, with the same confidence in both cases, things it read from a syntax tree and
|
|
6
|
+
* things it guessed from a word — and the report gave a reader no way to tell which.
|
|
7
|
+
*
|
|
8
|
+
* Measured rather than asserted: 68 keyword searches against 1 structural claim, and 6
|
|
9
|
+
* of 18 readable extensions covered by a parser. A report on a Go project and a report
|
|
10
|
+
* on a TypeScript project looked equally sure of themselves, and were not.
|
|
11
|
+
*
|
|
12
|
+
* Three depths, in the order they deserve to be trusted:
|
|
13
|
+
*
|
|
14
|
+
* - `parsed`: a syntax tree answered the question. `{m.role === 'user' ? 'You' : 'Bot'}`
|
|
15
|
+
* is a label and `if (!roles.includes(actor.role)) return res.status(403)` is a guard,
|
|
16
|
+
* and nothing about the words tells them apart.
|
|
17
|
+
* - `searched`: the file was read as text and matched against keywords. Everything this
|
|
18
|
+
* analyzer has always done, and where every defect of 18 September lived.
|
|
19
|
+
* - `skipped`: the language was seen and not read at all.
|
|
20
|
+
*/
|
|
21
|
+
export type ReadingDepth = 'parsed' | 'searched' | 'skipped';
|
|
22
|
+
export interface LanguageReading {
|
|
23
|
+
language: string;
|
|
24
|
+
files: number;
|
|
25
|
+
depth: ReadingDepth;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* What was read, and how, for every language present in the repository.
|
|
29
|
+
*
|
|
30
|
+
* Counts source files rather than all files: a language that appears only in an ignored
|
|
31
|
+
* directory was not read because it was not the project's, which is a different fact and
|
|
32
|
+
* one the reader does not need here.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readingDepths(sourceFiles: string[], unreadable: Array<{
|
|
35
|
+
language: string;
|
|
36
|
+
files: number;
|
|
37
|
+
}>): LanguageReading[];
|
|
38
|
+
/**
|
|
39
|
+
* The sentence a reader needs, or nothing.
|
|
40
|
+
*
|
|
41
|
+
* Silent where everything was parsed: a report that congratulates itself on reading
|
|
42
|
+
* properly is noise. It speaks when some of the reading was shallower than the rest,
|
|
43
|
+
* which is the case that misleads.
|
|
44
|
+
*/
|
|
45
|
+
export declare function describeReadingDepth(readings: LanguageReading[]): string | undefined;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.readingDepths = readingDepths;
|
|
4
|
+
exports.describeReadingDepth = describeReadingDepth;
|
|
5
|
+
const catalogue_1 = require("./catalogue");
|
|
6
|
+
/**
|
|
7
|
+
* The extensions a parser reads today.
|
|
8
|
+
*
|
|
9
|
+
* One list, so that adding Python to the structural layer changes what the report claims
|
|
10
|
+
* about Python in the same commit that makes it true. A second copy of this would drift
|
|
11
|
+
* within a week, which is the failure this file exists to stop somebody else making.
|
|
12
|
+
*/
|
|
13
|
+
const PARSED_EXTENSIONS = /\.(ts|tsx|js|jsx|mjs|cjs)$/;
|
|
14
|
+
/** Languages whose files are read as text but never parsed. */
|
|
15
|
+
function depthFor(files) {
|
|
16
|
+
if (files.length === 0)
|
|
17
|
+
return 'skipped';
|
|
18
|
+
return files.every((file) => PARSED_EXTENSIONS.test(file)) ? 'parsed' : 'searched';
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* What was read, and how, for every language present in the repository.
|
|
22
|
+
*
|
|
23
|
+
* Counts source files rather than all files: a language that appears only in an ignored
|
|
24
|
+
* directory was not read because it was not the project's, which is a different fact and
|
|
25
|
+
* one the reader does not need here.
|
|
26
|
+
*/
|
|
27
|
+
function readingDepths(sourceFiles, unreadable) {
|
|
28
|
+
const readings = [];
|
|
29
|
+
for (const { label, extensions } of catalogue_1.LANGUAGES) {
|
|
30
|
+
const files = sourceFiles.filter((file) => extensions.test(file));
|
|
31
|
+
if (files.length === 0)
|
|
32
|
+
continue;
|
|
33
|
+
readings.push({ language: label, files: files.length, depth: depthFor(files) });
|
|
34
|
+
}
|
|
35
|
+
for (const entry of unreadable) {
|
|
36
|
+
readings.push({ language: entry.language, files: entry.files, depth: 'skipped' });
|
|
37
|
+
}
|
|
38
|
+
return readings.sort((left, right) => right.files - left.files);
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The sentence a reader needs, or nothing.
|
|
42
|
+
*
|
|
43
|
+
* Silent where everything was parsed: a report that congratulates itself on reading
|
|
44
|
+
* properly is noise. It speaks when some of the reading was shallower than the rest,
|
|
45
|
+
* which is the case that misleads.
|
|
46
|
+
*/
|
|
47
|
+
function describeReadingDepth(readings) {
|
|
48
|
+
const searched = readings.filter((entry) => entry.depth === 'searched');
|
|
49
|
+
const skipped = readings.filter((entry) => entry.depth === 'skipped');
|
|
50
|
+
if (searched.length === 0 && skipped.length === 0)
|
|
51
|
+
return undefined;
|
|
52
|
+
const parts = [];
|
|
53
|
+
if (searched.length > 0) {
|
|
54
|
+
parts.push(`${searched.map((entry) => entry.language).join(', ')} ${searched.length === 1 ? 'was' : 'were'} read as text and matched against keywords, not parsed`);
|
|
55
|
+
}
|
|
56
|
+
if (skipped.length > 0) {
|
|
57
|
+
parts.push(`${skipped.map((entry) => `${entry.language} (${entry.files} files)`).join(', ')} not read at all`);
|
|
58
|
+
}
|
|
59
|
+
return `How this repository was read: ${parts.join('; ')}. A keyword can appear in a comment, a test fixture or a variable name, so findings in those languages rest on weaker evidence than the ones this analyzer parsed.`;
|
|
60
|
+
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.buildReport = buildReport;
|
|
4
4
|
const ruleEngine_1 = require("../rules/ruleEngine");
|
|
5
|
+
const readingDepth_1 = require("../analyzer/readingDepth");
|
|
5
6
|
const score_1 = require("./score");
|
|
6
7
|
const types_1 = require("./types");
|
|
7
8
|
const evaluateExpectations_1 = require("../expectations/evaluateExpectations");
|
|
@@ -296,6 +297,12 @@ function buildReport(analysis, options) {
|
|
|
296
297
|
// to know that one rests on seventeen verdicts and the other on nine.
|
|
297
298
|
assessedChecks,
|
|
298
299
|
verifiedChecks: passedChecksForMaturity,
|
|
300
|
+
/**
|
|
301
|
+
* How closely each language was read, so a reader can weigh a finding by more than
|
|
302
|
+
* its severity. A keyword match in Go and a parsed guard in TypeScript were being
|
|
303
|
+
* presented with the same confidence.
|
|
304
|
+
*/
|
|
305
|
+
readingDepth: (0, readingDepth_1.readingDepths)(analysis.files.source, analysis.files.unreadable),
|
|
299
306
|
detectors: detectorDiagnostics(analysis),
|
|
300
307
|
selectedProfile: requestedProfile,
|
|
301
308
|
inferredProfile: productProfile?.inferredProfile,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.renderMarkdown = renderMarkdown;
|
|
4
|
+
const readingDepth_1 = require("../analyzer/readingDepth");
|
|
4
5
|
function profileSummary(report) {
|
|
5
6
|
const profile = report.productProfile;
|
|
6
7
|
if (!profile) {
|
|
@@ -242,6 +243,16 @@ function renderMarkdown(report) {
|
|
|
242
243
|
]
|
|
243
244
|
: []),
|
|
244
245
|
`- Diagnostics: ${report.diagnostics.analyzedFileCount} analyzed / ${report.diagnostics.skippedFileCount} skipped / ${report.diagnostics.workspaceCount} workspaces / ${report.diagnostics.detectorCount} detectors`,
|
|
246
|
+
/**
|
|
247
|
+
* How the code was read, beside how much of it there was.
|
|
248
|
+
*
|
|
249
|
+
* A keyword match in Go and a parsed guard in TypeScript were printed with the same
|
|
250
|
+
* confidence, and nothing in the report distinguished them. Silent when everything
|
|
251
|
+
* was parsed: a report congratulating itself on reading properly is noise.
|
|
252
|
+
*/
|
|
253
|
+
...((0, readingDepth_1.describeReadingDepth)(report.diagnostics.readingDepth)
|
|
254
|
+
? [`- ${(0, readingDepth_1.describeReadingDepth)(report.diagnostics.readingDepth)}`]
|
|
255
|
+
: []),
|
|
245
256
|
`- Expectation mode: ${report.diagnostics.expectationMode}`,
|
|
246
257
|
`- ProdKit version: ${report.diagnostics.prodkitVersion}`,
|
|
247
258
|
`- Detector diagnostics: ${report.diagnostics.detectors.filter((d) => d.status === 'completed').length} completed / ${report.diagnostics.detectors.filter((d) => d.status === 'skipped').length} skipped`,
|
package/dist/report/types.d.ts
CHANGED
|
@@ -47,6 +47,7 @@ export interface Finding {
|
|
|
47
47
|
}
|
|
48
48
|
export type MaturityLevel = 'prototype' | 'early' | 'partial' | 'production_ready';
|
|
49
49
|
export type ExpectationMode = 'observed-only' | 'explicit-profile' | 'auto-applied' | 'auto-inconclusive';
|
|
50
|
+
import type { LanguageReading } from '../analyzer/readingDepth';
|
|
50
51
|
export interface ReportDiagnostics {
|
|
51
52
|
analyzedFileCount: number;
|
|
52
53
|
skippedFileCount: number;
|
|
@@ -56,6 +57,14 @@ export interface ReportDiagnostics {
|
|
|
56
57
|
assessedChecks: number;
|
|
57
58
|
/** Of those, the ones that ran and found what they were looking for. */
|
|
58
59
|
verifiedChecks: number;
|
|
60
|
+
/**
|
|
61
|
+
* How closely each language present was read.
|
|
62
|
+
*
|
|
63
|
+
* A finding matched from a keyword in Go and a finding read from a syntax tree in
|
|
64
|
+
* TypeScript were presented with identical confidence. They are not the same kind of
|
|
65
|
+
* fact, and the reader is entitled to know which one they have.
|
|
66
|
+
*/
|
|
67
|
+
readingDepth: LanguageReading[];
|
|
59
68
|
detectors: Array<{
|
|
60
69
|
id: string;
|
|
61
70
|
status: 'completed' | 'skipped';
|
|
@@ -4,9 +4,6 @@ export interface ScanOptions {
|
|
|
4
4
|
patterns?: string[];
|
|
5
5
|
ignore?: string[];
|
|
6
6
|
}
|
|
7
|
-
/**
|
|
8
|
-
* Scan files relative to a root project path. Returns paths relative to cwd.
|
|
9
|
-
*/
|
|
10
7
|
export declare function scanFiles(opts: ScanOptions): Promise<string[]>;
|
|
11
8
|
/**
|
|
12
9
|
* Quick check: does at least one path matching glob exist?
|
|
@@ -49,6 +49,20 @@ exports.DEFAULT_IGNORE = [
|
|
|
49
49
|
'**/coverage/**',
|
|
50
50
|
'**/venv/**',
|
|
51
51
|
'**/.venv/**',
|
|
52
|
+
/**
|
|
53
|
+
* Where Python puts what you installed, whatever the surrounding directory is called.
|
|
54
|
+
*
|
|
55
|
+
* `venv/` and `.venv/` were ignored by name, and a repository whose virtualenv was
|
|
56
|
+
* called `venv52/` had 7331 of its 8438 source files read as its own: botocore, boto3,
|
|
57
|
+
* the whole of pip's output. It produced a critical — `SECRET_KEY =
|
|
58
|
+
* 'AWS_SECRET_ACCESS_KEY'`, which is botocore naming an environment variable — against
|
|
59
|
+
* a project that had not written it.
|
|
60
|
+
*
|
|
61
|
+
* This is `node_modules` for Python, and like `node_modules` it cannot be anything
|
|
62
|
+
* else. The name of the virtualenv is a guess; `site-packages` is a fact.
|
|
63
|
+
*/
|
|
64
|
+
'**/site-packages/**',
|
|
65
|
+
'**/dist-packages/**',
|
|
52
66
|
'**/__pycache__/**',
|
|
53
67
|
'**/.next/**',
|
|
54
68
|
'**/.turbo/**',
|
|
@@ -124,6 +138,24 @@ exports.DEFAULT_IGNORE = [
|
|
|
124
138
|
/**
|
|
125
139
|
* Scan files relative to a root project path. Returns paths relative to cwd.
|
|
126
140
|
*/
|
|
141
|
+
/**
|
|
142
|
+
* The file Python writes at the root of a virtualenv, and the only reliable way to
|
|
143
|
+
* recognise one.
|
|
144
|
+
*
|
|
145
|
+
* A virtualenv can be called anything: `venv52`, `env-3.11`, `.direnv`. Its scripts live
|
|
146
|
+
* in `bin/` and its packages in `lib/pythonX/site-packages/`, but the marker at the root
|
|
147
|
+
* is always this. Finding it means everything beside it was installed rather than
|
|
148
|
+
* written.
|
|
149
|
+
*/
|
|
150
|
+
const VIRTUALENV_MARKER = 'pyvenv.cfg';
|
|
151
|
+
function withoutVirtualenvs(files) {
|
|
152
|
+
const roots = files
|
|
153
|
+
.filter((file) => file === VIRTUALENV_MARKER || file.endsWith(`/${VIRTUALENV_MARKER}`))
|
|
154
|
+
.map((file) => file.slice(0, file.length - VIRTUALENV_MARKER.length));
|
|
155
|
+
if (roots.length === 0)
|
|
156
|
+
return files;
|
|
157
|
+
return files.filter((file) => !roots.some((root) => root !== '' && file.startsWith(root)));
|
|
158
|
+
}
|
|
127
159
|
async function scanFiles(opts) {
|
|
128
160
|
const patterns = opts.patterns ?? ['**/*'];
|
|
129
161
|
const ignore = [...exports.DEFAULT_IGNORE, ...(opts.ignore ?? [])];
|
|
@@ -135,7 +167,7 @@ async function scanFiles(opts) {
|
|
|
135
167
|
ignore,
|
|
136
168
|
suppressErrors: true,
|
|
137
169
|
});
|
|
138
|
-
return entries.map((e) => e.split(path.sep).join('/'));
|
|
170
|
+
return withoutVirtualenvs(entries.map((e) => e.split(path.sep).join('/')));
|
|
139
171
|
}
|
|
140
172
|
/**
|
|
141
173
|
* Quick check: does at least one path matching glob exist?
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@produtype/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.29.1",
|
|
4
4
|
"description": "Deterministic CLI and library that analyzes a web application repository and reports how far it is from production-ready for the kind of product it is meant to be.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|