Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): Upgrade to Babel 7 #1047

Merged
merged 1 commit into from
Jul 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 0 additions & 37 deletions .babelrc

This file was deleted.

52 changes: 52 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
module.exports = api => {
api.cache(() => process.env.NODE_ENV);

return {
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
'@babel/preset-react',
],
plugins: [
'@babel/plugin-proposal-class-properties',
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-object-assign',
],
env: {
production: {
plugins: [['react-remove-properties', { properties: ['data-testid'] }]],
},
test: {
plugins: [
[
'istanbul',
{
exclude: [
'**/*-test.js',
'build/**',
'src/lib/polyfill.js',
'src/lib/browser.js',
'src/lib/viewers/box3d/model3d/Model3DAnimationClipsPullup.js',
'src/lib/viewers/box3d/model3d/model3DSettingsPullup.js',
'src/lib/viewers/box3d/model3d/Model3DVrControls.js',
'src/lib/viewers/box3d/**/SceneEntities.js',
'src/lib/viewers/box3d/**Constants.js',
],
},
],
[
'babel-plugin-transform-require-ignore',
{
extensions: ['.scss'],
},
],
'@babel/plugin-transform-modules-commonjs',
],
},
},
};
};
7 changes: 0 additions & 7 deletions browserslist

This file was deleted.

10 changes: 5 additions & 5 deletions build/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { NODE_ENV } = process.env;
const isRelease = NODE_ENV === 'production';
const isDev = NODE_ENV === 'dev';
const isProd = NODE_ENV === 'production';

const fs = require('fs');
const path = require('path');
Expand All @@ -10,7 +10,7 @@ const UglifyJsPlugin = require('uglifyjs-webpack-plugin');

const commonConfig = require('./webpack.common.config');
const RsyncPlugin = require('./RsyncPlugin');
const version = isRelease ? require('../package.json').version : 'dev';
const version = isProd ? require('../package.json').version : 'dev';

