@soda-gql/config 0.0.1 → 0.0.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.cjs CHANGED
@@ -5,14 +5,31 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
6
  var __getProtoOf = Object.getPrototypeOf;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
8
+ var __export = (all, symbols) => {
9
+ let target = {};
10
+ for (var name in all) {
11
+ __defProp(target, name, {
12
+ get: all[name],
13
+ enumerable: true
14
14
  });
15
15
  }
16
+ if (symbols) {
17
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
18
+ }
19
+ return target;
20
+ };
21
+ var __copyProps = (to, from, except, desc) => {
22
+ if (from && typeof from === "object" || typeof from === "function") {
23
+ for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
24
+ key = keys[i];
25
+ if (!__hasOwnProp.call(to, key) && key !== except) {
26
+ __defProp(to, key, {
27
+ get: ((k) => from[k]).bind(null, key),
28
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
29
+ });
30
+ }
31
+ }
32
+ }
16
33
  return to;
17
34
  };
18
35
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
@@ -22,25 +39,16 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
22
39
 
23
40
  //#endregion
24
41
  let __soda_gql_common = require("@soda-gql/common");
25
- __soda_gql_common = __toESM(__soda_gql_common);
26
42
  let neverthrow = require("neverthrow");
27
- neverthrow = __toESM(neverthrow);
28
43
  let zod = require("zod");
29
44
  zod = __toESM(zod);
30
45
  let node_fs = require("node:fs");
31
- node_fs = __toESM(node_fs);
32
46
  let node_path = require("node:path");
33
- node_path = __toESM(node_path);
34
47
  let node_module = require("node:module");
35
- node_module = __toESM(node_module);
36
48
  let node_path_posix = require("node:path/posix");
37
- node_path_posix = __toESM(node_path_posix);
38
49
  let node_vm = require("node:vm");
39
- node_vm = __toESM(node_vm);
40
50
  let __swc_core = require("@swc/core");
41
- __swc_core = __toESM(__swc_core);
42
- let node_os = require("node:os");
43
- node_os = __toESM(node_os);
51
+ let node_url = require("node:url");
44
52
 
45
53
  //#region packages/config/src/errors.ts
