Skip to content

Commit 2341a18

Browse files
authored
Removes direct UUID dep (#474)
Summary: UUID is already exposed in the js-sdk-utils package, so we should use it directly. That will ensure de-duping, as well as automatic tree shaking of the uuid dep (because the utils package imports UUID via ESM).
1 parent 764135b commit 2341a18

File tree

6 files changed

+18
-31
lines changed

6 files changed

+18
-31
lines changed

packages/optimizely-sdk/README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ Prod dependencies are as follows:
100100
"licenses": "MIT*",
101101
"repository": "https://github.com/perezd/node-murmurhash"
102102
},
103-
"uuid@3.3.2": {
104-
"licenses": "MIT",
105-
"repository": "https://github.com/kelektiv/node-uuid"
106-
},
107103
"decompress-response@4.2.1": {
108104
"licenses": "MIT",
109105
"repository": "https://github.com/sindresorhus/decompress-response"

packages/optimizely-sdk/lib/core/event_builder/index.tests.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import uuid from 'uuid';
1716
import sinon from 'sinon';
1817
import { assert } from 'chai';
1918

19+
import fns from '../../utils/fns';
2020
import testData from '../../tests/test_data';
2121
import projectConfig from '../project_config';
2222
import packageJSON from '../../../package.json';
@@ -31,15 +31,15 @@ describe('lib/core/event_builder', function() {
3131
beforeEach(function() {
3232
configObj = projectConfig.createProjectConfig(testData.getTestProjectConfig());
3333
clock = sinon.useFakeTimers(new Date().getTime());
34-
sinon.stub(uuid, 'v4').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
34+
sinon.stub(fns, 'uuid').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
3535
mockLogger = {
3636
log: sinon.stub(),
3737
};
3838
});
3939

4040
afterEach(function() {
4141
clock.restore();
42-
uuid.v4.restore();
42+
fns.uuid.restore();
4343
});
4444

4545
describe('getImpressionEvent', function() {

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
***************************************************************************/
1616
import { assert } from 'chai';
1717
import sinon from 'sinon';
18-
import uuid from 'uuid';
1918
import { sprintf } from '@optimizely/js-sdk-utils';
2019
import * as eventProcessor from '@optimizely/js-sdk-event-processor';
2120
import * as logging from '@optimizely/js-sdk-logging';
@@ -294,7 +293,7 @@ describe('lib/optimizely', function() {
294293
sinon.stub(eventDispatcher, 'dispatchEvent');
295294
sinon.stub(errorHandler, 'handleError');
296295
sinon.stub(createdLogger, 'log');
297-
sinon.stub(uuid, 'v4').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
296+
sinon.stub(fns, 'uuid').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
298297

299298
clock = sinon.useFakeTimers(new Date().getTime());
300299
});
@@ -305,7 +304,7 @@ describe('lib/optimizely', function() {
305304
errorHandler.handleError.restore();
306305
createdLogger.log.restore();
307306
clock.restore();
308-
uuid.v4.restore();
307+
fns.uuid.restore();
309308
});
310309

311310
describe('#activate', function() {
@@ -4337,7 +4336,7 @@ describe('lib/optimizely', function() {
43374336
sandbox.stub(eventDispatcher, 'dispatchEvent');
43384337
sandbox.stub(errorHandler, 'handleError');
43394338
sandbox.stub(createdLogger, 'log');
4340-
sandbox.stub(uuid, 'v4').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
4339+
sandbox.stub(fns, 'uuid').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
43414340
sandbox.stub(fns, 'currentTimestamp').returns(1509489766569);
43424341
clock = sinon.useFakeTimers(new Date().getTime());
43434342
});
@@ -7311,7 +7310,7 @@ describe('lib/optimizely', function() {
73117310
sinon.stub(eventDispatcher, 'dispatchEvent');
73127311
sinon.stub(errorHandler, 'handleError');
73137312
sinon.stub(createdLogger, 'log');
7314-
sinon.stub(uuid, 'v4').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
7313+
sinon.stub(fns, 'uuid').returns('a68cf1ad-0393-4e18-af87-efe8f01a7c9c');
73157314

73167315
clock = sinon.useFakeTimers(new Date().getTime());
73177316
});
@@ -7322,7 +7321,7 @@ describe('lib/optimizely', function() {
73227321
errorHandler.handleError.restore();
73237322
createdLogger.log.restore();
73247323
clock.restore();
7325-
uuid.v4.restore();
7324+
fns.uuid.restore();
73267325
});
73277326

73287327
describe('when eventBatchSize = 3 and eventFlushInterval = 100', function() {

packages/optimizely-sdk/lib/utils/fns/index.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,11 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import uuidLib from 'uuid';
17-
import { keyBy as keyByUtil } from '@optimizely/js-sdk-utils';
16+
import { generateUUID as uuid, keyBy as keyByUtil } from '@optimizely/js-sdk-utils';
1817

1918
var MAX_SAFE_INTEGER_LIMIT = Math.pow(2, 53);
2019

21-
export var assign = function(target) {
20+
export var assign = function (target) {
2221
if (!target) {
2322
return {};
2423
}
@@ -41,26 +40,24 @@ export var assign = function(target) {
4140
}
4241
};
4342

44-
export var currentTimestamp = function() {
43+
export var currentTimestamp = function () {
4544
return Math.round(new Date().getTime());
4645
};
4746

48-
export var isSafeInteger = function(number) {
47+
export var isSafeInteger = function (number) {
4948
return typeof number == 'number' && Math.abs(number) <= MAX_SAFE_INTEGER_LIMIT;
5049
};
5150

52-
export var keyBy = function(arr, key) {
51+
export var keyBy = function (arr, key) {
5352
if (!arr) return {};
54-
return keyByUtil(arr, function(item) {
53+
return keyByUtil(arr, function (item) {
5554
return item[key];
5655
});
5756
};
5857

59-
export var uuid = function() {
60-
return uuidLib.v4();
61-
};
58+
export { uuid };
6259

63-
export var isNumber = function(value) {
60+
export var isNumber = function (value) {
6461
return typeof value === 'number';
6562
};
6663

packages/optimizely-sdk/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@
4343
"@optimizely/js-sdk-logging": "^0.1.0",
4444
"@optimizely/js-sdk-utils": "^0.2.0",
4545
"json-schema": "^0.2.3",
46-
"murmurhash": "0.0.2",
47-
"uuid": "^3.3.2"
46+
"murmurhash": "0.0.2"
4847
},
4948
"devDependencies": {
5049
"@rollup/plugin-commonjs": "^11.0.2",

packages/utils/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
import { v4 } from 'uuid'
16+
export { v4 as generateUUID } from 'uuid'
1717

1818
export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>
1919

2020
export function getTimestamp(): number {
2121
return new Date().getTime()
2222
}
2323

24-
export function generateUUID(): string {
25-
return v4()
26-
}
27-
2824
/**
2925
* Validates a value is a valid TypeScript enum
3026
*

0 commit comments

Comments
 (0)