diff --git a/.circleci/config.yml b/.circleci/config.yml index 8a9999bd..853e882a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2 jobs: build: docker: - - image: cimg/node:12.22 + - image: cimg/node:14.20 steps: - checkout diff --git a/.eslintrc.yaml b/.eslintrc.yaml index 5b7ce5ef..3c751332 100644 --- a/.eslintrc.yaml +++ b/.eslintrc.yaml @@ -1,5 +1,5 @@ --- - parser: babel-eslint + parser: "@babel/eslint-parser" root: true extends: - prettier diff --git a/jest.config.js b/jest.config.js index aa175c59..05de06a1 100644 --- a/jest.config.js +++ b/jest.config.js @@ -7,11 +7,14 @@ module.exports = { setupFiles: ['jest-localstorage-mock', './jest.setup.js'], testMatch: ['**/__tests__/**/*-test.js'], transform: { - '^.+\\.js$': 'babel-jest', + '^.+\\.js$': ['babel-jest', { rootMode: 'upward' }], }, globals: { window: true, VERSION: version, }, - testURL: 'https://mydomain.com/some/path', + testEnvironmentOptions: { + url: 'https://mydomain.com/some/path', + }, + testEnvironment: 'jsdom', }; diff --git a/package.json b/package.json index 1a064d61..dd7fd77f 100644 --- a/package.json +++ b/package.json @@ -41,46 +41,43 @@ "prepublishOnly": "npm run build:min" }, "devDependencies": { - "@babel/cli": "^7.11.6", - "@babel/core": "^7.11.6", - "@babel/plugin-transform-regenerator": "7.10.4", - "@babel/plugin-transform-runtime": "7.11.5", - "@babel/preset-env": "^7.11.5", - "@babel/runtime": "^7.11.2", - "@rollup/plugin-node-resolve": "^6.0.0", - "@rollup/plugin-replace": "^2.2.0", - "babel-eslint": "^10.1.0", - "babel-jest": "^26.3.0", - "chai": "^4.1.2", - "cross-env": "^5.1.4", - "eslint": "^6.8.0", - "eslint-config-prettier": "^2.9.0", - "eslint-config-xo": "^0.20.1", - "eslint-formatter-pretty": "^1.3.0", - "eslint-plugin-babel": "^5.0.0", - "eslint-plugin-prettier": "^2.6.0", - "jest": "^26.6.3", - "jest-junit": "^11.1.0", - "jest-localstorage-mock": "^2.4.3", - "jsdom": "^11.12.0", - "prettier": "1.11.1", - "readline-sync": "1.4.9", + "@babel/cli": "^7.19.3", + "@babel/core": "^7.19.3", + "@babel/eslint-parser": "7.19.1", + "@babel/plugin-transform-regenerator": "7.18.6", + "@babel/plugin-transform-runtime": "7.19.1", + "@babel/preset-env": "^7.19.3", + "@babel/runtime": "^7.19.0", + "@rollup/plugin-node-resolve": "^14.1.0", + "@rollup/plugin-replace": "^4.0.0", + "babel-jest": "^29.1.0", + "cross-env": "^7.0.3", + "eslint": "^8.24.0", + "eslint-config-prettier": "^8.5.0", + "eslint-config-xo": "^0.42.0", + "eslint-formatter-pretty": "^4.1.0", + "eslint-plugin-babel": "^5.3.1", + "eslint-plugin-prettier": "^4.2.1", + "jest": "^29.1.1", + "jest-environment-jsdom": "^29.1.1", + "jest-junit": "^14.0.1", + "jest-localstorage-mock": "^2.4.22", + "jsdom": "^20.0.0", + "prettier": "2.7.1", "rimraf": "^3.0.2", - "rollup": "^1.26.0", - "rollup-plugin-babel": "^4.3.3", + "rollup": "^2.79.1", + "rollup-plugin-babel": "^4.4.0", "rollup-plugin-commonjs": "^10.1.0", - "rollup-plugin-filesize": "^6.2.1", + "rollup-plugin-filesize": "^9.1.2", "rollup-plugin-node-globals": "^1.4.0", "rollup-plugin-terser": "^7.0.2", - "rollup-plugin-uglify": "^6.0.4", - "semver": "^7.1.3", - "semver-compare": "^1.0.0", - "sinon": "7.2.7", - "typescript": "^3.7.5" + "sinon": "^14.0.0", + "typescript": "^4.8.4", + "@types/estree": "^1.0.0" }, "dependencies": { - "escape-string-regexp": "^1.0.5", - "launchdarkly-js-sdk-common": "3.6.0" + "escape-string-regexp": "^4.0.0", + "launchdarkly-js-sdk-common": "3.7.0" }, "repository": { "type": "git", diff --git a/rollup.config.js b/rollup.config.js index bd4ea49b..44dedbfd 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,10 +1,9 @@ const pkg = require('./package.json'); -const resolve = require('@rollup/plugin-node-resolve'); +const { nodeResolve } = require('@rollup/plugin-node-resolve'); const commonjs = require('rollup-plugin-commonjs'); const babel = require('rollup-plugin-babel'); const replace = require('@rollup/plugin-replace'); const { terser } = require('rollup-plugin-terser'); -const { uglify } = require('rollup-plugin-uglify'); const filesize = require('rollup-plugin-filesize'); const env = process.env.NODE_ENV || 'development'; @@ -17,7 +16,7 @@ const basePlugins = [ 'process.env.NODE_ENV': JSON.stringify(env), VERSION: JSON.stringify(version), }), - resolve({ + nodeResolve({ mainFields: ['browser', 'module', 'main'], preferBuiltins: true, }), @@ -29,12 +28,6 @@ const basePlugins = [ ]; const plugins = env === 'production' ? - basePlugins.concat( - uglify() - ) : - basePlugins; - -const esPlugins = env === 'production' ? basePlugins.concat( terser() ) : basePlugins; @@ -66,7 +59,7 @@ const configs = [ format: 'es', sourcemap: true, }, - plugins: esPlugins, + plugins: plugins, }, ]; diff --git a/src/GoalManager.js b/src/GoalManager.js index 28cfd114..87b57d04 100644 --- a/src/GoalManager.js +++ b/src/GoalManager.js @@ -75,7 +75,7 @@ export default function GoalManager(clientVars, readyCallback) { clientVars.requestor .fetchJSON(getGoalsPath()) - .then(g => { + .then((g) => { if (g && g.length > 0) { goals = g; goalTracker = GoalTracker(goals, sendGoalEvent); @@ -83,7 +83,7 @@ export default function GoalManager(clientVars, readyCallback) { } readyCallback(); }) - .catch(err => { + .catch((err) => { clientVars.emitter.maybeReportError( new common.errors.LDUnexpectedResponseError('Error fetching goals: ' + (err && err.message) ? err.message : err) ); diff --git a/src/GoalTracker.js b/src/GoalTracker.js index 7bc1311a..fa9fb63d 100644 --- a/src/GoalTracker.js +++ b/src/GoalTracker.js @@ -75,7 +75,7 @@ export default function GoalTracker(goals, onEvent) { } if (clickGoals.length > 0) { - listenerFn = function(event) { + listenerFn = function (event) { const goals = findGoalsForClick(event, clickGoals); for (let i = 0; i < goals.length; i++) { onEvent('click', goals[i]); @@ -85,7 +85,7 @@ export default function GoalTracker(goals, onEvent) { document.addEventListener('click', listenerFn); } - tracker.dispose = function() { + tracker.dispose = function () { document.removeEventListener('click', listenerFn); }; diff --git a/src/__tests__/LDClient-events-test.js b/src/__tests__/LDClient-events-test.js index d4ae18ae..919fd0d6 100644 --- a/src/__tests__/LDClient-events-test.js +++ b/src/__tests__/LDClient-events-test.js @@ -17,10 +17,10 @@ describe('LDClient', () => { describe('event generation', () => { function stubEventProcessor() { const ep = { events: [] }; - ep.start = function() {}; - ep.flush = function() {}; - ep.stop = function() {}; - ep.enqueue = function(e) { + ep.start = function () {}; + ep.flush = function () {}; + ep.stop = function () {}; + ep.enqueue = function (e) { ep.events.push(e); }; return ep; @@ -65,7 +65,7 @@ describe('LDClient', () => { const client = LDClient.initialize(envName, user, { eventProcessor: ep, bootstrap: {}, - eventUrlTransformer: url => url + suffix, + eventUrlTransformer: (url) => url + suffix, }); await client.waitForInitialization(); client.track('eventkey'); diff --git a/src/__tests__/LDClient-test.js b/src/__tests__/LDClient-test.js index 316038c1..0c195e52 100644 --- a/src/__tests__/LDClient-test.js +++ b/src/__tests__/LDClient-test.js @@ -116,7 +116,7 @@ describe('LDClient', () => { expect(server.requests[0].url).toMatch(/sdk\/eval/); }); - it('should resolve waitUntilGoalsReady when goals are loaded', done => { + it('should resolve waitUntilGoalsReady when goals are loaded', (done) => { const handleGoalsReady = jest.fn(); const client = LDClient.initialize(envName, user, { bootstrap: {}, sendEvents: false }); diff --git a/src/__tests__/browserPlatform-test.js b/src/__tests__/browserPlatform-test.js index 659188c4..f6733089 100644 --- a/src/__tests__/browserPlatform-test.js +++ b/src/__tests__/browserPlatform-test.js @@ -95,7 +95,7 @@ describe('browserPlatform', () => { }); it('calls URL transformer if specified', () => { - const p = browserPlatform({ eventUrlTransformer: url => url + '/x' }); + const p = browserPlatform({ eventUrlTransformer: (url) => url + '/x' }); expect(p.getCurrentUrl()).toEqual(expectedUrl + '/x'); }); }); diff --git a/src/__tests__/internal-test.js b/src/__tests__/internal-test.js index db83e5a6..dbc5a128 100644 --- a/src/__tests__/internal-test.js +++ b/src/__tests__/internal-test.js @@ -1,12 +1,12 @@ import { doesUrlMatch } from '../GoalTracker'; describe('url matching', () => { - const getHash = url => { + const getHash = (url) => { const idx = url.indexOf('#'); return idx === -1 ? '' : url.substring(idx, url.length); }; - const getSearch = url => { + const getSearch = (url) => { const idx = url.indexOf('?'); return idx === -1 ? '' : url.substring(idx, url.length); }; @@ -208,9 +208,9 @@ describe('url matching', () => { }, ]; - tests.forEach(method => { + tests.forEach((method) => { describe(method.type + ' matching', () => { - method.tests.forEach(each => { + method.tests.forEach((each) => { it(`expects \`${each.goal}\` to ${each.match ? 'match' : 'not match'} \`${each.path}\``, async () => { method.matcher(each.path, each.goal).toEqual(each.match); }); diff --git a/src/browserPlatform.js b/src/browserPlatform.js index 3147783e..f2da795e 100644 --- a/src/browserPlatform.js +++ b/src/browserPlatform.js @@ -25,7 +25,7 @@ export default function makeBrowserPlatform(options) { }; // Image-based mechanism for sending events if POST isn't available - ret.httpFallbackPing = url => { + ret.httpFallbackPing = (url) => { const img = new window.Image(); img.src = url; }; @@ -48,17 +48,17 @@ export default function makeBrowserPlatform(options) { try { if (window.localStorage) { ret.localStorage = { - get: key => - new Promise(resolve => { + get: (key) => + new Promise((resolve) => { resolve(window.localStorage.getItem(key)); }), set: (key, value) => - new Promise(resolve => { + new Promise((resolve) => { window.localStorage.setItem(key, value); resolve(); }), - clear: key => - new Promise(resolve => { + clear: (key) => + new Promise((resolve) => { window.localStorage.removeItem(key); resolve(); }), @@ -116,7 +116,7 @@ export default function makeBrowserPlatform(options) { return new eventSourceConstructor(url, esOptions); }; - ret.eventSourceIsActive = es => + ret.eventSourceIsActive = (es) => es.readyState === window.EventSource.OPEN || es.readyState === window.EventSource.CONNECTING; } diff --git a/src/httpRequest.js b/src/httpRequest.js index 6d71260f..be2ec435 100644 --- a/src/httpRequest.js +++ b/src/httpRequest.js @@ -43,7 +43,7 @@ export default function newHttpRequest(method, url, headers, body, pageIsClosing } resolve({ status: xhr.status, - header: key => xhr.getResponseHeader(key), + header: (key) => xhr.getResponseHeader(key), body: xhr.responseText, }); }); diff --git a/src/index.js b/src/index.js index cb73d7c0..e4084c84 100644 --- a/src/index.js +++ b/src/index.js @@ -21,7 +21,7 @@ export function initialize(env, user, options = {}) { const validatedOptions = clientVars.options; const emitter = clientVars.emitter; - const goalsPromise = new Promise(resolve => { + const goalsPromise = new Promise((resolve) => { const onGoals = emitter.on(goalsEvent, () => { emitter.off(goalsEvent, onGoals); resolve();