@soda-gql/metro-plugin 0.11.1 → 0.11.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/README.md CHANGED
@@ -84,6 +84,7 @@ The plugin automatically detects and uses the appropriate upstream transformer:
84
84
  | `configPath` | `string` | `undefined` | Path to soda-gql config file |
85
85
  | `enabled` | `boolean` | `true` | Enable/disable the plugin |
86
86
  | `debug` | `boolean` | `false` | Enable verbose logging |
87
+ | `upstreamTransformer` | `string` | `undefined` | Explicit path to upstream transformer to chain |
87
88
 
88
89
  ## Watch Mode Considerations
89
90
 
@@ -105,7 +106,19 @@ npx react-native start --reset-cache
105
106
 
106
107
  ## Chaining with Other Transformers
107
108
 
108
- If you need to chain with other transformers (e.g., react-native-svg-transformer), ensure soda-gql's transformer is applied first:
109
+ When using other Metro transformers (e.g., react-native-svg-transformer), soda-gql automatically detects and chains with them.
110
+
111
+ ### How Chaining Works
112
+
113
+ When an upstream transformer is detected, soda-gql generates a wrapper transformer file in `node_modules/.cache/soda-gql/`. This wrapper:
114
+
115
+ 1. Hardcodes the upstream transformer path at build time
116
+ 2. Enables reliable chaining in Metro worker processes
117
+ 3. Is automatically regenerated when the upstream path changes
118
+
119
+ ### Automatic Chaining (Recommended)
120
+
121
+ If you set `babelTransformerPath` before calling `withSodaGql`, it will be automatically preserved and chained:
109
122
 
110
123
  ```javascript
111
124
  // metro.config.js
@@ -114,17 +127,26 @@ const { withSodaGql } = require("@soda-gql/metro-plugin");
114
127
 
115
128
  const config = getDefaultConfig(__dirname);
116
129
 
117
- // Apply soda-gql first
118
- const sodaGqlConfig = withSodaGql(config);
119
-
120
- // Then chain other transformers
121
- module.exports = {
122
- ...sodaGqlConfig,
123
- transformer: {
124
- ...sodaGqlConfig.transformer,
125
- // Additional transformer customizations
126
- },
127
- };
130
+ // Set the other transformer first
131
+ config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
132
+
133
+ // soda-gql will automatically chain with it
134
+ module.exports = withSodaGql(config);
135
+ ```
136
+
137
+ ### Explicit Upstream Transformer
138
+
139
+ You can also explicitly specify the upstream transformer via options:
140
+
141
+ ```javascript
142
+ // metro.config.js
143
+ const { getDefaultConfig } = require("expo/metro-config");
144
+ const { withSodaGql } = require("@soda-gql/metro-plugin");
145
+
146
+ const config = getDefaultConfig(__dirname);
147
+ module.exports = withSodaGql(config, {
148
+ upstreamTransformer: require.resolve("react-native-svg-transformer"),
149
+ });
128
150
  ```
129
151
 
130
152
  ## Troubleshooting
package/dist/index.cjs CHANGED
@@ -1,6 +1,67 @@
1
1
  const require_transformer = require('./transformer.cjs');
2
2
  let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-support");
3
+ let node_crypto = require("node:crypto");
4
+ let node_fs = require("node:fs");
5
+ let node_path = require("node:path");
3
6
 
7
+ //#region packages/metro-plugin/src/wrapper-generator.ts
8
+ /** Cache directory location relative to project root */
9
+ const CACHE_DIR = "node_modules/.cache/soda-gql";
10
+ /** Wrapper file name suffix */
11
+ const WRAPPER_FILE = "metro-transformer-wrapper.js";
12
+ /**
13
+ * Generate a deterministic hash for cache key.
14
+ * Includes version prefix for cache invalidation on plugin updates.
15
+ */
16
+ function generateCacheKey(upstreamPath) {
17
+ const hash = (0, node_crypto.createHash)("md5");
18
+ hash.update("@soda-gql/metro-plugin:wrapper:v1");
19
+ hash.update(upstreamPath);
20
+ return hash.digest("hex").slice(0, 12);
21
+ }
22
+ /**
23
+ * Generate wrapper transformer content.
24
+ * The generated file imports soda-gql transformer factory and creates
25
+ * a transformer instance with the hardcoded upstream path.
26
+ */
27
+ function generateWrapperContent(upstreamPath) {
28
+ return `// Generated by @soda-gql/metro-plugin
29
+ // DO NOT EDIT - This file is auto-generated
30
+ // Upstream: ${upstreamPath}
31
+
32
+ const { createTransformerWithUpstream } = require("@soda-gql/metro-plugin/transformer");
33
+
34
+ const transformer = createTransformerWithUpstream(${JSON.stringify(upstreamPath)});
35
+
36
+ module.exports = transformer;
37
+ module.exports.transform = transformer.transform;
38
+ module.exports.getCacheKey = transformer.getCacheKey;
39
+ `;
40
+ }
41
+ /**
42
+ * Get or create wrapper transformer file.
43
+ * Returns the absolute path to the wrapper file.
44
+ *
45
+ * The wrapper file is cached based on the upstream transformer path.
46
+ * If the file already exists with the same content, it is reused.
47
+ *
48
+ * @param options - Wrapper generator options
49
+ * @returns Absolute path to the wrapper transformer file
50
+ */
51
+ function ensureWrapperTransformer(options) {
52
+ const { upstreamTransformerPath, projectRoot } = options;
53
+ const cacheDir = (0, node_path.join)(projectRoot, CACHE_DIR);
54
+ const wrapperPath = (0, node_path.join)(cacheDir, `${generateCacheKey(upstreamTransformerPath)}-${WRAPPER_FILE}`);
55
+ const expectedContent = generateWrapperContent(upstreamTransformerPath);
56
+ if ((0, node_fs.existsSync)(wrapperPath)) try {
57
+ if ((0, node_fs.readFileSync)(wrapperPath, "utf-8") === expectedContent) return wrapperPath;
58
+ } catch {}
59
+ (0, node_fs.mkdirSync)(cacheDir, { recursive: true });
60
+ (0, node_fs.writeFileSync)(wrapperPath, expectedContent, "utf-8");
61
+ return wrapperPath;
62
+ }
63
+
64
+ //#endregion
4
65
  //#region packages/metro-plugin/src/index.ts
