@prisma-next/config-loader
Advanced tools
| import { PrismaNextConfig, PrismaNextConfig as PrismaNextConfig$1 } from "@prisma-next/config/config-types"; | ||
| //#region src/errors.d.ts | ||
| declare class ConfigFileNotFoundError extends Error { | ||
| readonly configPath?: string; | ||
| readonly why?: string; | ||
| constructor(configPath?: string, why?: string); | ||
| } | ||
| //#endregion | ||
| //#region src/finalize-config.d.ts | ||
@@ -23,3 +16,3 @@ declare function finalizeConfig(config: PrismaNextConfig$1, configDir: string): PrismaNextConfig$1; | ||
| //#endregion | ||
| export { ConfigFileNotFoundError, type PrismaNextConfig, finalizeConfig, findNearestConfigPathForFile, loadConfig, loadConfigForFile }; | ||
| export { type PrismaNextConfig, finalizeConfig, findNearestConfigPathForFile, loadConfig, loadConfigForFile }; | ||
| //# sourceMappingURL=index.d.mts.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/errors.ts","../../src/finalize-config.ts","../../src/load.ts"],"mappings":";;cAAa,gCAAgC;WAClC;WACA;cAEG,qBAAqB;;;;iBCiBnB,eAAe,QAAQ,oBAAkB,oBAAoB;;;iBC0BvD,6BAA6B,mBAAmB;;;;;;;iBAoGhD,WAAW,sBAAsB,QAAQ;iBAQzC,kBAAkB,mBAAmB,QAAQ"} | ||
| {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/finalize-config.ts","../../src/load.ts"],"mappings":";;iBAqBgB,eAAe,QAAQ,oBAAkB,oBAAoB;;;iBC2BvD,6BAA6B,mBAAmB;;;;;;;iBAqGhD,WAAW,sBAAsB,QAAQ;iBAQzC,kBAAkB,mBAAmB,QAAQ"} |
+12
-21
| import { normalizeContractConfig } from "@prisma-next/config/config-types"; | ||
| import { dirname, join, resolve } from "pathe"; | ||
| import { access } from "node:fs/promises"; | ||
| import { ConfigValidationError, validateConfig } from "@prisma-next/config/config-validation"; | ||
| import { validateConfig } from "@prisma-next/config/config-validation"; | ||
| import { getEmittedArtifactPaths } from "@prisma-next/emitter"; | ||
| import { errorConfigFileNotFound, errorConfigValidation, errorUnexpected } from "@prisma-next/errors/control"; | ||
| import { CliStructuredError, errorConfigFileNotFound, errorConfigValidation, errorUnexpected } from "@prisma-next/errors/control"; | ||
| import { ifDefined } from "@prisma-next/utils/defined"; | ||
| //#region src/errors.ts | ||
| var ConfigFileNotFoundError = class extends Error { | ||
| configPath; | ||
| why; | ||
| constructor(configPath, why) { | ||
| super(why ?? (configPath ? `Config file not found: ${configPath}` : "Config file not found")); | ||
| this.name = "ConfigFileNotFoundError"; | ||
| if (configPath !== void 0) this.configPath = configPath; | ||
| if (why !== void 0) this.why = why; | ||
| } | ||
| }; | ||
| //#endregion | ||
| import { isStructuredError, structuredError } from "@prisma-next/utils/structured-error"; | ||
| //#region src/finalize-config.ts | ||
@@ -47,3 +36,6 @@ function finalizeContractSource(source, configDir) { | ||
| function throwValidation(field, why) { | ||
| throw new ConfigValidationError(field, why); | ||
| throw structuredError("CONFIG.VALIDATION_FAILED", why, { | ||
| why, | ||
| meta: { field } | ||
| }); | ||
| } | ||
@@ -88,4 +80,4 @@ function validateNoOutputsAreInputs(inputs, output) { | ||
| }); | ||
| if (resolvedConfigPath && result.configFile !== resolvedConfigPath) throw new ConfigFileNotFoundError(resolvedConfigPath); | ||
| if (!result.config || Object.keys(result.config).length === 0) throw new ConfigFileNotFoundError(result.configFile || resolvedConfigPath || configPath); | ||
| if (resolvedConfigPath && result.configFile !== resolvedConfigPath) throw errorConfigFileNotFound(resolvedConfigPath); | ||
| if (!result.config || Object.keys(result.config).length === 0) throw errorConfigFileNotFound(result.configFile || resolvedConfigPath || configPath); | ||
| validateConfig(result.config); | ||
@@ -102,4 +94,3 @@ /* v8 ignore next -- @preserve */ | ||
| function toStructuredConfigError(error, configPath) { | ||
| if (error instanceof ConfigValidationError) return errorConfigValidation(error.field, { why: error.why }); | ||
| if (error instanceof ConfigFileNotFoundError) return errorConfigFileNotFound(error.configPath); | ||
| if (isStructuredError(error) && error.code === "CONFIG.VALIDATION_FAILED" && !(error instanceof CliStructuredError)) return errorConfigValidation(typeof error.meta?.["field"] === "string" ? error.meta["field"] : "config", { why: error.why ?? error.message }); | ||
| if (error instanceof Error && hasStringCode(error)) return error; | ||
@@ -127,8 +118,8 @@ if (error instanceof Error) { | ||
| const configPath = await findNearestConfigPathForFile(filePath); | ||
| if (configPath === void 0) throw toStructuredConfigError(new ConfigFileNotFoundError(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME))); | ||
| if (configPath === void 0) throw errorConfigFileNotFound(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME)); | ||
| return loadConfig(configPath); | ||
| } | ||
| //#endregion | ||
| export { ConfigFileNotFoundError, finalizeConfig, findNearestConfigPathForFile, loadConfig, loadConfigForFile }; | ||
| export { finalizeConfig, findNearestConfigPathForFile, loadConfig, loadConfigForFile }; | ||
| //# sourceMappingURL=index.mjs.map |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"index.mjs","names":[],"sources":["../../src/errors.ts","../../src/finalize-config.ts","../../src/load.ts"],"sourcesContent":["export class ConfigFileNotFoundError extends Error {\n readonly configPath?: string;\n readonly why?: string;\n\n constructor(configPath?: string, why?: string) {\n super(why ?? (configPath ? `Config file not found: ${configPath}` : 'Config file not found'));\n this.name = 'ConfigFileNotFoundError';\n if (configPath !== undefined) {\n this.configPath = configPath;\n }\n if (why !== undefined) {\n this.why = why;\n }\n }\n}\n","import type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { normalizeContractConfig } from '@prisma-next/config/config-types';\nimport { resolve } from 'pathe';\n\ntype ContractSourceProvider = NonNullable<PrismaNextConfig['contract']>['source'];\n\nfunction finalizeContractSource(\n source: ContractSourceProvider,\n configDir: string,\n): ContractSourceProvider {\n const resolvedInputs = source.inputs?.map((input) => resolve(configDir, input));\n if (resolvedInputs === undefined) {\n return source;\n }\n\n return {\n ...source,\n inputs: resolvedInputs,\n };\n}\n\nexport function finalizeConfig(config: PrismaNextConfig, configDir: string): PrismaNextConfig {\n if (!config.contract) {\n return config;\n }\n const contract = normalizeContractConfig(config.contract);\n const source = finalizeContractSource(contract.source, configDir);\n const output = resolve(configDir, contract.output);\n\n return {\n ...config,\n contract: {\n ...contract,\n source,\n output,\n },\n };\n}\n","import { access } from 'node:fs/promises';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { ConfigValidationError, validateConfig } from '@prisma-next/config/config-validation';\nimport { getEmittedArtifactPaths } from '@prisma-next/emitter';\nimport {\n errorConfigFileNotFound,\n errorConfigValidation,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { dirname, join, resolve } from 'pathe';\nimport { ConfigFileNotFoundError } from './errors';\nimport { finalizeConfig } from './finalize-config';\n\nconst CONFIG_FILENAME = 'prisma-next.config.ts';\n\nfunction throwValidation(field: string, why: string): never {\n throw new ConfigValidationError(field, why);\n}\n\nfunction validateNoOutputsAreInputs(\n inputs: readonly string[] | undefined,\n output: string | undefined,\n): void {\n if (inputs === undefined || output === undefined) {\n return;\n }\n\n let emittedArtifactPaths: ReturnType<typeof getEmittedArtifactPaths>;\n try {\n emittedArtifactPaths = getEmittedArtifactPaths(output);\n } catch (error) {\n throwValidation('contract.output', error instanceof Error ? error.message : String(error));\n }\n\n const emittedPaths = new Set([emittedArtifactPaths.jsonPath, emittedArtifactPaths.dtsPath]);\n\n for (const input of inputs) {\n if (emittedPaths.has(input)) {\n throwValidation(\n 'contract.source.inputs[]',\n 'Config.contract.source.inputs must not include emitted artifact paths derived from contract.output',\n );\n }\n }\n}\n\nexport async function findNearestConfigPathForFile(filePath: string): Promise<string | undefined> {\n let current = dirname(resolve(process.cwd(), filePath));\n\n while (true) {\n const candidate = join(current, CONFIG_FILENAME);\n if (await fileExists(candidate)) {\n return candidate;\n }\n const parent = dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n}\n\nasync function fileExists(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function discoverAndFinalizeConfig(configPath?: string): Promise<PrismaNextConfig> {\n const cwd = process.cwd();\n const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined;\n const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;\n\n const c12 = await import('c12');\n const result = await c12.loadConfig<PrismaNextConfig>({\n name: 'prisma-next',\n ...ifDefined('configFile', resolvedConfigPath),\n cwd: configCwd,\n });\n\n if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {\n throw new ConfigFileNotFoundError(resolvedConfigPath);\n }\n\n if (!result.config || Object.keys(result.config).length === 0) {\n /* v8 ignore next -- @preserve */\n const displayPath = result.configFile || resolvedConfigPath || configPath;\n throw new ConfigFileNotFoundError(displayPath);\n }\n\n validateConfig(result.config);\n\n /* v8 ignore next -- @preserve */\n const loadedConfigDir = result.configFile ? dirname(result.configFile) : configCwd;\n const config = finalizeConfig(result.config, loadedConfigDir);\n validateNoOutputsAreInputs(config.contract?.source.inputs, config.contract?.output);\n return config;\n}\n\nfunction hasStringCode(error: Error): error is Error & { readonly code: string } {\n return 'code' in error && typeof error.code === 'string';\n}\n\n// Exported for direct unit coverage; not part of the public surface.\nexport function toStructuredConfigError(error: unknown, configPath?: string): Error {\n if (error instanceof ConfigValidationError) {\n return errorConfigValidation(error.field, {\n why: error.why,\n });\n }\n\n if (error instanceof ConfigFileNotFoundError) {\n return errorConfigFileNotFound(error.configPath);\n }\n\n if (error instanceof Error && hasStringCode(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n if (\n error.message.includes('not found') ||\n error.message.includes('Cannot find') ||\n error.message.includes('ENOENT')\n ) {\n const displayPath = configPath ? resolve(process.cwd(), configPath) : undefined;\n return errorConfigFileNotFound(displayPath, {\n why: error.message,\n });\n }\n return errorUnexpected(error.message, {\n why: `Failed to load config: ${error.message}`,\n });\n }\n return errorUnexpected(String(error));\n}\n\n/**\n * Loads, validates, and finalizes the Prisma Next config, mapping every failure\n * to a structured `@prisma-next/errors/control` error (`CliStructuredError`).\n * This is the sole public entry point: callers that need to degrade gracefully\n * (e.g. the language server) branch on the structured error's stable `.code`.\n */\nexport async function loadConfig(configPath?: string): Promise<PrismaNextConfig> {\n try {\n return await discoverAndFinalizeConfig(configPath);\n } catch (error) {\n throw toStructuredConfigError(error, configPath);\n }\n}\n\nexport async function loadConfigForFile(filePath: string): Promise<PrismaNextConfig> {\n const configPath = await findNearestConfigPathForFile(filePath);\n if (configPath === undefined) {\n throw toStructuredConfigError(\n new ConfigFileNotFoundError(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME)),\n );\n }\n return loadConfig(configPath);\n}\n"],"mappings":";;;;;;;;AAAA,IAAa,0BAAb,cAA6C,MAAM;CACjD;CACA;CAEA,YAAY,YAAqB,KAAc;EAC7C,MAAM,QAAQ,aAAa,0BAA0B,eAAe,wBAAwB;EAC5F,KAAK,OAAO;EACZ,IAAI,eAAe,KAAA,GACjB,KAAK,aAAa;EAEpB,IAAI,QAAQ,KAAA,GACV,KAAK,MAAM;CAEf;AACF;;;ACRA,SAAS,uBACP,QACA,WACwB;CACxB,MAAM,iBAAiB,OAAO,QAAQ,KAAK,UAAU,QAAQ,WAAW,KAAK,CAAC;CAC9E,IAAI,mBAAmB,KAAA,GACrB,OAAO;CAGT,OAAO;EACL,GAAG;EACH,QAAQ;CACV;AACF;AAEA,SAAgB,eAAe,QAA0B,WAAqC;CAC5F,IAAI,CAAC,OAAO,UACV,OAAO;CAET,MAAM,WAAW,wBAAwB,OAAO,QAAQ;CACxD,MAAM,SAAS,uBAAuB,SAAS,QAAQ,SAAS;CAChE,MAAM,SAAS,QAAQ,WAAW,SAAS,MAAM;CAEjD,OAAO;EACL,GAAG;EACH,UAAU;GACR,GAAG;GACH;GACA;EACF;CACF;AACF;;;ACvBA,MAAM,kBAAkB;AAExB,SAAS,gBAAgB,OAAe,KAAoB;CAC1D,MAAM,IAAI,sBAAsB,OAAO,GAAG;AAC5C;AAEA,SAAS,2BACP,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":"index.mjs","names":[],"sources":["../../src/finalize-config.ts","../../src/load.ts"],"sourcesContent":["import type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { normalizeContractConfig } from '@prisma-next/config/config-types';\nimport { resolve } from 'pathe';\n\ntype ContractSourceProvider = NonNullable<PrismaNextConfig['contract']>['source'];\n\nfunction finalizeContractSource(\n source: ContractSourceProvider,\n configDir: string,\n): ContractSourceProvider {\n const resolvedInputs = source.inputs?.map((input) => resolve(configDir, input));\n if (resolvedInputs === undefined) {\n return source;\n }\n\n return {\n ...source,\n inputs: resolvedInputs,\n };\n}\n\nexport function finalizeConfig(config: PrismaNextConfig, configDir: string): PrismaNextConfig {\n if (!config.contract) {\n return config;\n }\n const contract = normalizeContractConfig(config.contract);\n const source = finalizeContractSource(contract.source, configDir);\n const output = resolve(configDir, contract.output);\n\n return {\n ...config,\n contract: {\n ...contract,\n source,\n output,\n },\n };\n}\n","import { access } from 'node:fs/promises';\nimport type { PrismaNextConfig } from '@prisma-next/config/config-types';\nimport { validateConfig } from '@prisma-next/config/config-validation';\nimport { getEmittedArtifactPaths } from '@prisma-next/emitter';\nimport {\n CliStructuredError,\n errorConfigFileNotFound,\n errorConfigValidation,\n errorUnexpected,\n} from '@prisma-next/errors/control';\nimport { ifDefined } from '@prisma-next/utils/defined';\nimport { isStructuredError, structuredError } from '@prisma-next/utils/structured-error';\nimport { dirname, join, resolve } from 'pathe';\nimport { finalizeConfig } from './finalize-config';\n\nconst CONFIG_FILENAME = 'prisma-next.config.ts';\n\nfunction throwValidation(field: string, why: string): never {\n throw structuredError('CONFIG.VALIDATION_FAILED', why, { why, meta: { field } });\n}\n\nfunction validateNoOutputsAreInputs(\n inputs: readonly string[] | undefined,\n output: string | undefined,\n): void {\n if (inputs === undefined || output === undefined) {\n return;\n }\n\n let emittedArtifactPaths: ReturnType<typeof getEmittedArtifactPaths>;\n try {\n emittedArtifactPaths = getEmittedArtifactPaths(output);\n } catch (error) {\n throwValidation('contract.output', error instanceof Error ? error.message : String(error));\n }\n\n const emittedPaths = new Set([emittedArtifactPaths.jsonPath, emittedArtifactPaths.dtsPath]);\n\n for (const input of inputs) {\n if (emittedPaths.has(input)) {\n throwValidation(\n 'contract.source.inputs[]',\n 'Config.contract.source.inputs must not include emitted artifact paths derived from contract.output',\n );\n }\n }\n}\n\nexport async function findNearestConfigPathForFile(filePath: string): Promise<string | undefined> {\n let current = dirname(resolve(process.cwd(), filePath));\n\n while (true) {\n const candidate = join(current, CONFIG_FILENAME);\n if (await fileExists(candidate)) {\n return candidate;\n }\n const parent = dirname(current);\n if (parent === current) {\n return undefined;\n }\n current = parent;\n }\n}\n\nasync function fileExists(path: string): Promise<boolean> {\n try {\n await access(path);\n return true;\n } catch {\n return false;\n }\n}\n\nasync function discoverAndFinalizeConfig(configPath?: string): Promise<PrismaNextConfig> {\n const cwd = process.cwd();\n const resolvedConfigPath = configPath ? resolve(cwd, configPath) : undefined;\n const configCwd = resolvedConfigPath ? dirname(resolvedConfigPath) : cwd;\n\n const c12 = await import('c12');\n const result = await c12.loadConfig<PrismaNextConfig>({\n name: 'prisma-next',\n ...ifDefined('configFile', resolvedConfigPath),\n cwd: configCwd,\n });\n\n if (resolvedConfigPath && result.configFile !== resolvedConfigPath) {\n throw errorConfigFileNotFound(resolvedConfigPath);\n }\n\n if (!result.config || Object.keys(result.config).length === 0) {\n /* v8 ignore next -- @preserve */\n const displayPath = result.configFile || resolvedConfigPath || configPath;\n throw errorConfigFileNotFound(displayPath);\n }\n\n validateConfig(result.config);\n\n /* v8 ignore next -- @preserve */\n const loadedConfigDir = result.configFile ? dirname(result.configFile) : configCwd;\n const config = finalizeConfig(result.config, loadedConfigDir);\n validateNoOutputsAreInputs(config.contract?.source.inputs, config.contract?.output);\n return config;\n}\n\nfunction hasStringCode(error: Error): error is Error & { readonly code: string } {\n return 'code' in error && typeof error.code === 'string';\n}\n\n// Exported for direct unit coverage; not part of the public surface.\nexport function toStructuredConfigError(error: unknown, configPath?: string): Error {\n if (\n isStructuredError(error) &&\n error.code === 'CONFIG.VALIDATION_FAILED' &&\n !(error instanceof CliStructuredError)\n ) {\n const field = typeof error.meta?.['field'] === 'string' ? error.meta['field'] : 'config';\n return errorConfigValidation(field, {\n why: error.why ?? error.message,\n });\n }\n\n if (error instanceof Error && hasStringCode(error)) {\n return error;\n }\n\n if (error instanceof Error) {\n if (\n error.message.includes('not found') ||\n error.message.includes('Cannot find') ||\n error.message.includes('ENOENT')\n ) {\n const displayPath = configPath ? resolve(process.cwd(), configPath) : undefined;\n return errorConfigFileNotFound(displayPath, {\n why: error.message,\n });\n }\n return errorUnexpected(error.message, {\n why: `Failed to load config: ${error.message}`,\n });\n }\n return errorUnexpected(String(error));\n}\n\n/**\n * Loads, validates, and finalizes the Prisma Next config, mapping every failure\n * to a structured `@prisma-next/errors/control` error (`CliStructuredError`).\n * This is the sole public entry point: callers that need to degrade gracefully\n * (e.g. the language server) branch on the structured error's stable `.code`.\n */\nexport async function loadConfig(configPath?: string): Promise<PrismaNextConfig> {\n try {\n return await discoverAndFinalizeConfig(configPath);\n } catch (error) {\n throw toStructuredConfigError(error, configPath);\n }\n}\n\nexport async function loadConfigForFile(filePath: string): Promise<PrismaNextConfig> {\n const configPath = await findNearestConfigPathForFile(filePath);\n if (configPath === undefined) {\n throw errorConfigFileNotFound(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME));\n }\n return loadConfig(configPath);\n}\n"],"mappings":";;;;;;;;;AAMA,SAAS,uBACP,QACA,WACwB;CACxB,MAAM,iBAAiB,OAAO,QAAQ,KAAK,UAAU,QAAQ,WAAW,KAAK,CAAC;CAC9E,IAAI,mBAAmB,KAAA,GACrB,OAAO;CAGT,OAAO;EACL,GAAG;EACH,QAAQ;CACV;AACF;AAEA,SAAgB,eAAe,QAA0B,WAAqC;CAC5F,IAAI,CAAC,OAAO,UACV,OAAO;CAET,MAAM,WAAW,wBAAwB,OAAO,QAAQ;CACxD,MAAM,SAAS,uBAAuB,SAAS,QAAQ,SAA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SAAS,OAAO;EACd,MAAM,wBAAwB,OAAO,UAAU;CACjD;AACF;AAEA,eAAsB,kBAAkB,UAA6C;CACnF,MAAM,aAAa,MAAM,6BAA6B,QAAQ;CAC9D,IAAI,eAAe,KAAA,GACjB,MAAM,wBAAwB,KAAK,QAAQ,QAAQ,QAAQ,IAAI,GAAG,QAAQ,CAAC,GAAG,eAAe,CAAC;CAEhG,OAAO,WAAW,UAAU;AAC9B"} |
+8
-8
| { | ||
| "name": "@prisma-next/config-loader", | ||
| "version": "0.16.0-dev.30", | ||
| "version": "0.16.0-dev.31", | ||
| "license": "Apache-2.0", | ||
@@ -9,6 +9,6 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/config": "0.16.0-dev.30", | ||
| "@prisma-next/emitter": "0.16.0-dev.30", | ||
| "@prisma-next/errors": "0.16.0-dev.30", | ||
| "@prisma-next/utils": "0.16.0-dev.30", | ||
| "@prisma-next/config": "0.16.0-dev.31", | ||
| "@prisma-next/emitter": "0.16.0-dev.31", | ||
| "@prisma-next/errors": "0.16.0-dev.31", | ||
| "@prisma-next/utils": "0.16.0-dev.31", | ||
| "c12": "^3.3.4", | ||
@@ -18,5 +18,5 @@ "pathe": "^2.0.3" | ||
| "devDependencies": { | ||
| "@prisma-next/test-utils": "0.16.0-dev.30", | ||
| "@prisma-next/tsconfig": "0.16.0-dev.30", | ||
| "@prisma-next/tsdown": "0.16.0-dev.30", | ||
| "@prisma-next/test-utils": "0.16.0-dev.31", | ||
| "@prisma-next/tsconfig": "0.16.0-dev.31", | ||
| "@prisma-next/tsdown": "0.16.0-dev.31", | ||
| "@types/node": "25.9.4", | ||
@@ -23,0 +23,0 @@ "tsdown": "0.22.8", |
| export type { PrismaNextConfig } from '@prisma-next/config/config-types'; | ||
| export { ConfigFileNotFoundError } from '../errors'; | ||
| export { finalizeConfig } from '../finalize-config'; | ||
| export { findNearestConfigPathForFile, loadConfig, loadConfigForFile } from '../load'; |
+15
-15
| import { access } from 'node:fs/promises'; | ||
| import type { PrismaNextConfig } from '@prisma-next/config/config-types'; | ||
| import { ConfigValidationError, validateConfig } from '@prisma-next/config/config-validation'; | ||
| import { validateConfig } from '@prisma-next/config/config-validation'; | ||
| import { getEmittedArtifactPaths } from '@prisma-next/emitter'; | ||
| import { | ||
| CliStructuredError, | ||
| errorConfigFileNotFound, | ||
@@ -11,4 +12,4 @@ errorConfigValidation, | ||
| import { ifDefined } from '@prisma-next/utils/defined'; | ||
| import { isStructuredError, structuredError } from '@prisma-next/utils/structured-error'; | ||
| import { dirname, join, resolve } from 'pathe'; | ||
| import { ConfigFileNotFoundError } from './errors'; | ||
| import { finalizeConfig } from './finalize-config'; | ||
@@ -19,3 +20,3 @@ | ||
| function throwValidation(field: string, why: string): never { | ||
| throw new ConfigValidationError(field, why); | ||
| throw structuredError('CONFIG.VALIDATION_FAILED', why, { why, meta: { field } }); | ||
| } | ||
@@ -88,3 +89,3 @@ | ||
| if (resolvedConfigPath && result.configFile !== resolvedConfigPath) { | ||
| throw new ConfigFileNotFoundError(resolvedConfigPath); | ||
| throw errorConfigFileNotFound(resolvedConfigPath); | ||
| } | ||
@@ -95,3 +96,3 @@ | ||
| const displayPath = result.configFile || resolvedConfigPath || configPath; | ||
| throw new ConfigFileNotFoundError(displayPath); | ||
| throw errorConfigFileNotFound(displayPath); | ||
| } | ||
@@ -114,12 +115,13 @@ | ||
| export function toStructuredConfigError(error: unknown, configPath?: string): Error { | ||
| if (error instanceof ConfigValidationError) { | ||
| return errorConfigValidation(error.field, { | ||
| why: error.why, | ||
| if ( | ||
| isStructuredError(error) && | ||
| error.code === 'CONFIG.VALIDATION_FAILED' && | ||
| !(error instanceof CliStructuredError) | ||
| ) { | ||
| const field = typeof error.meta?.['field'] === 'string' ? error.meta['field'] : 'config'; | ||
| return errorConfigValidation(field, { | ||
| why: error.why ?? error.message, | ||
| }); | ||
| } | ||
| if (error instanceof ConfigFileNotFoundError) { | ||
| return errorConfigFileNotFound(error.configPath); | ||
| } | ||
| if (error instanceof Error && hasStringCode(error)) { | ||
@@ -164,7 +166,5 @@ return error; | ||
| if (configPath === undefined) { | ||
| throw toStructuredConfigError( | ||
| new ConfigFileNotFoundError(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME)), | ||
| ); | ||
| throw errorConfigFileNotFound(join(dirname(resolve(process.cwd(), filePath)), CONFIG_FILENAME)); | ||
| } | ||
| return loadConfig(configPath); | ||
| } |
| export class ConfigFileNotFoundError extends Error { | ||
| readonly configPath?: string; | ||
| readonly why?: string; | ||
| constructor(configPath?: string, why?: string) { | ||
| super(why ?? (configPath ? `Config file not found: ${configPath}` : 'Config file not found')); | ||
| this.name = 'ConfigFileNotFoundError'; | ||
| if (configPath !== undefined) { | ||
| this.configPath = configPath; | ||
| } | ||
| if (why !== undefined) { | ||
| this.why = why; | ||
| } | ||
| } | ||
| } |
37147
-3.79%10
-9.09%298
-7.17%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed