Skip to content

Commit eb4228b

Browse files
committed
Removed some async optimizations to get more clarity and stability
1 parent b92457b commit eb4228b

File tree

5 files changed

+67
-51
lines changed

5 files changed

+67
-51
lines changed

package-lock.json

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.0.0",
2+
"version": "2.1.0",
33
"private": true,
44
"author": "Jaid <jaid.jsx@gmail.com> (https://github.com/Jaid)",
55
"babel": {
@@ -15,13 +15,14 @@
1515
},
1616
"dependencies": {
1717
"better-docs": "^1.1.2",
18+
"command-join": "^2.0.0",
1819
"debug": "^4.1.1",
1920
"first-existing-path": "^1.0.1",
21+
"get-exec-file": "^1.1.0",
2022
"jsdoc": "^3.5.5",
2123
"jsdoc-babel": "^0.5.0",
2224
"jsdoc-export-default-interop": "^0.3.1",
2325
"tmp-promise": "^1.0.5",
24-
"get-exec-file": "^1.1.0",
2526
"tsd-jsdoc": "^2.1.2"
2627
},
2728
"peerDependencies": {

src/index.js

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import path from "path"
2+
import {execSync} from "child_process"
23

34
import fs from "fs-extra"
45
import tmpPromise from "tmp-promise"
56
import firstExistingPath from "first-existing-path"
6-
import getExecFile from "get-exec-file"
77
import readPkgUp from "read-pkg-up"
88
import {isObject} from "lodash"
9+
import commandJoin from "command-join"
910

1011
const debug = require("debug")("jsdoc-tsd-webpack-plugin")
1112

1213
const webpackId = "JsdocTsdWebpackPlugin"
1314

14-
const getHtmlConfigPath = async (compilation, configBase, template, options, configDir) => {
15+
const getHtmlConfigPath = (compilation, configBase, template, options, configDir) => {
1516
const config = {
1617
...configBase,
1718
opts: {
@@ -26,7 +27,7 @@ const getHtmlConfigPath = async (compilation, configBase, template, options, con
2627
return configPath
2728
}
2829

29-
const getTsdConfigPath = async (compilation, configBase, template, options, configDir) => {
30+
const getTsdConfigPath = (compilation, configBase, template, options, configDir) => {
3031
const config = {
3132
...configBase,
3233
opts: {
@@ -169,32 +170,33 @@ export default class {
169170
debug(`tsd output file should be named ${this.options.autoTsdOutputFile}`)
170171
}
171172

172-
const [htmlConfigPath, tsdConfigPath] = await Promise.all([
173-
getHtmlConfigPath(compilation, configBase, htmlModulePath, this.options, tempDir),
174-
getTsdConfigPath(compilation, configBase, tsdModulePath, this.options, tempDir),
175-
])
176-
177-
debug(`JSDoc HTML command: "${process.execPath}" "${jsdocPath}" --configure "${htmlConfigPath}"`)
178-
debug(`JSDoc TSD command: "${process.execPath}" "${jsdocPath}" --configure "${tsdConfigPath}"`)
179-
180-
const jsdocJobs = [htmlConfigPath, tsdConfigPath].map(configPath => getExecFile(process.execPath, [jsdocPath, "--configure", configPath], {
181-
timeout: 1000 * 120,
182-
}))
183-
const jsdocResults = await Promise.all(jsdocJobs)
184-
185-
for (const jsdocResult of jsdocResults) {
186-
if (jsdocResult.error) {
187-
throw new Error(`JSDoc failed with Error: ${error.message}`)
188-
}
189-
if (jsdocResult.stderr) {
190-
throw new Error(`JSDoc failed with error output: ${jsdocResult.stderr}`)
191-
}
173+
const setups = [
174+
{
175+
name: "TSD",
176+
modulePath: tsdModulePath,
177+
configFactory: getTsdConfigPath,
178+
},
179+
{
180+
name: "HTML",
181+
configFactory: getHtmlConfigPath,
182+
modulePath: htmlModulePath,
183+
},
184+
]
185+
186+
for (const {name, modulePath, configFactory} of setups) {
187+
const configPath = configFactory(compilation, configBase, modulePath, this.options, tempDir)
188+
const command = commandJoin([process.execPath, jsdocPath, "--configure", configPath])
189+
debug(`JSDoc ${name} command: ${command}`)
190+
const out = execSync(command, {
191+
timeout: 1000 * 120,
192+
cwd: compiler.context,
193+
encoding: "utf8",
194+
})
195+
debug(`JSDoc ${name} output: ${out}`)
192196
}
193197

194-
debug(`JSDoc HTML stdout: ${jsdocResults[0].stdout}`)
195-
debug(`JSDoc TSD stdout: ${jsdocResults[1].stdout}`)
196-
197198
if (this.options.autoTsdOutputFile) {
199+
debug(`Copying ${this.options.autoTsdOutputFile} to ${path.join(compiler.options.output.path, this.options.autoTsdOutputFile |> path.basename)}`)
198200
const tsdContent = fs.readFileSync(this.options.autoTsdOutputFile)
199201
compilation.assets[path.basename(this.options.autoTsdOutputFile)] = {
200202
source: () => tsdContent,

test/index.test.js

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const runWebpack = async (name, extraConfig) => {
2424
}))
2525
fs.ensureDirSync(path.join(__dirname, name, "info"))
2626
fs.writeJsonSync(path.join(__dirname, name, "info", "stats.json"), stats.toJson())
27+
return stats
2728
}
2829

2930
it("should run", () => runWebpack("basic", {
@@ -41,26 +42,32 @@ it("should run with publishimo-webpack-plugin", () => runWebpack("with-publishim
4142
],
4243
}))
4344

44-
it("should run with {babel: true}", () => runWebpack("with-babel", {
45-
plugins: [
46-
new CleanWebpackPlugin,
47-
new JsdocTsdWebpackPlugin({
48-
babel: {
49-
presets: ["jaid"],
50-
},
51-
}),
52-
new PublishimoWebpackPlugin,
53-
],
54-
module: {
55-
rules: [
56-
{
57-
test: /\.js$/,
58-
exclude: /node_modules\//,
59-
use: {
60-
loader: "babel-loader",
61-
options: {presets: ["jaid"]},
45+
it("should run with {babel: true}", async () => {
46+
await runWebpack("with-babel", {
47+
plugins: [
48+
new CleanWebpackPlugin,
49+
new JsdocTsdWebpackPlugin({
50+
babel: {
51+
presets: ["jaid"],
6252
},
63-
},
53+
}),
54+
new PublishimoWebpackPlugin,
6455
],
65-
},
66-
}))
56+
module: {
57+
rules: [
58+
{
59+
test: /\.js$/,
60+
exclude: /node_modules\//,
61+
use: {
62+
loader: "babel-loader",
63+
options: {presets: ["jaid"]},
64+
},
65+
},
66+
],
67+
},
68+
})
69+
const tsdContent = fs.readFileSync(path.join(__dirname, "with-babel", "dist", "main.d.ts"), "utf8")
70+
expect(tsdContent).toMatch("declare")
71+
const htmlContent = fs.readFileSync(path.join(__dirname, "with-babel", "dist-jsdoc", "with-babel", "1.0.0", "index.html"), "utf8")
72+
expect(htmlContent).toMatch("hi (with babel)")
73+
})

test/with-babel/src/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
* @return {string} The cleaned string
99
*/
1010
export default string => {
11-
return string |> #.trim()
11+
return string
12+
|> #.trim()
1213
}

0 commit comments

Comments
 (0)