Skip to content

Commit fc452f7

Browse files
committed
feat(material-parser): check module before install it; fix default value issue in ts parser
1 parent 7cbfade commit fc452f7

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

modules/material-parser/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alilc/lowcode-material-parser",
3-
"version": "1.0.1",
3+
"version": "1.0.1-beta.3",
44
"description": "material parser for Ali lowCode engine",
55
"main": "lib/index.js",
66
"files": [
@@ -18,6 +18,8 @@
1818
"@types/prop-types": "^15.7.3",
1919
"copy-webpack-plugin": "^9.1.0",
2020
"copyfiles": "^2.4.1",
21+
"eslint": "^8.12.0",
22+
"eslint-config-ali": "^14.0.0",
2123
"jest": "^26.6.3",
2224
"js-yaml": "^3.13.1",
2325
"json-schema-to-typescript": "^8.2.0",

modules/material-parser/src/parse/transform.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,11 @@ export function transformItem(name: string, item: any) {
286286
// if ('computed' in defaultValue) {
287287
// val = val.value;
288288
try {
289-
const value = safeEval(defaultValue.value);
290-
if (isEvaluable(value)) {
289+
if (isEvaluable(defaultValue.value)) {
290+
const value = safeEval(`'${defaultValue.value}'`);
291291
result.defaultValue = value;
292+
} else {
293+
result.defaultValue = defaultValue.value;
292294
}
293295
} catch (e) {
294296
log(e);

modules/material-parser/src/utils.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ export async function isNPMInstalled(args: {
1313
return pathExists(path.join(args.workDir, 'node_modules'));
1414
}
1515

16+
export async function isNPMModuleInstalled(
17+
args: { workDir: string; moduleDir: string; npmClient?: string },
18+
name: string,
19+
) {
20+
const modulePkgJsonPath = path.resolve(args.workDir, 'node_modules', name, 'package.json');
21+
return pathExists(modulePkgJsonPath);
22+
}
23+
1624
export async function install(args: { workDir: string; moduleDir: string; npmClient?: string }) {
1725
if (await isNPMInstalled(args)) return;
1826
const { workDir, npmClient = 'tnpm' } = args;
@@ -27,6 +35,7 @@ export async function installModule(
2735
args: { workDir: string; moduleDir: string; npmClient?: string },
2836
name: string,
2937
) {
38+
if (await isNPMModuleInstalled(args, name)) return;
3039
const { workDir, npmClient = 'tnpm' } = args;
3140
try {
3241
await spawn(npmClient, ['i', name], { stdio: 'inherit', cwd: workDir } as any);

0 commit comments

Comments
 (0)