@prisma/config 6.13.0-integration-feat-orm-1112-setup-external-tables-script.2 → 6.13.0-integration-feat-orm-1112-setup-external-tables-script.3

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';
@@ -253,7 +256,7 @@ declare type MigrationsConfigShape = {
253
256
  * Provide a function to pass a SQL script that will be used to setup external tables during migration diffing.
254
257
  * Also see `tables.external`.
255
258
  */
256
- setupExternalTables?: () => string;
259
+ setupExternalTables?: string;
257
260
  };
258
261
 
259
262
  declare const officialPrismaAdapters: readonly ["@prisma/adapter-planetscale", "@prisma/adapter-neon", "@prisma/adapter-libsql", "@prisma/adapter-better-sqlite3", "@prisma/adapter-d1", "@prisma/adapter-pg", "@prisma/adapter-mssql", "@prisma/adapter-mariadb"];
package/dist/index.js CHANGED
@@ -22863,19 +22863,9 @@ var ErrorCapturingSqlMigrationAwareDriverAdapterFactoryShape = Schema_exports.de
22863
22863
  decode: identity
22864
22864
  }
22865
22865
  );
22866
- var SetupExternalTablesShape = Schema_exports.declare(
22867
- (input) => {
22868
- return typeof input === "function";
22869
- },
22870
- {
22871
- identifier: "SetupExternalTables",
22872
- encode: identity,
22873
- decode: identity
22874
- }
22875
- );
22876
22866
  var MigrationsConfigShape = Schema_exports.Struct({
22877
22867
  path: Schema_exports.optional(Schema_exports.String),
22878
- setupExternalTables: Schema_exports.optional(SetupExternalTablesShape)
22868
+ setupExternalTables: Schema_exports.optional(Schema_exports.String)
22879
22869
  });
