Skip to content

Commit

Permalink
chore: test unplugin-icons
Browse files Browse the repository at this point in the history
  • Loading branch information
sorrycc committed Dec 24, 2024
1 parent c298e52 commit 69d5111
Show file tree
Hide file tree
Showing 7 changed files with 279 additions and 11 deletions.
3 changes: 2 additions & 1 deletion e2e/fixtures/plugins.unplugin/expect.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const { parseBuildResult } = require('../../../scripts/test-utils');
const { files } = parseBuildResult(__dirname);

const content = files['index.js'];
assert(content.includes('fooooooo'), `should replace FOOOO with "fooooooo"`);
assert(content.includes('fooooooo'), `should replace FOOOO with "fooooooo" with unplugin-replace`);
assert(content.includes('fill: "currentColor",'), `should include fill: "currentColor" with unplugin-icons`);
4 changes: 4 additions & 0 deletions e2e/fixtures/plugins.unplugin/mako.config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"externals": {
"react": "React",
"react/jsx-dev-runtime": "React.jsx"
},
"minify": false
}
6 changes: 6 additions & 0 deletions e2e/fixtures/plugins.unplugin/plugins.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const replace = require('unplugin-replace');
const icons = require('unplugin-icons');

module.exports = [
replace.raw({
Expand All @@ -9,4 +10,9 @@ module.exports = [
},
],
}),
icons.default.raw({
compiler: 'jsx',
jsx: 'react',
autoInstall: false,
}),
];
4 changes: 4 additions & 0 deletions e2e/fixtures/plugins.unplugin/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
import React from 'react';
import IconAccountBox from '~icons/mdi/account-box';

console.log(FOOOO);
export default () => <IconAccountBox />;
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"@biomejs/biome": "^1.4.1",
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@iconify-json/mdi": "^1.2.2",
"@jest/expect": "^29.7.0",
"@swc/helpers": "0.5.1",
"@taplo/cli": "^0.7.0",
Expand Down Expand Up @@ -55,6 +56,7 @@
"semver": "^7.5.4",
"typescript": "^5.4.3",
"umi": "^4.3.1",
"unplugin-icons": "^0.22.0",
"unplugin-replace": "^0.3.3",
"wait-port": "^1.1.0",
"webpack": "^5.0.0",
Expand Down
15 changes: 13 additions & 2 deletions packages/mako/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ export async function build(params: BuildParams) {
plugins.forEach((plugin: any) => {
Object.keys(plugin).forEach((key) => {
const oldValue = plugin[key];
const shouldAdapt = key === 'load' || key === 'transform';
if (typeof oldValue === 'function') {
plugin[key] = (context: any, ...args: any[]) => {
let result = oldValue.apply(
Expand Down Expand Up @@ -274,14 +273,26 @@ export async function build(params: BuildParams) {
[...args],
);
// adapter mako hooks for unplugin
if (shouldAdapt) {
if (key === 'load' || key === 'transform') {
// if result is null, return the original code
if (result === null) {
result = args[0];
}
const isPromise = typeof result === 'object' && result.then;
if (isPromise) {
result = result.then((result: any) => adapterResult(result));
} else {
result = adapterResult(result);
}
}
if (key === 'resolveId') {
if (typeof result === 'string') {
result = {
id: result,
external: false,
};
}
}
return result;
};
}
Expand Down
Loading

0 comments on commit 69d5111

Please sign in to comment.