@karmaniverous/get-dotenv 0.3.0 → 0.3.1

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
@@ -69,6 +69,8 @@ dotenv files. You can:
69
69
  * Specify a default environment, override the default with an existing
70
70
  environment variable, and override both with a direct setting.
71
71
  * Exclude public or private variables.
72
+ * Define dynamic variables progressively in terms of other variables and
73
+ other logic.
72
74
  * Execute a shell command after loading variables.
73
75
  * Place the shell command inside the invocation to support npm script
74
76
  arguments for other options.
@@ -82,6 +84,7 @@ Options:
82
84
  -v, --variable <string> environment from variable
83
85
  -r, --exclude-private exclude private variables (default: false)
84
86
  -u, --exclude-public exclude public variables (default: false)
87
+ -y, --dynamic-path <string> dynamic variables path
85
88
  -c, --command <string> shell command string
86
89
  -l, --log log extracted variables (default: false)
87
90
  -h, --help display help for command
@@ -5,7 +5,7 @@ import spawn from 'cross-spawn';
5
5
  import { parseArgsStringToArgv } from 'string-argv';
6
6
 
7
7
  // Import package exports.
8
- import { getDotenvSync } from '@karmaniverous/get-dotenv';
8
+ import { getDotenv } from '@karmaniverous/get-dotenv';
9
9
 
10
10
  // Create CLI.
11
11
  import { program } from 'commander';
@@ -25,6 +25,8 @@ program
25
25
  `* Specify a default environment, override the default with an existing`,
26
26
  ` environment variable, and override both with a direct setting.`,
27
27
  `* Exclude public or private variables.`,
28
+ `* Define dynamic variables progressively in terms of other variables and`,
29
+ ` other logic.`,
28
30
  `* Execute a shell command after loading variables.`,
29
31
  `* Place the shell command inside the invocation to support npm script`,
30
32
  ` arguments for other options.`,
@@ -50,6 +52,7 @@ program
50
52
  .option('-v, --variable <string>', 'environment from variable')
51
53
  .option('-r, --exclude-private', 'exclude private variables (default: false)')
52
54
  .option('-u, --exclude-public', 'exclude public variables (default: false)')
55
+ .option('-y, --dynamic-path <string>', 'dynamic variables path')
53
56
  .option('-c, --command <string>', 'shell command string')
54
57
  .option('-l, --log', 'log extracted variables (default: false)');
55
58
 
@@ -62,6 +65,7 @@ const {
62
65
  environment,
63
66
  excludePrivate,
64
67
  excludePublic,
68
+ dynamicPath,
65
69
  log,
66
70
  paths,
67
71
  privateToken,
@@ -74,12 +78,13 @@ if (command && program.args.length) program.error('command specified twice');
74
78
  const env = environment ?? process.env[variable] ?? defaultEnvironment;
75
79
 
76
80
  // Load dotenvs.
77
- getDotenvSync({
81
+ await getDotenv({
78
82
  dotenvToken,
79
83
  env,
80
84
  excludePrivate,
81
85
  excludePublic,
82
86
  loadProcess: true,
87
+ dynamicPath,
83
88
  log,
84
89
  paths,
85
90
  privateToken,
@@ -7,9 +7,12 @@ exports.getDotenvSync = exports.getDotenv = void 0;
7
7
  var _path = _interopRequireDefault(require("path"));
8
8
  var _dotenvExpand = require("dotenv-expand");
9
9
  var _readDotenv = require("../readDotEnv/readDotenv.js");
10
+ var _url = require("url");
10
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
12
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
12
13
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
14
+ const _dirname = (0, _url.fileURLToPath)(new _url.URL('.', import.meta.url));
15
+
13
16
  /**
14
17
  * get-dotenv options type
15
18
  *
@@ -65,7 +68,7 @@ const getDotenv = async function () {
65
68
  if (dynamicPath) {
66
69
  const {
67
70
  default: dynamic
68
- } = await Promise.resolve(`${dynamicPath}`).then(s => _interopRequireWildcard(require(s)));
71
+ } = await Promise.resolve(`${_path.default.relative(_dirname, dynamicPath).replace(/\\/g, '/')}`).then(s => _interopRequireWildcard(require(s)));
69
72
  Object.keys(dynamic).forEach(key => {
70
73
  Object.assign(dotenv, {
71
74
  [key]: dynamic[key](dotenv)
@@ -1,6 +1,8 @@
1
1
  import path from 'path';
2
2
  import { expand } from 'dotenv-expand';
3
3
  import { readDotenv, readDotenvSync } from '../readDotEnv/readDotenv.js';
4
+ import { URL, fileURLToPath } from 'url';
5
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
4
6
 
5
7
  /**
6
8
  * get-dotenv options type
@@ -71,7 +73,9 @@ export const getDotenv = async ({
71
73
 
72
74
  // Process dynamic variables.
73
75
  if (dynamicPath) {
74
- const { default: dynamic } = await import(dynamicPath);
76
+ const { default: dynamic } = await import(
77
+ path.relative(__dirname, dynamicPath).replace(/\\/g, '/')
78
+ );
75
79
 
76
80
  Object.keys(dynamic).forEach((key) => {
77
81
  Object.assign(dotenv, { [key]: dynamic[key](dotenv) });
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "bin": {
4
4
  "getdotenv": "bin/getdotenv/index.js"
5
5
  },
6
- "version": "0.3.0",
6
+ "version": "0.3.1",
7
7
  "publishConfig": {
8
8
  "access": "public"
9
9
  },