Skip to content

Commit

Permalink
fix(dotenv-flow): block the ability to import "dotenv-flow/config"
Browse files Browse the repository at this point in the history
Given that `dotenv-flow/config` is not a module but an executable script, it doesn't work when importing (as an ESM or from within TS).

This CR changes the `package.json`'s `"exports"` field declaration blocking the ability to `import "dotenv-flow/config"` to avoid the above confusion.
  • Loading branch information
kerimdzhanov committed Sep 20, 2023
1 parent 2450aed commit a1a8996
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,29 @@ require('dotenv-flow').config();

It will allow you to configure and use **dotenv-flow** from your code programmatically.

If you're using TypeScript or ES Modules:

```ts
import dotenvFlow from 'dotenv-flow';
dotenvFlow.config();
```

Alternatively, you can use the default config entry point that allows you to configure **dotenv-flow** using command switch flags or predefined environment variables:

```js
require('dotenv-flow/config');
```

Or, you may want **dotenv-flow** to load environment variables for your app without adding it to the code via Node's `--require` flag, for example:
Or even make **dotenv-flow** load environment variables for your app without adding it to the code using preload technique:

```sh
$ node -r "dotenv-flow/config" your_app.js
```

If you're using TypeScript (or ES6+ modules), to import the default config entry point (and configure **dotenv-flow** via CLI switches or env vars):

```ts
import 'dotenv-flow/config';
```

Or, to use/configure it programmatically:
It works with `ts-node` as well:

```ts
import dotenvFlow from 'dotenv-flow';
dotenvFlow.config();
```sh
$ ts-node -r "dotenv-flow/config" your_app.ts
```

### How it works
Expand Down Expand Up @@ -299,8 +299,8 @@ Then at every place `.env` is mentioned in the docs, read it as: "`.env.defaults
## `dotenv-flow/config` options

The following configuration options can be used when:
a) preloading **dotenv-flow** using Node's `-r` (`[ts-]node --require`) switch, or…
b) `import`ing the `dotenv-flow/config` entry point.
- a) preloading **dotenv-flow** using Node's `-r` (`[ts-]node --require`) switch, or…
- b) `require`ing the `dotenv-flow/config` entry point (using `require('dotenv-flow/config');`).

### Environment variables

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
"types": "lib/dotenv-flow.d.ts",
"exports": {
".": "./lib/dotenv-flow.js",
"./config": "./config.js",
"./config": {
"require": "./config.js"
},
"./package.json": "./package.json"
},
"files": [
Expand Down

0 comments on commit a1a8996

Please sign in to comment.