@soda-gql/webpack-plugin 0.1.0 → 0.3.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/README.md +2 -4
- package/dist/index.cjs +33 -1
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +8 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +32 -1
- package/dist/index.mjs.map +1 -1
- package/dist/loader.cjs +33 -15
- package/dist/loader.cjs.map +1 -0
- package/dist/loader.d.cts +1 -1
- package/dist/loader.d.cts.map +1 -1
- package/dist/loader.d.mts +1 -1
- package/dist/loader.d.mts.map +1 -1
- package/dist/loader.mjs +32 -15
- package/dist/loader.mjs.map +1 -1
- package/dist/{types-Dh6GvYnd.d.cts → types-BJUU2U2w.d.cts} +18 -2
- package/dist/types-BJUU2U2w.d.cts.map +1 -0
- package/dist/{types-o73wYce8.d.mts → types-DxhQ4VI-.d.mts} +18 -2
- package/dist/types-DxhQ4VI-.d.mts.map +1 -0
- package/package.json +42 -18
- package/dist/types-Dh6GvYnd.d.cts.map +0 -1
- package/dist/types-o73wYce8.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -115,13 +115,11 @@ module.exports = {
|
|
|
115
115
|
The plugin tracks dependencies between soda-gql files:
|
|
116
116
|
|
|
117
117
|
- **Models**: Base definitions (no dependencies)
|
|
118
|
-
- **
|
|
119
|
-
- **Operations**: Reference slices via `slice.embed()`
|
|
118
|
+
- **Operations**: Reference models via `model.embed()`
|
|
120
119
|
|
|
121
120
|
When a model file changes:
|
|
122
121
|
1. The model is rebuilt
|
|
123
|
-
2. All
|
|
124
|
-
3. All operations that use those slices are rebuilt
|
|
122
|
+
2. All operations that use the model are rebuilt
|
|
125
123
|
|
|
126
124
|
This ensures that changes propagate correctly through the dependency chain.
|
|
127
125
|
|
package/dist/index.cjs
CHANGED
|
@@ -15,6 +15,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
15
15
|
currentArtifact = null;
|
|
16
16
|
previousArtifact = null;
|
|
17
17
|
pendingInvalidations = /* @__PURE__ */ new Set();
|
|
18
|
+
swcTransformer = null;
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
this.options = options;
|
|
20
21
|
this.stateKey = (0, __soda_gql_plugin_common.getStateKey)(options.configPath);
|
|
@@ -56,6 +57,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
56
57
|
(0, __soda_gql_plugin_common.setSharedPluginSession)(this.stateKey, this.pluginSession);
|
|
57
58
|
this.currentArtifact = await this.pluginSession.getArtifactAsync();
|
|
58
59
|
(0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, this.currentArtifact);
|
|
60
|
+
await this.initializeSwcTransformer();
|
|
59
61
|
this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
@@ -67,6 +69,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
67
69
|
this.previousArtifact = this.currentArtifact;
|
|
68
70
|
this.currentArtifact = await this.pluginSession.getArtifactAsync();
|
|
69
71
|
(0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, this.currentArtifact);
|
|
72
|
+
await this.initializeSwcTransformer();
|
|
70
73
|
if (!this.currentArtifact) {
|
|
71
74
|
this.log("Failed to build artifact");
|
|
72
75
|
return;
|
|
@@ -148,6 +151,32 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
148
151
|
return invalidations;
|
|
149
152
|
}
|
|
150
153
|
/**
|
|
154
|
+
* Initialize SWC transformer if configured.
|
|
155
|
+
* Creates a new transformer instance with the current artifact.
|
|
156
|
+
*/
|
|
157
|
+
async initializeSwcTransformer() {
|
|
158
|
+
if (this.options.transformer !== "swc") return;
|
|
159
|
+
if (!this.currentArtifact || !this.pluginSession) {
|
|
160
|
+
this.swcTransformer = null;
|
|
161
|
+
(0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const { createTransformer } = await import("@soda-gql/swc-transformer");
|
|
166
|
+
this.swcTransformer = await createTransformer({
|
|
167
|
+
config: this.pluginSession.config,
|
|
168
|
+
artifact: this.currentArtifact,
|
|
169
|
+
sourceMap: true
|
|
170
|
+
});
|
|
171
|
+
(0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, this.swcTransformer);
|
|
172
|
+
this.log("SWC transformer initialized");
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc-transformer is installed.`);
|
|
175
|
+
this.swcTransformer = null;
|
|
176
|
+
(0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
151
180
|
* Cleanup resources.
|
|
152
181
|
*/
|
|
153
182
|
cleanup() {
|
|
@@ -155,8 +184,10 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
155
184
|
this.currentArtifact = null;
|
|
156
185
|
this.previousArtifact = null;
|
|
157
186
|
this.pendingInvalidations.clear();
|
|
187
|
+
this.swcTransformer = null;
|
|
158
188
|
(0, __soda_gql_plugin_common.setSharedPluginSession)(this.stateKey, null);
|
|
159
189
|
(0, __soda_gql_plugin_common.setSharedArtifact)(this.stateKey, null);
|
|
190
|
+
(0, __soda_gql_plugin_common.setSharedSwcTransformer)(this.stateKey, null);
|
|
160
191
|
}
|
|
161
192
|
/**
|
|
162
193
|
* Log a message if debug mode is enabled.
|
|
@@ -191,4 +222,5 @@ Object.defineProperty(exports, 'getStateKey', {
|
|
|
191
222
|
get: function () {
|
|
192
223
|
return __soda_gql_plugin_common.getStateKey;
|
|
193
224
|
}
|
|
194
|
-
});
|
|
225
|
+
});
|
|
226
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +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 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 pendingInvalidations: Set<string> = new Set();\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 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\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 // If we have a previous artifact, compute what changed\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 // Store affected files for webpack to pick up\n for (const filePath of affectedFiles) {\n this.pendingInvalidations.add(filePath);\n }\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 * Get pending invalidations and clear the set.\n */\n getPendingInvalidations(): Set<string> {\n const invalidations = new Set(this.pendingInvalidations);\n this.pendingInvalidations.clear();\n return invalidations;\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.pendingInvalidations.clear();\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":";;;;;;;;;AAoBA,IAAa,uBAAb,MAAa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,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,qBAAqB,OAAO;AACjC,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"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as WebpackPluginOptions, t as
|
|
1
|
+
import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-BJUU2U2w.cjs";
|
|
2
2
|
import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/plugin-common";
|
|
3
3
|
import { BuilderArtifact } from "@soda-gql/builder";
|
|
4
4
|
import { Compiler } from "webpack";
|
|
@@ -17,6 +17,7 @@ declare class SodaGqlWebpackPlugin {
|
|
|
17
17
|
private currentArtifact;
|
|
18
18
|
private previousArtifact;
|
|
19
19
|
private pendingInvalidations;
|
|
20
|
+
private swcTransformer;
|
|
20
21
|
constructor(options?: WebpackPluginOptions);
|
|
21
22
|
apply(compiler: Compiler): void;
|
|
22
23
|
/**
|
|
@@ -51,6 +52,11 @@ declare class SodaGqlWebpackPlugin {
|
|
|
51
52
|
* Get pending invalidations and clear the set.
|
|
52
53
|
*/
|
|
53
54
|
getPendingInvalidations(): Set<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Initialize SWC transformer if configured.
|
|
57
|
+
* Creates a new transformer instance with the current artifact.
|
|
58
|
+
*/
|
|
59
|
+
private initializeSwcTransformer;
|
|
54
60
|
/**
|
|
55
61
|
* Cleanup resources.
|
|
56
62
|
*/
|
|
@@ -65,5 +71,5 @@ declare class SodaGqlWebpackPlugin {
|
|
|
65
71
|
getArtifact(): BuilderArtifact | null;
|
|
66
72
|
}
|
|
67
73
|
//#endregion
|
|
68
|
-
export { SodaGqlWebpackPlugin, type WebpackLoaderOptions, type WebpackPluginOptions, getSharedArtifact, getSharedState, getStateKey };
|
|
74
|
+
export { SodaGqlWebpackPlugin, type TransformerType, type WebpackLoaderOptions, type WebpackPluginOptions, getSharedArtifact, getSharedState, getStateKey };
|
|
69
75
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAoBA;AAWuB,cAXV,oBAAA,CAWU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EAyMW,iBAAA,OAAA;EAkEZ,iBAAA,QAAA;EAAe,QAAA,aAAA;;;;;wBAhRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyMW;;;;;;;;;;;;;;;;;iBAkEZ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as WebpackPluginOptions, t as
|
|
1
|
+
import { n as WebpackLoaderOptions, r as WebpackPluginOptions, t as TransformerType } from "./types-DxhQ4VI-.mjs";
|
|
2
2
|
import { getSharedArtifact, getSharedState, getStateKey } from "@soda-gql/plugin-common";
|
|
3
3
|
import { BuilderArtifact } from "@soda-gql/builder";
|
|
4
4
|
import { Compiler } from "webpack";
|
|
@@ -17,6 +17,7 @@ declare class SodaGqlWebpackPlugin {
|
|
|
17
17
|
private currentArtifact;
|
|
18
18
|
private previousArtifact;
|
|
19
19
|
private pendingInvalidations;
|
|
20
|
+
private swcTransformer;
|
|
20
21
|
constructor(options?: WebpackPluginOptions);
|
|
21
22
|
apply(compiler: Compiler): void;
|
|
22
23
|
/**
|
|
@@ -51,6 +52,11 @@ declare class SodaGqlWebpackPlugin {
|
|
|
51
52
|
* Get pending invalidations and clear the set.
|
|
52
53
|
*/
|
|
53
54
|
getPendingInvalidations(): Set<string>;
|
|
55
|
+
/**
|
|
56
|
+
* Initialize SWC transformer if configured.
|
|
57
|
+
* Creates a new transformer instance with the current artifact.
|
|
58
|
+
*/
|
|
59
|
+
private initializeSwcTransformer;
|
|
54
60
|
/**
|
|
55
61
|
* Cleanup resources.
|
|
56
62
|
*/
|
|
@@ -65,5 +71,5 @@ declare class SodaGqlWebpackPlugin {
|
|
|
65
71
|
getArtifact(): BuilderArtifact | null;
|
|
66
72
|
}
|
|
67
73
|
//#endregion
|
|
68
|
-
export { SodaGqlWebpackPlugin, type WebpackLoaderOptions, type WebpackPluginOptions, getSharedArtifact, getSharedState, getStateKey };
|
|
74
|
+
export { SodaGqlWebpackPlugin, type TransformerType, type WebpackLoaderOptions, type WebpackPluginOptions, getSharedArtifact, getSharedState, getStateKey };
|
|
69
75
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/plugin.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;AAoBA;AAWuB,cAXV,oBAAA,CAWU;EAKL,gBAAA,UAAA,GAAA,sBAAA;EAyMW,iBAAA,OAAA;EAkEZ,iBAAA,QAAA;EAAe,QAAA,aAAA;;;;;wBAhRT;kBAKL;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAyMW;;;;;;;;;;;;;;;;;iBAkEZ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createPluginSession, getSharedArtifact, getSharedState, getSharedState as getSharedState$1, getStateKey, getStateKey as getStateKey$1, setSharedArtifact, setSharedPluginSession } from "@soda-gql/plugin-common";
|
|
1
|
+
import { createPluginSession, getSharedArtifact, getSharedState, getSharedState as getSharedState$1, getStateKey, getStateKey as getStateKey$1, setSharedArtifact, setSharedPluginSession, setSharedSwcTransformer } from "@soda-gql/plugin-common";
|
|
2
2
|
import { collectAffectedFiles } from "@soda-gql/builder";
|
|
3
3
|
import { normalizePath } from "@soda-gql/common";
|
|
4
4
|
|
|
@@ -15,6 +15,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
15
15
|
currentArtifact = null;
|
|
16
16
|
previousArtifact = null;
|
|
17
17
|
pendingInvalidations = /* @__PURE__ */ new Set();
|
|
18
|
+
swcTransformer = null;
|
|
18
19
|
constructor(options = {}) {
|
|
19
20
|
this.options = options;
|
|
20
21
|
this.stateKey = getStateKey$1(options.configPath);
|
|
@@ -56,6 +57,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
56
57
|
setSharedPluginSession(this.stateKey, this.pluginSession);
|
|
57
58
|
this.currentArtifact = await this.pluginSession.getArtifactAsync();
|
|
58
59
|
setSharedArtifact(this.stateKey, this.currentArtifact);
|
|
60
|
+
await this.initializeSwcTransformer();
|
|
59
61
|
this.log(`Initial build complete: ${Object.keys(this.currentArtifact?.elements ?? {}).length} elements`);
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
@@ -67,6 +69,7 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
67
69
|
this.previousArtifact = this.currentArtifact;
|
|
68
70
|
this.currentArtifact = await this.pluginSession.getArtifactAsync();
|
|
69
71
|
setSharedArtifact(this.stateKey, this.currentArtifact);
|
|
72
|
+
await this.initializeSwcTransformer();
|
|
70
73
|
if (!this.currentArtifact) {
|
|
71
74
|
this.log("Failed to build artifact");
|
|
72
75
|
return;
|
|
@@ -148,6 +151,32 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
148
151
|
return invalidations;
|
|
149
152
|
}
|
|
150
153
|
/**
|
|
154
|
+
* Initialize SWC transformer if configured.
|
|
155
|
+
* Creates a new transformer instance with the current artifact.
|
|
156
|
+
*/
|
|
157
|
+
async initializeSwcTransformer() {
|
|
158
|
+
if (this.options.transformer !== "swc") return;
|
|
159
|
+
if (!this.currentArtifact || !this.pluginSession) {
|
|
160
|
+
this.swcTransformer = null;
|
|
161
|
+
setSharedSwcTransformer(this.stateKey, null);
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
try {
|
|
165
|
+
const { createTransformer } = await import("@soda-gql/swc-transformer");
|
|
166
|
+
this.swcTransformer = await createTransformer({
|
|
167
|
+
config: this.pluginSession.config,
|
|
168
|
+
artifact: this.currentArtifact,
|
|
169
|
+
sourceMap: true
|
|
170
|
+
});
|
|
171
|
+
setSharedSwcTransformer(this.stateKey, this.swcTransformer);
|
|
172
|
+
this.log("SWC transformer initialized");
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.warn(`[@soda-gql/webpack-plugin] Failed to initialize SWC transformer: ${error}. Make sure @soda-gql/swc-transformer is installed.`);
|
|
175
|
+
this.swcTransformer = null;
|
|
176
|
+
setSharedSwcTransformer(this.stateKey, null);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
151
180
|
* Cleanup resources.
|
|
152
181
|
*/
|
|
153
182
|
cleanup() {
|
|
@@ -155,8 +184,10 @@ var SodaGqlWebpackPlugin = class SodaGqlWebpackPlugin {
|
|
|
155
184
|
this.currentArtifact = null;
|
|
156
185
|
this.previousArtifact = null;
|
|
157
186
|
this.pendingInvalidations.clear();
|
|
187
|
+
this.swcTransformer = null;
|
|
158
188
|
setSharedPluginSession(this.stateKey, null);
|
|
159
189
|
setSharedArtifact(this.stateKey, null);
|
|
190
|
+
setSharedSwcTransformer(this.stateKey, null);
|
|
160
191
|
}
|
|
161
192
|
/**
|
|
162
193
|
* Log a message if debug mode is enabled.
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["getStateKey","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 getSharedState,\n getStateKey,\n type PluginSession,\n setSharedArtifact,\n setSharedPluginSession,\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 pendingInvalidations: Set<string> = new Set();\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 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\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 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 if (!this.currentArtifact) {\n this.log(\"Failed to build artifact\");\n return;\n }\n\n // If we have a previous artifact, compute what changed\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 // Store affected files for webpack to pick up\n for (const filePath of affectedFiles) {\n this.pendingInvalidations.add(filePath);\n }\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 * Get pending invalidations and clear the set.\n */\n getPendingInvalidations(): Set<string> {\n const invalidations = new Set(this.pendingInvalidations);\n this.pendingInvalidations.clear();\n return invalidations;\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.pendingInvalidations.clear();\n setSharedPluginSession(this.stateKey, null);\n setSharedArtifact(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":";;;;;;;;;AAkBA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAgB,aAAa;CAE7B,AAAiB;CACjB,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,kBAA0C;CAClD,AAAQ,mBAA2C;CACnD,AAAQ,uCAAoC,IAAI,KAAK;CAErD,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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B,QAAO;EAElC,MAAM,aAAa,cAAc,SAAS;AAC1C,OAAK,MAAM,WAAW,OAAO,OAAO,KAAK,gBAAgB,SAAS,CAChE,KAAI,cAAc,QAAQ,SAAS,WAAW,KAAK,WACjD,QAAO;AAGX,SAAO;;;;;CAMT,0BAAuC;EACrC,MAAM,gBAAgB,IAAI,IAAI,KAAK,qBAAqB;AACxD,OAAK,qBAAqB,OAAO;AACjC,SAAO;;;;;CAMT,AAAQ,UAAgB;AACtB,OAAK,gBAAgB;AACrB,OAAK,kBAAkB;AACvB,OAAK,mBAAmB;AACxB,OAAK,qBAAqB,OAAO;AACjC,yBAAuB,KAAK,UAAU,KAAK;AAC3C,oBAAkB,KAAK,UAAU,KAAK;;;;;CAMxC,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","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 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 pendingInvalidations: Set<string> = new Set();\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 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\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 // If we have a previous artifact, compute what changed\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 // Store affected files for webpack to pick up\n for (const filePath of affectedFiles) {\n this.pendingInvalidations.add(filePath);\n }\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 * Get pending invalidations and clear the set.\n */\n getPendingInvalidations(): Set<string> {\n const invalidations = new Set(this.pendingInvalidations);\n this.pendingInvalidations.clear();\n return invalidations;\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.pendingInvalidations.clear();\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":";;;;;;;;;AAoBA,IAAa,uBAAb,MAAa,qBAAqB;CAChC,OAAgB,aAAa;CAE7B,AAAiB;CACjB,AAAiB;CACjB,AAAQ,gBAAsC;CAC9C,AAAQ,kBAA0C;CAClD,AAAQ,mBAA2C;CACnD,AAAQ,uCAAoC,IAAI,KAAK;CACrD,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,WAA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ugin-common");
|
|
3
3
|
let __soda_gql_common = require("@soda-gql/common");
|
|
4
|
-
let
|
|
5
|
-
let __soda_gql_babel_plugin = require("@soda-gql/babel-plugin");
|
|
4
|
+
let __soda_gql_babel_transformer = require("@soda-gql/babel-transformer");
|
|
6
5
|
|
|
7
6
|
//#region packages/webpack-plugin/src/loader.ts
|
|
8
7
|
/**
|
|
@@ -47,19 +46,37 @@ const sodaGqlLoader = function(source, inputSourceMap) {
|
|
|
47
46
|
const elementPath = element.metadata.sourcePath;
|
|
48
47
|
if (elementPath && elementPath !== filename) this.addDependency(elementPath);
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
49
|
+
if (options.transformer === "swc") {
|
|
50
|
+
const swcTransformer = (0, __soda_gql_plugin_common.getSharedSwcTransformer)(stateKey);
|
|
51
|
+
if (swcTransformer) {
|
|
52
|
+
const result$1 = swcTransformer.transform({
|
|
53
|
+
sourceCode: source,
|
|
54
|
+
sourcePath: filename,
|
|
55
|
+
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : void 0
|
|
56
|
+
});
|
|
57
|
+
if (result$1.transformed) {
|
|
58
|
+
const sourceMap = result$1.sourceMap ? JSON.parse(result$1.sourceMap) : void 0;
|
|
59
|
+
callback(null, result$1.sourceCode, sourceMap);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
callback(null, source, inputSourceMap);
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
console.warn("[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. Ensure the plugin has transformer: 'swc' option set.");
|
|
66
|
+
}
|
|
67
|
+
const result = (0, __soda_gql_babel_transformer.createBabelTransformer)({
|
|
68
|
+
artifact,
|
|
69
|
+
config: session.config,
|
|
70
|
+
sourceMap: true
|
|
71
|
+
}).transform({
|
|
72
|
+
sourceCode: source,
|
|
73
|
+
sourcePath: filename,
|
|
74
|
+
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : void 0
|
|
60
75
|
});
|
|
61
|
-
if (result
|
|
62
|
-
|
|
76
|
+
if (result.transformed) {
|
|
77
|
+
const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : void 0;
|
|
78
|
+
callback(null, result.sourceCode, sourceMap);
|
|
79
|
+
} else callback(null, source, inputSourceMap);
|
|
63
80
|
} catch (error) {
|
|
64
81
|
callback(error);
|
|
65
82
|
}
|
|
@@ -70,4 +87,5 @@ const raw = false;
|
|
|
70
87
|
|
|
71
88
|
//#endregion
|
|
72
89
|
exports.default = loader_default;
|
|
73
|
-
exports.raw = raw;
|
|
90
|
+
exports.raw = raw;
|
|
91
|
+
//# sourceMappingURL=loader.cjs.map
|
|
@@ -0,0 +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 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 to webpack for HMR\n // This ensures webpack rebuilds this file when its dependencies change\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n // Add all soda-gql source files as dependencies\n // This is a conservative approach that ensures rebuilds propagate\n this.addDependency(elementPath);\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":";;;;;;;;;;AAiBA,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,MAAM,UAAU,KAAK,YAAY;CACjC,MAAM,WAAW,KAAK;CACtB,MAAM,qDAAuB,QAAQ,WAAW;AAEhD,EAAC,YAAY;AACX,MAAI;GACF,MAAM,UAAU,oBAAoB,QAAQ;AAC5C,OAAI,CAAC,SAAS;AAEZ,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,IAAI,2DAA6B,SAAS;AAG1C,OAAI,CAAC,SACH,YAAW,MAAM,QAAQ,kBAAkB;AAG7C,OAAI,CAAC,UAAU;AACb,aAAS,MAAM,QAAQ,eAAiD;AACxE;;GAIF,MAAM,sDAA+B,SAAS;AAK9C,OAAI,CAJgB,OAAO,OAAO,SAAS,SAAS,CAAC,MAClD,iDAA0B,QAAQ,SAAS,WAAW,KAAK,eAC7D,EAEiB;AAEhB,aAAS,MAAM,QAAQ,eAAiD;AACxE;;AAKF,QAAK,MAAM,WAAW,OAAO,OAAO,SAAS,SAAS,EAAE;IACtD,MAAM,cAAc,QAAQ,SAAS;AACrC,QAAI,eAAe,gBAAgB,SAGjC,MAAK,cAAc,YAAY;;AAKnC,OAAI,QAAQ,gBAAgB,OAAO;IACjC,MAAM,uEAAyC,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,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"}
|
package/dist/loader.d.cts
CHANGED
package/dist/loader.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.cts","names":[],"sources":["../src/loader.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWoD;
|
|
1
|
+
{"version":3,"file":"loader.d.cts","names":[],"sources":["../src/loader.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWoD;AAqIpD,cAzGM,aAyGU,EAzGK,wBAyGL,CAzG8B,oBAyG9B,CAAA;cAAH,GAAA"}
|
package/dist/loader.d.mts
CHANGED
package/dist/loader.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.mts","names":[],"sources":["../src/loader.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWoD;
|
|
1
|
+
{"version":3,"file":"loader.d.mts","names":[],"sources":["../src/loader.ts"],"sourcesContent":[],"mappings":";;;;;;;AAWoD;AAqIpD,cAzGM,aAyGU,EAzGK,wBAyGL,CAzG8B,oBAyG9B,CAAA;cAAH,GAAA"}
|
package/dist/loader.mjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { createPluginSession, getSharedArtifact, getSharedPluginSession, getStateKey } from "@soda-gql/plugin-common";
|
|
1
|
+
import { createPluginSession, getSharedArtifact, getSharedPluginSession, getSharedSwcTransformer, getStateKey } from "@soda-gql/plugin-common";
|
|
2
2
|
import { normalizePath } from "@soda-gql/common";
|
|
3
|
-
import {
|
|
4
|
-
import { createPluginWithArtifact } from "@soda-gql/babel-plugin";
|
|
3
|
+
import { createBabelTransformer } from "@soda-gql/babel-transformer";
|
|
5
4
|
|
|
6
5
|
//#region packages/webpack-plugin/src/loader.ts
|
|
7
6
|
/**
|
|
@@ -46,19 +45,37 @@ const sodaGqlLoader = function(source, inputSourceMap) {
|
|
|
46
45
|
const elementPath = element.metadata.sourcePath;
|
|
47
46
|
if (elementPath && elementPath !== filename) this.addDependency(elementPath);
|
|
48
47
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
48
|
+
if (options.transformer === "swc") {
|
|
49
|
+
const swcTransformer = getSharedSwcTransformer(stateKey);
|
|
50
|
+
if (swcTransformer) {
|
|
51
|
+
const result$1 = swcTransformer.transform({
|
|
52
|
+
sourceCode: source,
|
|
53
|
+
sourcePath: filename,
|
|
54
|
+
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : void 0
|
|
55
|
+
});
|
|
56
|
+
if (result$1.transformed) {
|
|
57
|
+
const sourceMap = result$1.sourceMap ? JSON.parse(result$1.sourceMap) : void 0;
|
|
58
|
+
callback(null, result$1.sourceCode, sourceMap);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
callback(null, source, inputSourceMap);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
console.warn("[@soda-gql/webpack-plugin] SWC transformer not available, falling back to Babel. Ensure the plugin has transformer: 'swc' option set.");
|
|
65
|
+
}
|
|
66
|
+
const result = createBabelTransformer({
|
|
67
|
+
artifact,
|
|
68
|
+
config: session.config,
|
|
69
|
+
sourceMap: true
|
|
70
|
+
}).transform({
|
|
71
|
+
sourceCode: source,
|
|
72
|
+
sourcePath: filename,
|
|
73
|
+
inputSourceMap: inputSourceMap ? JSON.stringify(inputSourceMap) : void 0
|
|
59
74
|
});
|
|
60
|
-
if (result
|
|
61
|
-
|
|
75
|
+
if (result.transformed) {
|
|
76
|
+
const sourceMap = result.sourceMap ? JSON.parse(result.sourceMap) : void 0;
|
|
77
|
+
callback(null, result.sourceCode, sourceMap);
|
|
78
|
+
} else callback(null, source, inputSourceMap);
|
|
62
79
|
} catch (error) {
|
|
63
80
|
callback(error);
|
|
64
81
|
}
|
package/dist/loader.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.mjs","names":["sodaGqlLoader: LoaderDefinitionFunction<WebpackLoaderOptions>"],"sources":["../src/loader.ts"],"sourcesContent":["import {
|
|
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 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 to webpack for HMR\n // This ensures webpack rebuilds this file when its dependencies change\n for (const element of Object.values(artifact.elements)) {\n const elementPath = element.metadata.sourcePath;\n if (elementPath && elementPath !== filename) {\n // Add all soda-gql source files as dependencies\n // This is a conservative approach that ensures rebuilds propagate\n this.addDependency(elementPath);\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":";;;;;;;;;AAiBA,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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Y;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"}
|
|
@@ -2,6 +2,12 @@ import { PluginOptions } from "@soda-gql/plugin-common";
|
|
|
2
2
|
|
|
3
3
|
//#region packages/webpack-plugin/src/types.d.ts
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Transformer type for code transformation.
|
|
7
|
+
* - 'babel': Use Babel plugin (default, wider compatibility)
|
|
8
|
+
* - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
|
|
9
|
+
*/
|
|
10
|
+
type TransformerType = "babel" | "swc";
|
|
5
11
|
/**
|
|
6
12
|
* Options for the SodaGqlWebpackPlugin.
|
|
7
13
|
*/
|
|
@@ -19,6 +25,11 @@ type WebpackPluginOptions = PluginOptions & {
|
|
|
19
25
|
* Enable verbose logging for debugging.
|
|
20
26
|
*/
|
|
21
27
|
readonly debug?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Transformer to use for code transformation.
|
|
30
|
+
* @default 'babel'
|
|
31
|
+
*/
|
|
32
|
+
readonly transformer?: TransformerType;
|
|
22
33
|
};
|
|
23
34
|
/**
|
|
24
35
|
* Options for the webpack loader.
|
|
@@ -32,7 +43,12 @@ type WebpackLoaderOptions = {
|
|
|
32
43
|
* Enable/disable the loader.
|
|
33
44
|
*/
|
|
34
45
|
readonly enabled?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Transformer to use for code transformation.
|
|
48
|
+
* @default 'babel'
|
|
49
|
+
*/
|
|
50
|
+
readonly transformer?: TransformerType;
|
|
35
51
|
};
|
|
36
52
|
//#endregion
|
|
37
|
-
export {
|
|
38
|
-
//# sourceMappingURL=types-
|
|
53
|
+
export { WebpackLoaderOptions as n, WebpackPluginOptions as r, TransformerType as t };
|
|
54
|
+
//# sourceMappingURL=types-BJUU2U2w.d.cts.map
|
|
@@ -0,0 +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"}
|
|
@@ -2,6 +2,12 @@ import { PluginOptions } from "@soda-gql/plugin-common";
|
|
|
2
2
|
|
|
3
3
|
//#region packages/webpack-plugin/src/types.d.ts
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Transformer type for code transformation.
|
|
7
|
+
* - 'babel': Use Babel plugin (default, wider compatibility)
|
|
8
|
+
* - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
|
|
9
|
+
*/
|
|
10
|
+
type TransformerType = "babel" | "swc";
|
|
5
11
|
/**
|
|
6
12
|
* Options for the SodaGqlWebpackPlugin.
|
|
7
13
|
*/
|
|
@@ -19,6 +25,11 @@ type WebpackPluginOptions = PluginOptions & {
|
|
|
19
25
|
* Enable verbose logging for debugging.
|
|
20
26
|
*/
|
|
21
27
|
readonly debug?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Transformer to use for code transformation.
|
|
30
|
+
* @default 'babel'
|
|
31
|
+
*/
|
|
32
|
+
readonly transformer?: TransformerType;
|
|
22
33
|
};
|
|
23
34
|
/**
|
|
24
35
|
* Options for the webpack loader.
|
|
@@ -32,7 +43,12 @@ type WebpackLoaderOptions = {
|
|
|
32
43
|
* Enable/disable the loader.
|
|
33
44
|
*/
|
|
34
45
|
readonly enabled?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Transformer to use for code transformation.
|
|
48
|
+
* @default 'babel'
|
|
49
|
+
*/
|
|
50
|
+
readonly transformer?: TransformerType;
|
|
35
51
|
};
|
|
36
52
|
//#endregion
|
|
37
|
-
export {
|
|
38
|
-
//# sourceMappingURL=types-
|
|
53
|
+
export { WebpackLoaderOptions as n, WebpackPluginOptions as r, TransformerType as t };
|
|
54
|
+
//# sourceMappingURL=types-DxhQ4VI-.d.mts.map
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/webpack-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Webpack plugin for soda-gql with HMR support",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"private": false,
|
|
6
7
|
"license": "MIT",
|
|
@@ -12,37 +13,60 @@
|
|
|
12
13
|
"email": "shota.hatada@whatasoda.me",
|
|
13
14
|
"url": "https://github.com/whatasoda"
|
|
14
15
|
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"graphql",
|
|
18
|
+
"codegen",
|
|
19
|
+
"zero-runtime",
|
|
20
|
+
"typescript",
|
|
21
|
+
"webpack",
|
|
22
|
+
"webpack-plugin",
|
|
23
|
+
"hmr"
|
|
24
|
+
],
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/whatasoda/soda-gql.git",
|
|
28
|
+
"directory": "packages/webpack-plugin"
|
|
29
|
+
},
|
|
30
|
+
"homepage": "https://github.com/whatasoda/soda-gql#readme",
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/whatasoda/soda-gql/issues"
|
|
33
|
+
},
|
|
34
|
+
"engines": {
|
|
35
|
+
"node": ">=18"
|
|
36
|
+
},
|
|
15
37
|
"main": "./dist/index.mjs",
|
|
16
38
|
"module": "./dist/index.mjs",
|
|
17
39
|
"types": "./dist/index.d.mts",
|
|
18
40
|
"exports": {
|
|
19
|
-
".": {
|
|
20
|
-
"@soda-gql": "./src/index.ts",
|
|
21
|
-
"types": "./dist/index.d.mts",
|
|
22
|
-
"import": "./dist/index.mjs",
|
|
23
|
-
"require": "./dist/index.cjs",
|
|
24
|
-
"default": "./dist/index.mjs"
|
|
25
|
-
},
|
|
26
41
|
"./loader": {
|
|
27
|
-
"@soda-gql": "
|
|
42
|
+
"@soda-gql": "./@x-loader.ts",
|
|
28
43
|
"types": "./dist/loader.d.mts",
|
|
29
44
|
"import": "./dist/loader.mjs",
|
|
30
45
|
"require": "./dist/loader.cjs",
|
|
31
46
|
"default": "./dist/loader.mjs"
|
|
32
47
|
},
|
|
48
|
+
".": {
|
|
49
|
+
"@soda-gql": "./@x-index.ts",
|
|
50
|
+
"types": "./dist/index.d.mts",
|
|
51
|
+
"import": "./dist/index.mjs",
|
|
52
|
+
"require": "./dist/index.cjs",
|
|
53
|
+
"default": "./dist/index.mjs"
|
|
54
|
+
},
|
|
33
55
|
"./package.json": "./package.json"
|
|
34
56
|
},
|
|
35
57
|
"dependencies": {
|
|
36
|
-
"@soda-gql/builder": "0.
|
|
37
|
-
"@soda-gql/common": "0.
|
|
38
|
-
"@soda-gql/config": "0.
|
|
39
|
-
"@soda-gql/core": "0.
|
|
40
|
-
"@soda-gql/plugin-common": "0.
|
|
41
|
-
"@soda-gql/babel-
|
|
42
|
-
|
|
58
|
+
"@soda-gql/builder": "0.3.0",
|
|
59
|
+
"@soda-gql/common": "0.3.0",
|
|
60
|
+
"@soda-gql/config": "0.3.0",
|
|
61
|
+
"@soda-gql/core": "0.3.0",
|
|
62
|
+
"@soda-gql/plugin-common": "0.3.0",
|
|
63
|
+
"@soda-gql/babel-transformer": "0.3.0"
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"@soda-gql/swc-transformer": "0.3.0"
|
|
43
67
|
},
|
|
44
|
-
"devDependencies": {},
|
|
45
68
|
"peerDependencies": {
|
|
46
|
-
"webpack": "^5.0.0"
|
|
69
|
+
"webpack": "^5.0.0",
|
|
70
|
+
"@soda-gql/swc-transformer": "0.3.0"
|
|
47
71
|
}
|
|
48
72
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-Dh6GvYnd.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAAmC,KAAvB,oBAAA,GAAuB,aAAA,GAAA;EAKd;;;;EAKe,SAAA,OAAA,CAAA,EALf,MAKe,GALN,MAKM,EAAA;EAWxB;;;qBAXS,SAAS;;;;;;;;;KAWlB,oBAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-o73wYce8.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAKA;AAAmC,KAAvB,oBAAA,GAAuB,aAAA,GAAA;EAKd;;;;EAKe,SAAA,OAAA,CAAA,EALf,MAKe,GALN,MAKM,EAAA;EAWxB;;;qBAXS,SAAS;;;;;;;;;KAWlB,oBAAA"}
|