@bymaksym/loadline 0.1.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/LICENSE +21 -0
- package/README.md +182 -0
- package/bin/loadline.js +50 -0
- package/dist/cli/cli/args.js +324 -0
- package/dist/cli/cli/args.types.js +3 -0
- package/dist/cli/cli/gates.js +173 -0
- package/dist/cli/cli/gates.types.js +3 -0
- package/dist/cli/cli/main.js +156 -0
- package/dist/cli/cli/read-build.js +382 -0
- package/dist/cli/cli/read-build.types.js +3 -0
- package/dist/cli/cli/render-json.js +116 -0
- package/dist/cli/cli/render-json.types.js +10 -0
- package/dist/cli/cli/render-markdown.js +30 -0
- package/dist/cli/cli/render-pr.js +76 -0
- package/dist/cli/cli/render-sarif.js +83 -0
- package/dist/cli/cli/render-text.js +388 -0
- package/dist/cli/cli/report.js +196 -0
- package/dist/cli/cli/report.types.js +3 -0
- package/dist/cli/cli/self-check.js +85 -0
- package/dist/cli/cli/text.js +180 -0
- package/dist/cli/cli/text.types.js +10 -0
- package/dist/cli/src/app/core/analysis/analysis.js +661 -0
- package/dist/cli/src/app/core/analysis/analysis.types.js +6 -0
- package/dist/cli/src/app/core/analysis/barrels.js +128 -0
- package/dist/cli/src/app/core/analysis/blast.js +172 -0
- package/dist/cli/src/app/core/analysis/cycles.js +110 -0
- package/dist/cli/src/app/core/analysis/delivery.js +143 -0
- package/dist/cli/src/app/core/analysis/entries.js +217 -0
- package/dist/cli/src/app/core/analysis/exclusive.js +91 -0
- package/dist/cli/src/app/core/analysis/importers.js +38 -0
- package/dist/cli/src/app/core/analysis/insights.js +202 -0
- package/dist/cli/src/app/core/analysis/insights.types.js +10 -0
- package/dist/cli/src/app/core/analysis/invariant.js +69 -0
- package/dist/cli/src/app/core/analysis/metafile.types.js +44 -0
- package/dist/cli/src/app/core/analysis/module-graph.js +192 -0
- package/dist/cli/src/app/core/analysis/sourcemap.js +231 -0
- package/dist/cli/src/app/core/analysis/sourcemap.types.js +3 -0
- package/dist/cli/src/app/core/analysis/split-drift.js +47 -0
- package/dist/cli/src/app/core/assets/assets.js +296 -0
- package/dist/cli/src/app/core/assets/assets.types.js +11 -0
- package/dist/cli/src/app/core/baseline/baseline.js +0 -0
- package/dist/cli/src/app/core/baseline/baseline.types.js +3 -0
- package/dist/cli/src/app/core/caching/caching.js +241 -0
- package/dist/cli/src/app/core/caching/caching.types.js +10 -0
- package/dist/cli/src/app/core/caching/from-analysis.js +73 -0
- package/dist/cli/src/app/core/config/loadline-config.js +110 -0
- package/dist/cli/src/app/core/config/loadline-config.types.js +12 -0
- package/dist/cli/src/app/core/criteria/criteria.js +228 -0
- package/dist/cli/src/app/core/criteria/criteria.types.js +3 -0
- package/dist/cli/src/app/core/deps/deps.js +225 -0
- package/dist/cli/src/app/core/deps/deps.types.js +15 -0
- package/dist/cli/src/app/core/export/markdown-table.utils.js +40 -0
- package/dist/cli/src/app/core/export/summary.js +72 -0
- package/dist/cli/src/app/core/findings/actions.js +59 -0
- package/dist/cli/src/app/core/findings/assets.js +130 -0
- package/dist/cli/src/app/core/findings/caching.js +165 -0
- package/dist/cli/src/app/core/findings/compose.js +41 -0
- package/dist/cli/src/app/core/findings/deps.js +66 -0
- package/dist/cli/src/app/core/findings/effort.js +117 -0
- package/dist/cli/src/app/core/findings/finding-html.js +13 -0
- package/dist/cli/src/app/core/findings/finding-plain.js +26 -0
- package/dist/cli/src/app/core/findings/finding-text.js +1231 -0
- package/dist/cli/src/app/core/findings/finding.types.js +80 -0
- package/dist/cli/src/app/core/findings/findings.js +514 -0
- package/dist/cli/src/app/core/findings/graph.js +167 -0
- package/dist/cli/src/app/core/findings/own-in-boot.js +88 -0
- package/dist/cli/src/app/core/findings/page.js +49 -0
- package/dist/cli/src/app/core/findings/requests.js +185 -0
- package/dist/cli/src/app/core/findings/scan.js +126 -0
- package/dist/cli/src/app/core/findings/shipped.js +244 -0
- package/dist/cli/src/app/core/findings/situation.js +116 -0
- package/dist/cli/src/app/core/format/format.utils.js +204 -0
- package/dist/cli/src/app/core/i18n/en.js +819 -0
- package/dist/cli/src/app/core/i18n/es.js +822 -0
- package/dist/cli/src/app/core/i18n/ui-strings.js +11 -0
- package/dist/cli/src/app/core/i18n/ui.js +7 -0
- package/dist/cli/src/app/core/intake/bundle-graph.js +346 -0
- package/dist/cli/src/app/core/intake/bundle-graph.types.js +3 -0
- package/dist/cli/src/app/core/intake/dist-files.js +160 -0
- package/dist/cli/src/app/core/intake/index-html.js +292 -0
- package/dist/cli/src/app/core/json/json.utils.js +55 -0
- package/dist/cli/src/app/core/measurement/measurement.types.js +14 -0
- package/dist/cli/src/app/core/project/budget-advice.js +76 -0
- package/dist/cli/src/app/core/project/project-context.js +394 -0
- package/dist/cli/src/app/core/project/project-context.types.js +3 -0
- package/dist/cli/src/app/core/scan/catalog.js +67 -0
- package/dist/cli/src/app/core/scan/scan.js +280 -0
- package/dist/cli/src/app/core/scan/scan.types.js +10 -0
- package/dist/cli/src/app/core/scan/secrets.js +0 -0
- package/dist/cli/src/app/core/situation/situation.js +261 -0
- package/dist/cli/src/app/core/situation/situation.types.js +19 -0
- package/dist/cli/src/app/core/timing/timing.js +87 -0
- package/dist/cli/src/app/core/timing/timing.types.js +3 -0
- package/dist/cli/src/app/core/whatif/defer.js +68 -0
- package/dist/cli/src/app/state/report-messages.utils.js +73 -0
- package/docs/HOW-IT-WORKS.md +1087 -0
- package/loadline.html +78 -0
- package/package.json +154 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The project context: what `angular.json`, `package.json` and the pipeline file say about size
|
|
4
|
+
* budgets and about which configuration actually gets built.
|
|
5
|
+
*
|
|
6
|
+
* The metafile alone cannot answer "is there a budget, and does the pipeline enforce it?". These
|
|
7
|
+
* three files can, and the answer is the failure that motivated the tool: a budget written into
|
|
8
|
+
* a configuration the pipeline never compiles.
|
|
9
|
+
*
|
|
10
|
+
* No YAML parser: the pipeline file is scanned line by line for build commands. It is deliberately
|
|
11
|
+
* tolerant, and every guess is reported with the command it came from so it can be checked.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.pipelineKnown = exports.configurationBudgets = exports.readPipeline = exports.resolveBuildCommand = exports.isZoneless = exports.readPackageJson = exports.readAngularJson = exports.isInitialBudget = exports.parseSize = exports.EMPTY_CONTEXT = void 0;
|
|
15
|
+
exports.EMPTY_CONTEXT = { angular: null, pkg: null, pipelines: [] };
|
|
16
|
+
const KB = 1024;
|
|
17
|
+
const UNITS = { b: 1, kb: KB, mb: KB * KB, gb: KB * KB * KB };
|
|
18
|
+
/**
|
|
19
|
+
* A budget size as Angular CLI accepts it: `500kB`, `1.5MB`, `2mb`, a bare number of bytes.
|
|
20
|
+
* Percentages (`25%`) refer to a baseline and cannot be turned into bytes here.
|
|
21
|
+
*/
|
|
22
|
+
const parseSize = (value) => {
|
|
23
|
+
if (typeof value === 'number') {
|
|
24
|
+
return Number.isFinite(value) ? value : null;
|
|
25
|
+
}
|
|
26
|
+
if (typeof value !== 'string') {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*(b|kb|mb|gb)?\s*$/i.exec(value);
|
|
30
|
+
if (!match?.[1]) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
const unit = UNITS[(match[2] ?? 'b').toLowerCase()] ?? 1;
|
|
34
|
+
return Math.round(Number(match[1]) * unit);
|
|
35
|
+
};
|
|
36
|
+
exports.parseSize = parseSize;
|
|
37
|
+
const readBudgets = (value) => {
|
|
38
|
+
if (!Array.isArray(value)) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
return value
|
|
42
|
+
.filter((item) => !!item && typeof item === 'object')
|
|
43
|
+
.map(item => ({
|
|
44
|
+
type: typeof item.type === 'string' ? item.type : 'unknown',
|
|
45
|
+
warning: (0, exports.parseSize)(item.maximumWarning),
|
|
46
|
+
error: (0, exports.parseSize)(item.maximumError),
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
/** The budgets that bound the initial download. `initial` is the one Angular CLI writes by default. */
|
|
50
|
+
const isInitialBudget = (budget) => budget.type === 'initial' || budget.type === 'all';
|
|
51
|
+
exports.isInitialBudget = isInitialBudget;
|
|
52
|
+
const polyfillsHaveZone = (polyfills) => {
|
|
53
|
+
if (typeof polyfills === 'string') {
|
|
54
|
+
return polyfills.includes('zone.js');
|
|
55
|
+
}
|
|
56
|
+
if (Array.isArray(polyfills)) {
|
|
57
|
+
return polyfills.some(entry => typeof entry === 'string' && entry.includes('zone.js'));
|
|
58
|
+
}
|
|
59
|
+
return null;
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* Reads one application of an `angular.json`, and lists the rest.
|
|
63
|
+
*
|
|
64
|
+
* @param pick which application to read. Without it the first one that is an application wins,
|
|
65
|
+
* which is a guess: in a workspace with three of them the budgets shown could belong
|
|
66
|
+
* to an app the metafile has nothing to do with. That is why every name comes back —
|
|
67
|
+
* so the report can say which one it read and offer the others.
|
|
68
|
+
*/
|
|
69
|
+
const readAngularJson = (json, pick = null) => {
|
|
70
|
+
if (!json || typeof json !== 'object' || !('projects' in json)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
const projects = json.projects;
|
|
74
|
+
if (!projects || typeof projects !== 'object') {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
const entries = Object.entries(projects);
|
|
78
|
+
const buildable = entries.filter(([, project]) => buildTargetOf(project));
|
|
79
|
+
const applications = buildable.filter(([, project]) => project.projectType === 'application').map(([name]) => name);
|
|
80
|
+
const chosen = buildable.find(([name]) => name === pick) ??
|
|
81
|
+
buildable.find(([name, project]) => project.projectType === 'application' && applications.includes(name)) ??
|
|
82
|
+
buildable[0];
|
|
83
|
+
if (!chosen) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
const [name, project] = chosen;
|
|
87
|
+
const build = buildTargetOf(project);
|
|
88
|
+
if (!build) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
const configurations = Object.entries(build.configurations ?? {}).map(([configName, config]) => ({
|
|
92
|
+
name: configName,
|
|
93
|
+
budgets: readBudgets(config?.budgets),
|
|
94
|
+
}));
|
|
95
|
+
return {
|
|
96
|
+
project: name,
|
|
97
|
+
// A workspace of libraries only has no application: then every buildable project is the list.
|
|
98
|
+
applications: applications.length > 0 ? applications : buildable.map(entry => entry[0]),
|
|
99
|
+
baseBudgets: readBudgets(build.options?.budgets),
|
|
100
|
+
configurations,
|
|
101
|
+
defaultConfiguration: typeof build.defaultConfiguration === 'string' ? build.defaultConfiguration : null,
|
|
102
|
+
zonePolyfill: polyfillsHaveZone(build.options?.polyfills),
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
exports.readAngularJson = readAngularJson;
|
|
106
|
+
const buildTargetOf = (project) => project.architect?.['build'] ?? project.targets?.['build'];
|
|
107
|
+
const readPackageJson = (json) => {
|
|
108
|
+
if (!json || typeof json !== 'object') {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
const pkg = json;
|
|
112
|
+
const scripts = {};
|
|
113
|
+
const declared = Object.entries(pkg.scripts ?? {});
|
|
114
|
+
for (const [key, value] of declared) {
|
|
115
|
+
if (typeof value === 'string') {
|
|
116
|
+
scripts[key] = value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const deps = { ...pkg.devDependencies, ...pkg.dependencies };
|
|
120
|
+
const angularVersion = deps['@angular/core'];
|
|
121
|
+
return {
|
|
122
|
+
name: typeof pkg.name === 'string' && pkg.name.trim() ? pkg.name.trim() : null,
|
|
123
|
+
scripts,
|
|
124
|
+
// What the project asks for by name. It is what tells a dependency you chose from one that
|
|
125
|
+
// came along with something else, which changes the fix and not the weight.
|
|
126
|
+
dependencies: Object.keys({ ...pkg.dependencies }),
|
|
127
|
+
zoneDependency: 'zone.js' in deps,
|
|
128
|
+
angularVersion: typeof angularVersion === 'string' ? angularVersion.replace(/^[\^~>=<\s]+/, '') : null,
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
exports.readPackageJson = readPackageJson;
|
|
132
|
+
/**
|
|
133
|
+
* Is the project zoneless? `angular.json` decides when it lists the polyfills; otherwise the
|
|
134
|
+
* absence of `zone.js` in `package.json` does. `null` when neither file is loaded.
|
|
135
|
+
*/
|
|
136
|
+
const isZoneless = (context) => {
|
|
137
|
+
if (context.angular?.zonePolyfill !== null && context.angular?.zonePolyfill !== undefined) {
|
|
138
|
+
return !context.angular.zonePolyfill;
|
|
139
|
+
}
|
|
140
|
+
if (context.pkg) {
|
|
141
|
+
return !context.pkg.zoneDependency;
|
|
142
|
+
}
|
|
143
|
+
return null;
|
|
144
|
+
};
|
|
145
|
+
exports.isZoneless = isZoneless;
|
|
146
|
+
// --- Pipeline ---------------------------------------------------------------------------------
|
|
147
|
+
/**
|
|
148
|
+
* A command that builds the application, however it is invoked (`npx`, `pnpm exec`, plain).
|
|
149
|
+
*
|
|
150
|
+
* `ng build` used to be the whole list, and a project that builds any other way came out as "could
|
|
151
|
+
* not be followed" every single time — which reads as "your pipeline is odd" when what happened is
|
|
152
|
+
* that the tool only knew one command. An Nx workspace, which is the common case among the projects
|
|
153
|
+
* this is aimed at, never matched.
|
|
154
|
+
*
|
|
155
|
+
* Each entry captures whatever follows the command on the same line, which is where the flags that
|
|
156
|
+
* name a configuration are.
|
|
157
|
+
*/
|
|
158
|
+
const BUILD_COMMANDS = [
|
|
159
|
+
/\bng\s+build\b([^&|;]*)/,
|
|
160
|
+
/\bnx\s+build\b([^&|;]*)/,
|
|
161
|
+
/\bnx\s+run\s+[\w@/.:-]+:build[\w:-]*\b([^&|;]*)/,
|
|
162
|
+
/\bvite\s+build\b([^&|;]*)/,
|
|
163
|
+
/\brsbuild\s+build\b([^&|;]*)/,
|
|
164
|
+
// esbuild has no `build` subcommand, so it is only recognised when it is being invoked with
|
|
165
|
+
// flags. Matching the bare word would turn `pnpm add esbuild` into a build of the application.
|
|
166
|
+
/\besbuild\s+([^&|;]*--[\w-][^&|;]*)/,
|
|
167
|
+
];
|
|
168
|
+
/** The flags of a build command, when one of them is a build command. `null` when none is. */
|
|
169
|
+
const buildFlagsIn = (command) => {
|
|
170
|
+
for (const pattern of BUILD_COMMANDS) {
|
|
171
|
+
const found = pattern.exec(command);
|
|
172
|
+
if (found) {
|
|
173
|
+
return found[1] ?? '';
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return null;
|
|
177
|
+
};
|
|
178
|
+
/** `npm run x`, `pnpm run x`, `pnpm x`, `yarn x`, `yarn run x`, `npm run-script x`. */
|
|
179
|
+
const SCRIPT_CALL = /\b(?:npm\s+run(?:-script)?|pnpm\s+run|pnpm|yarn\s+run|yarn|bun\s+run|bun)\s+([\w:.-]+)/g;
|
|
180
|
+
/** Scripts that are the runner itself, not a project script. */
|
|
181
|
+
const NOT_SCRIPTS = new Set(['install', 'ci', 'i', 'exec', 'dlx', 'add', 'test', 'lint', 'audit', 'run', 'x']);
|
|
182
|
+
const configurationsOf = (buildArgs) => {
|
|
183
|
+
const configs = [];
|
|
184
|
+
// `--configuration` and `-c` are Angular's and Nx's; `--mode` is what Vite calls the same thing.
|
|
185
|
+
const flag = /(?:--configuration|--mode|-c)(?:=|\s+)([\w,.-]+)/g;
|
|
186
|
+
let match;
|
|
187
|
+
while ((match = flag.exec(buildArgs)) !== null) {
|
|
188
|
+
configs.push(...(match[1] ?? '').split(',').filter(Boolean));
|
|
189
|
+
}
|
|
190
|
+
if (/--prod\b/.test(buildArgs)) {
|
|
191
|
+
configs.push('production');
|
|
192
|
+
}
|
|
193
|
+
return configs;
|
|
194
|
+
};
|
|
195
|
+
/**
|
|
196
|
+
* Follows a command until it reaches a build, through the scripts of `package.json`:
|
|
197
|
+
* `pnpm run build:pre` → `ng build --configuration=preproduction`.
|
|
198
|
+
*/
|
|
199
|
+
const resolveBuildCommand = (command, scripts = {}, depth = 0) => {
|
|
200
|
+
const direct = buildFlagsIn(command);
|
|
201
|
+
if (direct !== null) {
|
|
202
|
+
return { resolved: null, configurations: configurationsOf(direct), unresolved: false };
|
|
203
|
+
}
|
|
204
|
+
if (depth > 5) {
|
|
205
|
+
return { resolved: null, configurations: [], unresolved: true };
|
|
206
|
+
}
|
|
207
|
+
let sawScript = false;
|
|
208
|
+
const calls = command.matchAll(SCRIPT_CALL);
|
|
209
|
+
for (const match of calls) {
|
|
210
|
+
const name = match[1] ?? '';
|
|
211
|
+
if (NOT_SCRIPTS.has(name)) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
sawScript = true;
|
|
215
|
+
const script = scripts[name];
|
|
216
|
+
if (!script) {
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const inner = (0, exports.resolveBuildCommand)(script, scripts, depth + 1);
|
|
220
|
+
if (inner && !inner.unresolved) {
|
|
221
|
+
return { ...inner, resolved: inner.resolved ?? script };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
// A script that mentions "build" but cannot be followed still counts: the person should check it.
|
|
225
|
+
return sawScript && /\bbuild\b/.test(command) ? { resolved: null, configurations: [], unresolved: true } : null;
|
|
226
|
+
};
|
|
227
|
+
exports.resolveBuildCommand = resolveBuildCommand;
|
|
228
|
+
/**
|
|
229
|
+
* Which CI wrote the file. Only used to describe it: what gets scanned is the same either way, and
|
|
230
|
+
* a file nobody recognises is still read line by line rather than skipped.
|
|
231
|
+
*/
|
|
232
|
+
const kindOf = (fileName, text) => {
|
|
233
|
+
if (/gitlab-ci/.test(fileName)) {
|
|
234
|
+
return 'gitlab';
|
|
235
|
+
}
|
|
236
|
+
if (/azure-pipelines/.test(fileName) || /^\s*vmImage:/m.test(text)) {
|
|
237
|
+
return 'azure';
|
|
238
|
+
}
|
|
239
|
+
if (/bitbucket-pipelines/.test(fileName) || /^pipelines:/m.test(text)) {
|
|
240
|
+
return 'bitbucket';
|
|
241
|
+
}
|
|
242
|
+
if (/circleci/.test(fileName) || /^workflows:/m.test(text)) {
|
|
243
|
+
return 'circleci';
|
|
244
|
+
}
|
|
245
|
+
if (/jenkinsfile/i.test(fileName)) {
|
|
246
|
+
return 'jenkins';
|
|
247
|
+
}
|
|
248
|
+
if (/^jobs:/m.test(text) && /runs-on:/.test(text)) {
|
|
249
|
+
return 'github';
|
|
250
|
+
}
|
|
251
|
+
return /^stages:/m.test(text) ? 'gitlab' : 'unknown';
|
|
252
|
+
};
|
|
253
|
+
/**
|
|
254
|
+
* Keys that structure a pipeline file rather than name a job. Without them the nearest key above a
|
|
255
|
+
* command is `script:` or `steps:` in every format, which is a label nobody recognises as a job.
|
|
256
|
+
*/
|
|
257
|
+
const NOT_JOB_KEYS = new Set([
|
|
258
|
+
'script',
|
|
259
|
+
'before_script',
|
|
260
|
+
'after_script',
|
|
261
|
+
'steps',
|
|
262
|
+
'step',
|
|
263
|
+
'jobs',
|
|
264
|
+
'stages',
|
|
265
|
+
'stage',
|
|
266
|
+
'pipelines',
|
|
267
|
+
'branches',
|
|
268
|
+
'default',
|
|
269
|
+
'definitions',
|
|
270
|
+
'run',
|
|
271
|
+
'with',
|
|
272
|
+
'env',
|
|
273
|
+
'variables',
|
|
274
|
+
'strategy',
|
|
275
|
+
'matrix',
|
|
276
|
+
'pool',
|
|
277
|
+
'trigger',
|
|
278
|
+
'workflows',
|
|
279
|
+
'parallel',
|
|
280
|
+
]);
|
|
281
|
+
/**
|
|
282
|
+
* The name of the job a line belongs to: the nearest bare key above it, indented less than the
|
|
283
|
+
* command and not one of the structural words.
|
|
284
|
+
*
|
|
285
|
+
* It used to be the key at a fixed column — 0 for GitLab, 2 for GitHub — which is the same as
|
|
286
|
+
* saying only those two formats have jobs. Every other CI came out with no job name at all, and
|
|
287
|
+
* "built by (nothing)" is indistinguishable from "not built". Hidden GitLab templates
|
|
288
|
+
* (`.build_template:`) still count: a build in a template runs in every job extending it.
|
|
289
|
+
*/
|
|
290
|
+
const jobOf = (lines, index) => {
|
|
291
|
+
const indentOf = (line) => line.length - line.trimStart().length;
|
|
292
|
+
/** GitLab and GitHub name a job with a bare key: `build:` on its own line. */
|
|
293
|
+
const key = /^(\s*)([\w.:$-]+):\s*(?:#.*)?$/;
|
|
294
|
+
/** Azure and Bitbucket declare it as a list item that carries the name: `- job: BuildWeb`. */
|
|
295
|
+
const item = /^(\s*)-\s*(?:job|deployment|stage):\s*([\w.:$-]+)\s*(?:#.*)?$/;
|
|
296
|
+
let limit = indentOf(lines[index] ?? '');
|
|
297
|
+
for (let i = index; i >= 0; i--) {
|
|
298
|
+
const line = lines[i] ?? '';
|
|
299
|
+
const declared = item.exec(line);
|
|
300
|
+
if (declared && (declared[1] ?? '').length < limit) {
|
|
301
|
+
return declared[2] ?? null;
|
|
302
|
+
}
|
|
303
|
+
const match = key.exec(line);
|
|
304
|
+
if (!match || (match[1] ?? '').length >= limit) {
|
|
305
|
+
continue;
|
|
306
|
+
}
|
|
307
|
+
const name = match[2] ?? '';
|
|
308
|
+
if (!NOT_JOB_KEYS.has(name.toLowerCase())) {
|
|
309
|
+
return name;
|
|
310
|
+
}
|
|
311
|
+
// A structural key still narrows the search: whatever names this job is further out.
|
|
312
|
+
limit = (match[1] ?? '').length;
|
|
313
|
+
}
|
|
314
|
+
return null;
|
|
315
|
+
};
|
|
316
|
+
/**
|
|
317
|
+
* Every build command found in a pipeline file, with the configuration it resolves to.
|
|
318
|
+
* Comments are dropped first: a commented-out `ng build` is not a build.
|
|
319
|
+
*/
|
|
320
|
+
const readPipeline = (fileName, text, scripts = {}) => {
|
|
321
|
+
const kind = kindOf(fileName, text);
|
|
322
|
+
const lines = text.split(/\r?\n/);
|
|
323
|
+
const builds = [];
|
|
324
|
+
for (const [index, rawLine] of lines.entries()) {
|
|
325
|
+
const line = rawLine.replace(/\s#.*$/, '').replace(/^\s*#.*$/, '');
|
|
326
|
+
if (!/\b(?:build|esbuild)\b/.test(line)) {
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
// The command itself: after `- ` in a list, after the key that introduces it, or the whole
|
|
330
|
+
// line. The keys are every CI's word for "run this": GitHub says `run`, GitLab `script`,
|
|
331
|
+
// Azure `script`, Bitbucket lists them under `script` too, CircleCI says `command`.
|
|
332
|
+
const command = line
|
|
333
|
+
.replace(/^\s*-\s*/, '')
|
|
334
|
+
.replace(/^\s*(?:run|script|before_script|after_script|commands?|steps?|bash|pwsh):\s*/, '')
|
|
335
|
+
.trim();
|
|
336
|
+
if (!command || /^[\w-]+:$/.test(command)) {
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const resolution = (0, exports.resolveBuildCommand)(command, scripts);
|
|
340
|
+
if (!resolution) {
|
|
341
|
+
continue;
|
|
342
|
+
}
|
|
343
|
+
builds.push({ job: jobOf(lines, index), command, ...resolution });
|
|
344
|
+
}
|
|
345
|
+
return { file: fileName, kind, builds, text };
|
|
346
|
+
};
|
|
347
|
+
exports.readPipeline = readPipeline;
|
|
348
|
+
// --- What the context says, once put together ---------------------------------------------------
|
|
349
|
+
/**
|
|
350
|
+
* One row per configuration: which initial budget applies to it and who builds it. `ng build`
|
|
351
|
+
* with no flag builds the default configuration.
|
|
352
|
+
*/
|
|
353
|
+
const configurationBudgets = (context) => {
|
|
354
|
+
const angular = context.angular;
|
|
355
|
+
if (!angular) {
|
|
356
|
+
return [];
|
|
357
|
+
}
|
|
358
|
+
const base = angular.baseBudgets.find(budget => (0, exports.isInitialBudget)(budget)) ?? null;
|
|
359
|
+
const builtBy = new Map();
|
|
360
|
+
const register = (target, job) => {
|
|
361
|
+
if (!target) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
const jobs = builtBy.get(target) ?? [];
|
|
365
|
+
if (!jobs.includes(job)) {
|
|
366
|
+
jobs.push(job);
|
|
367
|
+
}
|
|
368
|
+
builtBy.set(target, jobs);
|
|
369
|
+
};
|
|
370
|
+
for (const pipeline of context.pipelines) {
|
|
371
|
+
const followed = pipeline.builds.filter(build => !build.unresolved);
|
|
372
|
+
for (const build of followed) {
|
|
373
|
+
const targets = build.configurations.length > 0 ? build.configurations : [angular.defaultConfiguration ?? ''];
|
|
374
|
+
for (const target of targets) {
|
|
375
|
+
register(target, build.job ?? pipeline.file);
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
return angular.configurations.map(config => {
|
|
380
|
+
const own = config.budgets.find(budget => (0, exports.isInitialBudget)(budget)) ?? null;
|
|
381
|
+
const budget = own ?? base;
|
|
382
|
+
return {
|
|
383
|
+
name: config.name,
|
|
384
|
+
warning: budget?.warning ?? null,
|
|
385
|
+
error: budget?.error ?? null,
|
|
386
|
+
hasBudget: !!budget && (budget.warning !== null || budget.error !== null),
|
|
387
|
+
builtBy: builtBy.get(config.name) ?? [],
|
|
388
|
+
};
|
|
389
|
+
});
|
|
390
|
+
};
|
|
391
|
+
exports.configurationBudgets = configurationBudgets;
|
|
392
|
+
/** Whether any pipeline loaded has at least one build command that could be followed. */
|
|
393
|
+
const pipelineKnown = (context) => context.pipelines.some(pipeline => pipeline.builds.some(build => !build.unresolved));
|
|
394
|
+
exports.pipelineKnown = pipelineKnown;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Which npm packages are third-party services rather than parts of the application.
|
|
4
|
+
*
|
|
5
|
+
* It is a list, and a list is the wrong tool for most of what this project does — the rules
|
|
6
|
+
* elsewhere read conventions, never names, because a name list is right for the libraries in
|
|
7
|
+
* fashion today and wrong for the one released next year. Here the list **is** the fact: there is
|
|
8
|
+
* nothing about the shape of `@sentry/browser` that says "error capture", and the question being
|
|
9
|
+
* asked — how much of your first load is analytics, ads, support chat and error capture — cannot be
|
|
10
|
+
* answered from structure.
|
|
11
|
+
*
|
|
12
|
+
* So it is a list, kept short, kept honest about being incomplete, and updatable in one commit. It
|
|
13
|
+
* consults nothing: the alternative — asking npm what a package is — would mean sending the
|
|
14
|
+
* dependency list of a private application out to the network, which this tool does not do.
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.categoryOf = void 0;
|
|
18
|
+
/** Category → the package names, or scopes, that belong to it. A scope ends in `/`. */
|
|
19
|
+
const CATALOG = {
|
|
20
|
+
analytics: [
|
|
21
|
+
'@amplitude/',
|
|
22
|
+
'@segment/',
|
|
23
|
+
'@vercel/analytics',
|
|
24
|
+
'analytics',
|
|
25
|
+
'ga-gtag',
|
|
26
|
+
'gtag',
|
|
27
|
+
'mixpanel-browser',
|
|
28
|
+
'posthog-js',
|
|
29
|
+
'plausible-tracker',
|
|
30
|
+
'react-ga',
|
|
31
|
+
'react-ga4',
|
|
32
|
+
'vue-gtag',
|
|
33
|
+
'@snowplow/',
|
|
34
|
+
'matomo-tracker',
|
|
35
|
+
'heap-analytics',
|
|
36
|
+
],
|
|
37
|
+
ads: ['@google/adsense', 'react-adsense', 'prebid.js', 'adsbygoogle'],
|
|
38
|
+
support: ['@intercom/', 'intercom-client', 'react-intercom', 'crisp-sdk-web', 'zendesk', '@zendesk/', 'tawk.to'],
|
|
39
|
+
errors: [
|
|
40
|
+
'@sentry/',
|
|
41
|
+
'bugsnag-js',
|
|
42
|
+
'@bugsnag/',
|
|
43
|
+
'rollbar',
|
|
44
|
+
'@datadog/browser-rum',
|
|
45
|
+
'@datadog/browser-logs',
|
|
46
|
+
'logrocket',
|
|
47
|
+
'trackjs',
|
|
48
|
+
'@newrelic/browser-agent',
|
|
49
|
+
'raygun4js',
|
|
50
|
+
],
|
|
51
|
+
experiments: ['@optimizely/', 'launchdarkly-js-client-sdk', 'unleash-proxy-client', '@growthbook/', 'splitio'],
|
|
52
|
+
session: ['hotjar', '@hotjar/browser', 'fullstory', '@fullstory/browser', 'smartlook-client', 'clarity-js'],
|
|
53
|
+
payments: ['@stripe/', 'braintree-web', '@paypal/', 'square'],
|
|
54
|
+
maps: ['@googlemaps/', 'mapbox-gl', 'leaflet', 'google-map-react'],
|
|
55
|
+
social: ['react-share', 'react-facebook', 'twitter-widgets'],
|
|
56
|
+
};
|
|
57
|
+
/** The category a package belongs to, or `null` when it is not one of these. */
|
|
58
|
+
const categoryOf = (pkg) => {
|
|
59
|
+
for (const [category, names] of Object.entries(CATALOG)) {
|
|
60
|
+
const hit = names.some(name => (name.endsWith('/') ? pkg.startsWith(name) : pkg === name));
|
|
61
|
+
if (hit) {
|
|
62
|
+
return category;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return null;
|
|
66
|
+
};
|
|
67
|
+
exports.categoryOf = categoryOf;
|