@soda-gql/builder 0.10.2 → 0.11.1
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 +3 -3
- package/dist/index.cjs +137 -3849
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +34 -436
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +34 -436
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +122 -3806
- package/dist/index.mjs.map +1 -1
- package/dist/plugin-support.cjs +263 -0
- package/dist/plugin-support.cjs.map +1 -0
- package/dist/plugin-support.d.cts +308 -0
- package/dist/plugin-support.d.cts.map +1 -0
- package/dist/plugin-support.d.mts +308 -0
- package/dist/plugin-support.d.mts.map +1 -0
- package/dist/plugin-support.mjs +247 -0
- package/dist/plugin-support.mjs.map +1 -0
- package/dist/service-BIDYnmeU.d.cts +471 -0
- package/dist/service-BIDYnmeU.d.cts.map +1 -0
- package/dist/service-DdFZ_WpI.d.mts +471 -0
- package/dist/service-DdFZ_WpI.d.mts.map +1 -0
- package/dist/service-UG-_oJSl.mjs +4227 -0
- package/dist/service-UG-_oJSl.mjs.map +1 -0
- package/dist/service-nHDX5qIj.cjs +4384 -0
- package/dist/service-nHDX5qIj.cjs.map +1 -0
- package/package.json +12 -6
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
const require_service = require('./service-nHDX5qIj.cjs');
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
let __soda_gql_common = require("@soda-gql/common");
|
|
4
|
+
let __soda_gql_config = require("@soda-gql/config");
|
|
5
|
+
|
|
6
|
+
//#region packages/builder/src/plugin/errors.ts
|
|
7
|
+
/**
|
|
8
|
+
* Format a PluginError into a human-readable message.
|
|
9
|
+
*/
|
|
10
|
+
const formatPluginError = (error) => {
|
|
11
|
+
const codePrefix = `[${error.code}]`;
|
|
12
|
+
const stageInfo = "stage" in error ? ` (${error.stage})` : "";
|
|
13
|
+
return `${codePrefix}${stageInfo} ${error.message}`;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Type guard for PluginError.
|
|
17
|
+
*/
|
|
18
|
+
const isPluginError = (value) => {
|
|
19
|
+
return typeof value === "object" && value !== null && "type" in value && value.type === "PluginError" && "code" in value && "message" in value;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Assertion helper for unreachable code paths.
|
|
23
|
+
* This is the ONLY acceptable throw in plugin code.
|
|
24
|
+
*/
|
|
25
|
+
const assertUnreachable = (value, context) => {
|
|
26
|
+
throw new Error(`[INTERNAL] Unreachable code path${context ? ` in ${context}` : ""}: received ${JSON.stringify(value)}`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
//#endregion
|
|
30
|
+
//#region packages/builder/src/plugin/shared-state.ts
|
|
31
|
+
const sharedStates = new Map();
|
|
32
|
+
/**
|
|
33
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
34
|
+
*/
|
|
35
|
+
const getSharedState = (key) => {
|
|
36
|
+
let state = sharedStates.get(key);
|
|
37
|
+
if (!state) {
|
|
38
|
+
state = {
|
|
39
|
+
pluginSession: null,
|
|
40
|
+
currentArtifact: null,
|
|
41
|
+
moduleAdjacency: new Map(),
|
|
42
|
+
generation: 0,
|
|
43
|
+
swcTransformer: null,
|
|
44
|
+
transformerType: null,
|
|
45
|
+
builderService: null
|
|
46
|
+
};
|
|
47
|
+
sharedStates.set(key, state);
|
|
48
|
+
}
|
|
49
|
+
return state;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Update shared artifact.
|
|
53
|
+
*/
|
|
54
|
+
const setSharedArtifact = (key, artifact, moduleAdjacency) => {
|
|
55
|
+
const state = getSharedState(key);
|
|
56
|
+
state.currentArtifact = artifact;
|
|
57
|
+
if (moduleAdjacency) {
|
|
58
|
+
state.moduleAdjacency = moduleAdjacency;
|
|
59
|
+
}
|
|
60
|
+
state.generation++;
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Get shared artifact.
|
|
64
|
+
*/
|
|
65
|
+
const getSharedArtifact = (key) => {
|
|
66
|
+
return getSharedState(key).currentArtifact;
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Get shared plugin session.
|
|
70
|
+
*/
|
|
71
|
+
const getSharedPluginSession = (key) => {
|
|
72
|
+
return getSharedState(key).pluginSession;
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Set shared plugin session.
|
|
76
|
+
*/
|
|
77
|
+
const setSharedPluginSession = (key, session) => {
|
|
78
|
+
getSharedState(key).pluginSession = session;
|
|
79
|
+
};
|
|
80
|
+
/**
|
|
81
|
+
* Get the state key from config path or cwd.
|
|
82
|
+
*/
|
|
83
|
+
const getStateKey = (configPath) => {
|
|
84
|
+
return configPath ?? process.cwd();
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Set shared SWC transformer.
|
|
88
|
+
*/
|
|
89
|
+
const setSharedSwcTransformer = (key, transformer) => {
|
|
90
|
+
getSharedState(key).swcTransformer = transformer;
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Get shared SWC transformer.
|
|
94
|
+
*/
|
|
95
|
+
const getSharedSwcTransformer = (key) => {
|
|
96
|
+
return getSharedState(key).swcTransformer;
|
|
97
|
+
};
|
|
98
|
+
/**
|
|
99
|
+
* Set shared transformer type.
|
|
100
|
+
*/
|
|
101
|
+
const setSharedTransformerType = (key, transformerType) => {
|
|
102
|
+
getSharedState(key).transformerType = transformerType;
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Get shared transformer type.
|
|
106
|
+
*/
|
|
107
|
+
const getSharedTransformerType = (key) => {
|
|
108
|
+
return getSharedState(key).transformerType;
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* Get shared BuilderService.
|
|
112
|
+
*/
|
|
113
|
+
const getSharedBuilderService = (key) => {
|
|
114
|
+
return getSharedState(key).builderService;
|
|
115
|
+
};
|
|
116
|
+
/**
|
|
117
|
+
* Set shared BuilderService.
|
|
118
|
+
*/
|
|
119
|
+
const setSharedBuilderService = (key, service) => {
|
|
120
|
+
getSharedState(key).builderService = service;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
//#endregion
|
|
124
|
+
//#region packages/builder/src/plugin/session.ts
|
|
125
|
+
/**
|
|
126
|
+
* Plugin session management for all plugins.
|
|
127
|
+
* Unified from plugin-babel and plugin-swc implementations.
|
|
128
|
+
*/
|
|
129
|
+
/**
|
|
130
|
+
* Create plugin session by loading config and creating cached builder service.
|
|
131
|
+
* Returns null if disabled or config load fails.
|
|
132
|
+
*
|
|
133
|
+
* @param options - Plugin options
|
|
134
|
+
* @param pluginName - Name of the plugin for error messages
|
|
135
|
+
* @throws Error if failOnError is true and config load fails
|
|
136
|
+
*/
|
|
137
|
+
const createPluginSession = (options, pluginName) => {
|
|
138
|
+
const enabled = options.enabled ?? true;
|
|
139
|
+
const failOnError = options.failOnError ?? true;
|
|
140
|
+
if (!enabled) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const configResult = (0, __soda_gql_config.loadConfig)(options.configPath);
|
|
144
|
+
if (configResult.isErr()) {
|
|
145
|
+
const errorMsg = `[${pluginName}] Failed to load config: ${configResult.error.message}`;
|
|
146
|
+
console.error(errorMsg, {
|
|
147
|
+
code: configResult.error.code,
|
|
148
|
+
filePath: configResult.error.filePath,
|
|
149
|
+
cause: configResult.error.cause
|
|
150
|
+
});
|
|
151
|
+
if (failOnError) {
|
|
152
|
+
throw new Error(errorMsg);
|
|
153
|
+
}
|
|
154
|
+
return null;
|
|
155
|
+
}
|
|
156
|
+
const config = configResult.value;
|
|
157
|
+
if (config.artifact?.path) {
|
|
158
|
+
const artifactResult = require_service.loadArtifactSync(config.artifact.path);
|
|
159
|
+
if (artifactResult.isErr()) {
|
|
160
|
+
const errorMsg = `[${pluginName}] Failed to load pre-built artifact: ${artifactResult.error.message}`;
|
|
161
|
+
console.error(errorMsg, {
|
|
162
|
+
code: artifactResult.error.code,
|
|
163
|
+
filePath: artifactResult.error.filePath
|
|
164
|
+
});
|
|
165
|
+
if (failOnError) {
|
|
166
|
+
throw new Error(errorMsg);
|
|
167
|
+
}
|
|
168
|
+
return null;
|
|
169
|
+
}
|
|
170
|
+
const prebuiltArtifact = artifactResult.value;
|
|
171
|
+
console.log(`[${pluginName}] Using pre-built artifact: ${config.artifact.path}`);
|
|
172
|
+
return {
|
|
173
|
+
config,
|
|
174
|
+
getArtifact: () => prebuiltArtifact,
|
|
175
|
+
getArtifactAsync: async () => prebuiltArtifact,
|
|
176
|
+
isPrebuiltMode: true
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
const stateKey = getStateKey(options.configPath);
|
|
180
|
+
const ensureBuilderService = () => {
|
|
181
|
+
const existing = getSharedBuilderService(stateKey);
|
|
182
|
+
if (existing) {
|
|
183
|
+
return existing;
|
|
184
|
+
}
|
|
185
|
+
const service = require_service.createBuilderService({ config });
|
|
186
|
+
setSharedBuilderService(stateKey, service);
|
|
187
|
+
return service;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
190
|
+
* Build artifact on every invocation (like tsc-plugin).
|
|
191
|
+
* This ensures the artifact is always up-to-date with the latest source files.
|
|
192
|
+
*
|
|
193
|
+
* @throws Error if failOnError is true and build fails
|
|
194
|
+
*/
|
|
195
|
+
const getArtifact = () => {
|
|
196
|
+
const builderService = ensureBuilderService();
|
|
197
|
+
const buildResult = builderService.build();
|
|
198
|
+
if (buildResult.isErr()) {
|
|
199
|
+
const formattedError = require_service.formatBuilderErrorForCLI(buildResult.error);
|
|
200
|
+
console.error(`[${pluginName}] Build failed:\n${formattedError}`);
|
|
201
|
+
if (failOnError) {
|
|
202
|
+
throw new Error(`[${pluginName}] ${buildResult.error.message}`);
|
|
203
|
+
}
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
return buildResult.value;
|
|
207
|
+
};
|
|
208
|
+
/**
|
|
209
|
+
* Async version of getArtifact.
|
|
210
|
+
* Supports async metadata factories and parallel element evaluation.
|
|
211
|
+
*
|
|
212
|
+
* @throws Error if failOnError is true and build fails
|
|
213
|
+
*/
|
|
214
|
+
const getArtifactAsync = async () => {
|
|
215
|
+
const builderService = ensureBuilderService();
|
|
216
|
+
const buildResult = await builderService.buildAsync();
|
|
217
|
+
if (buildResult.isErr()) {
|
|
218
|
+
const formattedError = require_service.formatBuilderErrorForCLI(buildResult.error);
|
|
219
|
+
console.error(`[${pluginName}] Build failed:\n${formattedError}`);
|
|
220
|
+
if (failOnError) {
|
|
221
|
+
throw new Error(`[${pluginName}] ${buildResult.error.message}`);
|
|
222
|
+
}
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return buildResult.value;
|
|
226
|
+
};
|
|
227
|
+
return {
|
|
228
|
+
config,
|
|
229
|
+
getArtifact,
|
|
230
|
+
getArtifactAsync,
|
|
231
|
+
isPrebuiltMode: false
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
//#endregion
|
|
236
|
+
//#region packages/builder/src/plugin/utils/canonical-id.ts
|
|
237
|
+
/**
|
|
238
|
+
* Utility for working with canonical IDs.
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Resolve a canonical ID from a filename and AST path.
|
|
242
|
+
*/
|
|
243
|
+
const resolveCanonicalId = (filename, astPath) => (0, __soda_gql_common.createCanonicalId)((0, node_path.resolve)(filename), astPath);
|
|
244
|
+
|
|
245
|
+
//#endregion
|
|
246
|
+
exports.assertUnreachable = assertUnreachable;
|
|
247
|
+
exports.createPluginSession = createPluginSession;
|
|
248
|
+
exports.formatPluginError = formatPluginError;
|
|
249
|
+
exports.getSharedArtifact = getSharedArtifact;
|
|
250
|
+
exports.getSharedBuilderService = getSharedBuilderService;
|
|
251
|
+
exports.getSharedPluginSession = getSharedPluginSession;
|
|
252
|
+
exports.getSharedState = getSharedState;
|
|
253
|
+
exports.getSharedSwcTransformer = getSharedSwcTransformer;
|
|
254
|
+
exports.getSharedTransformerType = getSharedTransformerType;
|
|
255
|
+
exports.getStateKey = getStateKey;
|
|
256
|
+
exports.isPluginError = isPluginError;
|
|
257
|
+
exports.resolveCanonicalId = resolveCanonicalId;
|
|
258
|
+
exports.setSharedArtifact = setSharedArtifact;
|
|
259
|
+
exports.setSharedBuilderService = setSharedBuilderService;
|
|
260
|
+
exports.setSharedPluginSession = setSharedPluginSession;
|
|
261
|
+
exports.setSharedSwcTransformer = setSharedSwcTransformer;
|
|
262
|
+
exports.setSharedTransformerType = setSharedTransformerType;
|
|
263
|
+
//# sourceMappingURL=plugin-support.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-support.cjs","names":["loadArtifactSync","createBuilderService","formatBuilderErrorForCLI"],"sources":["../src/plugin/errors.ts","../src/plugin/shared-state.ts","../src/plugin/session.ts","../src/plugin/utils/canonical-id.ts"],"sourcesContent":["/**\n * Error types and formatters for plugin-babel.\n * Simplified from plugin-shared to include only types actually used by the Babel transformer.\n */\n\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { BuilderError } from \"../types\";\n\ntype OptionsInvalidBuilderConfig = { readonly code: \"INVALID_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsMissingBuilderConfig = { readonly code: \"MISSING_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsConfigLoadFailed = { readonly code: \"CONFIG_LOAD_FAILED\"; readonly message: string };\n\ntype BuilderEntryNotFound = Extract<BuilderError, { code: \"ENTRY_NOT_FOUND\" }>;\ntype BuilderDocDuplicate = Extract<BuilderError, { code: \"DOC_DUPLICATE\" }>;\ntype BuilderCircularDependency = Extract<BuilderError, { code: \"GRAPH_CIRCULAR_DEPENDENCY\" }>;\ntype BuilderModuleEvaluationFailed = Extract<BuilderError, { code: \"RUNTIME_MODULE_LOAD_FAILED\" }>;\ntype BuilderWriteFailed = Extract<BuilderError, { code: \"WRITE_FAILED\" }>;\n\ntype AnalysisMetadataMissingCause = { readonly filename: string };\ntype AnalysisArtifactMissingCause = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype AnalysisUnsupportedArtifactTypeCause = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype PluginErrorBase<Code extends string, Cause> = {\n readonly type: \"PluginError\";\n readonly code: Code;\n readonly message: string;\n readonly cause: Cause;\n};\n\nexport type PluginOptionsInvalidBuilderConfigError = PluginErrorBase<\n \"OPTIONS_INVALID_BUILDER_CONFIG\",\n OptionsInvalidBuilderConfig | OptionsMissingBuilderConfig | OptionsConfigLoadFailed\n> & { readonly stage: \"normalize-options\" };\n\nexport type PluginBuilderEntryNotFoundError = PluginErrorBase<\"SODA_GQL_BUILDER_ENTRY_NOT_FOUND\", BuilderEntryNotFound> & {\n readonly stage: \"builder\";\n readonly entry: string;\n};\n\nexport type PluginBuilderDocDuplicateError = PluginErrorBase<\"SODA_GQL_BUILDER_DOC_DUPLICATE\", BuilderDocDuplicate> & {\n readonly stage: \"builder\";\n readonly name: string;\n readonly sources: readonly string[];\n};\n\nexport type PluginBuilderCircularDependencyError = PluginErrorBase<\n \"SODA_GQL_BUILDER_CIRCULAR_DEPENDENCY\",\n BuilderCircularDependency\n> & { readonly stage: \"builder\"; readonly chain: readonly string[] };\n\nexport type PluginBuilderModuleEvaluationFailedError = PluginErrorBase<\n \"SODA_GQL_BUILDER_MODULE_EVALUATION_FAILED\",\n BuilderModuleEvaluationFailed\n> & { readonly stage: \"builder\"; readonly filePath: string; readonly astPath: string };\n\nexport type PluginBuilderWriteFailedError = PluginErrorBase<\"SODA_GQL_BUILDER_WRITE_FAILED\", BuilderWriteFailed> & {\n readonly stage: \"builder\";\n readonly outPath: string;\n};\n\nexport type PluginBuilderUnexpectedError = PluginErrorBase<\"SODA_GQL_BUILDER_UNEXPECTED\", unknown> & {\n readonly stage: \"builder\";\n};\n\nexport type PluginAnalysisMetadataMissingError = PluginErrorBase<\"SODA_GQL_METADATA_NOT_FOUND\", AnalysisMetadataMissingCause> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n};\n\nexport type PluginAnalysisArtifactMissingError = PluginErrorBase<\n \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n AnalysisArtifactMissingCause\n> & { readonly stage: \"analysis\"; readonly filename: string; readonly canonicalId: CanonicalId };\n\nexport type PluginAnalysisUnsupportedArtifactTypeError = PluginErrorBase<\n \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n AnalysisUnsupportedArtifactTypeCause\n> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype TransformMissingBuilderArgCause = { readonly filename: string; readonly builderType: string; readonly argName: string };\ntype TransformUnsupportedValueTypeCause = { readonly valueType: string };\ntype TransformAstVisitorFailedCause = { readonly filename: string; readonly reason: string };\n\nexport type PluginTransformMissingBuilderArgError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_MISSING_BUILDER_ARG\",\n TransformMissingBuilderArgCause\n> & {\n readonly stage: \"transform\";\n readonly filename: string;\n readonly builderType: string;\n readonly argName: string;\n};\n\nexport type PluginTransformUnsupportedValueTypeError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n TransformUnsupportedValueTypeCause\n> & { readonly stage: \"transform\"; readonly valueType: string };\n\nexport type PluginTransformAstVisitorFailedError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_AST_VISITOR_FAILED\",\n TransformAstVisitorFailedCause\n> & { readonly stage: \"transform\"; readonly filename: string; readonly reason: string };\n\n/**\n * Union of all plugin error types.\n */\nexport type PluginError =\n | PluginOptionsInvalidBuilderConfigError\n | PluginBuilderEntryNotFoundError\n | PluginBuilderDocDuplicateError\n | PluginBuilderCircularDependencyError\n | PluginBuilderModuleEvaluationFailedError\n | PluginBuilderWriteFailedError\n | PluginBuilderUnexpectedError\n | PluginAnalysisMetadataMissingError\n | PluginAnalysisArtifactMissingError\n | PluginAnalysisUnsupportedArtifactTypeError\n | PluginTransformMissingBuilderArgError\n | PluginTransformUnsupportedValueTypeError\n | PluginTransformAstVisitorFailedError;\n\n/**\n * Format a PluginError into a human-readable message.\n */\nexport const formatPluginError = (error: PluginError): string => {\n const codePrefix = `[${error.code}]`;\n const stageInfo = \"stage\" in error ? ` (${error.stage})` : \"\";\n return `${codePrefix}${stageInfo} ${error.message}`;\n};\n\n/**\n * Type guard for PluginError.\n */\nexport const isPluginError = (value: unknown): value is PluginError => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n value.type === \"PluginError\" &&\n \"code\" in value &&\n \"message\" in value\n );\n};\n\n/**\n * Assertion helper for unreachable code paths.\n * This is the ONLY acceptable throw in plugin code.\n */\nexport const assertUnreachable = (value: never, context?: string): never => {\n throw new Error(`[INTERNAL] Unreachable code path${context ? ` in ${context}` : \"\"}: received ${JSON.stringify(value)}`);\n};\n","import type { BuilderArtifact } from \"../artifact/types\";\nimport type { BuilderService } from \"../service\";\nimport type { PluginSession } from \"./session\";\n\n/**\n * Transformer type for code transformation.\n * - 'babel': Use Babel plugin (default, wider compatibility)\n * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)\n */\nexport type TransformerType = \"babel\" | \"swc\";\n\n/**\n * Minimal interface for SWC transformer.\n * Matches the Transformer interface from @soda-gql/swc.\n */\nexport interface SwcTransformerInterface {\n transform(input: { sourceCode: string; sourcePath: string; inputSourceMap?: string }): {\n transformed: boolean;\n sourceCode: string;\n sourceMap?: string;\n };\n}\n\n/**\n * Shared state between bundler plugins and loaders.\n * Enables efficient artifact sharing across build pipeline stages.\n */\nexport type SharedState = {\n pluginSession: PluginSession | null;\n currentArtifact: BuilderArtifact | null;\n moduleAdjacency: Map<string, Set<string>>;\n generation: number;\n swcTransformer: SwcTransformerInterface | null;\n transformerType: TransformerType | null;\n builderService: BuilderService | null;\n};\n\n// Global state for sharing between plugin and loader\nconst sharedStates = new Map<string, SharedState>();\n\n/**\n * Get shared state for a given project (identified by config path or cwd).\n */\nexport const getSharedState = (key: string): SharedState => {\n let state = sharedStates.get(key);\n if (!state) {\n state = {\n pluginSession: null,\n currentArtifact: null,\n moduleAdjacency: new Map(),\n generation: 0,\n swcTransformer: null,\n transformerType: null,\n builderService: null,\n };\n sharedStates.set(key, state);\n }\n return state;\n};\n\n/**\n * Update shared artifact.\n */\nexport const setSharedArtifact = (\n key: string,\n artifact: BuilderArtifact | null,\n moduleAdjacency?: Map<string, Set<string>>,\n): void => {\n const state = getSharedState(key);\n state.currentArtifact = artifact;\n if (moduleAdjacency) {\n state.moduleAdjacency = moduleAdjacency;\n }\n state.generation++;\n};\n\n/**\n * Get shared artifact.\n */\nexport const getSharedArtifact = (key: string): BuilderArtifact | null => {\n return getSharedState(key).currentArtifact;\n};\n\n/**\n * Get shared plugin session.\n */\nexport const getSharedPluginSession = (key: string): PluginSession | null => {\n return getSharedState(key).pluginSession;\n};\n\n/**\n * Set shared plugin session.\n */\nexport const setSharedPluginSession = (key: string, session: PluginSession | null): void => {\n getSharedState(key).pluginSession = session;\n};\n\n/**\n * Get the state key from config path or cwd.\n */\nexport const getStateKey = (configPath?: string): string => {\n return configPath ?? process.cwd();\n};\n\n/**\n * Set shared SWC transformer.\n */\nexport const setSharedSwcTransformer = (key: string, transformer: SwcTransformerInterface | null): void => {\n getSharedState(key).swcTransformer = transformer;\n};\n\n/**\n * Get shared SWC transformer.\n */\nexport const getSharedSwcTransformer = (key: string): SwcTransformerInterface | null => {\n return getSharedState(key).swcTransformer;\n};\n\n/**\n * Set shared transformer type.\n */\nexport const setSharedTransformerType = (key: string, transformerType: TransformerType | null): void => {\n getSharedState(key).transformerType = transformerType;\n};\n\n/**\n * Get shared transformer type.\n */\nexport const getSharedTransformerType = (key: string): TransformerType | null => {\n return getSharedState(key).transformerType;\n};\n\n/**\n * Get shared BuilderService.\n */\nexport const getSharedBuilderService = (key: string): BuilderService | null => {\n return getSharedState(key).builderService;\n};\n\n/**\n * Set shared BuilderService.\n */\nexport const setSharedBuilderService = (key: string, service: BuilderService | null): void => {\n getSharedState(key).builderService = service;\n};\n","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { loadArtifactSync } from \"../artifact/loader\";\nimport type { BuilderArtifact } from \"../artifact/types\";\nimport { formatBuilderErrorForCLI } from \"../errors/formatter\";\nimport type { BuilderService } from \"../service\";\nimport { createBuilderService } from \"../service\";\nimport { getSharedBuilderService, getStateKey, setSharedBuilderService } from \"./shared-state\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: boolean;\n /**\n * Whether to fail the build on error.\n * When true (default), throws an error that fails the bundler build.\n * When false, logs the error and continues (graceful degradation).\n */\n readonly failOnError?: boolean;\n};\n\n/**\n * Plugin session containing builder service and configuration.\n */\nexport type PluginSession = {\n readonly config: ResolvedSodaGqlConfig;\n readonly getArtifact: () => BuilderArtifact | null;\n readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;\n /**\n * Whether the session is using a pre-built artifact.\n * When true, artifacts are loaded from a file instead of built dynamically.\n */\n readonly isPrebuiltMode: boolean;\n};\n\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n *\n * @param options - Plugin options\n * @param pluginName - Name of the plugin for error messages\n * @throws Error if failOnError is true and config load fails\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n const failOnError = options.failOnError ?? true;\n\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load config: ${configResult.error.message}`;\n console.error(errorMsg, {\n code: configResult.error.code,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n if (failOnError) {\n throw new Error(errorMsg);\n }\n return null;\n }\n\n const config = configResult.value;\n\n // Check if pre-built artifact mode is enabled\n if (config.artifact?.path) {\n const artifactResult = loadArtifactSync(config.artifact.path);\n\n if (artifactResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load pre-built artifact: ${artifactResult.error.message}`;\n console.error(errorMsg, {\n code: artifactResult.error.code,\n filePath: artifactResult.error.filePath,\n });\n if (failOnError) {\n throw new Error(errorMsg);\n }\n return null;\n }\n\n const prebuiltArtifact = artifactResult.value;\n console.log(`[${pluginName}] Using pre-built artifact: ${config.artifact.path}`);\n\n return {\n config,\n getArtifact: () => prebuiltArtifact,\n getArtifactAsync: async () => prebuiltArtifact,\n isPrebuiltMode: true,\n };\n }\n\n // Dynamic build mode\n const stateKey = getStateKey(options.configPath);\n\n // Use global BuilderService cache to share FileTracker state across plugin instances\n const ensureBuilderService = (): BuilderService => {\n const existing = getSharedBuilderService(stateKey);\n if (existing) {\n return existing;\n }\n\n const service = createBuilderService({ config });\n setSharedBuilderService(stateKey, service);\n return service;\n };\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * This ensures the artifact is always up-to-date with the latest source files.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`);\n }\n return null;\n }\n return buildResult.value;\n };\n\n /**\n * Async version of getArtifact.\n * Supports async metadata factories and parallel element evaluation.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifactAsync = async (): Promise<BuilderArtifact | null> => {\n const builderService = ensureBuilderService();\n const buildResult = await builderService.buildAsync();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`);\n }\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n getArtifactAsync,\n isPrebuiltMode: false,\n };\n};\n","/**\n * Utility for working with canonical IDs.\n */\n\nimport { resolve } from \"node:path\";\nimport { type CanonicalId, createCanonicalId } from \"@soda-gql/common\";\n\n/**\n * Resolve a canonical ID from a filename and AST path.\n */\nexport const resolveCanonicalId = (filename: string, astPath: string): CanonicalId =>\n createCanonicalId(resolve(filename), astPath);\n"],"mappings":";;;;;;;;;AAqIA,MAAa,qBAAqB,UAA+B;CAC/D,MAAM,aAAa,IAAI,MAAM,KAAK;CAClC,MAAM,YAAY,WAAW,QAAQ,KAAK,MAAM,MAAM,KAAK;AAC3D,QAAO,GAAG,aAAa,UAAU,GAAG,MAAM;;;;;AAM5C,MAAa,iBAAiB,UAAyC;AACrE,QACE,OAAO,UAAU,YACjB,UAAU,QACV,UAAU,SACV,MAAM,SAAS,iBACf,UAAU,SACV,aAAa;;;;;;AAQjB,MAAa,qBAAqB,OAAc,YAA4B;AAC1E,OAAM,IAAI,MAAM,mCAAmC,UAAU,OAAO,YAAY,GAAG,aAAa,KAAK,UAAU,MAAM,GAAG;;;;;ACxH1H,MAAM,eAAe,IAAI,KAA0B;;;;AAKnD,MAAa,kBAAkB,QAA6B;CAC1D,IAAI,QAAQ,aAAa,IAAI,IAAI;AACjC,KAAI,CAAC,OAAO;AACV,UAAQ;GACN,eAAe;GACf,iBAAiB;GACjB,iBAAiB,IAAI,KAAK;GAC1B,YAAY;GACZ,gBAAgB;GAChB,iBAAiB;GACjB,gBAAgB;GACjB;AACD,eAAa,IAAI,KAAK,MAAM;;AAE9B,QAAO;;;;;AAMT,MAAa,qBACX,KACA,UACA,oBACS;CACT,MAAM,QAAQ,eAAe,IAAI;AACjC,OAAM,kBAAkB;AACxB,KAAI,iBAAiB;AACnB,QAAM,kBAAkB;;AAE1B,OAAM;;;;;AAMR,MAAa,qBAAqB,QAAwC;AACxE,QAAO,eAAe,IAAI,CAAC;;;;;AAM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;;;;;;;;;ACtJH,MAAa,sBAAsB,UAAkB,4EACzB,SAAS,EAAE,QAAQ"}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { i as BuilderArtifact, l as BuilderArtifactOperation, s as BuilderArtifactFragment, t as BuilderService, w as BuilderError } from "./service-BIDYnmeU.cjs";
|
|
2
|
+
import { CanonicalId } from "@soda-gql/common";
|
|
3
|
+
import { ResolvedSodaGqlConfig } from "@soda-gql/config";
|
|
4
|
+
|
|
5
|
+
//#region packages/builder/src/plugin/errors.d.ts
|
|
6
|
+
|
|
7
|
+
type OptionsInvalidBuilderConfig = {
|
|
8
|
+
readonly code: "INVALID_BUILDER_CONFIG";
|
|
9
|
+
readonly message: string;
|
|
10
|
+
};
|
|
11
|
+
type OptionsMissingBuilderConfig = {
|
|
12
|
+
readonly code: "MISSING_BUILDER_CONFIG";
|
|
13
|
+
readonly message: string;
|
|
14
|
+
};
|
|
15
|
+
type OptionsConfigLoadFailed = {
|
|
16
|
+
readonly code: "CONFIG_LOAD_FAILED";
|
|
17
|
+
readonly message: string;
|
|
18
|
+
};
|
|
19
|
+
type BuilderEntryNotFound = Extract<BuilderError, {
|
|
20
|
+
code: "ENTRY_NOT_FOUND";
|
|
21
|
+
}>;
|
|
22
|
+
type BuilderDocDuplicate = Extract<BuilderError, {
|
|
23
|
+
code: "DOC_DUPLICATE";
|
|
24
|
+
}>;
|
|
25
|
+
type BuilderCircularDependency = Extract<BuilderError, {
|
|
26
|
+
code: "GRAPH_CIRCULAR_DEPENDENCY";
|
|
27
|
+
}>;
|
|
28
|
+
type BuilderModuleEvaluationFailed = Extract<BuilderError, {
|
|
29
|
+
code: "RUNTIME_MODULE_LOAD_FAILED";
|
|
30
|
+
}>;
|
|
31
|
+
type BuilderWriteFailed = Extract<BuilderError, {
|
|
32
|
+
code: "WRITE_FAILED";
|
|
33
|
+
}>;
|
|
34
|
+
type AnalysisMetadataMissingCause = {
|
|
35
|
+
readonly filename: string;
|
|
36
|
+
};
|
|
37
|
+
type AnalysisArtifactMissingCause = {
|
|
38
|
+
readonly filename: string;
|
|
39
|
+
readonly canonicalId: CanonicalId;
|
|
40
|
+
};
|
|
41
|
+
type AnalysisUnsupportedArtifactTypeCause = {
|
|
42
|
+
readonly filename: string;
|
|
43
|
+
readonly canonicalId: CanonicalId;
|
|
44
|
+
readonly artifactType: string;
|
|
45
|
+
};
|
|
46
|
+
type PluginErrorBase<Code extends string, Cause> = {
|
|
47
|
+
readonly type: "PluginError";
|
|
48
|
+
readonly code: Code;
|
|
49
|
+
readonly message: string;
|
|
50
|
+
readonly cause: Cause;
|
|
51
|
+
};
|
|
52
|
+
type PluginOptionsInvalidBuilderConfigError = PluginErrorBase<"OPTIONS_INVALID_BUILDER_CONFIG", OptionsInvalidBuilderConfig | OptionsMissingBuilderConfig | OptionsConfigLoadFailed> & {
|
|
53
|
+
readonly stage: "normalize-options";
|
|
54
|
+
};
|
|
55
|
+
type PluginBuilderEntryNotFoundError = PluginErrorBase<"SODA_GQL_BUILDER_ENTRY_NOT_FOUND", BuilderEntryNotFound> & {
|
|
56
|
+
readonly stage: "builder";
|
|
57
|
+
readonly entry: string;
|
|
58
|
+
};
|
|
59
|
+
type PluginBuilderDocDuplicateError = PluginErrorBase<"SODA_GQL_BUILDER_DOC_DUPLICATE", BuilderDocDuplicate> & {
|
|
60
|
+
readonly stage: "builder";
|
|
61
|
+
readonly name: string;
|
|
62
|
+
readonly sources: readonly string[];
|
|
63
|
+
};
|
|
64
|
+
type PluginBuilderCircularDependencyError = PluginErrorBase<"SODA_GQL_BUILDER_CIRCULAR_DEPENDENCY", BuilderCircularDependency> & {
|
|
65
|
+
readonly stage: "builder";
|
|
66
|
+
readonly chain: readonly string[];
|
|
67
|
+
};
|
|
68
|
+
type PluginBuilderModuleEvaluationFailedError = PluginErrorBase<"SODA_GQL_BUILDER_MODULE_EVALUATION_FAILED", BuilderModuleEvaluationFailed> & {
|
|
69
|
+
readonly stage: "builder";
|
|
70
|
+
readonly filePath: string;
|
|
71
|
+
readonly astPath: string;
|
|
72
|
+
};
|
|
73
|
+
type PluginBuilderWriteFailedError = PluginErrorBase<"SODA_GQL_BUILDER_WRITE_FAILED", BuilderWriteFailed> & {
|
|
74
|
+
readonly stage: "builder";
|
|
75
|
+
readonly outPath: string;
|
|
76
|
+
};
|
|
77
|
+
type PluginBuilderUnexpectedError = PluginErrorBase<"SODA_GQL_BUILDER_UNEXPECTED", unknown> & {
|
|
78
|
+
readonly stage: "builder";
|
|
79
|
+
};
|
|
80
|
+
type PluginAnalysisMetadataMissingError = PluginErrorBase<"SODA_GQL_METADATA_NOT_FOUND", AnalysisMetadataMissingCause> & {
|
|
81
|
+
readonly stage: "analysis";
|
|
82
|
+
readonly filename: string;
|
|
83
|
+
};
|
|
84
|
+
type PluginAnalysisArtifactMissingError = PluginErrorBase<"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND", AnalysisArtifactMissingCause> & {
|
|
85
|
+
readonly stage: "analysis";
|
|
86
|
+
readonly filename: string;
|
|
87
|
+
readonly canonicalId: CanonicalId;
|
|
88
|
+
};
|
|
89
|
+
type PluginAnalysisUnsupportedArtifactTypeError = PluginErrorBase<"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE", AnalysisUnsupportedArtifactTypeCause> & {
|
|
90
|
+
readonly stage: "analysis";
|
|
91
|
+
readonly filename: string;
|
|
92
|
+
readonly canonicalId: CanonicalId;
|
|
93
|
+
readonly artifactType: string;
|
|
94
|
+
};
|
|
95
|
+
type TransformMissingBuilderArgCause = {
|
|
96
|
+
readonly filename: string;
|
|
97
|
+
readonly builderType: string;
|
|
98
|
+
readonly argName: string;
|
|
99
|
+
};
|
|
100
|
+
type TransformUnsupportedValueTypeCause = {
|
|
101
|
+
readonly valueType: string;
|
|
102
|
+
};
|
|
103
|
+
type TransformAstVisitorFailedCause = {
|
|
104
|
+
readonly filename: string;
|
|
105
|
+
readonly reason: string;
|
|
106
|
+
};
|
|
107
|
+
type PluginTransformMissingBuilderArgError = PluginErrorBase<"SODA_GQL_TRANSFORM_MISSING_BUILDER_ARG", TransformMissingBuilderArgCause> & {
|
|
108
|
+
readonly stage: "transform";
|
|
109
|
+
readonly filename: string;
|
|
110
|
+
readonly builderType: string;
|
|
111
|
+
readonly argName: string;
|
|
112
|
+
};
|
|
113
|
+
type PluginTransformUnsupportedValueTypeError = PluginErrorBase<"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE", TransformUnsupportedValueTypeCause> & {
|
|
114
|
+
readonly stage: "transform";
|
|
115
|
+
readonly valueType: string;
|
|
116
|
+
};
|
|
117
|
+
type PluginTransformAstVisitorFailedError = PluginErrorBase<"SODA_GQL_TRANSFORM_AST_VISITOR_FAILED", TransformAstVisitorFailedCause> & {
|
|
118
|
+
readonly stage: "transform";
|
|
119
|
+
readonly filename: string;
|
|
120
|
+
readonly reason: string;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* Union of all plugin error types.
|
|
124
|
+
*/
|
|
125
|
+
type PluginError = PluginOptionsInvalidBuilderConfigError | PluginBuilderEntryNotFoundError | PluginBuilderDocDuplicateError | PluginBuilderCircularDependencyError | PluginBuilderModuleEvaluationFailedError | PluginBuilderWriteFailedError | PluginBuilderUnexpectedError | PluginAnalysisMetadataMissingError | PluginAnalysisArtifactMissingError | PluginAnalysisUnsupportedArtifactTypeError | PluginTransformMissingBuilderArgError | PluginTransformUnsupportedValueTypeError | PluginTransformAstVisitorFailedError;
|
|
126
|
+
/**
|
|
127
|
+
* Format a PluginError into a human-readable message.
|
|
128
|
+
*/
|
|
129
|
+
declare const formatPluginError: (error: PluginError) => string;
|
|
130
|
+
/**
|
|
131
|
+
* Type guard for PluginError.
|
|
132
|
+
*/
|
|
133
|
+
declare const isPluginError: (value: unknown) => value is PluginError;
|
|
134
|
+
/**
|
|
135
|
+
* Assertion helper for unreachable code paths.
|
|
136
|
+
* This is the ONLY acceptable throw in plugin code.
|
|
137
|
+
*/
|
|
138
|
+
declare const assertUnreachable: (value: never, context?: string) => never;
|
|
139
|
+
//#endregion
|
|
140
|
+
//#region packages/builder/src/plugin/session.d.ts
|
|
141
|
+
/**
|
|
142
|
+
* Plugin options shared across all plugins.
|
|
143
|
+
*/
|
|
144
|
+
type PluginOptions = {
|
|
145
|
+
readonly configPath?: string;
|
|
146
|
+
readonly enabled?: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether to fail the build on error.
|
|
149
|
+
* When true (default), throws an error that fails the bundler build.
|
|
150
|
+
* When false, logs the error and continues (graceful degradation).
|
|
151
|
+
*/
|
|
152
|
+
readonly failOnError?: boolean;
|
|
153
|
+
};
|
|
154
|
+
/**
|
|
155
|
+
* Plugin session containing builder service and configuration.
|
|
156
|
+
*/
|
|
157
|
+
type PluginSession = {
|
|
158
|
+
readonly config: ResolvedSodaGqlConfig;
|
|
159
|
+
readonly getArtifact: () => BuilderArtifact | null;
|
|
160
|
+
readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;
|
|
161
|
+
/**
|
|
162
|
+
* Whether the session is using a pre-built artifact.
|
|
163
|
+
* When true, artifacts are loaded from a file instead of built dynamically.
|
|
164
|
+
*/
|
|
165
|
+
readonly isPrebuiltMode: boolean;
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* Create plugin session by loading config and creating cached builder service.
|
|
169
|
+
* Returns null if disabled or config load fails.
|
|
170
|
+
*
|
|
171
|
+
* @param options - Plugin options
|
|
172
|
+
* @param pluginName - Name of the plugin for error messages
|
|
173
|
+
* @throws Error if failOnError is true and config load fails
|
|
174
|
+
*/
|
|
175
|
+
declare const createPluginSession: (options: PluginOptions, pluginName: string) => PluginSession | null;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region packages/builder/src/plugin/shared-state.d.ts
|
|
178
|
+
/**
|
|
179
|
+
* Transformer type for code transformation.
|
|
180
|
+
* - 'babel': Use Babel plugin (default, wider compatibility)
|
|
181
|
+
* - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)
|
|
182
|
+
*/
|
|
183
|
+
type TransformerType = "babel" | "swc";
|
|
184
|
+
/**
|
|
185
|
+
* Minimal interface for SWC transformer.
|
|
186
|
+
* Matches the Transformer interface from @soda-gql/swc.
|
|
187
|
+
*/
|
|
188
|
+
interface SwcTransformerInterface {
|
|
189
|
+
transform(input: {
|
|
190
|
+
sourceCode: string;
|
|
191
|
+
sourcePath: string;
|
|
192
|
+
inputSourceMap?: string;
|
|
193
|
+
}): {
|
|
194
|
+
transformed: boolean;
|
|
195
|
+
sourceCode: string;
|
|
196
|
+
sourceMap?: string;
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Shared state between bundler plugins and loaders.
|
|
201
|
+
* Enables efficient artifact sharing across build pipeline stages.
|
|
202
|
+
*/
|
|
203
|
+
type SharedState = {
|
|
204
|
+
pluginSession: PluginSession | null;
|
|
205
|
+
currentArtifact: BuilderArtifact | null;
|
|
206
|
+
moduleAdjacency: Map<string, Set<string>>;
|
|
207
|
+
generation: number;
|
|
208
|
+
swcTransformer: SwcTransformerInterface | null;
|
|
209
|
+
transformerType: TransformerType | null;
|
|
210
|
+
builderService: BuilderService | null;
|
|
211
|
+
};
|
|
212
|
+
/**
|
|
213
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
214
|
+
*/
|
|
215
|
+
declare const getSharedState: (key: string) => SharedState;
|
|
216
|
+
/**
|
|
217
|
+
* Update shared artifact.
|
|
218
|
+
*/
|
|
219
|
+
declare const setSharedArtifact: (key: string, artifact: BuilderArtifact | null, moduleAdjacency?: Map<string, Set<string>>) => void;
|
|
220
|
+
/**
|
|
221
|
+
* Get shared artifact.
|
|
222
|
+
*/
|
|
223
|
+
declare const getSharedArtifact: (key: string) => BuilderArtifact | null;
|
|
224
|
+
/**
|
|
225
|
+
* Get shared plugin session.
|
|
226
|
+
*/
|
|
227
|
+
declare const getSharedPluginSession: (key: string) => PluginSession | null;
|
|
228
|
+
/**
|
|
229
|
+
* Set shared plugin session.
|
|
230
|
+
*/
|
|
231
|
+
declare const setSharedPluginSession: (key: string, session: PluginSession | null) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Get the state key from config path or cwd.
|
|
234
|
+
*/
|
|
235
|
+
declare const getStateKey: (configPath?: string) => string;
|
|
236
|
+
/**
|
|
237
|
+
* Set shared SWC transformer.
|
|
238
|
+
*/
|
|
239
|
+
declare const setSharedSwcTransformer: (key: string, transformer: SwcTransformerInterface | null) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Get shared SWC transformer.
|
|
242
|
+
*/
|
|
243
|
+
declare const getSharedSwcTransformer: (key: string) => SwcTransformerInterface | null;
|
|
244
|
+
/**
|
|
245
|
+
* Set shared transformer type.
|
|
246
|
+
*/
|
|
247
|
+
declare const setSharedTransformerType: (key: string, transformerType: TransformerType | null) => void;
|
|
248
|
+
/**
|
|
249
|
+
* Get shared transformer type.
|
|
250
|
+
*/
|
|
251
|
+
declare const getSharedTransformerType: (key: string) => TransformerType | null;
|
|
252
|
+
/**
|
|
253
|
+
* Get shared BuilderService.
|
|
254
|
+
*/
|
|
255
|
+
declare const getSharedBuilderService: (key: string) => BuilderService | null;
|
|
256
|
+
/**
|
|
257
|
+
* Set shared BuilderService.
|
|
258
|
+
*/
|
|
259
|
+
declare const setSharedBuilderService: (key: string, service: BuilderService | null) => void;
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region packages/builder/src/plugin/types/gql-call.d.ts
|
|
262
|
+
/**
|
|
263
|
+
* Base interface for all GraphQL call types.
|
|
264
|
+
*/
|
|
265
|
+
interface GqlCallBase {
|
|
266
|
+
readonly canonicalId: CanonicalId;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* GraphQL fragment call.
|
|
270
|
+
*/
|
|
271
|
+
interface GqlCallFragment extends GqlCallBase {
|
|
272
|
+
readonly type: "fragment";
|
|
273
|
+
readonly artifact: BuilderArtifactFragment;
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* GraphQL operation call.
|
|
277
|
+
*/
|
|
278
|
+
interface GqlCallOperation extends GqlCallBase {
|
|
279
|
+
readonly type: "operation";
|
|
280
|
+
readonly artifact: BuilderArtifactOperation;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Union of all GraphQL call types.
|
|
284
|
+
*/
|
|
285
|
+
type GqlCall = GqlCallFragment | GqlCallOperation;
|
|
286
|
+
//#endregion
|
|
287
|
+
//#region packages/builder/src/plugin/types/metadata.d.ts
|
|
288
|
+
/**
|
|
289
|
+
* Unified metadata types used across all plugins.
|
|
290
|
+
*/
|
|
291
|
+
/**
|
|
292
|
+
* Metadata for a GraphQL definition.
|
|
293
|
+
*/
|
|
294
|
+
type GqlDefinitionMetadata = {
|
|
295
|
+
readonly astPath: string;
|
|
296
|
+
readonly isTopLevel: boolean;
|
|
297
|
+
readonly isExported: boolean;
|
|
298
|
+
readonly exportBinding?: string;
|
|
299
|
+
};
|
|
300
|
+
//#endregion
|
|
301
|
+
//#region packages/builder/src/plugin/utils/canonical-id.d.ts
|
|
302
|
+
/**
|
|
303
|
+
* Resolve a canonical ID from a filename and AST path.
|
|
304
|
+
*/
|
|
305
|
+
declare const resolveCanonicalId: (filename: string, astPath: string) => CanonicalId;
|
|
306
|
+
//#endregion
|
|
307
|
+
export { type GqlCall, type GqlCallBase, type GqlCallFragment, type GqlCallOperation, type GqlDefinitionMetadata, PluginAnalysisArtifactMissingError, PluginAnalysisMetadataMissingError, PluginAnalysisUnsupportedArtifactTypeError, PluginBuilderCircularDependencyError, PluginBuilderDocDuplicateError, PluginBuilderEntryNotFoundError, PluginBuilderModuleEvaluationFailedError, PluginBuilderUnexpectedError, PluginBuilderWriteFailedError, PluginError, PluginOptions, PluginOptionsInvalidBuilderConfigError, PluginSession, PluginTransformAstVisitorFailedError, PluginTransformMissingBuilderArgError, PluginTransformUnsupportedValueTypeError, SharedState, SwcTransformerInterface, TransformerType, assertUnreachable, createPluginSession, formatPluginError, getSharedArtifact, getSharedBuilderService, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getSharedTransformerType, getStateKey, isPluginError, resolveCanonicalId, setSharedArtifact, setSharedBuilderService, setSharedPluginSession, setSharedSwcTransformer, setSharedTransformerType };
|
|
308
|
+
//# sourceMappingURL=plugin-support.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-support.d.cts","names":[],"sources":["../src/plugin/errors.ts","../src/plugin/session.ts","../src/plugin/shared-state.ts","../src/plugin/types/gql-call.ts","../src/plugin/types/metadata.ts","../src/plugin/utils/canonical-id.ts"],"sourcesContent":[],"mappings":";;;;;;AAQgC,KAA3B,2BAAA,GAC2B;EAC3B,SAAA,IAAA,EAAA,wBAAuB;EAEvB,SAAA,OAAA,EAAA,MAAoB;AAAU,CAAA;AACD,KAJ7B,2BAAA,GAKyB;EACzB,SAAA,IAAA,EAAA,wBAA6B;EAC7B,SAAA,OAAA,EAAA,MAAkB;AAAU,CAAA;AAEA,KAR5B,uBAAA,GASA;EACA,SAAA,IAAA,EAAA,oBAAA;EAMA,SAAA,OAAA,EAAe,MAAA;AAOpB,CAAA;KArBK,oBAAA,GAAuB,OAuB1B,CAvBkC,YAuBlC,EAAA;EAA8B,IAAA,EAAA,iBAAA;CAA8B,CAAA;KAtBzD,mBAAA,GAAsB,OAoB0B,CApBlB,YAoBkB,EAAA;EAAe,IAAA,EAAA,eAAA;AAKpE,CAAA,CAAA;AAKA,KA7BK,yBAAA,GAA4B,OA6BS,CA7BD,YA6BsD,EAAA;EAMnF,IAAA,EAAA,2BAAA;AAKZ,CAAA,CAAA;AAKA,KA5CK,6BAAA,GAAgC,OA4CI,CA5CI,YA4CgD,EAAA;EAKjF,IAAA,EAAA,4BAA4B;AAIxC,CAAA,CAAA;AAKA,KAzDK,kBAAA,GAAqB,OAyDd,CAzDsB,YAyDY,EAAA;EAE5C,IAAA,EAAA,cAAA;CAF+C,CAAA;KAvD5C,4BAAA,GA0D8E;EAAW,SAAA,QAAA,EAAA,MAAA;AAE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