5
66
  /**
6
67
  * Wrap Metro configuration with soda-gql support.
@@ -8,6 +69,9 @@ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-suppor
8
69
  * This function modifies the Metro configuration to use the soda-gql
9
70
  * transformer, which applies GraphQL code transformations at build time.
10
71
  *
72
+ * If the config already has a custom `babelTransformerPath` set (e.g., from
73
+ * react-native-svg-transformer), soda-gql will automatically chain with it.
74
+ *
11
75
  * @example
12
76
  * ```typescript
13
77
  * // Expo project (metro.config.js)
@@ -30,11 +94,22 @@ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-suppor
30
94
  *
31
95
  * @example
32
96
  * ```typescript
33
- * // With options
97
+ * // Chaining with another transformer (e.g., react-native-svg-transformer)
98
+ * // The existing babelTransformerPath is automatically detected and chained.
99
+ * const { getDefaultConfig } = require("expo/metro-config");
100
+ * const { withSodaGql } = require("@soda-gql/metro-plugin");
101
+ *
102
+ * const config = getDefaultConfig(__dirname);
103
+ * config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
104
+ * module.exports = withSodaGql(config);
105
+ * ```
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Explicitly specifying upstream transformer
34
110
  * const config = getDefaultConfig(__dirname);
35
111
  * module.exports = withSodaGql(config, {
36
- * configPath: "./soda-gql.config.ts",
37
- * debug: true,
112
+ * upstreamTransformer: require.resolve("react-native-svg-transformer"),
38
113
  * });
39
114
  * ```
40
115
  *
@@ -43,9 +118,22 @@ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-suppor
43
118
  * @returns Modified Metro configuration with soda-gql transformer
44
119
  */
45
120
  function withSodaGql(config, options = {}) {
46
- const transformerPath = require.resolve("@soda-gql/metro-plugin/transformer");
47
121
  const stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)(options.configPath);
48
122
  if (options.transformer) (0, __soda_gql_builder_plugin_support.setSharedTransformerType)(stateKey, options.transformer);
123
+ const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;
124
+ let transformerPath;
125
+ if (upstreamTransformer) {
126
+ let resolvedUpstream;
127
+ try {
128
+ resolvedUpstream = require.resolve(upstreamTransformer, { paths: [process.cwd()] });
129
+ } catch {
130
+ resolvedUpstream = upstreamTransformer;
131
+ }
132
+ transformerPath = ensureWrapperTransformer({
133
+ upstreamTransformerPath: resolvedUpstream,
134
+ projectRoot: process.cwd()
135
+ });
136
+ } else transformerPath = require.resolve("@soda-gql/metro-plugin/transformer");
49
137
  return {
50
138
  ...config,
51
139
  transformer: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions } from \"./types\";\n\n// Re-export shared state utilities for advanced usage\nexport { getSharedArtifact, getSharedState, getStateKey } from \"@soda-gql/builder/plugin-support\";\nexport type {\n MetroConfig,\n MetroPluginOptions,\n MetroTransformer,\n MetroTransformParams,\n MetroTransformResult,\n TransformerType,\n} from \"./types\";\n\n/**\n * Wrap Metro configuration with soda-gql support.\n *\n * This function modifies the Metro configuration to use the soda-gql\n * transformer, which applies GraphQL code transformations at build time.\n *\n * @example\n * ```typescript\n * // Expo project (metro.config.js)\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // React Native bare project (metro.config.js)\n * const { getDefaultConfig, mergeConfig } = require(\"@react-native/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // With options\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config, {\n * configPath: \"./soda-gql.config.ts\",\n * debug: true,\n * });\n * ```\n *\n * @param config - The Metro configuration to wrap\n * @param options - Optional plugin configuration\n * @returns Modified Metro configuration with soda-gql transformer\n */\nexport function withSodaGql<T extends MetroConfig>(config: T, options: MetroPluginOptions = {}): T {\n // Use package export path to ensure correct resolution from any location\n const transformerPath = require.resolve(\"@soda-gql/metro-plugin/transformer\");\n\n // Store transformer type in shared state for the transformer module to read\n const stateKey = getStateKey(options.configPath);\n if (options.transformer) {\n setSharedTransformerType(stateKey, options.transformer);\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n },\n } as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,YAAmC,QAAW,UAA8B,EAAE,EAAK;CAEjG,MAAM,kBAAkB,QAAQ,QAAQ,qCAAqC;CAG7E,MAAM,8DAAuB,QAAQ,WAAW;AAChD,KAAI,QAAQ,YACV,iEAAyB,UAAU,QAAQ,YAAY;AAGzD,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GACvB;EACF"}
