Skip to content

Commit

Permalink
Remove Atlaskit specific process.env switches (#195) (#196)
Browse files Browse the repository at this point in the history
* Remove Atlaskit specific process.env switches (#195)

* Add changeset
  • Loading branch information
marionebl authored Jun 9, 2021
1 parent dc5a362 commit 1ec5f76
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 39 deletions.
55 changes: 55 additions & 0 deletions .changeset/seven-rats-taste.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
"extract-react-types-loader": major
---

Remove Atlaskit specific process.env switches (#195)

BREAKING CHANGE
This removes the previously available process.env switches to conditionally disable the loader.
To restore the previous behaviour you'll have to use the `resolveLoader` webpack config, e.g.

```js
// webpack.config.js
const enabled = ['production', 'staging'].includes(process.env.WEBSITE_ENV) || process.env.FORCE_EXTRACT_REACT_TYPES;

module.exports = {
/* ... */
resolveLoader: {
alias: {
'extract-react-types-loader': enabled ? undefined : require.resolve('./noop-extract-react-types-loader')
}
}
};
```

```js
// noop-extract-react-types-loader.js
module.exports = function noopExtractReactPropTypesLoader() {
return `module.exports = {
component: {
kind: 'object',
members: [
{
kind: 'property',
key: { kind: 'id', name: 'Warning' },
value: { kind: 'any' },
optional: false,
leadingComments: [
{
type: 'commentBlock',
value: `extract-react-types is not being run in dev mode for speed reasons. If you need to
see prop types add the environment variable \`FORCE_EXTRACT_REACT_TYPES\`
raw: '**'
}
],
default: {
kind: 'string',
value: 'Prop types are not shown in dev mode'
}
}
],
referenceIdName: 'NoopPropTpes'
}
};`
}
```
40 changes: 1 addition & 39 deletions packages/extract-react-types-loader/index.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,8 @@
// @flow

const path = require('path');
const { extractReactTypes } = require('extract-react-types');

const devProps = {
component: {
kind: 'object',
members: [
{
kind: 'property',
key: { kind: 'id', name: 'Warning' },
value: { kind: 'any' },
optional: false,
leadingComments: [
{
type: 'commentBlock',
value: `extract-react-types is not being run in dev mode for speed reasons. If you need to
see prop types add the environment variable \`FORCE_EXTRACT_REACT_TYPES\`
eg:
- \`FORCE_EXTRACT_REACT_TYPES=true yarn start <packageName>\`
- \`FORCE_EXTRACT_REACT_TYPES=true yarn start:<team>\``,
raw: '**'
}
],
default: {
kind: 'string',
value: 'Prop types are not shown in dev mode'
}
}
],
referenceIdName: 'AvatarPropTypes'
}
};

module.exports = function extractReactTypesLoader(content /* : string */) {
if (
!['staging', 'production'].includes(process.env.WEBSITE_ENV) &&
!process.env.FORCE_EXTRACT_REACT_TYPES
) {
return `module.exports = ${JSON.stringify(devProps)}`;
}

const filename = this.resource;
const ext = path.extname(filename);
const typeSystem = ext === '.ts' || ext === '.tsx' ? 'typescript' : 'flow';
Expand All @@ -57,7 +19,7 @@ module.exports = function extractReactTypesLoader(content /* : string */) {
}
return null;
},
/*This is here for instances where there are paths which are not packages */
/* This is here for instances where there are paths which are not packages */
moduleDirectory: ['node_modules', 'src']
};

Expand Down

0 comments on commit 1ec5f76

Please sign in to comment.