From 702134b3b1d0d117dc1cfd37ab5b06d92828e736 Mon Sep 17 00:00:00 2001 From: Danny Coates Date: Thu, 10 Aug 2017 10:02:13 -0700 Subject: [PATCH] use import/export in the frontend code --- frontend/src/.eslintrc.yml | 8 +++++++- frontend/src/common.js | 8 +++----- frontend/src/download.js | 18 +++++++++--------- frontend/src/fileReceiver.js | 8 +++----- frontend/src/fileSender.js | 8 +++----- frontend/src/links.js | 4 +--- frontend/src/metrics.js | 6 +++--- frontend/src/progress.js | 11 ++++------- frontend/src/storage.js | 6 ++---- frontend/src/upload.js | 18 +++++++++--------- frontend/src/utils.js | 2 +- package-lock.json | 6 ------ package.json | 1 - server/server.js | 8 +++++--- webpack.config.js | 3 +-- 15 files changed, 51 insertions(+), 64 deletions(-) diff --git a/frontend/src/.eslintrc.yml b/frontend/src/.eslintrc.yml index 2eb01e5b..d6d7fd0c 100644 --- a/frontend/src/.eslintrc.yml +++ b/frontend/src/.eslintrc.yml @@ -1,3 +1,9 @@ env: browser: true - jquery: true + node: false + +parserOptions: + sourceType: module + +rules: + node/no-unsupported-features: off diff --git a/frontend/src/common.js b/frontend/src/common.js index 361a81d9..ddbbd7ca 100644 --- a/frontend/src/common.js +++ b/frontend/src/common.js @@ -1,5 +1,5 @@ -const Raven = require('raven-js'); -const { unsupported } = require('./metrics'); +import Raven from 'raven-js'; +import { unsupported } from './metrics'; if (navigator.doNotTrack !== '1' && window.RAVEN_CONFIG) { Raven.config(window.SENTRY_ID, window.RAVEN_CONFIG).install(); @@ -17,6 +17,4 @@ if ( }); } -module.exports = { - Raven -}; +export { Raven }; diff --git a/frontend/src/download.js b/frontend/src/download.js index 97cca47f..61399d31 100644 --- a/frontend/src/download.js +++ b/frontend/src/download.js @@ -1,13 +1,13 @@ -const { Raven } = require('./common'); -const FileReceiver = require('./fileReceiver'); -const { bytes, notify, gcmCompliant } = require('./utils'); -const Storage = require('./storage'); -const storage = new Storage(); -const links = require('./links'); -const metrics = require('./metrics'); -const progress = require('./progress'); -const $ = require('jquery'); +import { Raven } from './common'; +import FileReceiver from './fileReceiver'; +import { bytes, notify, gcmCompliant } from './utils'; +import Storage from './storage'; +import * as links from './links'; +import * as metrics from './metrics'; +import * as progress from './progress'; +import $ from 'jquery'; +const storage = new Storage(localStorage); function onUnload(size) { metrics.cancelledDownload({ size }); } diff --git a/frontend/src/fileReceiver.js b/frontend/src/fileReceiver.js index c93d7eba..53506a7d 100644 --- a/frontend/src/fileReceiver.js +++ b/frontend/src/fileReceiver.js @@ -1,7 +1,7 @@ -const EventEmitter = require('events'); -const { hexToArray } = require('./utils'); +import EventEmitter from 'events'; +import { hexToArray } from './utils'; -class FileReceiver extends EventEmitter { +export default class FileReceiver extends EventEmitter { constructor() { super(); } @@ -86,5 +86,3 @@ class FileReceiver extends EventEmitter { }); } } - -module.exports = FileReceiver; diff --git a/frontend/src/fileSender.js b/frontend/src/fileSender.js index ffe0ad19..dad2365a 100644 --- a/frontend/src/fileSender.js +++ b/frontend/src/fileSender.js @@ -1,7 +1,7 @@ -const EventEmitter = require('events'); -const { arrayToHex } = require('./utils'); +import EventEmitter from 'events'; +import { arrayToHex } from './utils'; -class FileSender extends EventEmitter { +export default class FileSender extends EventEmitter { constructor(file) { super(); this.file = file; @@ -116,5 +116,3 @@ class FileSender extends EventEmitter { }); } } - -module.exports = FileSender; diff --git a/frontend/src/links.js b/frontend/src/links.js index 2752912a..d27da908 100644 --- a/frontend/src/links.js +++ b/frontend/src/links.js @@ -18,6 +18,4 @@ function setOpenInNewTab(bool) { } } -module.exports = { - setOpenInNewTab -}; +export { setOpenInNewTab }; diff --git a/frontend/src/metrics.js b/frontend/src/metrics.js index d5ea40fb..9a0167d7 100644 --- a/frontend/src/metrics.js +++ b/frontend/src/metrics.js @@ -1,5 +1,5 @@ -const testPilotGA = require('testpilot-ga/src/TestPilotGA'); -const Storage = require('./storage'); +import testPilotGA from 'testpilot-ga/src/TestPilotGA'; +import Storage from './storage'; const storage = new Storage(); let hasLocalStorage = false; @@ -234,7 +234,7 @@ function addRestartHandlers() { }); } -module.exports = { +export { copiedLink, startedUpload, cancelledUpload, diff --git a/frontend/src/progress.js b/frontend/src/progress.js index 924102b4..70d9bc02 100644 --- a/frontend/src/progress.js +++ b/frontend/src/progress.js @@ -1,6 +1,6 @@ -const { bytes, percent } = require('./utils'); -const $ = require('jquery'); -require('jquery-circle-progress'); +import { bytes, percent } from './utils'; +import $ from 'jquery'; +import 'jquery-circle-progress'; let $progress = null; let $percent = null; @@ -50,7 +50,4 @@ function setText(str) { $text.text(str); } -module.exports = { - setProgress, - setText -}; +export { setProgress, setText }; diff --git a/frontend/src/storage.js b/frontend/src/storage.js index 2721390f..c8580a03 100644 --- a/frontend/src/storage.js +++ b/frontend/src/storage.js @@ -1,4 +1,4 @@ -const { isFile } = require('./utils'); +import { isFile } from './utils'; class Mem { constructor() { @@ -26,7 +26,7 @@ class Mem { } } -class Storage { +export default class Storage { constructor() { try { this.engine = localStorage || new Mem(); @@ -97,5 +97,3 @@ class Storage { this.engine.setItem(id, JSON.stringify(file)); } } - -module.exports = Storage; diff --git a/frontend/src/upload.js b/frontend/src/upload.js index 24e2308b..072f5f07 100644 --- a/frontend/src/upload.js +++ b/frontend/src/upload.js @@ -1,19 +1,19 @@ /* global MAXFILESIZE EXPIRE_SECONDS */ -const { Raven } = require('./common'); -const FileSender = require('./fileSender'); -const { +import { Raven } from './common'; +import FileSender from './fileSender'; +import { bytes, copyToClipboard, notify, gcmCompliant, ONE_DAY_IN_MS -} = require('./utils'); -const Storage = require('./storage'); -const storage = new Storage(); -const metrics = require('./metrics'); -const progress = require('./progress'); +} from './utils'; +import Storage from './storage'; +import * as metrics from './metrics'; +import * as progress from './progress'; +import $ from 'jquery'; -const $ = require('jquery'); +const storage = new Storage(localStorage); const allowedCopy = () => { const support = !!document.queryCommandSupported; diff --git a/frontend/src/utils.js b/frontend/src/utils.js index 92c59cb3..41da2ff0 100644 --- a/frontend/src/utils.js +++ b/frontend/src/utils.js @@ -131,7 +131,7 @@ function percent(ratio) { const ONE_DAY_IN_MS = 86400000; -module.exports = { +export { bytes, percent, copyToClipboard, diff --git a/package-lock.json b/package-lock.json index e9730980..e77d704b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -551,12 +551,6 @@ "babel-runtime": "6.25.0" } }, - "babel-plugin-add-module-exports": { - "version": "0.2.1", - "resolved": "https://registry.npmjs.org/babel-plugin-add-module-exports/-/babel-plugin-add-module-exports-0.2.1.tgz", - "integrity": "sha1-mumh9KjcZ/DN7E9K7aHkOl/2XiU=", - "dev": true - }, "babel-plugin-check-es2015-constants": { "version": "6.22.0", "resolved": "https://registry.npmjs.org/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz", diff --git a/package.json b/package.json index e0e8789c..439e2abb 100644 --- a/package.json +++ b/package.json @@ -20,7 +20,6 @@ "autoprefixer": "^7.1.2", "babel-core": "^6.25.0", "babel-loader": "^7.1.1", - "babel-plugin-add-module-exports": "^0.2.1", "babel-polyfill": "^6.23.0", "babel-preset-es2015": "^6.24.1", "babel-preset-stage-2": "^6.24.1", diff --git a/server/server.js b/server/server.js index 5d2ceb1a..3164ff3d 100644 --- a/server/server.js +++ b/server/server.js @@ -44,9 +44,11 @@ if (conf.env === 'development') { const config = require('../webpack.config.js'); config.devtool = 'inline-source-map'; const compiler = webpack(config); - app.use(webpackDevMiddleware(compiler, { - publicPath: config.output.publicPath - })); + app.use( + webpackDevMiddleware(compiler, { + publicPath: config.output.publicPath + }) + ); } app.engine( diff --git a/webpack.config.js b/webpack.config.js index 8641852e..cd576cec 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -21,8 +21,7 @@ module.exports = { ], query: { babelrc: false, - presets: ['es2015', 'stage-2'], - plugins: ['add-module-exports'] + presets: [['es2015', { modules: false }], 'stage-2'] } } ]