File tree 5 files changed +32
-27
lines changed
packages/styled-components
5 files changed +32
-27
lines changed Original file line number Diff line number Diff line change @@ -2,4 +2,5 @@ node_modules
2
2
dist
3
3
.DS_Store
4
4
* .log
5
- package-lock.json
5
+ package-lock.json
6
+ ** /styled-components /src /utils /errors.js
Original file line number Diff line number Diff line change @@ -6,18 +6,15 @@ module.exports = () => ({
6
6
[
7
7
'@babel/preset-env' ,
8
8
{
9
- targets : NODE_ENV === 'test'
10
- ? { node : 'current' }
11
- : undefined ,
9
+ targets : NODE_ENV === 'test' ? { node : 'current' } : undefined ,
12
10
loose : true ,
13
11
modules,
14
12
} ,
15
13
] ,
16
14
'@babel/preset-react' ,
17
- '@babel/preset-flow'
15
+ '@babel/preset-flow' ,
18
16
] ,
19
17
plugins : [
20
- 'babel-plugin-preval' ,
21
18
[ 'babel-plugin-transform-react-remove-prop-types' , { mode : 'unsafe-wrap' } ] ,
22
19
[ '@babel/plugin-proposal-object-rest-spread' , { loose : true } ] ,
23
20
[ '@babel/plugin-proposal-class-properties' , { loose : true } ] ,
Original file line number Diff line number Diff line change 12
12
},
13
13
"sideEffects" : false ,
14
14
"scripts" : {
15
+ "generateErrors" : " node scripts/generateErrorMap.js" ,
16
+ "prebuild" : " rimraf dist && npm run generateErrors" ,
15
17
"build" : " rollup -c" ,
16
- "prebuild" : " rimraf dist" ,
17
18
"postbuild" : " npm run lint:size" ,
18
19
"flow" : " flow check" ,
19
20
"flow:watch" : " flow-watch" ,
20
- "test" : " run-s test:*" ,
21
+ "pretest" : " npm run generateErrors" ,
22
+ "test" : " npm run test:web && npm run test:native && npm run test:primitives" ,
21
23
"test:web" : " jest -c ../../scripts/jest/config.main.js" ,
22
24
"test:native" : " jest -c ../../scripts/jest/config.native.js" ,
23
25
"test:primitives" : " jest -c ../../scripts/jest/config.primitives.js" ,
Original file line number Diff line number Diff line change
1
+ const fs = require ( 'fs' ) ;
2
+ const path = require ( 'path' ) ;
3
+
4
+ const md = fs . readFileSync ( path . join ( __dirname , '../src/utils/errors.md' ) , 'utf8' ) ;
5
+
6
+ const errorMap = md
7
+ . split ( / ^ # / gm)
8
+ . slice ( 1 )
9
+ . reduce ( ( errors , str ) => {
10
+ const [ , code , message ] = str . split ( / ^ .* ?( \d + ) \s * \n / ) ;
11
+
12
+ // eslint-disable-next-line no-param-reassign
13
+ errors [ code ] = message ;
14
+
15
+ return errors ;
16
+ } , { } ) ;
17
+
18
+ fs . writeFileSync (
19
+ path . join ( __dirname , '../src/utils/errors.js' ) ,
20
+ `export default ${ JSON . stringify ( errorMap ) } ;` ,
21
+ 'utf8'
22
+ ) ;
Original file line number Diff line number Diff line change 1
1
// @flow
2
+ import errorMap from './errors' ;
2
3
3
- declare var preval: Function ;
4
-
5
- /**
6
- * Parse errors.md and turn it into a simple hash of code: message
7
- */
8
- const ERRORS =
9
- process . env . NODE_ENV !== 'production'
10
- ? preval `
11
- const fs = require('fs');
12
- const md = fs.readFileSync(__dirname + '/errors.md', 'utf8');
13
-
14
- module.exports = md.split(/^#/gm).slice(1).reduce((errors, str) => {
15
- const [, code, message] = str.split(/^.*?(\\d+)\\s*\\n/)
16
- errors[code] = message
17
-
18
- return errors;
19
- }, {});
20
- `
21
- : { } ;
4
+ const ERRORS = process . env . NODE_ENV !== 'production' ? errorMap : { } ;
22
5
23
6
/**
24
7
* super basic version of sprintf
You can’t perform that action at this time.
0 commit comments