Skip to content

Commit 29bb18b

Browse files
committed
First iteration migrating cjs to es modules, also updted some libraries and updated builds commands
1 parent 5553a39 commit 29bb18b

File tree

212 files changed

+1007
-1072
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+1007
-1072
lines changed

.babelrc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"presets": [
3-
"env"
3+
["env", {
4+
"modules": false
5+
}]
46
],
57

68
"plugins": [
@@ -10,7 +12,19 @@
1012
],
1113

1214
"env": {
15+
"cjs": {
16+
"presets": [
17+
["env", {
18+
"modules": "commonjs"
19+
}]
20+
],
21+
},
1322
"test": {
23+
"presets": [
24+
["env", {
25+
"modules": "commonjs"
26+
}]
27+
],
1428
"plugins": [
1529
["istanbul", {
1630
"exclude": [

package.json

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
"files": [
66
"README.md",
77
"lib",
8-
"types/*.d.ts"
8+
"types/*.d.ts",
9+
"es6"
910
],
1011
"repository": "splitio/javascript-client",
1112
"homepage": "https://github.com/splitio/javascript-client#readme",
@@ -17,9 +18,14 @@
1718
"name": "Nico Zelaya",
1819
"email": "nicolas.zelaya@split.io",
1920
"url": "https://github.com/NicoZelaya"
21+
},
22+
{
23+
"name": "Manuel Marquez",
24+
"email": "manuel@split.io"
2025
}
2126
],
2227
"main": "lib/index.js",
28+
"module": "es6/index.js",
2329
"types": "types",
2430
"devDependencies": {
2531
"babel-cli": "^6.26.0",
@@ -35,25 +41,27 @@
3541
"cross-env": "^5.1.3",
3642
"csv-streamify": "^3.0.4",
3743
"eslint": "^4.5.0",
38-
"fetch-mock": "^5.12.2",
39-
"karma": "^1.7.1",
40-
"karma-chrome-launcher": "^2.2.0",
41-
"karma-coverage": "^1.1.1",
42-
"karma-firefox-launcher": "^1.0.0",
43-
"karma-phantomjs-launcher": "~1.0.2",
44-
"karma-safari-launcher": "^1.0.0",
45-
"karma-sauce-launcher": "^1.2.0",
46-
"karma-tap": "^3.0.1",
47-
"karma-webpack": "^2.0.4",
44+
"karma": "2.0.0",
45+
"karma-chrome-launcher": "2.2.0",
46+
"karma-coverage": "1.1.1",
47+
"karma-firefox-launcher": "1.1.0",
48+
"karma-phantomjs-launcher": "1.0.4",
49+
"karma-safari-launcher": "1.0.0",
50+
"karma-sauce-launcher": "1.2.0",
51+
"karma-tap": "4.0.0",
52+
"karma-webpack": "2.0.9",
4853
"redis-dump": "0.1.10",
4954
"rimraf": "^2.5.4",
5055
"tape": "^4.8.0",
5156
"tape-catch": "^1.0.6",
52-
"webpack": "^3.5.5"
57+
"webpack": "^3.5.5",
58+
"fetch-mock": "^6.0.0"
5359
},
5460
"scripts": {
61+
"build-esm": "rimraf es6 && cross-env BABEL_ENV=esm babel ./src -d es6 --ignore '__tests__'",
62+
"postbuild-esm": "cross-env NODE_ENV=esm node scripts/copy.packages.json.js",
5563
"build-cjs": "rimraf lib && cross-env BABEL_ENV=cjs babel ./src -d lib --ignore '__tests__'",
56-
"postbuild-cjs": "node scripts/copy.packages.json.js",
64+
"postbuild-cjs": "cross-env NODE_ENV=cjs node scripts/copy.packages.json.js",
5765
"build-umd": "cross-env NODE_ENV=development webpack",
5866
"build-min": "cross-env NODE_ENV=production webpack -p",
5967
"rebuild": "rimraf lib umd && npm run build-cjs && npm run build-umd && npm run build-min",
@@ -66,11 +74,11 @@
6674
"test-browser-e2e-ci": "cross-env NODE_ENV=test karma start karma/e2e.ci.karma.conf.js",
6775
"test-browser-offline": "cross-env NODE_ENV=test karma start karma/offline.karma.conf.js",
6876
"test-browser-destroy": "cross-env NODE_ENV=test karma start karma/destroy.ci.karma.conf.js",
69-
"test-node": "tape -r babel-register \"src/*/__tests__/**/!(browser).spec.js\"",
70-
"test-node-e2e": "tape -r babel-register src/__tests__/destroy/node.spec.js",
71-
"test-node-offline": "tape -r babel-register src/__tests__/offline/node.spec.js",
77+
"test-node": "cross-env BABEL_ENV=test tape -r babel-register \"src/*/__tests__/**/!(browser).spec.js\"",
78+
"test-node-e2e": "cross-env BABEL_ENV=test tape -r babel-register src/__tests__/destroy/node.spec.js",
79+
"test-node-offline": "cross-env BABEL_ENV=test tape -r babel-register src/__tests__/offline/node.spec.js",
7280
"pretest-node-redis": "cat ./src/__tests__/mocks/redis_mock.json | ./node_modules/redis-dump/bin/cli/redis-dump --convert | redis-cli",
73-
"test-node-redis": "tape -r babel-register \"src/__tests__/node_redis.spec.js\"",
81+
"test-node-redis": "cross-env BABEL_ENV=test tape -r babel-register \"src/__tests__/node_redis.spec.js\"",
7482
"pretest-ts-decls": "npm link",
7583
"test-ts-decls": "./scripts/ts-tests.sh",
7684
"posttest-ts-decls": "npm unlink && npm install",
@@ -80,6 +88,7 @@
8088
"stable": "npm run rebuild && npm publish"
8189
},
8290
"dependencies": {
91+
"5to6-codemod": "^1.7.1",
8392
"@types/node": "^8.0.26",
8493
"babel-runtime": "^6.26.0",
8594
"core-js": "^2.5.0",

scripts/copy.packages.json.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
const copyfiles = require('copyfiles');
44

55
const input = './src/**/package.json';
6-
const outputDir = './lib';
6+
const outputCjsDir = './lib';
7+
const outputEsmDir = './es6';
78

8-
copyfiles([input, outputDir], {
9+
copyfiles([input, process.env.NODE_ENV === 'cjs' ? outputCjsDir : outputEsmDir], {
910
up: 1
1011
}, (err) => {
1112
if (err) {

src/__tests__/browser.spec.js

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
'use strict';
2+
23
// Requiring the Split Facade, which requires 'isomorphic-fetch'
3-
require('../');
4+
// import '../';
5+
46
// This override the default implementation, so you MUST to be sure you include
57
// this AFTER the require('isomorphic-fetch')
6-
const fetchMock = require('fetch-mock');
7-
8-
const evaluationsSuite = require('./browserSuites/evaluations.spec');
9-
const impressionsSuite = require('./browserSuites/impressions.spec');
10-
const eventsSuite = require('./browserSuites/events.spec');
11-
const sharedInstantiationSuite = require('./browserSuites/shared-instantiation.spec');
8+
import fetchMock from 'fetch-mock';
129

13-
const tape = require('tape');
14-
const SettingsFactory = require('../utils/settings');
10+
import evaluationsSuite from './browserSuites/evaluations.spec';
11+
import impressionsSuite from './browserSuites/impressions.spec';
12+
import {
13+
withoutBindingTT,
14+
bindingTT
15+
} from './browserSuites/events.spec';
16+
import sharedInstantiationSuite from './browserSuites/shared-instantiation.spec';
17+
import tape from 'tape';
18+
import SettingsFactory from '../utils/settings';
1519
const settings = SettingsFactory({
1620
core: {
1721
key: 'facundo@split.io'
1822
}
1923
});
2024

21-
const splitChangesMock1 = require('./mocks/splitchanges.since.-1.json');
22-
const splitChangesMock2 = require('./mocks/splitchanges.since.1457552620999.json');
23-
const mySegmentsFacundo = require('./mocks/mysegments.facundo@split.io.json');
24-
const mySegmentsNicolas = require('./mocks/mysegments.nicolas@split.io.json');
25-
const mySegmentsMarcio = require('./mocks/mysegments.marcio@split.io.json');
25+
import splitChangesMock1 from './mocks/splitchanges.since.-1.json';
26+
import splitChangesMock2 from './mocks/splitchanges.since.1457552620999.json';
27+
import mySegmentsFacundo from './mocks/mysegments.facundo@split.io.json';
28+
import mySegmentsNicolas from './mocks/mysegments.nicolas@split.io.json';
29+
import mySegmentsMarcio from './mocks/mysegments.marcio@split.io.json';
2630

2731
const delayResponse = mock => {
2832
return new Promise(res => setTimeout(res, 0)).then(() => mock);
@@ -88,8 +92,8 @@ tape('## E2E CI Tests ##', function(assert) {
8892
/* Check impressions */
8993
assert.test('E2E / Impressions', impressionsSuite);
9094
/* Check events */
91-
assert.test('E2E / Events', eventsSuite.withoutBindingTT);
92-
assert.test('E2E / Events with TT binded', eventsSuite.bindingTT);
95+
assert.test('E2E / Events', withoutBindingTT);
96+
assert.test('E2E / Events with TT binded', bindingTT);
9397
/* Check shared clients */
9498
assert.test('E2E / Shared instances', sharedInstantiationSuite.bind(null, false));
9599
assert.test('E2E / Shared instances with Traffic Type on factory settings', sharedInstantiationSuite.bind(null, true));

src/__tests__/browserSuites/evaluations.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const SplitFactory = require('../../');
1+
import SplitFactory from '../../';
22

33
const SDK_INSTANCES_TO_TEST = 4;
44

5-
module.exports = function(config, assert) {
5+
export default function(config, assert) {
66
let i = 0, tested = 0;
77
const wBucketing = !!config.core.key.bucketingKey;
88

src/__tests__/browserSuites/events.spec.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
'use strict';
22

3-
const SplitFactory = require('../../');
4-
5-
const fetchMock = require('fetch-mock');
6-
7-
const SettingsFactory = require('../../utils/settings');
3+
import SplitFactory from '../../';
4+
import fetchMock from 'fetch-mock';
5+
import SettingsFactory from '../../utils/settings';
86
const settings = SettingsFactory({
97
core: {
108
key: 'asd'
@@ -28,7 +26,7 @@ const baseSettings = {
2826
}
2927
};
3028

31-
function withoutBindingTT(assert) {
29+
export function withoutBindingTT(assert) {
3230
const splitio = SplitFactory(baseSettings);
3331
const client = splitio.client();
3432

@@ -83,7 +81,7 @@ function withoutBindingTT(assert) {
8381
assert.notOk(client.track('asd', 20, 'trafficType'), 'client.track returns false if an event data was incorrect and it could not be added to the queue.');
8482
}
8583

86-
function bindingTT(assert) {
84+
export function bindingTT(assert) {
8785
const localSettings = Object.assign({}, baseSettings);
8886
localSettings.core.trafficType = 'binded_tt';
8987
const splitio = SplitFactory(localSettings);
@@ -139,8 +137,3 @@ function bindingTT(assert) {
139137
assert.notOk(client.track(), 'client.track returns false if an event data was incorrect and it could not be added to the queue.');
140138
assert.notOk(client.track(10, 'someTrafficType', 'someEvent'), 'client.track returns false if an event data was incorrect and it could not be added to the queue.');
141139
}
142-
143-
module.exports = {
144-
withoutBindingTT,
145-
bindingTT
146-
};

src/__tests__/browserSuites/impressions.spec.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
'use strict';
22

3-
const SplitFactory = require('../../');
4-
5-
const fetchMock = require('fetch-mock');
6-
7-
const SettingsFactory = require('../../utils/settings');
3+
import SplitFactory from '../../';
4+
import fetchMock from 'fetch-mock';
5+
import SettingsFactory from '../../utils/settings';
86
const settings = SettingsFactory({
97
core: {
108
key: 'asd'
119
}
1210
});
1311

14-
module.exports = function(assert) {
12+
export default function(assert) {
1513

1614
const splitio = SplitFactory({
1715
core: {
@@ -64,4 +62,4 @@ module.exports = function(assert) {
6462
// depends on hierarchical_dep_hierarchical which depends on hierarchical_dep_always_on
6563
assert.equal(client.getTreatment('hierarchical_splits_test'), 'on', 'We should get an evaluation as always.');
6664
});
67-
};
65+
};

src/__tests__/browserSuites/shared-instantiation.spec.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
'use strict';
22

3-
const SplitFactory = require('../../');
4-
5-
const SettingsFactory = require('../../utils/settings');
3+
import SplitFactory from '../../';
4+
import SettingsFactory from '../../utils/settings';
65
const settings = SettingsFactory({
76
core: {
87
key: 'asd'
98
}
109
});
1110

12-
const fetchMock = require('fetch-mock');
11+
import fetchMock from 'fetch-mock';
1312

14-
module.exports = function(startWithTT, assert) {
13+
export default function(startWithTT, assert) {
1514
const factory = SplitFactory({
1615
core: {
1716
authorizationKey: 'dummy',
@@ -120,4 +119,4 @@ module.exports = function(startWithTT, assert) {
120119
assert.comment('Shared instance - marcio@split.io');
121120
getTreatmentsAssertions(marcioClient, ['off', 'on', 'off', 'off']);
122121
});
123-
};
122+
};

src/__tests__/destroy/browser.spec.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
const tape = require('tape');
2-
const map = require('lodash/map');
3-
const pick = require('lodash/pick');
4-
5-
const SplitFactory = require('../../');
6-
7-
const fetchMock = require('fetch-mock');
8-
9-
const SettingsFactory = require('../../utils/settings');
1+
import tape from 'tape';
2+
import map from 'lodash/map';
3+
import pick from 'lodash/pick';
4+
import SplitFactory from '../../';
5+
import fetchMock from 'fetch-mock';
6+
import SettingsFactory from '../../utils/settings';
107
const settings = SettingsFactory({
118
core: {
129
key: 'facundo@split.io'
1310
}
1411
});
1512

16-
const splitChangesMock1 = require('./splitChanges.since.-1.json');
17-
const splitChangesMock2 = require('./splitChanges.since.1500492097547.json');
18-
const mySegmentsMock = require('./mySegments.json');
19-
const impressionsMock = require('./impressions.json');
13+
import splitChangesMock1 from './splitChanges.since.-1.json';
14+
import splitChangesMock2 from './splitChanges.since.1500492097547.json';
15+
import mySegmentsMock from './mySegments.json';
16+
import impressionsMock from './impressions.json';
2017

2118
const delayResponse = mock => {
2219
return new Promise(res => setTimeout(res, 0)).then(() => mock);
@@ -108,4 +105,4 @@ tape('SDK destroy for BrowserJS', async function (assert) {
108105
assert.equal( manager.split('Single_Test') , null );
109106

110107
assert.end();
111-
});
108+
});

src/__tests__/destroy/node.spec.js

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
const tape = require('tape');
2-
const map = require('lodash/map');
3-
const pick = require('lodash/pick');
4-
5-
const SplitFactory = require('../../');
6-
7-
const fetchMock = require('fetch-mock');
8-
9-
const SettingsFactory = require('../../utils/settings');
1+
import tape from 'tape';
2+
import map from 'lodash/map';
3+
import pick from 'lodash/pick';
4+
import SplitFactory from '../../';
5+
import fetchMock from 'fetch-mock';
6+
import SettingsFactory from '../../utils/settings';
107
const settings = SettingsFactory({
118
core: {
129
key: 'facundo@split.io'
1310
}
1411
});
1512

16-
const splitChangesMock1 = require('./splitChanges.since.-1.json');
17-
const splitChangesMock2 = require('./splitChanges.since.1500492097547.json');
18-
const impressionsMock = require('./impressions.json');
13+
import splitChangesMock1 from './splitChanges.since.-1.json';
14+
import splitChangesMock2 from './splitChanges.since.1500492097547.json';
15+
import impressionsMock from './impressions.json';
1916

2017
const delayResponse = (mock) => {
2118
return new Promise(res => setTimeout(res, 0)).then(() => mock);

0 commit comments

Comments
 (0)