diff --git a/README.md b/README.md index 2a7cad98..3066495e 100644 --- a/README.md +++ b/README.md @@ -184,7 +184,8 @@ The format, with its default values are as follows (using the below ordering of ], "scripts": [ "https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js" - ] + ], + "forceFetch": false }, "export": { "infile": false, @@ -273,6 +274,7 @@ These are set as variables in your environment. They take precedence over option - `HIGHCHARTS_CORE_SCRIPTS`: Highcharts core scripts to fetch. - `HIGHCHARTS_MODULES`: Highcharts modules to fetch. - `HIGHCHARTS_INDICATORS`: Highcharts indicators to fetch. +- `HIGHCHARTS_FORCE_FETCH`: Should refetch all the scripts after each server rerun. ### Custom code config - `HIGHCHARTS_ALLOW_CODE_EXECUTION`: If set to true, allow for the execution of arbitrary code when exporting. diff --git a/lib/cache.js b/lib/cache.js index d01ae510..c8ba97b1 100644 --- a/lib/cache.js +++ b/lib/cache.js @@ -54,7 +54,7 @@ const extractVersion = () => /** * Saves the Highcharts part of a config to a manifest file in the cache * - * @param {object} config - Highcarts related configuration object. + * @param {object} config - Highcharts related configuration object. * @param {object} fetchedModules - An object that contains mapped names of * fetched Highcharts modules to use. */ @@ -121,7 +121,7 @@ const fetchScript = async (script, proxyAgent) => { /** * Updates the Highcharts cache. * - * @param {object} config - Highcarts related configuration object. + * @param {object} config - Highcharts related configuration object. * @param {string} sourcePath - A path to the file where save updated sources. * @return {object} An object that contains mapped names of fetched Highcharts * modules to use. @@ -202,7 +202,7 @@ export const updateVersion = async (newVersion) => /** * Fetches any missing Highcharts and dependencies * - * @param {object} config - Highcarts related configuration object. + * @param {object} config - Highcharts related configuration object. */ export const checkCache = async (config) => { let fetchedModules; @@ -218,8 +218,12 @@ export const checkCache = async (config) => { // Create the .cache destination if it doesn't exist already !existsSync(cachePath) && mkdirSync(cachePath); - // Load the .cache manifest - if (existsSync(manifestPath)) { + // Fetch all the scripts either if manifest.json does not exist + // or if the forceFetch option is enabled + if (!existsSync(manifestPath) || config.forceFetch) { + log(3, '[cache] Fetching and caching Highcharts dependencies.'); + fetchedModules = await updateCache(config, sourcePath); + } else { let requestUpdate = false; // Read the manifest JSON @@ -274,10 +278,6 @@ export const checkCache = async (config) => { fetchedModules = manifest.modules; extractVersion(); } - } else { - // So we don't have one yet, which means we need to fetch everything - log(3, '[cache] Fetching and caching Highcharts dependencies.'); - fetchedModules = await updateCache(config, sourcePath); } // Finally, save the new manifest, which is basically our current config diff --git a/lib/schemas/config.js b/lib/schemas/config.js index b6a40fdd..d648323e 100644 --- a/lib/schemas/config.js +++ b/lib/schemas/config.js @@ -124,6 +124,13 @@ export const defaultConfig = { type: 'string[]', description: 'Additional direct scripts/optional dependencies (e.g. moment.js).' + }, + forceFetch: { + envLink: 'HIGHCHARTS_FORCE_FETCH', + value: false, + type: 'boolean', + description: + 'Should all the scripts be refetched after rerunning the server.' } }, export: { @@ -520,6 +527,12 @@ export const promptsConfig = { message: 'Custom scripts', initial: defaultConfig.highcharts.scripts.value.join(','), separator: ',' + }, + { + type: 'toggle', + name: 'forceFetch', + message: 'Should refetch all the scripts after each server rerun', + initial: defaultConfig.highcharts.forceFetch.value } ], export: [