Skip to content

Commit be7e4eb

Browse files
committed
remove babel-plugin-preval and generate errormap as a build step
1 parent fc20334 commit be7e4eb

File tree

5 files changed

+32
-27
lines changed

5 files changed

+32
-27
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
dist
33
.DS_Store
44
*.log
5-
package-lock.json
5+
package-lock.json
6+
**/styled-components/src/utils/errors.js

babel-preset.js

+2-5
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@ module.exports = () => ({
66
[
77
'@babel/preset-env',
88
{
9-
targets: NODE_ENV === 'test'
10-
? { node: 'current' }
11-
: undefined,
9+
targets: NODE_ENV === 'test' ? { node: 'current' } : undefined,
1210
loose: true,
1311
modules,
1412
},
1513
],
1614
'@babel/preset-react',
17-
'@babel/preset-flow'
15+
'@babel/preset-flow',
1816
],
1917
plugins: [
20-
'babel-plugin-preval',
2118
['babel-plugin-transform-react-remove-prop-types', { mode: 'unsafe-wrap' }],
2219
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
2320
['@babel/plugin-proposal-class-properties', { loose: true }],

packages/styled-components/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@
1212
},
1313
"sideEffects": false,
1414
"scripts": {
15+
"generateErrors": "node scripts/generateErrorMap.js",
16+
"prebuild": "rimraf dist && npm run generateErrors",
1517
"build": "rollup -c",
16-
"prebuild": "rimraf dist",
1718
"postbuild": "npm run lint:size",
1819
"flow": "flow check",
1920
"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",
2123
"test:web": "jest -c ../../scripts/jest/config.main.js",
2224
"test:native": "jest -c ../../scripts/jest/config.native.js",
2325
"test:primitives": "jest -c ../../scripts/jest/config.primitives.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
);

packages/styled-components/src/utils/error.js

+2-19
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
// @flow
2+
import errorMap from './errors';
23

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 : {};
225

236
/**
247
* super basic version of sprintf

0 commit comments

Comments
 (0)