Skip to content

Commit

Permalink
feat: Add ‘displayNamesProd’ option to add React display names (seek-…
Browse files Browse the repository at this point in the history
  • Loading branch information
markdalgleish authored Mar 18, 2019
1 parent 2d10ec1 commit 5b3c89e
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 45 deletions.
6 changes: 5 additions & 1 deletion config/babel/babelConfig.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { supportedBrowsers } = require('../../context');
const { supportedBrowsers, displayNamesProd } = require('../../context');
const { cwd } = require('../../lib/cwd');

const browserEnvOptions = {
Expand Down Expand Up @@ -43,6 +43,10 @@ module.exports = ({ target, lang = 'js' }) => {
require.resolve('babel-plugin-transform-react-remove-prop-types'),
require.resolve('@babel/plugin-transform-react-constant-elements'),
);

if (displayNamesProd) {
plugins.push(require.resolve('babel-plugin-add-react-displayname'));
}
}

const languagePreset =
Expand Down
3 changes: 3 additions & 0 deletions context/configSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,7 @@ module.exports = validator.compile({
sourceMapsProd: {
type: 'boolean',
},
displayNamesProd: {
type: 'boolean',
},
});
1 change: 1 addition & 0 deletions context/defaultSkuConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ module.exports = {
polyfills: [],
libraryName: null,
sourceMapsProd: false,
displayNamesProd: false,
dangerouslySetWebpackConfig: defaultDecorator,
dangerouslySetJestConfig: defaultDecorator,
dangerouslySetESLintConfig: defaultDecorator,
Expand Down
1 change: 1 addition & 0 deletions context/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,5 @@ module.exports = {
isBuildScript,
supportedBrowsers: skuConfig.supportedBrowsers,
sourceMapsProd: Boolean(skuConfig.sourceMapsProd),
displayNamesProd: Boolean(skuConfig.displayNamesProd),
};
16 changes: 16 additions & 0 deletions docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ const config = {
};
```

## displayNamesProd

type `boolean`

Default: `false`

Adds static `displayName` properties to React components in production. This setting is designed for usage on sites that generate React code snippets, e.g. [Braid](https://seek-oss.github.io/braid-design-system/).

Example:

```js
const config = {
displayNamesProd: true,
};
```

## environments

**Only for static apps**
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"autoprefixer": "^9.4.5",
"babel-jest": "^24.0.0",
"babel-loader": "^8.0.4",
"babel-plugin-add-react-displayname": "^0.0.5",
"babel-plugin-flow-react-proptypes": "^25.0.0",
"babel-plugin-macros": "^2.4.2",
"babel-plugin-module-resolver": "^3.1.1",
Expand Down
52 changes: 8 additions & 44 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2645,6 +2645,11 @@ babel-loader@^8.0.4:
mkdirp "^0.5.1"
util.promisify "^1.0.0"

babel-plugin-add-react-displayname@^0.0.5:
version "0.0.5"
resolved "https://registry.yarnpkg.com/babel-plugin-add-react-displayname/-/babel-plugin-add-react-displayname-0.0.5.tgz#339d4cddb7b65fd62d1df9db9fe04de134122bd5"
integrity sha1-M51M3be2X9YtHfnbn+BN4TQSK9U=

babel-plugin-dynamic-import-node@2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/babel-plugin-dynamic-import-node/-/babel-plugin-dynamic-import-node-2.2.0.tgz#c0adfb07d95f4a4495e9aaac6ec386c4d7c2524e"
Expand Down Expand Up @@ -4640,7 +4645,7 @@ debug@^4.0.0, debug@^4.0.1, debug@^4.1.0, debug@^4.1.1:
dependencies:
ms "^2.1.1"

debuglog@*, debuglog@^1.0.1:
debuglog@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/debuglog/-/debuglog-1.0.1.tgz#aa24ffb9ac3df9a2351837cfb2d279360cd78492"
integrity sha1-qiT/uaw9+aI1GDfPstJ5NgzXhJI=
Expand Down Expand Up @@ -7220,7 +7225,7 @@ import-local@^2.0.0:
pkg-dir "^3.0.0"
resolve-cwd "^2.0.0"

imurmurhash@*, imurmurhash@^0.1.4:
imurmurhash@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea"
integrity sha1-khi5srkoojixPcT7a21XbyMUU+o=
Expand Down Expand Up @@ -8861,11 +8866,6 @@ lockfile@^1.0.4:
dependencies:
signal-exit "^3.0.2"

lodash._baseindexof@*:
version "3.1.0"
resolved "https://registry.yarnpkg.com/lodash._baseindexof/-/lodash._baseindexof-3.1.0.tgz#fe52b53a1c6761e42618d654e4a25789ed61822c"
integrity sha1-/lK1OhxnYeQmGNZU5KJXie1hgiw=

lodash._baseuniq@~4.6.0:
version "4.6.0"
resolved "https://registry.yarnpkg.com/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz#0ebb44e456814af7905c6212fa2c9b2d51b841e8"
Expand All @@ -8874,33 +8874,11 @@ lodash._baseuniq@~4.6.0:
lodash._createset "~4.0.0"
lodash._root "~3.0.0"

lodash._bindcallback@*:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._bindcallback/-/lodash._bindcallback-3.0.1.tgz#e531c27644cf8b57a99e17ed95b35c748789392e"
integrity sha1-5THCdkTPi1epnhftlbNcdIeJOS4=

lodash._cacheindexof@*:
version "3.0.2"
resolved "https://registry.yarnpkg.com/lodash._cacheindexof/-/lodash._cacheindexof-3.0.2.tgz#3dc69ac82498d2ee5e3ce56091bafd2adc7bde92"
integrity sha1-PcaayCSY0u5ePOVgkbr9Ktx73pI=

lodash._createcache@*:
version "3.1.2"
resolved "https://registry.yarnpkg.com/lodash._createcache/-/lodash._createcache-3.1.2.tgz#56d6a064017625e79ebca6b8018e17440bdcf093"
integrity sha1-VtagZAF2JeeevKa4AY4XRAvc8JM=
dependencies:
lodash._getnative "^3.0.0"

lodash._createset@~4.0.0:
version "4.0.3"
resolved "https://registry.yarnpkg.com/lodash._createset/-/lodash._createset-4.0.3.tgz#0f4659fbb09d75194fa9e2b88a6644d363c9fe26"
integrity sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=

lodash._getnative@*, lodash._getnative@^3.0.0:
version "3.9.1"
resolved "https://registry.yarnpkg.com/lodash._getnative/-/lodash._getnative-3.9.1.tgz#570bc7dede46d61cdcde687d65d3eecbaa3aaff5"
integrity sha1-VwvH3t5G1hzc3mh9ZdPuy6o6r/U=

lodash._reinterpolate@~3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/lodash._reinterpolate/-/lodash._reinterpolate-3.0.0.tgz#0ccf2d89166af03b3663c796538b75ac6e114d9d"
Expand Down Expand Up @@ -8956,11 +8934,6 @@ lodash.memoize@^4.1.2:
resolved "https://registry.yarnpkg.com/lodash.memoize/-/lodash.memoize-4.1.2.tgz#bcc6c49a42a2840ed997f323eada5ecd182e0bfe"
integrity sha1-vMbEmkKihA7Zl/Mj6tpezRguC/4=

lodash.restparam@*:
version "3.6.1"
resolved "https://registry.yarnpkg.com/lodash.restparam/-/lodash.restparam-3.6.1.tgz#936a4e309ef330a7645ed4145986c85ae5b20805"
integrity sha1-k2pOMJ7zMKdkXtQUWYbIWuWyCAU=

lodash.set@^4.3.2:
version "4.3.2"
resolved "https://registry.yarnpkg.com/lodash.set/-/lodash.set-4.3.2.tgz#d8757b1da807dde24816b0d6a84bea1a76230b23"
Expand Down Expand Up @@ -10096,7 +10069,6 @@ npm@6.5.0:
cmd-shim "~2.0.2"
columnify "~1.5.4"
config-chain "^1.1.12"
debuglog "*"
detect-indent "~5.0.0"
detect-newline "^2.1.0"
dezalgo "~1.0.3"
Expand All @@ -10111,7 +10083,6 @@ npm@6.5.0:
has-unicode "~2.0.1"
hosted-git-info "^2.7.1"
iferr "^1.0.2"
imurmurhash "*"
inflight "~1.0.6"
inherits "~2.0.3"
ini "^1.3.5"
Expand All @@ -10124,14 +10095,8 @@ npm@6.5.0:
libnpx "^10.2.0"
lock-verify "^2.0.2"
lockfile "^1.0.4"
lodash._baseindexof "*"
lodash._baseuniq "~4.6.0"
lodash._bindcallback "*"
lodash._cacheindexof "*"
lodash._createcache "*"
lodash._getnative "*"
lodash.clonedeep "~4.5.0"
lodash.restparam "*"
lodash.union "~4.6.0"
lodash.uniq "~4.5.0"
lodash.without "~4.4.0"
Expand Down Expand Up @@ -10170,7 +10135,6 @@ npm@6.5.0:
read-package-json "^2.0.13"
read-package-tree "^5.2.1"
readable-stream "^2.3.6"
readdir-scoped-modules "*"
request "^2.88.0"
retry "^0.12.0"
rimraf "~2.6.2"
Expand Down Expand Up @@ -12106,7 +12070,7 @@ readable-stream@~1.1.10:
isarray "0.0.1"
string_decoder "~0.10.x"

readdir-scoped-modules@*, readdir-scoped-modules@^1.0.0:
readdir-scoped-modules@^1.0.0:
version "1.0.2"
resolved "https://registry.yarnpkg.com/readdir-scoped-modules/-/readdir-scoped-modules-1.0.2.tgz#9fafa37d286be5d92cbaebdee030dc9b5f406747"
integrity sha1-n6+jfShr5dksuuve4DDcm19AZ0c=
Expand Down

0 comments on commit 5b3c89e

Please sign in to comment.