mirror of
https://github.com/alibaba/lowcode-engine.git
synced 2026-03-01 05:30:40 +00:00
1. fix bug of failing to resolve RFC components
2. support transforming function args
3. fix bug of oneOfType
4. fix bug of crash when circular parsing
5. fix bug of union
6. support tuple
7. fix bug of builtin type parsing
8. fix bug of false positive component identification
9. fix bug of entry resolving
38 lines
1005 B
TypeScript
38 lines
1005 B
TypeScript
import { readFileSync } from 'fs-extra';
|
|
import { NodeVM } from 'vm2';
|
|
// import PropTypes from 'prop-types';
|
|
|
|
const cssPattern = /\.(css|scss|sass|less)$/;
|
|
function requireInSandbox(filePath: string, PropTypes: any) {
|
|
const vm = new NodeVM({
|
|
sandbox: {},
|
|
sourceExtensions: ['js', 'css', 'scss', 'sass', 'less'],
|
|
compiler: (code, filename) => {
|
|
if (filename.match(cssPattern)) {
|
|
return `
|
|
const handler = {
|
|
get() {
|
|
return new Proxy({}, handler);
|
|
},
|
|
};
|
|
const proxiedObject = new Proxy({}, handler);
|
|
module.exports = proxiedObject;
|
|
`;
|
|
} else {
|
|
return code;
|
|
}
|
|
},
|
|
require: {
|
|
external: true,
|
|
context: 'sandbox',
|
|
mock: {
|
|
'prop-types': PropTypes,
|
|
},
|
|
},
|
|
});
|
|
const fileContent = readFileSync(filePath, { encoding: 'utf8' });
|
|
return vm.run(fileContent, filePath);
|
|
}
|
|
|
|
export default requireInSandbox;
|