fix: 修复 windows 兼容问题

This commit is contained in:
winixt 2022-11-25 11:20:29 +08:00
parent 5eeb100533
commit cc16721fd5
2 changed files with 36 additions and 15 deletions

View File

@ -26,8 +26,28 @@ export default class BabelRegister {
}, },
], ],
], ],
ignore: [/node_modules/], plugins: [
only, function () {
return {
visitor: {
ExportAllDeclaration(path) {
if (path.node.source.value.startsWith('@@')) {
path.remove();
}
},
},
};
},
],
only: [
...only,
function (filepath) {
if (/@fesjs[/\\]+fes/.test(filepath)) {
return true;
}
return false;
},
],
extensions: ['.jsx', '.js', '.ts', '.tsx'], extensions: ['.jsx', '.js', '.ts', '.tsx'],
babelrc: false, babelrc: false,
cache: false, cache: false,

View File

@ -1,23 +1,24 @@
// @ts-ignore // @ts-ignore
import { readFileSync } from 'fs';
import { dirname } from 'path';
import crequire from 'crequire'; import crequire from 'crequire';
import lodash from 'lodash'; import lodash from 'lodash';
import resolve from 'resolve'; import resolve from 'resolve';
import { readFileSync } from 'fs';
import { dirname } from 'path';
import winPath from './winPath'; import winPath from './winPath';
function parse(filePath) { function parse(filePath) {
const content = readFileSync(filePath, 'utf-8'); const content = readFileSync(filePath, 'utf-8');
return (crequire(content)) return crequire(content)
.map(o => o.path) .map((o) => o.path)
.filter(path => path.charAt(0) === '.') .filter((path) => path.charAt(0) === '.')
.map(path => winPath( .map((path) =>
winPath(
resolve.sync(path, { resolve.sync(path, {
basedir: dirname(filePath), basedir: dirname(filePath),
extensions: ['.tsx', '.ts', '.jsx', '.js'] extensions: ['.tsx', '.ts', '.jsx', '.js'],
}) }),
)); ),
);
} }
export default function parseRequireDeps(filePath) { export default function parseRequireDeps(filePath) {