@jdeighan/env 8.0.13 → 8.0.17

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": "8.0.13",
4
+ "version": "8.0.17",
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": "^4.0.22",
35
- "@jdeighan/string-input": "^8.0.15",
34
+ "@jdeighan/coffee-utils": "^4.1.7",
35
+ "@jdeighan/string-input": "^8.0.20",
36
36
  "coffeescript": "^2.6.1",
37
37
  "cross-env": "^7.0.3"
38
38
  }
@@ -3,12 +3,12 @@
3
3
  import pathlib from 'path'
4
4
 
5
5
  import {
6
- assert, undef, pass, error, rtrim, isArray, isFunction, rtrunc, escapeStr,
6
+ assert, undef, pass, error, rtrim, isArray, isFunction,
7
+ rtrunc, escapeStr, croak,
7
8
  } from '@jdeighan/coffee-utils'
8
9
  import {log} from '@jdeighan/coffee-utils/log'
9
10
  import {debug} from '@jdeighan/coffee-utils/debug'
10
11
  import {slurp, pathTo, mkpath} from '@jdeighan/coffee-utils/fs'
11
- import {hPrivEnv, hPrivEnvCallbacks} from '@jdeighan/coffee-utils/privenv'
12
12
  import {PLLParser} from '@jdeighan/string-input'
13
13
 
