@dotenvx/dotenvx 1.11.0 → 1.11.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/CHANGELOG.md
CHANGED
|
@@ -2,7 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
-
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.11.
|
|
5
|
+
## [Unreleased](https://github.com/dotenvx/dotenvx/compare/v1.11.2...main)
|
|
6
|
+
|
|
7
|
+
## 1.11.2
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* detect encoding when reading `.env*` file on `run/get` ([#359](https://github.com/dotenvx/dotenvx/pull/359))
|
|
12
|
+
|
|
13
|
+
## 1.11.1
|
|
14
|
+
|
|
15
|
+
### Changed
|
|
16
|
+
|
|
17
|
+
* support encryption of `export KEY` variables and preserve `#!shebangs` ([#357](https://github.com/dotenvx/dotenvx/pull/357))
|
|
6
18
|
|
|
7
19
|
## 1.11.0
|
|
8
20
|
|
package/README.md
CHANGED
|
@@ -256,7 +256,7 @@ More examples
|
|
|
256
256
|
```sh
|
|
257
257
|
$ dotnet new console -n HelloWorld -o HelloWorld
|
|
258
258
|
$ cd HelloWorld
|
|
259
|
-
$ echo "HELLO=World"
|
|
259
|
+
$ echo "HELLO=World" | Out-File -FilePath .env -Encoding utf8
|
|
260
260
|
$ echo 'Console.WriteLine($"Hello {Environment.GetEnvironmentVariable("HELLO")}");' > Program.cs
|
|
261
261
|
|
|
262
262
|
$ dotenvx run -- dotnet run
|
package/package.json
CHANGED
package/src/cli/actions/get.js
CHANGED
|
@@ -5,7 +5,9 @@ const conventions = require('./../../lib/helpers/conventions')
|
|
|
5
5
|
const main = require('./../../lib/main')
|
|
6
6
|
|
|
7
7
|
function get (key) {
|
|
8
|
-
|
|
8
|
+
if (key) {
|
|
9
|
+
logger.debug(`key: ${key}`)
|
|
10
|
+
}
|
|
9
11
|
|
|
10
12
|
const options = this.opts()
|
|
11
13
|
logger.debug(`options: ${JSON.stringify(options)}`)
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
function detectEncoding (filepath) {
|
|
4
|
+
const buffer = fs.readFileSync(filepath)
|
|
5
|
+
|
|
6
|
+
// check for UTF-16LE BOM (Byte Order Mark)
|
|
7
|
+
if (buffer.length >= 2 && buffer[0] === 0xFF && buffer[1] === 0xFE) {
|
|
8
|
+
return 'utf16le'
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/* c8 ignore start */
|
|
12
|
+
// check for UTF-8 BOM
|
|
13
|
+
if (buffer.length >= 3 && buffer[0] === 0xEF && buffer[1] === 0xBB && buffer[2] === 0xBF) {
|
|
14
|
+
return 'utf8'
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Check if the file is entirely US-ASCII (0x00 - 0x7F), which is valid UTF-8
|
|
18
|
+
for (let i = 0; i < buffer.length; i++) {
|
|
19
|
+
if (buffer[i] > 0x7F) {
|
|
20
|
+
break
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/* c8 ignore stop */
|
|
24
|
+
|
|
25
|
+
return 'utf8'
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports = detectEncoding
|
|
@@ -39,6 +39,14 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
|
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
// preserve shebang
|
|
43
|
+
const [firstLine, ...remainingLines] = envSrc.split('\n')
|
|
44
|
+
let firstLinePreserved = ''
|
|
45
|
+
if (firstLine.startsWith('#!')) {
|
|
46
|
+
firstLinePreserved = firstLine + '\n'
|
|
47
|
+
envSrc = remainingLines.join('\n')
|
|
48
|
+
}
|
|
49
|
+
|
|
42
50
|
// generate key pair
|
|
43
51
|
const { publicKey, privateKey } = keyPair(existingPrivateKey)
|
|
44
52
|
|
|
@@ -66,7 +74,7 @@ function findOrCreatePublicKey (envFilepath, envKeysFilepath) {
|
|
|
66
74
|
''
|
|
67
75
|
].join('\n')
|
|
68
76
|
|
|
69
|
-
envSrc = `${prependPublicKey}\n${envSrc}`
|
|
77
|
+
envSrc = `${firstLinePreserved}${prependPublicKey}\n${envSrc}`
|
|
70
78
|
keysSrc = keysSrc.length > 1 ? keysSrc : `${firstTimeKeysSrc}\n`
|
|
71
79
|
|
|
72
80
|
let privateKeyAdded = false
|
|
@@ -7,13 +7,15 @@ function replace (src, key, value) {
|
|
|
7
7
|
const parsed = dotenv.parse(src)
|
|
8
8
|
if (Object.prototype.hasOwnProperty.call(parsed, key)) {
|
|
9
9
|
const regex = new RegExp(
|
|
10
|
-
// Match the key at the start of a line
|
|
11
|
-
`(^|\\n)
|
|
10
|
+
// Match the key at the start of a line, following a newline, or prefaced by export
|
|
11
|
+
`(^|\\n)\\s*(export\\s+)?${key}\\s*=\\s*` +
|
|
12
|
+
// `(^|\\n)${key}\\s*=\\s*` +
|
|
12
13
|
// Non-capturing group to handle different types of quotations and unquoted values
|
|
13
14
|
'(?:' +
|
|
14
15
|
'(["\'`])' + // Match an opening quote
|
|
15
16
|
'.*?' + // Non-greedy match for any characters within quotes
|
|
16
|
-
'\\2' + // Match the corresponding closing quote
|
|
17
|
+
// '\\2' + // Match the corresponding closing quote
|
|
18
|
+
'\\3' + // Match the corresponding closing quote
|
|
17
19
|
'|' +
|
|
18
20
|
// Match unquoted values; account for escaped newlines
|
|
19
21
|
'(?:[^#\\n\\\\]|\\\\.)*' + // Use non-capturing group for any character except #, newline, or backslash, or any escaped character
|
|
@@ -21,7 +23,7 @@ function replace (src, key, value) {
|
|
|
21
23
|
'gs' // Global and dotAll mode to treat string as single line
|
|
22
24
|
)
|
|
23
25
|
|
|
24
|
-
output = src.replace(regex, `$1${formatted}`)
|
|
26
|
+
output = src.replace(regex, `$1$2${formatted}`)
|
|
25
27
|
} else {
|
|
26
28
|
// append
|
|
27
29
|
if (src.endsWith('\n')) {
|
package/src/lib/services/run.js
CHANGED
|
@@ -15,6 +15,7 @@ const parseDecryptEvalExpand = require('./../helpers/parseDecryptEvalExpand')
|
|
|
15
15
|
const parseEnvironmentFromDotenvKey = require('./../helpers/parseEnvironmentFromDotenvKey')
|
|
16
16
|
const smartDotenvPrivateKey = require('./../helpers/smartDotenvPrivateKey')
|
|
17
17
|
const guessPrivateKeyFilename = require('./../helpers/guessPrivateKeyFilename')
|
|
18
|
+
const detectEncoding = require('./../helpers/detectEncoding')
|
|
18
19
|
|
|
19
20
|
class Run {
|
|
20
21
|
constructor (envs = [], overload = false, DOTENV_KEY = '', processEnv = process.env) {
|
|
@@ -89,7 +90,8 @@ class Run {
|
|
|
89
90
|
|
|
90
91
|
const filepath = path.resolve(envFilepath)
|
|
91
92
|
try {
|
|
92
|
-
const
|
|
93
|
+
const encoding = detectEncoding(filepath)
|
|
94
|
+
const src = fs.readFileSync(filepath, { encoding })
|
|
93
95
|
this.readableFilepaths.add(envFilepath)
|
|
94
96
|
|
|
95
97
|
// if DOTENV_PRIVATE_KEY_* already set in process.env then use it
|