houdini 1.2.30 → 1.2.32

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.
@@ -98,6 +98,15 @@ export type PluginHooks = {
98
98
  esm: string;
99
99
  commonjs: string;
100
100
  };
101
+ /**
102
+ * A relative path from the file exporting your plugin to a runtime that can be
103
+ * added to the project before generating artifacts. This is useful for plugins
104
+ * that want to add third-party documents to the user's application.
105
+ */
106
+ staticRuntime?: string | {
107
+ esm: string;
108
+ commonjs: string;
109
+ };
101
110
  /**
102
111
  * Transform the plugin's runtime while houdini is copying it .
103
112
  * You must have passed a value to includeRuntime for this hook to matter.
@@ -67169,7 +67169,15 @@ var Config = class {
67169
67169
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
67170
67170
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
67171
67171
  );
67172
- return [`src/**/*{${extensions.join(",")}}`];
67172
+ const include = [`src/**/*{${extensions.join(",")}}`];
67173
+ for (const plugin2 of this.plugins) {
67174
+ if (!plugin2.includeRuntime) {
67175
+ continue;
67176
+ }
67177
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
67178
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
67179
+ }
67180
+ return include;
67173
67181
  }
67174
67182
  pluginConfig(name) {
67175
67183
  return this.configFile.plugins?.[name] ?? {};
@@ -67090,7 +67090,15 @@ var Config = class {
67090
67090
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
67091
67091
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
67092
67092
  );
67093
- return [`src/**/*{${extensions.join(",")}}`];
67093
+ const include = [`src/**/*{${extensions.join(",")}}`];
67094
+ for (const plugin2 of this.plugins) {
67095
+ if (!plugin2.includeRuntime) {
67096
+ continue;
67097
+ }
67098
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
67099
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
67100
+ }
67101
+ return include;
67094
67102
  }
67095
67103
  pluginConfig(name) {
67096
67104
  return this.configFile.plugins?.[name] ?? {};
@@ -57397,7 +57397,15 @@ var Config = class {
57397
57397
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
57398
57398
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
57399
57399
  );
57400
- return [`src/**/*{${extensions.join(",")}}`];
57400
+ const include = [`src/**/*{${extensions.join(",")}}`];
57401
+ for (const plugin2 of this.plugins) {
57402
+ if (!plugin2.includeRuntime) {
57403
+ continue;
57404
+ }
57405
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
57406
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
57407
+ }
57408
+ return include;
57401
57409
  }
57402
57410
  pluginConfig(name) {
57403
57411
  return this.configFile.plugins?.[name] ?? {};
@@ -61225,9 +61233,11 @@ ${exportStatement("plugins")}
61225
61233
 
61226
61234
  // src/codegen/generators/runtime/index.ts
61227
61235
  async function runtimeGenerator(config, docs) {
61228
- const importStatement = config.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
61229
- const exportStatement = config.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
61230
- const exportStar = config.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
61236
+ const {
61237
+ importStatement,
61238
+ exportDefaultStatement: exportStatement,
61239
+ exportStarStatement: exportStar
61240
+ } = moduleStatments(config);
61231
61241
  await Promise.all([
61232
61242
  fs_exports.recursiveCopy(config.runtimeSource, config.runtimeDirectory, {
61233
61243
  [path_exports.join(config.runtimeSource, "lib", "constants.js")]: (content) => {
@@ -61245,66 +61255,47 @@ ${exportStatement("config")}
61245
61255
  },
61246
61256
  [path_exports.join(config.runtimeSource, "client", "plugins", "injectedPlugins.js")]: (content) => injectPlugins({ config, content, importStatement, exportStatement })
61247
61257
  }),
61248
- ...config.plugins.filter((plugin2) => plugin2.includeRuntime).map(
61249
- (plugin2) => generatePluginRuntime({
61250
- config,
61251
- docs,
61252
- plugin: plugin2,
61253
- importStatement,
61254
- exportDefaultStatement: exportStatement,
61255
- exportStarStatement: exportStar
61256
- })
61257
- ),
61258
+ transformPluginRuntimes({ config, docs }),
61258
61259
  generatePluginIndex({ config, exportStatement: exportStar })
61259
61260
  ]);
61260
61261
  await generateGraphqlReturnTypes(config, docs);
61261
61262
  }
61262
- async function generatePluginRuntime({
61263
- config,
61264
- docs,
61265
- plugin: plugin2,
61266
- importStatement,
61267
- exportDefaultStatement,
61268
- exportStarStatement
61269
- }) {
61270
- if (houdini_mode.is_testing || !plugin2.includeRuntime) {
61271
- return;
61272
- }
61273
- const runtime_path = path_exports.join(
61274
- path_exports.dirname(plugin2.filepath),
61275
- typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config.module]
61276
- );
61277
- try {
61278
- await fs_exports.stat(runtime_path);
61279
- } catch {
61280
- throw new HoudiniError({
61281
- message: "Cannot find runtime to generate for " + plugin2.name,
61282
- description: "Maybe it was bundled?"
61283
- });
61284
- }
61285
- const pluginDir = config.pluginRuntimeDirectory(plugin2.name);
61286
- let transformMap = plugin2.transformRuntime ?? {};
61287
- if (transformMap && typeof transformMap === "function") {
61288
- transformMap = transformMap(docs, { config });
61289
- }
61290
- await fs_exports.mkdirp(pluginDir);
61291
- await fs_exports.recursiveCopy(
61292
- runtime_path,
61293
- pluginDir,
61294
- Object.fromEntries(
61295
- Object.entries(transformMap).map(([key, value]) => [
61296
- path_exports.join(runtime_path, key),
61297
- (content) => value({
61263
+ async function transformPluginRuntimes({ config, docs }) {
61264
+ const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config);
61265
+ await Promise.all(
61266
+ config.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
61267
+ let transformMap = plugin2.transformRuntime ?? {};
61268
+ if (transformMap && typeof transformMap === "function") {
61269
+ transformMap = transformMap(docs, { config });
61270
+ }
61271
+ for (const [target, transform] of Object.entries(transformMap)) {
61272
+ const targetPath = path_exports.join(config.pluginRuntimeDirectory(plugin2.name), target);
61273
+ const content = await fs_exports.readFile(targetPath);
61274
+ if (!content) {
61275
+ return;
61276
+ }
61277
+ const transformed = transform({
61298
61278
  config,
61299
61279
  content,
61300
61280
  importStatement,
61301
61281
  exportDefaultStatement,
61302
61282
  exportStarStatement
61303
- })
61304
- ])
61305
- )
61283
+ });
61284
+ await fs_exports.writeFile(targetPath, transformed);
61285
+ }
61286
+ })
61306
61287
  );
61307
61288
  }
61289
+ function moduleStatments(config) {
61290
+ const importStatement = config.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
61291
+ const exportDefaultStatement = config.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
61292
+ const exportStarStatement = config.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
61293
+ return {
61294
+ importStatement,
61295
+ exportDefaultStatement,
61296
+ exportStarStatement
61297
+ };
61298
+ }
61308
61299
 
61309
61300
  // src/codegen/generators/typescript/documentTypes.ts
61310
61301
  var recast12 = __toESM(require_main2(), 1);
@@ -57393,7 +57393,15 @@ var Config = class {
57393
57393
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
57394
57394
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
57395
57395
  );
57396
- return [`src/**/*{${extensions.join(",")}}`];
57396
+ const include = [`src/**/*{${extensions.join(",")}}`];
57397
+ for (const plugin2 of this.plugins) {
57398
+ if (!plugin2.includeRuntime) {
57399
+ continue;
57400
+ }
57401
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
57402
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
57403
+ }
57404
+ return include;
57397
57405
  }
57398
57406
  pluginConfig(name) {
57399
57407
  return this.configFile.plugins?.[name] ?? {};
@@ -61221,9 +61229,11 @@ ${exportStatement("plugins")}
61221
61229
 
61222
61230
  // src/codegen/generators/runtime/index.ts
61223
61231
  async function runtimeGenerator(config, docs) {
61224
- const importStatement = config.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
61225
- const exportStatement = config.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
61226
- const exportStar = config.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
61232
+ const {
61233
+ importStatement,
61234
+ exportDefaultStatement: exportStatement,
61235
+ exportStarStatement: exportStar
61236
+ } = moduleStatments(config);
61227
61237
  await Promise.all([
61228
61238
  fs_exports.recursiveCopy(config.runtimeSource, config.runtimeDirectory, {
61229
61239
  [path_exports.join(config.runtimeSource, "lib", "constants.js")]: (content) => {
@@ -61241,66 +61251,47 @@ ${exportStatement("config")}
61241
61251
  },
61242
61252
  [path_exports.join(config.runtimeSource, "client", "plugins", "injectedPlugins.js")]: (content) => injectPlugins({ config, content, importStatement, exportStatement })
61243
61253
  }),
61244
- ...config.plugins.filter((plugin2) => plugin2.includeRuntime).map(
61245
- (plugin2) => generatePluginRuntime({
61246
- config,
61247
- docs,
61248
- plugin: plugin2,
61249
- importStatement,
61250
- exportDefaultStatement: exportStatement,
61251
- exportStarStatement: exportStar
61252
- })
61253
- ),
61254
+ transformPluginRuntimes({ config, docs }),
61254
61255
  generatePluginIndex({ config, exportStatement: exportStar })
61255
61256
  ]);
61256
61257
  await generateGraphqlReturnTypes(config, docs);
61257
61258
  }
61258
- async function generatePluginRuntime({
61259
- config,
61260
- docs,
61261
- plugin: plugin2,
61262
- importStatement,
61263
- exportDefaultStatement,
61264
- exportStarStatement
61265
- }) {
61266
- if (houdini_mode.is_testing || !plugin2.includeRuntime) {
61267
- return;
61268
- }
61269
- const runtime_path = path_exports.join(
61270
- path_exports.dirname(plugin2.filepath),
61271
- typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config.module]
61272
- );
61273
- try {
61274
- await fs_exports.stat(runtime_path);
61275
- } catch {
61276
- throw new HoudiniError({
61277
- message: "Cannot find runtime to generate for " + plugin2.name,
61278
- description: "Maybe it was bundled?"
61279
- });
61280
- }
61281
- const pluginDir = config.pluginRuntimeDirectory(plugin2.name);
61282
- let transformMap = plugin2.transformRuntime ?? {};
61283
- if (transformMap && typeof transformMap === "function") {
61284
- transformMap = transformMap(docs, { config });
61285
- }
61286
- await fs_exports.mkdirp(pluginDir);
61287
- await fs_exports.recursiveCopy(
61288
- runtime_path,
61289
- pluginDir,
61290
- Object.fromEntries(
61291
- Object.entries(transformMap).map(([key, value]) => [
61292
- path_exports.join(runtime_path, key),
61293
- (content) => value({
61259
+ async function transformPluginRuntimes({ config, docs }) {
61260
+ const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config);
61261
+ await Promise.all(
61262
+ config.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
61263
+ let transformMap = plugin2.transformRuntime ?? {};
61264
+ if (transformMap && typeof transformMap === "function") {
61265
+ transformMap = transformMap(docs, { config });
61266
+ }
61267
+ for (const [target, transform] of Object.entries(transformMap)) {
61268
+ const targetPath = path_exports.join(config.pluginRuntimeDirectory(plugin2.name), target);
61269
+ const content = await fs_exports.readFile(targetPath);
61270
+ if (!content) {
61271
+ return;
61272
+ }
61273
+ const transformed = transform({
61294
61274
  config,
61295
61275
  content,
61296
61276
  importStatement,
61297
61277
  exportDefaultStatement,
61298
61278
  exportStarStatement
61299
- })
61300
- ])
61301
- )
61279
+ });
61280
+ await fs_exports.writeFile(targetPath, transformed);
61281
+ }
61282
+ })
61302
61283
  );
61303
61284
  }
61285
+ function moduleStatments(config) {
61286
+ const importStatement = config.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
61287
+ const exportDefaultStatement = config.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
61288
+ const exportStarStatement = config.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
61289
+ return {
61290
+ importStatement,
61291
+ exportDefaultStatement,
61292
+ exportStarStatement
61293
+ };
61294
+ }
61304
61295
 
61305
61296
  // src/codegen/generators/typescript/documentTypes.ts
61306
61297
  var recast12 = __toESM(require_main2(), 1);
@@ -69153,7 +69153,15 @@ var Config = class {
69153
69153
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
69154
69154
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
69155
69155
  );
69156
- return [`src/**/*{${extensions.join(",")}}`];
69156
+ const include = [`src/**/*{${extensions.join(",")}}`];
69157
+ for (const plugin2 of this.plugins) {
69158
+ if (!plugin2.includeRuntime) {
69159
+ continue;
69160
+ }
69161
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
69162
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
69163
+ }
69164
+ return include;
69157
69165
  }
69158
69166
  pluginConfig(name) {
69159
69167
  return this.configFile.plugins?.[name] ?? {};
@@ -73916,9 +73924,11 @@ ${exportStatement("plugins")}
73916
73924
 
73917
73925
  // src/codegen/generators/runtime/index.ts
73918
73926
  async function runtimeGenerator(config2, docs) {
73919
- const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
73920
- const exportStatement = config2.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
73921
- const exportStar = config2.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
73927
+ const {
73928
+ importStatement,
73929
+ exportDefaultStatement: exportStatement,
73930
+ exportStarStatement: exportStar
73931
+ } = moduleStatments(config2);
73922
73932
  await Promise.all([
73923
73933
  fs_exports.recursiveCopy(config2.runtimeSource, config2.runtimeDirectory, {
73924
73934
  [path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
@@ -73936,66 +73946,71 @@ ${exportStatement("config")}
73936
73946
  },
73937
73947
  [path_exports.join(config2.runtimeSource, "client", "plugins", "injectedPlugins.js")]: (content) => injectPlugins({ config: config2, content, importStatement, exportStatement })
73938
73948
  }),
73939
- ...config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(
73940
- (plugin2) => generatePluginRuntime({
73941
- config: config2,
73942
- docs,
73943
- plugin: plugin2,
73944
- importStatement,
73945
- exportDefaultStatement: exportStatement,
73946
- exportStarStatement: exportStar
73947
- })
73948
- ),
73949
+ transformPluginRuntimes({ config: config2, docs }),
73949
73950
  generatePluginIndex({ config: config2, exportStatement: exportStar })
73950
73951
  ]);
73951
73952
  await generateGraphqlReturnTypes(config2, docs);
73952
73953
  }
73953
- async function generatePluginRuntime({
73954
- config: config2,
73955
- docs,
73956
- plugin: plugin2,
73957
- importStatement,
73958
- exportDefaultStatement,
73959
- exportStarStatement
73960
- }) {
73961
- if (houdini_mode.is_testing || !plugin2.includeRuntime) {
73962
- return;
73963
- }
73964
- const runtime_path = path_exports.join(
73965
- path_exports.dirname(plugin2.filepath),
73966
- typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config2.module]
73954
+ async function generatePluginRuntimes({ config: config2 }) {
73955
+ await Promise.all(
73956
+ config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
73957
+ if (houdini_mode.is_testing || !plugin2.includeRuntime) {
73958
+ return;
73959
+ }
73960
+ const runtime_path = path_exports.join(
73961
+ path_exports.dirname(plugin2.filepath),
73962
+ typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config2.module]
73963
+ );
73964
+ try {
73965
+ await fs_exports.stat(runtime_path);
73966
+ } catch {
73967
+ throw new HoudiniError({
73968
+ message: "Cannot find runtime to generate for " + plugin2.name,
73969
+ description: "Maybe it was bundled?"
73970
+ });
73971
+ }
73972
+ const pluginDir = config2.pluginRuntimeDirectory(plugin2.name);
73973
+ await fs_exports.mkdirp(pluginDir);
73974
+ await fs_exports.recursiveCopy(runtime_path, pluginDir);
73975
+ })
73967
73976
  );
73968
- try {
73969
- await fs_exports.stat(runtime_path);
73970
- } catch {
73971
- throw new HoudiniError({
73972
- message: "Cannot find runtime to generate for " + plugin2.name,
73973
- description: "Maybe it was bundled?"
73974
- });
73975
- }
73976
- const pluginDir = config2.pluginRuntimeDirectory(plugin2.name);
73977
- let transformMap = plugin2.transformRuntime ?? {};
73978
- if (transformMap && typeof transformMap === "function") {
73979
- transformMap = transformMap(docs, { config: config2 });
73980
- }
73981
- await fs_exports.mkdirp(pluginDir);
73982
- await fs_exports.recursiveCopy(
73983
- runtime_path,
73984
- pluginDir,
73985
- Object.fromEntries(
73986
- Object.entries(transformMap).map(([key, value]) => [
73987
- path_exports.join(runtime_path, key),
73988
- (content) => value({
73977
+ }
73978
+ async function transformPluginRuntimes({ config: config2, docs }) {
73979
+ const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config2);
73980
+ await Promise.all(
73981
+ config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
73982
+ let transformMap = plugin2.transformRuntime ?? {};
73983
+ if (transformMap && typeof transformMap === "function") {
73984
+ transformMap = transformMap(docs, { config: config2 });
73985
+ }
73986
+ for (const [target, transform] of Object.entries(transformMap)) {
73987
+ const targetPath = path_exports.join(config2.pluginRuntimeDirectory(plugin2.name), target);
73988
+ const content = await fs_exports.readFile(targetPath);
73989
+ if (!content) {
73990
+ return;
73991
+ }
73992
+ const transformed = transform({
73989
73993
  config: config2,
73990
73994
  content,
73991
73995
  importStatement,
73992
73996
  exportDefaultStatement,
73993
73997
  exportStarStatement
73994
- })
73995
- ])
73996
- )
73998
+ });
73999
+ await fs_exports.writeFile(targetPath, transformed);
74000
+ }
74001
+ })
73997
74002
  );
73998
74003
  }
74004
+ function moduleStatments(config2) {
74005
+ const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
74006
+ const exportDefaultStatement = config2.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
74007
+ const exportStarStatement = config2.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
74008
+ return {
74009
+ importStatement,
74010
+ exportDefaultStatement,
74011
+ exportStarStatement
74012
+ };
74013
+ }
73999
74014
 
74000
74015
  // src/codegen/generators/typescript/documentTypes.ts
74001
74016
  var recast12 = __toESM(require_main2(), 1);
@@ -78615,6 +78630,7 @@ async function componentFields2(config2, docs) {
78615
78630
 
78616
78631
  // src/codegen/index.ts
78617
78632
  async function compile(config2) {
78633
+ await generatePluginRuntimes({ config: config2 });
78618
78634
  const documents = await collectDocuments(config2);
78619
78635
  await runPipeline2(config2, documents);
78620
78636
  }
@@ -79208,6 +79224,9 @@ function find_exported_fn(body, name) {
79208
79224
  if (init.type === "TSSatisfiesExpression") {
79209
79225
  init = init.expression;
79210
79226
  }
79227
+ if (init.type === "CallExpression" && init.arguments[0] && (init.arguments[0].type === "FunctionExpression" || init.arguments[0].type === "ArrowFunctionExpression")) {
79228
+ init = init.arguments[0];
79229
+ }
79211
79230
  if (init.type === "FunctionExpression" || init.type === "ArrowFunctionExpression") {
79212
79231
  return init;
79213
79232
  }
@@ -69146,7 +69146,15 @@ var Config = class {
69146
69146
  const extensions = [".graphql", ".gql", ".ts", ".js"].concat(
69147
69147
  this.plugins.flatMap((plugin2) => plugin2.extensions ?? [])
69148
69148
  );
69149
- return [`src/**/*{${extensions.join(",")}}`];
69149
+ const include = [`src/**/*{${extensions.join(",")}}`];
69150
+ for (const plugin2 of this.plugins) {
69151
+ if (!plugin2.includeRuntime) {
69152
+ continue;
69153
+ }
69154
+ const includePath = relative(this.projectRoot, this.pluginDirectory(plugin2.name));
69155
+ include.push(`${includePath}/**/*{${extensions.join(",")}}`);
69156
+ }
69157
+ return include;
69150
69158
  }
69151
69159
  pluginConfig(name) {
69152
69160
  return this.configFile.plugins?.[name] ?? {};
@@ -73909,9 +73917,11 @@ ${exportStatement("plugins")}
73909
73917
 
73910
73918
  // src/codegen/generators/runtime/index.ts
73911
73919
  async function runtimeGenerator(config2, docs) {
73912
- const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
73913
- const exportStatement = config2.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
73914
- const exportStar = config2.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
73920
+ const {
73921
+ importStatement,
73922
+ exportDefaultStatement: exportStatement,
73923
+ exportStarStatement: exportStar
73924
+ } = moduleStatments(config2);
73915
73925
  await Promise.all([
73916
73926
  fs_exports.recursiveCopy(config2.runtimeSource, config2.runtimeDirectory, {
73917
73927
  [path_exports.join(config2.runtimeSource, "lib", "constants.js")]: (content) => {
@@ -73929,66 +73939,71 @@ ${exportStatement("config")}
73929
73939
  },
73930
73940
  [path_exports.join(config2.runtimeSource, "client", "plugins", "injectedPlugins.js")]: (content) => injectPlugins({ config: config2, content, importStatement, exportStatement })
73931
73941
  }),
73932
- ...config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(
73933
- (plugin2) => generatePluginRuntime({
73934
- config: config2,
73935
- docs,
73936
- plugin: plugin2,
73937
- importStatement,
73938
- exportDefaultStatement: exportStatement,
73939
- exportStarStatement: exportStar
73940
- })
73941
- ),
73942
+ transformPluginRuntimes({ config: config2, docs }),
73942
73943
  generatePluginIndex({ config: config2, exportStatement: exportStar })
73943
73944
  ]);
73944
73945
  await generateGraphqlReturnTypes(config2, docs);
73945
73946
  }
73946
- async function generatePluginRuntime({
73947
- config: config2,
73948
- docs,
73949
- plugin: plugin2,
73950
- importStatement,
73951
- exportDefaultStatement,
73952
- exportStarStatement
73953
- }) {
73954
- if (houdini_mode.is_testing || !plugin2.includeRuntime) {
73955
- return;
73956
- }
73957
- const runtime_path = path_exports.join(
73958
- path_exports.dirname(plugin2.filepath),
73959
- typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config2.module]
73947
+ async function generatePluginRuntimes({ config: config2 }) {
73948
+ await Promise.all(
73949
+ config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
73950
+ if (houdini_mode.is_testing || !plugin2.includeRuntime) {
73951
+ return;
73952
+ }
73953
+ const runtime_path = path_exports.join(
73954
+ path_exports.dirname(plugin2.filepath),
73955
+ typeof plugin2.includeRuntime === "string" ? plugin2.includeRuntime : plugin2.includeRuntime[config2.module]
73956
+ );
73957
+ try {
73958
+ await fs_exports.stat(runtime_path);
73959
+ } catch {
73960
+ throw new HoudiniError({
73961
+ message: "Cannot find runtime to generate for " + plugin2.name,
73962
+ description: "Maybe it was bundled?"
73963
+ });
73964
+ }
73965
+ const pluginDir = config2.pluginRuntimeDirectory(plugin2.name);
73966
+ await fs_exports.mkdirp(pluginDir);
73967
+ await fs_exports.recursiveCopy(runtime_path, pluginDir);
73968
+ })
73960
73969
  );
73961
- try {
73962
- await fs_exports.stat(runtime_path);
73963
- } catch {
73964
- throw new HoudiniError({
73965
- message: "Cannot find runtime to generate for " + plugin2.name,
73966
- description: "Maybe it was bundled?"
73967
- });
73968
- }
73969
- const pluginDir = config2.pluginRuntimeDirectory(plugin2.name);
73970
- let transformMap = plugin2.transformRuntime ?? {};
73971
- if (transformMap && typeof transformMap === "function") {
73972
- transformMap = transformMap(docs, { config: config2 });
73973
- }
73974
- await fs_exports.mkdirp(pluginDir);
73975
- await fs_exports.recursiveCopy(
73976
- runtime_path,
73977
- pluginDir,
73978
- Object.fromEntries(
73979
- Object.entries(transformMap).map(([key, value]) => [
73980
- path_exports.join(runtime_path, key),
73981
- (content) => value({
73970
+ }
73971
+ async function transformPluginRuntimes({ config: config2, docs }) {
73972
+ const { importStatement, exportDefaultStatement, exportStarStatement } = moduleStatments(config2);
73973
+ await Promise.all(
73974
+ config2.plugins.filter((plugin2) => plugin2.includeRuntime).map(async (plugin2) => {
73975
+ let transformMap = plugin2.transformRuntime ?? {};
73976
+ if (transformMap && typeof transformMap === "function") {
73977
+ transformMap = transformMap(docs, { config: config2 });
73978
+ }
73979
+ for (const [target, transform] of Object.entries(transformMap)) {
73980
+ const targetPath = path_exports.join(config2.pluginRuntimeDirectory(plugin2.name), target);
73981
+ const content = await fs_exports.readFile(targetPath);
73982
+ if (!content) {
73983
+ return;
73984
+ }
73985
+ const transformed = transform({
73982
73986
  config: config2,
73983
73987
  content,
73984
73988
  importStatement,
73985
73989
  exportDefaultStatement,
73986
73990
  exportStarStatement
73987
- })
73988
- ])
73989
- )
73991
+ });
73992
+ await fs_exports.writeFile(targetPath, transformed);
73993
+ }
73994
+ })
73990
73995
  );
73991
73996
  }
73997
+ function moduleStatments(config2) {
73998
+ const importStatement = config2.module === "commonjs" ? importDefaultFrom : (where, as) => `import ${as} from '${where}'`;
73999
+ const exportDefaultStatement = config2.module === "commonjs" ? exportDefault : (as) => `export default ${as}`;
74000
+ const exportStarStatement = config2.module === "commonjs" ? exportStarFrom : (where) => `export * from '${where}'`;
74001
+ return {
74002
+ importStatement,
74003
+ exportDefaultStatement,
74004
+ exportStarStatement
74005
+ };
74006
+ }
73992
74007
 
73993
74008
  // src/codegen/generators/typescript/documentTypes.ts
73994
74009
  var recast12 = __toESM(require_main2(), 1);
@@ -78608,6 +78623,7 @@ async function componentFields2(config2, docs) {
78608
78623
 
78609
78624
  // src/codegen/index.ts
78610
78625
  async function compile(config2) {
78626
+ await generatePluginRuntimes({ config: config2 });
78611
78627
  const documents = await collectDocuments(config2);
78612
78628
  await runPipeline2(config2, documents);
78613
78629
  }
@@ -79201,6 +79217,9 @@ function find_exported_fn(body, name) {
79201
79217
  if (init.type === "TSSatisfiesExpression") {
79202
79218
  init = init.expression;
79203
79219
  }
79220
+ if (init.type === "CallExpression" && init.arguments[0] && (init.arguments[0].type === "FunctionExpression" || init.arguments[0].type === "ArrowFunctionExpression")) {
79221
+ init = init.arguments[0];
79222
+ }
79204
79223
  if (init.type === "FunctionExpression" || init.type === "ArrowFunctionExpression") {
79205
79224
  return init;
79206
79225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "houdini",
3
- "version": "1.2.30",
3
+ "version": "1.2.32",
4
4
  "description": "The disappearing GraphQL clients",
5
5
  "keywords": [
6
6
  "typescript",