@soda-gql/plugin-common 0.0.9 → 0.2.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 +45 -7
- package/dist/index.cjs +106 -3
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +87 -27
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +87 -27
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +96 -4
- package/dist/index.mjs.map +1 -1
- package/package.json +25 -5
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ Shared utilities and types for soda-gql compiler plugins.
|
|
|
7
7
|
This package provides common functionality used across all soda-gql compiler plugins (Babel, SWC, TypeScript). It's designed for plugin developers and is not intended for direct use by end users.
|
|
8
8
|
|
|
9
9
|
If you're looking to use soda-gql in your project, see:
|
|
10
|
-
- [@soda-gql/plugin
|
|
10
|
+
- [@soda-gql/babel-plugin](../babel-plugin) - Babel plugin (production-ready)
|
|
11
11
|
- [@soda-gql/plugin-swc](../plugin-swc) - SWC plugin (in development)
|
|
12
12
|
- [@soda-gql/tsc-plugin](../tsc-plugin) - TypeScript plugin
|
|
13
13
|
|
|
@@ -16,8 +16,8 @@ If you're looking to use soda-gql in your project, see:
|
|
|
16
16
|
This package is automatically installed as a dependency of plugin packages. You don't need to install it directly.
|
|
17
17
|
|
|
18
18
|
```bash
|
|
19
|
-
# Installed automatically with plugin
|
|
20
|
-
bun add -D @soda-gql/plugin
|
|
19
|
+
# Installed automatically with babel-plugin
|
|
20
|
+
bun add -D @soda-gql/babel-plugin
|
|
21
21
|
```
|
|
22
22
|
|
|
23
23
|
## Exports
|
|
@@ -36,7 +36,7 @@ type TypeScriptGqlCall = GqlCall<ts.CallExpression>;
|
|
|
36
36
|
```
|
|
37
37
|
|
|
38
38
|
Available variants:
|
|
39
|
-
- `
|
|
39
|
+
- `GqlCallFragment<TCallNode>` - Fragment definitions
|
|
40
40
|
- `GqlCallSlice<TCallNode>` - Query/mutation/subscription slices
|
|
41
41
|
- `GqlCallOperation<TCallNode>` - Composed operations
|
|
42
42
|
- `GqlCallInlineOperation<TCallNode>` - Inline operations
|
|
@@ -113,14 +113,52 @@ Creates a plugin session with configuration and artifact management:
|
|
|
113
113
|
```typescript
|
|
114
114
|
import { createPluginSession } from "@soda-gql/plugin-common";
|
|
115
115
|
|
|
116
|
-
const session = createPluginSession(options, "@soda-gql/plugin
|
|
116
|
+
const session = createPluginSession(options, "@soda-gql/babel-plugin");
|
|
117
117
|
|
|
118
118
|
if (session) {
|
|
119
|
+
// Sync artifact retrieval
|
|
119
120
|
const artifact = session.getArtifact();
|
|
121
|
+
|
|
122
|
+
// Async artifact retrieval (supports async metadata factories)
|
|
123
|
+
const asyncArtifact = await session.getArtifactAsync();
|
|
124
|
+
|
|
120
125
|
const config = session.config;
|
|
121
126
|
}
|
|
122
127
|
```
|
|
123
128
|
|
|
129
|
+
### Shared State API
|
|
130
|
+
|
|
131
|
+
For bundler plugins that need to share state between plugin and loader stages (e.g., Webpack):
|
|
132
|
+
|
|
133
|
+
```typescript
|
|
134
|
+
import {
|
|
135
|
+
getSharedState,
|
|
136
|
+
setSharedArtifact,
|
|
137
|
+
getSharedArtifact,
|
|
138
|
+
getStateKey,
|
|
139
|
+
} from "@soda-gql/plugin-common";
|
|
140
|
+
|
|
141
|
+
// Get state key from config path
|
|
142
|
+
const key = getStateKey(configPath);
|
|
143
|
+
|
|
144
|
+
// Share artifact between plugin and loader
|
|
145
|
+
setSharedArtifact(key, artifact, moduleAdjacency);
|
|
146
|
+
|
|
147
|
+
// Retrieve shared artifact in loader
|
|
148
|
+
const sharedArtifact = getSharedArtifact(key);
|
|
149
|
+
|
|
150
|
+
// Full state access
|
|
151
|
+
const state = getSharedState(key);
|
|
152
|
+
// state.currentArtifact
|
|
153
|
+
// state.moduleAdjacency
|
|
154
|
+
// state.generation
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
The shared state enables:
|
|
158
|
+
- Efficient artifact sharing across build pipeline stages
|
|
159
|
+
- Module adjacency tracking for dependency-aware rebuilds
|
|
160
|
+
- Generation tracking for cache invalidation
|
|
161
|
+
|
|
124
162
|
## Plugin Development Guide
|
|
125
163
|
|
|
126
164
|
### Creating a New Plugin
|
|
@@ -167,7 +205,7 @@ function transformNode(node, metadata, artifact) {
|
|
|
167
205
|
}
|
|
168
206
|
|
|
169
207
|
const gqlCall = gqlCallResult.value;
|
|
170
|
-
// Transform based on gqlCall.type: "
|
|
208
|
+
// Transform based on gqlCall.type: "fragment" | "slice" | "operation" | "inlineOperation"
|
|
171
209
|
}
|
|
172
210
|
```
|
|
173
211
|
|
|
@@ -230,7 +268,7 @@ This package is written in TypeScript and provides complete type definitions:
|
|
|
230
268
|
```typescript
|
|
231
269
|
import type {
|
|
232
270
|
GqlCall,
|
|
233
|
-
|
|
271
|
+
GqlCallFragment,
|
|
234
272
|
GqlDefinitionMetadata,
|
|
235
273
|
PluginError,
|
|
236
274
|
PluginOptions,
|
package/dist/index.cjs
CHANGED
|
@@ -57,12 +57,104 @@ const createPluginSession = (options, pluginName) => {
|
|
|
57
57
|
}
|
|
58
58
|
return buildResult.value;
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Async version of getArtifact.
|
|
62
|
+
* Supports async metadata factories and parallel element evaluation.
|
|
63
|
+
*/
|
|
64
|
+
const getArtifactAsync = async () => {
|
|
65
|
+
const buildResult = await ensureBuilderService().buildAsync();
|
|
66
|
+
if (buildResult.isErr()) {
|
|
67
|
+
console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return buildResult.value;
|
|
71
|
+
};
|
|
60
72
|
return {
|
|
61
73
|
config,
|
|
62
|
-
getArtifact
|
|
74
|
+
getArtifact,
|
|
75
|
+
getArtifactAsync
|
|
63
76
|
};
|
|
64
77
|
};
|
|
65
78
|
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region packages/plugin-common/src/shared-state.ts
|
|
81
|
+
const sharedStates = /* @__PURE__ */ new Map();
|
|
82
|
+
/**
|
|
83
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
84
|
+
*/
|
|
85
|
+
const getSharedState = (key) => {
|
|
86
|
+
let state = sharedStates.get(key);
|
|
87
|
+
if (!state) {
|
|
88
|
+
state = {
|
|
89
|
+
pluginSession: null,
|
|
90
|
+
currentArtifact: null,
|
|
91
|
+
moduleAdjacency: /* @__PURE__ */ new Map(),
|
|
92
|
+
generation: 0,
|
|
93
|
+
swcTransformer: null,
|
|
94
|
+
transformerType: null
|
|
95
|
+
};
|
|
96
|
+
sharedStates.set(key, state);
|
|
97
|
+
}
|
|
98
|
+
return state;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Update shared artifact.
|
|
102
|
+
*/
|
|
103
|
+
const setSharedArtifact = (key, artifact, moduleAdjacency) => {
|
|
104
|
+
const state = getSharedState(key);
|
|
105
|
+
state.currentArtifact = artifact;
|
|
106
|
+
if (moduleAdjacency) state.moduleAdjacency = moduleAdjacency;
|
|
107
|
+
state.generation++;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Get shared artifact.
|
|
111
|
+
*/
|
|
112
|
+
const getSharedArtifact = (key) => {
|
|
113
|
+
return getSharedState(key).currentArtifact;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Get shared plugin session.
|
|
117
|
+
*/
|
|
118
|
+
const getSharedPluginSession = (key) => {
|
|
119
|
+
return getSharedState(key).pluginSession;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Set shared plugin session.
|
|
123
|
+
*/
|
|
124
|
+
const setSharedPluginSession = (key, session) => {
|
|
125
|
+
getSharedState(key).pluginSession = session;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Get the state key from config path or cwd.
|
|
129
|
+
*/
|
|
130
|
+
const getStateKey = (configPath) => {
|
|
131
|
+
return configPath ?? process.cwd();
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Set shared SWC transformer.
|
|
135
|
+
*/
|
|
136
|
+
const setSharedSwcTransformer = (key, transformer) => {
|
|
137
|
+
getSharedState(key).swcTransformer = transformer;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Get shared SWC transformer.
|
|
141
|
+
*/
|
|
142
|
+
const getSharedSwcTransformer = (key) => {
|
|
143
|
+
return getSharedState(key).swcTransformer;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Set shared transformer type.
|
|
147
|
+
*/
|
|
148
|
+
const setSharedTransformerType = (key, transformerType) => {
|
|
149
|
+
getSharedState(key).transformerType = transformerType;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Get shared transformer type.
|
|
153
|
+
*/
|
|
154
|
+
const getSharedTransformerType = (key) => {
|
|
155
|
+
return getSharedState(key).transformerType;
|
|
156
|
+
};
|
|
157
|
+
|
|
66
158
|
//#endregion
|
|
67
159
|
//#region packages/plugin-common/src/utils/canonical-id.ts
|
|
68
160
|
/**
|
|
@@ -71,11 +163,22 @@ const createPluginSession = (options, pluginName) => {
|
|
|
71
163
|
/**
|
|
72
164
|
* Resolve a canonical ID from a filename and AST path.
|
|
73
165
|
*/
|
|
74
|
-
const resolveCanonicalId = (filename, astPath) => (0,
|
|
166
|
+
const resolveCanonicalId = (filename, astPath) => (0, __soda_gql_common.createCanonicalId)((0, node_path.resolve)(filename), astPath);
|
|
75
167
|
|
|
76
168
|
//#endregion
|
|
77
169
|
exports.assertUnreachable = assertUnreachable;
|
|
78
170
|
exports.createPluginSession = createPluginSession;
|
|
79
171
|
exports.formatPluginError = formatPluginError;
|
|
172
|
+
exports.getSharedArtifact = getSharedArtifact;
|
|
173
|
+
exports.getSharedPluginSession = getSharedPluginSession;
|
|
174
|
+
exports.getSharedState = getSharedState;
|
|
175
|
+
exports.getSharedSwcTransformer = getSharedSwcTransformer;
|
|
176
|
+
exports.getSharedTransformerType = getSharedTransformerType;
|
|
177
|
+
exports.getStateKey = getStateKey;
|
|
80
178
|
exports.isPluginError = isPluginError;
|
|
81
|
-
exports.resolveCanonicalId = resolveCanonicalId;
|
|
179
|
+
exports.resolveCanonicalId = resolveCanonicalId;
|
|
180
|
+
exports.setSharedArtifact = setSharedArtifact;
|
|
181
|
+
exports.setSharedPluginSession = setSharedPluginSession;
|
|
182
|
+
exports.setSharedSwcTransformer = setSharedSwcTransformer;
|
|
183
|
+
exports.setSharedTransformerType = setSharedTransformerType;
|
|
184
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/shared-state.ts","../src/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 { BuilderError } from \"@soda-gql/builder\";\nimport type { CanonicalId } from \"@soda-gql/common\";\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","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { cachedFn } from \"@soda-gql/common\";\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: 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\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n console.error(`[${pluginName}] Failed to load config:`, {\n code: configResult.error.code,\n message: configResult.error.message,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n return null;\n }\n\n const config = configResult.value;\n const ensureBuilderService = cachedFn(() => createBuilderService({ config }));\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * If artifact.useBuilder is false and artifact.path is provided, load from file instead.\n * This ensures the artifact is always up-to-date with the latest source files.\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);\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 const getArtifactAsync = async (): Promise<BuilderArtifact | null> => {\n const builderService = ensureBuilderService();\n const buildResult = await builderService.buildAsync();\n if (buildResult.isErr()) {\n console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n getArtifactAsync,\n };\n};\n","import type { BuilderArtifact } from \"@soda-gql/builder\";\nimport type { PluginSession } from \"./plugin-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-transformer)\n */\nexport type TransformerType = \"babel\" | \"swc\";\n\n/**\n * Minimal interface for SWC transformer.\n * Matches the Transformer interface from @soda-gql/swc-transformer.\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};\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 };\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 * 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 resolveCanon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,QAAO;EACL;EACA;EACA;EACD;;;;;AChDH,MAAM,+BAAe,IAAI,KAA0B;;;;AAKnD,MAAa,kBAAkB,QAA6B;CAC1D,IAAI,QAAQ,aAAa,IAAI,IAAI;AACjC,KAAI,CAAC,OAAO;AACV,UAAQ;GACN,eAAe;GACf,iBAAiB;GACjB,iCAAiB,IAAI,KAAK;GAC1B,YAAY;GACZ,gBAAgB;GAChB,iBAAiB;GAClB;AACD,eAAa,IAAI,KAAK,MAAM;;AAE9B,QAAO;;;;;AAMT,MAAa,qBACX,KACA,UACA,oBACS;CACT,MAAM,QAAQ,eAAe,IAAI;AACjC,OAAM,kBAAkB;AACxB,KAAI,gBACF,OAAM,kBAAkB;AAE1B,OAAM;;;;;AAMR,MAAa,qBAAqB,QAAwC;AACxE,QAAO,eAAe,IAAI,CAAC;;;;;AAM7B,MAAa,0BAA0B,QAAsC;AAC3E,QAAO,eAAe,IAAI,CAAC;;;;;AAM7B,MAAa,0BAA0B,KAAa,YAAwC;AAC1F,gBAAe,IAAI,CAAC,gBAAgB;;;;;AAMtC,MAAa,eAAe,eAAgC;AAC1D,QAAO,cAAc,QAAQ,KAAK;;;;;AAMpC,MAAa,2BAA2B,KAAa,gBAAsD;AACzG,gBAAe,IAAI,CAAC,iBAAiB;;;;;AAMvC,MAAa,2BAA2B,QAAgD;AACtF,QAAO,eAAe,IAAI,CAAC;;;;;AAM7B,MAAa,4BAA4B,KAAa,oBAAkD;AACtG,gBAAe,IAAI,CAAC,kBAAkB;;;;;AAMxC,MAAa,4BAA4B,QAAwC;AAC/E,QAAO,eAAe,IAAI,CAAC;;;;;;;;;;;ACpH7B,MAAa,sBAAsB,UAAkB,4EACzB,SAAS,EAAE,QAAQ"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BuilderArtifact,
|
|
1
|
+
import { BuilderArtifact, BuilderArtifactFragment, BuilderArtifactOperation, BuilderError } from "@soda-gql/builder";
|
|
2
|
+
import { CanonicalId } from "@soda-gql/common";
|
|
2
3
|
import { ResolvedSodaGqlConfig } from "@soda-gql/config";
|
|
3
4
|
|
|
4
5
|
//#region packages/plugin-common/src/errors.d.ts
|
|
@@ -150,6 +151,7 @@ type PluginOptions = {
|
|
|
150
151
|
type PluginSession = {
|
|
151
152
|
readonly config: ResolvedSodaGqlConfig;
|
|
152
153
|
readonly getArtifact: () => BuilderArtifact | null;
|
|
154
|
+
readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;
|
|
153
155
|
};
|
|
154
156
|
/**
|
|
155
157
|
* Create plugin session by loading config and creating cached builder service.
|
|
@@ -157,48 +159,106 @@ type PluginSession = {
|
|
|
157
159
|
*/
|
|
158
160
|
declare const createPluginSession: (options: PluginOptions, pluginName: string) => PluginSession | null;
|
|
159
161
|
//#endregion
|
|
160
|
-
//#region packages/plugin-common/src/
|
|
162
|
+
//#region packages/plugin-common/src/shared-state.d.ts
|
|
161
163
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
+
* Transformer type for code transformation.
|
|
165
|
+
* - 'babel': Use Babel plugin (default, wider compatibility)
|
|
166
|
+
* - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
|
|
164
167
|
*/
|
|
165
|
-
|
|
166
|
-
readonly canonicalId: CanonicalId;
|
|
167
|
-
readonly builderCall: TCallNode;
|
|
168
|
-
}
|
|
168
|
+
type TransformerType = "babel" | "swc";
|
|
169
169
|
/**
|
|
170
|
-
*
|
|
170
|
+
* Minimal interface for SWC transformer.
|
|
171
|
+
* Matches the Transformer interface from @soda-gql/swc-transformer.
|
|
171
172
|
*/
|
|
172
|
-
interface
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
interface SwcTransformerInterface {
|
|
174
|
+
transform(input: {
|
|
175
|
+
sourceCode: string;
|
|
176
|
+
sourcePath: string;
|
|
177
|
+
inputSourceMap?: string;
|
|
178
|
+
}): {
|
|
179
|
+
transformed: boolean;
|
|
180
|
+
sourceCode: string;
|
|
181
|
+
sourceMap?: string;
|
|
182
|
+
};
|
|
175
183
|
}
|
|
176
184
|
/**
|
|
177
|
-
*
|
|
185
|
+
* Shared state between bundler plugins and loaders.
|
|
186
|
+
* Enables efficient artifact sharing across build pipeline stages.
|
|
187
|
+
*/
|
|
188
|
+
type SharedState = {
|
|
189
|
+
pluginSession: PluginSession | null;
|
|
190
|
+
currentArtifact: BuilderArtifact | null;
|
|
191
|
+
moduleAdjacency: Map<string, Set<string>>;
|
|
192
|
+
generation: number;
|
|
193
|
+
swcTransformer: SwcTransformerInterface | null;
|
|
194
|
+
transformerType: TransformerType | null;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
198
|
+
*/
|
|
199
|
+
declare const getSharedState: (key: string) => SharedState;
|
|
200
|
+
/**
|
|
201
|
+
* Update shared artifact.
|
|
178
202
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
declare const setSharedArtifact: (key: string, artifact: BuilderArtifact | null, moduleAdjacency?: Map<string, Set<string>>) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Get shared artifact.
|
|
206
|
+
*/
|
|
207
|
+
declare const getSharedArtifact: (key: string) => BuilderArtifact | null;
|
|
208
|
+
/**
|
|
209
|
+
* Get shared plugin session.
|
|
210
|
+
*/
|
|
211
|
+
declare const getSharedPluginSession: (key: string) => PluginSession | null;
|
|
212
|
+
/**
|
|
213
|
+
* Set shared plugin session.
|
|
214
|
+
*/
|
|
215
|
+
declare const setSharedPluginSession: (key: string, session: PluginSession | null) => void;
|
|
216
|
+
/**
|
|
217
|
+
* Get the state key from config path or cwd.
|
|
218
|
+
*/
|
|
219
|
+
declare const getStateKey: (configPath?: string) => string;
|
|
220
|
+
/**
|
|
221
|
+
* Set shared SWC transformer.
|
|
222
|
+
*/
|
|
223
|
+
declare const setSharedSwcTransformer: (key: string, transformer: SwcTransformerInterface | null) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Get shared SWC transformer.
|
|
226
|
+
*/
|
|
227
|
+
declare const getSharedSwcTransformer: (key: string) => SwcTransformerInterface | null;
|
|
228
|
+
/**
|
|
229
|
+
* Set shared transformer type.
|
|
230
|
+
*/
|
|
231
|
+
declare const setSharedTransformerType: (key: string, transformerType: TransformerType | null) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Get shared transformer type.
|
|
234
|
+
*/
|
|
235
|
+
declare const getSharedTransformerType: (key: string) => TransformerType | null;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region packages/plugin-common/src/types/gql-call.d.ts
|
|
238
|
+
/**
|
|
239
|
+
* Base interface for all GraphQL call types.
|
|
240
|
+
*/
|
|
241
|
+
interface GqlCallBase {
|
|
242
|
+
readonly canonicalId: CanonicalId;
|
|
182
243
|
}
|
|
183
244
|
/**
|
|
184
|
-
* GraphQL
|
|
185
|
-
* Unified naming: "operation" (was "composedOperation" in tsc-plugin).
|
|
245
|
+
* GraphQL fragment call.
|
|
186
246
|
*/
|
|
187
|
-
interface
|
|
188
|
-
readonly type: "
|
|
189
|
-
readonly artifact:
|
|
247
|
+
interface GqlCallFragment extends GqlCallBase {
|
|
248
|
+
readonly type: "fragment";
|
|
249
|
+
readonly artifact: BuilderArtifactFragment;
|
|
190
250
|
}
|
|
191
251
|
/**
|
|
192
|
-
* GraphQL
|
|
252
|
+
* GraphQL operation call.
|
|
193
253
|
*/
|
|
194
|
-
interface
|
|
195
|
-
readonly type: "
|
|
196
|
-
readonly artifact:
|
|
254
|
+
interface GqlCallOperation extends GqlCallBase {
|
|
255
|
+
readonly type: "operation";
|
|
256
|
+
readonly artifact: BuilderArtifactOperation;
|
|
197
257
|
}
|
|
198
258
|
/**
|
|
199
259
|
* Union of all GraphQL call types.
|
|
200
260
|
*/
|
|
201
|
-
type GqlCall
|
|
261
|
+
type GqlCall = GqlCallFragment | GqlCallOperation;
|
|
202
262
|
//#endregion
|
|
203
263
|
//#region packages/plugin-common/src/types/metadata.d.ts
|
|
204
264
|
/**
|
|
@@ -220,5 +280,5 @@ type GqlDefinitionMetadata = {
|
|
|
220
280
|
*/
|
|
221
281
|
declare const resolveCanonicalId: (filename: string, astPath: string) => CanonicalId;
|
|
222
282
|
//#endregion
|
|
223
|
-
export { type GqlCall, type GqlCallBase, type
|
|
283
|
+
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, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getSharedTransformerType, getStateKey, isPluginError, resolveCanonicalId, setSharedArtifact, setSharedPluginSession, setSharedSwcTransformer, setSharedTransformerType };
|
|
224
284
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/types/gql-call.ts","../src/types/metadata.ts","../src/utils/canonical-id.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/shared-state.ts","../src/types/gql-call.ts","../src/types/metadata.ts","../src/utils/canonical-id.ts"],"sourcesContent":[],"mappings":";;;;;;AAQgC,KAA3B,2BAAA,GAC2B;EAC3B,SAAA,IAAA,EAAA,wBAAuB;EAEvB,SAAA,OAAA,EAAA,MAAoB;AAAU,CAAA;AACD,KAJ7B,2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AAA,OAAA,EAAA,MAAA,EAAA,GKA2C,WLA3C"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { BuilderArtifact,
|
|
1
|
+
import { BuilderArtifact, BuilderArtifactFragment, BuilderArtifactOperation, BuilderError } from "@soda-gql/builder";
|
|
2
|
+
import { CanonicalId } from "@soda-gql/common";
|
|
2
3
|
import { ResolvedSodaGqlConfig } from "@soda-gql/config";
|
|
3
4
|
|
|
4
5
|
//#region packages/plugin-common/src/errors.d.ts
|
|
@@ -150,6 +151,7 @@ type PluginOptions = {
|
|
|
150
151
|
type PluginSession = {
|
|
151
152
|
readonly config: ResolvedSodaGqlConfig;
|
|
152
153
|
readonly getArtifact: () => BuilderArtifact | null;
|
|
154
|
+
readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;
|
|
153
155
|
};
|
|
154
156
|
/**
|
|
155
157
|
* Create plugin session by loading config and creating cached builder service.
|
|
@@ -157,48 +159,106 @@ type PluginSession = {
|
|
|
157
159
|
*/
|
|
158
160
|
declare const createPluginSession: (options: PluginOptions, pluginName: string) => PluginSession | null;
|
|
159
161
|
//#endregion
|
|
160
|
-
//#region packages/plugin-common/src/
|
|
162
|
+
//#region packages/plugin-common/src/shared-state.d.ts
|
|
161
163
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
+
* Transformer type for code transformation.
|
|
165
|
+
* - 'babel': Use Babel plugin (default, wider compatibility)
|
|
166
|
+
* - 'swc': Use SWC transformer (faster, requires @soda-gql/swc-transformer)
|
|
164
167
|
*/
|
|
165
|
-
|
|
166
|
-
readonly canonicalId: CanonicalId;
|
|
167
|
-
readonly builderCall: TCallNode;
|
|
168
|
-
}
|
|
168
|
+
type TransformerType = "babel" | "swc";
|
|
169
169
|
/**
|
|
170
|
-
*
|
|
170
|
+
* Minimal interface for SWC transformer.
|
|
171
|
+
* Matches the Transformer interface from @soda-gql/swc-transformer.
|
|
171
172
|
*/
|
|
172
|
-
interface
|
|
173
|
-
|
|
174
|
-
|
|
173
|
+
interface SwcTransformerInterface {
|
|
174
|
+
transform(input: {
|
|
175
|
+
sourceCode: string;
|
|
176
|
+
sourcePath: string;
|
|
177
|
+
inputSourceMap?: string;
|
|
178
|
+
}): {
|
|
179
|
+
transformed: boolean;
|
|
180
|
+
sourceCode: string;
|
|
181
|
+
sourceMap?: string;
|
|
182
|
+
};
|
|
175
183
|
}
|
|
176
184
|
/**
|
|
177
|
-
*
|
|
185
|
+
* Shared state between bundler plugins and loaders.
|
|
186
|
+
* Enables efficient artifact sharing across build pipeline stages.
|
|
187
|
+
*/
|
|
188
|
+
type SharedState = {
|
|
189
|
+
pluginSession: PluginSession | null;
|
|
190
|
+
currentArtifact: BuilderArtifact | null;
|
|
191
|
+
moduleAdjacency: Map<string, Set<string>>;
|
|
192
|
+
generation: number;
|
|
193
|
+
swcTransformer: SwcTransformerInterface | null;
|
|
194
|
+
transformerType: TransformerType | null;
|
|
195
|
+
};
|
|
196
|
+
/**
|
|
197
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
198
|
+
*/
|
|
199
|
+
declare const getSharedState: (key: string) => SharedState;
|
|
200
|
+
/**
|
|
201
|
+
* Update shared artifact.
|
|
178
202
|
*/
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
203
|
+
declare const setSharedArtifact: (key: string, artifact: BuilderArtifact | null, moduleAdjacency?: Map<string, Set<string>>) => void;
|
|
204
|
+
/**
|
|
205
|
+
* Get shared artifact.
|
|
206
|
+
*/
|
|
207
|
+
declare const getSharedArtifact: (key: string) => BuilderArtifact | null;
|
|
208
|
+
/**
|
|
209
|
+
* Get shared plugin session.
|
|
210
|
+
*/
|
|
211
|
+
declare const getSharedPluginSession: (key: string) => PluginSession | null;
|
|
212
|
+
/**
|
|
213
|
+
* Set shared plugin session.
|
|
214
|
+
*/
|
|
215
|
+
declare const setSharedPluginSession: (key: string, session: PluginSession | null) => void;
|
|
216
|
+
/**
|
|
217
|
+
* Get the state key from config path or cwd.
|
|
218
|
+
*/
|
|
219
|
+
declare const getStateKey: (configPath?: string) => string;
|
|
220
|
+
/**
|
|
221
|
+
* Set shared SWC transformer.
|
|
222
|
+
*/
|
|
223
|
+
declare const setSharedSwcTransformer: (key: string, transformer: SwcTransformerInterface | null) => void;
|
|
224
|
+
/**
|
|
225
|
+
* Get shared SWC transformer.
|
|
226
|
+
*/
|
|
227
|
+
declare const getSharedSwcTransformer: (key: string) => SwcTransformerInterface | null;
|
|
228
|
+
/**
|
|
229
|
+
* Set shared transformer type.
|
|
230
|
+
*/
|
|
231
|
+
declare const setSharedTransformerType: (key: string, transformerType: TransformerType | null) => void;
|
|
232
|
+
/**
|
|
233
|
+
* Get shared transformer type.
|
|
234
|
+
*/
|
|
235
|
+
declare const getSharedTransformerType: (key: string) => TransformerType | null;
|
|
236
|
+
//#endregion
|
|
237
|
+
//#region packages/plugin-common/src/types/gql-call.d.ts
|
|
238
|
+
/**
|
|
239
|
+
* Base interface for all GraphQL call types.
|
|
240
|
+
*/
|
|
241
|
+
interface GqlCallBase {
|
|
242
|
+
readonly canonicalId: CanonicalId;
|
|
182
243
|
}
|
|
183
244
|
/**
|
|
184
|
-
* GraphQL
|
|
185
|
-
* Unified naming: "operation" (was "composedOperation" in tsc-plugin).
|
|
245
|
+
* GraphQL fragment call.
|
|
186
246
|
*/
|
|
187
|
-
interface
|
|
188
|
-
readonly type: "
|
|
189
|
-
readonly artifact:
|
|
247
|
+
interface GqlCallFragment extends GqlCallBase {
|
|
248
|
+
readonly type: "fragment";
|
|
249
|
+
readonly artifact: BuilderArtifactFragment;
|
|
190
250
|
}
|
|
191
251
|
/**
|
|
192
|
-
* GraphQL
|
|
252
|
+
* GraphQL operation call.
|
|
193
253
|
*/
|
|
194
|
-
interface
|
|
195
|
-
readonly type: "
|
|
196
|
-
readonly artifact:
|
|
254
|
+
interface GqlCallOperation extends GqlCallBase {
|
|
255
|
+
readonly type: "operation";
|
|
256
|
+
readonly artifact: BuilderArtifactOperation;
|
|
197
257
|
}
|
|
198
258
|
/**
|
|
199
259
|
* Union of all GraphQL call types.
|
|
200
260
|
*/
|
|
201
|
-
type GqlCall
|
|
261
|
+
type GqlCall = GqlCallFragment | GqlCallOperation;
|
|
202
262
|
//#endregion
|
|
203
263
|
//#region packages/plugin-common/src/types/metadata.d.ts
|
|
204
264
|
/**
|
|
@@ -220,5 +280,5 @@ type GqlDefinitionMetadata = {
|
|
|
220
280
|
*/
|
|
221
281
|
declare const resolveCanonicalId: (filename: string, astPath: string) => CanonicalId;
|
|
222
282
|
//#endregion
|
|
223
|
-
export { type GqlCall, type GqlCallBase, type
|
|
283
|
+
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, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getSharedTransformerType, getStateKey, isPluginError, resolveCanonicalId, setSharedArtifact, setSharedPluginSession, setSharedSwcTransformer, setSharedTransformerType };
|
|
224
284
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/types/gql-call.ts","../src/types/metadata.ts","../src/utils/canonical-id.ts"],"sourcesContent":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/errors.ts","../src/plugin-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oB;EAC3B,SAAA,OAAA,EAAA,MAAA;EAEA,SAAA,UAAA,EAAA,OAAoB;EACpB,SAAA,UAAA,EAAA,OAAmB;EACnB,SAAA,aAAA,CAAA,EAAA,MAAyB;AAAU,CAAA;;;;AARY;AAEpB;AAE3B,cKAQ,kBLAe,EAAA,CAAA,QAAA,EAAA,MAAA,EAAA,OAAA,EAAA,MAAA,EAAA,GKA2C,WLA3C"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createBuilderService
|
|
2
|
-
import { cachedFn } from "@soda-gql/common";
|
|
1
|
+
import { createBuilderService } from "@soda-gql/builder";
|
|
2
|
+
import { cachedFn, createCanonicalId } from "@soda-gql/common";
|
|
3
3
|
import { loadConfig } from "@soda-gql/config";
|
|
4
4
|
import { resolve } from "node:path";
|
|
5
5
|
|
|
@@ -57,12 +57,104 @@ const createPluginSession = (options, pluginName) => {
|
|
|
57
57
|
}
|
|
58
58
|
return buildResult.value;
|
|
59
59
|
};
|
|
60
|
+
/**
|
|
61
|
+
* Async version of getArtifact.
|
|
62
|
+
* Supports async metadata factories and parallel element evaluation.
|
|
63
|
+
*/
|
|
64
|
+
const getArtifactAsync = async () => {
|
|
65
|
+
const buildResult = await ensureBuilderService().buildAsync();
|
|
66
|
+
if (buildResult.isErr()) {
|
|
67
|
+
console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return buildResult.value;
|
|
71
|
+
};
|
|
60
72
|
return {
|
|
61
73
|
config,
|
|
62
|
-
getArtifact
|
|
74
|
+
getArtifact,
|
|
75
|
+
getArtifactAsync
|
|
63
76
|
};
|
|
64
77
|
};
|
|
65
78
|
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region packages/plugin-common/src/shared-state.ts
|
|
81
|
+
const sharedStates = /* @__PURE__ */ new Map();
|
|
82
|
+
/**
|
|
83
|
+
* Get shared state for a given project (identified by config path or cwd).
|
|
84
|
+
*/
|
|
85
|
+
const getSharedState = (key) => {
|
|
86
|
+
let state = sharedStates.get(key);
|
|
87
|
+
if (!state) {
|
|
88
|
+
state = {
|
|
89
|
+
pluginSession: null,
|
|
90
|
+
currentArtifact: null,
|
|
91
|
+
moduleAdjacency: /* @__PURE__ */ new Map(),
|
|
92
|
+
generation: 0,
|
|
93
|
+
swcTransformer: null,
|
|
94
|
+
transformerType: null
|
|
95
|
+
};
|
|
96
|
+
sharedStates.set(key, state);
|
|
97
|
+
}
|
|
98
|
+
return state;
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* Update shared artifact.
|
|
102
|
+
*/
|
|
103
|
+
const setSharedArtifact = (key, artifact, moduleAdjacency) => {
|
|
104
|
+
const state = getSharedState(key);
|
|
105
|
+
state.currentArtifact = artifact;
|
|
106
|
+
if (moduleAdjacency) state.moduleAdjacency = moduleAdjacency;
|
|
107
|
+
state.generation++;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* Get shared artifact.
|
|
111
|
+
*/
|
|
112
|
+
const getSharedArtifact = (key) => {
|
|
113
|
+
return getSharedState(key).currentArtifact;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Get shared plugin session.
|
|
117
|
+
*/
|
|
118
|
+
const getSharedPluginSession = (key) => {
|
|
119
|
+
return getSharedState(key).pluginSession;
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Set shared plugin session.
|
|
123
|
+
*/
|
|
124
|
+
const setSharedPluginSession = (key, session) => {
|
|
125
|
+
getSharedState(key).pluginSession = session;
|
|
126
|
+
};
|
|
127
|
+
/**
|
|
128
|
+
* Get the state key from config path or cwd.
|
|
129
|
+
*/
|
|
130
|
+
const getStateKey = (configPath) => {
|
|
131
|
+
return configPath ?? process.cwd();
|
|
132
|
+
};
|
|
133
|
+
/**
|
|
134
|
+
* Set shared SWC transformer.
|
|
135
|
+
*/
|
|
136
|
+
const setSharedSwcTransformer = (key, transformer) => {
|
|
137
|
+
getSharedState(key).swcTransformer = transformer;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Get shared SWC transformer.
|
|
141
|
+
*/
|
|
142
|
+
const getSharedSwcTransformer = (key) => {
|
|
143
|
+
return getSharedState(key).swcTransformer;
|
|
144
|
+
};
|
|
145
|
+
/**
|
|
146
|
+
* Set shared transformer type.
|
|
147
|
+
*/
|
|
148
|
+
const setSharedTransformerType = (key, transformerType) => {
|
|
149
|
+
getSharedState(key).transformerType = transformerType;
|
|
150
|
+
};
|
|
151
|
+
/**
|
|
152
|
+
* Get shared transformer type.
|
|
153
|
+
*/
|
|
154
|
+
const getSharedTransformerType = (key) => {
|
|
155
|
+
return getSharedState(key).transformerType;
|
|
156
|
+
};
|
|
157
|
+
|
|
66
158
|
//#endregion
|
|
67
159
|
//#region packages/plugin-common/src/utils/canonical-id.ts
|
|
68
160
|
/**
|
|
@@ -74,5 +166,5 @@ const createPluginSession = (options, pluginName) => {
|
|
|
74
166
|
const resolveCanonicalId = (filename, astPath) => createCanonicalId(resolve(filename), astPath);
|
|
75
167
|
|
|
76
168
|
//#endregion
|
|
77
|
-
export { assertUnreachable, createPluginSession, formatPluginError, isPluginError, resolveCanonicalId };
|
|
169
|
+
export { assertUnreachable, createPluginSession, formatPluginError, getSharedArtifact, getSharedPluginSession, getSharedState, getSharedSwcTransformer, getSharedTransformerType, getStateKey, isPluginError, resolveCanonicalId, setSharedArtifact, setSharedPluginSession, setSharedSwcTransformer, setSharedTransformerType };
|
|
78
170
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/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 { BuilderError, CanonicalId } from \"@soda-gql/builder\";\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","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { cachedFn } from \"@soda-gql/common\";\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: 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};\n\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n console.error(`[${pluginName}] Failed to load config:`, {\n code: configResult.error.code,\n message: configResult.error.message,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n return null;\n }\n\n const config = configResult.value;\n const ensureBuilderService = cachedFn(() => createBuilderService({ config }));\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * If artifact.useBuilder is false and artifact.path is provided, load from file instead.\n * This ensures the artifact is always up-to-date with the latest source files.\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n };\n};\n","/**\n * Utility for working with canonical IDs.\n */\n\nimport { resolve } from \"node:path\";\nimport { type CanonicalId, createCanonicalId } from \"@soda-gql/builder\";\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":";;;;;;;;;AAoIA,MAAa,qBAAqB,UAA+B;AAG/D,QAAO,GAFY,IAAI,MAAM,KAAK,KAChB,WAAW,QAAQ,KAAK,MAAM,MAAM,KAAK,GAC1B,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;;;;;;;;;AC/H1H,MAAa,uBAAuB,SAAwB,eAA6C;AAEvG,KAAI,EADY,QAAQ,WAAW,MAEjC,QAAO;CAGT,MAAM,eAAe,WAAW,QAAQ,WAAW;AACnD,KAAI,aAAa,OAAO,EAAE;AACxB,UAAQ,MAAM,IAAI,WAAW,2BAA2B;GACtD,MAAM,aAAa,MAAM;GACzB,SAAS,aAAa,MAAM;GAC5B,UAAU,aAAa,MAAM;GAC7B,OAAO,aAAa,MAAM;GAC3B,CAAC;AACF,SAAO;;CAGT,MAAM,SAAS,aAAa;CAC5B,MAAM,uBAAuB,eAAe,qBAAqB,EAAE,QAAQ,CAAC,CAAC;;;;;;CAO7E,MAAM,oBAA4C;EAEhD,MAAM,cADiB,sBAAsB,CACV,OAAO;AAC1C,MAAI,YAAY,OAAO,EAAE;AACvB,WAAQ,MAAM,IAAI,WAAW,8BAA8B,YAAY,MAAM,UAAU;AACvF,UAAO;;AAET,SAAO,YAAY;;AAGrB,QAAO;EACL;EACA;EACD;;;;;;;;;;;AC1DH,MAAa,sBAAsB,UAAkB,YACnD,kBAAkB,QAAQ,SAAS,EAAE,QAAQ"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/errors.ts","../src/plugin-session.ts","../src/shared-state.ts","../src/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 { BuilderError } from \"@soda-gql/builder\";\nimport type { CanonicalId } from \"@soda-gql/common\";\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","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createBuilderService } from \"@soda-gql/builder\";\nimport { cachedFn } from \"@soda-gql/common\";\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: 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\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n console.error(`[${pluginName}] Failed to load config:`, {\n code: configResult.error.code,\n message: configResult.error.message,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n return null;\n }\n\n const config = configResult.value;\n const ensureBuilderService = cachedFn(() => createBuilderService({ config }));\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * If artifact.useBuilder is false and artifact.path is provided, load from file instead.\n * This ensures the artifact is always up-to-date with the latest source files.\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);\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 const getArtifactAsync = async (): Promise<BuilderArtifact | null> => {\n const builderService = ensureBuilderService();\n const buildResult = await builderService.buildAsync();\n if (buildResult.isErr()) {\n console.error(`[${pluginName}] Failed to build artifact: ${buildResult.error.message}`);\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n getArtifactAsync,\n };\n};\n","import type { BuilderArtifact } from \"@soda-gql/builder\";\nimport type { PluginSession } from \"./plugin-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-transformer)\n */\nexport type TransformerType = \"babel\" | \"swc\";\n\n/**\n * Minimal interface for SWC transformer.\n * Matches the Transformer interface from @soda-gql/swc-transformer.\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};\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 };\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 * 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;AAG/D,QAAO,GAFY,IAAI,MAAM,KAAK,KAChB,WAAW,QAAQ,KAAK,MAAM,MAAM,KAAK,GAC1B,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;;;;;;;;;AC/H1H,MAAa,uBAAuB,SAAwB,eAA6C;AAEvG,KAAI,EADY,QAAQ,WAAW,MAEjC,QAAO;CAGT,MAAM,eAAe,WAAW,QAAQ,WAAW;AACnD,KAAI,aAAa,OAAO,EAAE;AACxB,UAAQ,MAAM,IAAI,WA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,gBAAe,IAAI,CAAC,gBAAgB;;;;;AAMtC,MAAa,eAAe,eAAgC;AAC1D,QAAO,cAAc,QAAQ,KAAK;;;;;AAMpC,MAAa,2BAA2B,KAAa,gBAAsD;AACzG,gBAAe,IAAI,CAAC,iBAAiB;;;;;AAMvC,MAAa,2BAA2B,QAAgD;AACtF,QAAO,eAAe,IAAI,CAAC;;;;;AAM7B,MAAa,4BAA4B,KAAa,oBAAkD;AACtG,gBAAe,IAAI,CAAC,kBAAkB;;;;;AAMxC,MAAa,4BAA4B,QAAwC;AAC/E,QAAO,eAAe,IAAI,CAAC;;;;;;;;;;;ACpH7B,MAAa,sBAAsB,UAAkB,YACnD,kBAAkB,QAAQ,SAAS,EAAE,QAAQ"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/plugin-common",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Shared utilities for soda-gql build plugins",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"private": false,
|
|
6
7
|
"license": "MIT",
|
|
@@ -12,12 +13,31 @@
|
|
|
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
|
+
"plugin"
|
|
22
|
+
],
|
|
23
|
+
"repository": {
|
|
24
|
+
"type": "git",
|
|
25
|
+
"url": "https://github.com/whatasoda/soda-gql.git",
|
|
26
|
+
"directory": "packages/plugin-common"
|
|
27
|
+
},
|
|
28
|
+
"homepage": "https://github.com/whatasoda/soda-gql#readme",
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/whatasoda/soda-gql/issues"
|
|
31
|
+
},
|
|
32
|
+
"engines": {
|
|
33
|
+
"node": ">=18"
|
|
34
|
+
},
|
|
15
35
|
"main": "./dist/index.mjs",
|
|
16
36
|
"module": "./dist/index.mjs",
|
|
17
37
|
"types": "./dist/index.d.mts",
|
|
18
38
|
"exports": {
|
|
19
39
|
".": {
|
|
20
|
-
"@soda-gql": "
|
|
40
|
+
"@soda-gql": "./@x-index.ts",
|
|
21
41
|
"types": "./dist/index.d.mts",
|
|
22
42
|
"import": "./dist/index.mjs",
|
|
23
43
|
"require": "./dist/index.cjs",
|
|
@@ -26,9 +46,9 @@
|
|
|
26
46
|
"./package.json": "./package.json"
|
|
27
47
|
},
|
|
28
48
|
"dependencies": {
|
|
29
|
-
"@soda-gql/builder": "0.0
|
|
30
|
-
"@soda-gql/common": "0.0
|
|
31
|
-
"@soda-gql/config": "0.0
|
|
49
|
+
"@soda-gql/builder": "0.2.0",
|
|
50
|
+
"@soda-gql/common": "0.2.0",
|
|
51
|
+
"@soda-gql/config": "0.2.0",
|
|
32
52
|
"neverthrow": "^8.1.1"
|
|
33
53
|
},
|
|
34
54
|
"devDependencies": {},
|