diff --git a/package.json b/package.json index c760695fe56d..009d5b6c4f27 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/packages/expect/package.json b/packages/expect/package.json index d8313f080d41..f964d7cc7102 100644 --- a/packages/expect/package.json +++ b/packages/expect/package.json @@ -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", diff --git a/packages/expect/src/__tests__/fake_chalk.test.js b/packages/expect/src/__tests__/fake_chalk.test.js new file mode 100644 index 000000000000..9678253e7c97 --- /dev/null +++ b/packages/expect/src/__tests__/fake_chalk.test.js @@ -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'); + }); +}); diff --git a/packages/expect/src/fake_chalk.js b/packages/expect/src/fake_chalk.js new file mode 100644 index 000000000000..6afb3b686a63 --- /dev/null +++ b/packages/expect/src/fake_chalk.js @@ -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; diff --git a/packages/pretty-format/package.json b/packages/pretty-format/package.json index c94e1de2dc22..ad4bd7c2e4aa 100644 --- a/packages/pretty-format/package.json +++ b/packages/pretty-format/package.json @@ -12,6 +12,6 @@ "author": "James Kyle ", "dependencies": { "ansi-regex": "^3.0.0", - "ansi-styles": "^3.0.0" + "ansi-styles": "^3.2.0" } } diff --git a/scripts/browserBuild.js b/scripts/browserBuild.js index 48e2451f8663..dbad6e4a1da1 100644 --- a/scripts/browserBuild.js +++ b/scripts/browserBuild.js @@ -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'); @@ -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(), diff --git a/yarn.lock b/yarn.lock index d433d6f82eb6..cd0c089c37b4 100644 --- a/yarn.lock +++ b/yarn.lock @@ -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" @@ -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: