Skip to content

Commit 1ec5f76

Browse files
authored
Remove Atlaskit specific process.env switches (#195) (#196)
* Remove Atlaskit specific process.env switches (#195) * Add changeset
1 parent dc5a362 commit 1ec5f76

File tree

2 files changed

+56
-39
lines changed

2 files changed

+56
-39
lines changed

.changeset/seven-rats-taste.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
"extract-react-types-loader": major
3+
---
4+
5+
Remove Atlaskit specific process.env switches (#195)
6+
7+
BREAKING CHANGE
8+
This removes the previously available process.env switches to conditionally disable the loader.
9+
To restore the previous behaviour you'll have to use the `resolveLoader` webpack config, e.g.
10+
11+
```js
12+
// webpack.config.js
13+
const enabled = ['production', 'staging'].includes(process.env.WEBSITE_ENV) || process.env.FORCE_EXTRACT_REACT_TYPES;
14+
15+
module.exports = {
16+
/* ... */
17+
resolveLoader: {
18+
alias: {
19+
'extract-react-types-loader': enabled ? undefined : require.resolve('./noop-extract-react-types-loader')
20+
}
21+
}
22+
};
23+
```
24+
25+
```js
26+
// noop-extract-react-types-loader.js
27+
module.exports = function noopExtractReactPropTypesLoader() {
28+
return `module.exports = {
29+
component: {
30+
kind: 'object',
31+
members: [
32+
{
33+
kind: 'property',
34+
key: { kind: 'id', name: 'Warning' },
35+
value: { kind: 'any' },
36+
optional: false,
37+
leadingComments: [
38+
{
39+
type: 'commentBlock',
40+
value: `extract-react-types is not being run in dev mode for speed reasons. If you need to
41+
see prop types add the environment variable \`FORCE_EXTRACT_REACT_TYPES\`
42+
raw: '**'
43+
}
44+
],
45+
default: {
46+
kind: 'string',
47+
value: 'Prop types are not shown in dev mode'
48+
}
49+
}
50+
],
51+
referenceIdName: 'NoopPropTpes'
52+
}
53+
};`
54+
}
55+
```

packages/extract-react-types-loader/index.js

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,8 @@
11
// @flow
2-
32
const path = require('path');
43
const { extractReactTypes } = require('extract-react-types');
54

6-
const devProps = {
7-
component: {
8-
kind: 'object',
9-
members: [
10-
{
11-
kind: 'property',
12-
key: { kind: 'id', name: 'Warning' },
13-
value: { kind: 'any' },
14-
optional: false,
15-
leadingComments: [
16-
{
17-
type: 'commentBlock',
18-
value: `extract-react-types is not being run in dev mode for speed reasons. If you need to
19-
see prop types add the environment variable \`FORCE_EXTRACT_REACT_TYPES\`
20-
eg:
21-
- \`FORCE_EXTRACT_REACT_TYPES=true yarn start <packageName>\`
22-
- \`FORCE_EXTRACT_REACT_TYPES=true yarn start:<team>\``,
23-
raw: '**'
24-
}
25-
],
26-
default: {
27-
kind: 'string',
28-
value: 'Prop types are not shown in dev mode'
29-
}
30-
}
31-
],
32-
referenceIdName: 'AvatarPropTypes'
33-
}
34-
};
35-
365
module.exports = function extractReactTypesLoader(content /* : string */) {
37-
if (
38-
!['staging', 'production'].includes(process.env.WEBSITE_ENV) &&
39-
!process.env.FORCE_EXTRACT_REACT_TYPES
40-
) {
41-
return `module.exports = ${JSON.stringify(devProps)}`;
42-
}
43-
446
const filename = this.resource;
457
const ext = path.extname(filename);
468
const typeSystem = ext === '.ts' || ext === '.tsx' ? 'typescript' : 'flow';
@@ -57,7 +19,7 @@ module.exports = function extractReactTypesLoader(content /* : string */) {
5719
}
5820
return null;
5921
},
60-
/*This is here for instances where there are paths which are not packages */
22+
/* This is here for instances where there are paths which are not packages */
6123
moduleDirectory: ['node_modules', 'src']
6224
};
6325

0 commit comments

Comments
 (0)