@cloud411716/fancy-webnovel 0.1.47 → 0.1.48

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloud411716/fancy-webnovel",
3
- "version": "0.1.47",
3
+ "version": "0.1.48",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "exports": {
@@ -176,28 +176,29 @@ function spawnScraper(platform, length, outDir) {
176
176
  return new Promise(async (resolve) => {
177
177
  const { spawn } = await import('child_process');
178
178
  const args = scraperArgs(platform, length, outDir);
179
- // 先尝试 9222 端口(Chrome CDP),没有 Chrome 则尝试 9223
180
179
  const ports = ['9222', '9223'];
181
180
  let portIdx = 0;
182
181
 
183
182
  function tryPort(port) {
184
183
  const scraperScript = join(dirname(fileURLToPath(import.meta.url)), 'scrapers', args.script);
185
184
  const fullArgs = ['--port', port, ...args.extra];
185
+ // stderr 透传到父进程 stderr,用户实时看到进度
186
186
  const p = spawn('node', [scraperScript, ...fullArgs], {
187
187
  timeout: 120000,
188
- stdio: ['ignore', 'pipe', 'pipe'],
188
+ stdio: ['ignore', 'pipe', 'inherit'],
189
189
  });
190
- let out = '', err = '';
190
+ let out = '';
191
191
  p.stdout.on('data', d => { out += d.toString(); });
192
- p.stderr.on('data', d => { err += d.toString(); });
193
192
  p.on('close', (code) => {
194
193
  if (code === 0 && out.trim()) {
195
- resolve({ ok: true, output: out, stderr: err });
194
+ resolve({ ok: true, output: out, stderr: '' });
196
195
  } else if (portIdx < ports.length - 1) {
197
196
  portIdx++;
198
197
  tryPort(ports[portIdx]);
199
198
  } else {
200
- resolve({ ok: false, output: out, error: err || `exit ${code}` });
199
+ // 截取 stderr 末尾 300 字符,避免过长
200
+ const errTail = out.trimEnd().slice(-300);
201
+ resolve({ ok: false, output: out, error: errTail || `exit ${code}` });
201
202
  }
202
203
  });
203
204
  p.on('error', (e) => {