@jdeighan/env 9.0.6 → 9.1.2

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jdeighan/env",
3
3
  "type": "module",
4
- "version": "9.0.6",
4
+ "version": "9.1.2",
5
5
  "description": "enhanced syntax for .env files",
6
6
  "main": "./src/EnvLoaderEx.js",
7
7
  "exports": {
@@ -31,8 +31,8 @@
31
31
  },
32
32
  "homepage": "https://github.com/johndeighan/env#readme",
33
33
  "dependencies": {
34
- "@jdeighan/coffee-utils": "^7.0.1",
35
- "@jdeighan/string-input": "^11.0.0",
34
+ "@jdeighan/coffee-utils": "^7.0.8",
35
+ "@jdeighan/mapper": "^13.0.2",
36
36
  "coffeescript": "^2.6.1",
37
37
  "cross-env": "^7.0.3"
38
38
  },
@@ -9,7 +9,7 @@ import {
9
9
  import {log} from '@jdeighan/coffee-utils/log'
10
10
  import {debug} from '@jdeighan/coffee-utils/debug'
11
11
  import {slurp, pathTo, mkpath} from '@jdeighan/coffee-utils/fs'
12
- import {PLLParser} from '@jdeighan/string-input/pll'
12
+ import {TreeMapper} from '@jdeighan/mapper/tree'
13
13
 
14
14
  hDefCallbacks = {
15
15
  getVar: (name) ->
@@ -28,7 +28,7 @@ hDefCallbacks = {
28
28
 
29
29
  # ---------------------------------------------------------------------------
30
30
 
31
- export class EnvLoader extends PLLParser
31
+ export class EnvLoader extends TreeMapper
32
32
 
33
33
  constructor: (contents, source, hOptions={}) ->
34
34
  # --- Valid options:
@@ -199,9 +199,11 @@ export class EnvLoader extends PLLParser
199
199
 
200
200
  procEnv: (tree) ->
201
201
 
202
- debug "enter procEnv()"
202
+ assert tree?, "procEnv(): tree is undef"
203
+ debug "enter procEnv()", tree
203
204
 
204
205
  for h in tree
206
+ debug 'h', h
205
207
  switch h.node.type
206
208
 
207
209
  when 'assign'
@@ -214,8 +216,8 @@ export class EnvLoader extends PLLParser
214
216
  {key} = h.node
215
217
  debug "if_truthy: '#{key}'"
216
218
  if @getVar(key)
217
- debug "procEnv(): if_truthy('#{key}') - proc body"
218
- @procEnv(h.body)
219
+ debug "procEnv(): if_truthy('#{key}') - proc subtree"
220
+ @procEnv(h.subtree)
219
221
  else
220
222
  debug "procEnv(): if_truthy('#{key}') - skip"
221
223
 
@@ -225,15 +227,15 @@ export class EnvLoader extends PLLParser
225
227
  if @getVar(key)
226
228
  debug "procEnv(): if_falsy('#{key}') - skip"
227
229
  else
228
- debug "procEnv(): if_falsy('#{key}') - proc body"
229
- @procEnv(h.body)
230
+ debug "procEnv(): if_falsy('#{key}') - proc subtree"
231
+ @procEnv(h.subtree)
230
232
 
231
233
  when 'compare'
232
234
  {key, op, value} = h.node
233
235
  debug "procEnv(key=#{key}, value=#{value})"
234
236
  if @doCompare(key, op, value)
235
- debug "procEnv(): compare('#{key}','#{value}') - proc body"
236
- @procEnv(h.body)
237
+ debug "procEnv(): compare('#{key}','#{value}') - proc subtree"
238
+ @procEnv(h.subtree)
237
239
  else
238
240
  debug "procEnv(): compare('#{key}','#{value}') - skip"
239
241
 
@@ -270,8 +272,10 @@ export loadEnvString = (contents, hOptions={}, source=undef) ->
270
272
 
271
273
  export loadEnvFile = (filepath, hOptions={}) ->
272
274
 
273
- debug "LOADENV #{filepath}"
274
- loadEnvString undef, hOptions, filepath
275
+ debug "enter loadEnvFile #{filepath}"
276
+ contents = slurp filepath
277
+ loadEnvString contents, hOptions, filepath
278
+ debug "return from loadEnvFile"
275
279
  return
276
280
 
277
281
  # ---------------------------------------------------------------------------
@@ -282,7 +286,7 @@ export loadEnvFrom = (searchDir, hOptions={}) ->
282
286
  # onefile - load only the first file found
283
287
  # hCallbacks - getVar, setVar, clearVar, clearAll, names
284
288
 
285
- debug "enter loadEnvFrom('#{searchDir}')"
289
+ debug "enter loadEnvFrom '#{searchDir}'"
286
290
  path = pathTo('.env', searchDir, "up")
287
291
  if ! path?
288
292
  debug "return from loadEnvFrom() - no .env file found"
@@ -296,7 +300,8 @@ export loadEnvFrom = (searchDir, hOptions={}) ->
296
300
  debug "found .env file: #{path}"
297
301
  lPaths.unshift path
298
302
 
299
- for path in lPaths
300
- loadEnvFile(path, hOptions)
303
+ debug 'lPaths', lPaths
304
+ for filepath in lPaths
305
+ loadEnvFile filepath, hOptions
301
306
  debug "return from loadEnvFrom()"
302
307
  return lPaths
@@ -32,8 +32,8 @@ import {
32
32
  } from '@jdeighan/coffee-utils/fs';
33
33
 
34
34
  import {
35
- PLLParser
36
- } from '@jdeighan/string-input/pll';
35
+ TreeMapper
36
+ } from '@jdeighan/mapper/tree';
37
37
 
38
38
  hDefCallbacks = {
39
39
  getVar: function(name) {
@@ -54,7 +54,7 @@ hDefCallbacks = {
54
54
  };
55
55
 
56
56
  // ---------------------------------------------------------------------------
57
- export var EnvLoader = class EnvLoader extends PLLParser {
57
+ export var EnvLoader = class EnvLoader extends TreeMapper {
58
58
  constructor(contents, source, hOptions = {}) {
59
59
  // --- Valid options:
60
60
  // prefix - load only vars with this prefix
@@ -206,9 +206,11 @@ export var EnvLoader = class EnvLoader extends PLLParser {
206
206
  // ..........................................................
207
207
  procEnv(tree) {
208
208
  var h, i, key, len, op, value;
209
- debug("enter procEnv()");
209
+ assert(tree != null, "procEnv(): tree is undef");
210
+ debug("enter procEnv()", tree);
210
211
  for (i = 0, len = tree.length; i < len; i++) {
211
212
  h = tree[i];
213
+ debug('h', h);
212
214
  switch (h.node.type) {
213
215
  case 'assign':
214
216
  ({key, value} = h.node);
@@ -220,8 +222,8 @@ export var EnvLoader = class EnvLoader extends PLLParser {
220
222
  ({key} = h.node);
221
223
  debug(`if_truthy: '${key}'`);
222
224
  if (this.getVar(key)) {
223
- debug(`procEnv(): if_truthy('${key}') - proc body`);
224
- this.procEnv(h.body);
225
+ debug(`procEnv(): if_truthy('${key}') - proc subtree`);
226
+ this.procEnv(h.subtree);
225
227
  } else {
226
228
  debug(`procEnv(): if_truthy('${key}') - skip`);
227
229
  }
@@ -232,16 +234,16 @@ export var EnvLoader = class EnvLoader extends PLLParser {
232
234
  if (this.getVar(key)) {
233
235
  debug(`procEnv(): if_falsy('${key}') - skip`);
234
236
  } else {
235
- debug(`procEnv(): if_falsy('${key}') - proc body`);
236
- this.procEnv(h.body);
237
+ debug(`procEnv(): if_falsy('${key}') - proc subtree`);
238
+ this.procEnv(h.subtree);
237
239
  }
238
240
  break;
239
241
  case 'compare':
240
242
  ({key, op, value} = h.node);
241
243
  debug(`procEnv(key=${key}, value=${value})`);
242
244
  if (this.doCompare(key, op, value)) {
243
- debug(`procEnv(): compare('${key}','${value}') - proc body`);
244
- this.procEnv(h.body);
245
+ debug(`procEnv(): compare('${key}','${value}') - proc subtree`);
246
+ this.procEnv(h.subtree);
245
247
  } else {
246
248
  debug(`procEnv(): compare('${key}','${value}') - skip`);
247
249
  }
@@ -278,18 +280,21 @@ export var loadEnvString = function(contents, hOptions = {}, source = undef) {
278
280
  // ---------------------------------------------------------------------------
279
281
  // Load environment from a file
280
282
  export var loadEnvFile = function(filepath, hOptions = {}) {
281
- debug(`LOADENV ${filepath}`);
282
- loadEnvString(undef, hOptions, filepath);
283
+ var contents;
284
+ debug(`enter loadEnvFile ${filepath}`);
285
+ contents = slurp(filepath);
286
+ loadEnvString(contents, hOptions, filepath);
287
+ debug("return from loadEnvFile");
283
288
  };
284
289
 
285
290
  // ---------------------------------------------------------------------------
286
291
  // Load environment from .env file
287
292
  export var loadEnvFrom = function(searchDir, hOptions = {}) {
288
- var i, lPaths, len, path;
293
+ var filepath, i, lPaths, len, path;
289
294
  // --- valid options:
290
295
  // onefile - load only the first file found
291
296
  // hCallbacks - getVar, setVar, clearVar, clearAll, names
292
- debug(`enter loadEnvFrom('${searchDir}')`);
297
+ debug(`enter loadEnvFrom '${searchDir}'`);
293
298
  path = pathTo('.env', searchDir, "up");
294
299
  if (path == null) {
295
300
  debug("return from loadEnvFrom() - no .env file found");
@@ -304,9 +309,10 @@ export var loadEnvFrom = function(searchDir, hOptions = {}) {
304
309
  lPaths.unshift(path);
305
310
  }
306
311
  }
312
+ debug('lPaths', lPaths);
307
313
  for (i = 0, len = lPaths.length; i < len; i++) {
308
- path = lPaths[i];
309
- loadEnvFile(path, hOptions);
314
+ filepath = lPaths[i];
315
+ loadEnvFile(filepath, hOptions);
310
316
  }
311
317
  debug("return from loadEnvFrom()");
312
318
  return lPaths;