zarro 1.218.0 → 1.219.0

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/README.md CHANGED
@@ -193,25 +193,35 @@ TEST_EXCLUDE=src/PeanutButter/**/*
193
193
  Note also here the shorthand of `@` - if a task has the same name as the npm script
194
194
  used to invoke it, this is a quick way to surface that task to `npm run` -space.
195
195
 
196
+ #### Precedence
197
+ - an environment variable which is already set (from your shell, `cross-env` in an npm script,
198
+ your CI system...) wins over `.zarro-defaults`, unless the name in `.zarro-defaults` is
199
+ prefixed with `!`: `!FOO=bar` forces `FOO` to `bar` even if it is already set.
200
+ - within `.zarro-defaults`, later lines override earlier ones, so no `!` is needed to override
201
+ a value given above it (see sections, below).
202
+ - values are used exactly as written: `FOO="a b"` sets `FOO` to `"a b"`, quotes included, so
203
+ leave the quotes off: `FOO=a b`.
204
+
196
205
  #### Variables for one npm script only
197
206
  Variables can be limited to a single npm script by putting them under a `[section]` header,
198
207
  named for the npm script (so `npm run release-beta` is `[release-beta]`). Names are
199
- matched case-insensitively. Variables before any header, or under `[defaults]`, always apply:
208
+ matched case-insensitively. Variables before any header, or under `[defaults]`, always apply.
209
+ A section applies until the next header, and, since later lines win, it can override a value
210
+ given above it:
200
211
 
201
212
  ```
202
213
  DOTNET_CORE=1
214
+ FOO=the value for everything
203
215
 
204
216
  [release]
205
217
  NPM_PUBLISH_ACCESS=public
218
+ FOO=the value, just for `npm run release`
206
219
 
207
220
  [defaults]
208
221
  # back to variables which apply to every script
209
222
  TEST_EXCLUDE=src/PeanutButter/**/*
210
223
  ```
211
224
 
212
- A section applies until the next header. The usual rules still hold inside a section: the
213
- value of an existing environment variable wins unless the name is prefixed with `!`.
214
-
215
225
  #### Taking a value from another environment variable
216
226
  A value which starts with `$` is replaced with the value of the environment variable of
217
227
  that name, eg `NPM_TOKEN=$MY_SECRET_TOKEN`. If that variable isn't set, the value is empty
@@ -7,20 +7,25 @@
7
7
  async function createZarroDefaultsEmpty(defaultsFile) {
8
8
  await writeTextFile(defaultsFile, `# zarro defaults file:
9
9
  # place one VARIABLE=VALUE per line below
10
- # variables here will not override existing environment variables
11
- # unless prepended with a bang, ie
12
- # !VARIABLE=Value
13
- # so this means anything you set in your package.json, eg with
14
- # cross-env, will override what's in here unless you've specifically
15
- # marked the setting in here as forced with !
10
+ # values are used exactly as written, so don't put quotes around them
11
+ #
12
+ # precedence:
13
+ # - variables here will not override existing environment variables
14
+ # unless prepended with a bang, ie
15
+ # !VARIABLE=Value
16
+ # so anything you set in your package.json, eg with cross-env,
17
+ # will override what's in here unless you've specifically marked
18
+ # the setting in here as forced with !
19
+ # - within this file, later lines override earlier ones (no ! needed)
16
20
  #
17
21
  # a variable can take its value from another environment variable:
18
22
  # VARIABLE=$OTHER_VARIABLE
19
23
  #
20
24
  # variables can be limited to one npm script with a [section] header, eg
25
+ # VARIABLE=value for everything
21
26
  # [release]
22
- # VARIABLE=Value
23
- # applies only when running \`npm run release\`; use [defaults] to go
27
+ # VARIABLE=value just for \`npm run release\`
28
+ # a section applies until the next header; use [defaults] to go
24
29
  # back to variables which apply to everything
25
30
  `);
26
31
  }
@@ -35,6 +40,9 @@
35
40
  }
36
41
  const lines = await readTextFileLines(defaultsFile), currentTask = taskName.toLowerCase();
37
42
  let currentSection = defaultsSection;
43
+ // variables this file has set: later lines may override them, whereas
44
+ // variables which were already in the environment need a ! to be overridden
45
+ const setByThisFile = new Set();
38
46
  for (const line of lines) {
39
47
  const [code] = splitComment(line);
40
48
  if (isEmpty(code)) {
@@ -53,18 +61,20 @@
53
61
  log.warn(`invalid config line in ${defaultsFile}:\n${line}`);
54
62
  continue;
55
63
  }
56
- const parts = code.trim().split("="), name = parts[0], value = parts.slice(1).join("="), forced = name[0] === "!", forwarded = value[0] === "$", notYetSet = env[name] === undefined;
57
- if (notYetSet || forced) {
58
- const key = name.replace(/^!/, ""), finalValue = forwarded
64
+ const parts = code.trim().split("="), name = parts[0], value = parts.slice(1).join("="), forced = name[0] === "!", forwarded = value[0] === "$", key = name.replace(/^!/, ""), canSet = env[key] === undefined || setByThisFile.has(key);
65
+ if (canSet || forced) {
66
+ const finalValue = forwarded
59
67
  ? env[value.substring(1)]
60
68
  : value;
61
69
  if (finalValue) {
62
70
  debug(`setting env var ${key} to '${finalValue}'`);
63
71
  env[key] = finalValue;
72
+ setByThisFile.add(key);
64
73
  }
65
74
  else {
66
75
  debug(`deleting env var ${key}`);
67
76
  delete env[key];
77
+ setByThisFile.delete(key);
68
78
  }
69
79
  }
70
80
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zarro",
3
- "version": "1.218.0",
3
+ "version": "1.219.0",
4
4
  "description": "Some glue to make gulp easier, perhaps even zero- or close-to-zero-conf",
5
5
  "bin": {
6
6
  "zarro": "index.js"