1
1
'use strict' ;
2
2
3
3
var path$1 = require ( 'path' ) ;
4
- var fs$1 = require ( 'fs' ) ;
4
+ var fs = require ( 'fs' ) ;
5
5
var os = require ( 'os' ) ;
6
6
var crypto = require ( 'crypto' ) ;
7
+ var fs$1 = require ( 'node:fs' ) ;
7
8
var node_url = require ( 'node:url' ) ;
8
9
var path$2 = require ( 'node:path' ) ;
9
- var actualFS = require ( 'node:fs' ) ;
10
10
var promises = require ( 'node:fs/promises' ) ;
11
11
var node_events = require ( 'node:events' ) ;
12
12
var Stream = require ( 'node:stream' ) ;
@@ -35,7 +35,7 @@ function _interopNamespaceDefault(e) {
35
35
return Object . freeze ( n ) ;
36
36
}
37
37
38
- var actualFS__namespace = /*#__PURE__*/ _interopNamespaceDefault ( actualFS ) ;
38
+ var fs__namespace = /*#__PURE__*/ _interopNamespaceDefault ( fs$1 ) ;
39
39
40
40
/**
41
41
* Takes any input and guarantees an array back.
@@ -124,7 +124,7 @@ class Cache {
124
124
}
125
125
set dir ( val ) {
126
126
this . _dir = val ;
127
- fs$1 . mkdirSync ( this . dir , { recursive : true } ) ;
127
+ fs . mkdirSync ( this . dir , { recursive : true } ) ;
128
128
}
129
129
130
130
/**
@@ -135,7 +135,7 @@ class Cache {
135
135
*/
136
136
async read ( keys ) {
137
137
const blobPath = path$1 . resolve ( this . _dir , this . getChecksum ( keys ) ) ;
138
- return fs$1 . promises . readFile ( blobPath ) . then ( JSON . parse )
138
+ return fs . promises . readFile ( blobPath ) . then ( JSON . parse )
139
139
}
140
140
141
141
/**
@@ -146,7 +146,7 @@ class Cache {
146
146
readSync ( keys ) {
147
147
const blobPath = path$1 . resolve ( this . _dir , this . getChecksum ( keys ) ) ;
148
148
try {
149
- const data = fs$1 . readFileSync ( blobPath , 'utf8' ) ;
149
+ const data = fs . readFileSync ( blobPath , 'utf8' ) ;
150
150
return JSON . parse ( data )
151
151
} catch ( err ) {
152
152
return null
@@ -161,7 +161,7 @@ class Cache {
161
161
*/
162
162
async write ( keys , content ) {
163
163
const blobPath = path$1 . resolve ( this . _dir , this . getChecksum ( keys ) ) ;
164
- return fs$1 . promises . writeFile ( blobPath , JSON . stringify ( content ) )
164
+ return fs . promises . writeFile ( blobPath , JSON . stringify ( content ) )
165
165
}
166
166
167
167
/**
@@ -171,7 +171,7 @@ class Cache {
171
171
*/
172
172
writeSync ( keys , content ) {
173
173
const blobPath = path$1 . resolve ( this . _dir , this . getChecksum ( keys ) ) ;
174
- fs$1 . writeFileSync ( blobPath , JSON . stringify ( content ) ) ;
174
+ fs . writeFileSync ( blobPath , JSON . stringify ( content ) ) ;
175
175
}
176
176
177
177
/**
@@ -190,8 +190,8 @@ class Cache {
190
190
* @returns {Promise }
191
191
*/
192
192
async clear ( ) {
193
- const files = await fs$1 . promises . readdir ( this . _dir ) ;
194
- const promises = files . map ( file => fs$1 . promises . unlink ( path$1 . resolve ( this . _dir , file ) ) ) ;
193
+ const files = await fs . promises . readdir ( this . _dir ) ;
194
+ const promises = files . map ( file => fs . promises . unlink ( path$1 . resolve ( this . _dir , file ) ) ) ;
195
195
return Promise . all ( promises )
196
196
}
197
197
@@ -201,14 +201,13 @@ class Cache {
201
201
*/
202
202
async remove ( ) {
203
203
await this . clear ( ) ;
204
- return fs$1 . promises . rmdir ( this . _dir )
204
+ return fs . promises . rmdir ( this . _dir )
205
205
}
206
206
}
207
207
208
208
class TempFile {
209
209
constructor ( source ) {
210
- const tempDir = fs$1 . mkdtempSync ( path$1 . join ( os . tmpdir ( ) , 'jsdoc-api-' ) ) ;
211
- this . path = path$1 . join ( tempDir , crypto . randomBytes ( 6 ) . toString ( 'hex' ) + '.js' ) ;
210
+ this . path = path$1 . join ( TempFile . tempFileDir , crypto . randomBytes ( 6 ) . toString ( 'hex' ) + '.js' ) ;
212
211
fs$1 . writeFileSync ( this . path , source ) ;
213
212
}
214
213
@@ -219,6 +218,15 @@ class TempFile {
219
218
// already deleted
220
219
}
221
220
}
221
+
222
+ static tempFileDir = path$1 . join ( os . homedir ( ) , '.jsdoc-api/temp' )
223
+ static cacheDir = path$1 . join ( os . homedir ( ) , '.jsdoc-api/cache' )
224
+
225
+ static createTmpDirs ( ) {
226
+ /* No longer using os.tmpdir(). See: https://github.com/jsdoc2md/jsdoc-api/issues/19 */
227
+ fs$1 . mkdirSync ( TempFile . tempFileDir , { recursive : true } ) ;
228
+ fs$1 . mkdirSync ( TempFile . cacheDir , { recursive : true } ) ;
229
+ }
222
230
}
223
231
224
232
function getDefaultExportFromCjs ( x ) {
@@ -4822,12 +4830,12 @@ class Minipass extends node_events.EventEmitter {
4822
4830
}
4823
4831
}
4824
4832
4825
- const realpathSync = fs$1 . realpathSync . native ;
4833
+ const realpathSync = fs . realpathSync . native ;
4826
4834
const defaultFS = {
4827
- lstatSync : fs$1 . lstatSync ,
4828
- readdir : fs$1 . readdir ,
4829
- readdirSync : fs$1 . readdirSync ,
4830
- readlinkSync : fs$1 . readlinkSync ,
4835
+ lstatSync : fs . lstatSync ,
4836
+ readdir : fs . readdir ,
4837
+ readdirSync : fs . readdirSync ,
4838
+ readlinkSync : fs . readlinkSync ,
4831
4839
realpathSync,
4832
4840
promises : {
4833
4841
lstat : promises . lstat ,
@@ -4837,7 +4845,7 @@ const defaultFS = {
4837
4845
} ,
4838
4846
} ;
4839
4847
// if they just gave us require('fs') then use our default
4840
- const fsFromOption = ( fsOption ) => ! fsOption || fsOption === defaultFS || fsOption === actualFS__namespace ?
4848
+ const fsFromOption = ( fsOption ) => ! fsOption || fsOption === defaultFS || fsOption === fs__namespace ?
4841
4849
defaultFS
4842
4850
: {
4843
4851
...defaultFS ,
@@ -8131,7 +8139,7 @@ class FileSet {
8131
8139
files = arrayify ( files ) ;
8132
8140
for ( const file of files ) {
8133
8141
try {
8134
- const stat = await actualFS . promises . stat ( file ) ;
8142
+ const stat = await fs$1 . promises . stat ( file ) ;
8135
8143
if ( stat . isFile ( ) && ! this . files . includes ( file ) ) {
8136
8144
this . files . push ( file ) ;
8137
8145
} else if ( stat . isDirectory ( ) && ! this . dirs . includes ( file ) ) {
@@ -8205,14 +8213,14 @@ class FileSet {
8205
8213
*/
8206
8214
function walkBack ( startAt , lookingFor ) {
8207
8215
startAt = path$1 . resolve ( startAt ) ;
8208
- if ( fs$1 . existsSync ( startAt ) && fs$1 . statSync ( startAt ) . isDirectory ( ) ) {
8216
+ if ( fs . existsSync ( startAt ) && fs . statSync ( startAt ) . isDirectory ( ) ) {
8209
8217
const dirs = path$1 . resolve ( startAt ) . split ( path$1 . sep ) ;
8210
8218
for ( let i = 0 ; i < dirs . length ; i ++ ) {
8211
8219
const basedir = i < dirs . length - 1
8212
8220
? dirs . slice ( 0 , dirs . length - i ) . join ( path$1 . sep )
8213
8221
: path$1 . sep ;
8214
8222
8215
- if ( fs$1 . existsSync ( path$1 . join ( basedir , lookingFor ) ) ) {
8223
+ if ( fs . existsSync ( path$1 . join ( basedir , lookingFor ) ) ) {
8216
8224
return path$1 . join ( basedir , lookingFor )
8217
8225
}
8218
8226
}
@@ -8279,6 +8287,7 @@ class JsdocCommand {
8279
8287
try {
8280
8288
result = await this . getOutput ( ) ;
8281
8289
} finally {
8290
+ /* run even if getOutput fails */
8282
8291
if ( this . tempFiles ) {
8283
8292
for ( const tempFile of this . tempFiles ) {
8284
8293
tempFile . delete ( ) ;
@@ -8349,8 +8358,16 @@ const exec = util.promisify(cp.exec);
8349
8358
8350
8359
class Explain extends JsdocCommand {
8351
8360
async getOutput ( ) {
8352
- if ( this . options . cache && ! this . options . source ) {
8353
- return this . readCache ( ) . catch ( this . _runJsdoc . bind ( this ) )
8361
+ if ( this . options . cache && ! this . options . source . length ) {
8362
+ try {
8363
+ return await this . readCache ( )
8364
+ } catch ( err ) {
8365
+ if ( err . code === 'ENOENT' ) {
8366
+ return this . _runJsdoc ( )
8367
+ } else {
8368
+ throw err
8369
+ }
8370
+ }
8354
8371
} else {
8355
8372
return this . _runJsdoc ( )
8356
8373
}
@@ -8363,7 +8380,7 @@ class Explain extends JsdocCommand {
8363
8380
8364
8381
let jsdocOutput = { stdout : '' , stderr : '' } ;
8365
8382
try {
8366
- jsdocOutput = await exec ( cmd ) ;
8383
+ jsdocOutput = await exec ( cmd , { maxBuffer : 1024 * 1024 * 100 } ) ; /* 100MB */
8367
8384
const explainOutput = JSON . parse ( jsdocOutput . stdout ) ;
8368
8385
if ( this . options . cache ) {
8369
8386
await this . cache . write ( this . cacheKey , explainOutput ) ;
@@ -8380,7 +8397,12 @@ class Explain extends JsdocCommand {
8380
8397
8381
8398
async readCache ( ) {
8382
8399
if ( this . cache ) {
8383
- const promises = this . inputFileSet . files . map ( file => fs . readFile ( file , 'utf8' ) ) ;
8400
+ /* Create the cache key then check the cache for a match, returning pre-generated output if so.
8401
+ The current cache key is a union of the input file names plus their content - this could be expensive when processing a lot of files.
8402
+ */
8403
+ const promises = this . inputFileSet . files . map ( file => {
8404
+ return fs$1 . promises . readFile ( file , 'utf8' )
8405
+ } ) ;
8384
8406
const contents = await Promise . all ( promises ) ;
8385
8407
this . cacheKey = contents . concat ( this . inputFileSet . files ) ;
8386
8408
return this . cache . read ( this . cacheKey )
@@ -8408,16 +8430,17 @@ class Render extends JsdocCommand {
8408
8430
* @typicalname jsdoc
8409
8431
*/
8410
8432
8433
+ TempFile . createTmpDirs ( ) ;
8434
+
8411
8435
/**
8412
8436
* @external cache-point
8413
8437
* @see https://github.com/75lb/cache-point
8414
8438
*/
8415
-
8416
8439
/**
8417
8440
* The [cache-point](https://github.com/75lb/cache-point) instance used when `cache: true` is specified on `.explain()`.
8418
8441
* @type {external:cache-point }
8419
8442
*/
8420
- const cache = new Cache ( { dir : path$1 . join ( os$1 . tmpdir ( ) , 'jsdoc-api' ) } ) ;
8443
+ const cache = new Cache ( { dir : TempFile . cacheDir } ) ;
8421
8444
8422
8445
/**
8423
8446
* @alias module:jsdoc-api
@@ -8459,7 +8482,6 @@ const jsdoc = {
8459
8482
*/
8460
8483
class JsdocOptions {
8461
8484
constructor ( options = { } ) {
8462
-
8463
8485
/**
8464
8486
* One or more filenames to process. Either `files`, `source` or `configure` must be supplied.
8465
8487
* @type {string|string[] }
0 commit comments