@umijs/ast 4.0.33 → 4.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as t from '@umijs/bundler-utils/compiled/babel/types';
|
|
2
|
-
export declare function setConfigByName(ast: t.File, name: string, value:
|
|
2
|
+
export declare function setConfigByName(ast: t.File, name: string, value: string): t.File;
|
|
3
3
|
declare const config: {
|
|
4
4
|
dva: {};
|
|
5
5
|
};
|
|
@@ -27,52 +27,26 @@ __export(setConfigByName_exports, {
|
|
|
27
27
|
});
|
|
28
28
|
module.exports = __toCommonJS(setConfigByName_exports);
|
|
29
29
|
var traverse = __toESM(require("@umijs/bundler-utils/compiled/babel/traverse"));
|
|
30
|
+
var import_parser = require("@umijs/bundler-utils/compiled/babel/parser");
|
|
30
31
|
var t = __toESM(require("@umijs/bundler-utils/compiled/babel/types"));
|
|
31
32
|
function setConfigByName(ast, name, value) {
|
|
32
|
-
|
|
33
|
-
|
|
33
|
+
if (typeof value !== "string") {
|
|
34
|
+
value = JSON.stringify(value);
|
|
35
|
+
}
|
|
34
36
|
let isChanged = false;
|
|
37
|
+
let valueObject = t.stringLiteral(value);
|
|
35
38
|
try {
|
|
36
|
-
|
|
39
|
+
JSON.parse(value);
|
|
40
|
+
valueObject = (0, import_parser.parseExpression)(value);
|
|
37
41
|
} catch (error) {
|
|
38
|
-
_value = value;
|
|
39
|
-
}
|
|
40
|
-
const valueType = typeof _value;
|
|
41
|
-
switch (valueType) {
|
|
42
|
-
case "string":
|
|
43
|
-
valueObject = t.stringLiteral(_value);
|
|
44
|
-
break;
|
|
45
|
-
case "boolean":
|
|
46
|
-
valueObject = t.booleanLiteral(_value);
|
|
47
|
-
break;
|
|
48
|
-
case "number":
|
|
49
|
-
valueObject = t.numericLiteral(_value);
|
|
50
|
-
break;
|
|
51
|
-
case "object":
|
|
52
|
-
if (Array.isArray(_value)) {
|
|
53
|
-
valueObject = t.arrayExpression(_value.map((i) => {
|
|
54
|
-
return t.stringLiteral(i);
|
|
55
|
-
}));
|
|
56
|
-
} else {
|
|
57
|
-
const valueObjs = [];
|
|
58
|
-
Object.keys(_value).forEach((key) => {
|
|
59
|
-
valueObjs.push(t.objectProperty(t.identifier(key), t.stringLiteral(_value[key])));
|
|
60
|
-
});
|
|
61
|
-
valueObject = t.objectExpression(valueObjs);
|
|
62
|
-
}
|
|
63
|
-
break;
|
|
64
|
-
default:
|
|
65
|
-
console.log(`${valueType} is not supported.`);
|
|
66
|
-
break;
|
|
67
42
|
}
|
|
68
|
-
if (!valueObject)
|
|
69
|
-
return;
|
|
70
43
|
traverse.default(ast, {
|
|
71
44
|
ObjectProperty(path) {
|
|
72
45
|
var _a;
|
|
73
46
|
if (((_a = path.node.key) == null ? void 0 : _a.name) === name) {
|
|
74
47
|
path.node.value = valueObject;
|
|
75
48
|
isChanged = true;
|
|
49
|
+
path.stop();
|
|
76
50
|
}
|
|
77
51
|
}
|
|
78
52
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@umijs/ast",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.35",
|
|
4
4
|
"description": "@umijs/ast",
|
|
5
5
|
"homepage": "https://github.com/umijs/umi/tree/master/packages/ast#readme",
|
|
6
6
|
"bugs": "https://github.com/umijs/umi/issues",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"test": "umi-scripts jest-turbo"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@umijs/bundler-utils": "4.0.
|
|
24
|
+
"@umijs/bundler-utils": "4.0.35"
|
|
25
25
|
},
|
|
26
26
|
"publishConfig": {
|
|
27
27
|
"access": "public"
|