1
+ {"version":3,"file":"index.cjs","names":["transformerPath: string","resolvedUpstream: string"],"sources":["../src/wrapper-generator.ts","../src/index.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/** Cache directory location relative to project root */\nconst CACHE_DIR = \"node_modules/.cache/soda-gql\";\n\n/** Wrapper file name suffix */\nconst WRAPPER_FILE = \"metro-transformer-wrapper.js\";\n\n/**\n * Options for generating wrapper transformer.\n */\nexport type WrapperGeneratorOptions = {\n /** Absolute path to the upstream transformer to chain */\n readonly upstreamTransformerPath: string;\n /** Absolute path to the project root */\n readonly projectRoot: string;\n};\n\n/**\n * Generate a deterministic hash for cache key.\n * Includes version prefix for cache invalidation on plugin updates.\n */\nexport function generateCacheKey(upstreamPath: string): string {\n const hash = createHash(\"md5\");\n hash.update(\"@soda-gql/metro-plugin:wrapper:v1\");\n hash.update(upstreamPath);\n return hash.digest(\"hex\").slice(0, 12);\n}\n\n/**\n * Generate wrapper transformer content.\n * The generated file imports soda-gql transformer factory and creates\n * a transformer instance with the hardcoded upstream path.\n */\nexport function generateWrapperContent(upstreamPath: string): string {\n return `// Generated by @soda-gql/metro-plugin\n// DO NOT EDIT - This file is auto-generated\n// Upstream: ${upstreamPath}\n\nconst { createTransformerWithUpstream } = require(\"@soda-gql/metro-plugin/transformer\");\n\nconst transformer = createTransformerWithUpstream(${JSON.stringify(upstreamPath)});\n\nmodule.exports = transformer;\nmodule.exports.transform = transformer.transform;\nmodule.exports.getCacheKey = transformer.getCacheKey;\n`;\n}\n\n/**\n * Get or create wrapper transformer file.\n * Returns the absolute path to the wrapper file.\n *\n * The wrapper file is cached based on the upstream transformer path.\n * If the file already exists with the same content, it is reused.\n *\n * @param options - Wrapper generator options\n * @returns Absolute path to the wrapper transformer file\n */\nexport function ensureWrapperTransformer(options: WrapperGeneratorOptions): string {\n const { upstreamTransformerPath, projectRoot } = options;\n\n const cacheDir = join(projectRoot, CACHE_DIR);\n const cacheKey = generateCacheKey(upstreamTransformerPath);\n const wrapperPath = join(cacheDir, `${cacheKey}-${WRAPPER_FILE}`);\n\n // Generate expected content\n const expectedContent = generateWrapperContent(upstreamTransformerPath);\n\n // Check if wrapper needs regeneration\n if (existsSync(wrapperPath)) {\n try {\n const existingContent = readFileSync(wrapperPath, \"utf-8\");\n if (existingContent === expectedContent) {\n return wrapperPath;\n }\n } catch {\n // File exists but couldn't be read, regenerate\n }\n }\n\n // Create cache directory if it doesn't exist\n mkdirSync(cacheDir, { recursive: true });\n\n // Write wrapper file\n writeFileSync(wrapperPath, expectedContent, \"utf-8\");\n\n return wrapperPath;\n}\n","import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions } from \"./types\";\nimport { ensureWrapperTransformer } from \"./wrapper-generator\";\n\n// Re-export shared state utilities for advanced usage\nexport { getSharedArtifact, getSharedState, getStateKey } from \"@soda-gql/builder/plugin-support\";\nexport type {\n MetroConfig,\n MetroPluginOptions,\n MetroTransformer,\n MetroTransformParams,\n MetroTransformResult,\n TransformerType,\n} from \"./types\";\n\n/**\n * Wrap Metro configuration with soda-gql support.\n *\n * This function modifies the Metro configuration to use the soda-gql\n * transformer, which applies GraphQL code transformations at build time.\n *\n * If the config already has a custom `babelTransformerPath` set (e.g., from\n * react-native-svg-transformer), soda-gql will automatically chain with it.\n *\n * @example\n * ```typescript\n * // Expo project (metro.config.js)\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // React Native bare project (metro.config.js)\n * const { getDefaultConfig, mergeConfig } = require(\"@react-native/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // Chaining with another transformer (e.g., react-native-svg-transformer)\n * // The existing babelTransformerPath is automatically detected and chained.\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * config.transformer.babelTransformerPath = require.resolve(\"react-native-svg-transformer\");\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // Explicitly specifying upstream transformer\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config, {\n * upstreamTransformer: require.resolve(\"react-native-svg-transformer\"),\n * });\n * ```\n *\n * @param config - The Metro configuration to wrap\n * @param options - Optional plugin configuration\n * @returns Modified Metro configuration with soda-gql transformer\n */\nexport function withSodaGql<T extends MetroConfig>(config: T, options: MetroPluginOptions = {}): T {\n // Store transformer type in shared state for the transformer module to read\n const stateKey = getStateKey(options.configPath);\n if (options.transformer) {\n setSharedTransformerType(stateKey, options.transformer);\n }\n\n // Determine upstream transformer path:\n // 1. Explicit option takes precedence\n // 2. Fall back to existing babelTransformerPath from config (auto-detect)\n const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;\n\n let transformerPath: string;\n\n if (upstreamTransformer) {\n // Resolve upstream to absolute path for reliable worker loading\n let resolvedUpstream: string;\n try {\n resolvedUpstream = require.resolve(upstreamTransformer, {\n paths: [process.cwd()],\n });\n } catch {\n // If resolution fails, use the path as-is (might be an absolute path already)\n resolvedUpstream = upstreamTransformer;\n }\n\n // Generate wrapper transformer with hardcoded upstream\n transformerPath = ensureWrapperTransformer({\n upstreamTransformerPath: resolvedUpstream,\n projectRoot: process.cwd(),\n });\n } else {\n // No upstream - use main transformer directly\n transformerPath = require.resolve(\"@soda-gql/metro-plugin/transformer\");\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n },\n } as T;\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,YAAY;;AAGlB,MAAM,eAAe;;;;;AAgBrB,SAAgB,iBAAiB,cAA8B;CAC7D,MAAM,mCAAkB,MAAM;AAC9B,MAAK,OAAO,oCAAoC;AAChD,MAAK,OAAO,aAAa;AACzB,QAAO,KAAK,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;;;;;;;AAQxC,SAAgB,uBAAuB,cAA8B;AACnE,QAAO;;eAEM,aAAa;;;;oDAIwB,KAAK,UAAU,aAAa,CAAC;;;;;;;;;;;;;;;;;AAkBjF,SAAgB,yBAAyB,SAA0C;CACjF,MAAM,EAAE,yBAAyB,gBAAgB;CAEjD,MAAM,+BAAgB,aAAa,UAAU;CAE7C,MAAM,kCAAmB,UAAU,GADlB,iBAAiB,wBAAwB,CACX,GAAG,eAAe;CAGjE,MAAM,kBAAkB,uBAAuB,wBAAwB;AAGvE,6BAAe,YAAY,CACzB,KAAI;AAEF,gCADqC,aAAa,QAAQ,KAClC,gBACtB,QAAO;SAEH;AAMV,wBAAU,UAAU,EAAE,WAAW,MAAM,CAAC;AAGxC,4BAAc,aAAa,iBAAiB,QAAQ;AAEpD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpBT,SAAgB,YAAmC,QAAW,UAA8B,EAAE,EAAK;CAEjG,MAAM,8DAAuB,QAAQ,WAAW;AAChD,KAAI,QAAQ,YACV,iEAAyB,UAAU,QAAQ,YAAY;CAMzD,MAAM,sBAAsB,QAAQ,uBAAuB,OAAO,aAAa;CAE/E,IAAIA;AAEJ,KAAI,qBAAqB;EAEvB,IAAIC;AACJ,MAAI;AACF,sBAAmB,QAAQ,QAAQ,qBAAqB,EACtD,OAAO,CAAC,QAAQ,KAAK,CAAC,EACvB,CAAC;UACI;AAEN,sBAAmB;;AAIrB,oBAAkB,yBAAyB;GACzC,yBAAyB;GACzB,aAAa,QAAQ,KAAK;GAC3B,CAAC;OAGF,mBAAkB,QAAQ,QAAQ,qCAAqC;AAGzE,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GACvB;EACF"}
package/dist/index.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as TransformerType, r as MetroTransformParams, t as MetroConfig } from "./types-C6LTFGZE.cjs";
1
+ import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as TransformerType, r as MetroTransformParams, t as MetroConfig } from "./types-DPugisG3.cjs";
2
2
  import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builder/plugin-support";
