Skip to content

Commit b6316b8

Browse files
committed
Added #562, cache path option now supports absolute paths.
1 parent e740944 commit b6316b8

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/cache.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ See LICENSE file in root for details.
1717
// before starting the service
1818

1919
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
20-
import { join } from 'path';
20+
import { isAbsolute, join } from 'path';
2121

2222
import { HttpsProxyAgent } from 'https-proxy-agent';
2323

@@ -83,7 +83,7 @@ export const saveConfigToManifest = async (config, fetchedModules) => {
8383
log(3, '[cache] Writing a new manifest.');
8484
try {
8585
writeFileSync(
86-
join(__dirname, config.cachePath, 'manifest.json'),
86+
join(getCachePath(), 'manifest.json'),
8787
JSON.stringify(newManifest),
8888
'utf8'
8989
);
@@ -306,15 +306,17 @@ export const updateVersion = async (newVersion) => {
306306
*/
307307
export const checkAndUpdateCache = async (options) => {
308308
const { highcharts, server } = options;
309-
const cachePath = join(__dirname, highcharts.cachePath);
309+
310+
const cachePath = getCachePath();
310311

311312
let fetchedModules;
313+
312314
// Prepare paths to manifest and sources from the .cache folder
313315
const manifestPath = join(cachePath, 'manifest.json');
314316
const sourcePath = join(cachePath, 'sources.js');
315317

316318
// Create the cache destination if it doesn't exist already
317-
!existsSync(cachePath) && mkdirSync(cachePath);
319+
!existsSync(cachePath) && mkdirSync(cachePath, { recursive: true });
318320

319321
// Fetch all the scripts either if manifest.json does not exist
320322
// or if the forceFetch option is enabled
@@ -387,8 +389,17 @@ export const checkAndUpdateCache = async (options) => {
387389
await saveConfigToManifest(highcharts, fetchedModules);
388390
};
389391

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+
};
392403

393404
export const getCache = () => cache;
394405

0 commit comments

Comments
 (0)