Skip to content

Commit c553146

Browse files
authored
[builder][BREAKING] JSDoc: Fail build when jsdoc command failed (SAP/ui5-builder#845)
BREAKING CHANGE: The `jsdocGenerator` processor and the corresponding `generateJsdoc` task will now throw an error when JSDoc reports an error (exit code != 0). This will also fail the build when running `ui5 build jsdoc`.
1 parent 9078c7a commit c553146

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

packages/builder/lib/processors/jsdoc/jsdocGenerator.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -170,18 +170,16 @@ async function buildJsdoc({sourcePath, configPath}) {
170170
"--verbose",
171171
sourcePath
172172
];
173-
return new Promise((resolve, reject) => {
173+
const exitCode = await new Promise((resolve /* , reject */) => {
174174
const child = spawn("node", args, {
175175
stdio: ["ignore", "ignore", "inherit"]
176176
});
177-
child.on("close", function(code) {
178-
if (code === 0 || code === 1) {
179-
resolve();
180-
} else {
181-
reject(new Error(`JSDoc child process closed with code ${code}`));
182-
}
183-
});
177+
child.on("close", resolve);
184178
});
179+
180+
if (exitCode !== 0) {
181+
throw new Error(`JSDoc reported an error, check the log for issues (exit code: ${exitCode})`);
182+
}
185183
}
186184

187185
jsdocGenerator._generateJsdocConfig = generateJsdocConfig;

packages/builder/test/lib/processors/jsdoc/jsdocGenerator.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,20 @@ test.serial("buildJsdoc", async (t) => {
114114

115115
// Re-execute with exit code 1
116116
exitCode = 1;
117-
await t.notThrowsAsync(jsdocGenerator._buildJsdoc({
117+
await t.throwsAsync(jsdocGenerator._buildJsdoc({
118118
sourcePath: "/some/path",
119119
configPath: "/some/config/path/jsdoc-config.json"
120-
}));
120+
}), {
121+
message: "JSDoc reported an error, check the log for issues (exit code: 1)"
122+
});
121123

122124
// Re-execute with exit code 2
123125
exitCode = 2;
124126
const error = await t.throwsAsync(jsdocGenerator._buildJsdoc({
125127
sourcePath: "/some/path",
126128
configPath: "/some/config/path/jsdoc-config.json"
127129
}));
128-
t.is(error.message, "JSDoc child process closed with code 2");
130+
t.is(error.message, "JSDoc reported an error, check the log for issues (exit code: 2)");
129131
});
130132

131133
test.serial("jsdocGenerator", async (t) => {

0 commit comments

Comments
 (0)