3
3
 
4
4
  //#region packages/metro-plugin/src/index.d.ts
@@ -9,6 +9,9 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
9
9
  * This function modifies the Metro configuration to use the soda-gql
10
10
  * transformer, which applies GraphQL code transformations at build time.
11
11
  *
12
+ * If the config already has a custom `babelTransformerPath` set (e.g., from
13
+ * react-native-svg-transformer), soda-gql will automatically chain with it.
14
+ *
12
15
  * @example
13
16
  * ```typescript
14
17
  * // Expo project (metro.config.js)
@@ -31,11 +34,22 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
31
34
  *
32
35
  * @example
33
36
  * ```typescript
34
- * // With options
37
+ * // Chaining with another transformer (e.g., react-native-svg-transformer)
38
+ * // The existing babelTransformerPath is automatically detected and chained.
39
+ * const { getDefaultConfig } = require("expo/metro-config");
40
+ * const { withSodaGql } = require("@soda-gql/metro-plugin");
41
+ *
42
+ * const config = getDefaultConfig(__dirname);
43
+ * config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
44
+ * module.exports = withSodaGql(config);
45
+ * ```
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Explicitly specifying upstream transformer
35
50
  * const config = getDefaultConfig(__dirname);
36
51
  * module.exports = withSodaGql(config, {
37
- * configPath: "./soda-gql.config.ts",
38
- * debug: true,
52
+ * upstreamTransformer: require.resolve("react-native-svg-transformer"),
39
53
  * });
40
54
  * ```
41
55
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sBAAsB,qBAAqB,aAAY,qBAA0B"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAqEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sBAAsB,qBAAqB,aAAY,qBAA0B"}
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as TransformerType, r as MetroTransformParams, t as MetroConfig } from "./types-C88YiO8c.mjs";
1
+ import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as TransformerType, r as MetroTransformParams, t as MetroConfig } from "./types-BjrzxgOZ.mjs";
2
2
  import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builder/plugin-support";
3
3
 
4
4
  //#region packages/metro-plugin/src/index.d.ts
@@ -9,6 +9,9 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
9
9
  * This function modifies the Metro configuration to use the soda-gql
10
10
  * transformer, which applies GraphQL code transformations at build time.
11
11
  *
12
+ * If the config already has a custom `babelTransformerPath` set (e.g., from
13
+ * react-native-svg-transformer), soda-gql will automatically chain with it.
14
+ *
12
15
  * @example
13
16
  * ```typescript
14
17
  * // Expo project (metro.config.js)
@@ -31,11 +34,22 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
31
34
  *
32
35
  * @example
33
36
  * ```typescript