let rsyncLocation = '';
if (fs.existsSync('build/rsync.json')) {
Expand All @@ -23,7 +23,7 @@ if (fs.existsSync('build/rsync.json')) {
const lib = path.resolve('src/lib');
const thirdParty = path.resolve('src/third-party');
const staticFolder = path.resolve('dist');
const languages = isRelease ? locales : ['en-US']; // Only 1 language needed for dev
const languages = isProd ? locales : ['en-US']; // Only 1 language needed for dev

/* eslint-disable key-spacing, require-jsdoc */
function updateConfig(conf, language, index) {
Expand All @@ -33,7 +33,7 @@ function updateConfig(conf, language, index) {
preview: [`${lib}/Preview.js`],
csv: [`${lib}/viewers/text/BoxCSV.js`],
},
mode: isRelease ? 'production' : 'development',
mode: isProd ? 'production' : 'development',
optimization: {
minimizer: [
new UglifyJsPlugin({
Expand Down Expand Up @@ -78,7 +78,7 @@ function updateConfig(conf, language, index) {
}
}

if (isRelease) {
if (isProd) {
// Optimize CSS - minimize, remove comments and duplicate rules
config.plugins.push(
new OptimizeCssAssetsPlugin({
Expand Down
35 changes: 20 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,23 @@
"url": "[email protected]:box/box-content-preview.git"
},
"devDependencies": {
"@babel/core": "^7.5.5",
"@babel/plugin-proposal-class-properties": "^7.5.5",
"@babel/plugin-transform-object-assign": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@babel/preset-react": "^7.0.0",
"@box/frontend": "^1.4.0",
"@box/languages": "^1.0.0",
"@commitlint/cli": "^7.2.1",
"@commitlint/config-conventional": "7.1.2",
"@commitlint/travis-cli": "^8.1.0",
"autoprefixer": "^9.6.1",
"axios": "^0.19.0",
"babel-core": "^6.26.0",
"babel-eslint": "^8.0.3",
"babel-loader": "^7.1.2",
"babel-plugin-istanbul": "^4.1.4",
"babel-plugin-react-remove-properties": "^0.2.5",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-plugin-transform-class-properties": "^6.23.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"babel-plugin-istanbul": "^5.2.0",
"babel-plugin-react-remove-properties": "^0.3.0",
"babel-plugin-transform-require-ignore": "^0.1.1",
"babel-preset-es2015": "^6.24.0",
"babel-preset-es2016": "^6.24.1",
"babel-preset-react": "^6.23.0",
"box-annotations": "^2.3.0",
"box-react-ui": "^22.7.0",
"chai": "^4.2.0",
Expand Down Expand Up @@ -59,7 +56,7 @@
"husky": "^1.3.1",
"i18n-webpack-plugin": "^1.0.0",
"jsuri": "^1.3.1",
"karma": "^3.1.4",
"karma": "^4.2.0",
"karma-chai": "^0.1.0",
"karma-chai-dom": "^1.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand All @@ -77,7 +74,7 @@
"lint-staged": "^8.0.4",
"lodash": "^4.17.11",
"mini-css-extract-plugin": "^0.8.0",
"mocha": "^4.0.1",
"mocha": "^6.2.0",
"mock-local-storage": "^1.0.2",
"mojito-rb-gen": "^0.0.1",
"node-noop": "^1.0.0",
Expand All @@ -94,7 +91,7 @@
"react-dom": "^16.7.0",
"react-virtualized": "^9.13.0",
"sass-loader": "^7.1.0",
"sinon": "^7.2.3",
"sinon": "^7.3.2",
"sinon-chai": "3.3.0",
"string-replace-loader": "^2.2.0",
"style-loader": "^0.23.1",
Expand Down Expand Up @@ -140,6 +137,14 @@
"upgrade:annotations": "./build/upgrade_annotations.sh",
"upgrade:pdfjs": "./build/upgrade_pdfjs.sh && ./build/minify_pdfjs.sh"
},
"browserslist": [
"last 2 Chrome versions",
"last 2 Firefox versions",
"last 2 Safari versions",
"last 2 Edge versions",
"last 2 iOS versions",
"IE 11"
],
"lint-staged": {
"linters": {
"*.js": ["eslint --fix", "git add"],
Expand Down
9 changes: 5 additions & 4 deletions src/lib/PreviewError.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ class PreviewError extends Error {
* @param {string} code - Error code
* @param {string} [displayMessage] - Translated error message that can be displayed to a user
* @param {Object} [details] - Optional error options
* @param {...Object} [params] - Additional params, this may contain the original error message
* @param {string} [message] - Original error message
* @param {...Object} [params] - Additional params
* @return {PreviewError} PreviewError instance
*/
constructor(code, displayMessage = '', details = {}, ...params) {
constructor(code, displayMessage = '', details = {}, message, ...params) {
jstoffan marked this conversation as resolved.
Show resolved Hide resolved
// Pass remaining arguments to parent constructor
super(...params);
super(message, ...params);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the parent constructor wants [message, fileName, lineNumber], you can probably get rid of ...params since latter two are optional and not passed in for PreviewErrors usage.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I didn't see them passed in anywhere, but I wanted to stay as close to the original implementation as possible.

Copy link
Contributor

@priyajeet priyajeet Jul 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also PreviewError's 2nd arg is the message, aka displayMessage, so shouldn't it be super(displayMessage)? And if so, maybe you wont need line 45

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. If both are passed in, this.message should still be the original message, not the display message.


// Workaround to make `instanceof PreviewError` work in ES5
this.constructor = PreviewError;
Expand All @@ -41,7 +42,7 @@ class PreviewError extends Error {
this.displayMessage = displayMessage || __('error_generic');

// Default base error message to display message if not set - some code may depend on Error.message
this.message = this.message || this.displayMessage;
this.message = message || this.displayMessage;
}
}

Expand Down
5 changes: 0 additions & 5 deletions src/lib/__tests__/Preview-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,11 +1209,6 @@ describe('lib/Preview', () => {
};
});

it('should use the saved preview options', () => {
preview.parseOptions(preview.previewOptions);
expect(stubs.assign).to.be.calledWith(preview.previewOptions);
});

it('should set the container', () => {
preview.parseOptions(preview.previewOptions);
expect(preview.options.container).to.equal(containerEl);
Expand Down
8 changes: 6 additions & 2 deletions src/lib/viewers/doc/__tests__/PresentationPreloader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ describe('lib/viewers/doc/PresentationPreloader', () => {
preloader = new PresentationPreloader({
hideLoadingIndicator: () => {},
});
stubs = {};
preloader.previewUI = {
hideLoadingIndicator: sandbox.stub(),
};
stubs = {
hideLoadingIndicator: preloader.previewUI.hideLoadingIndicator,
};
});

afterEach(() => {
Expand All @@ -30,7 +35,6 @@ describe('lib/viewers/doc/PresentationPreloader', () => {
stubs.checkDocumentLoaded = sandbox.stub(preloader, 'checkDocumentLoaded');
stubs.emit = sandbox.stub(preloader, 'emit');
stubs.setDimensions = sandbox.stub(util, 'setDimensions');
stubs.hideLoadingIndicator = sandbox.stub(preloader.previewUI, 'hideLoadingIndicator');
preloader.imageEl = {};
preloader.preloadEl = document.createElement('div');
});
Expand Down
Loading