Skip to content

Commit 90f5591

Browse files
committed
The extractModuleNames function and env corrections.
1 parent 18c89ea commit 90f5591

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

lib/cache.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,14 @@ export const extractVersion = (cache) => {
5252

5353
/**
5454
* Extracts the Highcharts module name based on the scriptPath.
55+
*
56+
* @param {string} scriptPath - The path to the module.
57+
*
58+
* @returns {string} The name of a module.
5559
*/
5660
export const extractModuleName = (scriptPath) => {
57-
return scriptPath
58-
.replace(/\\/g, '/')
59-
.replace(
60-
/(.*)\/|(.*)modules\/|stock\/(.*)indicators\/|maps\/(.*)modules\//gi,
61-
''
62-
)
63-
.replace(/\.min\.js$|\.js$/i, '');
61+
// Normalize slashes, get part after the last '/' and remove .js extension
62+
return scriptPath.replace(/\\/g, '/').split('/').pop().replace(/\.js$/i, '');
6463
};
6564

6665
/**

lib/envs.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ export const Config = z.object({
141141
})
142142
)
143143
.transform((value) => (value !== '' ? value : undefined)),
144+
HIGHCHARTS_USE_NPM: v.boolean(),
144145
HIGHCHARTS_CORE_SCRIPTS: v.array(scriptsNames.core),
145146
HIGHCHARTS_MODULE_SCRIPTS: v.array(scriptsNames.modules),
146147
HIGHCHARTS_INDICATOR_SCRIPTS: v.array(scriptsNames.indicators),

lib/schemas/config.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ export const defaultConfig = {
168168
envLink: 'HIGHCHARTS_CDN_URL',
169169
description: 'The CDN URL for Highcharts scripts to be used.'
170170
},
171+
useNpm: {
172+
value: false,
173+
type: 'boolean',
174+
envLink: 'HIGHCHARTS_USE_NPM',
175+
description: 'Flag to use Highcharts scripts from NPM package'
176+
},
171177
coreScripts: {
172178
value: scriptsNames.core,
173179
type: 'string[]',
@@ -191,12 +197,6 @@ export const defaultConfig = {
191197
type: 'string[]',
192198
description: 'Additional custom scripts or dependencies to fetch.'
193199
},
194-
useNpm: {
195-
value: false,
196-
type: 'boolean',
197-
envLink: 'HIGHCHARTS_USE_NPM',
198-
description: 'Flag to use Highcharts scripts from NPM package'
199-
},
200200
forceFetch: {
201201
value: false,
202202
type: 'boolean',
@@ -759,6 +759,12 @@ export const promptsConfig = {
759759
message: 'The URL of CDN',
760760
initial: defaultConfig.highcharts.cdnURL.value
761761
},
762+
{
763+
type: 'toggle',
764+
name: 'useNpm',
765+
message: 'Flag to use Highcharts scripts from NPM package',
766+
initial: defaultConfig.highcharts.useNpm.value
767+
},
762768
{
763769
type: 'multiselect',
764770
name: 'coreScripts',
@@ -787,12 +793,6 @@ export const promptsConfig = {
787793
initial: defaultConfig.highcharts.customScripts.value.join(','),
788794
separator: ','
789795
},
790-
{
791-
type: 'toggle',
792-
name: 'useNpm',
793-
message: 'Flag to use Highcharts scripts from NPM package',
794-
initial: defaultConfig.highcharts.useNpm.value
795-
},
796796
{
797797
type: 'toggle',
798798
name: 'forceFetch',

tests/unit/cache.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ describe('extractVersion', () => {
1313
describe('extractModuleName', () => {
1414
it('should extract the module name from a given script path', () => {
1515
const paths = [
16-
{ input: 'modules/exporting', expected: 'exporting' },
17-
{ input: 'maps/modules/map', expected: 'map' }
16+
{ input: 'modules/exporting.js', expected: 'exporting' },
17+
{ input: 'maps/modules/map.js', expected: 'map' }
1818
];
1919

2020
paths.forEach(({ input, expected }) => {

0 commit comments

Comments
 (0)