mirror of
https://github.com/zhigang1992/styled-components.git
synced 2026-01-12 22:52:39 +08:00
remove babel-plugin-preval and generate errormap as a build step
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -2,4 +2,5 @@ node_modules
|
||||
dist
|
||||
.DS_Store
|
||||
*.log
|
||||
package-lock.json
|
||||
package-lock.json
|
||||
**/styled-components/src/utils/errors.js
|
||||
|
||||
@@ -6,18 +6,15 @@ module.exports = () => ({
|
||||
[
|
||||
'@babel/preset-env',
|
||||
{
|
||||
targets: NODE_ENV === 'test'
|
||||
? { node: 'current' }
|
||||
: undefined,
|
||||
targets: NODE_ENV === 'test' ? { node: 'current' } : undefined,
|
||||
loose: true,
|
||||
modules,
|
||||
},
|
||||
],
|
||||
'@babel/preset-react',
|
||||
'@babel/preset-flow'
|
||||
'@babel/preset-flow',
|
||||
],
|
||||
plugins: [
|
||||
'babel-plugin-preval',
|
||||
['babel-plugin-transform-react-remove-prop-types', { mode: 'unsafe-wrap' }],
|
||||
['@babel/plugin-proposal-object-rest-spread', { loose: true }],
|
||||
['@babel/plugin-proposal-class-properties', { loose: true }],
|
||||
|
||||
@@ -12,12 +12,14 @@
|
||||
},
|
||||
"sideEffects": false,
|
||||
"scripts": {
|
||||
"generateErrors": "node scripts/generateErrorMap.js",
|
||||
"prebuild": "rimraf dist && npm run generateErrors",
|
||||
"build": "rollup -c",
|
||||
"prebuild": "rimraf dist",
|
||||
"postbuild": "npm run lint:size",
|
||||
"flow": "flow check",
|
||||
"flow:watch": "flow-watch",
|
||||
"test": "run-s test:*",
|
||||
"pretest": "npm run generateErrors",
|
||||
"test": "npm run test:web && npm run test:native && npm run test:primitives",
|
||||
"test:web": "jest -c ../../scripts/jest/config.main.js",
|
||||
"test:native": "jest -c ../../scripts/jest/config.native.js",
|
||||
"test:primitives": "jest -c ../../scripts/jest/config.primitives.js",
|
||||
|
||||
22
packages/styled-components/scripts/generateErrorMap.js
Normal file
22
packages/styled-components/scripts/generateErrorMap.js
Normal file
@@ -0,0 +1,22 @@
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const md = fs.readFileSync(path.join(__dirname, '../src/utils/errors.md'), 'utf8');
|
||||
|
||||
const errorMap = md
|
||||
.split(/^#/gm)
|
||||
.slice(1)
|
||||
.reduce((errors, str) => {
|
||||
const [, code, message] = str.split(/^.*?(\d+)\s*\n/);
|
||||
|
||||
// eslint-disable-next-line no-param-reassign
|
||||
errors[code] = message;
|
||||
|
||||
return errors;
|
||||
}, {});
|
||||
|
||||
fs.writeFileSync(
|
||||
path.join(__dirname, '../src/utils/errors.js'),
|
||||
`export default ${JSON.stringify(errorMap)};`,
|
||||
'utf8'
|
||||
);
|
||||
@@ -1,24 +1,7 @@
|
||||
// @flow
|
||||
import errorMap from './errors';
|
||||
|
||||
declare var preval: Function;
|
||||
|
||||
/**
|
||||
* Parse errors.md and turn it into a simple hash of code: message
|
||||
*/
|
||||
const ERRORS =
|
||||
process.env.NODE_ENV !== 'production'
|
||||
? preval`
|
||||
const fs = require('fs');
|
||||
const md = fs.readFileSync(__dirname + '/errors.md', 'utf8');
|
||||
|
||||
module.exports = md.split(/^#/gm).slice(1).reduce((errors, str) => {
|
||||
const [, code, message] = str.split(/^.*?(\\d+)\\s*\\n/)
|
||||
errors[code] = message
|
||||
|
||||
return errors;
|
||||
}, {});
|
||||
`
|
||||
: {};
|
||||
const ERRORS = process.env.NODE_ENV !== 'production' ? errorMap : {};
|
||||
|
||||
/**
|
||||
* super basic version of sprintf
|
||||
|
||||
Reference in New Issue
Block a user