@adonisjs/env 4.0.1-0 → 4.0.2-0

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/README.md CHANGED
@@ -141,6 +141,21 @@ env.get('NODE_ENV') // is unknown, hence a string or undefined
141
141
 
142
142
  The above code may seem like a lot of work to set up environment variables. However, you have fine-grained control over each step. In the case of AdonisJS, all this boilerplate is hidden inside the framework's application bootstrapping logic.
143
143
 
144
+ ## Known Exceptions
145
+
146
+ ### E_INVALID_ENV_VARIABLES
147
+ The exception is raised during environment variables validation exception. The exception is raised with `Validation failed for one or more environment variables` message.
148
+
149
+ You can access the detailed error messages using the `error.cause` property.
150
+
151
+ ```ts
152
+ try {
153
+ validate(envValues)
154
+ } catch (error) {
155
+ console.log(error.cause)
156
+ }
157
+ ```
158
+
144
159
  [gh-workflow-image]: https://img.shields.io/github/workflow/status/adonisjs/env/test?style=for-the-badge
145
160
  [gh-workflow-url]: https://github.com/adonisjs/env/actions/workflows/test.yml "Github action"
146
161
 
@@ -1,13 +1,12 @@
1
1
  import { fileURLToPath } from 'node:url';
2
2
  import { readFile } from 'node:fs/promises';
3
3
  import { isAbsolute, join } from 'node:path';
4
- import { MissingEnvPathFileException } from './exceptions/missing_env_path_file.js';
5
4
  export class EnvLoader {
6
5
  #appRoot;
7
6
  constructor(appRoot) {
8
7
  this.#appRoot = typeof appRoot === 'string' ? appRoot : fileURLToPath(appRoot);
9
8
  }
10
- async #loadFile(filePath, optional = true) {
9
+ async #loadFile(filePath) {
11
10
  try {
12
11
  return await readFile(filePath, 'utf-8');
13
12
  }
@@ -15,12 +14,7 @@ export class EnvLoader {
15
14
  if (error.code !== 'ENOENT') {
16
15
  throw error;
17
16
  }
18
- if (optional) {
19
- return '';
20
- }
21
- throw new MissingEnvPathFileException(`Cannot find env file from "ENV_PATH"`, {
22
- cause: error,
23
- });
17
+ return '';
24
18
  }
25
19
  }
26
20
  async load() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adonisjs/env",
3
- "version": "4.0.1-0",
3
+ "version": "4.0.2-0",
4
4
  "description": "Environment variable manager for Node.js",
5
5
  "main": "build/index.js",
6
6
  "type": "module",
@@ -14,7 +14,7 @@
14
14
  },
15
15
  "scripts": {
16
16
  "pretest": "npm run lint",
17
- "test": "npm run vscode:test",
17
+ "test": "c8 npm run vscode:test",
18
18
  "clean": "del-cli build",
19
19
  "compile": "npm run lint && npm run clean && tsc",
20
20
  "build": "npm run compile",
@@ -41,9 +41,10 @@
41
41
  "@japa/runner": "^2.2.2",
42
42
  "@japa/spec-reporter": "^1.3.2",
43
43
  "@poppinss/dev-utils": "^2.0.3",
44
- "@swc/core": "^1.3.9",
44
+ "@swc/core": "^1.3.14",
45
45
  "@types/fs-extra": "^9.0.13",
46
46
  "@types/node": "^18.11.0",
47
+ "c8": "^7.12.0",
47
48
  "del-cli": "^5.0.0",
48
49
  "eslint": "^8.25.0",
49
50
  "eslint-config-prettier": "^8.5.0",
@@ -114,5 +115,14 @@
114
115
  "tag": "next",
115
116
  "branch": "main",
116
117
  "anyBranch": false
118
+ },
119
+ "c8": {
120
+ "reporter": [
121
+ "text",
122
+ "html"
123
+ ],
124
+ "exclude": [
125
+ "tests/**"
126
+ ]
117
127
  }
118
128
  }
@@ -1,5 +0,0 @@
1
- import { Exception } from '@poppinss/utils';
2
- export declare class MissingEnvPathFileException extends Exception {
3
- static status: number;
4
- static code: string;
5
- }
@@ -1,5 +0,0 @@
1
- import { Exception } from '@poppinss/utils';
2
- export class MissingEnvPathFileException extends Exception {
3
- static status = 500;
4
- static code = 'E_MISSING_ENV_PATH_FILE';
5
- }