@prisma/config 7.10.0-dev.5 → 7.10.0-dev.57

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
@@ -73,6 +73,11 @@ declare type ExperimentalConfig = {
73
73
  extensions?: boolean;
74
74
  };
75
75
 
76
+ /**
77
+ * Find the config file selected by automatic Prisma 7 discovery without loading it.
78
+ */
79
+ export declare function findPrismaConfigFile(configRoot?: string): string | null;
80
+
76
81
  export declare type InjectFormatters = {
77
82
  dim: (data: string) => string;
78
83
  log: (data: string) => void;
package/dist/index.js CHANGED
@@ -35,6 +35,7 @@ __export(index_exports, {
35
35
  defaultTestConfig: () => defaultTestConfig,
36
36
  defineConfig: () => defineConfig,
37
37
  env: () => env,
38
+ findPrismaConfigFile: () => findPrismaConfigFile,
38
39
  loadConfigFromFile: () => loadConfigFromFile
39
40
  });
40
41
  module.exports = __toCommonJS(index_exports);
@@ -520,10 +521,39 @@ function env(name) {
520
521
  }
521
522
 
522
523
  // src/loadConfigFromFile.ts
523
- var import_node_path = __toESM(require("node:path"));
524
+ var fs = __toESM(require("node:fs"));
525
+ var path = __toESM(require("node:path"));
524
526
  var import_node_process = __toESM(require("node:process"));
525
527
  var debug3 = Debug("prisma:config:loadConfigFromFile");
526
528
  var SUPPORTED_EXTENSIONS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
529
+ var PRISMA7_CONFIG_FILE_CANDIDATES = [
530
+ ...SUPPORTED_EXTENSIONS.map((extension) => `prisma7.config${extension}`),
531
+ ...SUPPORTED_EXTENSIONS.map((extension) => path.join(".config", `prisma7${extension}`))
532
+ ];
533
+ var LEGACY_CONFIG_FILE_BASENAMES = [
534
+ "prisma.config",
535
+ path.join(".config", "prisma"),
536
+ path.join(".config", "prisma.config")
537
+ ];
538
+ var LEGACY_CONFIG_FILE_CANDIDATES = LEGACY_CONFIG_FILE_BASENAMES.flatMap((basename2) => [
539
+ ...SUPPORTED_EXTENSIONS.map((extension) => `${basename2}${extension}`),
540
+ ...SUPPORTED_EXTENSIONS.map((extension) => path.join(basename2, `index${extension}`))
541
+ ]);
542
+ function findPrisma7ConfigFile(configRoot = import_node_process.default.cwd()) {
543
+ return findFirstConfigFile(PRISMA7_CONFIG_FILE_CANDIDATES, configRoot);
544
+ }
545
+ function findPrismaConfigFile(configRoot = import_node_process.default.cwd()) {
546
+ return findPrisma7ConfigFile(configRoot) ?? findFirstConfigFile(LEGACY_CONFIG_FILE_CANDIDATES, configRoot);
547
+ }
548
+ function findFirstConfigFile(candidates, configRoot) {
549
+ for (const candidate of candidates) {
550
+ const resolvedPath = path.resolve(configRoot, candidate);
551
+ if (fs.statSync(resolvedPath, { throwIfNoEntry: false })?.isFile()) {
552
+ return resolvedPath;
553
+ }
554
+ }
555
+ return null;
556
+ }
527
557
  async function loadConfigFromFile({
528
558
  configFile,
529
559
  configRoot = import_node_process.default.cwd()
@@ -532,7 +562,8 @@ async function loadConfigFromFile({
532
562
  const getTime = () => `${(performance.now() - start).toFixed(2)}ms`;
533
563
  const diagnostics = [];
534
564
  try {
535
- const { configModule, resolvedPath, error } = await loadConfigTsOrJs(configRoot, configFile);
565
+ const selectedConfigFile = configFile ?? findPrisma7ConfigFile(configRoot) ?? void 0;
566
+ const { configModule, resolvedPath, error } = await loadConfigTsOrJs(configRoot, selectedConfigFile);
536
567
  if (error) {
537
568
  return {
538
569
  resolvedPath,
@@ -561,7 +592,7 @@ async function loadConfigFromFile({
561
592
  }
562
593
  diagnostics.push({
563
594
  _tag: "log",
564
- value: ({ log, dim: dim2 }) => () => log(dim2(`Loaded Prisma config from ${import_node_path.default.relative(configRoot, resolvedPath)}.
595
+ value: ({ log, dim: dim2 }) => () => log(dim2(`Loaded Prisma config from ${path.relative(configRoot, resolvedPath)}.
565
596
  `))
566
597
  });
567
598
  const prismaConfig = transformPathsInConfigToAbsolute(parsedConfig, resolvedPath);
@@ -617,18 +648,18 @@ async function loadConfigTsOrJs(configRoot, configFile) {
617
648
  extensions: SUPPORTED_EXTENSIONS
618
649
  }
619
650
  });
620
- const resolvedPath = _resolvedPath ? import_node_path.default.normalize(_resolvedPath) : void 0;
651
+ const resolvedPath = _resolvedPath ? path.normalize(_resolvedPath) : void 0;
621
652
  const doesConfigFileExist = resolvedPath !== void 0 && meta !== void 0;
622
653
  if (configFile && !doesConfigFileExist) {
623
654
  debug3(`The given config file was not found at %s`, resolvedPath);
624
655
  return {
625
656
  require: null,
626
- resolvedPath: import_node_path.default.join(configRoot, configFile),
657
+ resolvedPath: path.join(configRoot, configFile),
627
658
  error: { _tag: "ConfigFileNotFound" }
628
659
  };
629
660
  }
630
661
  if (doesConfigFileExist) {
631
- const extension = import_node_path.default.extname(import_node_path.default.basename(resolvedPath));
662
+ const extension = path.extname(path.basename(resolvedPath));
632
663
  if (!SUPPORTED_EXTENSIONS.includes(extension)) {
633
664
  return {
634
665
  configModule: config,
@@ -650,7 +681,7 @@ async function loadConfigTsOrJs(configRoot, configFile) {
650
681
  debug3("jiti import failed: %s", error.message);
651
682
  const configFileMatch = error.message.match(/prisma\.config\.(\w+)/);
652
683
  const extension = configFileMatch?.[1];
653
- const filenameWithExtension = import_node_path.default.join(configRoot, extension ? `prisma.config.${extension}` : "");
684
+ const filenameWithExtension = configFile ? path.resolve(configRoot, configFile) : path.join(configRoot, extension ? `prisma.config.${extension}` : "");
654
685
  debug3("faulty config file: %s", filenameWithExtension);
655
686
  return {
656
687
  error: {
@@ -666,7 +697,7 @@ function transformPathsInConfigToAbsolute(prismaConfig, resolvedPath) {
666
697
  if (!value) {
667
698
  return void 0;
668
699
  }
669
- return import_node_path.default.resolve(import_node_path.default.dirname(resolvedPath), value);
700
+ return path.resolve(path.dirname(resolvedPath), value);
670
701
  }
671
702
  return {
672
703
  ...prismaConfig,
@@ -692,5 +723,6 @@ function transformPathsInConfigToAbsolute(prismaConfig, resolvedPath) {
692
723
  defaultTestConfig,
693
724
  defineConfig,
694
725
  env,
726
+ findPrismaConfigFile,
695
727
  loadConfigFromFile
696
728
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/config",
3
- "version": "7.10.0-dev.5",
3
+ "version": "7.10.0-dev.57",
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",
@@ -19,8 +19,8 @@
19
19
  },
20
20
  "devDependencies": {
21
21
  "dotenv": "17.2.3",
22
- "@prisma/debug": "7.10.0-dev.5",
23
- "@prisma/get-platform": "7.10.0-dev.5"
22
+ "@prisma/debug": "7.10.0-dev.57",
23
+ "@prisma/get-platform": "7.10.0-dev.57"
24
24
  },
25
25
  "files": [
26
26
  "dist"