Skip to content

Commit b21303f

Browse files
committed
Disable caching when input is passed via 'source'. Fixes jsdoc2md/jsdoc-to-markdown#147.
1 parent 2c6be26 commit b21303f

6 files changed

Lines changed: 27 additions & 290 deletions

File tree

lib/jsdoc-api.js renamed to index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ exports.cache = new Cache({ dir: path.join(require('os').tmpdir(), 'jsdoc-api')
2626
*/
2727
function explainSync (options) {
2828
options = new JsdocOptions(options)
29-
const ExplainSync = require('./explain-sync')
29+
const ExplainSync = require('./lib/explain-sync')
3030
const command = new ExplainSync(options, exports.cache)
3131
return command.execute()
3232
}
@@ -41,7 +41,7 @@ function explainSync (options) {
4141
*/
4242
function explain (options) {
4343
options = new JsdocOptions(options)
44-
const Explain = require('./explain')
44+
const Explain = require('./lib/explain')
4545
const command = new Explain(options, exports.cache)
4646
return command.execute()
4747
}
@@ -57,7 +57,7 @@ function explain (options) {
5757
*/
5858
function renderSync (options) {
5959
options = new JsdocOptions(options)
60-
const RenderSync = require('./render-sync')
60+
const RenderSync = require('./lib/render-sync')
6161
const command = new RenderSync(options)
6262
return command.execute()
6363
}

lib/explain.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ class Explain extends JsdocCommand {
1313

1414
getOutput (err) {
1515
if (err) return Promise.reject(err)
16-
17-
if (this.options.cache) {
16+
if (this.options.cache && !this.options.source) {
1817
return this.readCache().catch(this._runJsdoc.bind(this))
1918
} else {
2019
return this._runJsdoc()

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"description": "A programmatic interface for jsdoc",
66
"repository": "https://github.com/jsdoc2md/jsdoc-api.git",
77
"license": "MIT",
8-
"main": "lib/jsdoc-api",
98
"keywords": [
109
"jsdoc",
1110
"api",

test/caching.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,26 @@ runner.test('caching: .explain({ files, cache: true })', function () {
4242
})
4343
})
4444
})
45+
46+
runner.test('caching: .explain({ source, cache: true }) - Ensure correct output (#147)', function () {
47+
return jsdoc.cache.clear().then(() => {
48+
let one = jsdoc.explain({ source: '/**\n * Function one\n */\nfunction one () {}\n', cache: true })
49+
let two = jsdoc.explain({ source: '/**\n * Function two\n */\nfunction two () {}\n', cache: true })
50+
let three = jsdoc.explain({ source: '/**\n * Function three\n */\nfunction three () {}\n', cache: true })
51+
Promise.all([ one, two, three ]).then(output => {
52+
a.strictEqual(output[0][0].description, 'Function one')
53+
a.strictEqual(output[1][0].description, 'Function two')
54+
a.strictEqual(output[2][0].description, 'Function three')
55+
})
56+
57+
/* ensure it works correctly the second time */
58+
one = jsdoc.explain({ source: '/**\n * Function one\n */\nfunction one () {}\n', cache: true })
59+
two = jsdoc.explain({ source: '/**\n * Function two\n */\nfunction two () {}\n', cache: true })
60+
three = jsdoc.explain({ source: '/**\n * Function three\n */\nfunction three () {}\n', cache: true })
61+
Promise.all([ one, two, three ]).then(output => {
62+
a.strictEqual(output[0][0].description, 'Function one')
63+
a.strictEqual(output[1][0].description, 'Function two')
64+
a.strictEqual(output[2][0].description, 'Function three')
65+
})
66+
})
67+
})

test/fixture/html/0-src.html

Lines changed: 0 additions & 62 deletions
This file was deleted.

test/fixture/html/1-jsdoc.json

Lines changed: 0 additions & 222 deletions
This file was deleted.

0 commit comments

Comments
 (0)