@nitpicker/report-google-sheets 0.5.0 → 0.5.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/lib/archive.d.ts CHANGED
@@ -1,8 +1,20 @@
1
1
  import { Archive } from '@nitpicker/crawler';
2
+ /**
3
+ * Result of opening an archive with signal handlers registered.
4
+ */
5
+ export interface ArchiveHandle {
6
+ /** The opened archive instance. */
7
+ readonly archive: Archive;
8
+ /** Removes the registered signal handlers. Call this when the archive is no longer in use. */
9
+ readonly removeSignalHandlers: () => void;
10
+ }
2
11
  /**
3
12
  * Opens a `.nitpicker` archive file and registers process signal handlers
4
13
  * to ensure the archive is closed gracefully on unexpected termination.
14
+ *
15
+ * The caller must invoke `removeSignalHandlers()` when the archive is no
16
+ * longer needed to avoid listener accumulation.
5
17
  * @param filePath - Path to the `.nitpicker` archive file
6
- * @returns The opened `Archive` instance with plugin data loaded
18
+ * @returns An {@link ArchiveHandle} containing the archive and a cleanup function.
7
19
  */
8
- export declare function getArchive(filePath: string): Promise<Archive>;
20
+ export declare function getArchive(filePath: string): Promise<ArchiveHandle>;
package/lib/archive.js CHANGED
@@ -3,8 +3,11 @@ import { archiveLog } from './debug.js';
3
3
  /**
4
4
  * Opens a `.nitpicker` archive file and registers process signal handlers
5
5
  * to ensure the archive is closed gracefully on unexpected termination.
6
+ *
7
+ * The caller must invoke `removeSignalHandlers()` when the archive is no
8
+ * longer needed to avoid listener accumulation.
6
9
  * @param filePath - Path to the `.nitpicker` archive file
7
- * @returns The opened `Archive` instance with plugin data loaded
10
+ * @returns An {@link ArchiveHandle} containing the archive and a cleanup function.
8
11
  */
9
12
  export async function getArchive(filePath) {
10
13
  archiveLog('Open file: %s', filePath);
@@ -13,14 +16,19 @@ export async function getArchive(filePath) {
13
16
  openPluginData: true,
14
17
  });
15
18
  archiveLog('File open succeeded');
19
+ const signals = ['SIGINT', 'SIGBREAK', 'SIGHUP', 'SIGABRT'];
16
20
  const close = async () => {
17
21
  await archive.close();
18
22
  process.exit();
19
23
  };
20
24
  archiveLog('Bind close method to SIGINT, SIGBREAK, SIGHUP, SIGABRT events');
21
- process.on('SIGINT', close);
22
- process.on('SIGBREAK', close);
23
- process.on('SIGHUP', close);
24
- process.on('SIGABRT', close);
25
- return archive;
25
+ for (const signal of signals) {
26
+ process.on(signal, close);
27
+ }
28
+ const removeSignalHandlers = () => {
29
+ for (const signal of signals) {
30
+ process.removeListener(signal, close);
31
+ }
32
+ };
33
+ return { archive, removeSignalHandlers };
26
34
  }
package/lib/report.js CHANGED
@@ -55,142 +55,145 @@ export async function report(params) {
55
55
  });
56
56
  log('Authentication succeeded');
57
57
  log('Opening archive: %s', filePath);
58
- const archive = await getArchive(filePath);
58
+ const { archive, removeSignalHandlers } = await getArchive(filePath);
59
59
  log('Archive opened');