14
14
  hDefCallbacks = {
@@ -276,27 +276,18 @@ export loadEnvFile = (filepath, hOptions={}) ->
276
276
  # ---------------------------------------------------------------------------
277
277
  # Load environment from .env file
278
278
 
279
- export loadEnvFrom = (searchDir, rootName='DIR_ROOT', hOptions={}) ->
279
+ export loadEnvFrom = (searchDir, hOptions={}) ->
280
280
  # --- valid options:
281
281
  # onefile - load only the first file found
282
282
  # hCallbacks - getVar, setVar, clearVar, clearAll, names
283
283
 
284
- debug "enter loadEnvFrom('#{searchDir}', rootName=#{rootName})"
284
+ debug "enter loadEnvFrom('#{searchDir}')"
285
285
  path = pathTo('.env', searchDir, "up")
286
286
  if ! path?
287
287
  debug "return from loadEnvFrom() - no .env file found"
288
288
  return
289
289
  debug "found .env file: #{path}"
290
290
 
291
- # --- Don't set root directory if it's already defined
292
- if rootName && ! process.env[rootName]
293
- root = mkpath(rtrunc(path, 5))
294
- debug "set env var #{rootName} to #{root}"
295
- if hOptions.hCallbacks
296
- hOptions.hCallbacks.setVar(rootName, root)
297
- else
298
- hDefCallbacks.setVar(rootName, root)
299
-
300
291
  lPaths = [path] # --- build an array of paths
301
292
  if ! hOptions.onefile
302
293
  # --- search upward for .env files, but process top down
@@ -310,27 +301,16 @@ export loadEnvFrom = (searchDir, rootName='DIR_ROOT', hOptions={}) ->
310
301
  return
311
302
 
312
303
  # ---------------------------------------------------------------------------
313
- # Instead of loading into process.env,
314
- # this loads into hPrivEnv from '@jdeighan/coffee-utils/privenv'
315
-
316
- export loadPrivEnvFrom = (rootDir, rootName='DIR_ROOT', hInit=undef) ->
317
-
318
- hPrivEnvCallbacks.clearAll()
319
-
320
- # --- Load any vars found in hInit
321
- if hInit?
322
- for name,value of hInit
323
- hPrivEnvCallbacks.setVar name, value
324
-
325
- if rootName
326
- hPrivEnvCallbacks.setVar rootName, rootDir
327
- loadEnvFrom(rootDir, rootName, {hCallbacks: hPrivEnvCallbacks})
328
- return
329
-
330
- # ---------------------------------------------------------------------------
304
+ # Load environment
331
305
 
332
- # --- Auto-load private environment if true env var DIR_ROOT is set
306
+ export loadEnv = (hOptions={}) ->
307
+ # --- valid options:
308
+ # onefile - load only the first file found
309
+ # hCallbacks - getVar, setVar, clearVar, clearAll, names
333
310
 
334
- if process.env.DIR_ROOT
335
- rootDir = process.env.DIR_ROOT
336
- loadPrivEnvFrom process.env.DIR_ROOT
311
+ debug "enter loadEnv()"
312
+ dir = process.env.DIR_ROOT
313
+ if dir
314
+ loadEnvFrom(dir, hOptions)
315
+ else
316
+ croak "env var DIR_ROOT not set!"
@@ -1,6 +1,6 @@
1
1
  // Generated by CoffeeScript 2.6.1
2
2
  // EnvLoaderEx.coffee
3
- var hDefCallbacks, rootDir;
3
+ var hDefCallbacks;
4
4
 
5
5
  import pathlib from 'path';
6
6
 
@@ -13,7 +13,8 @@ import {
13
13
  isArray,
14
14
  isFunction,
15
15
  rtrunc,
16
- escapeStr
16
+ escapeStr,
17
+ croak
17
18
  } from '@jdeighan/coffee-utils';
18
19
 
19
20
  import {
@@ -30,11 +31,6 @@ import {
30
31
  mkpath
31
32
  } from '@jdeighan/coffee-utils/fs';
32
33
 
33
- import {
34
- hPrivEnv,
35
- hPrivEnvCallbacks
36
- } from '@jdeighan/coffee-utils/privenv';
37
-
38
34
  import {
39
35
  PLLParser
40
36
  } from '@jdeighan/string-input';
@@ -287,28 +283,18 @@ export var loadEnvFile = function(filepath, hOptions = {}) {
287
283
 
288
284
  // ---------------------------------------------------------------------------
289
285
  // Load environment from .env file
290
- export var loadEnvFrom = function(searchDir, rootName = 'DIR_ROOT', hOptions = {}) {
291
- var i, lPaths, len, path, root;
286
+ export var loadEnvFrom = function(searchDir, hOptions = {}) {
287
+ var i, lPaths, len, path;
292
288
  // --- valid options:
293
289
  // onefile - load only the first file found
294
290
  // hCallbacks - getVar, setVar, clearVar, clearAll, names
295
- debug(`enter loadEnvFrom('${searchDir}', rootName=${rootName})`);
291
+ debug(`enter loadEnvFrom('${searchDir}')`);
296
292
  path = pathTo('.env', searchDir, "up");
297
293
  if (path == null) {
298
294
  debug("return from loadEnvFrom() - no .env file found");
299
295
  return;
300
296
  }
301
297
  debug(`found .env file: ${path}`);
302
- // --- Don't set root directory if it's already defined
303
- if (rootName && !process.env[rootName]) {
304
- root = mkpath(rtrunc(path, 5));
305
- debug(`set env var ${rootName} to ${root}`);
306
- if (hOptions.hCallbacks) {
307
- hOptions.hCallbacks.setVar(rootName, root);
308
- } else {
309
- hDefCallbacks.setVar(rootName, root);
310
- }
311
- }
312
298
  lPaths = [path]; // --- build an array of paths
313
299
  if (!hOptions.onefile) {
314
300
  // --- search upward for .env files, but process top down
@@ -325,30 +311,17 @@ export var loadEnvFrom = function(searchDir, rootName = 'DIR_ROOT', hOptions = {
325
311
  };
326
312
 
327
313
  // ---------------------------------------------------------------------------
328
- // Instead of loading into process.env,
329
- // this loads into hPrivEnv from '@jdeighan/coffee-utils/privenv'
330
- export var loadPrivEnvFrom = function(rootDir, rootName = 'DIR_ROOT', hInit = undef) {
331
- var name, value;
332
- hPrivEnvCallbacks.clearAll();
333
- // --- Load any vars found in hInit
334
- if (hInit != null) {
335
- for (name in hInit) {
336
- value = hInit[name];
337
- hPrivEnvCallbacks.setVar(name, value);
338
- }
339
- }
340
- if (rootName) {
341
- hPrivEnvCallbacks.setVar(rootName, rootDir);
314
+ // Load environment
315
+ export var loadEnv = function(hOptions = {}) {
316
+ var dir;
317
+ // --- valid options:
318
+ // onefile - load only the first file found
319
+ // hCallbacks - getVar, setVar, clearVar, clearAll, names
320
+ debug("enter loadEnv()");
321
+ dir = process.env.DIR_ROOT;
322
+ if (dir) {
323
+ return loadEnvFrom(dir, hOptions);
324
+ } else {
325
+ return croak("env var DIR_ROOT not set!");
342
326
  }
343
- loadEnvFrom(rootDir, rootName, {
344
- hCallbacks: hPrivEnvCallbacks
345
- });
346
327
  };
347
-
348
- // ---------------------------------------------------------------------------
349
-
350
- // --- Auto-load private environment if true env var DIR_ROOT is set
351
- if (process.env.DIR_ROOT) {
352
- rootDir = process.env.DIR_ROOT;
353
- loadPrivEnvFrom(process.env.DIR_ROOT);
354
- }