@dotenvx/dotenvx 1.11.1 → 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,13 @@
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.1...main)
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))
6
12
 
7
13
  ## 1.11.1
8
14
 
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" > .env
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
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.11.1",
2
+ "version": "1.11.2",
3
3
  "name": "@dotenvx/dotenvx",
4
4
  "description": "a better dotenv–from the creator of `dotenv`",
5
5
  "author": "@motdotla",
@@ -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
- logger.debug(`key: ${key}`)
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
@@ -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 src = fs.readFileSync(filepath, { encoding: ENCODING })
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