22880
22870
  if (false) {
22881
22871
  __testMigrationsConfigShapeValueA;
@@ -23002,33 +22992,18 @@ function defaultTestConfig() {
23002
22992
  }
23003
22993
 
23004
22994
  // src/loadConfigFromFile.ts
23005
- var import_node_fs = __toESM(require("node:fs"));
23006
22995
  var import_node_path = __toESM(require("node:path"));
23007
22996
  var import_node_process = __toESM(require("node:process"));
23008
- var import_jiti = require("jiti");
23009
22997
  var debug4 = Debug("prisma:config:loadConfigFromFile");
22998
+ var SUPPORTED_EXTENSIONS = [".js", ".ts", ".mjs", ".cjs", ".mts", ".cts"];
23010
22999
  async function loadConfigFromFile({
23011
23000
  configFile,
23012
23001
  configRoot = import_node_process.default.cwd()
23013
23002
  }) {
23014
23003
  const start = performance.now();
23015
23004
  const getTime = () => `${(performance.now() - start).toFixed(2)}ms`;
23016
- let resolvedPath;
23017
- if (configFile) {
23018
- resolvedPath = import_node_path.default.resolve(configRoot, configFile);
23019
- if (!import_node_fs.default.existsSync(resolvedPath)) {
23020
- debug4(`The given config file was not found at %s`, resolvedPath);
23021
- return { resolvedPath, error: { _tag: "ConfigFileNotFound" } };
23022
- }
23023
- } else {
23024
- resolvedPath = ["prisma.config.ts"].map((file) => import_node_path.default.resolve(configRoot, file)).find((file) => import_node_fs.default.existsSync(file)) ?? null;
23025
- if (resolvedPath === null) {
23026
- debug4(`No config file found in the current working directory %s`, configRoot);
23027
- return { resolvedPath, config: defaultConfig() };
23028
- }
23029
- }
23030
23005
  try {
23031
- const { required: required3, error } = await requireTypeScriptFile(resolvedPath);
23006
+ const { configModule, resolvedPath, error } = await loadConfigTsOrJs(configRoot, configFile);
23032
23007
  if (error) {
23033
23008
  return {
23034
23009
  resolvedPath,
@@ -23036,22 +23011,26 @@ async function loadConfigFromFile({
23036
23011
  };
23037
23012
  }
23038
23013
  debug4(`Config file loaded in %s`, getTime());
23039
- let defaultExport;
23014
+ if (resolvedPath === null) {
23015
+ debug4(`No config file found in the current working directory %s`, configRoot);
23016
+ return { resolvedPath: null, config: defaultConfig() };
23017
+ }
23018
+ let parsedConfig;
23040
23019
  try {
23041
- defaultExport = parseDefaultExport(required3["default"]);
23020
+ parsedConfig = parseDefaultExport(configModule);
23042
23021
  } catch (e) {
23043
23022
  const error2 = e;
23044
23023
  return {
23045
23024
  resolvedPath,
23046
23025
  error: {
23047
- _tag: "ConfigFileParseError",
23026
+ _tag: "ConfigFileSyntaxError",
23048
23027
  error: error2
23049
23028
  }
23050
23029
  };
23051
23030
  }
23052
23031
  import_node_process.default.stdout.write(`Loaded Prisma config from "${resolvedPath}".
23053
23032
  `);
23054
- const prismaConfig = transformPathsInConfigToAbsolute(defaultExport, resolvedPath);
23033
+ const prismaConfig = transformPathsInConfigToAbsolute(parsedConfig, resolvedPath);
23055
23034
  return {
23056
23035
  config: {
23057
23036
  ...prismaConfig,
@@ -23062,7 +23041,7 @@ async function loadConfigFromFile({
23062
23041
  } catch (e) {
23063
23042
  const error = e;
23064
23043
  return {
23065
- resolvedPath,
23044
+ resolvedPath: configRoot,
23066
23045
  error: {
23067
23046
  _tag: "UnknownError",
23068
23047
  error
@@ -23070,25 +23049,79 @@ async function loadConfigFromFile({
23070
23049
  };
23071
23050
  }
23072
23051
  }
23073
- async function requireTypeScriptFile(resolvedPath) {
23052
+ async function loadConfigTsOrJs(configRoot, configFile) {
23053
+ const { loadConfig: loadConfigWithC12 } = await import("c12");
23054
+ const { deepmerge } = await import("deepmerge-ts");
23074
23055
  try {
23075
- const jiti = (0, import_jiti.createJiti)(__filename, {
23076
- interopDefault: true,
23077
- moduleCache: false
23056
+ const {
23057
+ config: config2,
23058
+ configFile: _resolvedPath,
23059
+ meta
23060
+ } = await loadConfigWithC12({
23061
+ cwd: configRoot,
23062
+ // configuration base name
23063
+ name: "prisma",
23064
+ // the config file to load (without file extensions), defaulting to `${cwd}.${name}`
23065
+ configFile,
23066
+ // do not load .env files
23067
+ dotenv: false,
23068
+ // do not load RC config
23069
+ rcFile: false,
23070
+ // do not extend remote config files
23071
+ giget: false,
23072
+ // do not extend the default config
23073
+ extend: false,
23074
+ // do not load from nearest package.json
23075
+ packageJson: false,
23076
+ // @ts-expect-error: this is a type-error in `c12` itself
23077
+ merger: deepmerge,
23078
+ jitiOptions: {
23079
+ interopDefault: true,
23080
+ moduleCache: false,
23081
+ extensions: SUPPORTED_EXTENSIONS
23082
+ }
23078
23083
  });
23079
- const configExport = await jiti.import(resolvedPath);
23084
+ const resolvedPath = _resolvedPath ? import_node_path.default.normalize(_resolvedPath) : void 0;
23085
+ const doesConfigFileExist = resolvedPath !== void 0 && meta !== void 0;
23086
+ if (configFile && !doesConfigFileExist) {
23087
+ debug4(`The given config file was not found at %s`, resolvedPath);
23088
+ return {
23089
+ require: null,
23090
+ resolvedPath: import_node_path.default.join(configRoot, configFile),
23091
+ error: { _tag: "ConfigFileNotFound" }
23092
+ };
23093
+ }
23094
+ if (doesConfigFileExist) {
23095
+ const extension = import_node_path.default.extname(import_node_path.default.basename(resolvedPath));
23096
+ if (!SUPPORTED_EXTENSIONS.includes(extension)) {
23097
+ return {
23098
+ configModule: config2,
23099
+ resolvedPath,
23100
+ error: {
23101
+ _tag: "ConfigLoadError",
23102
+ error: new Error(`Unsupported Prisma config file extension: ${extension}`)
23103
+ }
23104
+ };
23105
+ }
23106
+ }
23080
23107
  return {
23081
- required: configExport,
23108
+ configModule: config2,
23109
+ resolvedPath: doesConfigFileExist ? resolvedPath : null,
23082
23110
  error: null
23083
23111
  };
23084
23112
  } catch (e) {
23085
23113
  const error = e;
23086
23114
  debug4("jiti import failed: %s", error.message);
23115
+ const configFileMatch = error.message.match(/prisma\.config\.(\w+)/);
23116
+ const extension = configFileMatch?.[1];
23117
+ const filenameWithExtension = import_node_path.default.join(configRoot, extension ? `prisma.config.${extension}` : "");
23118
+ debug4("faulty config file: %s", filenameWithExtension);
23087
23119
  return {
23088
23120
  error: {
23089
- _tag: "TypeScriptImportFailed",
23121
+ _tag: "ConfigLoadError",
23090
23122
  error
23091
- }
23123
+ },
23124
+ resolvedPath: filenameWithExtension
23092
23125
  };
23093
23126
  }
23094
23127
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prisma/config",
3
- "version": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.2",
3
+ "version": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.3",
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/driver-adapter-utils": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.2",
21
- "@prisma/get-platform": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.2"
21
+ "@prisma/driver-adapter-utils": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.3",
22
+ "@prisma/get-platform": "6.13.0-integration-feat-orm-1112-setup-external-tables-script.3"
22
23
  },
23
24
  "files": [
24
25
  "dist"