Skip to content

Commit fdb7fb8

Browse files
committed
test
1 parent 943e8ff commit fdb7fb8

File tree

4 files changed

+96
-15
lines changed

4 files changed

+96
-15
lines changed

dist/index.cjs

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var currentModulePaths = require('current-module-paths');
1313
var toSpawnArgs = require('object-to-spawn-args');
1414
var cp = require('child_process');
1515
var util = require('node:util');
16-
var streamReadAll = require('stream-read-all');
1716

1817
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
1918
class TempFile {
@@ -121,6 +120,53 @@ class Explain extends JsdocCommand {
121120
}
122121

123122
async _runJsdoc () {
123+
const jsdocArgs = [
124+
this.jsdocPath,
125+
...toSpawnArgs(this.jsdocOptions),
126+
'-X',
127+
...(this.options.source.length ? this.tempFileSet.files : this.inputFileSet.files)
128+
];
129+
let jsdocOutput = { stdout: '', stderr: '' };
130+
131+
const code = await new Promise((resolve, reject) => {
132+
const handle = cp.spawn('node', jsdocArgs);
133+
handle.stdout.setEncoding('utf8');
134+
handle.stderr.setEncoding('utf8');
135+
handle.stdout.on('data', chunk => {
136+
jsdocOutput.stdout += chunk;
137+
});
138+
handle.stderr.on('data', chunk => {
139+
jsdocOutput.stderr += chunk;
140+
});
141+
handle.on('exit', (code) => {
142+
resolve(code);
143+
});
144+
handle.on('error', reject);
145+
});
146+
// console.log(handle.stdout.closed, handle.stdout.isPaused(), handle.stdout.readable, handle.stdout.destroyed, handle.stdout.errorer, handle.stdout.readableEnded)
147+
// jsdocOutput.stdout = await streamReadText(handle.stdout)
148+
// jsdocOutput.stderr = await streamReadText(handle.stderr)
149+
// console.log(jsdocOutput)
150+
try {
151+
if (code > 0) {
152+
throw new Error('jsdoc exited with non-zero code: ' + code)
153+
} else {
154+
const explainOutput = JSON.parse(jsdocOutput.stdout);
155+
if (this.options.cache) {
156+
await this.cache.write(this.cacheKey, explainOutput);
157+
}
158+
return explainOutput
159+
}
160+
} catch (err) {
161+
const firstLineOfStdout = jsdocOutput.stdout.split(/\r?\n/)[0];
162+
const jsdocErr = new Error(jsdocOutput.stderr.trim() || firstLineOfStdout || 'Jsdoc failed.');
163+
jsdocErr.name = 'JSDOC_ERROR';
164+
jsdocErr.cause = err;
165+
throw jsdocErr
166+
}
167+
}
168+
169+
async _runJsdoc1 () {
124170
return new Promise((resolve, reject) => {
125171
const jsdocArgs = [
126172
this.jsdocPath,
@@ -130,8 +176,8 @@ class Explain extends JsdocCommand {
130176
];
131177
let jsdocOutput = { stdout: '', stderr: '' };
132178
const handle = cp.spawn('node', jsdocArgs);
133-
streamReadAll.streamReadText(handle.stdout).then(stdout => jsdocOutput.stdout = stdout);
134-
streamReadAll.streamReadText(handle.stderr).then(stderr => jsdocOutput.stderr = stderr);
179+
streamReadText(handle.stdout).then(stdout => jsdocOutput.stdout = stdout);
180+
streamReadText(handle.stderr).then(stderr => jsdocOutput.stderr = stderr);
135181
handle.on('close', (code) => {
136182
try {
137183
if (code > 0) {

lib/explain.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import toSpawnArgs from 'object-to-spawn-args'
33
import cp from 'child_process'
44
import util from 'node:util'
55
import { promises as fs } from 'node:fs'
6-
import { streamReadText } from 'stream-read-all'
76
const exec = util.promisify(cp.exec)
87

98
class Explain extends JsdocCommand {
@@ -24,6 +23,53 @@ class Explain extends JsdocCommand {
2423
}
2524

2625
async _runJsdoc () {
26+
const jsdocArgs = [
27+
this.jsdocPath,
28+
...toSpawnArgs(this.jsdocOptions),
29+
'-X',
30+
...(this.options.source.length ? this.tempFileSet.files : this.inputFileSet.files)
31+
]
32+
let jsdocOutput = { stdout: '', stderr: '' }
33+
34+
const code = await new Promise((resolve, reject) => {
35+
const handle = cp.spawn('node', jsdocArgs)
36+
handle.stdout.setEncoding('utf8')
37+
handle.stderr.setEncoding('utf8')
38+
handle.stdout.on('data', chunk => {
39+
jsdocOutput.stdout += chunk
40+
})
41+
handle.stderr.on('data', chunk => {
42+
jsdocOutput.stderr += chunk
43+
})
44+
handle.on('exit', (code) => {
45+
resolve(code)
46+
})
47+
handle.on('error', reject)
48+
})
49+
// console.log(handle.stdout.closed, handle.stdout.isPaused(), handle.stdout.readable, handle.stdout.destroyed, handle.stdout.errorer, handle.stdout.readableEnded)
50+
// jsdocOutput.stdout = await streamReadText(handle.stdout)
51+
// jsdocOutput.stderr = await streamReadText(handle.stderr)
52+
// console.log(jsdocOutput)
53+
try {
54+
if (code > 0) {
55+
throw new Error('jsdoc exited with non-zero code: ' + code)
56+
} else {
57+
const explainOutput = JSON.parse(jsdocOutput.stdout)
58+
if (this.options.cache) {
59+
await this.cache.write(this.cacheKey, explainOutput)
60+
}
61+
return explainOutput
62+
}
63+
} catch (err) {
64+
const firstLineOfStdout = jsdocOutput.stdout.split(/\r?\n/)[0]
65+
const jsdocErr = new Error(jsdocOutput.stderr.trim() || firstLineOfStdout || 'Jsdoc failed.')
66+
jsdocErr.name = 'JSDOC_ERROR'
67+
jsdocErr.cause = err
68+
throw jsdocErr
69+
}
70+
}
71+
72+
async _runJsdoc1 () {
2773
return new Promise((resolve, reject) => {
2874
const jsdocArgs = [
2975
this.jsdocPath,

package-lock.json

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@
3737
"file-set": "^5.2.2",
3838
"jsdoc": "^4.0.4",
3939
"object-to-spawn-args": "^2.0.1",
40-
"stream-read-all": "^5.0.2",
4140
"walk-back": "^5.1.1"
4241
},
4342
"peerDependencies": {

0 commit comments

Comments
 (0)