@@ -4,6 +4,12 @@ import {
44import ConfigStrategyList from './ConfigStrategyList' ;
55import DEFAULT_RESOLVERS from './ConfigCacheResolvers' ;
66
7+ /**
8+ * @private
9+ * @type {WeakMap }
10+ */
11+ const CACHE = new WeakMap ( ) ;
12+
713/**
814 * @private
915 * @type {String }
@@ -25,19 +31,17 @@ const VALUE_RESOLVERS = new WeakMap();
2531/**
2632 * Please set `WEBPACK_CONFIG_CACHE` environment variable to `false` to make it non persistent or just use {@link ConfigCache#persistent}
2733 * @class
28- * @extends {Map }
2934 */
30- class ConfigCache extends Map {
35+ class ConfigCache {
3136 /**
3237 * @constructor
3338 * @param {ConfigEnvironment } environment
3439 * @param {Function[] } [valueResolvers]
3540 */
3641 constructor ( environment , valueResolvers = DEFAULT_RESOLVERS ) {
37- super ( ) ;
38-
42+ CACHE . set ( this , new Map ( ) ) ;
3943 ENVIRONMENT . set ( this , environment ) ;
40- VALUE_RESOLVERS . set ( this , ConfigStrategyList . from ( valueResolvers ) ) ;
44+ VALUE_RESOLVERS . set ( this , new ConfigStrategyList ( valueResolvers ) ) ;
4145 }
4246
4347 /**
@@ -55,6 +59,15 @@ class ConfigCache extends Map {
5559 return this . environment . getOrDefault ( PERSISTENT_KEY , true ) === true ;
5660 }
5761
62+ /**
63+ * @private
64+ * @readonly
65+ * @type {Map }
66+ */
67+ get cache ( ) {
68+ return CACHE . get ( this ) ;
69+ }
70+
5871 /**
5972 * @example
6073 * import {
@@ -79,18 +92,19 @@ class ConfigCache extends Map {
7992 }
8093
8194 /**
82- * @override
95+ * @param {String } key
96+ * @returns {* }
8397 */
8498 get ( key ) {
8599 let value ;
86100
87101 if ( this . persistent ) {
88- if ( ! this . has ( key ) ) {
102+ if ( ! this . cache . has ( key ) ) {
89103 value = require ( key ) ;
90104
91- this . set ( key , value ) ;
105+ this . cache . set ( key , value ) ;
92106 } else {
93- value = super . get ( key ) ;
107+ value = this . cache . get ( key ) ;
94108 }
95109 } else {
96110 delete require . cache [ key ] ;
@@ -100,6 +114,14 @@ class ConfigCache extends Map {
100114
101115 return this . valueResolvers . resolve ( value , x => ! isUndefined ( x ) ) ;
102116 }
117+ /**
118+ * @param {String } key
119+ * @param {* } value
120+ * @returns {void }
121+ */
122+ set ( key , value ) {
123+ return this . cache . set ( key , value ) ;
124+ }
103125}
104126
105127export default ConfigCache ;
0 commit comments