60
- log('Loading config');
61
- const config = await loadConfig(configPath);
62
- log('Config loaded');
63
- const plugins = config.plugins?.analyze
64
- ? Object.keys(config.plugins.analyze)
65
- : undefined;
66
- log('Loaded plugins: %O', plugins);
67
- log('Loading plugin reports');
68
- const reports = await getPluginReports(archive /*plugins*/);
69
- log('Plugin reports loaded: %d', reports.length);
70
- const sheets = new Sheets(sheetUrl, auth);
71
- log('Reporting starts');
72
- const sheetNames = [
73
- 'Page List',
74
- 'Links',
75
- 'Resources',
76
- 'Images',
77
- 'Violations',
78
- 'Discrepancies',
79
- 'Summary',
80
- 'Referrers Relational Table',
81
- 'Resources Relational Table',
82
- ];
83
- let selectedSheetNames;
84
- if (all) {
85
- log('All sheets selected (--all or non-TTY)');
86
- selectedSheetNames = sheetNames;
87
- }
88
- else {
89
- log('Choice creating data');
90
- const chosenSheets = await enquirer
91
- .prompt([
92
- {
93
- message: 'What do you report?',
94
- name: 'sheetName',
95
- type: 'multiselect',
96
- choices: sheetNames,
97
- },
98
- ])
99
- .catch(() => {
100
- // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
101
- // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
102
- // 即座に終了して回避する
103
- process.exit(0);
104
- });
105
- if (!chosenSheets) {
106
- log('Choice creating data');
107
- archiveLog('Closes file');
108
- await archive.close();
109
- return;
60
+ try {
61
+ log('Loading config');
62
+ const config = await loadConfig(configPath);
63
+ log('Config loaded');
64
+ const plugins = config.plugins?.analyze
65
+ ? Object.keys(config.plugins.analyze)
66
+ : undefined;
67
+ log('Loaded plugins: %O', plugins);
68
+ log('Loading plugin reports');
69
+ const reports = await getPluginReports(archive /*plugins*/);
70
+ log('Plugin reports loaded: %d', reports.length);
71
+ const sheets = new Sheets(sheetUrl, auth);
72
+ log('Reporting starts');
73
+ const sheetNames = [
74
+ 'Page List',
75
+ 'Links',
76
+ 'Resources',
77
+ 'Images',
78
+ 'Violations',
79
+ 'Discrepancies',
80
+ 'Summary',
81
+ 'Referrers Relational Table',
82
+ 'Resources Relational Table',
83
+ ];
84
+ let selectedSheetNames;
85
+ if (all) {
86
+ log('All sheets selected (--all or non-TTY)');
87
+ selectedSheetNames = sheetNames;
110
88
  }
111
- selectedSheetNames = chosenSheets.sheetName;
112
- }
113
- log('Chosen sheets: %O', selectedSheetNames);
114
- const createSheetList = [];
115
- if (selectedSheetNames.includes('Page List')) {
116
- createSheetList.push(createPageList);
117
- }
118
- if (selectedSheetNames.includes('Links')) {
119
- createSheetList.push(createLinks);
120
- }
121
- if (selectedSheetNames.includes('Discrepancies')) {
122
- createSheetList.push(createDiscrepancies);
123
- }
124
- if (selectedSheetNames.includes('Violations')) {
125
- createSheetList.push(createViolations);
126
- }
127
- if (selectedSheetNames.includes('Referrers Relational Table')) {
128
- createSheetList.push(createReferrersRelationalTable);
129
- }
130
- if (selectedSheetNames.includes('Resources Relational Table')) {
131
- createSheetList.push(createResourcesRelationalTable);
132
- }
133
- if (selectedSheetNames.includes('Resources')) {
134
- createSheetList.push(createResources);
135
- }
136
- if (selectedSheetNames.includes('Images')) {
137
- createSheetList.push(createImageList);
138
- }
139
- if (!silent) {
140
- // eslint-disable-next-line no-console
141
- console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
142
- }
143
- const lanes = silent
144
- ? null
145
- : new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
146
- log('Lanes created (verbose: %s, silent: %s)', !process.stdout.isTTY, !!silent);
147
- const RATE_LIMIT_LANE = 10_000;
148
- let countdownSeq = 0;
149
- let waitingCount = 0;
150
- if (lanes) {
151
- sheets.onLog = (message) => {
152
- if (message.waiting && message.waitTime) {
153
- waitingCount++;
154
- const id = `rateLimit_${countdownSeq++}`;
155
- const label = message.message === 'TooManyRequestError'
156
- ? 'Too Many Requests (429)'
157
- : message.message === 'UserRateLimitExceededError'
158
- ? 'Rate Limit Exceeded (403)'
159
- : 'Connection Reset';
160
- lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
89
+ else {
90
+ log('Choice creating data');
91
+ const chosenSheets = await enquirer
92
+ .prompt([
93
+ {
94
+ message: 'What do you report?',
95
+ name: 'sheetName',
96
+ type: 'multiselect',
97
+ choices: sheetNames,
98
+ },
99
+ ])
100
+ .catch(() => {
101
+ // enquirer v2.4.1: Ctrl+C 後に readline を二重 close して
102
+ // ERR_USE_AFTER_CLOSE が unhandled rejection になるため、
103
+ // 即座に終了して回避する
104
+ process.exit(0);
105
+ });
106
+ if (!chosenSheets) {
107
+ log('Choice creating data');
108
+ return;
161
109
  }
162
- else {
163
- waitingCount--;
164
- if (waitingCount <= 0) {
165
- waitingCount = 0;
166
- lanes.delete(RATE_LIMIT_LANE);
110
+ selectedSheetNames = chosenSheets.sheetName;
111
+ }
112
+ log('Chosen sheets: %O', selectedSheetNames);
113
+ const createSheetList = [];
114
+ if (selectedSheetNames.includes('Page List')) {
115
+ createSheetList.push(createPageList);
116
+ }
117
+ if (selectedSheetNames.includes('Links')) {
118
+ createSheetList.push(createLinks);
119
+ }
120
+ if (selectedSheetNames.includes('Discrepancies')) {
121
+ createSheetList.push(createDiscrepancies);
122
+ }
123
+ if (selectedSheetNames.includes('Violations')) {
124
+ createSheetList.push(createViolations);
125
+ }
126
+ if (selectedSheetNames.includes('Referrers Relational Table')) {
127
+ createSheetList.push(createReferrersRelationalTable);
128
+ }
129
+ if (selectedSheetNames.includes('Resources Relational Table')) {
130
+ createSheetList.push(createResourcesRelationalTable);
131
+ }
132
+ if (selectedSheetNames.includes('Resources')) {
133
+ createSheetList.push(createResources);
134
+ }
135
+ if (selectedSheetNames.includes('Images')) {
136
+ createSheetList.push(createImageList);
137
+ }
138
+ if (!silent) {
139
+ // eslint-disable-next-line no-console
140
+ console.log(`\nGenerating ${createSheetList.length} sheet(s)...\n`);
141
+ }
142
+ const lanes = silent
143
+ ? null
144
+ : new Lanes({ verbose: !process.stdout.isTTY, indent: ' ' });
145
+ log('Lanes created (verbose: %s, silent: %s)', !process.stdout.isTTY, !!silent);
146
+ const RATE_LIMIT_LANE = 10_000;
147
+ let countdownSeq = 0;
148
+ let waitingCount = 0;
149
+ if (lanes) {
150
+ sheets.onLog = (message) => {
151
+ if (message.waiting && message.waitTime) {
152
+ waitingCount++;
153
+ const id = `rateLimit_${countdownSeq++}`;
154
+ const label = message.message === 'TooManyRequestError'
155
+ ? 'Too Many Requests (429)'
156
+ : message.message === 'UserRateLimitExceededError'
157
+ ? 'Rate Limit Exceeded (403)'
158
+ : 'Connection Reset';
159
+ lanes.update(RATE_LIMIT_LANE, c.yellow(`${label}: waiting %countdown(${message.waitTime}, ${id}, s)%s`));
167
160
  }
168
- }
169
- };
170
- }
171
- log('Reporting starts (limit: %d)', limit);
172
- try {
173
- await createSheets({
174
- sheets,
175
- archive,
176
- reports,
177
- limit,
178
- createSheetList,
179
- options: lanes ? { lanes } : undefined,
180
- });
161
+ else {
162
+ waitingCount--;
163
+ if (waitingCount <= 0) {
164
+ waitingCount = 0;
165
+ lanes.delete(RATE_LIMIT_LANE);
166
+ }
167
+ }
168
+ };
169
+ }
170
+ log('Reporting starts (limit: %d)', limit);
171
+ try {
172
+ await createSheets({
173
+ sheets,
174
+ archive,
175
+ reports,
176
+ limit,
177
+ createSheetList,
178
+ options: lanes ? { lanes } : undefined,
179
+ });
180
+ }
181
+ finally {
182
+ lanes?.close();
183
+ }
184
+ log('Reporting done');
185
+ if (!silent) {
186
+ // eslint-disable-next-line no-console
187
+ console.log('\nReport complete.');
188
+ }
189
+ if (selectedSheetNames.includes('Summary')) {
190
+ await addToSummary( /*sheets, archive, reports*/);
191
+ }
181
192
  }
182
193
  finally {
183
- lanes?.close();
184
- }
185
- log('Reporting done');
186
- if (!silent) {
187
- // eslint-disable-next-line no-console
188
- console.log('\nReport complete.');
189
- }
190
- if (selectedSheetNames.includes('Summary')) {
191
- await addToSummary( /*sheets, archive, reports*/);
194
+ archiveLog('Closes file');
195
+ removeSignalHandlers();
196
+ await archive.close();
197
+ log('Done');
192
198
  }
193
- archiveLog('Closes file');
194
- await archive.close();
195
- log('Done');
196
199
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nitpicker/report-google-sheets",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "Nitpicker reporter that outputs crawl and analysis results to Google Sheets",
5
5
  "author": "D-ZERO",
6
6
  "license": "Apache-2.0",
@@ -44,5 +44,5 @@
44
44
  "googleapis": "171.4.0",
45
45
  "vitest": "4.0.18"
46
46
  },
47
- "gitHead": "607d06bd596a0270d7088f32373d7367eb47ea94"
47
+ "gitHead": "e0b1407813feb089c14fa07859651ffebf5c023f"
48
48
  }