Skip to content

Commit

Permalink
Add fake chalk in browser builds in order to support IE10 (#4367)
Browse files Browse the repository at this point in the history
* Add a fake chalk in order to work in older browsers

Closes #4074

* Make fake chalk private

* fix import

* Normalize ansi-styles version

* Remove yarn.lock from npmignore

* Move fake chalk into expect package
  • Loading branch information
SimenB authored and cpojer committed Aug 27, 2017
1 parent e5fd773 commit 51e0a24
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"devDependencies": {
"ansi-regex": "^3.0.0",
"ansi-styles": "^3.0.0",
"ansi-styles": "^3.2.0",
"babel-core": "^6.23.1",
"babel-eslint": "^7.2.3",
"babel-plugin-external-helpers": "^6.22.0",
Expand Down
1 change: 1 addition & 0 deletions packages/expect/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"main": "build/index.js",
"browser": "build-es5/index.js",
"dependencies": {
"ansi-styles": "^3.2.0",
"jest-diff": "^20.0.3",
"jest-get-type": "^20.0.3",
"jest-matcher-utils": "^20.0.3",
Expand Down
20 changes: 20 additions & 0 deletions packages/expect/src/__tests__/fake_chalk.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Copyright (c) 2014-present, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
'use strict';

const fakeChalk = require.requireActual('../fake_chalk');

describe('Fake Chalk', () => {
it('returns input when invoked', () => {
expect(fakeChalk.red('yo')).toEqual('yo');
});

it('supports chaining', () => {
expect(fakeChalk.red.blue('yo')).toEqual('yo');
});
});
25 changes: 25 additions & 0 deletions packages/expect/src/fake_chalk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) 2014, Facebook, Inc. All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
* @flow
*/

import ansiStyles from 'ansi-styles';

const returnInput = str => str;

const allColorsAsFunc = Object.keys(ansiStyles)
.map(style => ({[style]: returnInput}))
.reduce((acc, cur) => Object.assign(acc, cur));

Object.keys(allColorsAsFunc)
.map(color => allColorsAsFunc[color])
.forEach(style => {
Object.assign(style, allColorsAsFunc);
Object.assign(returnInput, style);
});

module.exports = allColorsAsFunc;
2 changes: 1 addition & 1 deletion packages/pretty-format/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
"author": "James Kyle <me@thejameskyle.com>",
"dependencies": {
"ansi-regex": "^3.0.0",
"ansi-styles": "^3.0.0"
"ansi-styles": "^3.2.0"
}
}
8 changes: 8 additions & 0 deletions scripts/browserBuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
'use strict';

const path = require('path');
const rollup = require('rollup').rollup;
const rollupResolve = require('rollup-plugin-node-resolve');
const rollupCommonjs = require('rollup-plugin-commonjs');
Expand Down Expand Up @@ -48,6 +49,13 @@ function browserBuild(pkgName, entryPath, destination) {
entry: entryPath,
onwarn: () => {},
plugins: [
{
resolveId(id) {
return id === 'chalk'
? path.resolve(__dirname, '../packages/expect/build/fake_chalk.js')
: undefined;
},
},
rollupFlow(),
rollupJson(),
rollupCommonjs(),
Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ ansi-styles@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe"

ansi-styles@^3.0.0, ansi-styles@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.1.0.tgz#09c202d5c917ec23188caa5c9cb9179cd9547750"
ansi-styles@^3.1.0, ansi-styles@^3.2.0:
version "3.2.0"
resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88"
dependencies:
color-convert "^1.0.0"
color-convert "^1.9.0"

anymatch@^1.3.0:
version "1.3.0"
Expand Down Expand Up @@ -1556,7 +1556,7 @@ collapse-white-space@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/collapse-white-space/-/collapse-white-space-1.0.2.tgz#9c463fb9c6d190d2dcae21a356a01bcae9eeef6d"

color-convert@^1.0.0:
color-convert@^1.9.0:
version "1.9.0"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a"
dependencies:
Expand Down

0 comments on commit 51e0a24

Please sign in to comment.