From e54f43722554517f1d84304302b40ee24dd1304e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 7 May 2024 10:32:53 +0200 Subject: [PATCH 1/6] bump deps --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7e6a88be..1aaf8f2b 100644 --- a/package.json +++ b/package.json @@ -8,12 +8,12 @@ "url": "https://github.com/supercharge/framework/issues" }, "devDependencies": { - "@supercharge/eslint-config-typescript": "~4.0.1", + "@supercharge/eslint-config-typescript": "~4.0.2", "@supercharge/tsconfig": "~7.0.0", - "@types/node": "~20.10.5", + "@types/node": "~20.12.8", "eslint": "~8.56.0", - "lerna": "~8.0.1", - "nx": "17.1.2" + "lerna": "~8.1.2", + "nx": "18.3.4" }, "engines": { "node": ">=22" From 74d6f8ecf0f4fec60d370df329d6d4849dba0e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 7 May 2024 10:33:00 +0200 Subject: [PATCH 2/6] remove dotenv dependency --- packages/core/package.json | 5 ++--- packages/env/package.json | 3 +-- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index 96755054..f7baae9d 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -21,12 +21,11 @@ "@supercharge/console": "^4.0.0-alpha.2", "@supercharge/contracts": "^4.0.0-alpha.2", "@supercharge/errors": "~2.0.1", - "@supercharge/fs": "~3.4.0", + "@supercharge/fs": "~3.4.2", "@supercharge/goodies": "~2.0.0", "@supercharge/http": "^4.0.0-alpha.2", "@supercharge/set": "~2.2.1", "@supercharge/support": "^4.0.0-alpha.2", - "dotenv": "~16.3.1", "type-fest": "~4.8.3", "youch": "~3.3.3", "youch-terminal": "~2.2.3" @@ -38,7 +37,7 @@ "mocked-env": "~1.3.5", "sinon": "~17.0.1", "supertest": "~6.3.3", - "typescript": "~5.3.3", + "typescript": "~5.4.5", "uvu": "~0.5.6" }, "engines": { diff --git a/packages/env/package.json b/packages/env/package.json index fc6f599c..a9b3509a 100644 --- a/packages/env/package.json +++ b/packages/env/package.json @@ -18,8 +18,7 @@ "dependencies": { "@supercharge/contracts": "^4.0.0-alpha.2", "@supercharge/fs": "~3.4.0", - "@supercharge/strings": "~2.0.0", - "dotenv": "~16.3.1" + "@supercharge/strings": "~2.0.0" }, "devDependencies": { "@types/lodash": "~4.14.202", From 307a942f78b010fedcf4cbc4e2241bf996ab1b93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 7 May 2024 10:33:16 +0200 Subject: [PATCH 3/6] use native node tools to load environment variables --- .../load-environment-variables.ts | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/packages/core/src/bootstrappers/load-environment-variables.ts b/packages/core/src/bootstrappers/load-environment-variables.ts index 7e85d63f..28da3f5c 100644 --- a/packages/core/src/bootstrappers/load-environment-variables.ts +++ b/packages/core/src/bootstrappers/load-environment-variables.ts @@ -1,8 +1,8 @@ import Path from 'node:path' import Fs from '@supercharge/fs' +import { parseEnv } from 'node:util' import { Str } from '@supercharge/strings' -import Dotenv, { DotenvConfigOptions } from 'dotenv' import { Application, Bootstrapper } from '@supercharge/contracts' import { EnvironmentFileError } from '../errors/environment-file-error.js' @@ -31,8 +31,8 @@ export class LoadEnvironmentVariables implements Bootstrapper { * in case the environment file does not exist, an error will be thrown. */ async loadEnvironment (): Promise { - await this.loadDefaultEnvironmentFile() await this.loadSpecificEnvironmentFile() + await this.loadDefaultEnvironmentFile() } /** @@ -42,23 +42,22 @@ export class LoadEnvironmentVariables implements Bootstrapper { const envPath = this.app.environmentFilePath() if (await Fs.notExists(envPath)) { - throw new Error(`Invalid environment file. Cannot find env file "${envPath}".`) + throw new EnvironmentFileError(`Invalid environment file. Cannot find env file "${envPath}".`) } - await this.loadEnvironmentFile( - this.app.environmentFilePath(), { override: false } - ) + await this.loadEnvironmentFile(envPath) } /** - * Load the given environment `file` content into `process.env`. + * Load the environment file from the given `path` into `process.env`. */ - async loadEnvironmentFile (path: string, options: DotenvConfigOptions): Promise { - const { error } = Dotenv.config({ path, ...options }) + async loadEnvironmentFile (envFilePath: string): Promise { + const content = await Fs.content(envFilePath) + const environmentVariables = parseEnv(content) - if (error) { - throw new EnvironmentFileError(`Failed to load environment file "${path}"`, { cause: error }) - } + Object.entries(environmentVariables).forEach(([key, value]) => { + process.env[key] = value + }) } /** @@ -77,7 +76,7 @@ export class LoadEnvironmentVariables implements Bootstrapper { : this.app.resolveFromBasePath(this.app.environmentPath(), `.env.${env}`) if (await Fs.exists(envFilePath)) { - await this.loadEnvironmentFile(envFilePath, { override: true }) + await this.loadEnvironmentFile(envFilePath) } } } From d5926a47a6a717a3688d3aec924ba10d7a9bb999 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 7 May 2024 10:38:15 +0200 Subject: [PATCH 4/6] remove mocked-env dependency --- packages/core/package.json | 1 - packages/core/test/http-kernel.js | 5 ----- 2 files changed, 6 deletions(-) diff --git a/packages/core/package.json b/packages/core/package.json index f7baae9d..def53d2b 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -34,7 +34,6 @@ "@supercharge/view": "^4.0.0-alpha.2", "c8": "~8.0.1", "expect": "~29.7.0", - "mocked-env": "~1.3.5", "sinon": "~17.0.1", "supertest": "~6.3.3", "typescript": "~5.4.5", diff --git a/packages/core/test/http-kernel.js b/packages/core/test/http-kernel.js index f164eca8..69f48b36 100644 --- a/packages/core/test/http-kernel.js +++ b/packages/core/test/http-kernel.js @@ -4,7 +4,6 @@ import { test } from 'uvu' import Path from 'node:path' import { expect } from 'expect' import Supertest from 'supertest' -import MockedEnv from 'mocked-env' import { fileURLToPath } from 'node:url' import { Server } from '@supercharge/http' import { HttpKernel, Application, ErrorHandler } from '../dist/index.js' @@ -67,8 +66,6 @@ test('fails to bootstrap the HTTP kernel when missing a .env file', async () => }) test('loads specific environment from .env.testing file because of NODE_ENV=testing', async () => { - const restoreEnv = MockedEnv({ restore: true }) - const env = app.env().get('NODE_ENV') app.env().set('NODE_ENV', 'testing') @@ -78,8 +75,6 @@ test('loads specific environment from .env.testing file because of NODE_ENV=test expect(app.env().get('OVERWRITE')).toEqual('1') app.env().set('NODE_ENV', env) - - restoreEnv() }) test('registers and calls booted callbacks', async () => { From d0ee05326985c2082569f61eb89f50986b55939b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Tue, 7 May 2024 10:38:29 +0200 Subject: [PATCH 5/6] load env-specific .env file last --- packages/core/src/bootstrappers/load-environment-variables.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/bootstrappers/load-environment-variables.ts b/packages/core/src/bootstrappers/load-environment-variables.ts index 28da3f5c..f0748b51 100644 --- a/packages/core/src/bootstrappers/load-environment-variables.ts +++ b/packages/core/src/bootstrappers/load-environment-variables.ts @@ -31,8 +31,8 @@ export class LoadEnvironmentVariables implements Bootstrapper { * in case the environment file does not exist, an error will be thrown. */ async loadEnvironment (): Promise { - await this.loadSpecificEnvironmentFile() await this.loadDefaultEnvironmentFile() + await this.loadSpecificEnvironmentFile() } /** From 406be596da98f12f283df0e1849a11b767fef9c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6hls?= Date: Wed, 8 May 2024 13:32:41 +0200 Subject: [PATCH 6/6] disable npm cache --- .github/workflows/run-tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index b53ce02b..e93be144 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -32,8 +32,8 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node-version }} - cache: 'npm' - cache-dependency-path: '**/package.json' + # cache: 'npm' + # cache-dependency-path: '**/package.json' - name: Install dependencies run: npm install