@bymaksym/loadline 1.0.0 → 1.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.
Files changed (112) hide show
  1. package/README.md +229 -43
  2. package/dist/cli/cli/args.js +79 -128
  3. package/dist/cli/cli/gates.js +80 -14
  4. package/dist/cli/cli/main.js +164 -33
  5. package/dist/cli/cli/memory.js +40 -4
  6. package/dist/cli/cli/{declared.js → read/declared.js} +1 -1
  7. package/dist/cli/cli/read/locate.js +214 -0
  8. package/dist/cli/cli/{read-build.js → read/read-build.js} +149 -84
  9. package/dist/cli/cli/read/read-config.js +120 -0
  10. package/dist/cli/cli/{html-report.js → render/html-report.js} +14 -10
  11. package/dist/cli/cli/render/render-agent.js +114 -0
  12. package/dist/cli/cli/render/render-asked.js +104 -0
  13. package/dist/cli/cli/render/render-badge.js +140 -0
  14. package/dist/cli/cli/{render-json.js → render/render-json.js} +18 -5
  15. package/dist/cli/cli/{render-markdown.js → render/render-markdown.js} +5 -5
  16. package/dist/cli/cli/{render-pr.js → render/render-pr.js} +33 -13
  17. package/dist/cli/cli/{render-sarif.js → render/render-sarif.js} +8 -3
  18. package/dist/cli/cli/{render-text.js → render/render-text.js} +118 -111
  19. package/dist/cli/cli/render/terminal.js +55 -0
  20. package/dist/cli/cli/report.js +68 -27
  21. package/dist/cli/cli/self-check.js +19 -23
  22. package/dist/cli/cli/since-last.js +2 -2
  23. package/dist/cli/cli/text/text-errors.js +124 -0
  24. package/dist/cli/cli/text/text.js +343 -0
  25. package/dist/cli/cli/text/usage.js +240 -0
  26. package/dist/cli/src/app/core/analysis/analysis.js +63 -23
  27. package/dist/cli/src/app/core/analysis/{barrels.js → graph/barrels.js} +1 -1
  28. package/dist/cli/src/app/core/analysis/{blast.js → graph/blast.js} +56 -17
  29. package/dist/cli/src/app/core/analysis/{cycles.js → graph/cycles.js} +1 -1
  30. package/dist/cli/src/app/core/analysis/{importers.js → graph/importers.js} +1 -1
  31. package/dist/cli/src/app/core/analysis/{insights.js → graph/insights.js} +10 -4
  32. package/dist/cli/src/app/core/analysis/invariant.js +1 -1
  33. package/dist/cli/src/app/core/analysis/metafile.types.js +7 -1
  34. package/dist/cli/src/app/core/analysis/{delivery.js → screens/delivery.js} +1 -1
  35. package/dist/cli/src/app/core/analysis/{entries.js → screens/entries.js} +50 -9
  36. package/dist/cli/src/app/core/analysis/screens/marks.js +32 -0
  37. package/dist/cli/src/app/core/analysis/screens/route-files.js +116 -0
  38. package/dist/cli/src/app/core/analysis/{sourcemap.js → sourcemap/sourcemap.js} +106 -7
  39. package/dist/cli/src/app/core/analysis/{split-drift.js → sourcemap/split-drift.js} +1 -1
  40. package/dist/cli/src/app/core/analysis/tool.js +83 -0
  41. package/dist/cli/src/app/core/assets/assets.js +134 -15
  42. package/dist/cli/src/app/core/baseline/baseline.js +0 -0
  43. package/dist/cli/src/app/core/{intake → build-text}/index-html.js +168 -13
  44. package/dist/cli/src/app/core/build-text/route-table.js +178 -0
  45. package/dist/cli/src/app/core/build-text/tool-marks.js +54 -0
  46. package/dist/cli/src/app/core/caching/caching.js +121 -43
  47. package/dist/cli/src/app/core/caching/from-analysis.js +20 -4
  48. package/dist/cli/src/app/core/config/config-text.js +90 -0
  49. package/dist/cli/src/app/core/config/config-values.js +358 -0
  50. package/dist/cli/src/app/core/config/loadline-config.js +81 -16
  51. package/dist/cli/src/app/core/config/merge-config.js +98 -0
  52. package/dist/cli/src/app/core/deps/deps.js +104 -16
  53. package/dist/cli/src/app/core/export/summary.js +29 -5
  54. package/dist/cli/src/app/core/findings/actions.js +3 -1
  55. package/dist/cli/src/app/core/findings/{boot-single.js → bundle/boot-single.js} +3 -3
  56. package/dist/cli/src/app/core/findings/{dupes.js → bundle/dupes.js} +8 -5
  57. package/dist/cli/src/app/core/findings/{graph.js → bundle/graph.js} +30 -18
  58. package/dist/cli/src/app/core/findings/{own-in-boot.js → bundle/own-in-boot.js} +9 -5
  59. package/dist/cli/src/app/core/findings/{requests.js → bundle/requests.js} +3 -3
  60. package/dist/cli/src/app/core/findings/{shipped.js → bundle/shipped.js} +28 -14
  61. package/dist/cli/src/app/core/findings/compose.js +6 -1
  62. package/dist/cli/src/app/core/findings/effort.js +2 -0
  63. package/dist/cli/src/app/core/findings/finding.types.js +1 -0
  64. package/dist/cli/src/app/core/findings/findings.js +48 -19
  65. package/dist/cli/src/app/core/findings/{assets.js → folder/assets.js} +38 -14
  66. package/dist/cli/src/app/core/findings/{caching.js → folder/caching.js} +16 -9
  67. package/dist/cli/src/app/core/findings/{page.js → folder/page.js} +6 -2
  68. package/dist/cli/src/app/core/findings/{scan.js → folder/scan.js} +25 -11
  69. package/dist/cli/src/app/core/findings/kind-names.js +163 -0
  70. package/dist/cli/src/app/core/findings/{deps.js → supplied/deps.js} +13 -8
  71. package/dist/cli/src/app/core/findings/supplied/forbidden.js +71 -0
  72. package/dist/cli/src/app/core/findings/{situation.js → supplied/situation.js} +2 -2
  73. package/dist/cli/src/app/core/findings/text/causes.js +39 -0
  74. package/dist/cli/src/app/core/findings/{finding-html.js → text/finding-html.js} +8 -1
  75. package/dist/cli/src/app/core/findings/{finding-text.js → text/finding-text.js} +208 -77
  76. package/dist/cli/src/app/core/findings/text/tool-advice.js +97 -0
  77. package/dist/cli/src/app/core/format/format.utils.js +158 -11
  78. package/dist/cli/src/app/core/format/ownership.js +93 -0
  79. package/dist/cli/src/app/core/i18n/en.js +76 -17
  80. package/dist/cli/src/app/core/i18n/es.js +82 -22
  81. package/dist/cli/src/app/core/intake/bundle-graph.js +281 -43
  82. package/dist/cli/src/app/core/intake/dist-files.js +82 -14
  83. package/dist/cli/src/app/core/intake/embedded.js +11 -1
  84. package/dist/cli/src/app/core/intake/unreached.js +139 -0
  85. package/dist/cli/src/app/core/intake/webpack-modules.js +185 -0
  86. package/dist/cli/src/app/core/intake/webpack-stats.js +298 -0
  87. package/dist/cli/src/app/core/project/project-context.js +16 -4
  88. package/dist/cli/src/app/core/project/project-name.js +36 -0
  89. package/dist/cli/src/app/core/scan/scan.js +58 -19
  90. package/dist/cli/src/app/core/scan/secrets.js +23 -3
  91. package/dist/cli/src/app/core/situation/situation-text.js +23 -0
  92. package/dist/cli/src/app/core/situation/situation.js +6 -4
  93. package/dist/cli/src/app/core/timing/timing.js +5 -2
  94. package/dist/cli/src/app/core/whatif/defer.js +29 -4
  95. package/dist/cli/src/app/core/whatif/source-importers.js +58 -0
  96. package/dist/cli/src/app/core/whatif/why.js +102 -0
  97. package/docs/CONFIG-REFERENCE.md +230 -0
  98. package/docs/CONFIG.md +511 -0
  99. package/docs/HOW-IT-WORKS.md +286 -25
  100. package/loadline.html +24 -20
  101. package/loadline.schema.json +1209 -0
  102. package/package.json +35 -29
  103. package/dist/cli/cli/locate.js +0 -60
  104. package/dist/cli/cli/text.js +0 -215
  105. /package/dist/cli/cli/{read-build.types.js → read/read-build.types.js} +0 -0
  106. /package/dist/cli/cli/{render-json.types.js → render/render-json.types.js} +0 -0
  107. /package/dist/cli/cli/{text.types.js → text/text.types.js} +0 -0
  108. /package/dist/cli/src/app/core/analysis/{exclusive.js → graph/exclusive.js} +0 -0
  109. /package/dist/cli/src/app/core/analysis/{insights.types.js → graph/insights.types.js} +0 -0
  110. /package/dist/cli/src/app/core/analysis/{module-graph.js → graph/module-graph.js} +0 -0
  111. /package/dist/cli/src/app/core/analysis/{sourcemap.types.js → sourcemap/sourcemap.types.js} +0 -0
  112. /package/dist/cli/src/app/core/findings/{finding-plain.js → text/finding-plain.js} +0 -0
