Skip to content

Commit

Permalink
Inline 'testMinificationUsedDCE' and remove unit test for now
Browse files Browse the repository at this point in the history
What:
- Inlines the 'testMinificationUsedDCE' method into
  'packages/react/index.js'
- Removes unit test for 'testMinififcationUsedDCE'
- Puts dependencies back the way that they were; should remove extra
  dependencies that were added for the unit test.

Why:
- It would add complexity to the build process to add another file to
  the 'build/packages/react/cjs' folder, and that is the only way to
  pull this out and test it. So instead we are inlining this.
  • Loading branch information
flarnie committed Aug 16, 2017
1 parent ab6c1f0 commit 8a1c36b
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 238 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"babel-jest": "20.1.0-delta.1",
"babel-plugin-check-es2015-constants": "^6.5.0",
"babel-plugin-external-helpers": "^6.22.0",
"babel-plugin-minify-dead-code-elimination": "^0.1.7",
"babel-plugin-syntax-trailing-function-commas": "^6.5.0",
"babel-plugin-transform-async-to-generator": "^6.22.0",
"babel-plugin-transform-class-properties": "^6.11.5",
Expand All @@ -33,7 +32,6 @@
"babel-plugin-transform-es3-property-literals": "^6.5.0",
"babel-plugin-transform-object-rest-spread": "^6.6.5",
"babel-plugin-transform-react-jsx-source": "^6.8.0",
"babel-preset-minify": "0.0.0",
"babel-preset-react": "^6.5.0",
"babel-traverse": "^6.9.0",
"babylon": "6.15.0",
Expand Down Expand Up @@ -88,7 +86,7 @@
"through2": "^2.0.0",
"tmp": "~0.0.28",
"typescript": "~1.8.10",
"uglify-js": "2.8.29",
"uglify-js": "^2.8.29",
"yargs": "^6.3.0"
},
"devEngines": {
Expand Down
45 changes: 43 additions & 2 deletions packages/react/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,50 @@
'use strict';

function testMinificationUsedDCE() {
// use scoped variable for our initial test, in case
// 'top-level' mangling is not enabled.
const source = testMinificationUsedDCE.toString();
const longVariableName = source;
if (longVariableName && source.match(/longVariableName/g).length === 3) {
// We are not minified.
// This might be a Node environment where DCE is not expected anyway.
return;
}
if (process.env.NODE_ENV === 'development') {
// We expect this method only to be called in production.
throw new Error('This is unreachable');
}
try {
if (source.match(/toString/g).length !== 2) {
// We always look for two matches:
// The actual occurence and then the call to 'match'
//
// We know for a fact the above line exists so there should be 2
// matches.
// Therefore the browser gave us invalid source.
return;
}
if (source.match(/unreachable/g).length === 2) {
// We always look for two matches:
// The actual occurence and then the call to 'match'

// Dead code elimination would have stripped that branch
// because it is impossible to reach in production.
setTimeout(function() {
// Ensure it gets reported to production logging
throw new Error(
'React is running in production mode, but dead code ' +
'elimination has not been applied. Read how to correctly ' +
'configure React for production: ' +
'https://fburl.com/react-perf-use-the-production-build'
);
});
}
} catch (e) {}
}

if (process.env.NODE_ENV === 'production') {
// TODO: actually update the build process so this works.
(require('./cjs/testMinificationUsedDCE.js'))();
testMinificationUsedDCE();
module.exports = require('./cjs/react.production.min.js');
} else {
module.exports = require('./cjs/react.development.js');
Expand Down
37 changes: 7 additions & 30 deletions scripts/rollup/packaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ const reactNativeSrcDependencies = [
'src/renderers/native/ReactNativeTypes.js',
];

// these files need to be copied to the react build
const reactPackageDependencies = [
'src/shared/utils/testMinificationUsedDCE.js',
];

function getPackageName(name) {
if (name.indexOf('/') !== -1) {
return name.split('/')[0];
Expand Down Expand Up @@ -104,7 +99,7 @@ function copyBundleIntoNodePackage(packageName, filename, bundleType) {
from = resolve(`./build/dist/${filename}`);
to = `${packageDirectory}/umd/${filename}`;
}
const promises = [];

// for NODE bundles we have to move the files into a cjs directory
// within the package directory. we also need to set the from
// to be the root build from directory
Expand All @@ -115,31 +110,13 @@ function copyBundleIntoNodePackage(packageName, filename, bundleType) {
fs.mkdirSync(distDirectory);
}
to = `${packageDirectory}/cjs/${filename}`;
if (packageName === 'react') {
// we are building the React package
let promises = [];
// we also need to copy over some specific files from src
// defined in reactPackageDependencies
for (const srcDependency of reactPackageDependencies) {
// TODO: the srcDependency needs to be processed
// before this step.
var specificFrom = resolve(srcDependency);
var specificTo = resolve(`${distDirectory}/${basename(srcDependency)}`);
promises.push(
asyncCopyTo(specificFrom, specificTo)
);
}
}
}
promises.push(
asyncCopyTo(from, to).then(() => {
// delete the old file if this is a not a UMD bundle
if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
fs.unlinkSync(from);
}
})
);
return Promise.all(promises);
return asyncCopyTo(from, to).then(() => {
// delete the old file if this is a not a UMD bundle
if (bundleType !== UMD_DEV && bundleType !== UMD_PROD) {
fs.unlinkSync(from);
}
});
} else {
return Promise.resolve();
}
Expand Down
144 changes: 0 additions & 144 deletions src/shared/utils/__tests__/testMinificationUsedDCE-test.js

This file was deleted.

59 changes: 0 additions & 59 deletions src/shared/utils/testMinificationUsedDCE.js

This file was deleted.

0 comments on commit 8a1c36b

Please sign in to comment.