@@ -17,7 +17,7 @@ See LICENSE file in root for details.
17
17
// before starting the service
18
18
19
19
import { existsSync , mkdirSync , readFileSync , writeFileSync } from 'fs' ;
20
- import { join } from 'path' ;
20
+ import { isAbsolute , join } from 'path' ;
21
21
22
22
import { HttpsProxyAgent } from 'https-proxy-agent' ;
23
23
@@ -83,7 +83,7 @@ export const saveConfigToManifest = async (config, fetchedModules) => {
83
83
log ( 3 , '[cache] Writing a new manifest.' ) ;
84
84
try {
85
85
writeFileSync (
86
- join ( __dirname , config . cachePath , 'manifest.json' ) ,
86
+ join ( getCachePath ( ) , 'manifest.json' ) ,
87
87
JSON . stringify ( newManifest ) ,
88
88
'utf8'
89
89
) ;
@@ -306,15 +306,17 @@ export const updateVersion = async (newVersion) => {
306
306
*/
307
307
export const checkAndUpdateCache = async ( options ) => {
308
308
const { highcharts, server } = options ;
309
- const cachePath = join ( __dirname , highcharts . cachePath ) ;
309
+
310
+ const cachePath = getCachePath ( ) ;
310
311
311
312
let fetchedModules ;
313
+
312
314
// Prepare paths to manifest and sources from the .cache folder
313
315
const manifestPath = join ( cachePath , 'manifest.json' ) ;
314
316
const sourcePath = join ( cachePath , 'sources.js' ) ;
315
317
316
318
// Create the cache destination if it doesn't exist already
317
- ! existsSync ( cachePath ) && mkdirSync ( cachePath ) ;
319
+ ! existsSync ( cachePath ) && mkdirSync ( cachePath , { recursive : true } ) ;
318
320
319
321
// Fetch all the scripts either if manifest.json does not exist
320
322
// or if the forceFetch option is enabled
@@ -387,8 +389,17 @@ export const checkAndUpdateCache = async (options) => {
387
389
await saveConfigToManifest ( highcharts , fetchedModules ) ;
388
390
} ;
389
391
390
- export const getCachePath = ( ) =>
391
- join ( __dirname , getOptions ( ) . highcharts . cachePath ) ;
392
+ /**
393
+ * Returns the path to the cache folder.
394
+ * @returns {string } The path to the cache folder.
395
+ */
396
+ export const getCachePath = ( ) => {
397
+ const cachePathOption = getOptions ( ) . highcharts . cachePath ;
398
+
399
+ return isAbsolute ( cachePathOption )
400
+ ? cachePathOption
401
+ : join ( __dirname , cachePathOption ) ;
402
+ } ;
392
403
393
404
export const getCache = ( ) => cache ;
394
405
0 commit comments