@nitpicker/report-html 0.21.0 → 0.22.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 +191 -0
- package/lib/collect-html-report-pages.d.ts +14 -3
- package/lib/collect-html-report-pages.js +5 -4
- package/lib/page-report-limit.d.ts +7 -0
- package/lib/page-report-limit.js +7 -0
- package/lib/report.js +23 -12
- package/lib/resolve-directory-prefixes.js +3 -3
- package/lib/resolve-page-selection.d.ts +40 -0
- package/lib/resolve-page-selection.js +51 -0
- package/lib/types.d.ts +10 -0
- package/package.json +7 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to the Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by the Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding any notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
Copyright 2025 D-ZERO Co., Ltd.
|
|
180
|
+
|
|
181
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
182
|
+
you may not use this file except in compliance with the License.
|
|
183
|
+
You may obtain a copy of the License at
|
|
184
|
+
|
|
185
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
186
|
+
|
|
187
|
+
Unless required by applicable law or agreed to in writing, software
|
|
188
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
189
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
190
|
+
See the License for the specific language governing permissions and
|
|
191
|
+
limitations under the License.
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
2
|
import type { HtmlReportPage } from '@nitpicker/viewer/report-ui';
|
|
3
|
+
/** Row-set restriction for {@link collectHtmlReportPages}. */
|
|
4
|
+
export interface CollectHtmlReportPagesOptions {
|
|
5
|
+
/** Directory-prefix filters. Empty or omitted lists every inner page. */
|
|
6
|
+
readonly directories?: readonly string[];
|
|
7
|
+
/**
|
|
8
|
+
* Exact-match URL allowlist, already normalized (see
|
|
9
|
+
* `resolvePageListUrlFilter`). ANDed with `directories` when both are
|
|
10
|
+
* given — see `PageListRowFilterOptions.urls`'s docs.
|
|
11
|
+
*/
|
|
12
|
+
readonly urls?: readonly string[];
|
|
13
|
+
}
|
|
3
14
|
/**
|
|
4
15
|
* Collects inner-page rows for a static HTML report in `natural_url_rank`
|
|
5
16
|
* order, attaching redirect sources and per-page resource-file tallies.
|
|
6
17
|
* @param accessor - Archive whose viewer read model is already current.
|
|
7
|
-
* @param
|
|
18
|
+
* @param options - Row-set restriction. Empty or omitted lists every inner page.
|
|
8
19
|
* @returns Page rows ready for `renderHtmlReport`.
|
|
9
20
|
* @example
|
|
10
|
-
* const pages = await collectHtmlReportPages(accessor, ['/docs']);
|
|
21
|
+
* const pages = await collectHtmlReportPages(accessor, { directories: ['/docs'] });
|
|
11
22
|
*/
|
|
12
|
-
export declare function collectHtmlReportPages(accessor: ArchiveAccessor,
|
|
23
|
+
export declare function collectHtmlReportPages(accessor: ArchiveAccessor, options?: CollectHtmlReportPagesOptions): Promise<HtmlReportPage[]>;
|
|
@@ -3,15 +3,15 @@ import { buildRedirectFromUrlsByDestId, getResourceFileCountsByPageIds, streamPa
|
|
|
3
3
|
* Collects inner-page rows for a static HTML report in `natural_url_rank`
|
|
4
4
|
* order, attaching redirect sources and per-page resource-file tallies.
|
|
5
5
|
* @param accessor - Archive whose viewer read model is already current.
|
|
6
|
-
* @param
|
|
6
|
+
* @param options - Row-set restriction. Empty or omitted lists every inner page.
|
|
7
7
|
* @returns Page rows ready for `renderHtmlReport`.
|
|
8
8
|
* @example
|
|
9
|
-
* const pages = await collectHtmlReportPages(accessor, ['/docs']);
|
|
9
|
+
* const pages = await collectHtmlReportPages(accessor, { directories: ['/docs'] });
|
|
10
10
|
*/
|
|
11
|
-
export async function collectHtmlReportPages(accessor,
|
|
11
|
+
export async function collectHtmlReportPages(accessor, options = {}) {
|
|
12
12
|
const redirectFrom = await buildRedirectFromUrlsByDestId(accessor);
|
|
13
13
|
const pages = [];
|
|
14
|
-
for await (const chunk of streamPageListRows(accessor,
|
|
14
|
+
for await (const chunk of streamPageListRows(accessor, options)) {
|
|
15
15
|
const counts = await getResourceFileCountsByPageIds(accessor, chunk.map((row) => row.pageId));
|
|
16
16
|
for (const row of chunk) {
|
|
17
17
|
const resources = counts.get(row.pageId) ?? { total: 0, exists: 0 };
|
|
@@ -24,6 +24,7 @@ export async function collectHtmlReportPages(accessor, directories = []) {
|
|
|
24
24
|
resourceFilesExists: resources.exists,
|
|
25
25
|
resourceFilesTotal: resources.total,
|
|
26
26
|
consoleErrorCount: row.consoleErrorCount,
|
|
27
|
+
redirectTo: row.redirectDestUrl,
|
|
27
28
|
});
|
|
28
29
|
}
|
|
29
30
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static HTML report's inner-page ceiling, shared by both page-selection
|
|
3
|
+
* paths (`resolveDirectoryPrefixes`'s interactive `--html-dirs` narrowing and
|
|
4
|
+
* `resolvePageSelection`'s non-interactive `--urls` guard) so the two can
|
|
5
|
+
* never drift to different limits.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PAGE_REPORT_LIMIT = 10000;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The static HTML report's inner-page ceiling, shared by both page-selection
|
|
3
|
+
* paths (`resolveDirectoryPrefixes`'s interactive `--html-dirs` narrowing and
|
|
4
|
+
* `resolvePageSelection`'s non-interactive `--urls` guard) so the two can
|
|
5
|
+
* never drift to different limits.
|
|
6
|
+
*/
|
|
7
|
+
export const PAGE_REPORT_LIMIT = 10_000;
|
package/lib/report.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { writeFile } from 'node:fs/promises';
|
|
2
2
|
import { TaskList } from '@d-zero/dealer';
|
|
3
|
-
import { getViewerSummary, requireViewerReadModel } from '@nitpicker/query';
|
|
3
|
+
import { getViewerSummary, requireViewerReadModel, resolveAndValidatePageListUrlFilter, warnUnmatchedPageListUrls, } from '@nitpicker/query';
|
|
4
4
|
import { renderHtmlReport } from '@nitpicker/viewer/report-ui';
|
|
5
5
|
import { collectHtmlReportPages } from './collect-html-report-pages.js';
|
|
6
6
|
import { openReportArchive } from './open-report-archive.js';
|
|
7
|
-
import { resolveDirectoryPrefixes } from './resolve-directory-prefixes.js';
|
|
8
7
|
import { resolveOutputPath } from './resolve-output-path.js';
|
|
8
|
+
import { resolvePageSelection } from './resolve-page-selection.js';
|
|
9
9
|
/** A `write()`-only sink that renders nothing, for `params.silent`. */
|
|
10
10
|
const NULL_STREAM = {
|
|
11
11
|
write: () => true,
|
|
@@ -33,24 +33,32 @@ const NULL_STREAM = {
|
|
|
33
33
|
export async function report(params) {
|
|
34
34
|
await using archive = await openReportArchive(params.filePath, params.onExtractProgress);
|
|
35
35
|
await requireViewerReadModel(archive.accessor);
|
|
36
|
-
const
|
|
36
|
+
const warn = params.silent
|
|
37
|
+
? () => { }
|
|
38
|
+
: (message) => {
|
|
39
|
+
// eslint-disable-next-line no-console
|
|
40
|
+
console.warn(message);
|
|
41
|
+
};
|
|
42
|
+
const normalizedUrls = params.urls === undefined
|
|
43
|
+
? undefined
|
|
44
|
+
: await resolveAndValidatePageListUrlFilter(archive.accessor, params.urls, warn);
|
|
45
|
+
const selection = await resolvePageSelection({
|
|
37
46
|
accessor: archive.accessor,
|
|
38
|
-
|
|
47
|
+
directoryInput: params.directoryInput,
|
|
48
|
+
urls: normalizedUrls,
|
|
39
49
|
interactive: params.interactive === true,
|
|
40
|
-
onWarn:
|
|
41
|
-
? () => { }
|
|
42
|
-
: (message) => {
|
|
43
|
-
// eslint-disable-next-line no-console
|
|
44
|
-
console.warn(message);
|
|
45
|
-
},
|
|
50
|
+
onWarn: warn,
|
|
46
51
|
});
|
|
47
|
-
const directoryPrefixes =
|
|
52
|
+
const directoryPrefixes = selection.directories;
|
|
48
53
|
const outputPath = resolveOutputPath(params.filePath, params.outputPath);
|
|
49
54
|
let html = '';
|
|
50
55
|
let pipeline = TaskList.from(0);
|
|
51
56
|
pipeline = pipeline.pipe('Collect pages', async (input, ctx) => {
|
|
52
57
|
ctx.progress('reading inner pages...');
|
|
53
|
-
const pages = await collectHtmlReportPages(archive.accessor,
|
|
58
|
+
const pages = await collectHtmlReportPages(archive.accessor, {
|
|
59
|
+
directories: directoryPrefixes,
|
|
60
|
+
urls: selection.urls,
|
|
61
|
+
});
|
|
54
62
|
const summary = await getViewerSummary(archive.accessor);
|
|
55
63
|
ctx.progress(`${pages.length.toLocaleString()} pages`);
|
|
56
64
|
html = renderHtmlReport({
|
|
@@ -60,6 +68,9 @@ export async function report(params) {
|
|
|
60
68
|
generatedAt: new Date().toISOString(),
|
|
61
69
|
directoryPrefixes,
|
|
62
70
|
});
|
|
71
|
+
if (selection.urls) {
|
|
72
|
+
await warnUnmatchedPageListUrls(archive.accessor, selection.urls, warn);
|
|
73
|
+
}
|
|
63
74
|
return input;
|
|
64
75
|
});
|
|
65
76
|
pipeline = pipeline.pipe('Write HTML', async (input, ctx) => {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { countPageListHostnames, countPageListRows } from '@nitpicker/query';
|
|
2
2
|
import enquirer from 'enquirer';
|
|
3
3
|
import { HtmlReportCancelledError } from './html-report-cancelled-error.js';
|
|
4
|
+
import { PAGE_REPORT_LIMIT } from './page-report-limit.js';
|
|
4
5
|
import { parseDirectoryInput } from './parse-directory-input.js';
|
|
5
|
-
const PAGE_LIMIT = 10_000;
|
|
6
6
|
/**
|
|
7
7
|
* Asks for comma-separated directory prefixes on a TTY.
|
|
8
8
|
* @returns The raw input string.
|
|
@@ -40,7 +40,7 @@ export async function resolveDirectoryPrefixes(options) {
|
|
|
40
40
|
const unfilteredTotal = await countPageListRows(options.accessor);
|
|
41
41
|
const hostnameCount = await countPageListHostnames(options.accessor);
|
|
42
42
|
let input = options.initialInput;
|
|
43
|
-
if (unfilteredTotal <=
|
|
43
|
+
if (unfilteredTotal <= PAGE_REPORT_LIMIT && input == null) {
|
|
44
44
|
return [];
|
|
45
45
|
}
|
|
46
46
|
for (;;) {
|
|
@@ -68,7 +68,7 @@ export async function resolveDirectoryPrefixes(options) {
|
|
|
68
68
|
const selectedTotal = await countPageListRows(options.accessor, {
|
|
69
69
|
directories: prefixes.map((prefix) => prefix.display),
|
|
70
70
|
});
|
|
71
|
-
if (selectedTotal >
|
|
71
|
+
if (selectedTotal > PAGE_REPORT_LIMIT) {
|
|
72
72
|
throw new Error(`The selected directories contain ${selectedTotal.toLocaleString()} inner pages; narrow them to 10,000 or fewer.`);
|
|
73
73
|
}
|
|
74
74
|
return prefixes;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { ArchiveAccessor } from '@nitpicker/crawler';
|
|
2
|
+
/** Row-set restriction {@link resolvePageSelection} resolves to. */
|
|
3
|
+
export interface PageSelection {
|
|
4
|
+
/** Directory-prefix filters, display form, ready for `collectHtmlReportPages`. */
|
|
5
|
+
readonly directories: string[];
|
|
6
|
+
/** Normalized URL allowlist, or `undefined` when `--urls` was not given. */
|
|
7
|
+
readonly urls: readonly string[] | undefined;
|
|
8
|
+
}
|
|
9
|
+
interface ResolvePageSelectionOptions {
|
|
10
|
+
readonly accessor: ArchiveAccessor;
|
|
11
|
+
readonly directoryInput?: string;
|
|
12
|
+
/** Already-normalized URLs (via `resolvePageListUrlFilter`), or `undefined` when `--urls` was not given. */
|
|
13
|
+
readonly urls?: readonly string[];
|
|
14
|
+
readonly interactive: boolean;
|
|
15
|
+
readonly onWarn: (message: string) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Decides the report's page restriction: the `--urls` path (this function's
|
|
19
|
+
* own AND-combination with `--html-dirs`, no interactive prompting, no
|
|
20
|
+
* 10,000-page-limit *enforcement via prompting* since a URL list is expected
|
|
21
|
+
* to already be well under it) or the pre-existing `--html-dirs`-only path
|
|
22
|
+
* (delegated to {@link resolveDirectoryPrefixes} unchanged, including its
|
|
23
|
+
* interactive prompt loop).
|
|
24
|
+
*
|
|
25
|
+
* `--urls` skips `resolveDirectoryPrefixes`'s prompt-forcing flow entirely
|
|
26
|
+
* because that flow's whole purpose — interactively narrowing an
|
|
27
|
+
* unboundedly large report down to size — doesn't apply once the caller has
|
|
28
|
+
* already named the exact pages it wants. The 10,000-page ceiling itself
|
|
29
|
+
* still applies (checked after combining `--urls` with any `--html-dirs`
|
|
30
|
+
* narrowing), so a directory prefix that happens to still leave the
|
|
31
|
+
* URL-restricted set too large is still rejected.
|
|
32
|
+
* @param options - Archive, optional non-interactive directory input,
|
|
33
|
+
* optional normalized URL allowlist, interactivity, and warning sink.
|
|
34
|
+
* @returns The resolved directory prefixes and URL allowlist to pass to
|
|
35
|
+
* `collectHtmlReportPages`.
|
|
36
|
+
* @throws {Error} If the `--urls` path's combined row count exceeds the
|
|
37
|
+
* 10,000-page ceiling.
|
|
38
|
+
*/
|
|
39
|
+
export declare function resolvePageSelection(options: ResolvePageSelectionOptions): Promise<PageSelection>;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { countPageListRows } from '@nitpicker/query';
|
|
2
|
+
import { PAGE_REPORT_LIMIT } from './page-report-limit.js';
|
|
3
|
+
import { parseDirectoryInput } from './parse-directory-input.js';
|
|
4
|
+
import { resolveDirectoryPrefixes } from './resolve-directory-prefixes.js';
|
|
5
|
+
/**
|
|
6
|
+
* Decides the report's page restriction: the `--urls` path (this function's
|
|
7
|
+
* own AND-combination with `--html-dirs`, no interactive prompting, no
|
|
8
|
+
* 10,000-page-limit *enforcement via prompting* since a URL list is expected
|
|
9
|
+
* to already be well under it) or the pre-existing `--html-dirs`-only path
|
|
10
|
+
* (delegated to {@link resolveDirectoryPrefixes} unchanged, including its
|
|
11
|
+
* interactive prompt loop).
|
|
12
|
+
*
|
|
13
|
+
* `--urls` skips `resolveDirectoryPrefixes`'s prompt-forcing flow entirely
|
|
14
|
+
* because that flow's whole purpose — interactively narrowing an
|
|
15
|
+
* unboundedly large report down to size — doesn't apply once the caller has
|
|
16
|
+
* already named the exact pages it wants. The 10,000-page ceiling itself
|
|
17
|
+
* still applies (checked after combining `--urls` with any `--html-dirs`
|
|
18
|
+
* narrowing), so a directory prefix that happens to still leave the
|
|
19
|
+
* URL-restricted set too large is still rejected.
|
|
20
|
+
* @param options - Archive, optional non-interactive directory input,
|
|
21
|
+
* optional normalized URL allowlist, interactivity, and warning sink.
|
|
22
|
+
* @returns The resolved directory prefixes and URL allowlist to pass to
|
|
23
|
+
* `collectHtmlReportPages`.
|
|
24
|
+
* @throws {Error} If the `--urls` path's combined row count exceeds the
|
|
25
|
+
* 10,000-page ceiling.
|
|
26
|
+
*/
|
|
27
|
+
export async function resolvePageSelection(options) {
|
|
28
|
+
if (options.urls === undefined) {
|
|
29
|
+
const prefixes = await resolveDirectoryPrefixes({
|
|
30
|
+
accessor: options.accessor,
|
|
31
|
+
initialInput: options.directoryInput,
|
|
32
|
+
interactive: options.interactive,
|
|
33
|
+
onWarn: options.onWarn,
|
|
34
|
+
});
|
|
35
|
+
return { directories: prefixes.map((prefix) => prefix.display), urls: undefined };
|
|
36
|
+
}
|
|
37
|
+
const directoryPrefixes = options.directoryInput
|
|
38
|
+
? parseDirectoryInput(options.directoryInput)
|
|
39
|
+
: [];
|
|
40
|
+
const directories = directoryPrefixes.map((prefix) => prefix.display);
|
|
41
|
+
const total = await countPageListRows(options.accessor, {
|
|
42
|
+
urls: options.urls,
|
|
43
|
+
directories,
|
|
44
|
+
});
|
|
45
|
+
if (total > PAGE_REPORT_LIMIT) {
|
|
46
|
+
throw new Error(`--urls matched ${total.toLocaleString()} inner page(s)` +
|
|
47
|
+
(directories.length > 0 ? ' after --html-dirs narrowing' : '') +
|
|
48
|
+
`; exceeds the ${PAGE_REPORT_LIMIT.toLocaleString()}-page report limit. Narrow --urls or --html-dirs further.`);
|
|
49
|
+
}
|
|
50
|
+
return { directories, urls: options.urls };
|
|
51
|
+
}
|
package/lib/types.d.ts
CHANGED
|
@@ -6,6 +6,16 @@ export interface HtmlReportParams {
|
|
|
6
6
|
readonly outputPath?: string;
|
|
7
7
|
/** Comma-separated directory prefixes used for non-interactive large reports. */
|
|
8
8
|
readonly directoryInput?: string;
|
|
9
|
+
/**
|
|
10
|
+
* URL allowlist restricting the report to exactly these pages, already
|
|
11
|
+
* classified into valid/invalid by the CLI (`readUrlListFile` +
|
|
12
|
+
* `isValidUrl`) but not yet normalized to the archive's own URL form —
|
|
13
|
+
* `report()` does that via `resolveAndValidatePageListUrlFilter` once the
|
|
14
|
+
* archive is open. ANDed with `directoryInput` when both are given. Skips the
|
|
15
|
+
* interactive/10,000-page-limit-prompting flow `directoryInput` alone
|
|
16
|
+
* triggers — see `resolvePageSelection`.
|
|
17
|
+
*/
|
|
18
|
+
readonly urls?: readonly string[];
|
|
9
19
|
/** Whether the reporter may prompt for directory prefixes. */
|
|
10
20
|
readonly interactive?: boolean;
|
|
11
21
|
/** Suppresses completion and warning output. */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nitpicker/report-html",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.22.0",
|
|
4
4
|
"description": "Self-contained static HTML reports for Nitpicker archives",
|
|
5
5
|
"author": "D-ZERO",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -30,10 +30,10 @@
|
|
|
30
30
|
"clean": "tsc --build --clean"
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
|
-
"@d-zero/dealer": "1.
|
|
34
|
-
"@nitpicker/crawler": "0.
|
|
35
|
-
"@nitpicker/query": "0.
|
|
36
|
-
"@nitpicker/viewer": "0.
|
|
33
|
+
"@d-zero/dealer": "1.14.0",
|
|
34
|
+
"@nitpicker/crawler": "0.22.0",
|
|
35
|
+
"@nitpicker/query": "0.22.0",
|
|
36
|
+
"@nitpicker/viewer": "0.22.0",
|
|
37
37
|
"enquirer": "2.4.1",
|
|
38
38
|
"react": "19.2.8",
|
|
39
39
|
"react-dom": "19.2.8"
|
|
@@ -41,5 +41,6 @@
|
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@d-zero/shared": "0.23.0",
|
|
43
43
|
"vitest": "4.1.11"
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
|
+
"gitHead": "934b1714f4394effb3865d84bf8348ed74f45840"
|
|
45
46
|
}
|