Skip to content
This repository was archived by the owner on Jun 18, 2019. It is now read-only.

Commit 28b1a2e

Browse files
authored
develop
1 parent 50ddd26 commit 28b1a2e

12 files changed

Lines changed: 80 additions & 64 deletions

.babelrc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,11 @@
99
"presets": [
1010
["env", {
1111
"targets": {
12-
"node": 6
12+
"node": true
1313
}
1414
}]
1515
],
1616
"plugins": [
17-
["babel-plugin-transform-builtin-extend", {
18-
"globals": [
19-
"Array"
20-
]
21-
}],
2217
"transform-runtime"
2318
],
2419
"only": [

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
fast_finish: true
3838
include:
3939
- stage: release
40-
node_js: 9
40+
node_js: 8
4141
deploy:
4242
skip_cleanup: true
4343
provider: script

package.json

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,38 @@
22
"name": "webpack-config",
33
"description": "Helps to load, extend and merge webpack configs",
44
"main": "dist/index.js",
5-
"files": ["dist/", "src/"],
5+
"files": [
6+
"dist/",
7+
"src/"
8+
],
69
"scripts": {
710
"clean": "rm -rf dist coverage docs",
811
"lint": "eslint --ext js,md ./ --cache",
912
"build": "babel src --out-dir dist --source-maps",
1013
"test": "babel-node jasmine.js",
11-
"cover":
12-
"NODE_ENV=test nyc --reporter=lcov jasmine JASMINE_CONFIG_PATH=jasmine.json",
14+
"cover": "NODE_ENV=test nyc --reporter=lcov jasmine JASMINE_CONFIG_PATH=jasmine.json",
1315
"postcover": "nyc report",
1416
"codeclimate": "codeclimate-test-reporter < ./coverage/lcov.info",
1517
"jsdoc": "jsdoc ./src -c ./jsdoc.json"
1618
},
1719
"nyc": {
18-
"include": ["src/*.js"],
19-
"require": ["babel-register"],
20+
"include": [
21+
"src/*.js"
22+
],
23+
"require": [
24+
"babel-register"
25+
],
2026
"sourceMap": false,
2127
"instrument": false
2228
},
2329
"repository": {
2430
"type": "git",
2531
"url": "https://github.com/Fitbit/webpack-config.git"
2632
},
27-
"keywords": ["webpack", "webpack-config"],
33+
"keywords": [
34+
"webpack",
35+
"webpack-config"
36+
],
2837
"author": "Marat Dreizin <marat.dreizin@gmail.com>",
2938
"license": "Apache-2.0",
3039
"bugs": {
@@ -35,7 +44,6 @@
3544
"babel-cli": "^6.26.0",
3645
"babel-eslint": "^8.2.3",
3746
"babel-plugin-istanbul": "^4.1.6",
38-
"babel-plugin-transform-builtin-extend": "^1.1.2",
3947
"babel-plugin-transform-runtime": "^6.23.0",
4048
"babel-preset-env": "^1.6.1",
4149
"babel-register": "^6.26.0",
@@ -57,6 +65,6 @@
5765
"yargs-parser": "^10.0.0"
5866
},
5967
"engines": {
60-
"node": ">=6.0.0"
68+
"node": ">=8.0.0"
6169
}
6270
}

src/ConfigCache.js

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import {
44
import ConfigStrategyList from './ConfigStrategyList';
55
import 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

105127
export default ConfigCache;

src/ConfigFactory.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
isObject
44
} from 'lodash';
55
import Config from './Config';
6-
import ConfigList from './ConfigList';
76
import { env } from './ConfigArgv';
87

98
/**
@@ -51,7 +50,7 @@ class ConfigFactory {
5150

5251
/**
5352
* @param {Function|Object|Object[]} value
54-
* @returns {Config|ConfigList}
53+
* @returns {Config|Config[]}
5554
*/
5655
createConfig(value) {
5756
let config;
@@ -61,7 +60,7 @@ class ConfigFactory {
6160
}
6261

6362
if (Array.isArray(value)) {
64-
config = ConfigList.from(value, x => this.initWith(x));
63+
config = Array.from(value, x => this.initWith(x));
6564
} else if (isObject(value)) {
6665
config = this.initWith(value);
6766
}

src/ConfigList.js

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/ConfigLoader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class ConfigLoader {
6262

6363
/**
6464
* @param {String} filename
65-
* @returns {Config|ConfigList}
65+
* @returns {Config|Config[]}
6666
*/
6767
loadConfig(filename) {
6868
filename = this.pathResolver.resolve(filename);

src/ConfigPathResolver.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class ConfigPathResolver {
2727
*/
2828
constructor(stringResolver, pathResolvers = DEFAULT_RESOLVERS) {
2929
STRING_RESOLVER.set(this, stringResolver);
30-
PATH_RESOLVERS.set(this, ConfigStrategyList.from(pathResolvers));
30+
PATH_RESOLVERS.set(this, new ConfigStrategyList(pathResolvers));
3131
}
3232

3333
/**

src/ConfigStrategyList.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,39 @@ import {
22
isError
33
} from 'lodash';
44

5+
/**
6+
* @private
7+
* @type {WeakMap}
8+
*/
9+
const RESOLVERS = new WeakMap();
10+
511
/**
612
* @class
7-
* @extends {Array}
813
*/
9-
class ConfigStrategyList extends Array {
14+
class ConfigStrategyList {
15+
/**
16+
* @constructor
17+
* @param {Function[]} resolvers
18+
*/
19+
constructor(resolvers) {
20+
RESOLVERS.set(this, resolvers);
21+
}
22+
23+
/**
24+
* @readonly
25+
* @type {Function[]}
26+
*/
27+
get resolvers() {
28+
return RESOLVERS.get(this);
29+
}
30+
1031
/**
1132
* @param {*} value
1233
* @param {Function} predicate
1334
* @returns {*}
1435
*/
1536
resolve(value, predicate) {
16-
for (const resolver of this) {
37+
for (const resolver of this.resolvers) {
1738
try {
1839
const resolvedValue = resolver(value),
1940
throwsError = isError(resolvedValue) || resolvedValue instanceof Error;

test/ConfigFactory.spec.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import Config from '../src/Config';
2-
import ConfigList from '../src/ConfigList';
32
import ConfigFactory from '../src/ConfigFactory';
43
import MockConfigContainer from './MockConfigContainer';
54

@@ -42,7 +41,7 @@ describe('ConfigFactory', () => {
4241
foo: 'foo1'
4342
}]);
4443

45-
expect(configs).toEqual(jasmine.any(ConfigList));
44+
expect(configs).toEqual(jasmine.any(Array));
4645
expect(configs.length).toEqual(1);
4746
expect(configs[0]).toEqual(jasmine.any(Config));
4847
expect(configs[0].toObject()).toEqual({

0 commit comments

Comments
 (0)