@soda-gql/webpack-plugin 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,4 +1,4 @@
1
- let __soda_gql_plugin_common = require("@soda-gql/plugin-common");
1
+ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-support");
2
2
  let __soda_gql_builder = require("@soda-gql/builder");
3
3
  let __soda_gql_common = require("@soda-gql/common");
4
4
 
@@ -17,7 +17,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
17
17
  swcTransformer = null;
18
18
  constructor(options = {}) {
19
19
  this.options = options;
20
- this.stateKey = (0, __soda_gql_plugin_common.getStateKey)(options.configPath);
20
+ this.stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)(options.configPath);
21
21
  }
22
22
  apply(compiler) {
23
23
  compiler.hooks.beforeRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {
@@ -48,23 +48,23 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
48
48
  */
49
49
  async initialize() {
50
50
  if (this.pluginSession) return;
51
- const existingSession = (0, __soda_gql_plugin_common.getSharedPluginSession)(this.stateKey);
51
+ const existingSession = (0, __soda_gql_builder_plugin_support.getSharedPluginSession)(this.stateKey);
52
52
  if (existingSession) {
53
53
  this.pluginSession = existingSession;
54
54
  this.currentArtifact = await this.pluginSession.getArtifactAsync();
55
- (0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, this.currentArtifact);
55
+ (0, __soda_gql_builder_plugin_support.setSharedArtifact)(this.stateKey, this.currentArtifact);
56
56
  await this.initializeSwcTransformer();
57
57
  this.log(`Reusing session: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);
58
58
  return;
59
59
  }
60
- this.pluginSession = (0, __soda_gql_plugin_common.createPluginSession)(this.options, SodaGqlWebpackPlugin.pluginName);
60
+ this.pluginSession = (0, __soda_gql_builder_plugin_support.createPluginSession)(this.options, SodaGqlWebpackPlugin.pluginName);
61
61
  if (!this.pluginSession) {
62
62
  this.log("Plugin disabled or config load failed");
63
63
  return;
64
64
  }
65
- (0, __soda_gql_plugin_common.setSharedPluginSession)(this.stateKey, this.pluginSession);
65
+ (0, __soda_gql_builder_plugin_support.setSharedPluginSession)(this.stateKey, this.pluginSession);
66
66
  this.currentArtifact = await this.pluginSession.getArtifactAsync();
67
- (0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, this.currentArtifact);
67
+ (0, __soda_gql_builder_plugin_support.setSharedArtifact)(this.stateKey, this.currentArtifact);
68
68
  await this.initializeSwcTransformer();
69
69
  this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);
70
70
  }
@@ -76,7 +76,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
76
76
  if (!this.pluginSession) return;
77
77
  this.previousArtifact = this.currentArtifact;
78
78
  this.currentArtifact = await this.pluginSession.getArtifactAsync();
79
- (0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, this.currentArtifact);
79
+ (0, __soda_gql_builder_plugin_support.setSharedArtifact)(this.stateKey, this.currentArtifact);
80
80
  await this.initializeSwcTransformer();
81
81
  if (!this.currentArtifact) {
82
82
  this.log("Failed to build artifact");
@@ -84,7 +84,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
84
84
  }
85
85
  if (this.previousArtifact && this.hasArtifactChanged()) {
86
86
  const changedFiles = this.getChangedSodaGqlFiles();
87
- const sharedState = (0, __soda_gql_plugin_common.getSharedState)(this.stateKey);
87
+ const sharedState = (0, __soda_gql_builder_plugin_support.getSharedState)(this.stateKey);
88
88
  const affectedFiles = this.computeAffectedFiles(changedFiles, sharedState.moduleAdjacency);
89
89
  this.log(`Changed files: ${changedFiles.size}, Affected files: ${affectedFiles.size}`);
90
90
  }
@@ -157,22 +157,22 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
157
157
  if (this.options.transformer !== "swc") return;
158
158
  if (!this.currentArtifact || !this.pluginSession) {
159
159
  this.swcTransformer = null;
160
- (0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
160
+ (0, __soda_gql_builder_plugin_support.setSharedSwcTransformer)(this.stateKey, null);
161
161
  return;
162
162
  }
163
163
  try {
164
- const { createTransformer } = await import("@soda-gql/swc-transformer");
164
+ const { createTransformer } = await import("@soda-gql/swc");
165
165
  this.swcTransformer = await createTransformer({
166
166
  config: this.pluginSession.config,
167
167
  artifact: this.currentArtifact,
168
168
  sourceMap: true
169
169
  });
170
- (0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, this.swcTransformer);
170
+ (0, __soda_gql_builder_plugin_support.setSharedSwcTransformer)(this.stateKey, this.swcTransformer);
171
171
  this.log("SWC transformer initialized");
172
172
  } catch (error) {
173
- console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc-transformer is installed.`);
173
+ console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc is installed.`);
174
174
  this.swcTransformer = null;
175
- (0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
175
+ (0, __soda_gql_builder_plugin_support.setSharedSwcTransformer)(this.stateKey, null);
176
176
  }
177
177
  }
178
178
  /**
@@ -183,9 +183,9 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
183
183
  this.currentArtifact = null;
184
184
  this.previousArtifact = null;
185
185
  this.swcTransformer = null;
186
- (0, __soda_gql_plugin_common.setSharedPluginSession)(this.stateKey, null);
187
- (0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, null);
188
- (0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
186
+ (0, __soda_gql_builder_plugin_support.setSharedPluginSession)(this.stateKey, null);
187
+ (0, __soda_gql_builder_plugin_support.setSharedArtifact)(this.stateKey, null);
188
+ (0, __soda_gql_builder_plugin_support.setSharedSwcTransformer)(this.stateKey, null);
189
189
  }
190
190
  /**
191
191
  * Log a message if debug mode is enabled.
@@ -206,43 +206,43 @@ exports.SodaGqlWebpackPlugin = SodaGqlWebpackPlugin;
206
206
  Object.defineProperty(exports, 'getSharedArtifact', {
207
207
  enumerable: true,
208
208
  get: function () {
209
- return __soda_gql_plugin_common.getSharedArtifact;
209
+ return __soda_gql_builder_plugin_support.getSharedArtifact;
210
210
  }
211
211
  });
212
212
  Object.defineProperty(exports, 'getSharedBuilderService', {
213
213
  enumerable: true,
214
214
  get: function () {
215
- return __soda_gql_plugin_common.getSharedBuilderService;
215
+ return __soda_gql_builder_plugin_support.getSharedBuilderService;
216
216
  }
217
217
  });
218
218
  Object.defineProperty(exports, 'getSharedPluginSession', {
219
219
  enumerable: true,
220
220
  get: function () {
221
- return __soda_gql_plugin_common.getSharedPluginSession;
221
+ return __soda_gql_builder_plugin_support.getSharedPluginSession;
222
222
  }
223
223
  });
224
224
  Object.defineProperty(exports, 'getSharedState', {
225
225
  enumerable: true,
226
226
  get: function () {
227
- return __soda_gql_plugin_common.getSharedState;
227
+ return __soda_gql_builder_plugin_support.getSharedState;
228
228
  }
229
229
  });
230
230
  Object.defineProperty(exports, 'getStateKey', {
231
231
  enumerable: true,
232
232
  get: function () {
233
- return __soda_gql_plugin_common.getStateKey;
233
+ return __soda_gql_builder_plugin_support.getStateKey;
234
234
  }
235
235
  });
236
236
  Object.defineProperty(exports, 'setSharedBuilderService', {
237
237
  enumerable: true,
238
238
  get: function () {
239
- return __soda_gql_plugin_common.setSharedBuilderService;
239
+ return __soda_gql_builder_plugin_support.setSharedBuilderService;
240
240
  }
241
241
  });
242
242
  Object.defineProperty(exports, 'setSharedPluginSession', {
243
243
  enumerable: true,
244
244
  get: function () {
245
- return __soda_gql_plugin_common.setSharedPluginSession;
245
+ return __soda_gql_builder_plugin_support.setSharedPluginSession;
246
246
  }
247
247
  });
248
248
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { BuilderArtifact, BuilderArtifactElement } from \"@soda-gql/builder\";\nimport { collectAffectedFiles } from \"@soda-gql/builder\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport {\n createPluginSession,\n getSharedPluginSession,\n getSharedState,\n getStateKey,\n type PluginSession,\n type SwcTransformerInterface,\n setSharedArtifact,\n setSharedPluginSession,\n setSharedSwcTransformer,\n} from \"@soda-gql/plugin-common\";\nimport type { Compiler } from \"webpack\";\nimport type { WebpackPluginOptions } from \"./types\";\n\n/**\n * Webpack plugin for soda-gql that handles incremental rebuilds\n * when model files change during dev server execution.\n */\nexport class SodaGqlWebpackPlugin {\n static readonly pluginName = \"SodaGqlWebpackPlugin\";\n\n private readonly options: WebpackPluginOptions;\n private readonly stateKey: string;\n private pluginSession: PluginSession | null = null;\n private currentArtifact: BuilderArtifact | null = null;\n private previousArtifact: BuilderArtifact | null = null;\n private swcTransformer: SwcTransformerInterface | null = null;\n\n constructor(options: WebpackPluginOptions = {}) {\n this.options = options;\n this.stateKey = getStateKey(options.configPath);\n }\n\n apply(compiler: Compiler): void {\n // Initialize plugin session on first build\n compiler.hooks.beforeRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.initialize();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Handle watch mode\n compiler.hooks.watchRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.handleWatchRun();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Track file invalidations\n compiler.hooks.invalid.tap(SodaGqlWebpackPlugin.pluginName, (fileName, _changeTime) => {\n if (fileName) {\n this.handleFileInvalidation(fileName);\n }\n });\n\n // Cleanup on watch close\n compiler.hooks.watchClose.tap(SodaGqlWebpackPlugin.pluginName, () => {\n this.cleanup();\n });\n }\n\n /**\n * Initialize plugin session and build initial artifact.\n */\n private async initialize(): Promise<void> {\n if (this.pluginSession) return;\n\n // Try to reuse existing shared session (e.g., from client compilation in Next.js)\n const existingSession = getSharedPluginSession(this.stateKey);\n if (existingSession) {\n this.pluginSession = existingSession;\n\n // Still need to build artifact for this compilation\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Update shared artifact\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Initialize SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Reusing session: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n return;\n }\n\n // Fall back to creating new session (first plugin instance)\n this.pluginSession = createPluginSession(this.options, SodaGqlWebpackPlugin.pluginName);\n if (!this.pluginSession) {\n this.log(\"Plugin disabled or config load failed\");\n return;\n }\n\n // Share the plugin session with loader and other plugin instances\n setSharedPluginSession(this.stateKey, this.pluginSession);\n\n // Initial artifact build\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Create SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n }\n\n /**\n * Handle watch mode run - rebuild artifact and compute affected files.\n */\n private async handleWatchRun(): Promise<void> {\n if (!this.pluginSession) {\n await this.initialize();\n }\n\n if (!this.pluginSession) return;\n\n // Store previous artifact for comparison\n this.previousArtifact = this.currentArtifact;\n\n // Rebuild artifact (BuilderService handles change detection internally)\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Reinitialize SWC transformer with new artifact\n await this.initializeSwcTransformer();\n\n if (!this.currentArtifact) {\n this.log(\"Failed to build artifact\");\n return;\n }\n\n // Log artifact changes for debugging (loader handles dependency tracking)\n if (this.previousArtifact && this.hasArtifactChanged()) {\n const changedFiles = this.getChangedSodaGqlFiles();\n const sharedState = getSharedState(this.stateKey);\n const affectedFiles = this.computeAffectedFiles(changedFiles, sharedState.moduleAdjacency);\n\n this.log(`Changed files: ${changedFiles.size}, Affected files: ${affectedFiles.size}`);\n }\n }\n\n /**\n * Handle file invalidation event from webpack.\n */\n private handleFileInvalidation(fileName: string): void {\n const normalized = normalizePath(fileName);\n if (this.isSodaGqlFile(normalized)) {\n this.log(`soda-gql file changed: ${normalized}`);\n }\n }\n\n /**\n * Check if artifact has changed by comparing element counts and hashes.\n */\n private hasArtifactChanged(): boolean {\n if (!this.previousArtifact || !this.currentArtifact) return true;\n\n const prevCount = Object.keys(this.previousArtifact.elements).length;\n const newCount = Object.keys(this.currentArtifact.elements).length;\n if (prevCount !== newCount) return true;\n\n // Compare individual elements by their content hash\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n if (!prevElement) return true;\n // Compare using metadata\n if (element.metadata.contentHash !== prevElement.metadata.contentHash) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get files that changed between previous and current artifact.\n */\n private getChangedSodaGqlFiles(): Set<string> {\n const changed = new Set<string>();\n\n if (!this.previousArtifact || !this.currentArtifact) return changed;\n\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n // Compare elements by their source paths and content hashes\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n const sourcePath = element.metadata.sourcePath;\n\n if (!prevElement || prevElement.metadata.contentHash !== element.metadata.contentHash) {\n changed.add(normalizePath(sourcePath));\n }\n }\n\n // Check for removed elements\n for (const [id, element] of Object.entries(prevElements)) {\n if (!currElements[id]) {\n const sourcePath = element.metadata.sourcePath;\n changed.add(normalizePath(sourcePath));\n }\n }\n\n return changed;\n }\n\n /**\n * Compute all files affected by the changed files using module adjacency.\n */\n private computeAffectedFiles(changedFiles: Set<string>, moduleAdjacency: Map<string, Set<string>>): Set<string> {\n // Use the existing collectAffectedFiles from builder\n return collectAffectedFiles({\n changedFiles,\n removedFiles: new Set(),\n previousModuleAdjacency: moduleAdjacency,\n });\n }\n\n /**\n * Check if a file path corresponds to a soda-gql source file.\n */\n private isSodaGqlFile(filePath: string): boolean {\n if (!this.currentArtifact) return false;\n\n const normalized = normalizePath(filePath);\n for (const element of Object.values(this.currentArtifact.elements)) {\n if (normalizePath(element.metadata.sourcePath) === normalized) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Initialize SWC transformer if configured.\n * Creates a new transformer instance with the current artifact.\n */\n private async initializeSwcTransformer(): Promise<void> {\n if (this.options.transformer !== \"swc\") {\n return;\n }\n\n if (!this.currentArtifact || !this.pluginSession) {\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n return;\n }\n\n try {\n const { createTransformer } = await import(\"@soda-gql/swc-transformer\");\n this.swcTransformer = await createTransformer({\n config: this.pluginSession.config,\n artifact: this.currentArtifact,\n sourceMap: true,\n });\n setSharedSwcTransformer(this.stateKey, this.swcTransformer);\n this.log(\"SWC transformer initialized\");\n } catch (error) {\n console.warn(\n `[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. ` +\n \"Make sure @soda-gql/swc-transformer is installed.\",\n );\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n }\n }\n\n /**\n * Cleanup resources.\n */\n private cleanup(): void {\n this.pluginSession = null;\n this.currentArtifact = null;\n this.previousArtifact = null;\n this.swcTransformer = null;\n setSharedPluginSession(this.stateKey, null);\n setSharedArtifact(this.stateKey, null);\n setSharedSwcTransformer(this.stateKey, null);\n }\n\n /**\n * Log a message if debug mode is enabled.\n */\n private log(message: string): void {\n if (this.options.debug) {\n console.log(`[${SodaGqlWebpackPlugin.pluginName}] ${message}`);\n }\n }\n\n /**\n * Get the current artifact (for use by loader).\n */\n getArtifact(): BuilderArtifact | null {\n return this.currentAr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F,MAAM,EAAE,sBAAsB,MAAM,OAAO;AAC3C,QAAK,iBAAiB,MAAM,kBAAkB;IAC5C,QAAQ,KAAK,cAAc;IAC3B,UAAU,KAAK;IACf,WAAW;IACZ,CAAC;AACF,yDAAwB,KAAK,UAAU,KAAK,eAAe;AAC3D,QAAK,IAAI,8BAA8B;WAChC,OAAO;AACd,WAAQ,KACN,oEAAoE,MAAM,qDAE3E;AACD,QAAK,iBAAiB;AACtB,yDAAwB,KAAK,UAAU,KAAK;;;;;;CAOhD,AAAQ,UAAgB;AACtB,OAAK,gBAAgB;AACrB,OAAK,kBAAkB;AACvB,OAAK,mBAAmB;AACxB,OAAK,iBAAiB;AACtB,uDAAuB,KAAK,UAAU,KAAK;AAC3C,kDAAkB,KAAK,UAAU,KAAK;AACtC,wDAAwB,KAAK,UAAU,KAAK;;;;;CAM9C,AAAQ,IAAI,SAAuB;AACjC,MAAI,KAAK,QAAQ,MACf,SAAQ,IAAI,IAAI,qBAAqB,WAAW,IAAI,UAAU;;;;;CAOlE,cAAsC;AACpC,SAAO,KAAK"}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/plugin.ts"],"sourcesContent":["import type { BuilderArtifact, BuilderArtifactElement } from \"@soda-gql/builder\";\nimport { collectAffectedFiles } from \"@soda-gql/builder\";\nimport {\n createPluginSession,\n getSharedPluginSession,\n getSharedState,\n getStateKey,\n type PluginSession,\n type SwcTransformerInterface,\n setSharedArtifact,\n setSharedPluginSession,\n setSharedSwcTransformer,\n} from \"@soda-gql/builder/plugin-support\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport type { Compiler } from \"webpack\";\nimport type { WebpackPluginOptions } from \"./types\";\n\n/**\n * Webpack plugin for soda-gql that handles incremental rebuilds\n * when model files change during dev server execution.\n */\nexport class SodaGqlWebpackPlugin {\n static readonly pluginName = \"SodaGqlWebpackPlugin\";\n\n private readonly options: WebpackPluginOptions;\n private readonly stateKey: string;\n private pluginSession: PluginSession | null = null;\n private currentArtifact: BuilderArtifact | null = null;\n private previousArtifact: BuilderArtifact | null = null;\n private swcTransformer: SwcTransformerInterface | null = null;\n\n constructor(options: WebpackPluginOptions = {}) {\n this.options = options;\n this.stateKey = getStateKey(options.configPath);\n }\n\n apply(compiler: Compiler): void {\n // Initialize plugin session on first build\n compiler.hooks.beforeRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.initialize();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Handle watch mode\n compiler.hooks.watchRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.handleWatchRun();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Track file invalidations\n compiler.hooks.invalid.tap(SodaGqlWebpackPlugin.pluginName, (fileName, _changeTime) => {\n if (fileName) {\n this.handleFileInvalidation(fileName);\n }\n });\n\n // Cleanup on watch close\n compiler.hooks.watchClose.tap(SodaGqlWebpackPlugin.pluginName, () => {\n this.cleanup();\n });\n }\n\n /**\n * Initialize plugin session and build initial artifact.\n */\n private async initialize(): Promise<void> {\n if (this.pluginSession) return;\n\n // Try to reuse existing shared session (e.g., from client compilation in Next.js)\n const existingSession = getSharedPluginSession(this.stateKey);\n if (existingSession) {\n this.pluginSession = existingSession;\n\n // Still need to build artifact for this compilation\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Update shared artifact\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Initialize SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Reusing session: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n return;\n }\n\n // Fall back to creating new session (first plugin instance)\n this.pluginSession = createPluginSession(this.options, SodaGqlWebpackPlugin.pluginName);\n if (!this.pluginSession) {\n this.log(\"Plugin disabled or config load failed\");\n return;\n }\n\n // Share the plugin session with loader and other plugin instances\n setSharedPluginSession(this.stateKey, this.pluginSession);\n\n // Initial artifact build\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Create SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n }\n\n /**\n * Handle watch mode run - rebuild artifact and compute affected files.\n */\n private async handleWatchRun(): Promise<void> {\n if (!this.pluginSession) {\n await this.initialize();\n }\n\n if (!this.pluginSession) return;\n\n // Store previous artifact for comparison\n this.previousArtifact = this.currentArtifact;\n\n // Rebuild artifact (BuilderService handles change detection internally)\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Reinitialize SWC transformer with new artifact\n await this.initializeSwcTransformer();\n\n if (!this.currentArtifact) {\n this.log(\"Failed to build artifact\");\n return;\n }\n\n // Log artifact changes for debugging (loader handles dependency tracking)\n if (this.previousArtifact && this.hasArtifactChanged()) {\n const changedFiles = this.getChangedSodaGqlFiles();\n const sharedState = getSharedState(this.stateKey);\n const affectedFiles = this.computeAffectedFiles(changedFiles, sharedState.moduleAdjacency);\n\n this.log(`Changed files: ${changedFiles.size}, Affected files: ${affectedFiles.size}`);\n }\n }\n\n /**\n * Handle file invalidation event from webpack.\n */\n private handleFileInvalidation(fileName: string): void {\n const normalized = normalizePath(fileName);\n if (this.isSodaGqlFile(normalized)) {\n this.log(`soda-gql file changed: ${normalized}`);\n }\n }\n\n /**\n * Check if artifact has changed by comparing element counts and hashes.\n */\n private hasArtifactChanged(): boolean {\n if (!this.previousArtifact || !this.currentArtifact) return true;\n\n const prevCount = Object.keys(this.previousArtifact.elements).length;\n const newCount = Object.keys(this.currentArtifact.elements).length;\n if (prevCount !== newCount) return true;\n\n // Compare individual elements by their content hash\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n if (!prevElement) return true;\n // Compare using metadata\n if (element.metadata.contentHash !== prevElement.metadata.contentHash) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get files that changed between previous and current artifact.\n */\n private getChangedSodaGqlFiles(): Set<string> {\n const changed = new Set<string>();\n\n if (!this.previousArtifact || !this.currentArtifact) return changed;\n\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n // Compare elements by their source paths and content hashes\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n const sourcePath = element.metadata.sourcePath;\n\n if (!prevElement || prevElement.metadata.contentHash !== element.metadata.contentHash) {\n changed.add(normalizePath(sourcePath));\n }\n }\n\n // Check for removed elements\n for (const [id, element] of Object.entries(prevElements)) {\n if (!currElements[id]) {\n const sourcePath = element.metadata.sourcePath;\n changed.add(normalizePath(sourcePath));\n }\n }\n\n return changed;\n }\n\n /**\n * Compute all files affected by the changed files using module adjacency.\n */\n private computeAffectedFiles(changedFiles: Set<string>, moduleAdjacency: Map<string, Set<string>>): Set<string> {\n // Use the existing collectAffectedFiles from builder\n return collectAffectedFiles({\n changedFiles,\n removedFiles: new Set(),\n previousModuleAdjacency: moduleAdjacency,\n });\n }\n\n /**\n * Check if a file path corresponds to a soda-gql source file.\n */\n private isSodaGqlFile(filePath: string): boolean {\n if (!this.currentArtifact) return false;\n\n const normalized = normalizePath(filePath);\n for (const element of Object.values(this.currentArtifact.elements)) {\n if (normalizePath(element.metadata.sourcePath) === normalized) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Initialize SWC transformer if configured.\n * Creates a new transformer instance with the current artifact.\n */\n private async initializeSwcTransformer(): Promise<void> {\n if (this.options.transformer !== \"swc\") {\n return;\n }\n\n if (!this.currentArtifact || !this.pluginSession) {\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n return;\n }\n\n try {\n const { createTransformer } = await import(\"@soda-gql/swc\");\n this.swcTransformer = await createTransformer({\n config: this.pluginSession.config,\n artifact: this.currentArtifact,\n sourceMap: true,\n });\n setSharedSwcTransformer(this.stateKey, this.swcTransformer);\n this.log(\"SWC transformer initialized\");\n } catch (error) {\n console.warn(\n `[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc is installed.`,\n );\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n }\n }\n\n /**\n * Cleanup resources.\n */\n private cleanup(): void {\n this.pluginSession = null;\n this.currentArtifact = null;\n this.previousArtifact = null;\n this.swcTransformer = null;\n setSharedPluginSession(this.stateKey, null);\n setSharedArtifact(this.stateKey, null);\n setSharedSwcTransformer(this.stateKey, null);\n }\n\n /**\n * Log a message if debug mode is enabled.\n */\n private log(message: string): void {\n if (this.options.debug) {\n console.log(`[${SodaGqlWebpackPlugin.pluginName}] ${message}`);\n }\n }\n\n /**\n * Get the current artifact (for use by loader).\n */\n getArtifact(): BuilderArtifact | null {\n return this.currentArtifact;\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAgB,aAAa;CAE7B,AAAiB;CACjB,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,kBAA0C;CAClD,AAAQ,mBAA2C;CACnD,AAAQ,iBAAiD;CAEzD,YAAY,UAAgC,EAAE,EAAE;AAC9C,OAAK,UAAU;AACf,OAAK,8DAAuB,QAAQ,WAAW;;CAGjD,MAAM,UAA0B;AAE9B,WAAS,MAAM,UAAU,SAAS,qBAAqB,YAAY,OAAO,WAAW,aAAa;AAChG,OAAI;AACF,UAAM,KAAK,YAAY;AACvB,cAAU;YACH,OAAO;AACd,aAAS,MAAe;;IAE1B;AAGF,WAAS,MAAM,SAAS,SAAS,qBAAqB,YAAY,OAAO,WAAW,aAAa;AAC/F,OAAI;AACF,UAAM,KAAK,gBAAgB;AAC3B,cAAU;YACH,OAAO;AACd,aAAS,MAAe;;IAE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qB,WAAW,IAAI,UAAU;;;;;CAOlE,cAAsC;AACpC,SAAO,KAAK"}
package/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-BJUU2U2w.cjs";
2
- import { getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedState, getStateKey, setSharedBuilderService, setSharedPluginSession } from "@soda-gql/plugin-common";
1
+ import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-D39igyVT.cjs";
2
+ import { getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedState, getStateKey, setSharedBuilderService, setSharedPluginSession } from "@soda-gql/builder/plugin-support";
3
3
  import { BuilderArtifact } from "@soda-gql/builder";
4
4
  import { Compiler } from "webpack";
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA;AAUuB,cAVV,oBAAA,CAUU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EA+QD,iBAAA,OAAA;EAAe,iBAAA,QAAA;;;;;wBApRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+QD"}
1
+ {"version":3,"file":"index.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA;AAUuB,cAVV,oBAAA,CAUU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EA8QD,iBAAA,OAAA;EAAe,iBAAA,QAAA;;;;;wBAnRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8QD"}
package/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-DxhQ4VI-.mjs";
2
- import { getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedState, getStateKey, setSharedBuilderService, setSharedPluginSession } from "@soda-gql/plugin-common";
1
+ import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-B9bA0Wbk.mjs";
2
+ import { getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedState, getStateKey, setSharedBuilderService, setSharedPluginSession } from "@soda-gql/builder/plugin-support";
3
3
  import { BuilderArtifact } from "@soda-gql/builder";
4
4
  import { Compiler } from "webpack";
5
5
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA;AAUuB,cAVV,oBAAA,CAUU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EA+QD,iBAAA,OAAA;EAAe,iBAAA,QAAA;;;;;wBApRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+QD"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAqBA;AAUuB,cAVV,oBAAA,CAUU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EA8QD,iBAAA,OAAA;EAAe,iBAAA,QAAA;;;;;wBAnRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8QD"}
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createPluginSession, getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedPluginSession as getSharedPluginSession$1, getSharedState, getSharedState as getSharedState$1, getStateKey, getStateKey as getStateKey$1, setSharedArtifact, setSharedBuilderService, setSharedPluginSession, setSharedPluginSession as setSharedPluginSession$1, setSharedSwcTransformer } from "@soda-gql/plugin-common";
1
+ import { createPluginSession, getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedPluginSession as getSharedPluginSession$1, getSharedState, getSharedState as getSharedState$1, getStateKey, getStateKey as getStateKey$1, setSharedArtifact, setSharedBuilderService, setSharedPluginSession, setSharedPluginSession as setSharedPluginSession$1, setSharedSwcTransformer } from "@soda-gql/builder/plugin-support";
2
2
  import { collectAffectedFiles } from "@soda-gql/builder";
3
3
  import { normalizePath } from "@soda-gql/common";
4
4
 
@@ -161,7 +161,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
161
161
  return;
162
162
  }
163
163
  try {
164
- const { createTransformer } = await import("@soda-gql/swc-transformer");
164
+ const { createTransformer } = await import("@soda-gql/swc");
165
165
  this.swcTransformer = await createTransformer({
166
166
  config: this.pluginSession.config,
167
167
  artifact: this.currentArtifact,
@@ -170,7 +170,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
170
170
  setSharedSwcTransformer(this.stateKey, this.swcTransformer);
171
171
  this.log("SWC transformer initialized");
172
172
  } catch (error) {
173
- console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc-transformer is installed.`);
173
+ console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc is installed.`);
174
174
  this.swcTransformer = null;
175
175
  setSharedSwcTransformer(this.stateKey, null);
176
176
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["getStateKey","getSharedPluginSession","getSharedState"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { BuilderArtifact, BuilderArtifactElement } from \"@soda-gql/builder\";\nimport { collectAffectedFiles } from \"@soda-gql/builder\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport {\n createPluginSession,\n getSharedPluginSession,\n getSharedState,\n getStateKey,\n type PluginSession,\n type SwcTransformerInterface,\n setSharedArtifact,\n setSharedPluginSession,\n setSharedSwcTransformer,\n} from \"@soda-gql/plugin-common\";\nimport type { Compiler } from \"webpack\";\nimport type { WebpackPluginOptions } from \"./types\";\n\n/**\n * Webpack plugin for soda-gql that handles incremental rebuilds\n * when model files change during dev server execution.\n */\nexport class SodaGqlWebpackPlugin {\n static readonly pluginName = \"SodaGqlWebpackPlugin\";\n\n private readonly options: WebpackPluginOptions;\n private readonly stateKey: string;\n private pluginSession: PluginSession | null = null;\n private currentArtifact: BuilderArtifact | null = null;\n private previousArtifact: BuilderArtifact | null = null;\n private swcTransformer: SwcTransformerInterface | null = null;\n\n constructor(options: WebpackPluginOptions = {}) {\n this.options = options;\n this.stateKey = getStateKey(options.configPath);\n }\n\n apply(compiler: Compiler): void {\n // Initialize plugin session on first build\n compiler.hooks.beforeRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.initialize();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Handle watch mode\n compiler.hooks.watchRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.handleWatchRun();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Track file invalidations\n compiler.hooks.invalid.tap(SodaGqlWebpackPlugin.pluginName, (fileName, _changeTime) => {\n if (fileName) {\n this.handleFileInvalidation(fileName);\n }\n });\n\n // Cleanup on watch close\n compiler.hooks.watchClose.tap(SodaGqlWebpackPlugin.pluginName, () => {\n this.cleanup();\n });\n }\n\n /**\n * Initialize plugin session and build initial artifact.\n */\n private async initialize(): Promise<void> {\n if (this.pluginSession) return;\n\n // Try to reuse existing shared session (e.g., from client compilation in Next.js)\n const existingSession = getSharedPluginSession(this.stateKey);\n if (existingSession) {\n this.pluginSession = existingSession;\n\n // Still need to build artifact for this compilation\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Update shared artifact\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Initialize SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Reusing session: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n return;\n }\n\n // Fall back to creating new session (first plugin instance)\n this.pluginSession = createPluginSession(this.options, SodaGqlWebpackPlugin.pluginName);\n if (!this.pluginSession) {\n this.log(\"Plugin disabled or config load failed\");\n return;\n }\n\n // Share the plugin session with loader and other plugin instances\n setSharedPluginSession(this.stateKey, this.pluginSession);\n\n // Initial artifact build\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Create SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n }\n\n /**\n * Handle watch mode run - rebuild artifact and compute affected files.\n */\n private async handleWatchRun(): Promise<void> {\n if (!this.pluginSession) {\n await this.initialize();\n }\n\n if (!this.pluginSession) return;\n\n // Store previous artifact for comparison\n this.previousArtifact = this.currentArtifact;\n\n // Rebuild artifact (BuilderService handles change detection internally)\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Reinitialize SWC transformer with new artifact\n await this.initializeSwcTransformer();\n\n if (!this.currentArtifact) {\n this.log(\"Failed to build artifact\");\n return;\n }\n\n // Log artifact changes for debugging (loader handles dependency tracking)\n if (this.previousArtifact && this.hasArtifactChanged()) {\n const changedFiles = this.getChangedSodaGqlFiles();\n const sharedState = getSharedState(this.stateKey);\n const affectedFiles = this.computeAffectedFiles(changedFiles, sharedState.moduleAdjacency);\n\n this.log(`Changed files: ${changedFiles.size}, Affected files: ${affectedFiles.size}`);\n }\n }\n\n /**\n * Handle file invalidation event from webpack.\n */\n private handleFileInvalidation(fileName: string): void {\n const normalized = normalizePath(fileName);\n if (this.isSodaGqlFile(normalized)) {\n this.log(`soda-gql file changed: ${normalized}`);\n }\n }\n\n /**\n * Check if artifact has changed by comparing element counts and hashes.\n */\n private hasArtifactChanged(): boolean {\n if (!this.previousArtifact || !this.currentArtifact) return true;\n\n const prevCount = Object.keys(this.previousArtifact.elements).length;\n const newCount = Object.keys(this.currentArtifact.elements).length;\n if (prevCount !== newCount) return true;\n\n // Compare individual elements by their content hash\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n if (!prevElement) return true;\n // Compare using metadata\n if (element.metadata.contentHash !== prevElement.metadata.contentHash) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get files that changed between previous and current artifact.\n */\n private getChangedSodaGqlFiles(): Set<string> {\n const changed = new Set<string>();\n\n if (!this.previousArtifact || !this.currentArtifact) return changed;\n\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n // Compare elements by their source paths and content hashes\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n const sourcePath = element.metadata.sourcePath;\n\n if (!prevElement || prevElement.metadata.contentHash !== element.metadata.contentHash) {\n changed.add(normalizePath(sourcePath));\n }\n }\n\n // Check for removed elements\n for (const [id, element] of Object.entries(prevElements)) {\n if (!currElements[id]) {\n const sourcePath = element.metadata.sourcePath;\n changed.add(normalizePath(sourcePath));\n }\n }\n\n return changed;\n }\n\n /**\n * Compute all files affected by the changed files using module adjacency.\n */\n private computeAffectedFiles(changedFiles: Set<string>, moduleAdjacency: Map<string, Set<string>>): Set<string> {\n // Use the existing collectAffectedFiles from builder\n return collectAffectedFiles({\n changedFiles,\n removedFiles: new Set(),\n previousModuleAdjacency: moduleAdjacency,\n });\n }\n\n /**\n * Check if a file path corresponds to a soda-gql source file.\n */\n private isSodaGqlFile(filePath: string): boolean {\n if (!this.currentArtifact) return false;\n\n const normalized = normalizePath(filePath);\n for (const element of Object.values(this.currentArtifact.elements)) {\n if (normalizePath(element.metadata.sourcePath) === normalized) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Initialize SWC transformer if configured.\n * Creates a new transformer instance with the current artifact.\n */\n private async initializeSwcTransformer(): Promise<void> {\n if (this.options.transformer !== \"swc\") {\n return;\n }\n\n if (!this.currentArtifact || !this.pluginSession) {\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n return;\n }\n\n try {\n const { createTransformer } = await import(\"@soda-gql/swc-transformer\");\n this.swcTransformer = await createTransformer({\n config: this.pluginSession.config,\n artifact: this.currentArtifact,\n sourceMap: true,\n });\n setSharedSwcTransformer(this.stateKey, this.swcTransformer);\n this.log(\"SWC transformer initialized\");\n } catch (error) {\n console.warn(\n `[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. ` +\n \"Make sure @soda-gql/swc-transformer is installed.\",\n );\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n }\n }\n\n /**\n * Cleanup resources.\n */\n private cleanup(): void {\n this.pluginSession = null;\n this.currentArtifact = null;\n this.previousArtifact = null;\n this.swcTransformer = null;\n setSharedPluginSession(this.stateKey, null);\n setSharedArtifact(this.stateKey, null);\n setSharedSwcTransformer(this.stateKey, null);\n }\n\n /**\n * Log a message if debug mode is enabled.\n */\n private log(message: string): void {\n if (this.options.debug) {\n console.log(`[${SodaGqlWebpackPlugin.pluginName}] ${message}`);\n }\n }\n\n /**\n * Get the current artifact (for use by loader).\n */\n getArtifact(): BuilderArtifact | null {\n return this.currentArtifact;\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAgB,aAAa;CAE7B,AAAiB;CACjB,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,kBAA0C;CAClD,AAAQ,mBAA2C;CACnD,AAAQ,iBAAiD;CAEzD,YAAY,UAAgC,EAAE,EAAE;AAC9C,OAAK,UAAU;AACf,OAAK,WAAWA,cAAY,QAAQ,WAAW;;CAGjD,MAAM,UAA0B;AAE9B,WAAS,MAAM,UAAU,SAAS,qBAAqB,YAAY,OAAO,WAAW,aAAa;AAChG,OAAI;AACF,UAAM,KAAK,YAAY;AACvB,cAAU;YACH,OAAO;AACd,aAAS,MAAe;;IAE1B;AAGF,WAAS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ACtB,2BAAuB,KAAK,UAAU,KAAK;AAC3C,oBAAkB,KAAK,UAAU,KAAK;AACtC,0BAAwB,KAAK,UAAU,KAAK;;;;;CAM9C,AAAQ,IAAI,SAAuB;AACjC,MAAI,KAAK,QAAQ,MACf,SAAQ,IAAI,IAAI,qBAAqB,WAAW,IAAI,UAAU;;;;;CAOlE,cAAsC;AACpC,SAAO,KAAK"}
1
+ {"version":3,"file":"index.mjs","names":["getStateKey","getSharedPluginSession","getSharedState"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { BuilderArtifact, BuilderArtifactElement } from \"@soda-gql/builder\";\nimport { collectAffectedFiles } from \"@soda-gql/builder\";\nimport {\n createPluginSession,\n getSharedPluginSession,\n getSharedState,\n getStateKey,\n type PluginSession,\n type SwcTransformerInterface,\n setSharedArtifact,\n setSharedPluginSession,\n setSharedSwcTransformer,\n} from \"@soda-gql/builder/plugin-support\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport type { Compiler } from \"webpack\";\nimport type { WebpackPluginOptions } from \"./types\";\n\n/**\n * Webpack plugin for soda-gql that handles incremental rebuilds\n * when model files change during dev server execution.\n */\nexport class SodaGqlWebpackPlugin {\n static readonly pluginName = \"SodaGqlWebpackPlugin\";\n\n private readonly options: WebpackPluginOptions;\n private readonly stateKey: string;\n private pluginSession: PluginSession | null = null;\n private currentArtifact: BuilderArtifact | null = null;\n private previousArtifact: BuilderArtifact | null = null;\n private swcTransformer: SwcTransformerInterface | null = null;\n\n constructor(options: WebpackPluginOptions = {}) {\n this.options = options;\n this.stateKey = getStateKey(options.configPath);\n }\n\n apply(compiler: Compiler): void {\n // Initialize plugin session on first build\n compiler.hooks.beforeRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.initialize();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Handle watch mode\n compiler.hooks.watchRun.tapAsync(SodaGqlWebpackPlugin.pluginName, async (_compiler, callback) => {\n try {\n await this.handleWatchRun();\n callback();\n } catch (error) {\n callback(error as Error);\n }\n });\n\n // Track file invalidations\n compiler.hooks.invalid.tap(SodaGqlWebpackPlugin.pluginName, (fileName, _changeTime) => {\n if (fileName) {\n this.handleFileInvalidation(fileName);\n }\n });\n\n // Cleanup on watch close\n compiler.hooks.watchClose.tap(SodaGqlWebpackPlugin.pluginName, () => {\n this.cleanup();\n });\n }\n\n /**\n * Initialize plugin session and build initial artifact.\n */\n private async initialize(): Promise<void> {\n if (this.pluginSession) return;\n\n // Try to reuse existing shared session (e.g., from client compilation in Next.js)\n const existingSession = getSharedPluginSession(this.stateKey);\n if (existingSession) {\n this.pluginSession = existingSession;\n\n // Still need to build artifact for this compilation\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Update shared artifact\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Initialize SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Reusing session: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n return;\n }\n\n // Fall back to creating new session (first plugin instance)\n this.pluginSession = createPluginSession(this.options, SodaGqlWebpackPlugin.pluginName);\n if (!this.pluginSession) {\n this.log(\"Plugin disabled or config load failed\");\n return;\n }\n\n // Share the plugin session with loader and other plugin instances\n setSharedPluginSession(this.stateKey, this.pluginSession);\n\n // Initial artifact build\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Create SWC transformer if configured\n await this.initializeSwcTransformer();\n\n this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);\n }\n\n /**\n * Handle watch mode run - rebuild artifact and compute affected files.\n */\n private async handleWatchRun(): Promise<void> {\n if (!this.pluginSession) {\n await this.initialize();\n }\n\n if (!this.pluginSession) return;\n\n // Store previous artifact for comparison\n this.previousArtifact = this.currentArtifact;\n\n // Rebuild artifact (BuilderService handles change detection internally)\n this.currentArtifact = await this.pluginSession.getArtifactAsync();\n\n // Share artifact with loader\n setSharedArtifact(this.stateKey, this.currentArtifact);\n\n // Reinitialize SWC transformer with new artifact\n await this.initializeSwcTransformer();\n\n if (!this.currentArtifact) {\n this.log(\"Failed to build artifact\");\n return;\n }\n\n // Log artifact changes for debugging (loader handles dependency tracking)\n if (this.previousArtifact && this.hasArtifactChanged()) {\n const changedFiles = this.getChangedSodaGqlFiles();\n const sharedState = getSharedState(this.stateKey);\n const affectedFiles = this.computeAffectedFiles(changedFiles, sharedState.moduleAdjacency);\n\n this.log(`Changed files: ${changedFiles.size}, Affected files: ${affectedFiles.size}`);\n }\n }\n\n /**\n * Handle file invalidation event from webpack.\n */\n private handleFileInvalidation(fileName: string): void {\n const normalized = normalizePath(fileName);\n if (this.isSodaGqlFile(normalized)) {\n this.log(`soda-gql file changed: ${normalized}`);\n }\n }\n\n /**\n * Check if artifact has changed by comparing element counts and hashes.\n */\n private hasArtifactChanged(): boolean {\n if (!this.previousArtifact || !this.currentArtifact) return true;\n\n const prevCount = Object.keys(this.previousArtifact.elements).length;\n const newCount = Object.keys(this.currentArtifact.elements).length;\n if (prevCount !== newCount) return true;\n\n // Compare individual elements by their content hash\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n if (!prevElement) return true;\n // Compare using metadata\n if (element.metadata.contentHash !== prevElement.metadata.contentHash) {\n return true;\n }\n }\n\n return false;\n }\n\n /**\n * Get files that changed between previous and current artifact.\n */\n private getChangedSodaGqlFiles(): Set<string> {\n const changed = new Set<string>();\n\n if (!this.previousArtifact || !this.currentArtifact) return changed;\n\n const prevElements = this.previousArtifact.elements as Record<string, BuilderArtifactElement>;\n const currElements = this.currentArtifact.elements as Record<string, BuilderArtifactElement>;\n\n // Compare elements by their source paths and content hashes\n for (const [id, element] of Object.entries(currElements)) {\n const prevElement = prevElements[id];\n const sourcePath = element.metadata.sourcePath;\n\n if (!prevElement || prevElement.metadata.contentHash !== element.metadata.contentHash) {\n changed.add(normalizePath(sourcePath));\n }\n }\n\n // Check for removed elements\n for (const [id, element] of Object.entries(prevElements)) {\n if (!currElements[id]) {\n const sourcePath = element.metadata.sourcePath;\n changed.add(normalizePath(sourcePath));\n }\n }\n\n return changed;\n }\n\n /**\n * Compute all files affected by the changed files using module adjacency.\n */\n private computeAffectedFiles(changedFiles: Set<string>, moduleAdjacency: Map<string, Set<string>>): Set<string> {\n // Use the existing collectAffectedFiles from builder\n return collectAffectedFiles({\n changedFiles,\n removedFiles: new Set(),\n previousModuleAdjacency: moduleAdjacency,\n });\n }\n\n /**\n * Check if a file path corresponds to a soda-gql source file.\n */\n private isSodaGqlFile(filePath: string): boolean {\n if (!this.currentArtifact) return false;\n\n const normalized = normalizePath(filePath);\n for (const element of Object.values(this.currentArtifact.elements)) {\n if (normalizePath(element.metadata.sourcePath) === normalized) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Initialize SWC transformer if configured.\n * Creates a new transformer instance with the current artifact.\n */\n private async initializeSwcTransformer(): Promise<void> {\n if (this.options.transformer !== \"swc\") {\n return;\n }\n\n if (!this.currentArtifact || !this.pluginSession) {\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n return;\n }\n\n try {\n const { createTransformer } = await import(\"@soda-gql/swc\");\n this.swcTransformer = await createTransformer({\n config: this.pluginSession.config,\n artifact: this.currentArtifact,\n sourceMap: true,\n });\n setSharedSwcTransformer(this.stateKey, this.swcTransformer);\n this.log(\"SWC transformer initialized\");\n } catch (error) {\n console.warn(\n `[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc is installed.`,\n );\n this.swcTransformer = null;\n setSharedSwcTransformer(this.stateKey, null);\n }\n }\n\n /**\n * Cleanup resources.\n */\n private cleanup(): void {\n this.pluginSession = null;\n this.currentArtifact = null;\n this.previousArtifact = null;\n this.swcTransformer = null;\n setSharedPluginSession(this.stateKey, null);\n setSharedArtifact(this.stateKey, null);\n setSharedSwcTransformer(this.stateKey, null);\n }\n\n /**\n * Log a message if debug mode is enabled.\n */\n private log(message: string): void {\n if (this.options.debug) {\n console.log(`[${SodaGqlWebpackPlugin.pluginName}] ${message}`);\n }\n }\n\n /**\n * Get the current artifact (for use by loader).\n */\n getArtifact(): BuilderArtifact | null {\n return this.currentArtifact;\n }\n}\n"],"mappings":";;;;;;;;;AAqBA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAgB,aAAa;CAE7B,AAAiB;CACjB,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,kBAA0C;CAClD,AAAQ,mBAA2C;CACnD,AAAQ,iBAAiD;CAEzD,YAAY,UAAgC,EAAE,EAAE;AAC9C,OAAK,UAAU;AACf,OAAK,WAAWA,cAAY,QAAQ,WAAW;;CAGjD,MAAM,UAA0B;AAE9B,WAAS,MAAM,UAAU,SAAS,qBAAqB,YAAY,OAAO,WAAW,aAAa;AAChG,OAAI;AACF,UAAM,KAAK,YAAY;AACvB,cAAU;YACH,OAAO;AACd,aAAS,MAAe;;IAE1B;AAGF,WAAS,MAAM,SAAS,SAAS,qBAAqB,YAAY,OAAO,WAAW,aAAa;AAC/F,OAAI;AACF,UAAM,KAAK,gBAAgB;AAC3B,cAAU;YACH,OAAO;AACd,aAAS,MAAe;;IAE1B;AAGF,WAAS,MAAM,QAAQ,IAAI,qBAAqB,aAAa,UAAU,gBAAgB;AACrF,OAAI,SACF,MAAK,uBAAuB,SAAS;IAEvC;AAGF,WAAS,MAAM,WAAW,IAAI,qBAAqB,kBAAkB;AACnE,QAAK,SAAS;IACd;;;;;CAMJ,MAAc,aAA4B;AACxC,MAAI,KAAK,cAAe;EAGxB,MAAM,kBAAkBC,yBAAuB,KAAK,SAAS;AAC7D,MAAI,iBAAiB;AACnB,QAAK,gBAAgB;AAGrB,QAAK,kBAAkB,MAAM,KAAK,cAAc,kBAAkB;AAGlE,qBAAkB,KAAK,UAAU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O,OAAO,KAAK,gBAAgB,SAAS,CAChE,KAAI,cAAc,QAAQ,SAAS,WAAW,KAAK,WACjD,QAAO;AAGX,SAAO;;;;;;CAOT,MAAc,2BAA0C;AACtD,MAAI,KAAK,QAAQ,gBAAgB,MAC/B;AAGF,MAAI,CAAC,KAAK,mBAAmB,CAAC,KAAK,eAAe;AAChD,QAAK,iBAAiB;AACtB,2BAAwB,KAAK,UAAU,KAAK;AAC5C;;AAGF,MAAI;GACF,MAAM,EAAE,sBAAsB,MAAM,OAAO;AAC3C,QAAK,iBAAiB,MAAM,kBAAkB;IAC5C,QAAQ,KAAK,cAAc;IAC3B,UAAU,KAAK;IACf,WAAW;IACZ,CAAC;AACF,2BAAwB,KAAK,UAAU,KAAK,eAAe;AAC3D,QAAK,IAAI,8BAA8B;WAChC,OAAO;AACd,WAAQ,KACN,oEAAoE,MAAM,yCAC3E;AACD,QAAK,iBAAiB;AACtB,2BAAwB,KAAK,UAAU,KAAK;;;;;;CAOhD,AAAQ,UAAgB;AACtB,OAAK,gBAAgB;AACrB,OAAK,kBAAkB;AACvB,OAAK,mBAAmB;AACxB,OAAK,iBAAiB;AACtB,2BAAuB,KAAK,UAAU,KAAK;AAC3C,oBAAkB,KAAK,UAAU,KAAK;AACtC,0BAAwB,KAAK,UAAU,KAAK;;;;;CAM9C,AAAQ,IAAI,SAAuB;AACjC,MAAI,KAAK,QAAQ,MACf,SAAQ,IAAI,IAAI,qBAAqB,WAAW,IAAI,UAAU;;;;;CAOlE,cAAsC;AACpC,SAAO,KAAK"}
package/dist/loader.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  Object.defineProperty(exports, '__esModule', { value: true });
2
- let __soda_gql_plugin_common = require("@soda-gql/plugin-common");
2
+ let __soda_gql_builder_plugin_support = require("@soda-gql/builder/plugin-support");
3
3
  let __soda_gql_common = require("@soda-gql/common");
4
- let __soda_gql_babel_transformer = require("@soda-gql/babel-transformer");
4
+ let __soda_gql_babel = require("@soda-gql/babel");
5
5
 
6
6
  //#region packages/webpack-plugin/src/loader.ts
7
7
  /**
@@ -9,9 +9,9 @@ let __soda_gql_babel_transformer = require("@soda-gql/babel-transformer");
9
9
  * First tries to use shared session from plugin, falls back to creating own.
10
10
  */
11
11
  const ensurePluginSession = (options) => {
12
- const sharedSession = (0, __soda_gql_plugin_common.getSharedPluginSession)((0, __soda_gql_plugin_common.getStateKey)(options.configPath));
12
+ const sharedSession = (0, __soda_gql_builder_plugin_support.getSharedPluginSession)((0, __soda_gql_builder_plugin_support.getStateKey)(options.configPath));
13
13
  if (sharedSession) return sharedSession;
14
- return (0, __soda_gql_plugin_common.createPluginSession)({
14
+ return (0, __soda_gql_builder_plugin_support.createPluginSession)({
15
15
  configPath: options.configPath,
16
16
  enabled: options.enabled
17
17
  }, "@soda-gql/webpack-plugin/loader");
@@ -23,7 +23,7 @@ const sodaGqlLoader = function(source, inputSourceMap) {
23
23
  const callback = this.async();
24
24
  const options = this.getOptions();
25
25
  const filename = this.resourcePath;
26
- const stateKey = (0, __soda_gql_plugin_common.getStateKey)(options.configPath);
26
+ const stateKey = (0, __soda_gql_builder_plugin_support.getStateKey)(options.configPath);
27
27
  (async () => {
28
28
  try {
29
29
  const session = ensurePluginSession(options);
@@ -31,7 +31,7 @@ const sodaGqlLoader = function(source, inputSourceMap) {
31
31
  callback(null, source, inputSourceMap);
32
32
  return;
33
33
  }
34
- let artifact = (0, __soda_gql_plugin_common.getSharedArtifact)(stateKey);
34
+ let artifact = (0, __soda_gql_builder_plugin_support.getSharedArtifact)(stateKey);
35
35
  if (!artifact) artifact = await session.getArtifactAsync();
36
36
  if (!artifact) {
37
37
  callback(null, source, inputSourceMap);
@@ -42,7 +42,7 @@ const sodaGqlLoader = function(source, inputSourceMap) {
42
42
  callback(null, source, inputSourceMap);
43
43
  return;
44
44
  }
45
- const sharedState = (0, __soda_gql_plugin_common.getSharedState)(stateKey);
45
+ const sharedState = (0, __soda_gql_builder_plugin_support.getSharedState)(stateKey);
46
46
  const normalizedFilename = (0, __soda_gql_common.normalizePath)(filename);
47
47
  if (sharedState.moduleAdjacency.size > 0) {
48
48
  const importers = sharedState.moduleAdjacency.get(normalizedFilename);
@@ -53,7 +53,7 @@ const sodaGqlLoader = function(source, inputSourceMap) {
53
53
  if (elementPath && elementPath !== filename) this.addDependency(elementPath);
54
54
  }
55
55
  if (options.transformer === "swc") {
56
- const swcTransformer = (0, __soda_gql_plugin_common.getSharedSwcTransformer)(stateKey);
56
+ const swcTransformer = (0, __soda_gql_builder_plugin_support.getSharedSwcTransformer)(stateKey);
57
57
  if (swcTransformer) {
58
58
  const result$1 = swcTransformer.transform({
59
59
  sourceCode: source,
@@ -70,7 +70,7 @@ const sodaGqlLoader = function(source, inputSourceMap) {
70
70
  }
71
71
  console.warn("[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. Ensure the plugin has transformer: 'swc' option set.");
72
72
  }
73
- const result = (0, __soda_gql_babel_transformer.createBabelTransformer)({
73
+ const result = (0, __soda_gql_babel.createBabelTransformer)({
74
74
  artifact,
75
75
  config: session.config,
76
76
  sourceMap: true
@@ -1 +1 @@
1
- {"version":3,"file":"loader.cjs","names":["sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions>","result"],"sources":["../src/loader.ts"],"sourcesContent":["import { createBabelTransformer } from \"@soda-gql/babel-transformer\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport {\n createPluginSession,\n getSharedArtifact,\n getSharedPluginSession,\n getSharedState,\n getSharedSwcTransformer,\n getStateKey,\n type PluginSession,\n} from \"@soda-gql/plugin-common\";\nimport type { LoaderDefinitionFunction } from \"webpack\";\nimport type { WebpackLoaderOptions } from \"./types\";\n\n/**\n * Ensure plugin session is initialized.\n * First tries to use shared session from plugin, falls back to creating own.\n */\nconst ensurePluginSession = (options: WebpackLoaderOptions): PluginSession | null => {\n const stateKey = getStateKey(options.configPath);\n\n // Try to use shared session from plugin first\n const sharedSession = getSharedPluginSession(stateKey);\n if (sharedSession) {\n return sharedSession;\n }\n\n // Fall back to creating own session (for standalone loader usage)\n return createPluginSession(\n {\n configPath: options.configPath,\n enabled: options.enabled,\n },\n \"@soda-gql/webpack-plugin/loader\",\n );\n};\n\n/**\n * Webpack loader that transforms soda-gql code using the babel-plugin.\n */\nconst sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions> = function (source, inputSourceMap) {\n const callback = this.async();\n const options = this.getOptions();\n const filename = this.resourcePath;\n const stateKey = getStateKey(options.configPath);\n\n (async () => {\n try {\n const session = ensurePluginSession(options);\n if (!session) {\n // Plugin disabled or config load failed, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Try to use shared artifact from plugin first (more efficient in watch mode)\n let artifact = getSharedArtifact(stateKey);\n\n // Fall back to fetching artifact if not shared\n if (!artifact) {\n artifact = await session.getArtifactAsync();\n }\n\n if (!artifact) {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Check if this file contains any soda-gql elements\n const normalizedPath = normalizePath(filename);\n const hasElements = Object.values(artifact.elements).some(\n (element) => normalizePath(element.metadata.sourcePath) === normalizedPath,\n );\n\n if (!hasElements) {\n // Not a soda-gql file, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Add dependencies based on module adjacency for precise HMR\n const sharedState = getSharedState(stateKey);\n const normalizedFilename = normalizePath(filename);\n\n // Use module adjacency for efficient dependency tracking\n // moduleAdjacency maps: importedFile -> Set<importingFiles>\n if (sharedState.moduleAdjacency.size > 0) {\n // Add files that import this file (reverse dependencies)\n const importers = sharedState.moduleAdjacency.get(normalizedFilename);\n if (importers) {\n for (const importer of importers) {\n this.addDependency(importer);\n }\n }\n\n // Add files that this file imports (forward dependencies)\n for (const [importedFile, importingFiles] of sharedState.moduleAdjacency) {\n if (importingFiles.has(normalizedFilename)) {\n this.addDependency(importedFile);\n }\n }\n } else {\n // Fallback: Add all soda-gql source files as dependencies (conservative approach)\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n this.addDependency(elementPath);\n }\n }\n }\n\n // Use SWC transformer if configured and available\n if (options.transformer === \"swc\") {\n const swcTransformer = getSharedSwcTransformer(stateKey);\n if (swcTransformer) {\n const result = swcTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n return;\n }\n // Not transformed (no soda-gql code in file), pass through\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n // SWC transformer not available, fall through to Babel\n console.warn(\n \"[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. \" +\n \"Ensure the plugin has transformer: 'swc' option set.\",\n );\n }\n\n // Transform using babel-transformer directly (default)\n const babelTransformer = createBabelTransformer({\n artifact,\n config: session.config,\n sourceMap: true,\n });\n\n const result = babelTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n } else {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n }\n } catch (error) {\n callback(error as Error);\n }\n })();\n};\n\nexport default sodaGqlLoader;\n\n// Mark as non-raw (we handle string source code)\nexport const raw = false;\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,uBAAuB,YAAwD;CAInF,MAAM,+GAHuB,QAAQ,WAAW,CAGM;AACtD,KAAI,cACF,QAAO;AAIT,0DACE;EACE,YAAY,QAAQ;EACpB,SAAS,QAAQ;EAClB,EACD,kCACD;;;;;AAMH,MAAMA,gBAAgE,SAAU,QAAQ,gBAAgB;CACtG,MAAM,WAAW,KAAK,OAAO;CAC7B,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SAAO,UAAU,GAAG;AACpE,eAAS,MAAMA,SAAO,YAAY,UAAU;AAC5C;;AAGF,cAAS,MAAM,QAAQ,eAAiD;AACxE;;AAGF,YAAQ,KACN,wIAED;;GAUH,MAAM,kEAN0C;IAC9C;IACA,QAAQ,QAAQ;IAChB,WAAW;IACZ,CAAC,CAE8B,UAAU;IACxC,YAAY;IACZ,YAAY;IACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;IACnE,CAAC;AAEF,OAAI,OAAO,aAAa;IACtB,MAAM,YAAY,OAAO,YAAY,KAAK,MAAM,OAAO,UAAU,GAAG;AACpE,aAAS,MAAM,OAAO,YAAY,UAAU;SAE5C,UAAS,MAAM,QAAQ,eAAiD;WAEnE,OAAO;AACd,YAAS,MAAe;;KAExB;;AAGN,qBAAe;AAGf,MAAa,MAAM"}
1
+ {"version":3,"file":"loader.cjs","names":["sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions>","result"],"sources":["../src/loader.ts"],"sourcesContent":["import { createBabelTransformer } from \"@soda-gql/babel\";\nimport {\n createPluginSession,\n getSharedArtifact,\n getSharedPluginSession,\n getSharedState,\n getSharedSwcTransformer,\n getStateKey,\n type PluginSession,\n} from \"@soda-gql/builder/plugin-support\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport type { LoaderDefinitionFunction } from \"webpack\";\nimport type { WebpackLoaderOptions } from \"./types\";\n\n/**\n * Ensure plugin session is initialized.\n * First tries to use shared session from plugin, falls back to creating own.\n */\nconst ensurePluginSession = (options: WebpackLoaderOptions): PluginSession | null => {\n const stateKey = getStateKey(options.configPath);\n\n // Try to use shared session from plugin first\n const sharedSession = getSharedPluginSession(stateKey);\n if (sharedSession) {\n return sharedSession;\n }\n\n // Fall back to creating own session (for standalone loader usage)\n return createPluginSession(\n {\n configPath: options.configPath,\n enabled: options.enabled,\n },\n \"@soda-gql/webpack-plugin/loader\",\n );\n};\n\n/**\n * Webpack loader that transforms soda-gql code using the babel-plugin.\n */\nconst sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions> = function (source, inputSourceMap) {\n const callback = this.async();\n const options = this.getOptions();\n const filename = this.resourcePath;\n const stateKey = getStateKey(options.configPath);\n\n (async () => {\n try {\n const session = ensurePluginSession(options);\n if (!session) {\n // Plugin disabled or config load failed, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Try to use shared artifact from plugin first (more efficient in watch mode)\n let artifact = getSharedArtifact(stateKey);\n\n // Fall back to fetching artifact if not shared\n if (!artifact) {\n artifact = await session.getArtifactAsync();\n }\n\n if (!artifact) {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Check if this file contains any soda-gql elements\n const normalizedPath = normalizePath(filename);\n const hasElements = Object.values(artifact.elements).some(\n (element) => normalizePath(element.metadata.sourcePath) === normalizedPath,\n );\n\n if (!hasElements) {\n // Not a soda-gql file, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Add dependencies based on module adjacency for precise HMR\n const sharedState = getSharedState(stateKey);\n const normalizedFilename = normalizePath(filename);\n\n // Use module adjacency for efficient dependency tracking\n // moduleAdjacency maps: importedFile -> Set<importingFiles>\n if (sharedState.moduleAdjacency.size > 0) {\n // Add files that import this file (reverse dependencies)\n const importers = sharedState.moduleAdjacency.get(normalizedFilename);\n if (importers) {\n for (const importer of importers) {\n this.addDependency(importer);\n }\n }\n\n // Add files that this file imports (forward dependencies)\n for (const [importedFile, importingFiles] of sharedState.moduleAdjacency) {\n if (importingFiles.has(normalizedFilename)) {\n this.addDependency(importedFile);\n }\n }\n } else {\n // Fallback: Add all soda-gql source files as dependencies (conservative approach)\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n this.addDependency(elementPath);\n }\n }\n }\n\n // Use SWC transformer if configured and available\n if (options.transformer === \"swc\") {\n const swcTransformer = getSharedSwcTransformer(stateKey);\n if (swcTransformer) {\n const result = swcTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n return;\n }\n // Not transformed (no soda-gql code in file), pass through\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n // SWC transformer not available, fall through to Babel\n console.warn(\n \"[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. \" +\n \"Ensure the plugin has transformer: 'swc' option set.\",\n );\n }\n\n // Transform using babel-transformer directly (default)\n const babelTransformer = createBabelTransformer({\n artifact,\n config: session.config,\n sourceMap: true,\n });\n\n const result = babelTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n } else {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n }\n } catch (error) {\n callback(error as Error);\n }\n })();\n};\n\nexport default sodaGqlLoader;\n\n// Mark as non-raw (we handle string source code)\nexport const raw = false;\n"],"mappings":";;;;;;;;;;AAkBA,MAAM,uBAAuB,YAAwD;CAInF,MAAM,iIAHuB,QAAQ,WAAW,CAGM;AACtD,KAAI,cACF,QAAO;AAIT,mEACE;EACE,YAAY,QAAQ;EACpB,SAAS,QAAQ;EAClB,EACD,kCACD;;;;;AAMH,MAAMA,gBAAgE,SAAU,QAAQ,gBAAgB;CACtG,MAAM,WAAW,KAAK,OAAO;CAC7B,MAAM,UAAU,KAAK,YAAY;CACjC,MAAM,WAAW,KAAK;CACtB,MAAM,8DAAuB,QAAQ,WAAW;AAEhD,EAAC,YAAY;AACX,MAAI;GACF,MAAM,UAAU,oBAAoB,QAAQ;AAC5C,OAAI,CAA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QAAQ,QAAQ;IAChB,WAAW;IACZ,CAAC,CAE8B,UAAU;IACxC,YAAY;IACZ,YAAY;IACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;IACnE,CAAC;AAEF,OAAI,OAAO,aAAa;IACtB,MAAM,YAAY,OAAO,YAAY,KAAK,MAAM,OAAO,UAAU,GAAG;AACpE,aAAS,MAAM,OAAO,YAAY,UAAU;SAE5C,UAAS,MAAM,QAAQ,eAAiD;WAEnE,OAAO;AACd,YAAS,MAAe;;KAExB;;AAGN,qBAAe;AAGf,MAAa,MAAM"}
package/dist/loader.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as WebpackLoaderOptions } from "./types-BJUU2U2w.cjs";
1
+ import { n as WebpackLoaderOptions } from "./types-D39igyVT.cjs";
2
2
  import { LoaderDefinitionFunction } from "webpack";
3
3
 
4
4
  //#region packages/webpack-plugin/src/loader.d.ts
package/dist/loader.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { n as WebpackLoaderOptions } from "./types-DxhQ4VI-.mjs";
1
+ import { n as WebpackLoaderOptions } from "./types-B9bA0Wbk.mjs";
2
2
  import { LoaderDefinitionFunction } from "webpack";
3
3
 
4
4
  //#region packages/webpack-plugin/src/loader.d.ts
package/dist/loader.mjs CHANGED
@@ -1,6 +1,6 @@
1
- import { createPluginSession, getSharedArtifact, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getStateKey } from "@soda-gql/plugin-common";
1
+ import { createPluginSession, getSharedArtifact, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getStateKey } from "@soda-gql/builder/plugin-support";
2
2
  import { normalizePath } from "@soda-gql/common";
3
- import { createBabelTransformer } from "@soda-gql/babel-transformer";
3
+ import { createBabelTransformer } from "@soda-gql/babel";
4
4
 
5
5
  //#region packages/webpack-plugin/src/loader.ts
6
6
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"loader.mjs","names":["sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions>","result"],"sources":["../src/loader.ts"],"sourcesContent":["import { createBabelTransformer } from \"@soda-gql/babel-transformer\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport {\n createPluginSession,\n getSharedArtifact,\n getSharedPluginSession,\n getSharedState,\n getSharedSwcTransformer,\n getStateKey,\n type PluginSession,\n} from \"@soda-gql/plugin-common\";\nimport type { LoaderDefinitionFunction } from \"webpack\";\nimport type { WebpackLoaderOptions } from \"./types\";\n\n/**\n * Ensure plugin session is initialized.\n * First tries to use shared session from plugin, falls back to creating own.\n */\nconst ensurePluginSession = (options: WebpackLoaderOptions): PluginSession | null => {\n const stateKey = getStateKey(options.configPath);\n\n // Try to use shared session from plugin first\n const sharedSession = getSharedPluginSession(stateKey);\n if (sharedSession) {\n return sharedSession;\n }\n\n // Fall back to creating own session (for standalone loader usage)\n return createPluginSession(\n {\n configPath: options.configPath,\n enabled: options.enabled,\n },\n \"@soda-gql/webpack-plugin/loader\",\n );\n};\n\n/**\n * Webpack loader that transforms soda-gql code using the babel-plugin.\n */\nconst sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions> = function (source, inputSourceMap) {\n const callback = this.async();\n const options = this.getOptions();\n const filename = this.resourcePath;\n const stateKey = getStateKey(options.configPath);\n\n (async () => {\n try {\n const session = ensurePluginSession(options);\n if (!session) {\n // Plugin disabled or config load failed, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Try to use shared artifact from plugin first (more efficient in watch mode)\n let artifact = getSharedArtifact(stateKey);\n\n // Fall back to fetching artifact if not shared\n if (!artifact) {\n artifact = await session.getArtifactAsync();\n }\n\n if (!artifact) {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Check if this file contains any soda-gql elements\n const normalizedPath = normalizePath(filename);\n const hasElements = Object.values(artifact.elements).some(\n (element) => normalizePath(element.metadata.sourcePath) === normalizedPath,\n );\n\n if (!hasElements) {\n // Not a soda-gql file, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Add dependencies based on module adjacency for precise HMR\n const sharedState = getSharedState(stateKey);\n const normalizedFilename = normalizePath(filename);\n\n // Use module adjacency for efficient dependency tracking\n // moduleAdjacency maps: importedFile -> Set<importingFiles>\n if (sharedState.moduleAdjacency.size > 0) {\n // Add files that import this file (reverse dependencies)\n const importers = sharedState.moduleAdjacency.get(normalizedFilename);\n if (importers) {\n for (const importer of importers) {\n this.addDependency(importer);\n }\n }\n\n // Add files that this file imports (forward dependencies)\n for (const [importedFile, importingFiles] of sharedState.moduleAdjacency) {\n if (importingFiles.has(normalizedFilename)) {\n this.addDependency(importedFile);\n }\n }\n } else {\n // Fallback: Add all soda-gql source files as dependencies (conservative approach)\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n this.addDependency(elementPath);\n }\n }\n }\n\n // Use SWC transformer if configured and available\n if (options.transformer === \"swc\") {\n const swcTransformer = getSharedSwcTransformer(stateKey);\n if (swcTransformer) {\n const result = swcTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n return;\n }\n // Not transformed (no soda-gql code in file), pass through\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n // SWC transformer not available, fall through to Babel\n console.warn(\n \"[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. \" +\n \"Ensure the plugin has transformer: 'swc' option set.\",\n );\n }\n\n // Transform using babel-transformer directly (default)\n const babelTransformer = createBabelTransformer({\n artifact,\n config: session.config,\n sourceMap: true,\n });\n\n const result = babelTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n } else {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n }\n } catch (error) {\n callback(error as Error);\n }\n })();\n};\n\nexport default sodaGqlLoader;\n\n// Mark as non-raw (we handle string source code)\nexport const raw = false;\n"],"mappings":";;;;;;;;;AAkBA,MAAM,uBAAuB,YAAwD;CAInF,MAAM,gBAAgB,uBAHL,YAAY,QAAQ,WAAW,CAGM;AACtD,KAAI,cACF,QAAO;AAIT,QAAO,oBACL;EACE,YAAY,QAAQ;EACpB,SAAS,QAAQ;EAClB,EACD,kCACD;;;;;AAMH,MAAMA,gBAAgE,SAAU,QAAQ,gBAAgB;CACtG,MAAM,WAAW,KAAK,OAAO;CAC7B,MAAM,UAAU,KAAK,YAAY;CACjC,MAAM,WAAW,KAAK;CACtB,MAAM,WAAW,YAAY,QAAQ,WAAW;AAEhD,EAAC,YAAY;AACX,MAAI;GACF,MAAM,UAAU,oBAAoB,QAAQ;AAC5C,OAAI,CAAC,SAAS;AAEZ,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,IAAI,WAAW,kBAAkB,SAAS;AAG1C,OAAI,CAAC,SACH,YAAW,MAAM,QAAQ,kBAAkB;AAG7C,OAAI,CAAC,UAAU;AACb,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,MAAM,iBAAiB,cAAc,SAAS;AAK9C,OAAI,CAJgB,OAAO,OAAO,SAAS,SAAS,CAAC,MAClD,YAAY,cAAc,QAAQ,SAAS,WAAW,KAAK,eAC7D,EAEiB;AAEhB,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,MAAM,cAAc,eAAe,SAAS;GAC5C,MAAM,qBAAqB,cAAc,SAAS;AAIlD,OAAI,YAAY,gBAAgB,OAAO,GAAG;IAExC,MAAM,YAAY,YAAY,gBAAgB,IAAI,mBAAmB;AACrE,QAAI,UACF,MAAK,MAAM,YAAY,UACrB,MAAK,cAAc,SAAS;AAKhC,SAAK,MAAM,CAAC,cAAc,mBAAmB,YAAY,gBACvD,KAAI,eAAe,IAAI,mBAAmB,CACxC,MAAK,cAAc,aAAa;SAKpC,MAAK,MAAM,WAAW,OAAO,OAAO,SAAS,SAAS,EAAE;IACtD,MAAM,cAAc,QAAQ,SAAS;AACrC,QAAI,eAAe,gBAAgB,SACjC,MAAK,cAAc,YAAY;;AAMrC,OAAI,QAAQ,gBAAgB,OAAO;IACjC,MAAM,iBAAiB,wBAAwB,SAAS;AACxD,QAAI,gBAAgB;KAClB,MAAMC,WAAS,eAAe,UAAU;MACtC,YAAY;MACZ,YAAY;MACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;MACnE,CAAC;AAEF,SAAIA,SAAO,aAAa;MACtB,MAAM,YAAYA,SAAO,YAAY,KAAK,MAAMA,SAAO,UAAU,GAAG;AACpE,eAAS,MAAMA,SAAO,YAAY,UAAU;AAC5C;;AAGF,cAAS,MAAM,QAAQ,eAAiD;AACxE;;AAGF,YAAQ,KACN,wIAED;;GAUH,MAAM,SANmB,uBAAuB;IAC9C;IACA,QAAQ,QAAQ;IAChB,WAAW;IACZ,CAAC,CAE8B,UAAU;IACxC,YAAY;IACZ,YAAY;IACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;IACnE,CAAC;AAEF,OAAI,OAAO,aAAa;IACtB,MAAM,YAAY,OAAO,YAAY,KAAK,MAAM,OAAO,UAAU,GAAG;AACpE,aAAS,MAAM,OAAO,YAAY,UAAU;SAE5C,UAAS,MAAM,QAAQ,eAAiD;WAEnE,OAAO;AACd,YAAS,MAAe;;KAExB;;AAGN,qBAAe;AAGf,MAAa,MAAM"}
1
+ {"version":3,"file":"loader.mjs","names":["sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions>","result"],"sources":["../src/loader.ts"],"sourcesContent":["import { createBabelTransformer } from \"@soda-gql/babel\";\nimport {\n createPluginSession,\n getSharedArtifact,\n getSharedPluginSession,\n getSharedState,\n getSharedSwcTransformer,\n getStateKey,\n type PluginSession,\n} from \"@soda-gql/builder/plugin-support\";\nimport { normalizePath } from \"@soda-gql/common\";\nimport type { LoaderDefinitionFunction } from \"webpack\";\nimport type { WebpackLoaderOptions } from \"./types\";\n\n/**\n * Ensure plugin session is initialized.\n * First tries to use shared session from plugin, falls back to creating own.\n */\nconst ensurePluginSession = (options: WebpackLoaderOptions): PluginSession | null => {\n const stateKey = getStateKey(options.configPath);\n\n // Try to use shared session from plugin first\n const sharedSession = getSharedPluginSession(stateKey);\n if (sharedSession) {\n return sharedSession;\n }\n\n // Fall back to creating own session (for standalone loader usage)\n return createPluginSession(\n {\n configPath: options.configPath,\n enabled: options.enabled,\n },\n \"@soda-gql/webpack-plugin/loader\",\n );\n};\n\n/**\n * Webpack loader that transforms soda-gql code using the babel-plugin.\n */\nconst sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions> = function (source, inputSourceMap) {\n const callback = this.async();\n const options = this.getOptions();\n const filename = this.resourcePath;\n const stateKey = getStateKey(options.configPath);\n\n (async () => {\n try {\n const session = ensurePluginSession(options);\n if (!session) {\n // Plugin disabled or config load failed, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Try to use shared artifact from plugin first (more efficient in watch mode)\n let artifact = getSharedArtifact(stateKey);\n\n // Fall back to fetching artifact if not shared\n if (!artifact) {\n artifact = await session.getArtifactAsync();\n }\n\n if (!artifact) {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Check if this file contains any soda-gql elements\n const normalizedPath = normalizePath(filename);\n const hasElements = Object.values(artifact.elements).some(\n (element) => normalizePath(element.metadata.sourcePath) === normalizedPath,\n );\n\n if (!hasElements) {\n // Not a soda-gql file, pass through unchanged\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n\n // Add dependencies based on module adjacency for precise HMR\n const sharedState = getSharedState(stateKey);\n const normalizedFilename = normalizePath(filename);\n\n // Use module adjacency for efficient dependency tracking\n // moduleAdjacency maps: importedFile -> Set<importingFiles>\n if (sharedState.moduleAdjacency.size > 0) {\n // Add files that import this file (reverse dependencies)\n const importers = sharedState.moduleAdjacency.get(normalizedFilename);\n if (importers) {\n for (const importer of importers) {\n this.addDependency(importer);\n }\n }\n\n // Add files that this file imports (forward dependencies)\n for (const [importedFile, importingFiles] of sharedState.moduleAdjacency) {\n if (importingFiles.has(normalizedFilename)) {\n this.addDependency(importedFile);\n }\n }\n } else {\n // Fallback: Add all soda-gql source files as dependencies (conservative approach)\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n this.addDependency(elementPath);\n }\n }\n }\n\n // Use SWC transformer if configured and available\n if (options.transformer === \"swc\") {\n const swcTransformer = getSharedSwcTransformer(stateKey);\n if (swcTransformer) {\n const result = swcTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n return;\n }\n // Not transformed (no soda-gql code in file), pass through\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n return;\n }\n // SWC transformer not available, fall through to Babel\n console.warn(\n \"[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. \" +\n \"Ensure the plugin has transformer: 'swc' option set.\",\n );\n }\n\n // Transform using babel-transformer directly (default)\n const babelTransformer = createBabelTransformer({\n artifact,\n config: session.config,\n sourceMap: true,\n });\n\n const result = babelTransformer.transform({\n sourceCode: source,\n sourcePath: filename,\n inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : undefined,\n });\n\n if (result.transformed) {\n const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : undefined;\n callback(null, result.sourceCode, sourceMap);\n } else {\n callback(null, source, inputSourceMap as Parameters<typeof callback>[2]);\n }\n } catch (error) {\n callback(error as Error);\n }\n })();\n};\n\nexport default sodaGqlLoader;\n\n// Mark as non-raw (we handle string source code)\nexport const raw = false;\n"],"mappings":";;;;;;;;;AAkBA,MAAM,uBAAuB,YAAwD;CAInF,MAAM,gBAAgB,uBAHL,YAAY,QAAQ,WAAW,CAGM;AACtD,KAAI,cACF,QAAO;AAIT,QAAO,oBACL;EACE,YAAY,QAAQ;EACpB,SAAS,QAAQ;EAClB,EACD,kCACD;;;;;AAMH,MAAMA,gBAAgE,SAAU,QAAQ,gBAAgB;CACtG,MAAM,WAAW,KAAK,OAAO;CAC7B,MAAM,UAAU,KAAK,YAAY;CACjC,MAAM,WAAW,KAAK;CACtB,MAAM,WAAW,YAAY,QAAQ,WAAW;AAEhD,EAAC,YAAY;AACX,MAAI;GACF,MAAM,UAAU,oBAAoB,QAAQ;AAC5C,OAAI,CAAC,SAAS;AAEZ,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,IAAI,WAAW,kBAAkB,SAAS;AAG1C,OAAI,CAAC,SACH,YAAW,MAAM,QAAQ,kBAAkB;AAG7C,OAAI,CAAC,UAAU;AACb,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,MAAM,iBAAiB,cAAc,SAAS;AAK9C,OAAI,CAJgB,OAAO,OAAO,SAAS,SAAS,CAAC,MAClD,YAAY,cAAc,QAAQ,SAAS,WAAW,KAAK,eAC7D,EAEiB;AAEhB,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,MAAM,cAAc,eAAe,SAAS;GAC5C,MAAM,qBAAqB,cAAc,SAAS;AAIlD,OAAI,YAAY,gBAAgB,OAAO,GAAG;IAExC,MAAM,YAAY,YAAY,gBAAgB,IAAI,mBAAmB;AACrE,QAAI,UACF,MAAK,MAAM,YAAY,UACrB,MAAK,cAAc,SAAS;AAKhC,SAAK,MAAM,CAAC,cAAc,mBAAmB,YAAY,gBACvD,KAAI,eAAe,IAAI,mBAAmB,CACxC,MAAK,cAAc,aAAa;SAKpC,MAAK,MAAM,WAAW,OAAO,OAAO,SAAS,SAAS,EAAE;IACtD,MAAM,cAAc,QAAQ,SAAS;AACrC,QAAI,eAAe,gBAAgB,SACjC,MAAK,cAAc,YAAY;;AAMrC,OAAI,QAAQ,gBAAgB,OAAO;IACjC,MAAM,iBAAiB,wBAAwB,SAAS;AACxD,QAAI,gBAAgB;KAClB,MAAMC,WAAS,eAAe,UAAU;MACtC,YAAY;MACZ,YAAY;MACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;MACnE,CAAC;AAEF,SAAIA,SAAO,aAAa;MACtB,MAAM,YAAYA,SAAO,YAAY,KAAK,MAAMA,SAAO,UAAU,GAAG;AACpE,eAAS,MAAMA,SAAO,YAAY,UAAU;AAC5C;;AAGF,cAAS,MAAM,QAAQ,eAAiD;AACxE;;AAGF,YAAQ,KACN,wIAED;;GAUH,MAAM,SANmB,uBAAuB;IAC9C;IACA,QAAQ,QAAQ;IAChB,WAAW;IACZ,CAAC,CAE8B,UAAU;IACxC,YAAY;IACZ,YAAY;IACZ,gBAAgB,iBAAiB,KAAK,UAAU,eAAe,GAAG;IACnE,CAAC;AAEF,OAAI,OAAO,aAAa;IACtB,MAAM,YAAY,OAAO,YAAY,KAAK,MAAM,OAAO,UAAU,GAAG;AACpE,aAAS,MAAM,OAAO,YAAY,UAAU;SAE5C,UAAS,MAAM,QAAQ,eAAiD;WAEnE,OAAO;AACd,YAAS,MAAe;;KAExB;;AAGN,qBAAe;AAGf,MAAa,MAAM"}
@@ -1,11 +1,11 @@
1
- import { PluginOptions } from "@soda-gql/plugin-common";
1
+ import { PluginOptions } from "@soda-gql/builder/plugin-support";
2
2
 
3
3
  //#region packages/webpack-plugin/src/types.d.ts
4
4
 
5
5
  /**
6
6
  * Transformer type for code transformation.
7
7
  * - 'babel': Use Babel plugin (default, wider compatibility)
8
- * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
8
+ * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)
9
9
  */
10
10
  type TransformerType = "babel" | "swc";
11
11
  /**
@@ -51,4 +51,4 @@ type WebpackLoaderOptions = {
51
51
  };
52
52
  //#endregion
53
53
  export { WebpackLoaderOptions as n, WebpackPluginOptions as r, TransformerType as t };
54
- //# sourceMappingURL=types-BJUU2U2w.d.cts.map
54
+ //# sourceMappingURL=types-B9bA0Wbk.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types-BJUU2U2w.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAKA;;AAKqB,KAVT,eAAA,GAUS,OAAA,GAAA,KAAA;;;;AAgBI,KArBb,oBAAA,GAAuB,aAqBV,GAAA;EAAe;AAMxC;;;qBAtBqB,SAAS;;;;qBAKT,SAAS;;;;;;;;;yBAWL;;;;;KAMb,oBAAA;;;;;;;;;;;;;yBAea"}
1
+ {"version":3,"file":"types-B9bA0Wbk.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAKA;;AAKqB,KAVT,eAAA,GAUS,OAAA,GAAA,KAAA;;;;AAgBI,KArBb,oBAAA,GAAuB,aAqBV,GAAA;EAAe;AAMxC;;;qBAtBqB,SAAS;;;;qBAKT,SAAS;;;;;;;;;yBAWL;;;;;KAMb,oBAAA;;;;;;;;;;;;;yBAea"}
@@ -1,11 +1,11 @@
1
- import { PluginOptions } from "@soda-gql/plugin-common";
1
+ import { PluginOptions } from "@soda-gql/builder/plugin-support";
2
2
 
3
3
  //#region packages/webpack-plugin/src/types.d.ts
4
4
 
5
5
  /**
6
6
  * Transformer type for code transformation.
7
7
  * - 'babel': Use Babel plugin (default, wider compatibility)
8
- * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
8
+ * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)
9
9
  */
10
10
  type TransformerType = "babel" | "swc";
11
11
  /**
@@ -51,4 +51,4 @@ type WebpackLoaderOptions = {
51
51
  };
52
52
  //#endregion
53
53
  export { WebpackLoaderOptions as n, WebpackPluginOptions as r, TransformerType as t };
54
- //# sourceMappingURL=types-DxhQ4VI-.d.mts.map
54
+ //# sourceMappingURL=types-D39igyVT.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types-DxhQ4VI-.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAKA;;AAKqB,KAVT,eAAA,GAUS,OAAA,GAAA,KAAA;;;;AAgBI,KArBb,oBAAA,GAAuB,aAqBV,GAAA;EAAe;AAMxC;;;qBAtBqB,SAAS;;;;qBAKT,SAAS;;;;;;;;;yBAWL;;;;;KAMb,oBAAA;;;;;;;;;;;;;yBAea"}
1
+ {"version":3,"file":"types-D39igyVT.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;AAKA;;AAKqB,KAVT,eAAA,GAUS,OAAA,GAAA,KAAA;;;;AAgBI,KArBb,oBAAA,GAAuB,aAqBV,GAAA;EAAe;AAMxC;;;qBAtBqB,SAAS;;;;qBAKT,SAAS;;;;;;;;;yBAWL;;;;;KAMb,oBAAA;;;;;;;;;;;;;yBAea"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@soda-gql/webpack-plugin",
3
- "version": "0.10.1",
3
+ "version": "0.11.0",
4
4
  "description": "Webpack plugin for soda-gql with HMR support",
5
5
  "type": "module",
6
6
  "private": false,
@@ -55,19 +55,18 @@
55
55
  "./package.json": "./package.json"
56
56
  },
57
57
  "dependencies": {
58
- "@soda-gql/builder": "~0.10.0",
59
- "@soda-gql/common": "~0.10.0",
60
- "@soda-gql/config": "~0.10.0",
61
- "@soda-gql/core": "~0.10.0",
62
- "@soda-gql/plugin-common": "~0.10.0",
63
- "@soda-gql/babel-transformer": "~0.10.0"
58
+ "@soda-gql/builder": "0.11.0",
59
+ "@soda-gql/common": "0.11.0",
60
+ "@soda-gql/config": "0.11.0",
61
+ "@soda-gql/core": "0.11.0",
62
+ "@soda-gql/babel": "0.11.0"
64
63
  },
65
64
  "devDependencies": {
66
- "@soda-gql/swc-transformer": "~0.10.0"
65
+ "@soda-gql/swc": "0.11.0"
67
66
  },
68
67
  "peerDependencies": {
69
68
  "webpack": "^5.0.0",
70
- "@soda-gql/swc-transformer": "~0.10.0"
69
+ "@soda-gql/swc": "0.11.0"
71
70
  },
72
71
  "optionalDependencies": {}
73
72
  }