From 2b3ba7f2312a90b4ced1e8954715aac046931d71 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Mon, 14 May 2018 03:06:11 +0300 Subject: [PATCH] Remove "browser" version Ref #18 Since the problem with uglify is fixed there is not reason to keep browser version which do not add any benefits. Actually it blocks us from distributing `esm` version which is widely used these days and supported by the most popular bundlers like webpack, rollup and parcel. Here's a few links https://github.com/facebook/fbjs/pull/86#issuecomment-285204734 Both uglify and babel minify support evaulation and eliminating ```js (function () { function warning() {} var __DEV__ = 'production' !== 'production' if (__DEV__) { warning = function (msg) { console.log(msg) } } warning() } ()); ``` https://skalman.github.io/UglifyJS-online/ https://babeljs.io/repl#?babili=true&browsers=&build=&builtIns=false&code_lz=BQMwrgdgxgLglgewgAmASmQbwFDOeaeJZAdwEMAnCOCAc3SwF9tdkA3S5AfS4BEBRAGo9kAXmQByAA4UEAEzCxEECcgCEo8dNkKlSCSzxwQqHgOFcMOPHnJUatMfkh6UwALYBnWldY3kUEieCAA2AKYAdCEI9F4-fsjMeMysdtR06NiMqGhoANxAA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&lineWrap=false&presets=babili%2Cenv&prettier=false&targets=&version=6.26.0&envVersion=1.6.2 --- browser.js | 62 ---------------------------------------------------- package.json | 5 ++--- test/test.js | 6 +++-- 3 files changed, 6 insertions(+), 67 deletions(-) delete mode 100644 browser.js diff --git a/browser.js b/browser.js deleted file mode 100644 index c00bbf4..0000000 --- a/browser.js +++ /dev/null @@ -1,62 +0,0 @@ -/** - * Copyright (c) 2014-present, Facebook, Inc. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - * - * @providesModule warning - */ - -'use strict'; - -/** - * Similar to invariant but only logs a warning if the condition is not met. - * This can be used to log issues in development environments in critical - * paths. Removing the logging code for production environments will keep the - * same logic and follow the same code paths. - */ - -var warning = function() {}; - -if (process.env.NODE_ENV !== 'production') { - function printWarning(format, args) { - var len = arguments.length; - args = new Array(len > 2 ? len - 2 : 0); - for (var key = 2; key < len; key++) { - args[key - 2] = arguments[key]; - } - var argIndex = 0; - var message = 'Warning: ' + - format.replace(/%s/g, function() { - return args[argIndex++]; - }); - if (typeof console !== 'undefined') { - console.error(message); - } - try { - // --- Welcome to debugging React --- - // This error was thrown as a convenience so that you can use this stack - // to find the callsite that caused this warning to fire. - throw new Error(message); - } catch (x) {} - } - - warning = function(condition, format, args) { - var len = arguments.length; - args = new Array(len > 2 ? len - 2 : 0); - for (var key = 2; key < len; key++) { - args[key - 2] = arguments[key]; - } - if (format === undefined) { - throw new Error( - '`warning(condition, format, ...args)` requires a warning ' + - 'message argument' - ); - } - if (!condition) { - printWarning.apply(null, [format].concat(args)); - } - }; -} - -module.exports = warning; diff --git a/package.json b/package.json index 7b46f60..030aa3b 100644 --- a/package.json +++ b/package.json @@ -3,14 +3,12 @@ "version": "3.0.0", "description": "A mirror of Facebook's Warning", "main": "warning.js", - "browser": "browser.js", "browserify": { "transform": [ "loose-envify" ] }, "files": [ - "browser.js", "warning.js" ], "scripts": { @@ -21,7 +19,8 @@ }, "devDependencies": { "browserify": "^11.0.1", - "tap": "^1.4.0" + "tap": "^1.4.0", + "uglify-js": "^3.3.25" }, "repository": { "type": "git", diff --git a/test/test.js b/test/test.js index 5c72ca2..6868ff6 100644 --- a/test/test.js +++ b/test/test.js @@ -3,6 +3,7 @@ var browserify = require('browserify'); var test = require('tap').test; var vm = require('vm'); +var minify = require('uglify-js').minify; var file = __dirname + '/package/' + process.env.NODE_ENV + '.js'; @@ -19,8 +20,9 @@ test('browserify', function(t) { }); b.bundle(function(err, src) { t.notOk(err); - t.notMatch(String(src), /\bprocess\.env\.NODE_ENV\b/); - t.notMatch(String(src), /__DEV__/); + var minified = minify(src).code + t.notMatch(String(minified), /\bprocess\.env\.NODE_ENV\b/); + t.notMatch(String(minified), /__DEV__/); var c = {console: {}}; vm.runInNewContext(src, c); c.package(t);