Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
75lb committed Nov 1, 2024
1 parent 943e8ff commit fdb7fb8
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 15 deletions.
52 changes: 49 additions & 3 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ var currentModulePaths = require('current-module-paths');
var toSpawnArgs = require('object-to-spawn-args');
var cp = require('child_process');
var util = require('node:util');
var streamReadAll = require('stream-read-all');

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

async _runJsdoc () {
const jsdocArgs = [
this.jsdocPath,
...toSpawnArgs(this.jsdocOptions),
'-X',
...(this.options.source.length ? this.tempFileSet.files : this.inputFileSet.files)
];
let jsdocOutput = { stdout: '', stderr: '' };

const code = await new Promise((resolve, reject) => {
const handle = cp.spawn('node', jsdocArgs);
handle.stdout.setEncoding('utf8');
handle.stderr.setEncoding('utf8');
handle.stdout.on('data', chunk => {
jsdocOutput.stdout += chunk;
});
handle.stderr.on('data', chunk => {
jsdocOutput.stderr += chunk;
});
handle.on('exit', (code) => {
resolve(code);
});
handle.on('error', reject);
});
// console.log(handle.stdout.closed, handle.stdout.isPaused(), handle.stdout.readable, handle.stdout.destroyed, handle.stdout.errorer, handle.stdout.readableEnded)
// jsdocOutput.stdout = await streamReadText(handle.stdout)
// jsdocOutput.stderr = await streamReadText(handle.stderr)
// console.log(jsdocOutput)
try {
if (code > 0) {
throw new Error('jsdoc exited with non-zero code: ' + code)
} else {
const explainOutput = JSON.parse(jsdocOutput.stdout);
if (this.options.cache) {
await this.cache.write(this.cacheKey, explainOutput);
}
return explainOutput
}
} catch (err) {
const firstLineOfStdout = jsdocOutput.stdout.split(/\r?\n/)[0];
const jsdocErr = new Error(jsdocOutput.stderr.trim() || firstLineOfStdout || 'Jsdoc failed.');
jsdocErr.name = 'JSDOC_ERROR';
jsdocErr.cause = err;
throw jsdocErr
}
}

async _runJsdoc1 () {
return new Promise((resolve, reject) => {
const jsdocArgs = [
this.jsdocPath,
Expand All @@ -130,8 +176,8 @@ class Explain extends JsdocCommand {
];
let jsdocOutput = { stdout: '', stderr: '' };
const handle = cp.spawn('node', jsdocArgs);
streamReadAll.streamReadText(handle.stdout).then(stdout => jsdocOutput.stdout = stdout);
streamReadAll.streamReadText(handle.stderr).then(stderr => jsdocOutput.stderr = stderr);
streamReadText(handle.stdout).then(stdout => jsdocOutput.stdout = stdout);
streamReadText(handle.stderr).then(stderr => jsdocOutput.stderr = stderr);
handle.on('close', (code) => {
try {
if (code > 0) {
Expand Down
48 changes: 47 additions & 1 deletion lib/explain.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import toSpawnArgs from 'object-to-spawn-args'
import cp from 'child_process'
import util from 'node:util'
import { promises as fs } from 'node:fs'
import { streamReadText } from 'stream-read-all'
const exec = util.promisify(cp.exec)

class Explain extends JsdocCommand {
Expand All @@ -24,6 +23,53 @@ class Explain extends JsdocCommand {
}

async _runJsdoc () {
const jsdocArgs = [
this.jsdocPath,
...toSpawnArgs(this.jsdocOptions),
'-X',
...(this.options.source.length ? this.tempFileSet.files : this.inputFileSet.files)
]
let jsdocOutput = { stdout: '', stderr: '' }

const code = await new Promise((resolve, reject) => {
const handle = cp.spawn('node', jsdocArgs)
handle.stdout.setEncoding('utf8')
handle.stderr.setEncoding('utf8')
handle.stdout.on('data', chunk => {
jsdocOutput.stdout += chunk
})
handle.stderr.on('data', chunk => {
jsdocOutput.stderr += chunk
})
handle.on('exit', (code) => {
resolve(code)
})
handle.on('error', reject)
})
// console.log(handle.stdout.closed, handle.stdout.isPaused(), handle.stdout.readable, handle.stdout.destroyed, handle.stdout.errorer, handle.stdout.readableEnded)
// jsdocOutput.stdout = await streamReadText(handle.stdout)
// jsdocOutput.stderr = await streamReadText(handle.stderr)
// console.log(jsdocOutput)
try {
if (code > 0) {
throw new Error('jsdoc exited with non-zero code: ' + code)
} else {
const explainOutput = JSON.parse(jsdocOutput.stdout)
if (this.options.cache) {
await this.cache.write(this.cacheKey, explainOutput)
}
return explainOutput
}
} catch (err) {
const firstLineOfStdout = jsdocOutput.stdout.split(/\r?\n/)[0]
const jsdocErr = new Error(jsdocOutput.stderr.trim() || firstLineOfStdout || 'Jsdoc failed.')
jsdocErr.name = 'JSDOC_ERROR'
jsdocErr.cause = err
throw jsdocErr
}
}

async _runJsdoc1 () {
return new Promise((resolve, reject) => {
const jsdocArgs = [
this.jsdocPath,
Expand Down
10 changes: 0 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
"file-set": "^5.2.2",
"jsdoc": "^4.0.4",
"object-to-spawn-args": "^2.0.1",
"stream-read-all": "^5.0.2",
"walk-back": "^5.1.1"
},
"peerDependencies": {
Expand Down

0 comments on commit fdb7fb8

Please sign in to comment.