@soda-gql/metro-plugin 0.11.0 → 0.11.2
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 +26 -12
- package/dist/index.cjs +25 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -5
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +19 -5
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +25 -4
- package/dist/index.mjs.map +1 -1
- package/dist/transformer.cjs +24 -1
- package/dist/transformer.cjs.map +1 -1
- package/dist/transformer.d.cts +1 -1
- package/dist/transformer.d.cts.map +1 -1
- package/dist/transformer.d.mts +1 -1
- package/dist/transformer.d.mts.map +1 -1
- package/dist/transformer.mjs +24 -1
- package/dist/transformer.mjs.map +1 -1
- package/dist/{types-C6LTFGZE.d.cts → types-D-K1oBE_.d.mts} +22 -2
- package/dist/types-D-K1oBE_.d.mts.map +1 -0
- package/dist/{types-C88YiO8c.d.mts → types-DEWrNhj2.d.cts} +22 -2
- package/dist/types-DEWrNhj2.d.cts.map +1 -0
- package/package.json +6 -6
- package/dist/types-C6LTFGZE.d.cts.map +0 -1
- package/dist/types-C88YiO8c.d.mts.map +0 -1
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,11 @@ npx react-native start --reset-cache
|
|
|
105
106
|
|
|
106
107
|
## Chaining with Other Transformers
|
|
107
108
|
|
|
108
|
-
|
|
109
|
+
When using other Metro transformers (e.g., react-native-svg-transformer), soda-gql automatically detects and chains with them.
|
|
110
|
+
|
|
111
|
+
### Automatic Chaining (Recommended)
|
|
112
|
+
|
|
113
|
+
If you set `babelTransformerPath` before calling `withSodaGql`, it will be automatically preserved and chained:
|
|
109
114
|
|
|
110
115
|
```javascript
|
|
111
116
|
// metro.config.js
|
|
@@ -114,17 +119,26 @@ const { withSodaGql } = require("@soda-gql/metro-plugin");
|
|
|
114
119
|
|
|
115
120
|
const config = getDefaultConfig(__dirname);
|
|
116
121
|
|
|
117
|
-
//
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
//
|
|
121
|
-
module.exports =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
// Set the other transformer first
|
|
123
|
+
config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
|
|
124
|
+
|
|
125
|
+
// soda-gql will automatically chain with it
|
|
126
|
+
module.exports = withSodaGql(config);
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Explicit Upstream Transformer
|
|
130
|
+
|
|
131
|
+
You can also explicitly specify the upstream transformer via options:
|
|
132
|
+
|
|
133
|
+
```javascript
|
|
134
|
+
// metro.config.js
|
|
135
|
+
const { getDefaultConfig } = require("expo/metro-config");
|
|
136
|
+
const { withSodaGql } = require("@soda-gql/metro-plugin");
|
|
137
|
+
|
|
138
|
+
const config = getDefaultConfig(__dirname);
|
|
139
|
+
module.exports = withSodaGql(config, {
|
|
140
|
+
upstreamTransformer: require.resolve("react-native-svg-transformer"),
|
|
141
|
+
});
|
|
128
142
|
```
|
|
129
143
|
|
|
130
144
|
## Troubleshooting
|
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,9 @@ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-suppor
|
|
|
8
8
|
* This function modifies the Metro configuration to use the soda-gql
|
|
9
9
|
* transformer, which applies GraphQL code transformations at build time.
|
|
10
10
|
*
|
|
11
|
+
* If the config already has a custom `babelTransformerPath` set (e.g., from
|
|
12
|
+
* react-native-svg-transformer), soda-gql will automatically chain with it.
|
|
13
|
+
*
|
|
11
14
|
* @example
|
|
12
15
|
* ```typescript
|
|
13
16
|
* // Expo project (metro.config.js)
|
|
@@ -30,11 +33,22 @@ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-suppor
|
|
|
30
33
|
*
|
|
31
34
|
* @example
|
|
32
35
|
* ```typescript
|
|
33
|
-
* //
|
|
36
|
+
* // Chaining with another transformer (e.g., react-native-svg-transformer)
|
|
37
|
+
* // The existing babelTransformerPath is automatically detected and chained.
|
|
38
|
+
* const { getDefaultConfig } = require("expo/metro-config");
|
|
39
|
+
* const { withSodaGql } = require("@soda-gql/metro-plugin");
|
|
40
|
+
*
|
|
41
|
+
* const config = getDefaultConfig(__dirname);
|
|
42
|
+
* config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
|
|
43
|
+
* module.exports = withSodaGql(config);
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Explicitly specifying upstream transformer
|
|
34
49
|
* const config = getDefaultConfig(__dirname);
|
|
35
50
|
* module.exports = withSodaGql(config, {
|
|
36
|
-
*
|
|
37
|
-
* debug: true,
|
|
51
|
+
* upstreamTransformer: require.resolve("react-native-svg-transformer"),
|
|
38
52
|
* });
|
|
39
53
|
* ```
|
|
40
54
|
*
|
|
@@ -46,11 +60,18 @@ function withSodaGql(config, options = {}) {
|
|
|
46
60
|
const transformerPath = require.resolve("@soda-gql/metro-plugin/transformer");
|
|
47
61
|
const stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)(options.configPath);
|
|
48
62
|
if (options.transformer) (0, __soda_gql_builder_plugin_support.setSharedTransformerType)(stateKey, options.transformer);
|
|
63
|
+
const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;
|
|
64
|
+
const sodaGqlTransformerOptions = {
|
|
65
|
+
...upstreamTransformer && { upstreamTransformer },
|
|
66
|
+
...options.configPath && { configPath: options.configPath },
|
|
67
|
+
...options.transformer && { transformerType: options.transformer }
|
|
68
|
+
};
|
|
49
69
|
return {
|
|
50
70
|
...config,
|
|
51
71
|
transformer: {
|
|
52
72
|
...config.transformer,
|
|
53
|
-
babelTransformerPath: transformerPath
|
|
73
|
+
babelTransformerPath: transformerPath,
|
|
74
|
+
...Object.keys(sodaGqlTransformerOptions).length > 0 && { sodaGqlTransformerOptions }
|
|
54
75
|
}
|
|
55
76
|
};
|
|
56
77
|
}
|
package/dist/index.cjs.map
CHANGED
|
@@ -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 * //
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["sodaGqlTransformerOptions: SodaGqlTransformerOptions"],"sources":["../src/index.ts"],"sourcesContent":["import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions, SodaGqlTransformerOptions } 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 SodaGqlTransformerOptions,\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 // 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 // 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 // Build sodaGqlTransformerOptions to pass to the transformer\n const sodaGqlTransformerOptions: SodaGqlTransformerOptions = {\n ...(upstreamTransformer && { upstreamTransformer }),\n ...(options.configPath && { configPath: options.configPath }),\n ...(options.transformer && { transformerType: options.transformer }),\n };\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n // Pass options to transformer via Metro config\n ...(Object.keys(sodaGqlTransformerOptions).length > 0 && { sodaGqlTransformerOptions }),\n },\n } as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,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;CAMzD,MAAM,sBAAsB,QAAQ,uBAAuB,OAAO,aAAa;CAG/E,MAAMA,4BAAuD;EAC3D,GAAI,uBAAuB,EAAE,qBAAqB;EAClD,GAAI,QAAQ,cAAc,EAAE,YAAY,QAAQ,YAAY;EAC5D,GAAI,QAAQ,eAAe,EAAE,iBAAiB,QAAQ,aAAa;EACpE;AAED,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GAEtB,GAAI,OAAO,KAAK,0BAA0B,CAAC,SAAS,KAAK,EAAE,2BAA2B;GACvF;EACF"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as
|
|
1
|
+
import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as SodaGqlTransformerOptions, r as MetroTransformParams, s as TransformerType, t as MetroConfig } from "./types-DEWrNhj2.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
|
-
* //
|
|
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
|
-
*
|
|
38
|
-
* debug: true,
|
|
52
|
+
* upstreamTransformer: require.resolve("react-native-svg-transformer"),
|
|
39
53
|
* });
|
|
40
54
|
* ```
|
|
41
55
|
*
|
|
@@ -45,5 +59,5 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
|
|
|
45
59
|
*/
|
|
46
60
|
declare function withSodaGql<T extends MetroConfig>(config: T, options?: MetroPluginOptions): T;
|
|
47
61
|
//#endregion
|
|
48
|
-
export { type MetroConfig, type MetroPluginOptions, type MetroTransformParams, type MetroTransformResult, type MetroTransformer, type TransformerType, getSharedArtifact, getSharedState, getStateKey, withSodaGql };
|
|
62
|
+
export { type MetroConfig, type MetroPluginOptions, type MetroTransformParams, type MetroTransformResult, type MetroTransformer, type SodaGqlTransformerOptions, type TransformerType, getSharedArtifact, getSharedState, getStateKey, withSodaGql };
|
|
49
63
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
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
|
|
1
|
+
import { a as MetroTransformer, i as MetroTransformResult, n as MetroPluginOptions, o as SodaGqlTransformerOptions, r as MetroTransformParams, s as TransformerType, t as MetroConfig } from "./types-D-K1oBE_.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
|
-
* //
|
|
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
|
-
*
|
|
38
|
-
* debug: true,
|
|
52
|
+
* upstreamTransformer: require.resolve("react-native-svg-transformer"),
|
|
39
53
|
* });
|
|
40
54
|
* ```
|
|
41
55
|
*
|
|
@@ -45,5 +59,5 @@ import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/builde
|
|
|
45
59
|
*/
|
|
46
60
|
declare function withSodaGql<T extends MetroConfig>(config: T, options?: MetroPluginOptions): T;
|
|
47
61
|
//#endregion
|
|
48
|
-
export { type MetroConfig, type MetroPluginOptions, type MetroTransformParams, type MetroTransformResult, type MetroTransformer, type TransformerType, getSharedArtifact, getSharedState, getStateKey, withSodaGql };
|
|
62
|
+
export { type MetroConfig, type MetroPluginOptions, type MetroTransformParams, type MetroTransformResult, type MetroTransformer, type SodaGqlTransformerOptions, type TransformerType, getSharedArtifact, getSharedState, getStateKey, withSodaGql };
|
|
49
63
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;
|
|
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
|
@@ -8,6 +8,9 @@ import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getState
|
|
|
8
8
|
* This function modifies the Metro configuration to use the soda-gql
|
|
9
9
|
* transformer, which applies GraphQL code transformations at build time.
|
|
10
10
|
*
|
|
11
|
+
* If the config already has a custom `babelTransformerPath` set (e.g., from
|
|
12
|
+
* react-native-svg-transformer), soda-gql will automatically chain with it.
|
|
13
|
+
*
|
|
11
14
|
* @example
|
|
12
15
|
* ```typescript
|
|
13
16
|
* // Expo project (metro.config.js)
|
|
@@ -30,11 +33,22 @@ import { getSharedArtifact, getSharedState, getStateKey, getStateKey as getState
|
|
|
30
33
|
*
|
|
31
34
|
* @example
|
|
32
35
|
* ```typescript
|
|
33
|
-
* //
|
|
36
|
+
* // Chaining with another transformer (e.g., react-native-svg-transformer)
|
|
37
|
+
* // The existing babelTransformerPath is automatically detected and chained.
|
|
38
|
+
* const { getDefaultConfig } = require("expo/metro-config");
|
|
39
|
+
* const { withSodaGql } = require("@soda-gql/metro-plugin");
|
|
40
|
+
*
|
|
41
|
+
* const config = getDefaultConfig(__dirname);
|
|
42
|
+
* config.transformer.babelTransformerPath = require.resolve("react-native-svg-transformer");
|
|
43
|
+
* module.exports = withSodaGql(config);
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Explicitly specifying upstream transformer
|
|
34
49
|
* const config = getDefaultConfig(__dirname);
|
|
35
50
|
* module.exports = withSodaGql(config, {
|
|
36
|
-
*
|
|
37
|
-
* debug: true,
|
|
51
|
+
* upstreamTransformer: require.resolve("react-native-svg-transformer"),
|
|
38
52
|
* });
|
|
39
53
|
* ```
|
|
40
54
|
*
|
|
@@ -46,11 +60,18 @@ function withSodaGql(config, options = {}) {
|
|
|
46
60
|
const transformerPath = __require.resolve("@soda-gql/metro-plugin/transformer");
|
|
47
61
|
const stateKey = getStateKey$1(options.configPath);
|
|
48
62
|
if (options.transformer) setSharedTransformerType(stateKey, options.transformer);
|
|
63
|
+
const upstreamTransformer = options.upstreamTransformer ?? config.transformer?.babelTransformerPath;
|
|
64
|
+
const sodaGqlTransformerOptions = {
|
|
65
|
+
...upstreamTransformer && { upstreamTransformer },
|
|
66
|
+
...options.configPath && { configPath: options.configPath },
|
|
67
|
+
...options.transformer && { transformerType: options.transformer }
|
|
68
|
+
};
|
|
49
69
|
return {
|
|
50
70
|
...config,
|
|
51
71
|
transformer: {
|
|
52
72
|
...config.transformer,
|
|
53
|
-
babelTransformerPath: transformerPath
|
|
73
|
+
babelTransformerPath: transformerPath,
|
|
74
|
+
...Object.keys(sodaGqlTransformerOptions).length > 0 && { sodaGqlTransformerOptions }
|
|
54
75
|
}
|
|
55
76
|
};
|
|
56
77
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -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 * //
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["getStateKey","sodaGqlTransformerOptions: SodaGqlTransformerOptions"],"sources":["../src/index.ts"],"sourcesContent":["import { getStateKey, setSharedTransformerType } from \"@soda-gql/builder/plugin-support\";\nimport type { MetroConfig, MetroPluginOptions, SodaGqlTransformerOptions } 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 SodaGqlTransformerOptions,\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 // 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 // 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 // Build sodaGqlTransformerOptions to pass to the transformer\n const sodaGqlTransformerOptions: SodaGqlTransformerOptions = {\n ...(upstreamTransformer && { upstreamTransformer }),\n ...(options.configPath && { configPath: options.configPath }),\n ...(options.transformer && { transformerType: options.transformer }),\n };\n\n return {\n ...config,\n transformer: {\n ...config.transformer,\n babelTransformerPath: transformerPath,\n // Pass options to transformer via Metro config\n ...(Object.keys(sodaGqlTransformerOptions).length > 0 && { sodaGqlTransformerOptions }),\n },\n } as T;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqEA,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;CAMzD,MAAM,sBAAsB,QAAQ,uBAAuB,OAAO,aAAa;CAG/E,MAAMC,4BAAuD;EAC3D,GAAI,uBAAuB,EAAE,qBAAqB;EAClD,GAAI,QAAQ,cAAc,EAAE,YAAY,QAAQ,YAAY;EAC5D,GAAI,QAAQ,eAAe,EAAE,iBAAiB,QAAQ,aAAa;EACpE;AAED,QAAO;EACL,GAAG;EACH,aAAa;GACX,GAAG,OAAO;GACV,sBAAsB;GAEtB,GAAI,OAAO,KAAK,0BAA0B,CAAC,SAAS,KAAK,EAAE,2BAA2B;GACvF;EACF"}
|
package/dist/transformer.cjs
CHANGED
|
@@ -819,6 +819,10 @@ const UPSTREAM_TRANSFORMER_CANDIDATES = [
|
|
|
819
819
|
*/
|
|
820
820
|
let upstreamTransformer = null;
|
|
821
821
|
/**
|
|
822
|
+
* Cached custom upstream transformer path (from sodaGqlTransformerOptions).
|
|
823
|
+
*/
|
|
824
|
+
let customUpstreamPath = null;
|
|
825
|
+
/**
|
|
822
826
|
* Try to resolve a module from multiple locations.
|
|
823
827
|
* Falls back through various resolution strategies.
|
|
824
828
|
*/
|
|
@@ -832,11 +836,29 @@ const tryResolve = (moduleName) => {
|
|
|
832
836
|
return null;
|
|
833
837
|
};
|
|
834
838
|
/**
|
|
839
|
+
* Set custom upstream transformer path from options.
|
|
840
|
+
* Called once during the first transform to capture the path from Metro options.
|
|
841
|
+
*/
|
|
842
|
+
const setCustomUpstreamPath = (sodaGqlOptions) => {
|
|
843
|
+
if (customUpstreamPath !== null) return;
|
|
844
|
+
customUpstreamPath = sodaGqlOptions?.upstreamTransformer ?? null;
|
|
845
|
+
};
|
|
846
|
+
/**
|
|
835
847
|
* Detect and load the upstream Metro Babel transformer.
|
|
836
|
-
*
|
|
848
|
+
* Priority:
|
|
849
|
+
* 1. Custom upstream path from sodaGqlTransformerOptions (set via setCustomUpstreamPath)
|
|
850
|
+
* 2. Default candidates in order of preference
|
|
837
851
|
*/
|
|
838
852
|
const getUpstreamTransformer = () => {
|
|
839
853
|
if (upstreamTransformer) return upstreamTransformer;
|
|
854
|
+
if (customUpstreamPath) {
|
|
855
|
+
const resolved = tryResolve(customUpstreamPath);
|
|
856
|
+
if (resolved) {
|
|
857
|
+
upstreamTransformer = require(resolved);
|
|
858
|
+
return upstreamTransformer;
|
|
859
|
+
}
|
|
860
|
+
console.warn(`[@soda-gql/metro-plugin] Custom upstream transformer not found: ${customUpstreamPath}. Falling back to default transformers.`);
|
|
861
|
+
}
|
|
840
862
|
for (const candidate of UPSTREAM_TRANSFORMER_CANDIDATES) {
|
|
841
863
|
const resolved = tryResolve(candidate);
|
|
842
864
|
if (resolved) {
|
|
@@ -900,6 +922,7 @@ const initializeSwcTransformer = async (artifact, config) => {
|
|
|
900
922
|
async function transform(params) {
|
|
901
923
|
const { src, filename, options } = params;
|
|
902
924
|
const stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)();
|
|
925
|
+
setCustomUpstreamPath(options.sodaGqlTransformerOptions);
|
|
903
926
|
const upstream = getUpstreamTransformer();
|
|
904
927
|
const session = ensurePluginSession();
|
|
905
928
|
if (!session) return upstream.transform(params);
|