34
- * // With options
37
+ * // Chaining with another transformer (e.g., react-native-svg-transformer)
38
+ * // The existing babelTransformerPath is automatically detected and chained.
39
+ * const { getDefaultConfig } = require("expo/metro-config");
40
+ * const { withSodaGql } = require("@soda-gql/metro-plugin");
41
+ *
42
+ * const config = getDefaultConfig(__dirname);
43
+ * config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
44
+ * module.exports = withSodaGql(config);
45
+ * ```
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * // Explicitly specifying upstream transformer
35
50
  * const config = getDefaultConfig(__dirname);
36
51
  * module.exports = withSodaGql(config, {
37
- * configPath: "./soda-gql.config.ts",
38
- * debug: true,
52
+ * upstreamTransformer: require.resolve("react-native-svg-transformer"),
39
53
  * });
40
54
  * ```
41
55
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAsDA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sBAAsB,qBAAqB,aAAY,qBAA0B"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAqEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAAgB,sBAAsB,qBAAqB,aAAY,qBAA0B"}
package/dist/index.mjs CHANGED
@@ -1,6 +1,67 @@
1
1
  import { t as __require } from "./chunk--GtjC1aJ.mjs";
2
2
  import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getStateKey$1, setSharedTransformerType } from "@soda-gql/builder/plugin-support";
3
+ import { createHash } from "node:crypto";
4
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
+ import { join } from "node:path";
3
6
 
7
+ //#region packages/metro-plugin/src/wrapper-generator.ts
8
+ /** Cache directory location relative to project root */
9
+ const CACHE_DIR = "node_modules/.cache/soda-gql";
10
+ /** Wrapper file name suffix */
11
+ const WRAPPER_FILE = "metro-transformer-wrapper.js";
12
+ /**
13
+ * Generate a deterministic hash for cache key.
14
+ * Includes version prefix for cache invalidation on plugin updates.
15
+ */
16
+ function generateCacheKey(upstreamPath) {
17
+ const hash = createHash("md5");
18
+ hash.update("@soda-gql/metro-plugin:wrapper:v1");
19
+ hash.update(upstreamPath);
20
+ return hash.digest("hex").slice(0, 12);
21
+ }
22
+ /**
23
+ * Generate wrapper transformer content.
24
+ * The generated file imports soda-gql transformer factory and creates
25
+ * a transformer instance with the hardcoded upstream path.
26
+ */
27
+ function generateWrapperContent(upstreamPath) {
28
+ return `// Generated by @soda-gql/metro-plugin
29
+ // DO NOT EDIT - This file is auto-generated
30
+ // Upstream: ${upstreamPath}
31
+
32
+ const { createTransformerWithUpstream } = require("@soda-gql/metro-plugin/transformer");
33
+
34
+ const transformer = createTransformerWithUpstream(${JSON.stringify(upstreamPath)});
35
+
36
+ module.exports = transformer;
37
+ module.exports.transform = transformer.transform;
38
+ module.exports.getCacheKey = transformer.getCacheKey;
39
+ `;
40
+ }
41
+ /**
42
+ * Get or create wrapper transformer file.
43
+ * Returns the absolute path to the wrapper file.
44
+ *
45
+ * The wrapper file is cached based on the upstream transformer path.
46
+ * If the file already exists with the same content, it is reused.
47
+ *
48
+ * @param options - Wrapper generator options
49
+ * @returns Absolute path to the wrapper transformer file
50
+ */
51
+ function ensureWrapperTransformer(options) {
52
+ const { upstreamTransformerPath, projectRoot } = options;
53
+ const cacheDir = join(projectRoot, CACHE_DIR);
54
+ const wrapperPath = join(cacheDir, `${generateCacheKey(upstreamTransformerPath)}-${WRAPPER_FILE}`);
55
+ const expectedContent = generateWrapperContent(upstreamTransformerPath);
56
+ if (existsSync(wrapperPath)) try {
57
+ if (readFileSync(wrapperPath, "utf-8") === expectedContent) return wrapperPath;
58
+ } catch {}
59
+ mkdirSync(cacheDir, { recursive: true });
60
+ writeFileSync(wrapperPath, expectedContent, "utf-8");
61
+ return wrapperPath;
62
+ }
63
+
64
+ //#endregion
4
65
  //#region packages/metro-plugin/src/index.ts
5
66
  /**
6
67
  * Wrap Metro configuration with soda-gql support.
@@ -8,6 +69,9 @@ import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getState
8
69
  * This function modifies the Metro configuration to use the soda-gql
9
70
  * transformer, which applies GraphQL code transformations at build time.
10
71
  *
72
+ * If the config already has a custom `babelTransformerPath` set (e.g., from
73
+ * react-native-svg-transformer), soda-gql will automatically chain with it.
74
+ *
11
75
  * @example
12
76
  * ```typescript
13
77
  * // Expo project (metro.config.js)
@@ -30,11 +94,22 @@ import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getState
30
94
  *
31
95
  * @example
32
96
  * ```typescript
33
- * // With options
97
+ * // Chaining with another transformer (e.g., react-native-svg-transformer)
98
+ * // The existing babelTransformerPath is automatically detected and chained.
99
+ * const { getDefaultConfig } = require("expo/metro-config");
100
+ * const { withSodaGql } = require("@soda-gql/metro-plugin");
101
+ *
102
+ * const config = getDefaultConfig(__dirname);
103
+ * config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
104
+ * module.exports = withSodaGql(config);
105
+ * ```
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * // Explicitly specifying upstream transformer
34
110
  * const config = getDefaultConfig(__dirname);
35
111
  * module.exports = withSodaGql(config, {
36
- * configPath: "./soda-gql.config.ts",
37
- * debug: true,
112
+ * upstreamTransformer: require.resolve("react-native-svg-transformer"),
38
113
  * });
39
114
  * ```
40
115
  *
@@ -43,9 +118,22 @@ import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getState
43
118
  * @returns Modified Metro configuration with soda-gql transformer
44
119
  */
