New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

dotenv-mono

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dotenv-mono - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

.eslintrc.js

13

CHANGELOG.md

@@ -5,9 +5,18 @@ # Changelog

### 0.1.1 (2022-11-10)
### [0.1.2](https://github.com/marcocesarato/dotenv-mono/compare/v0.1.1...v0.1.2) (2022-11-11)
### Features
- add cwd and depth config ([4343ac2](https://github.com/marcocesarato/dotenv-mono/commit/4343ac2320431b9ff5853d3047b1ea972a29932d))
### Bug Fixes
* default priority ([892948e](https://github.com/marcocesarato/dotenv-mono/commit/892948e2a944af98a217f888ede1fbbe1d9d9960))
- improve code compatibility ([e0f5b16](https://github.com/marcocesarato/dotenv-mono/commit/e0f5b165a1f4a16bc196f1433ac1bea9ff93599f))
### [0.1.1](https://github.com/marcocesarato/dotenv-mono/compare/v0.1.0...v0.1.1) (2022-11-10)
### Bug Fixes
- default priority ([892948e](https://github.com/marcocesarato/dotenv-mono/commit/892948e2a944af98a217f888ede1fbbe1d9d9960))
## 0.1.0 (2022-11-10)

@@ -7,6 +7,11 @@ export type Data = Record<string, any>;

priorities?: {[key: string]: number};
depth?: number;
cwd?: string;
};
export class DotEnv {
public path: string | null | undefined;
public ext: string | null | undefined;
public cwd: string | null | undefined;
public priorities?: {[key: string]: number} | null | undefined;
public extension: string | null | undefined;
public depth: number | null | undefined;
public expand: string | null | undefined;

@@ -13,0 +18,0 @@ public env: Data | null | undefined;

35

index.js

@@ -8,6 +8,8 @@ const fs = require("fs");

constructor(props = {}) {
this.env = {};
this.path = props.path;
this.expand = props.expand ?? false;
this.ext = props.extension;
this.env = {};
this.expand = props.expand || false;
this.extension = props.extension;
this.cwd = props.cwd;
this.depth = props.depth || 4;
this.setPriorities(props.priorities);

@@ -19,10 +21,12 @@ }

const ext = this.ext ? `.${this.ext}` : "";
this.priorities = {
[`.env${ext}.${this.nodeEnv}.local`]: 75,
[`.env${ext}.local`]: 50,
[`.env${ext}.${this.nodeEnv}`]: 25,
[`.env${ext}`]: 1,
...(priorities ?? {}),
};
const ext = this.extension ? `.${this.extension}` : "";
this.priorities = Object.assign(
{
[`.env${ext}.${this.nodeEnv}.local`]: 75,
[`.env${ext}.local`]: 50,
[`.env${ext}.${this.nodeEnv}`]: 25,
[`.env${ext}`]: 1,
},
priorities || {},
);

@@ -42,5 +46,5 @@ return this;

if (this.expand) {
this.env = dotenvExpand.expand(config)?.parsed ?? {};
this.env = dotenvExpand.expand(config)?.parsed || {};
} else {
this.env = config?.parsed ?? {};
this.env = config?.parsed || {};
}

@@ -60,4 +64,3 @@ }

let dotenv = null;
let directory = path.resolve(process.cwd() || "");
const maxDepth = 3;
let directory = path.resolve(this.cwd || process.cwd() || "");
const {root} = path.parse(directory);

@@ -85,3 +88,3 @@ const matcher = (cwd) => {

let match = false;
while (maxDepth ? depth < maxDepth : true) {
while (this.depth ? depth < this.depth : true) {
depth++;

@@ -88,0 +91,0 @@ const foundPath = matcher(directory);

{
"name": "dotenv-mono",
"version": "0.1.1",
"version": "0.1.2",
"main": "index.js",
"module": "index.js",
"description": "This is a package that permit to load a dotenv even from a children applications or packages of a monorepo. It contains also some additionals features like manipulations and save of the changes on the dotenv file.",
"keywords": [
"monorepo",
"dotenv",
"dotenv-expand",
"load",
"loader",
"mono",
"repo",
"changes",
"edit",
"priorities",
"env",
"environemnt",
"production",
"development",
"prod",
"dev",
"apps",
"packages"
],
"author": "Marco Cesarato <cesarato.developer@gmail.com>",

@@ -65,2 +45,7 @@ "bugs": {

},
"standard-version": {
"scripts": {
"postchangelog": "prettier -w CHANGELOG.md"
}
},
"types": "./index.d.ts",

@@ -70,3 +55,35 @@ "repository": {

"url": "git+https://github.com/marcocesarato/dotenv-mono.git"
}
},
"keywords": [
"monorepo",
"dotenv",
"dotenv-expand",
"load",
"loader",
"mono",
"repo",
"changes",
"edit",
"priorities",
"env",
"environemnt",
"local",
"test",
"production",
"development",
"prod",
"dev",
"apps",
"packages",
"nextjs",
"next.js",
"react",
"node",
"nodejs",
"node.js",
".env",
".env.local",
".env.development",
".env.production"
]
}

@@ -42,6 +42,10 @@ <div align="center">

#### Priorities
#### How it works?
This package find up, starting from the current process directory, the first file name that match the specific criterias.
##### Priorities
This package find up, starting from the current process directory, the first file, that match the best specific
filename criteria with the higher priority. The depth of the folder, starting from the current process directory,
overwrite the files upper, having a higher priority.
| Priority | File name |

@@ -54,4 +58,14 @@ | -------- | ---------------------------------------- |

They can be customized on the constructor `priorities` property, see the example below.
###### Example
```text
├── .env | PRIORITY = 1
├── app | --------------
│ ├── .env.local | PRIORITY = 150
│ ├── nextjs | --------------
│ │ ├── .env | PRIORITY = 201
```
They can be customized on the constructor `priorities` property, see the example below on the [usage](#change-priorities) section.
## 📖 Install

@@ -65,2 +79,26 @@

### Install on Next.js
For custom advanced configuration of Next.js, you can create a `next.config.js` or `next.config.mjs` file in the root of
your project directory (next to `package.json`).
Add these lines at the top of the file:
```js
// Load dotenv-mono
const {dotenvLoad} = require("dotenv-mono");
dotenvLoad();
/* other */
/**
* @type {import('next').NextConfig}
*/
const nextConfig = {
/* config options here */
};
module.exports = nextConfig;
```
## 💻 Usage

@@ -124,5 +162,21 @@

## 💡 Methods
> Work in progress...
### Config
| Setting | Description | Default |
| ------------ | -------------------------------------------------------------------------------------------- | ----------------------------- |
| `expand` | Enable or disable [`dotenv-expand`](https://www.npmjs.com/package/dotenv-expand) plugin | `true` |
| `priorities` | Set the criteria of the filename priority to load as dotenv file | See [Priorities](#priorities) |
| `depth` | Set max depth of folder to search up from the children directory | `4` |
| `cwd` | Set the current working directory | |
| `path` | Set the file to load | |
| `extension` | Used to load specific dotenv file used only on specific apps/packages (ex. `.env.server...`) | |
## 🤔 How to contribute
Have an idea? Found a bug? Please raise to [ISSUES](https://github.com/marcocesarato/dotenv-mono/issues) or [PULL REQUEST](https://github.com/marcocesarato/dotenv-mono/pulls).
Have an idea? Found a bug? Please raise to [ISSUES](https://github.com/marcocesarato/dotenv-mono/issues)
or [PULL REQUEST](https://github.com/marcocesarato/dotenv-mono/pulls).
Contributions are welcome and are greatly appreciated! Every little bit helps, and credit will always be given.

@@ -129,0 +183,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc