diff --git a/package-lock.json b/package-lock.json index 971b002fcac..f9ee02651fa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5318,7 +5318,6 @@ }, "node_modules/@parcel/watcher-wasm/node_modules/napi-wasm": { "version": "1.1.0", - "extraneous": true, "inBundle": true, "license": "MIT" }, @@ -5484,7 +5483,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "android" @@ -5497,7 +5495,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "android" @@ -5510,7 +5507,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -5523,7 +5519,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "darwin" @@ -5536,7 +5531,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -5549,7 +5543,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "freebsd" @@ -5562,7 +5555,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5575,7 +5567,6 @@ "cpu": [ "arm" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5588,7 +5579,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5601,7 +5591,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5614,7 +5603,6 @@ "cpu": [ "loong64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5627,7 +5615,6 @@ "cpu": [ "ppc64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5640,7 +5627,6 @@ "cpu": [ "riscv64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5653,7 +5639,6 @@ "cpu": [ "riscv64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5666,7 +5651,6 @@ "cpu": [ "s390x" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5679,7 +5663,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5692,7 +5675,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "linux" @@ -5705,7 +5687,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "openharmony" @@ -5718,7 +5699,6 @@ "cpu": [ "arm64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -5731,7 +5711,6 @@ "cpu": [ "ia32" ], - "dev": true, "optional": true, "os": [ "win32" @@ -5744,7 +5723,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -5757,7 +5735,6 @@ "cpu": [ "x64" ], - "dev": true, "optional": true, "os": [ "win32" @@ -12268,7 +12245,6 @@ "version": "2.3.3", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.3.tgz", "integrity": "sha512-5xoDfX+fL7faATnagmWPpbFtwh/R77WmMMqqHGS65C3vvB0YHrgF+B1YmZ3441tMj5n63k0212XNoJwzlhffQw==", - "dev": true, "hasInstallScript": true, "optional": true, "os": [ diff --git a/src/utils/dev.ts b/src/utils/dev.ts index 198037a18af..d55c4cc19c5 100644 --- a/src/utils/dev.ts +++ b/src/utils/dev.ts @@ -172,7 +172,6 @@ const getEnvSourceName = (source) => { // @ts-expect-error TS(7031) FIXME: Binding element 'devConfig' implicitly has an 'any... Remove this comment to see the full error message export const getDotEnvVariables = async ({ devConfig, env, site }): Promise => { const dotEnvFiles = await loadDotEnvFiles({ envFiles: devConfig.envFiles, projectDir: site.root }) - // @ts-expect-error TS(2339) FIXME: Property 'env' does not exist on type '{ warning: ... Remove this comment to see the full error message dotEnvFiles.forEach(({ env: fileEnv, file }) => { const newSourceName = `${file} file` diff --git a/src/utils/dot-env.ts b/src/utils/dot-env.ts index 27cebc92163..6738f270310 100644 --- a/src/utils/dot-env.ts +++ b/src/utils/dot-env.ts @@ -7,26 +7,53 @@ import { isFileAsync } from '../lib/fs.js' import { warn } from './command-helpers.js' -// @ts-expect-error TS(7031) FIXME: Binding element 'envFiles' implicitly has an 'any'... Remove this comment to see the full error message -export const loadDotEnvFiles = async function ({ envFiles, projectDir }) { +interface DotEnvFile { + file: string + env: Record +} + +interface DotEnvWarning { + warning: string +} + +type LoadedDotEnvFile = DotEnvFile | DotEnvWarning | undefined + +const isDefined = (value: T): value is NonNullable => value !== undefined && value !== null +const isWarning = (result: LoadedDotEnvFile): result is DotEnvWarning => isDefined(result) && 'warning' in result +const isDotEnvFile = (result: LoadedDotEnvFile): result is DotEnvFile => + isDefined(result) && 'file' in result && 'env' in result + +interface LoadDotEnvFilesOptions { + envFiles: string[] + projectDir: string +} + +export const loadDotEnvFiles = async function ({ + envFiles, + projectDir, +}: LoadDotEnvFilesOptions): Promise { const response = await tryLoadDotEnvFiles({ projectDir, dotenvFiles: envFiles }) - // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. - const filesWithWarning = response.filter((el) => el.warning) + const filesWithWarning = response.filter(isWarning) filesWithWarning.forEach((el) => { - // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. warn(el.warning) }) - // @ts-expect-error TS(2532) FIXME: Object is possibly 'undefined'. - return response.filter((el) => el.file && el.env) + return response.filter(isDotEnvFile) } // in the user configuration, the order is highest to lowest const defaultEnvFiles = ['.env.development.local', '.env.local', '.env.development', '.env'] -// @ts-expect-error TS(7031) FIXME: Binding element 'projectDir' implicitly has an 'an... Remove this comment to see the full error message -export const tryLoadDotEnvFiles = async ({ dotenvFiles = defaultEnvFiles, projectDir }) => { +interface TryLoadDotEnvFilesOptions { + projectDir: string + dotenvFiles?: string[] +} + +export const tryLoadDotEnvFiles = async ({ + dotenvFiles = defaultEnvFiles, + projectDir, +}: TryLoadDotEnvFilesOptions): Promise => { const results = await Promise.all( dotenvFiles.map(async (file) => { const filepath = path.resolve(projectDir, file) @@ -37,8 +64,7 @@ export const tryLoadDotEnvFiles = async ({ dotenvFiles = defaultEnvFiles, projec } } catch (error) { return { - // @ts-expect-error TS(2571) FIXME: Object is of type 'unknown'. - warning: `Failed reading env variables from file: ${filepath}: ${error.message}`, + warning: `Failed reading env variables from file: ${filepath}: ${error instanceof Error ? error.message : error}`, } } const content = await readFile(filepath, 'utf-8') @@ -48,5 +74,5 @@ export const tryLoadDotEnvFiles = async ({ dotenvFiles = defaultEnvFiles, projec ) // we return in order of lowest to highest priority - return results.filter(Boolean).reverse() + return results.filter(isDefined).reverse() }