45
120
  function withSodaGql(config, options = {}) {
46
- const transformerPath = __require.resolve("@soda-gql/metro-plugin/transformer");
47
121
  const stateKey = getStateKey$1(options.configPath);
48
122
  if (options.transformer) setSharedTransformerType(stateKey, options.transformer);
123
+ const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;
124
+ let transformerPath;
125
+ if (upstreamTransformer) {
126
+ let resolvedUpstream;
127
+ try {
128
+ resolvedUpstream = __require.resolve(upstreamTransformer, { paths: [process.cwd()] });
129
+ } catch {
130
+ resolvedUpstream = upstreamTransformer;
131
+ }
132
+ transformerPath = ensureWrapperTransformer({
133
+ upstreamTransformerPath: resolvedUpstream,
134
+ projectRoot: process.cwd()
135
+ });
136
+ } else transformerPath = __require.resolve("@soda-gql/metro-plugin/transformer");
49
137
  return {
50
138
  ...config,
51
139
  transformer: {
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["getStateKey"],"sources":["../src/index.ts"],"sourcesContent":["import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions } from \"./types\";\n\n// Re-export shared state utilities for advanced usage\nexport { getSharedArtifact, getSharedState, getStateKey } from \"@soda-gql/builder/plugin-support\";\nexport type {\n MetroConfig,\n MetroPluginOptions,\n MetroTransformer,\n MetroTransformParams,\n MetroTransformResult,\n TransformerType,\n} from \"./types\";\n\n/**\n * Wrap Metro configuration with soda-gql support.\n *\n * This function modifies the Metro configuration to use the soda-gql\n * transformer, which applies GraphQL code transformations at build time.\n *\n * @example\n * ```typescript\n * // Expo project (metro.config.js)\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // React Native bare project (metro.config.js)\n * const { getDefaultConfig, mergeConfig } = require(\"@react-native/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // With options\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config, {\n * configPath: \"./soda-gql.config.ts\",\n * debug: true,\n * });\n * ```\n *\n * @param config - The Metro configuration to wrap\n * @param options - Optional plugin configuration\n * @returns Modified Metro configuration with soda-gql transformer\n */\nexport function withSodaGql<T extends MetroConfig>(config: T, options: MetroPluginOptions = {}): T {\n // Use package export path to ensure correct resolution from any location\n const transformerPath = require.resolve(\"@soda-gql/metro-plugin/transformer\");\n\n // Store transformer type in shared state for the transformer module to read\n const stateKey = getStateKey(options.configPath);\n if (options.transformer) {\n setSharedTransformerType(stateKey, options.transformer);\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n },\n } as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAgB,YAAmC,QAAW,UAA8B,EAAE,EAAK;CAEjG,MAAM,4BAA0B,QAAQ,qCAAqC;CAG7E,MAAM,WAAWA,cAAY,QAAQ,WAAW;AAChD,KAAI,QAAQ,YACV,0BAAyB,UAAU,QAAQ,YAAY;AAGzD,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GACvB;EACF"}
1
+ {"version":3,"file":"index.mjs","names":["getStateKey","transformerPath: string","resolvedUpstream: string"],"sources":["../src/wrapper-generator.ts","../src/index.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { existsSync, mkdirSync, readFileSync, writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\n/** Cache directory location relative to project root */\nconst CACHE_DIR = \"node_modules/.cache/soda-gql\";\n\n/** Wrapper file name suffix */\nconst WRAPPER_FILE = \"metro-transformer-wrapper.js\";\n\n/**\n * Options for generating wrapper transformer.\n */\nexport type WrapperGeneratorOptions = {\n /** Absolute path to the upstream transformer to chain */\n readonly upstreamTransformerPath: string;\n /** Absolute path to the project root */\n readonly projectRoot: string;\n};\n\n/**\n * Generate a deterministic hash for cache key.\n * Includes version prefix for cache invalidation on plugin updates.\n */\nexport function generateCacheKey(upstreamPath: string): string {\n const hash = createHash(\"md5\");\n hash.update(\"@soda-gql/metro-plugin:wrapper:v1\");\n hash.update(upstreamPath);\n return hash.digest(\"hex\").slice(0, 12);\n}\n\n/**\n * Generate wrapper transformer content.\n * The generated file imports soda-gql transformer factory and creates\n * a transformer instance with the hardcoded upstream path.\n */\nexport function generateWrapperContent(upstreamPath: string): string {\n return `// Generated by @soda-gql/metro-plugin\n// DO NOT EDIT - This file is auto-generated\n// Upstream: ${upstreamPath}\n\nconst { createTransformerWithUpstream } = require(\"@soda-gql/metro-plugin/transformer\");\n\nconst transformer = createTransformerWithUpstream(${JSON.stringify(upstreamPath)});\n\nmodule.exports = transformer;\nmodule.exports.transform = transformer.transform;\nmodule.exports.getCacheKey = transformer.getCacheKey;\n`;\n}\n\n/**\n * Get or create wrapper transformer file.\n * Returns the absolute path to the wrapper file.\n *\n * The wrapper file is cached based on the upstream transformer path.\n * If the file already exists with the same content, it is reused.\n *\n * @param options - Wrapper generator options\n * @returns Absolute path to the wrapper transformer file\n */\nexport function ensureWrapperTransformer(options: WrapperGeneratorOptions): string {\n const { upstreamTransformerPath, projectRoot } = options;\n\n const cacheDir = join(projectRoot, CACHE_DIR);\n const cacheKey = generateCacheKey(upstreamTransformerPath);\n const wrapperPath = join(cacheDir, `${cacheKey}-${WRAPPER_FILE}`);\n\n // Generate expected content\n const expectedContent = generateWrapperContent(upstreamTransformerPath);\n\n // Check if wrapper needs regeneration\n if (existsSync(wrapperPath)) {\n try {\n const existingContent = readFileSync(wrapperPath, \"utf-8\");\n if (existingContent === expectedContent) {\n return wrapperPath;\n }\n } catch {\n // File exists but couldn't be read, regenerate\n }\n }\n\n // Create cache directory if it doesn't exist\n mkdirSync(cacheDir, { recursive: true });\n\n // Write wrapper file\n writeFileSync(wrapperPath, expectedContent, \"utf-8\");\n\n return wrapperPath;\n}\n","import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions } from \"./types\";\nimport { ensureWrapperTransformer } from \"./wrapper-generator\";\n\n// Re-export shared state utilities for advanced usage\nexport { getSharedArtifact, getSharedState, getStateKey } from \"@soda-gql/builder/plugin-support\";\nexport type {\n MetroConfig,\n MetroPluginOptions,\n MetroTransformer,\n MetroTransformParams,\n MetroTransformResult,\n TransformerType,\n} from \"./types\";\n\n/**\n * Wrap Metro configuration with soda-gql support.\n *\n * This function modifies the Metro configuration to use the soda-gql\n * transformer, which applies GraphQL code transformations at build time.\n *\n * If the config already has a custom `babelTransformerPath` set (e.g., from\n * react-native-svg-transformer), soda-gql will automatically chain with it.\n *\n * @example\n * ```typescript\n * // Expo project (metro.config.js)\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // React Native bare project (metro.config.js)\n * const { getDefaultConfig, mergeConfig } = require(\"@react-native/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // Chaining with another transformer (e.g., react-native-svg-transformer)\n * // The existing babelTransformerPath is automatically detected and chained.\n * const { getDefaultConfig } = require(\"expo/metro-config\");\n * const { withSodaGql } = require(\"@soda-gql/metro-plugin\");\n *\n * const config = getDefaultConfig(__dirname);\n * config.transformer.babelTransformerPath = require.resolve(\"react-native-svg-transformer\");\n * module.exports = withSodaGql(config);\n * ```\n *\n * @example\n * ```typescript\n * // Explicitly specifying upstream transformer\n * const config = getDefaultConfig(__dirname);\n * module.exports = withSodaGql(config, {\n * upstreamTransformer: require.resolve(\"react-native-svg-transformer\"),\n * });\n * ```\n *\n * @param config - The Metro configuration to wrap\n * @param options - Optional plugin configuration\n * @returns Modified Metro configuration with soda-gql transformer\n */\nexport function withSodaGql<T extends MetroConfig>(config: T, options: MetroPluginOptions = {}): T {\n // Store transformer type in shared state for the transformer module to read\n const stateKey = getStateKey(options.configPath);\n if (options.transformer) {\n setSharedTransformerType(stateKey, options.transformer);\n }\n\n // Determine upstream transformer path:\n // 1. Explicit option takes precedence\n // 2. Fall back to existing babelTransformerPath from config (auto-detect)\n const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;\n\n let transformerPath: string;\n\n if (upstreamTransformer) {\n // Resolve upstream to absolute path for reliable worker loading\n let resolvedUpstream: string;\n try {\n resolvedUpstream = require.resolve(upstreamTransformer, {\n paths: [process.cwd()],\n });\n } catch {\n // If resolution fails, use the path as-is (might be an absolute path already)\n resolvedUpstream = upstreamTransformer;\n }\n\n // Generate wrapper transformer with hardcoded upstream\n transformerPath = ensureWrapperTransformer({\n upstreamTransformerPath: resolvedUpstream,\n projectRoot: process.cwd(),\n });\n } else {\n // No upstream - use main transformer directly\n transformerPath = require.resolve(\"@soda-gql/metro-plugin/transformer\");\n }\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n },\n } as T;\n}\n"],"mappings":";;;;;;;;AAKA,MAAM,YAAY;;AAGlB,MAAM,eAAe;;;;;AAgBrB,SAAgB,iBAAiB,cAA8B;CAC7D,MAAM,OAAO,WAAW,MAAM;AAC9B,MAAK,OAAO,oCAAoC;AAChD,MAAK,OAAO,aAAa;AACzB,QAAO,KAAK,OAAO,MAAM,CAAC,MAAM,GAAG,GAAG;;;;;;;AAQxC,SAAgB,uBAAuB,cAA8B;AACnE,QAAO;;eAEM,aAAa;;;;oDAIwB,KAAK,UAAU,aAAa,CAAC;;;;;;;;;;;;;;;;;AAkBjF,SAAgB,yBAAyB,SAA0C;CACjF,MAAM,EAAE,yBAAyB,gBAAgB;CAEjD,MAAM,WAAW,KAAK,aAAa,UAAU;CAE7C,MAAM,cAAc,KAAK,UAAU,GADlB,iBAAiB,wBAAwB,CACX,GAAG,eAAe;CAGjE,MAAM,kBAAkB,uBAAuB,wBAAwB;AAGvE,KAAI,WAAW,YAAY,CACzB,KAAI;AAEF,MADwB,aAAa,aAAa,QAAQ,KAClC,gBACtB,QAAO;SAEH;AAMV,WAAU,UAAU,EAAE,WAAW,MAAM,CAAC;AAGxC,eAAc,aAAa,iBAAiB,QAAQ;AAEpD,QAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACpBT,SAAgB,YAAmC,QAAW,UAA8B,EAAE,EAAK;CAEjG,MAAM,WAAWA,cAAY,QAAQ,WAAW;AAChD,KAAI,QAAQ,YACV,0BAAyB,UAAU,QAAQ,YAAY;CAMzD,MAAM,sBAAsB,QAAQ,uBAAuB,OAAO,aAAa;CAE/E,IAAIC;AAEJ,KAAI,qBAAqB;EAEvB,IAAIC;AACJ,MAAI;AACF,gCAA2B,QAAQ,qBAAqB,EACtD,OAAO,CAAC,QAAQ,KAAK,CAAC,EACvB,CAAC;UACI;AAEN,sBAAmB;;AAIrB,oBAAkB,yBAAyB;GACzC,yBAAyB;GACzB,aAAa,QAAQ,KAAK;GAC3B,CAAC;OAGF,6BAA0B,QAAQ,qCAAqC;AAGzE,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GACvB;EACF"}
@@ -833,7 +833,7 @@ const tryResolve = (moduleName) => {
833
833
  };
834
834
  /**
835
835
  * Detect and load the upstream Metro Babel transformer.
836
- * Tries multiple candidates in order of preference.
836
+ * Tries candidates in order of preference.
837
837
  */
838
838
  const getUpstreamTransformer = () => {
839
839
  if (upstreamTransformer) return upstreamTransformer;
@@ -898,9 +898,16 @@ const initializeSwcTransformer = async (artifact, config) => {
898
898
  * Wraps the upstream Metro Babel transformer.
899
899
  */
900
900
  async function transform(params) {
901
+ return transformCore(params, getUpstreamTransformer);
902
+ }
903
+ /**
904
+ * Core transformation logic.
905
+ * @internal
906
+ */
907
+ async function transformCore(params, getUpstream) {
901
908
  const { src, filename, options } = params;
902
909
  const stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)();
903
- const upstream = getUpstreamTransformer();
910
+ const upstream = getUpstream();
904
911
  const session = ensurePluginSession();
905
912
  if (!session) return upstream.transform(params);
906
913
  let artifact = (0, __soda_gql_builder_plugin_support.getSharedArtifact)(stateKey);
@@ -972,11 +979,19 @@ async function transform(params) {
972
979
  * Includes artifact generation to ensure cache invalidation when models change.
973
980
  */
974
981
  function getCacheKey() {
982
+ return getCacheKeyCore(getUpstreamTransformer);
983
+ }
984
+ /**
985
+ * Core cache key generation logic.
986
+ * @internal
987
+ */
988
+ function getCacheKeyCore(getUpstream, upstreamPath) {
975
989
  const state = (0, __soda_gql_builder_plugin_support.getSharedState)((0, __soda_gql_builder_plugin_support.getStateKey)());
976
990
  const artifact = state.currentArtifact;
977
- const upstream = getUpstreamTransformer();
991
+ const upstream = getUpstream();
978
992
  const hash = node_crypto.default.createHash("md5");
979
- hash.update("@soda-gql/metro-plugin:v2");
993
+ hash.update("@soda-gql/metro-plugin:v3");
994
+ if (upstreamPath) hash.update(upstreamPath);
980
995
  if (upstream.getCacheKey) hash.update(upstream.getCacheKey());
981
996
  hash.update(String(state.generation));
982
997
  if (artifact) {
@@ -985,9 +1000,39 @@ function getCacheKey() {
985
1000
  }
986
1001
  return hash.digest("hex");
987
1002
  }
1003
+ /**
1004
+ * Create a transformer with a specific upstream transformer path.
1005
+ * Used by generated wrapper files to inject the upstream path at build time.
1006
+ *
1007
+ * @param upstreamPath - Absolute path to the upstream transformer module
1008
+ * @returns MetroTransformer instance configured with the specified upstream
1009
+ */
1010
+ function createTransformerWithUpstream(upstreamPath) {
1011
+ let cachedUpstream = null;
1012
+ const getUpstream = () => {
1013
+ if (cachedUpstream) return cachedUpstream;
1014
+ const resolved = tryResolve(upstreamPath);
1015
+ if (!resolved) throw new Error(`[@soda-gql/metro-plugin] Upstream transformer not found: ${upstreamPath}`);
1016
+ cachedUpstream = require(resolved);
1017
+ return cachedUpstream;
1018
+ };
1019
+ return {
1020
+ transform: (params) => transformCore(params, getUpstream),
1021
+ getCacheKey: () => getCacheKeyCore(getUpstream, upstreamPath)
1022
+ };
1023
+ }
1024
+ /**
1025
+ * Reset upstream transformer cache for testing.
1026
+ * @internal
1027
+ */
1028
+ function __resetUpstreamTransformer() {
1029
+ upstreamTransformer = null;
1030
+ }
988
1031
 
989
1032
  //#endregion
1033
+ exports.__resetUpstreamTransformer = __resetUpstreamTransformer;
990
1034
  exports.__toESM = __toESM;
1035
+ exports.createTransformerWithUpstream = createTransformerWithUpstream;
991
1036
  exports.getCacheKey = getCacheKey;
992
1037
  exports.transform = transform;
993
1038
  //# sourceMappingURL=transformer.cjs.map