@dotenvx/dotenvx 0.3.9 → 0.4.12
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/LICENSE +28 -0
- package/README.md +225 -246
- package/bin/dotenvx.cjs +34 -0
- package/config.cjs +1 -0
- package/config.d.ts +1 -0
- package/config.mjs +2 -0
- package/index.cjs +141 -0
- package/index.d.ts +66 -0
- package/index.mjs +3 -0
- package/lib/cli.cjs +43 -0
- package/lib/native-package.cjs +21 -0
- package/lib/platforms.cjs +18 -0
- package/lib/redactOutput.cjs +72 -0
- package/lib/redaction.cjs +64 -0
- package/lib/validateOptions.cjs +57 -0
- package/native.cjs +23 -0
- package/package.json +63 -35
- package/src/cli/dotenvx.js +0 -110
- package/src/cli/helpers.js +0 -28
- package/src/lib/main.js +0 -58
- package/src/shared/logger.js +0 -26
- package/src/shared/packageJson.js +0 -8
package/src/cli/dotenvx.js
DELETED
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const fs = require('fs')
|
|
4
|
-
const { Command } = require('commander')
|
|
5
|
-
const program = new Command()
|
|
6
|
-
|
|
7
|
-
// constants
|
|
8
|
-
const ENCODING = 'utf8'
|
|
9
|
-
|
|
10
|
-
const logger = require('./../shared/logger')
|
|
11
|
-
const helpers = require('./helpers')
|
|
12
|
-
const packageJson = require('./../shared/packageJson')
|
|
13
|
-
const main = require('./../lib/main')
|
|
14
|
-
|
|
15
|
-
// global log levels
|
|
16
|
-
program
|
|
17
|
-
.option('-l, --log-level <level>', 'set log level', 'info')
|
|
18
|
-
.option('-q, --quiet', 'sets log level to error')
|
|
19
|
-
.option('-v, --verbose', 'sets log level to verbose')
|
|
20
|
-
.option('-d, --debug', 'sets log level to debug')
|
|
21
|
-
.hook('preAction', (thisCommand, actionCommand) => {
|
|
22
|
-
const options = thisCommand.opts()
|
|
23
|
-
|
|
24
|
-
if (options.logLevel) {
|
|
25
|
-
logger.level = options.logLevel
|
|
26
|
-
logger.debug(`Setting log level to ${options.logLevel}`)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// --quiet overides --log-level. only errors will be shown
|
|
30
|
-
if (options.quiet) {
|
|
31
|
-
logger.level = 'error'
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// --verbose overrides --quiet
|
|
35
|
-
if (options.verbose) {
|
|
36
|
-
logger.level = 'verbose'
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// --debug overrides --verbose
|
|
40
|
-
if (options.debug) {
|
|
41
|
-
logger.level = 'debug'
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
// cli
|
|
46
|
-
program
|
|
47
|
-
.name(packageJson.name)
|
|
48
|
-
.description(packageJson.description)
|
|
49
|
-
.version(packageJson.version)
|
|
50
|
-
|
|
51
|
-
program.command('run')
|
|
52
|
-
.description('inject env variables into your application process')
|
|
53
|
-
.option('-f, --env-file <paths...>', 'path to your env file', '.env')
|
|
54
|
-
.option('-o, --overload', 'override existing env variables')
|
|
55
|
-
.action(function () {
|
|
56
|
-
// injecting 1 environment variable from ${options.envFile}
|
|
57
|
-
const options = this.opts()
|
|
58
|
-
logger.debug('Configuring options')
|
|
59
|
-
logger.debug(options)
|
|
60
|
-
|
|
61
|
-
// convert to array if needed
|
|
62
|
-
let optionEnvFile = options.envFile
|
|
63
|
-
if (!Array.isArray(optionEnvFile)) {
|
|
64
|
-
optionEnvFile = [optionEnvFile]
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
const env = {}
|
|
68
|
-
const readableFilepaths = new Set()
|
|
69
|
-
const populated = new Set()
|
|
70
|
-
|
|
71
|
-
for (const envFilepath of optionEnvFile) {
|
|
72
|
-
const filepath = helpers.resolvePath(envFilepath)
|
|
73
|
-
|
|
74
|
-
logger.verbose(`Loading env from ${filepath}`)
|
|
75
|
-
|
|
76
|
-
try {
|
|
77
|
-
logger.debug(`Reading env from ${filepath}`)
|
|
78
|
-
const src = fs.readFileSync(filepath, { encoding: ENCODING })
|
|
79
|
-
|
|
80
|
-
logger.debug(`Parsing env from ${filepath}`)
|
|
81
|
-
const parsed = main.parse(src)
|
|
82
|
-
|
|
83
|
-
logger.debug(`Populating env from ${filepath}`)
|
|
84
|
-
const result = main.populate(process.env, parsed, options.overload)
|
|
85
|
-
|
|
86
|
-
readableFilepaths.add(envFilepath)
|
|
87
|
-
result.populated.forEach(key => populated.add(key))
|
|
88
|
-
} catch (e) {
|
|
89
|
-
logger.warn(e)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
if (readableFilepaths.size > 0) {
|
|
94
|
-
logger.info(`Injecting ${populated.size} environment variables from ${[...readableFilepaths]}`)
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
// Extract command and arguments after '--'
|
|
98
|
-
const commandIndex = process.argv.indexOf('--')
|
|
99
|
-
if (commandIndex === -1 || commandIndex === process.argv.length - 1) {
|
|
100
|
-
logger.error('At least one argument is required after the run command, received 0.')
|
|
101
|
-
logger.error('Exiting')
|
|
102
|
-
process.exit(1)
|
|
103
|
-
} else {
|
|
104
|
-
const subCommand = process.argv.slice(commandIndex + 1)
|
|
105
|
-
|
|
106
|
-
helpers.executeCommand(subCommand, env)
|
|
107
|
-
}
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
program.parse(process.argv)
|
package/src/cli/helpers.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const { spawn } = require('child_process')
|
|
3
|
-
|
|
4
|
-
// resolve path based on current running process location
|
|
5
|
-
const resolvePath = function (filepath) {
|
|
6
|
-
return path.resolve(process.cwd(), filepath)
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
const executeCommand = function (subCommand, env) {
|
|
10
|
-
const subprocess = spawn(subCommand[0], subCommand.slice(1), {
|
|
11
|
-
stdio: 'inherit',
|
|
12
|
-
shell: true,
|
|
13
|
-
env: { ...process.env, ...env }
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
subprocess.on('close', (code) => {
|
|
17
|
-
process.exit(code)
|
|
18
|
-
})
|
|
19
|
-
|
|
20
|
-
subprocess.on('error', (_err) => {
|
|
21
|
-
process.exit(1)
|
|
22
|
-
})
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = {
|
|
26
|
-
resolvePath,
|
|
27
|
-
executeCommand
|
|
28
|
-
}
|
package/src/lib/main.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const logger = require('./../shared/logger')
|
|
2
|
-
const dotenv = require('dotenv')
|
|
3
|
-
|
|
4
|
-
const config = function (options) {
|
|
5
|
-
return dotenv.config(options)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const parse = function (src) {
|
|
9
|
-
const result = dotenv.parse(src)
|
|
10
|
-
|
|
11
|
-
logger.debug(result)
|
|
12
|
-
|
|
13
|
-
return result
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const populate = function (processEnv = {}, parsed = {}, overload = false) {
|
|
17
|
-
if (typeof parsed !== 'object') {
|
|
18
|
-
throw new Error('OBJECT_REQUIRED: Please check the parsed argument being passed to populate')
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const populated = new Set()
|
|
22
|
-
const preExisting = new Set()
|
|
23
|
-
|
|
24
|
-
// set processEnv
|
|
25
|
-
for (const key of Object.keys(parsed)) {
|
|
26
|
-
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
27
|
-
if (overload === true) {
|
|
28
|
-
processEnv[key] = parsed[key]
|
|
29
|
-
populated.add(key)
|
|
30
|
-
|
|
31
|
-
logger.verbose(`${key} set`)
|
|
32
|
-
logger.debug(`${key} set to ${parsed[key]}`)
|
|
33
|
-
} else {
|
|
34
|
-
preExisting.add(key)
|
|
35
|
-
|
|
36
|
-
logger.verbose(`${key} pre-exists`)
|
|
37
|
-
logger.debug(`${key} pre-exists as ${processEnv[key]}`)
|
|
38
|
-
}
|
|
39
|
-
} else {
|
|
40
|
-
processEnv[key] = parsed[key]
|
|
41
|
-
populated.add(key)
|
|
42
|
-
|
|
43
|
-
logger.verbose(`${key} set`)
|
|
44
|
-
logger.debug(`${key} set to ${parsed[key]}`)
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
return {
|
|
49
|
-
populated,
|
|
50
|
-
preExisting
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
module.exports = {
|
|
55
|
-
config,
|
|
56
|
-
parse,
|
|
57
|
-
populate
|
|
58
|
-
}
|
package/src/shared/logger.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const winston = require('winston')
|
|
2
|
-
|
|
3
|
-
const printf = winston.format.printf
|
|
4
|
-
const combine = winston.format.combine
|
|
5
|
-
const createLogger = winston.createLogger
|
|
6
|
-
const transports = winston.transports
|
|
7
|
-
|
|
8
|
-
const packageJson = require('./packageJson')
|
|
9
|
-
|
|
10
|
-
const dotenvxFormat = printf(({ level, message, label, timestamp }) => {
|
|
11
|
-
const formattedMessage = typeof message === 'object' ? JSON.stringify(message) : message
|
|
12
|
-
|
|
13
|
-
return `[dotenvx@${packageJson.version}][${level.toUpperCase()}] ${formattedMessage}`
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
const logger = createLogger({
|
|
17
|
-
level: 'info',
|
|
18
|
-
format: combine(
|
|
19
|
-
dotenvxFormat
|
|
20
|
-
),
|
|
21
|
-
transports: [
|
|
22
|
-
new transports.Console()
|
|
23
|
-
]
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
module.exports = logger
|