-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (60 loc) · 1.85 KB
/
index.js
File metadata and controls
66 lines (60 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// @flow
const path = require('path');
const { extractReactTypes } = require('@extract-types/core');
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';
const resolveOpts = {
pathFilter: (pkg, location, dist) => {
if (
!pkg.types &&
pkg['atlaskit:src'] &&
location.includes('node_modules') &&
location.includes(pkg.main)
) {
return location.replace(dist, pkg['atlaskit:src']);
}
return null;
},
/*This is here for instances where there are paths which are not packages */
moduleDirectory: ['node_modules', 'src']
};
const types = extractReactTypes(content, typeSystem, filename, resolveOpts);
return `module.exports = ${JSON.stringify(types)}`;
};