prismic-ts-codegen 0.1.3 → 0.1.4

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/bin/cli.mjs CHANGED
@@ -1189,6 +1189,10 @@ const loadModels = async (config) => {
1189
1189
  };
1190
1190
 
1191
1191
  const jiti = _jiti(process.cwd());
1192
+ const loadModuleWithJiti = (id) => {
1193
+ const mod = jiti(id);
1194
+ return "default" in mod ? mod.default : mod;
1195
+ };
1192
1196
  const DEFAULT_CONFIG_PATHS = [
1193
1197
  "prismicCodegen.config.ts",
1194
1198
  "prismicCodegen.config.js"
@@ -1196,15 +1200,14 @@ const DEFAULT_CONFIG_PATHS = [
1196
1200
  const loadConfig = (config) => {
1197
1201
  if (config.path) {
1198
1202
  if (existsSync(config.path)) {
1199
- return jiti(config.path);
1203
+ return loadModuleWithJiti(resolve(config.path));
1200
1204
  } else {
1201
1205
  throw new Error(`Config file does not exist: ${config.path}`);
1202
1206
  }
1203
1207
  } else {
1204
1208
  for (const configPath of DEFAULT_CONFIG_PATHS) {
1205
1209
  if (existsSync(configPath)) {
1206
- const mod = jiti(resolve(configPath));
1207
- return "default" in mod ? mod.default : mod;
1210
+ return loadModuleWithJiti(resolve(configPath));
1208
1211
  }
1209
1212
  }
1210
1213
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prismic-ts-codegen",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "An experimental Prismic model-to-TypeScript-type generator",
5
5
  "keywords": [
6
6
  "typescript",
@@ -6,6 +6,12 @@ import type { Config } from "./types";
6
6
 
7
7
  const jiti = _jiti(process.cwd());
8
8
 
9
+ const loadModuleWithJiti = <TModule>(id: string): TModule => {
10
+ const mod = jiti(id) as TModule | { default: TModule };
11
+
12
+ return "default" in mod ? mod.default : mod;
13
+ };
14
+
9
15
  const DEFAULT_CONFIG_PATHS = [
10
16
  "prismicCodegen.config.ts",
11
17
  "prismicCodegen.config.js",
@@ -18,18 +24,14 @@ type LoadConfigConfig = {
18
24
  export const loadConfig = (config: LoadConfigConfig): Config => {
19
25
  if (config.path) {
20
26
  if (existsSync(config.path)) {
21
- return jiti(config.path);
27
+ return loadModuleWithJiti(resolvePath(config.path));
22
28
  } else {
23
29
  throw new Error(`Config file does not exist: ${config.path}`);
24
30
  }
25
31
  } else {
26
32
  for (const configPath of DEFAULT_CONFIG_PATHS) {
27
33
  if (existsSync(configPath)) {
28
- const mod = jiti(resolvePath(configPath)) as
29
- | Config
30
- | { default: Config };
31
-
32
- return "default" in mod ? mod.default : mod;
34
+ return loadModuleWithJiti(resolvePath(configPath));
33
35
  }
34
36
  }
35
37
  }