@@ -1,12 +1,43 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.pageCssOf = exports.sniff = exports.bundleFilesOf = exports.brotliSizes = exports.gzipSizes = exports.gzipSize = exports.isLockName = exports.isContextName = exports.hashOf = exports.isSearchable = exports.isAsset = void 0;
4
- const metafile_types_1 = require("../analysis/metafile.types");
3
+ exports.pageCssOf = exports.sniff = exports.bundleFilesOf = exports.withGzipFallback = exports.brotliSizes = exports.gzipSizes = exports.pathInside = exports.gzipSize = exports.isLockName = exports.isContextName = exports.hashOf = exports.isSearchable = exports.droppedStats = exports.statsFileIn = exports.STATS_NAMES = exports.isAsset = void 0;
5
4
  const baseline_1 = require("../baseline/baseline");
6
5
  const loadline_config_1 = require("../config/loadline-config");
6
+ const embedded_1 = require("./embedded");
7
+ const webpack_stats_1 = require("./webpack-stats");
7
8
  /** The files that make up the build output, the only ones worth compressing. */
8
9
  const isAsset = (name) => /\.(?:m?js|css)$/i.test(name);
9
10
  exports.isAsset = isAsset;
11
+ /**
12
+ * What a build's stats file is called, newest first: Angular's metafile from 22.2 and before it,
13
+ * the webpack stats Angular 8 to 11 write with differential loading, Create React App's `--stats`
14
+ * and Vue CLI's `--report-json`. The page and the command look for the same names; a name says
15
+ * where to look, and the content still decides (`metafileOf`).
16
+ */
17
+ exports.STATS_NAMES = [
18
+ 'browser-stats.json',
19
+ 'stats.json',
20
+ 'stats-es2015.json',
21
+ 'bundle-stats.json',
22
+ 'report.json',
23
+ ];
24
+ /** The stats file among some files, by the order of `STATS_NAMES`. */
25
+ const statsFileIn = (files) => {
26
+ for (const name of exports.STATS_NAMES) {
27
+ const found = files.find(file => file.name === name);
28
+ if (found) {
29
+ return found;
30
+ }
31
+ }
32
+ return null;
33
+ };
34
+ exports.statsFileIn = statsFileIn;
35
+ /** The same among dropped files, when it is one: a `report.json` that is no stats file stays a file. */
36
+ const droppedStats = async (files) => {
37
+ const named = (0, exports.statsFileIn)(files);
38
+ return named && (await (0, exports.sniff)(named)) === 'stats' ? named : null;
39
+ };
40
+ exports.droppedStats = droppedStats;
10
41
  /**
11
42
  * Files worth reading as text, to find which names anything in the folder mentions.
12
43
  *
@@ -24,6 +55,11 @@ exports.isSearchable = isSearchable;
24
55
  * the report says so, rather than reporting "no duplicates" and meaning "nobody looked".
25
56
  */
