Skip to content

Commit

Permalink
Added #562, cache path option now supports absolute paths.
Browse files Browse the repository at this point in the history
  • Loading branch information
jszuminski committed Sep 2, 2024
1 parent e740944 commit b6316b8
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions lib/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ See LICENSE file in root for details.
// before starting the service

import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'fs';
import { join } from 'path';
import { isAbsolute, join } from 'path';

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

Expand Down Expand Up @@ -83,7 +83,7 @@ export const saveConfigToManifest = async (config, fetchedModules) => {
log(3, '[cache] Writing a new manifest.');
try {
writeFileSync(
join(__dirname, config.cachePath, 'manifest.json'),
join(getCachePath(), 'manifest.json'),
JSON.stringify(newManifest),
'utf8'
);
Expand Down Expand Up @@ -306,15 +306,17 @@ export const updateVersion = async (newVersion) => {
*/
export const checkAndUpdateCache = async (options) => {
const { highcharts, server } = options;
const cachePath = join(__dirname, highcharts.cachePath);

const cachePath = getCachePath();

let fetchedModules;

// Prepare paths to manifest and sources from the .cache folder
const manifestPath = join(cachePath, 'manifest.json');
const sourcePath = join(cachePath, 'sources.js');

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

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

export const getCachePath = () =>
join(__dirname, getOptions().highcharts.cachePath);
/**
* Returns the path to the cache folder.
* @returns {string} The path to the cache folder.
*/
export const getCachePath = () => {
const cachePathOption = getOptions().highcharts.cachePath;

return isAbsolute(cachePathOption)
? cachePathOption
: join(__dirname, cachePathOption);
};

export const getCache = () => cache;

Expand Down

0 comments on commit b6316b8

Please sign in to comment.