Skip to content

Commit 70275b8

Browse files
xsahxlheimanba
authored andcommitted
fix: Serverless-Devs/Serverless-Devs#608 魔法变量解析不符合预期
1 parent 08a29ca commit 70275b8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/common/execCommand/parse.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import * as fs from 'fs-extra';
2-
import { startsWith, get, merge, replace } from 'lodash';
2+
import { startsWith, get, merge, replace, isNil } from 'lodash';
33
import { getCurrentPath } from './utils';
44
import path from 'path';
55
import yaml from 'js-yaml';
@@ -44,11 +44,10 @@ export default class Parse {
4444
const { variableName, type, funName, funVariable } = variableObj;
4545
const result = '';
4646
if (type === 'Literal') {
47-
return (
48-
this.globalJsonKeyMap[variableName] ||
49-
this.globalJsonKeyMap[`services.${variableName}`] ||
50-
'${' + variableName + '}'
51-
);
47+
if (!isNil(this.globalJsonKeyMap[variableName])) return this.globalJsonKeyMap[variableName];
48+
if (!isNil(this.globalJsonKeyMap[`services.${variableName}`]))
49+
return this.globalJsonKeyMap[`services.${variableName}`];
50+
return '${' + variableName + '}';
5251
}
5352
if (type === 'Fun' && (funName === 'Env' || funName === 'env')) {
5453
return process.env[funVariable];
@@ -125,7 +124,7 @@ export default class Parse {
125124
let realValue = startsWith(matchResult, 'env.')
126125
? get(process, matchResult)
127126
: this.findVariableValue(variableObj);
128-
if (realValue) {
127+
if (!isNil(realValue)) {
129128
tmp =
130129
Object.prototype.toString.call(realValue) === '[object String]'
131130
? replace(tmp, iterator, realValue)

0 commit comments

Comments
 (0)