zarro 1.168.2 → 1.168.4
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.
- package/index.js +24 -6
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -70,8 +70,13 @@ async function loadDefaults() {
|
|
|
70
70
|
await createZarroDefaultsEmpty();
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
|
+
let currentSection = "defaults"; // unnamed section is defaults section
|
|
73
74
|
const
|
|
74
|
-
lines = await readTextFileLines(defaultsFile)
|
|
75
|
+
lines = await readTextFileLines(defaultsFile),
|
|
76
|
+
taskName = `${ process.env.npm_lifecycle_event }`.toLowerCase(),
|
|
77
|
+
shouldSkip = () => {
|
|
78
|
+
return currentSection !== "defaults" && currentSection !== taskName;
|
|
79
|
+
};
|
|
75
80
|
for (const line of lines) {
|
|
76
81
|
const
|
|
77
82
|
[ code, _ ] = splitComment(line);
|
|
@@ -79,6 +84,16 @@ async function loadDefaults() {
|
|
|
79
84
|
// comment-only line or empty line
|
|
80
85
|
continue;
|
|
81
86
|
}
|
|
87
|
+
const sectionMatch = code.match(/\s*\[(?<section>[a-zA-Z0-9\s-_.]+)]\s*/);
|
|
88
|
+
if (sectionMatch) {
|
|
89
|
+
currentSection = `${sectionMatch.groups.section}`.toLowerCase();
|
|
90
|
+
continue;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
if (shouldSkip()) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
|
|
82
97
|
if (looksInvalid(code)) {
|
|
83
98
|
log.warn(`invalid config line in ${ defaultsFile }:\n${ line }`);
|
|
84
99
|
continue;
|
|
@@ -88,18 +103,21 @@ async function loadDefaults() {
|
|
|
88
103
|
name = parts[0],
|
|
89
104
|
value = Array.from(skip(parts, 1)).join("="),
|
|
90
105
|
forced = name[0] === '!',
|
|
106
|
+
forwarded = value[0] === '$',
|
|
91
107
|
notYetSet = process.env[name] === undefined;
|
|
92
108
|
if (notYetSet || forced) {
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
109
|
+
const
|
|
110
|
+
key = name.replace(/^!/, ""),
|
|
111
|
+
finalValue = forwarded ? process.env[value.substring(1)] : value;
|
|
112
|
+
if (finalValue) {
|
|
113
|
+
debug(`setting env var ${ key } to '${ finalValue }'`);
|
|
114
|
+
process.env[key] = finalValue;
|
|
97
115
|
} else {
|
|
98
116
|
debug(`deleting env var ${ key }`);
|
|
99
117
|
delete process.env[key];
|
|
100
118
|
}
|
|
101
119
|
} else {
|
|
102
|
-
debug(`env var ${ name } is already set, force it by setting !${ name }=${ value } in ${ defaultsFile }`)
|
|
120
|
+
debug(`env var ${ name } is already set, force it by setting !${ name }=${ value } in ${ defaultsFile }`);
|
|
103
121
|
}
|
|
104
122
|
}
|
|
105
123
|
}
|