Skip to content

Commit 469c018

Browse files
author
Dawnlck
authored
feat(customStyleName): 完善customStyleName传参 (#603)
* feat(customStyleName): 完善customStyleName传参 * test(customStyleName): 提供customStyleName传入file参数的测例 * test(customStyleName): 补充customStyleName 的分支测例
1 parent d21264e commit 469c018

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

src/Plugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export default class Plugin {
7676
? addDefault(file.path, path, { nameHint: methodName })
7777
: addNamed(file.path, methodName, path);
7878
if (this.customStyleName) {
79-
const stylePath = winPath(this.customStyleName(transformedMethodName));
79+
const stylePath = winPath(this.customStyleName(transformedMethodName, file));
8080
addSideEffect(file.path, `${stylePath}`);
8181
} else if (this.styleLibraryDirectory) {
8282
const stylePath = winPath(
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { Button } from 'element-ui';
2+
3+
ReactDOM.render(<div>
4+
<Button>xxxx</Button>
5+
</div>);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"use strict";
2+
3+
var _react = _interopRequireDefault(require("react"));
4+
5+
require("../../../../element-ui/lib/theme-light/button");
6+
7+
var _button2 = _interopRequireDefault(require("element-ui/lib/button"));
8+
9+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10+
11+
ReactDOM.render( /*#__PURE__*/_react.default.createElement("div", null, /*#__PURE__*/_react.default.createElement(_button2.default, null, "xxxx")));

test/index.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,20 @@ describe('index', () => {
101101
customStyleName: name => `element-ui/lib/theme-light/${name}`,
102102
},
103103
];
104+
} else if (caseName === 'custom-style-name-file') {
105+
pluginWithOpts = [
106+
plugin,
107+
{
108+
libraryName: 'element-ui',
109+
customStyleName: (name, file) => {
110+
const { root, filename } = file?.opts;
111+
const diff = filename?.slice(root?.length);
112+
const count = diff.match(/\//g).length;
113+
const prefix = String.prototype.repeat.call('../', count);
114+
return `${prefix}element-ui/lib/theme-light/${name}`;
115+
},
116+
},
117+
];
104118
} else {
105119
pluginWithOpts = [plugin, { libraryName: 'antd' }];
106120
}

0 commit comments

Comments
 (0)