Skip to content

Commit

Permalink
Showing 2 changed files with 36 additions and 15 deletions.
24 changes: 22 additions & 2 deletions packages/fes-compiler/src/service/babelRegister.js
Original file line number Diff line number Diff line change
@@ -26,8 +26,28 @@ export default class BabelRegister {
},
],
],
ignore: [/node_modules/],
only,
plugins: [
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'],
babelrc: false,
cache: false,
27 changes: 14 additions & 13 deletions packages/fes-utils/src/parseRequireDeps.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@

// @ts-ignore
import { readFileSync } from 'fs';
import { dirname } from 'path';
import crequire from 'crequire';
import lodash from 'lodash';
import resolve from 'resolve';
import { readFileSync } from 'fs';
import { dirname } from 'path';
import winPath from './winPath';

function parse(filePath) {
const content = readFileSync(filePath, 'utf-8');
return (crequire(content))
.map(o => o.path)
.filter(path => path.charAt(0) === '.')
.map(path => winPath(
resolve.sync(path, {
basedir: dirname(filePath),
extensions: ['.tsx', '.ts', '.jsx', '.js']
})
));
return crequire(content)
.map((o) => o.path)
.filter((path) => path.charAt(0) === '.')
.map((path) =>
winPath(
resolve.sync(path, {
basedir: dirname(filePath),
extensions: ['.tsx', '.ts', '.jsx', '.js'],
}),
),
);
}

export default function parseRequireDeps(filePath) {
const paths = [filePath];
const ret = [winPath(filePath)];

while (paths.length) {
// 避免依赖循环
// 避免依赖循环
const extraPaths = lodash.pullAll(parse(paths.shift()), ret);
if (extraPaths.length) {
paths.push(...extraPaths);

0 comments on commit cc16721

Please sign in to comment.