@prisma/config 6.13.0-dev.10 → 6.13.0-dev.12

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/dist/index.d.ts CHANGED
@@ -221,12 +221,15 @@ declare type IsolationLevel = 'READ UNCOMMITTED' | 'READ COMMITTED' | 'REPEATABL
221
221
  export declare function loadConfigFromFile({ configFile, configRoot, }: LoadConfigFromFileInput): Promise<ConfigFromFile>;
222
222
 
223
223
  export declare type LoadConfigFromFileError = {
224
+ /**
225
+ * The config file was not found at the specified path.
226
+ */
224
227
  _tag: 'ConfigFileNotFound';
225
228
  } | {
226
- _tag: 'TypeScriptImportFailed';
229
+ _tag: 'ConfigLoadError';
227
230
  error: Error;
228
231
  } | {
229
- _tag: 'ConfigFileParseError';
232
+ _tag: 'ConfigFileSyntaxError';
230
233
  error: Error;
231
234
  } | {
232
235
  _tag: 'UnknownError';
package/dist/index.js CHANGED
@@ -22991,33 +22991,18 @@ function defaultTestConfig() {
22991
22991
  }
22992
22992
 
22993
22993
  // src/loadConfigFromFile.ts
22994
- var import_node_fs = __toESM(require("node:fs"));
22995
22994
  var import_node_path = __toESM(require("node:path"));
22996
22995
  var import_node_process = __toESM(require("node:process"));
22997
- var import_jiti = require("jiti");
22998
22996
  var debug4 = Debug("prisma:config:loadConfigFromFile");
22997
+ var SUPPORTED_EXTENSIONS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
22999
22998
  async function loadConfigFromFile({
23000
22999
  configFile,
23001
23000
  configRoot = import_node_process.default.cwd()
23002
23001
  }) {
23003
23002
  const start = performance.now();
23004
23003
  const getTime = () => `${(performance.now() - start).toFixed(2)}ms`;
23005
- let resolvedPath;
23006
- if (configFile) {
23007
- resolvedPath = import_node_path.default.resolve(configRoot, configFile);
23008
- if (!import_node_fs.default.existsSync(resolvedPath)) {
23009
- debug4(`The given config file was not found at %s`, resolvedPath);
23010
- return { resolvedPath, error: { _tag: "ConfigFileNotFound" } };
23011
- }
23012
- } else {
23013
- resolvedPath = ["prisma.config.ts"].map((file) => import_node_path.default.resolve(configRoot, file)).find((file) => import_node_fs.default.existsSync(file)) ?? null;
23014
- if (resolvedPath === null) {
23015
- debug4(`No config file found in the current working directory %s`, configRoot);
23016
- return { resolvedPath, config: defaultConfig() };
23017
- }
23018
- }
23019
23004
  try {
23020
- const { required: required3, error } = await requireTypeScriptFile(resolvedPath);
23005
+ const { configModule, resolvedPath, error } = await loadConfigTsOrJs(configRoot, configFile);
23021
23006
  if (error) {
23022
23007
  return {
23023
23008
  resolvedPath,
@@ -23025,22 +23010,26 @@ async function loadConfigFromFile({
23025
23010
  };
23026
23011
  }
23027
23012
  debug4(`Config file loaded in %s`, getTime());
23028
- let defaultExport;
23013
+ if (resolvedPath === null) {
23014
+ debug4(`No config file found in the current working directory %s`, configRoot);
23015
+ return { resolvedPath: null, config: defaultConfig() };
23016
+ }
23017
+ let parsedConfig;
23029
23018
  try {
23030
- defaultExport = parseDefaultExport(required3["default"]);
23019
+ parsedConfig = parseDefaultExport(configModule);
23031
23020
  } catch (e) {
23032
23021
  const error2 = e;
23033
23022
  return {
23034
23023
  resolvedPath,
23035
23024
  error: {
23036
- _tag: "ConfigFileParseError",
23025
+ _tag: "ConfigFileSyntaxError",
23037
23026
  error: error2
23038
23027
  }
23039
23028
  };
23040
23029
  }
23041
23030
  import_node_process.default.stdout.write(`Loaded Prisma config from "${resolvedPath}".
23042
23031
  `);
23043
- const prismaConfig = transformPathsInConfigToAbsolute(defaultExport, resolvedPath);
23032
+ const prismaConfig = transformPathsInConfigToAbsolute(parsedConfig, resolvedPath);
23044
23033
  return {
23045
23034
  config: {
23046
23035
  ...prismaConfig,
@@ -23051,7 +23040,7 @@ async function loadConfigFromFile({
23051
23040
  } catch (e) {
23052
23041
  const error = e;
23053
23042
  return {
23054
- resolvedPath,
23043
+ resolvedPath: configRoot,
23055
23044
  error: {
23056
23045
  _tag: "UnknownError",
23057
23046
  error
@@ -23059,25 +23048,79 @@ async function loadConfigFromFile({
23059
23048
  };
23060
23049
  }
23061
23050
  }
23062
- async function requireTypeScriptFile(resolvedPath) {
23051
+ async function loadConfigTsOrJs(configRoot, configFile) {
23052
+ const { loadConfig: loadConfigWithC12 } = await import("c12");
23053
+ const { deepmerge } = await import("deepmerge-ts");
23063
23054
  try {
23064
- const jiti = (0, import_jiti.createJiti)(__filename, {
23065
- interopDefault: true,
23066
- moduleCache: false
23055
+ const {
23056
+ config: config2,
23057
+ configFile: _resolvedPath,
23058
+ meta
23059
+ } = await loadConfigWithC12({
23060
+ cwd: configRoot,
23061
+ // configuration base name
23062
+ name: "prisma",
23063
+ // the config file to load (without file extensions), defaulting to `${cwd}.${name}`
23064
+ configFile,
23065
+ // do not load .env files
23066
+ dotenv: false,
23067
+ // do not load RC config
23068
+ rcFile: false,
23069
+ // do not extend remote config files
23070
+ giget: false,
23071
+ // do not extend the default config
23072
+ extend: false,
23073
+ // do not load from nearest package.json
23074
+ packageJson: false,
23075
+ // @ts-expect-error: this is a type-error in `c12` itself
23076
+ merger: deepmerge,
23077
+ jitiOptions: {
23078
+ interopDefault: true,
23079
+ moduleCache: false,
23080
+ extensions: SUPPORTED_EXTENSIONS
23081
+ }
23067
23082
  });
23068
- const configExport = await jiti.import(resolvedPath);
23083
+ const resolvedPath = _resolvedPath ? import_node_path.default.normalize(_resolvedPath) : void 0;
23084
+ const doesConfigFileExist = resolvedPath !== void 0 && meta !== void 0;
23085
+ if (configFile && !doesConfigFileExist) {
23086
+ debug4(`The given config file was not found at %s`, resolvedPath);
23087
+ return {
23088
+ require: null,
23089
+ resolvedPath: import_node_path.default.join(configRoot, configFile),
23090
+ error: { _tag: "ConfigFileNotFound" }
23091
+ };
23092
+ }
23093
+ if (doesConfigFileExist) {
23094
+ const extension = import_node_path.default.extname(import_node_path.default.basename(resolvedPath));
23095
+ if (!SUPPORTED_EXTENSIONS.includes(extension)) {
23096
+ return {
23097
+ configModule: config2,
23098
+ resolvedPath,
23099
+ error: {
23100
+ _tag: "ConfigLoadError",
23101
+ error: new Error(`Unsupported Prisma config file extension: ${extension}`)
23102
+ }
23103
+ };
23104
+ }
23105
+ }
23069
23106
  return {
23070
- required: configExport,
23107
+ configModule: config2,
23108
+ resolvedPath: doesConfigFileExist ? resolvedPath : null,
23071
23109
  error: null
23072
23110
  };
23073
23111
  } catch (e) {
23074
23112
  const error = e;
23075
23113
  debug4("jiti import failed: %s", error.message);
23114
+ const configFileMatch = error.message.match(/prisma\.config\.(\w+)/);
23115
+ const extension = configFileMatch?.[1];
23116
+ const filenameWithExtension = import_node_path.default.join(configRoot, extension ? `prisma.config.${extension}` : "");
23117
+ debug4("faulty config file: %s", filenameWithExtension);
23076
23118
  return {
23077
23119
  error: {
23078
- _tag: "TypeScriptImportFailed",
23120
+ _tag: "ConfigLoadError",
23079
23121
  error
23080
- }
23122
+ },
23123
+ resolvedPath: filenameWithExtension
23081
23124
  };
23082
23125
  }
23083
23126
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/config",
3
- "version": "6.13.0-dev.10",
3
+ "version": "6.13.0-dev.12",
4
4
  "description": "Internal package used to define and read Prisma configuration files",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -12,13 +12,14 @@
12
12
  "license": "Apache-2.0",
13
13
  "author": "Alberto Schiabel <schiabel@prisma.io>",
14
14
  "dependencies": {
15
- "jiti": "2.4.2"
15
+ "c12": "3.1.0",
16
+ "deepmerge-ts": "7.1.5"
16
17
  },
17
18
  "devDependencies": {
18
19
  "effect": "3.16.12",
19
20
  "vitest": "3.2.4",
20
- "@prisma/get-platform": "6.13.0-dev.10",
21
- "@prisma/driver-adapter-utils": "6.13.0-dev.10"
21
+ "@prisma/driver-adapter-utils": "6.13.0-dev.12",
22
+ "@prisma/get-platform": "6.13.0-dev.12"
22
23
  },
23
24
  "files": [
24
25
  "dist"