26
57
  const hashOf = async (file) => {
58
+ // A report written by `--html` brings the hash instead of the bytes.
59
+ const known = (0, embedded_1.knownHashOf)(file);
60
+ if (known) {
61
+ return known;
62
+ }
27
63
  // Read as possibly absent: `crypto.subtle` is undefined outside a secure context (a page opened
28
64
  // over plain http), whatever lib.dom says.
29
65
  const subtle = crypto.subtle;
@@ -70,14 +106,27 @@ const gzipSize = async (file) => {
70
106
  return size;
71
107
  };
72
108
  exports.gzipSize = gzipSize;
73
- /** Every asset of the folder, compressed. Keyed by file name, which is how the metafile names them. */
74
- const gzipSizes = async (files, onProgress) => {
109
+ /**
110
+ * Where a picked file sits inside the folder: `browser/assets/a.js` picked as `browser` is
111
+ * `assets/a.js`. The file name when the browser gave no path.
112
+ */
113
+ const pathInside = (file) => (file.webkitRelativePath || '').split('/').slice(1).join('/') || file.name;
114
+ exports.pathInside = pathInside;
115
+ /**
116
+ * Every asset of the folder, compressed. Keyed by file name, which is how the metafile names them.
117
+ *
118
+ * @param byPath filled with the same figures by path inside the folder, for the files that share a
119
+ * name: keyed by name, 25 `plugin.min.js` all weigh the last one compressed.
120
+ */
121
+ const gzipSizes = async (files, onProgress, byPath) => {
75
122
  const sizes = new Map();
76
- for (const file of files) {
77
- sizes.set(file.name, await (0, exports.gzipSize)(file));
123
+ for (const [index, file] of files.entries()) {
124
+ const size = await (0, exports.gzipSize)(file);
125
+ sizes.set(file.name, size);
126
+ byPath?.set((0, exports.pathInside)(file), size);
78
127
  // Tens of megabytes go through here one file at a time, and the page used to say nothing
79
128
  // about it beyond one line of grey text that never changed.
80
- onProgress?.(sizes.size, files.length);
129
+ onProgress?.(index + 1, files.length);
81
130
  }
82
131
  return sizes;
83
132
  };
@@ -86,19 +135,41 @@ exports.gzipSizes = gzipSizes;
86
135
  * Sizes of the pre-compressed files of the folder. Nothing has to be decompressed: the size of a
87
136
  * `.br` file *is* the brotli figure.
88
137
  */
89
- const brotliSizes = (files) => {
138
+ const brotliSizes = (files, byPath = false) => {
90
139
  const sizes = new Map();
91
140
  for (const file of files) {
92
141
  // `.br` is what every server and every plugin writes; `.brotli` turns up often enough that
93
142
  // not reading it means silently showing gzip figures on a folder that had brotli ones.
94
143
  const found = /^(.*\.(?:m?js|css))\.(?:br|brotli)$/i.exec(file.name);
95
144
  if (found?.[1]) {
96
- sizes.set(found[1], file.size);
145
+ sizes.set(byPath ? (0, exports.pathInside)(file).replace(/\.(?:br|brotli)$/i, '') : found[1], file.size);
97
146
  }
98
147
  }
99
148
  return sizes;
100
149
  };
101
150
  exports.brotliSizes = brotliSizes;
151
+ /**
152
+ * The brotli figures with a gzip one wherever a file brought no `.br` of its own.
153
+ *
154
+ * Pre-compressing plugins skip small files — vite-plugin-compression below 1 kB — and the server
155
+ * then sends that file the way it sends anything else, gzip. Without this a file with no `.br` was
156
+ * missing from the brotli figures, and the analysis reads "not in the figures" as "not a file of
157
+ * this folder": a Vue build lost `runtime-core` from its bootstrap (18 kB instead of 40) and a whole
158
+ * screen from its table, under a line calling it the server side of a rendered build.
159
+ */
160
+ const withGzipFallback = (brotli, gzip) => {
161
+ const complete = new Map(brotli);
162
+ if (complete.size === 0) {
163
+ return complete;
164
+ }
165
+ for (const [name, bytes] of gzip) {
166
+ if (!complete.has(name)) {
167
+ complete.set(name, bytes);
168
+ }
169
+ }
170
+ return complete;
171
+ };
172
+ exports.withGzipFallback = withGzipFallback;
102
173
  /**
103
174
  * The picked folder as the folder reader takes it: each file with its path **inside** the folder.
104
175
  *
@@ -106,10 +177,7 @@ exports.brotliSizes = brotliSizes;
106
177
  * happened to pick; what a chunk writing `./sibling.js` means is `assets/sibling.js`, from the root
107
178
  * of the build. Dropping the first segment is what makes the two line up.
108
179
  */
109
- const bundleFilesOf = (files) => files.map(file => {
110
- const inside = (file.webkitRelativePath || '').split('/').slice(1).join('/');
111
- return { path: inside || file.name, bytes: file.size, text: () => file.text() };
112
- });
180
+ const bundleFilesOf = (files) => files.map(file => ({ path: (0, exports.pathInside)(file), bytes: file.size, text: () => file.text() }));
113
181
  exports.bundleFilesOf = bundleFilesOf;
114
182
  /** What a dropped file is, without loading it. Cheap: reads the name, then the JSON if needed. */
115
183
  const sniff = async (file) => {
@@ -132,7 +200,7 @@ const sniff = async (file) => {
132
200
  if ((0, loadline_config_1.isLoadlineConfig)(parsed)) {
133
201
  return 'config';
134
202
  }
135
- if ((0, metafile_types_1.isMetafile)(parsed)) {
203
+ if ((0, webpack_stats_1.metafileOf)(parsed)) {
136
204
  return 'stats';
137
205
  }
138
206
  // An audit report has no name of its own — people redirect it to whatever they like — so it
@@ -7,7 +7,7 @@
7
7
  * have handed over, and from there everything goes through the doors it always went through.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.filesOf = exports.isEmbeddedBuild = void 0;
10
+ exports.filesOf = exports.knownHashOf = exports.isEmbeddedBuild = void 0;
11
11
  const json_utils_1 = require("../json/json.utils");
12
12
  const isEmbeddedBuild = (value) => {
13
13
  const record = (0, json_utils_1.asRecord)(value);
@@ -33,6 +33,13 @@ const bytesOf = (file) => {
33
33
  }
34
34
  return bytes;
35
35
  };
36
+ /**
37
+ * The hashes that came with the build, for the stand-ins that carry no content of their own. Read
38
+ * by `hashOf` before it reads any bytes: hashing the filler would compare paths, not files.
39
+ */
40
+ const KNOWN_HASHES = new WeakMap();
41
+ const knownHashOf = (file) => KNOWN_HASHES.get(file) ?? null;
42
+ exports.knownHashOf = knownHashOf;
36
43
  /**
37
44
  * The folder as a folder picker would have handed it over: each `File` carries the path it had
38
45
  * under the folder, which is what tells `orders/index.html` from `settings/index.html`.
@@ -41,6 +48,9 @@ const filesOf = (folder) => folder.files.map(file => {
41
48
  const name = file.path.split('/').at(-1) ?? file.path;
42
49
  const made = new File([file.text ?? bytesOf(file)], name);
43
50
  Object.defineProperty(made, 'webkitRelativePath', { value: `${folder.name}/${file.path}` });
51
+ if (file.sha256) {
52
+ KNOWN_HASHES.set(made, file.sha256);
53
+ }
44
54
  return made;
45
55
  });
46
56
  exports.filesOf = filesOf;
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+ /**
3
+ * What a folder holds that no import reaches, and what to make of it.
4
+ *
5
+ * The graph read out of the chunks (`bundle-graph.ts`) has every edge an `import` writes. A build
6
+ * also holds files no `import` names: chunks a loader older than `import()` finds by an id, the
7
+ * copy for browsers without ES modules, a service worker, the leftovers of an old build. Each of
8
+ * them used to land in "nothing reaches these", and the first kind cost whole applications their
9
+ * screens. This file tells them apart, and only ever touches what the imports left over — a build
10
+ * every chunk of which is already reached comes out exactly as it did.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.offPageOf = exports.lazyByName = exports.reachOver = exports.mentionedBy = exports.mentionKeysOf = void 0;
14
+ const format_utils_1 = require("../format/format.utils");
15
+ const JS_FILE = /\.m?js$/i;
16
+ /**
17
+ * The names a string can call a chunk by, each to the files it could mean.
18
+ *
19
+ * The file name with and without its extension, and — when it looks like a hash rather than a word
20
+ * — the part before the first dot: Stencil lists its components as `"p-w91mnxr1"` and loads
21
+ * `p-w91mnxr1.entry.js`. A plain word (`index`, `polyfills`, `vendor`) is never a key: it is what
22
+ * every bundle says in passing, and a match on it would tie two files that have nothing to do with
23
+ * each other.
24
+ */
25
+ const mentionKeysOf = (paths) => {
26
+ const keys = new Map();
27
+ const add = (key, path) => {
28
+ const known = keys.get(key) ?? [];
29
+ if (!known.includes(path)) {
30
+ keys.set(key, [...known, path]);
31
+ }
32
+ };
33
+ for (const path of paths) {
34
+ const name = (0, format_utils_1.baseName)(path);
35
+ const bare = name.replace(JS_FILE, '');
36
+ add(name, path);
37
+ const stem = bare.split('.', 1)[0] ?? '';
38
+ if (stem.length >= 8 && /[\d\-_]/.test(stem) && stem !== bare) {
39
+ add(stem, path);
40
+ }
41
+ if (/[\d\-_.]/.test(bare)) {
42
+ add(bare, path);
43
+ }
44
+ }
45
+ return keys;
46
+ };
47
+ exports.mentionKeysOf = mentionKeysOf;
48
+ /** The file a string inside a chunk names, by the keys of `mentionKeysOf`; `null` when none or several. */
49
+ const mentionedBy = (literal, keys) => {
50
+ const name = (0, format_utils_1.baseName)(literal.replace(/[?#].*$/, ''));
51
+ const found = keys.get(name);
52
+ return found?.length === 1 ? (found[0] ?? null) : null;
53
+ };
54
+ exports.mentionedBy = mentionedBy;
55
+ /** Every chunk reachable from `seeds` over its imports, static and lazy, and over `extra` when asked. */
56
+ const reachOver = (read, seeds, extra = () => []) => {
57
+ const seen = new Set();
58
+ const stack = [...seeds];
59
+ while (stack.length > 0) {
60
+ const chunk = stack.pop() ?? '';
61
+ const info = read.get(chunk);
62
+ if (!info || seen.has(chunk)) {
63
+ continue;
64
+ }
65
+ seen.add(chunk);
66
+ stack.push(...info.statics, ...info.dynamics.map(entry => entry.target), ...extra(info));
67
+ }
68
+ return seen;
69
+ };
70
+ exports.reachOver = reachOver;
71
+ /**
72
+ * The last way in: a chunk no import reaches, named in a plain string by a chunk the application
73
+ * does reach, is taken as loaded on demand by it.
74
+ *
75
+ * It is what a loader older than `import()`, or one that builds the name at run time, leaves to
76
+ * read. Stencil's entry lists its components as `["p-w91mnxr1", …]` and loads them with
77
+ * ``import(`./${id}.entry.js`)``; Polymer's AMD build loads its views with `require(["./my-view1.js"])`
78
+ * under a name the minifier chose. Without it a Stencil app read as zero screens with 33 of its 36
79
+ * chunks "in no figure here", and a Polymer one as a 2 kB loader and nothing else.
80
+ *
81
+ * It only ever touches what nothing else reached, so a build every chunk of which is already
82
+ * accounted for — any Vite, Rollup or esbuild build — comes out exactly as it did before. And it is
83
+ * repeated, because a component reached this way can name the next one.
84
+ *
85
+ * @param held files no string may pull in: the `nomodule` copy and the service workers, which are
86
+ * named in the code of the page on purpose and are no part of a screen.
87
+ * @returns the chunks it added, each now a lazy target of the chunk that named it.
88
+ */
89
+ const lazyByName = (read, roots, held) => {
90
+ const added = new Set();
91
+ for (let reached = (0, exports.reachOver)(read, roots), grew = true; grew; reached = (0, exports.reachOver)(read, roots)) {
92
+ grew = false;
93
+ for (const chunk of reached) {
94
+ const info = read.get(chunk);
95
+ const mentioned = info?.mentions ?? [];
96
+ for (const target of mentioned) {
97
+ if (reached.has(target) || held.has(target) || added.has(target)) {
98
+ continue;
99
+ }
100
+ info?.dynamics.push({ target, from: null });
101
+ added.add(target);
102
+ grew = true;
103
+ }
104
+ }
105
+ }
106
+ return added;
107
+ };
108
+ exports.lazyByName = lazyByName;
109
+ /** A file of Ember's server-side renderer, by its name. */
110
+ const FASTBOOT = /(?:^|[-_.])fastboot[-_.]/i;
111
+ /**
112
+ * Files of the build no screen downloads, and why: what only the `nomodule` scripts reach is the
113
+ * copy for browsers without ES modules, and what only a service worker reaches runs beside the page.
114
+ * Whatever the application itself reaches stays in, whoever else reaches it too.
115
+ */
116
+ const offPageOf = (read, roots, legacyRoots, workerRoots) => {
117
+ const modern = (0, exports.reachOver)(read, roots);
118
+ const offPage = new Map();
119
+ const withMentions = (info) => info.mentions;
120
+ for (const chunk of (0, exports.reachOver)(read, legacyRoots, withMentions)) {
121
+ if (!modern.has(chunk)) {
122
+ offPage.set(chunk, 'legacy');
123
+ }
124
+ }
125
+ for (const chunk of (0, exports.reachOver)(read, workerRoots)) {
126
+ if (!modern.has(chunk) && !offPage.has(chunk)) {
127
+ offPage.set(chunk, 'service-worker');
128
+ }
129
+ }
130
+ // Ember writes what only FastBoot runs into the folder it deploys (`fetch-fastboot-….js`,
131
+ // `auto-import-fastboot-….js`): server code, and it was listed as what nothing reaches.
132
+ for (const chunk of read.keys()) {
133
+ if (!modern.has(chunk) && !offPage.has(chunk) && FASTBOOT.test(chunk.split('/').pop() ?? chunk)) {
134
+ offPage.set(chunk, 'server');
135
+ }
136
+ }
137
+ return offPage;
138
+ };
139
+ exports.offPageOf = offPageOf;
@@ -0,0 +1,185 @@
1
+ "use strict";
2
+ /**
3
+ * The modules of a webpack `stats.json`, read: where each one is, what it is called once webpack's
4
+ * own decoration is off its name, and who imports it. `webpack-stats.ts` builds the metafile out of
5
+ * them; this is the part that has to understand how webpack writes a module down.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.importersOf = exports.requested = exports.collect = exports.textsOf = exports.idsOf = exports.modulePath = void 0;
9
+ const json_utils_1 = require("../json/json.utils");
10
+ /**
11
+ * Modules that are no file of anybody's: the list `entry: [a, b]` builds in webpack 4 (`multi …`),
12
+ * a global the page provides (`external "React"`), what `IgnorePlugin` dropped, a DLL reference and
13
+ * the plumbing of module federation. None of them is code the build ships.
14
+ */
15
+ const SYNTHETIC = /^(?:multi |external |ignored|delegated |container |remote |provide shared|consume shared)/;
16
+ /** `./src/main.ts + 50 modules`: a concatenated module, named after the one it starts at. */
17
+ const CONCATENATED = / \+ \d+ modules?$/;
18
+ /** `./src/locales lazy ^\.\/.*\.json$ namespace object`: the folder an `import()` with a variable reads. */
19
+ const CONTEXT = / (?:lazy|lazy-once|eager|weak|sync|async-weak)(?: |$)/;
20
+ /**
21
+ * A module's name as the rest of Loadline names a file: the loaders in front of it dropped (`…!./src/x.css`),
22
+ * the query of a Vue component's part (`?vue&type=script`) too, so the three parts of one `.vue`
23
+ * file are one file, and the `./` webpack starts every name with. webpack's own code — `(webpack)/…`
24
+ * in webpack 4, the runtime modules of webpack 5 — is filed under `node_modules/webpack`, which is
25
+ * what it is: a dependency, not a file of the application.
26
+ *
27
+ * `null` for a module that is no file (`SYNTHETIC`).
28
+ */
29
+ const modulePath = (name) => {
30
+ const bare = name.replace(/^css /, '');
31
+ if (SYNTHETIC.test(bare)) {
32
+ return null;
33
+ }
34
+ let path = bare.replace(CONCATENATED, '');
35
+ path = path.slice(path.lastIndexOf('!') + 1);
36
+ const context = CONTEXT.exec(path);
37
+ if (context) {
38
+ path = path.slice(0, context.index);
39
+ }
40
+ path = path.split('?', 1)[0] ?? '';
41
+ if (path.startsWith('(webpack)/')) {
42
+ path = `node_modules/webpack/${path.slice('(webpack)/'.length)}`;
43
+ }
44
+ else if (path.startsWith('webpack/runtime/')) {
45
+ path = `node_modules/${path}`;
46
+ }
47
+ path = path.replace(/^\.\//, '');
48
+ return path === '' ? null : path;
49
+ };
50
+ exports.modulePath = modulePath;
51
+ const idsOf = (value) => ((0, json_utils_1.asArray)(value) ?? []).filter(id => typeof id === 'number' || typeof id === 'string').map(String);
52
+ exports.idsOf = idsOf;
53
+ const textsOf = (value) => ((0, json_utils_1.asArray)(value) ?? []).filter((item) => typeof item === 'string');
54
+ exports.textsOf = textsOf;
55
+ /**
56
+ * Every module, wherever the stats put it: at the top (`modules: true`), inside each chunk
57
+ * (`chunkModules: true`) or both — Angular's builder writes only the second — inside a concatenated
58
+ * module (`modules`, with no chunks of their own in webpack 5, so they take the outer one's), and
59
+ * inside the groups webpack 5 makes for the terminal (`children`).
60
+ */
61
+ const collect = (raw, inherited, into, outer = null) => {
62
+ const module = (0, json_utils_1.asRecord)(raw);
63
+ if (!module) {
64
+ return;
65
+ }
66
+ const grouped = (0, json_utils_1.asArray)(module['children']);
67
+ if (grouped && typeof module['identifier'] !== 'string') {
68
+ for (const child of grouped) {
69
+ (0, exports.collect)(child, inherited, into);
70
+ }
71
+ return;
72
+ }
73
+ const own = (0, exports.idsOf)(module['chunks']);
74
+ const chunks = own.length > 0 ? own : inherited;
75
+ const nested = (0, json_utils_1.asArray)(module['modules']);
76
+ if (nested && nested.length > 0) {
77
+ for (const inner of nested) {
78
+ (0, exports.collect)(inner, chunks, into, (0, json_utils_1.asText)(module['name']));
79
+ }
80
+ return;
81
+ }
82
+ const name = (0, json_utils_1.asText)(module['name']);
83
+ const path = name ? (0, exports.modulePath)(name) : null;
84
+ if (!name || !path) {
85
+ return;
86
+ }
87
+ const key = (0, json_utils_1.asText)(module['identifier']) ?? name;
88
+ const known = into.rows.get(key);
89
+ if (known) {
90
+ for (const chunk of chunks) {
91
+ known.chunks.add(chunk);
92
+ }
93
+ return;
94
+ }
95
+ const reasons = [];
96
+ const written = (0, json_utils_1.asArray)(module['reasons']) ?? [];
97
+ for (const item of written) {
98
+ const reason = (0, json_utils_1.asRecord)(item);
99
+ const from = (0, json_utils_1.asText)(reason?.['resolvedModule']) ?? (0, json_utils_1.asText)(reason?.['moduleName']) ?? '';
100
+ const kind = (0, json_utils_1.asText)(reason?.['type']) ?? '';
101
+ // An entry has no importer, and it is the reason that says which module the entry is.
102
+ if (reason && (from || kind.endsWith('entry'))) {
103
+ reasons.push({
104
+ from,
105
+ kind,
106
+ loc: (0, json_utils_1.asText)(reason['loc']) ?? '',
107
+ request: (0, json_utils_1.asText)(reason['userRequest']) ?? '',
108
+ });
109
+ }
110
+ }
111
+ const bailout = (0, exports.textsOf)(module['optimizationBailout']).join('\n');
112
+ const issuer = (0, json_utils_1.asText)(module['issuerName']);
113
+ const row = {
114
+ path,
115
+ size: typeof module['size'] === 'number' ? module['size'] : 0,
116
+ chunks: new Set(chunks),
117
+ reasons,
118
+ style: name.startsWith('css ') || (0, json_utils_1.asText)(module['moduleType']) === 'css/mini-extract',
119
+ // What webpack could not treat as an ES module, which is what the metafile's `cjs` means.
120
+ // Code only: a JSON file is no module of either kind and is not a CommonJS package.
121
+ cjs: /\.c?js$/.test(path) && bailout.includes('not an ECMAScript module'),
122
+ issuer: issuer ? (0, exports.modulePath)(issuer) : null,
123
+ source: outer ? (0, json_utils_1.asText)(module['source']) : null,
124
+ };
125
+ into.rows.set(key, row);
126
+ if (outer) {
127
+ into.concatenated.set(outer, [...(into.concatenated.get(outer) ?? []), row]);
128
+ }
129
+ };
130
+ exports.collect = collect;
131
+ /** `import('./a')` from `src/app/routes.ts` is `src/app/a`: a name for a chunk when nothing better names it. */
132
+ const requested = (from, request) => {
133
+ const parts = from.split('/').slice(0, -1);
134
+ for (const segment of request.split('/')) {
135
+ if (segment === '..') {
136
+ parts.pop();
137
+ }
138
+ else if (segment !== '.' && segment !== '') {
139
+ parts.push(segment);
140
+ }
141
+ }
142
+ return parts.join('/');
143
+ };
144
+ exports.requested = requested;
145
+ /** `path` is the file `base` names once an extension or an `index` is added, as a resolver would. */
146
+ const resolvesTo = (base, path) => {
147
+ const bare = path.replace(/\.[^./]+$/, '');
148
+ return bare === base || bare === `${base}/index`;
149
+ };
150
+ /**
151
+ * Who really imports `imported`, when webpack says "a concatenated module" did.
152
+ *
153
+ * webpack 4 writes the reason with the name of the whole concatenation — `./src/main.ts + 20
154
+ * modules` — and taken at its word, `src/main.ts` imported everything its twenty modules import.
155
+ * An Angular 8 build came out with `main.ts` as a barrel of 26 re-exports holding 546 kB. The file
156
+ * that wrote the import is found by what it wrote: a relative path that resolves to the module from
157
+ * it, a package named in its source between quotes, or — when neither is in the stats — the module
158
+ * webpack recorded as having imported it first. With none of the three the edge is left out: an
159
+ * unknown importer is "not known" in the report, and a guessed one is a false chain.
160
+ *
161
+ * webpack 5 names the file in `resolvedModule`, which `collect` already prefers.
162
+ */
163
+ const importersOf = (reason, imported, into) => {
164
+ const from = (0, exports.modulePath)(reason.from);
165
+ const inner = into.concatenated.get(reason.from);
166
+ if (!from || !inner) {
167
+ return from ? [from] : [];
168
+ }
169
+ const { request } = reason;
170
+ if (request.startsWith('.')) {
171
+ const resolved = inner.filter(row => resolvesTo((0, exports.requested)(row.path, request), imported.path));
172
+ if (resolved.length > 0) {
173
+ return resolved.map(row => row.path);
174
+ }
175
+ }
176
+ else if (request) {
177
+ const quoting = inner.filter(row => row.source?.includes(`'${request}'`) === true || row.source?.includes(`"${request}"`) === true);
178
+ if (quoting.length > 0) {
179
+ return quoting.map(row => row.path);
180
+ }
181
+ }
182
+ const first = inner.find(row => row.path === imported.issuer);
183
+ return first ? [first.path] : [];
184
+ };
185
+ exports.importersOf = importersOf;