46
54
  const configError = ({ code, message, filePath, cause }) => ({
@@ -116,6 +124,9 @@ function executeConfigFile(configPath) {
116
124
  const mod = { exports: {} };
117
125
  const requireInner = (0, node_module.createRequire)(filePath);
118
126
  const require$1 = (specifier) => {
127
+ if (specifier === "@soda-gql/config") {
128
+ return src_exports;
129
+ }
119
130
  if (!specifier.startsWith(".")) {
120
131
  return requireInner(specifier);
121
132
  }
@@ -141,14 +152,14 @@ function executeConfigFile(configPath) {
141
152
  if (!config) {
142
153
  throw new Error("Invalid config module");
143
154
  }
144
- return config;
155
+ return (0, neverthrow.ok)(config);
145
156
  } catch (error) {
146
- throw configError({
157
+ return (0, neverthrow.err)(configError({
147
158
  code: "CONFIG_LOAD_FAILED",
148
159
  message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,
149
160
  filePath,
150
161
  cause: error
151
- });
162
+ }));
152
163
  }
153
164
  }
154
165
 
@@ -156,21 +167,23 @@ function executeConfigFile(configPath) {
156
167
  //#region packages/config/src/normalize.ts
157
168
  /**
158
169
  * Resolve and normalize config with defaults.
170
+ * Paths in the config are resolved relative to the config file's directory.
159
171
  */
160
- function normalizeConfig(config) {
172
+ function normalizeConfig(config, configPath) {
173
+ const configDir = (0, node_path.dirname)(configPath);
161
174
  const analyzer = config.analyzer ?? "ts";
162
175
  const graphqlSystemAliases = config.graphqlSystemAliases ?? ["@/graphql-system"];
163
176
  const exclude = config.exclude ?? [];
164
177
  const resolved = {
165
178
  analyzer,
166
- outdir: (0, node_path.resolve)(config.outdir),
179
+ outdir: (0, node_path.resolve)(configDir, config.outdir),
167
180
  graphqlSystemAliases,
168
- include: config.include.map((pattern) => (0, node_path.resolve)(pattern)),
169
- exclude: exclude.map((pattern) => (0, node_path.resolve)(pattern)),
181
+ include: config.include.map((pattern) => (0, node_path.resolve)(configDir, pattern)),
182
+ exclude: exclude.map((pattern) => (0, node_path.resolve)(configDir, pattern)),
170
183
  schemas: Object.fromEntries(Object.entries(config.schemas).map(([name, schemaConfig]) => [name, {
171
- schema: (0, node_path.resolve)(schemaConfig.schema),
172
- runtimeAdapter: (0, node_path.resolve)(schemaConfig.runtimeAdapter),
173
- scalars: (0, node_path.resolve)(schemaConfig.scalars)
184
+ schema: (0, node_path.resolve)(configDir, schemaConfig.schema),
185
+ runtimeAdapter: (0, node_path.resolve)(configDir, schemaConfig.runtimeAdapter),
186
+ scalars: (0, node_path.resolve)(configDir, schemaConfig.scalars)
174
187
  }])),
175
188
  plugins: config.plugins ?? {}
176
189
  };
@@ -213,7 +226,11 @@ function loadConfig(configPath) {
213
226
  }));
214
227
  }
215
228
  try {
216
- return normalizeConfig(executeConfigFile(resolvedPath));
229
+ const result = executeConfigFile(resolvedPath);
230
+ if (result.isErr()) {
231
+ return (0, neverthrow.err)(result.error);
232
+ }
233
+ return normalizeConfig(result.value, resolvedPath);
217
234
  } catch (error) {
218
235
  return (0, neverthrow.err)(configError({
219
236
  code: "CONFIG_LOAD_FAILED",
@@ -234,11 +251,20 @@ function loadConfigFrom(dir) {
234
251
  //#endregion
235
252
  //#region packages/config/src/test-utils.ts
236
253
  /**
254
+ * Get project root from this package location.
255
+ * packages/config/src/test-utils.ts -> project root
256
+ */
257
+ const getProjectRoot = () => {
258
+ return (0, node_url.fileURLToPath)(new URL("../../../", require("url").pathToFileURL(__filename).href));
259
+ };
260
+ /**
237
261
  * Create temporary config file with proper formatting.
238
262
  * Uses template literals to support functions, regex, etc.
239
263
  */
240
264
  async function withTempConfig(config, fn) {
241
- const tmpDir = (0, node_fs.mkdtempSync)((0, node_path.join)((0, node_os.tmpdir)(), "soda-gql-test-"));
265
+ const projectRoot = getProjectRoot();
266
+ const tmpDir = (0, node_path.join)(projectRoot, "tests/.tmp/config-test", `${Date.now()}`);
267
+ (0, node_fs.mkdirSync)(tmpDir, { recursive: true });
242
268
  const configPath = (0, node_path.join)(tmpDir, "soda-gql.config.ts");
243
269
  const configContent = `
244
270
  import { defineConfig } from "@soda-gql/config";
@@ -258,11 +284,29 @@ export default defineConfig(${JSON.stringify(config, null, 2)});
258
284
  */
259
285
  function createTempConfigFile(dir, config) {
260
286
  const configPath = (0, node_path.join)(dir, "soda-gql.config.ts");
261
- const configContent = `export default ${JSON.stringify(config, null, 2)};`;
287
+ const configContent = `
288
+ import { defineConfig } from "@soda-gql/config";
289
+
290
+ export default defineConfig(${JSON.stringify(config, null, 2)});
291
+ `.trim();
262
292
  (0, node_fs.writeFileSync)(configPath, configContent);
263
293
  return configPath;
264
294
  }
265
295
 
296
+ //#endregion
297
+ //#region packages/config/src/index.ts
298
+ var src_exports = /* @__PURE__ */ __export({
299
+ configError: () => configError,
300
+ createTempConfigFile: () => createTempConfigFile,
301
+ defineConfig: () => defineConfig,
302
+ findConfigFile: () => findConfigFile,
303
+ loadConfig: () => loadConfig,
304
+ loadConfigFrom: () => loadConfigFrom,
305
+ normalizeConfig: () => normalizeConfig,
306
+ validateConfig: () => validateConfig,
307
+ withTempConfig: () => withTempConfig
308
+ });
309
+
266
310
  //#endregion
267
311
  exports.configError = configError;
268
312
  exports.createTempConfigFile = createTempConfigFile;
package/dist/index.d.cts CHANGED
@@ -149,8 +149,9 @@ declare function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, Conf
149
149
  //#region packages/config/src/normalize.d.ts
150
150
  /**
151
151
  * Resolve and normalize config with defaults.
152
+ * Paths in the config are resolved relative to the config file's directory.
152
153
  */
153
- declare function normalizeConfig(config: SodaGqlConfig): Result<ResolvedSodaGqlConfig, ConfigError>;
154
+ declare function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError>;
154
155
  //#endregion
155
156
  //#region packages/config/src/test-utils.d.ts
156
157
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAAA;AAf0B,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;MAAA,EAMpB,eANoB;SAAA,EAAA,MAAA;UAAA,CAAA,EAAA,MAAA;OAMpB,CAAA,EAAA,OAAA;MAIJ,WAAA;;;KClBQ,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GAAe,MDgBzB,CAAA,MAAA,EAAA,OAAA,CAAA;AAAA,KCbU,aAAA,GDaV;;;;;WATM,QAAA,CAAA,EAAA,IAAA,GAAA,KAAA;;;;;;ACdR;EAOY,SAAA,MAAY,EAAA,MAAA;EAGZ;;;;;;EAyCqB,SAAA,oBAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EAIrB;;;;;;EAOoB,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;;;;ACpDhC;;;WAG+B,OAAA,CAAA,EAAA,SAAA,MAAA,EAAA;;;AAyC/B;EAA4B,SAAA,OAAA,EDPR,QC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sBkF,WHtBlF,CAAA;;;;iBG8CQ,cAAA,eAA6B,OAAO,uBAAuB;;;AH7D3E;AAEA;AAOA;AAeE,iBIfc,eAAA,CJed,MAAA,EIfsC,aJetC,CAAA,EIfsD,MJetD,CIf6D,qBJe7D,EIfoF,WJepF,CAAA;;;;;AAxBF;AAEA;AAOa,iBKAS,cLepB,CAAA,CAAA,CAAA,CAAA,MAAA,EKf8C,OLe9C,CKfsD,aLetD,CAAA,EAAA,EAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GKfkG,OLelG,CKf0G,CLe1G,CAAA,CAAA,EKf+G,OLe/G,CKfuH,CLevH,CAAA;;;;AAf0B,iBKqBZ,oBAAA,CLrBY,GAAA,EAAA,MAAA,EAAA,MAAA,EKqB8B,OLrB9B,CKqBsC,aLrBtC,CAAA,CAAA,EAAA,MAAA"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAf0B;AAAA,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,IAAA,EAMpB,eANoB;EAAA,OAAA,EAAA,MAAA;EAMpB,QAAA,CAAA,EAAA,MAAA;EAIJ,KAAA,CAAA,EAAA,OAAA;CAKF,EAAA,GALE,WAKF;;;KCvBU,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GAAe,MDgBzB,CAAA,MAAA,EAAA,OAAA,CAAA;AAf0B,KCEhB,aAAA,GDFgB;EAAA;;;;EAUxB,SAAA,QAAA,CAAA,EAAA,IAAA,GAAA,KAAA;EAKF;;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;;;AHrCvD,cGUC,wBHVc,EAAA,SAAA,CAAA,oBAAA,EAAA,qBAAA,EAAA,oBAAA,EAAA,qBAAA,CAAA;AAE3B;AAOA;;AAA4B,iBGWZ,cAAA,CHXY,QAAA,CAAA,EAAA,MAAA,CAAA,EAAA,MAAA,GAAA,IAAA;;;;AAUxB,iBGkBY,UAAA,CHlBZ,UAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EGkBwD,MHlBxD,CGkB+D,qBHlB/D,EGkBsF,WHlBtF,CAAA;;;;iBG8CY,cAAA,eAA6B,OAAO,uBAAuB;;;AHjE3E;AAEA;AAOA;;AAA4B,iBICZ,eAAA,CJDY,MAAA,EICY,aJDZ,EAAA,UAAA,EAAA,MAAA,CAAA,EICgD,MJDhD,CICuD,qBJDvD,EIC8E,WJD9E,CAAA;;;;;AAT5B;AAEA;AAOa,iBKQS,cLOpB,CAAA,CAAA,CAAA,CAAA,MAAA,EKP8C,OLO9C,CKPsD,aLOtD,CAAA,EAAA,EAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GKPkG,OLOlG,CKP0G,CLO1G,CAAA,CAAA,EKP+G,OLO/G,CKPuH,CLOvH,CAAA;;;;AAf0B,iBK+BZ,oBAAA,CL/BY,GAAA,EAAA,MAAA,EAAA,MAAA,EK+B8B,OL/B9B,CK+BsC,aL/BtC,CAAA,CAAA,EAAA,MAAA"}
@@ -149,8 +149,9 @@ declare function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, Conf
149
149
  //#region packages/config/src/normalize.d.ts
150
150
  /**
151
151
  * Resolve and normalize config with defaults.
152
+ * Paths in the config are resolved relative to the config file's directory.
152
153
  */
153
- declare function normalizeConfig(config: SodaGqlConfig): Result<ResolvedSodaGqlConfig, ConfigError>;
154
+ declare function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError>;
154
155
  //#endregion
155
156
  //#region packages/config/src/test-utils.d.ts
156
157
  /**
@@ -164,4 +165,4 @@ declare function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPa
164
165
  declare function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string;
165
166
  //#endregion
166
167
  export { type ConfigError, type ConfigErrorCode, type PluginConfig, type ResolvedSodaGqlConfig, type SchemaConfig, type SodaGqlConfig, configError, createTempConfigFile, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig, withTempConfig };
167
- //# sourceMappingURL=index.d.ts.map
168
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils.ts"],"sourcesContent":[],"mappings":";;;KAAY,eAAA;KAEA,WAAA;iBACK;EAHL,SAAA,OAAA,EAAe,MAAA;EAEf,SAAA,QAAW,CAAA,EAAA,MACN;EAMJ,SAAA,KAeX,CAAA,EAAA,OAAA;CAf0B;AAAA,cAAf,WAAe,EAAA,CAAA;EAAA,IAAA;EAAA,OAAA;EAAA,QAAA;EAAA;CAAA,EAAA;EAAA,IAAA,EAMpB,eANoB;EAAA,OAAA,EAAA,MAAA;EAMpB,QAAA,CAAA,EAAA,MAAA;EAIJ,KAAA,CAAA,EAAA,OAAA;CAKF,EAAA,GALE,WAKF;;;KCvBU,YAAA;;;EDDA,SAAA,OAAA,EAAe,MAAA;AAE3B,CAAA;AAOa,KCDD,YAAA,GAAe,MDgBzB,CAAA,MAAA,EAAA,OAAA,CAAA;AAf0B,KCEhB,aAAA,GDFgB;EAAA;;;;EAUxB,SAAA,QAAA,CAAA,EAAA,IAAA,GAAA,KAAA;EAKF;;;;ACvBF;AAOA;EAGY,SAAA,MAAA,EAAa,MAAA;EAqCmB;;;;;AAQ5C;EAM4C,SAAA,oBAAA,CAAA,EAAA,SAAA,MAAA,EAAA;EAAf;;;;;;;ECnDhB;;;;;AA4Cb;EACgB,SAAA,OAAY,CAAA,EAAA,SAA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IAAA;;;;AAUxB,iBGkBY,UAAA,CHlBZ,UAAA,EAAA,MAAA,GAAA,SAAA,CAAA,EGkBwD,MHlBxD,CGkB+D,qBHlB/D,EGkBsF,WHlBtF,CAAA;;;;iBG8CY,cAAA,eAA6B,OAAO,uBAAuB;;;AHjE3E;AAEA;AAOA;;AAA4B,iBICZ,eAAA,CJDY,MAAA,EICY,aJDZ,EAAA,UAAA,EAAA,MAAA,CAAA,EICgD,MJDhD,CICuD,qBJDvD,EIC8E,WJD9E,CAAA;;;;;AAT5B;AAEA;AAOa,iBKQS,cLOpB,CAAA,CAAA,CAAA,CAAA,MAAA,EKP8C,OLO9C,CKPsD,aLOtD,CAAA,EAAA,EAAA,EAAA,CAAA,UAAA,EAAA,MAAA,EAAA,GKPkG,OLOlG,CKP0G,CLO1G,CAAA,CAAA,EKP+G,OLO/G,CKPuH,CLOvH,CAAA;;;;AAf0B,iBK+BZ,oBAAA,CL/BY,GAAA,EAAA,MAAA,EAAA,MAAA,EK+B8B,OL/B9B,CK+BsC,aL/BtC,CAAA,CAAA,EAAA,MAAA"}
@@ -2,13 +2,30 @@ import { createRequire } from "node:module";
2
2
  import { defineSchemaFor, resolveRelativeImportWithExistenceCheck } from "@soda-gql/common";
3
3
  import { err, ok } from "neverthrow";
4
4
  import z from "zod";
5
- import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { dirname, join, resolve } from "node:path";
7
7
  import { dirname as dirname$1, resolve as resolve$1 } from "node:path/posix";
8
8
  import { Script } from "node:vm";
9
9
  import { transformSync } from "@swc/core";
10
- import { tmpdir } from "node:os";
10
+ import { fileURLToPath } from "node:url";
11
11
 
12
+ //#region rolldown:runtime
13
+ var __defProp = Object.defineProperty;
14
+ var __export = (all, symbols) => {
15
+ let target = {};
16
+ for (var name in all) {
17
+ __defProp(target, name, {
18
+ get: all[name],
19
+ enumerable: true
20
+ });
21
+ }
22
+ if (symbols) {
23
+ __defProp(target, Symbol.toStringTag, { value: "Module" });
24
+ }
25
+ return target;
26
+ };
27
+
28
+ //#endregion
12
29
  //#region packages/config/src/errors.ts
13
30
  const configError = ({ code, message, filePath, cause }) => ({
14
31
  code,
@@ -83,6 +100,9 @@ function executeConfigFile(configPath) {
83
100
  const mod = { exports: {} };
84
101
  const requireInner = createRequire(filePath);
85
102
  const require = (specifier) => {
103
+ if (specifier === "@soda-gql/config") {
104
+ return src_exports;
105
+ }
86
106
  if (!specifier.startsWith(".")) {
87
107
  return requireInner(specifier);
88
108
  }
@@ -108,14 +128,14 @@ function executeConfigFile(configPath) {
108
128
  if (!config) {
109
129
  throw new Error("Invalid config module");
110
130
  }
111
- return config;
131
+ return ok(config);
112
132
  } catch (error) {
113
- throw configError({
133
+ return err(configError({
114
134
  code: "CONFIG_LOAD_FAILED",
115
135
  message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,
116
136
  filePath,
117
137
  cause: error
118
- });
138
+ }));
119
139
  }
120
140
  }
121
141
 
@@ -123,21 +143,23 @@ function executeConfigFile(configPath) {
123
143
  //#region packages/config/src/normalize.ts
124
144
  /**
125
145
  * Resolve and normalize config with defaults.
146
+ * Paths in the config are resolved relative to the config file's directory.
126
147
  */
127
- function normalizeConfig(config) {
148
+ function normalizeConfig(config, configPath) {
149
+ const configDir = dirname(configPath);
128
150
  const analyzer = config.analyzer ?? "ts";
129
151
  const graphqlSystemAliases = config.graphqlSystemAliases ?? ["@/graphql-system"];
130
152
  const exclude = config.exclude ?? [];
131
153
  const resolved = {
132
154
  analyzer,
133
- outdir: resolve(config.outdir),
155
+ outdir: resolve(configDir, config.outdir),
134
156
  graphqlSystemAliases,
135
- include: config.include.map((pattern) => resolve(pattern)),
136
- exclude: exclude.map((pattern) => resolve(pattern)),
157
+ include: config.include.map((pattern) => resolve(configDir, pattern)),
158
+ exclude: exclude.map((pattern) => resolve(configDir, pattern)),
137
159
  schemas: Object.fromEntries(Object.entries(config.schemas).map(([name, schemaConfig]) => [name, {
138
- schema: resolve(schemaConfig.schema),
139
- runtimeAdapter: resolve(schemaConfig.runtimeAdapter),
140
- scalars: resolve(schemaConfig.scalars)
160
+ schema: resolve(configDir, schemaConfig.schema),
161
+ runtimeAdapter: resolve(configDir, schemaConfig.runtimeAdapter),
162
+ scalars: resolve(configDir, schemaConfig.scalars)
141
163
  }])),
142
164
  plugins: config.plugins ?? {}
143
165
  };
@@ -180,7 +202,11 @@ function loadConfig(configPath) {
180
202
  }));
181
203
  }
182
204
  try {
183
- return normalizeConfig(executeConfigFile(resolvedPath));
205
+ const result = executeConfigFile(resolvedPath);
206
+ if (result.isErr()) {
207
+ return err(result.error);
208
+ }
209
+ return normalizeConfig(result.value, resolvedPath);
184
210
  } catch (error) {
185
211
  return err(configError({
186
212
  code: "CONFIG_LOAD_FAILED",
@@ -201,11 +227,20 @@ function loadConfigFrom(dir) {
201
227
  //#endregion
202
228
  //#region packages/config/src/test-utils.ts
203
229
  /**
230
+ * Get project root from this package location.
231
+ * packages/config/src/test-utils.ts -> project root
232
+ */
233
+ const getProjectRoot = () => {
234
+ return fileURLToPath(new URL("../../../", import.meta.url));
235
+ };
236
+ /**
204
237
  * Create temporary config file with proper formatting.
205
238
  * Uses template literals to support functions, regex, etc.
206
239
  */
207
240
  async function withTempConfig(config, fn) {
208
- const tmpDir = mkdtempSync(join(tmpdir(), "soda-gql-test-"));
241
+ const projectRoot = getProjectRoot();
242
+ const tmpDir = join(projectRoot, "tests/.tmp/config-test", `${Date.now()}`);
243
+ mkdirSync(tmpDir, { recursive: true });
209
244
  const configPath = join(tmpDir, "soda-gql.config.ts");
210
245
  const configContent = `
211
246
  import { defineConfig } from "@soda-gql/config";
@@ -225,11 +260,29 @@ export default defineConfig(${JSON.stringify(config, null, 2)});
225
260
  */
226
261
  function createTempConfigFile(dir, config) {
227
262
  const configPath = join(dir, "soda-gql.config.ts");
228
- const configContent = `export default ${JSON.stringify(config, null, 2)};`;
263
+ const configContent = `
264
+ import { defineConfig } from "@soda-gql/config";
265
+
266
+ export default defineConfig(${JSON.stringify(config, null, 2)});
267
+ `.trim();
229
268
  writeFileSync(configPath, configContent);
230
269
  return configPath;
231
270
  }
232
271
 
272
+ //#endregion
273
+ //#region packages/config/src/index.ts
274
+ var src_exports = /* @__PURE__ */ __export({
275
+ configError: () => configError,
276
+ createTempConfigFile: () => createTempConfigFile,
277
+ defineConfig: () => defineConfig,
278
+ findConfigFile: () => findConfigFile,
279
+ loadConfig: () => loadConfig,
280
+ loadConfigFrom: () => loadConfigFrom,
281
+ normalizeConfig: () => normalizeConfig,
282
+ validateConfig: () => validateConfig,
283
+ withTempConfig: () => withTempConfig
284
+ });
285
+
233
286
  //#endregion
234
287
  export { configError, createTempConfigFile, defineConfig, findConfigFile, loadConfig, loadConfigFrom, normalizeConfig, validateConfig, withTempConfig };
235
- //# sourceMappingURL=index.js.map
288
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["config: SodaGqlConfig","resolve","mod: { exports: unknown }","configModule","dirname","resolved: ResolvedSodaGqlConfig"],"sources":["../src/errors.ts","../src/helper.ts","../src/evaluation.ts","../src/normalize.ts","../src/loader.ts","../src/test-utils.ts","../src/index.ts"],"sourcesContent":["export type ConfigErrorCode = \"CONFIG_NOT_FOUND\" | \"CONFIG_LOAD_FAILED\" | \"CONFIG_VALIDATION_FAILED\" | \"CONFIG_INVALID_PATH\";\n\nexport type ConfigError = {\n readonly code: ConfigErrorCode;\n readonly message: string;\n readonly filePath?: string;\n readonly cause?: unknown;\n};\n\nexport const configError = ({\n code,\n message,\n filePath,\n cause,\n}: {\n code: ConfigErrorCode;\n message: string;\n filePath?: string;\n cause?: unknown;\n}): ConfigError => ({\n code,\n message,\n filePath,\n cause,\n});\n","import { defineSchemaFor } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport z from \"zod\";\nimport { type ConfigError, configError } from \"./errors\";\nimport type { SchemaConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Thin wrapper class to simplify the validation of exported value from config file.\n * As we use SWC + VM to execute the config file, the exported value is not typed.\n * This wrapper class ensures the exported value is a valid soda-gql config object.\n */\nexport class SodaGqlConfigContainer {\n private constructor(public readonly config: SodaGqlConfig) {}\n\n public static create(config: SodaGqlConfig): SodaGqlConfigContainer {\n return new SodaGqlConfigContainer(config);\n }\n}\n\n/**\n * Type-safe helper for defining soda-gql configuration.\n * Supports both static and dynamic (async) configs.\n *\n * @example Static config\n * ```ts\n * import { defineConfig } from \"@soda-gql/config\";\n *\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * });\n * ```\n *\n * @example Async config\n * ```ts\n * export default defineConfig(async () => ({\n * outdir: await resolveOutputDir(),\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * }));\n * ```\n */\nexport function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: () => SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: SodaGqlConfig | (() => SodaGqlConfig)): SodaGqlConfigContainer {\n const validated = validateConfig(typeof config === \"function\" ? config() : config);\n if (validated.isErr()) {\n throw validated.error;\n }\n return SodaGqlConfigContainer.create(validated.value);\n}\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n runtimeAdapter: z.string().min(1),\n scalars: z.string().min(1),\n});\n\nconst SodaGqlConfigSchema = defineSchemaFor<SodaGqlConfig>()({\n analyzer: z.enum([\"ts\", \"swc\"]).optional(),\n outdir: z.string().min(1),\n graphqlSystemAliases: z.array(z.string()).optional(),\n include: z.array(z.string().min(1)),\n exclude: z.array(z.string().min(1)).optional(),\n schemas: z.record(z.string(), SchemaConfigSchema),\n plugins: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport function validateConfig(config: unknown): Result<SodaGqlConfig, ConfigError> {\n const result = SodaGqlConfigSchema.safeParse(config);\n\n if (!result.success) {\n return err(\n configError({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: `Invalid config: ${result.error.message}`,\n }),\n );\n }\n\n return ok(result.data satisfies SodaGqlConfig);\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path/posix\";\nimport { Script } from \"node:vm\";\nimport { resolveRelativeImportWithExistenceCheck } from \"@soda-gql/common\";\nimport { transformSync } from \"@swc/core\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport { type ConfigError, configError } from \"./errors\";\nimport { SodaGqlConfigContainer } from \"./helper\";\n// TODO: split config package into definition and evaluation parts\nimport * as configModule from \"./index\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Load and execute TypeScript config file synchronously using SWC + VM.\n */\nexport function executeConfigFile(configPath: string): Result<SodaGqlConfig, ConfigError> {\n const filePath = resolve(configPath);\n try {\n // Read the config file\n const source = readFileSync(filePath, \"utf-8\");\n\n // Transform TypeScript to CommonJS using SWC\n const result = transformSync(source, {\n filename: filePath,\n jsc: {\n parser: {\n syntax: \"typescript\",\n },\n },\n module: {\n type: \"commonjs\",\n },\n sourceMaps: false,\n minify: false,\n });\n\n // Create CommonJS context\n const mod: { exports: unknown } = { exports: {} };\n\n const requireInner = createRequire(filePath);\n const require = (specifier: string) => {\n if (specifier === \"@soda-gql/config\") {\n return configModule;\n }\n\n // Handle external modules normally\n if (!specifier.startsWith(\".\")) {\n return requireInner(specifier);\n }\n\n // Resolve relative imports with existence check\n const resolvedPath = resolveRelativeImportWithExistenceCheck({ filePath, specifier });\n if (!resolvedPath) {\n throw new Error(`Module not found: ${specifier}`);\n }\n return requireInner(resolvedPath);\n };\n\n // Execute in VM context\n new Script(result.code, { filename: filePath }).runInNewContext({\n require,\n module: mod,\n exports: mod.exports,\n __dirname: dirname(filePath),\n __filename: filePath,\n console,\n process,\n });\n\n const config =\n mod.exports &&\n typeof mod.exports === \"object\" &&\n \"default\" in mod.exports &&\n mod.exports.default instanceof SodaGqlConfigContainer\n ? mod.exports.default.config\n : null;\n\n if (!config) {\n throw new Error(\"Invalid config module\");\n }\n\n return ok(config);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,\n filePath: filePath,\n cause: error,\n }),\n );\n }\n}\n","import { dirname, resolve } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { ok } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport type { ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Resolve and normalize config with defaults.\n * Paths in the config are resolved relative to the config file's directory.\n */\nexport function normalizeConfig(config: SodaGqlConfig, configPath: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configDir = dirname(configPath);\n // Default analyzer to \"ts\"\n const analyzer = config.analyzer ?? \"ts\";\n\n // Default graphqlSystemAliases to [\"@/graphql-system\"]\n const graphqlSystemAliases = config.graphqlSystemAliases ?? [\"@/graphql-system\"];\n\n // Default exclude to empty array\n const exclude = config.exclude ?? [];\n\n const resolved: ResolvedSodaGqlConfig = {\n analyzer,\n outdir: resolve(configDir, config.outdir),\n graphqlSystemAliases,\n include: config.include.map((pattern) => resolve(configDir, pattern)),\n exclude: exclude.map((pattern) => resolve(configDir, pattern)),\n schemas: Object.fromEntries(\n Object.entries(config.schemas).map(([name, schemaConfig]) => [\n name,\n {\n schema: resolve(configDir, schemaConfig.schema),\n runtimeAdapter: resolve(configDir, schemaConfig.runtimeAdapter),\n scalars: resolve(configDir, schemaConfig.scalars),\n },\n ]),\n ),\n plugins: config.plugins ?? {},\n };\n\n return ok(resolved);\n}\n","import { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { err } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport { configError } from \"./errors\";\nimport { executeConfigFile } from \"./evaluation\";\nimport { normalizeConfig } from \"./normalize\";\nimport type { ResolvedSodaGqlConfig } from \"./types\";\n\nexport const DEFAULT_CONFIG_FILENAMES = [\n \"soda-gql.config.ts\",\n \"soda-gql.config.mts\",\n \"soda-gql.config.js\",\n \"soda-gql.config.mjs\",\n] as const;\n\n/**\n * Find config file by walking up directory tree.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n while (currentDir !== dirname(currentDir)) {\n for (const filename of DEFAULT_CONFIG_FILENAMES) {\n const configPath = join(currentDir, filename);\n if (existsSync(configPath)) {\n return configPath;\n }\n }\n currentDir = dirname(currentDir);\n }\n return null;\n}\n\n/**\n * Load config with Result type (for library use).\n */\nexport function loadConfig(configPath: string | undefined): Result<ResolvedSodaGqlConfig, ConfigError> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return err(configError({ code: \"CONFIG_NOT_FOUND\", message: \"Config file not found\" }));\n }\n\n try {\n const result = executeConfigFile(resolvedPath);\n if (result.isErr()) {\n return err(result.error);\n }\n return normalizeConfig(result.value, resolvedPath);\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error}`,\n filePath: resolvedPath,\n cause: error,\n }),\n );\n }\n}\n\n/**\n * Load config from specific directory.\n */\nexport function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configPath = findConfigFile(dir);\n return loadConfig(configPath ?? undefined);\n}\n","import { mkdirSync, rmSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Get project root from this package location.\n * packages/config/src/test-utils.ts -> project root\n */\nconst getProjectRoot = (): string => {\n return fileURLToPath(new URL(\"../../../\", import.meta.url));\n};\n\n/**\n * Create temporary config file with proper formatting.\n * Uses template literals to support functions, regex, etc.\n */\nexport async function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T> {\n const projectRoot = getProjectRoot();\n const tmpDir = join(projectRoot, \"tests/.tmp/config-test\", `${Date.now()}`);\n mkdirSync(tmpDir, { recursive: true });\n const configPath = join(tmpDir, \"soda-gql.config.ts\");\n\n // Generate config file using template\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n\n return fn(configPath).finally(() => {\n rmSync(tmpDir, { recursive: true, force: true });\n });\n}\n\n/**\n * Simple temp config creation (without auto-cleanup).\n */\nexport function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string {\n const configPath = join(dir, \"soda-gql.config.ts\");\n\n // Write config as TypeScript module\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n return configPath;\n}\n","export type { ConfigError, ConfigErrorCode } from \"./errors\";\nexport { configError } from \"./errors\";\nexport { defineConfig, validateConfig } from \"./helper\";\nexport {\n findConfigFile,\n loadConfig,\n loadConfigFrom,\n} from \"./loader\";\nexport { normalizeConfig } from \"./normalize\";\nexport { createTempConfigFile, withTempConfig } from \"./test-utils\";\nexport type {\n PluginConfig,\n ResolvedSodaGqlConfig,\n SchemaConfig,\n SodaGqlConfig,\n} from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAa,eAAe,EAC1B,MACA,SACA,UACA,aAMkB;CAClB;CACA;CACA;CACA;CACD;;;;;;;;;ACbD,IAAa,yBAAb,MAAa,uBAAuB;CAClC,AAAQ,YAAY,AAAgBA,QAAuB;EAAvB;;C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,aAAa,eAAe,IAAI;AACtC,QAAO,WAAW,cAAc,UAAU;;;;;;;;;AC1D5C,MAAM,uBAA+B;AACnC,QAAO,cAAc,IAAI,IAAI,aAAa,OAAO,KAAK,IAAI,CAAC;;;;;;AAO7D,eAAsB,eAAkB,QAAgC,IAAoD;CAC1H,MAAM,cAAc,gBAAgB;CACpC,MAAM,SAAS,KAAK,aAAa,0BAA0B,GAAG,KAAK,KAAK,GAAG;AAC3E,WAAU,QAAQ,EAAE,WAAW,MAAM,CAAC;CACtC,MAAM,aAAa,KAAK,QAAQ,qBAAqB;CAGrD,MAAM,gBAAgB;;;8BAGM,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;EAC5D,MAAM;AAEN,eAAc,YAAY,cAAc;AAExC,QAAO,GAAG,WAAW,CAAC,cAAc;AAClC,SAAO,QAAQ;GAAE,WAAW;GAAM,OAAO;GAAM,CAAC;GAChD;;;;;AAMJ,SAAgB,qBAAqB,KAAa,QAAwC;CACxF,MAAM,aAAa,KAAK,KAAK,qBAAqB;CAGlD,MAAM,gBAAgB;;;8BAGM,KAAK,UAAU,QAAQ,MAAM,EAAE,CAAC;EAC5D,MAAM;AAEN,eAAc,YAAY,cAAc;AACxC,QAAO"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soda-gql/config",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "Centralized configuration loader and helpers for soda-gql tooling.",
5
5
  "type": "module",
6
6
  "private": false,
@@ -27,7 +27,7 @@
27
27
  "./package.json": "./package.json"
28
28
  },
29
29
  "dependencies": {
30
- "@soda-gql/common": "0.0.1",
30
+ "@soda-gql/common": "0.0.3",
31
31
  "@swc/core": "^1.10.0",
32
32
  "neverthrow": "^8.2.0",
33
33
  "zod": "^4.1.11"
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/errors.ts","../src/types.ts","../src/helper.ts","../src/loader.ts","../src/normalize.ts","../src/test-utils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AAA,CLrBY,GAAA,EAAA,MAAA,EAAA,MAAA,EKqB8B,OLrB9B,CKqBsC,aLrBtC,CAAA,CAAA,EAAA,MAAA"}
package/dist/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":["config: SodaGqlConfig","resolve","mod: { exports: unknown }","dirname","resolved: ResolvedSodaGqlConfig"],"sources":["../src/errors.ts","../src/helper.ts","../src/evaluation.ts","../src/normalize.ts","../src/loader.ts","../src/test-utils.ts"],"sourcesContent":["export type ConfigErrorCode = \"CONFIG_NOT_FOUND\" | \"CONFIG_LOAD_FAILED\" | \"CONFIG_VALIDATION_FAILED\" | \"CONFIG_INVALID_PATH\";\n\nexport type ConfigError = {\n readonly code: ConfigErrorCode;\n readonly message: string;\n readonly filePath?: string;\n readonly cause?: unknown;\n};\n\nexport const configError = ({\n code,\n message,\n filePath,\n cause,\n}: {\n code: ConfigErrorCode;\n message: string;\n filePath?: string;\n cause?: unknown;\n}): ConfigError => ({\n code,\n message,\n filePath,\n cause,\n});\n","import { defineSchemaFor } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport z from \"zod\";\nimport { type ConfigError, configError } from \"./errors\";\nimport type { SchemaConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Thin wrapper class to simplify the validation of exported value from config file.\n * As we use SWC + VM to execute the config file, the exported value is not typed.\n * This wrapper class ensures the exported value is a valid soda-gql config object.\n */\nexport class SodaGqlConfigContainer {\n private constructor(public readonly config: SodaGqlConfig) {}\n\n public static create(config: SodaGqlConfig): SodaGqlConfigContainer {\n return new SodaGqlConfigContainer(config);\n }\n}\n\n/**\n * Type-safe helper for defining soda-gql configuration.\n * Supports both static and dynamic (async) configs.\n *\n * @example Static config\n * ```ts\n * import { defineConfig } from \"@soda-gql/config\";\n *\n * export default defineConfig({\n * outdir: \"./graphql-system\",\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * });\n * ```\n *\n * @example Async config\n * ```ts\n * export default defineConfig(async () => ({\n * outdir: await resolveOutputDir(),\n * include: [\"./src/**\\/*.ts\"],\n * schemas: {\n * default: {\n * schema: \"./schema.graphql\",\n * runtimeAdapter: \"./runtime-adapter.ts\",\n * scalars: \"./scalars.ts\",\n * },\n * },\n * }));\n * ```\n */\nexport function defineConfig(config: SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: () => SodaGqlConfig): SodaGqlConfigContainer;\nexport function defineConfig(config: SodaGqlConfig | (() => SodaGqlConfig)): SodaGqlConfigContainer {\n const validated = validateConfig(typeof config === \"function\" ? config() : config);\n if (validated.isErr()) {\n throw validated.error;\n }\n return SodaGqlConfigContainer.create(validated.value);\n}\n\nconst SchemaConfigSchema = defineSchemaFor<SchemaConfig>()({\n schema: z.string().min(1),\n runtimeAdapter: z.string().min(1),\n scalars: z.string().min(1),\n});\n\nconst SodaGqlConfigSchema = defineSchemaFor<SodaGqlConfig>()({\n analyzer: z.enum([\"ts\", \"swc\"]).optional(),\n outdir: z.string().min(1),\n graphqlSystemAliases: z.array(z.string()).optional(),\n include: z.array(z.string().min(1)),\n exclude: z.array(z.string().min(1)).optional(),\n schemas: z.record(z.string(), SchemaConfigSchema),\n plugins: z.record(z.string(), z.unknown()).optional(),\n});\n\nexport function validateConfig(config: unknown): Result<SodaGqlConfig, ConfigError> {\n const result = SodaGqlConfigSchema.safeParse(config);\n\n if (!result.success) {\n return err(\n configError({\n code: \"CONFIG_VALIDATION_FAILED\",\n message: `Invalid config: ${result.error.message}`,\n }),\n );\n }\n\n return ok(result.data satisfies SodaGqlConfig);\n}\n","import { readFileSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport { dirname, resolve } from \"node:path/posix\";\nimport { Script } from \"node:vm\";\nimport { resolveRelativeImportWithExistenceCheck } from \"@soda-gql/common\";\nimport { transformSync } from \"@swc/core\";\nimport { configError } from \"./errors\";\nimport { SodaGqlConfigContainer } from \"./helper\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Load and execute TypeScript config file synchronously using SWC + VM.\n */\nexport function executeConfigFile(configPath: string): SodaGqlConfig {\n const filePath = resolve(configPath);\n try {\n // Read the config file\n const source = readFileSync(filePath, \"utf-8\");\n\n // Transform TypeScript to CommonJS using SWC\n const result = transformSync(source, {\n filename: filePath,\n jsc: {\n parser: {\n syntax: \"typescript\",\n },\n },\n module: {\n type: \"commonjs\",\n },\n sourceMaps: false,\n minify: false,\n });\n\n // Create CommonJS context\n const mod: { exports: unknown } = { exports: {} };\n\n const requireInner = createRequire(filePath);\n const require = (specifier: string) => {\n // Handle external modules normally\n if (!specifier.startsWith(\".\")) {\n return requireInner(specifier);\n }\n\n // Resolve relative imports with existence check\n const resolvedPath = resolveRelativeImportWithExistenceCheck({ filePath, specifier });\n if (!resolvedPath) {\n throw new Error(`Module not found: ${specifier}`);\n }\n return requireInner(resolvedPath);\n };\n\n // Execute in VM context\n new Script(result.code, { filename: filePath }).runInNewContext({\n require,\n module: mod,\n exports: mod.exports,\n __dirname: dirname(filePath),\n __filename: filePath,\n console,\n process,\n });\n\n const config =\n mod.exports &&\n typeof mod.exports === \"object\" &&\n \"default\" in mod.exports &&\n mod.exports.default instanceof SodaGqlConfigContainer\n ? mod.exports.default.config\n : null;\n\n if (!config) {\n throw new Error(\"Invalid config module\");\n }\n\n return config;\n } catch (error) {\n throw configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error instanceof Error ? error.message : String(error)}`,\n filePath: filePath,\n cause: error,\n });\n }\n}\n","import { resolve } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { ok } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport type { ResolvedSodaGqlConfig, SodaGqlConfig } from \"./types\";\n\n/**\n * Resolve and normalize config with defaults.\n */\nexport function normalizeConfig(config: SodaGqlConfig): Result<ResolvedSodaGqlConfig, ConfigError> {\n // Default analyzer to \"ts\"\n const analyzer = config.analyzer ?? \"ts\";\n\n // Default graphqlSystemAliases to [\"@/graphql-system\"]\n const graphqlSystemAliases = config.graphqlSystemAliases ?? [\"@/graphql-system\"];\n\n // Default exclude to empty array\n const exclude = config.exclude ?? [];\n\n const resolved: ResolvedSodaGqlConfig = {\n analyzer,\n outdir: resolve(config.outdir),\n graphqlSystemAliases,\n include: config.include.map((pattern) => resolve(pattern)),\n exclude: exclude.map((pattern) => resolve(pattern)),\n schemas: Object.fromEntries(\n Object.entries(config.schemas).map(([name, schemaConfig]) => [\n name,\n {\n schema: resolve(schemaConfig.schema),\n runtimeAdapter: resolve(schemaConfig.runtimeAdapter),\n scalars: resolve(schemaConfig.scalars),\n },\n ]),\n ),\n plugins: config.plugins ?? {},\n };\n\n return ok(resolved);\n}\n","import { existsSync } from \"node:fs\";\nimport { dirname, join } from \"node:path\";\nimport type { Result } from \"neverthrow\";\nimport { err } from \"neverthrow\";\nimport type { ConfigError } from \"./errors\";\nimport { configError } from \"./errors\";\nimport { executeConfigFile } from \"./evaluation\";\nimport { normalizeConfig } from \"./normalize\";\nimport type { ResolvedSodaGqlConfig } from \"./types\";\n\nexport const DEFAULT_CONFIG_FILENAMES = [\n \"soda-gql.config.ts\",\n \"soda-gql.config.mts\",\n \"soda-gql.config.js\",\n \"soda-gql.config.mjs\",\n] as const;\n\n/**\n * Find config file by walking up directory tree.\n */\nexport function findConfigFile(startDir: string = process.cwd()): string | null {\n let currentDir = startDir;\n while (currentDir !== dirname(currentDir)) {\n for (const filename of DEFAULT_CONFIG_FILENAMES) {\n const configPath = join(currentDir, filename);\n if (existsSync(configPath)) {\n return configPath;\n }\n }\n currentDir = dirname(currentDir);\n }\n return null;\n}\n\n/**\n * Load config with Result type (for library use).\n */\nexport function loadConfig(configPath: string | undefined): Result<ResolvedSodaGqlConfig, ConfigError> {\n const resolvedPath = configPath ?? findConfigFile();\n\n if (!resolvedPath) {\n return err(configError({ code: \"CONFIG_NOT_FOUND\", message: \"Config file not found\" }));\n }\n\n try {\n return normalizeConfig(executeConfigFile(resolvedPath));\n } catch (error) {\n return err(\n configError({\n code: \"CONFIG_LOAD_FAILED\",\n message: `Failed to load config: ${error}`,\n filePath: resolvedPath,\n cause: error,\n }),\n );\n }\n}\n\n/**\n * Load config from specific directory.\n */\nexport function loadConfigFrom(dir: string): Result<ResolvedSodaGqlConfig, ConfigError> {\n const configPath = findConfigFile(dir);\n return loadConfig(configPath ?? undefined);\n}\n","import { mkdtempSync, rmSync, writeFileSync } from \"node:fs\";\nimport { tmpdir } from \"node:os\";\nimport { join } from \"node:path\";\nimport type { SodaGqlConfig } from \"./types\";\n\n/**\n * Create temporary config file with proper formatting.\n * Uses template literals to support functions, regex, etc.\n */\nexport async function withTempConfig<T>(config: Partial<SodaGqlConfig>, fn: (configPath: string) => Promise<T>): Promise<T> {\n const tmpDir = mkdtempSync(join(tmpdir(), \"soda-gql-test-\"));\n const configPath = join(tmpDir, \"soda-gql.config.ts\");\n\n // Generate config file using template\n const configContent = `\nimport { defineConfig } from \"@soda-gql/config\";\n\nexport default defineConfig(${JSON.stringify(config, null, 2)});\n`.trim();\n\n writeFileSync(configPath, configContent);\n\n return fn(configPath).finally(() => {\n rmSync(tmpDir, { recursive: true, force: true });\n });\n}\n\n/**\n * Simple temp config creation (without auto-cleanup).\n */\nexport function createTempConfigFile(dir: string, config: Partial<SodaGqlConfig>): string {\n const configPath = join(dir, \"soda-gql.config.ts\");\n\n // Write config as direct export (no imports needed for simple configs)\n const configContent = `export default ${JSON.stringify(config, null, 2)};`;\n\n writeFileSync(configPath, configContent);\n return configPath;\n}\n"],"mappings":";;;;;;;;;;;;AASA,MAAa,eAAe,EAC1B,MACA,SACA,UACA,aAMkB;CAClB;CACA;CACA;CACA;CACD;;;;;;;;;ACbD,IAAa,yBAAb,MAAa,uBAAuB;CAClC,AAAQ,YAAY,AAAgBA,QAAuB;EAAvB;;CAEpC,OAAc,OAAO,QAA+C;AAClE,S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