@soda-gql/babel-plugin 0.1.0 → 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 +11 -14
- package/dist/index.cjs +4 -610
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -580
- package/dist/index.mjs.map +1 -1
- package/package.json +29 -11
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["t","toRemove: NodePath[]","bindings: ExportBindingMap","t","isGqlReference","t","t","types","lastLoader: NodePath<t.Statement> | null","runtimeCalls: t.Expression[]","t"],"sources":["../src/ast/imports.ts","../src/ast/metadata.ts","../src/ast/analysis.ts","../src/ast/ast.ts","../src/ast/runtime.ts","../src/ast/transformer.ts","../src/transformer.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\n\nconst RUNTIME_MODULE = \"@soda-gql/runtime\";\n\n/**\n * Ensure that the gqlRuntime require exists in the program for CJS output.\n * Injects: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n */\nexport const ensureGqlRuntimeRequire = (programPath: NodePath<t.Program>) => {\n // Check if the require already exists\n const existing = programPath.node.body.find(\n (statement): statement is t.VariableDeclaration =>\n t.isVariableDeclaration(statement) &&\n statement.declarations.some((decl) => {\n if (!t.isIdentifier(decl.id) || decl.id.name !== \"__soda_gql_runtime\") {\n return false;\n }\n if (!decl.init || !t.isCallExpression(decl.init)) {\n return false;\n }\n const callExpr = decl.init;\n if (!t.isIdentifier(callExpr.callee) || callExpr.callee.name !== \"require\") {\n return false;\n }\n const arg = callExpr.arguments[0];\n return arg && t.isStringLiteral(arg) && arg.value === RUNTIME_MODULE;\n }),\n );\n\n if (existing) {\n return;\n }\n\n // Create: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n const requireCall = t.callExpression(t.identifier(\"require\"), [t.stringLiteral(RUNTIME_MODULE)]);\n\n const variableDeclaration = t.variableDeclaration(\"const\", [\n t.variableDeclarator(t.identifier(\"__soda_gql_runtime\"), requireCall),\n ]);\n\n // Insert at the beginning of the file\n programPath.node.body.unshift(variableDeclaration);\n};\n\n/**\n * Ensure that the gqlRuntime import exists in the program.\n * gqlRuntime is always imported from @soda-gql/runtime.\n */\nexport const ensureGqlRuntimeImport = (programPath: NodePath<t.Program>) => {\n const existing = programPath.node.body.find(\n (statement) => statement.type === \"ImportDeclaration\" && statement.source.value === RUNTIME_MODULE,\n );\n\n if (existing && t.isImportDeclaration(existing)) {\n const hasSpecifier = existing.specifiers.some(\n (specifier) =>\n specifier.type === \"ImportSpecifier\" &&\n specifier.imported.type === \"Identifier\" &&\n specifier.imported.name === \"gqlRuntime\",\n );\n\n if (!hasSpecifier) {\n existing.specifiers = [...existing.specifiers, t.importSpecifier(t.identifier(\"gqlRuntime\"), t.identifier(\"gqlRuntime\"))];\n }\n\n return;\n }\n\n programPath.node.body.unshift(\n t.importDeclaration(\n [t.importSpecifier(t.identifier(\"gqlRuntime\"), t.identifier(\"gqlRuntime\"))],\n t.stringLiteral(RUNTIME_MODULE),\n ),\n );\n};\n\n/**\n * Remove the graphql-system import (runtimeModule) and gql-related exports from the program.\n * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,\n * so the original graphql-system import should be completely removed.\n *\n * This handles both ESM imports and CommonJS require() statements.\n */\nexport const removeGraphqlSystemImports = (\n programPath: NodePath<t.Program>,\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper,\n filename: string,\n) => {\n // After transformation, all gql usage should be replaced with gqlRuntime\n // So we can safely remove the graphql-system import\n const toRemove: NodePath[] = [];\n\n programPath.traverse({\n // Remove ESM import declarations for the graphql-system\n ImportDeclaration(path) {\n if (t.isStringLiteral(path.node.source)) {\n const isGraphqlSystem = graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: filename,\n specifier: path.node.source.value,\n });\n if (isGraphqlSystem) {\n toRemove.push(path);\n }\n }\n },\n // Remove CommonJS require() statements for the graphql-system\n // - const graphql_system_1 = require(\"../../graphql-system\");\n // - const { gql } = require(\"@/graphql-system\");\n VariableDeclaration(path) {\n const shouldRemove = path.node.declarations.every((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.init);\n if (!specifier) {\n return false;\n }\n\n return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: filename,\n specifier: specifier,\n });\n });\n\n if (shouldRemove) {\n toRemove.push(path);\n }\n },\n });\n\n for (const path of toRemove) {\n path.remove();\n }\n};\n\n/**\n * Check if an expression is a require() call and extract its target specifier.\n * Handles multiple patterns:\n * - require(\"@/graphql-system\")\n * - Object(require(\"@/graphql-system\")) (interop helper pattern)\n */\nconst extractRequireTargetSpecifier = (expr: t.Node | null | undefined): string | undefined => {\n if (!expr) {\n return undefined;\n }\n\n // Direct require(\"@/graphql-system\")\n if (t.isCallExpression(expr)) {\n if (t.isIdentifier(expr.callee) && expr.callee.name === \"require\") {\n const arg = expr.arguments[0];\n if (arg && t.isStringLiteral(arg)) {\n return arg.value;\n }\n }\n\n // Object(require(\"@/graphql-system\")) or similar interop helpers\n if (t.isIdentifier(expr.callee) && (expr.callee.name === \"Object\" || expr.callee.name.startsWith(\"__import\"))) {\n const arg = expr.arguments[0];\n if (arg && t.isCallExpression(arg)) {\n if (t.isIdentifier(arg.callee) && arg.callee.name === \"require\") {\n const requireArg = arg.arguments[0];\n if (requireArg && t.isStringLiteral(requireArg)) {\n return requireArg.value;\n }\n }\n }\n }\n }\n\n return undefined;\n};\n","import { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport { type CanonicalPathTracker, createCanonicalTracker } from \"@soda-gql/builder\";\nimport type { GqlDefinitionMetadata } from \"@soda-gql/plugin-common\";\n\nexport type GqlDefinitionMetadataMap = WeakMap<t.CallExpression, GqlDefinitionMetadata>;\n\ntype CanonicalTrackerFactory = typeof createCanonicalTracker;\n\ntype CollectArgs = {\n readonly programPath: NodePath<t.Program>;\n readonly filename: string;\n readonly createTracker?: CanonicalTrackerFactory;\n};\n\ntype ScopeHandle = ReturnType<CanonicalPathTracker[\"enterScope\"]>;\ntype ExportBindingMap = Map<string, string>;\n\nexport const collectGqlDefinitionMetadata = ({ programPath, filename, createTracker }: CollectArgs): GqlDefinitionMetadataMap => {\n const exportBindings = collectExportBindings(programPath.node);\n const trackerFactory = createTracker ?? createCanonicalTracker;\n const tracker = trackerFactory({\n filePath: filename,\n getExportName: (localName) => exportBindings.get(localName),\n });\n\n const getAnonymousName = createAnonymousNameFactory();\n const scopeHandles = new WeakMap<NodePath<t.Node>, ScopeHandle>();\n const metadata = new WeakMap<t.CallExpression, GqlDefinitionMetadata>();\n\n programPath.traverse({\n enter(path) {\n if (path.isCallExpression() && isGqlDefinitionCall(path.node)) {\n const depthBeforeRegister = tracker.currentDepth();\n const { astPath } = tracker.registerDefinition();\n const isTopLevel = depthBeforeRegister <= 1;\n const exportInfo = isTopLevel ? resolveTopLevelExport(path, exportBindings) : null;\n\n metadata.set(path.node, {\n astPath,\n isTopLevel,\n isExported: exportInfo?.isExported ?? false,\n exportBinding: exportInfo?.exportBinding,\n });\n\n path.skip();\n return;\n }\n\n const handle = maybeEnterScope(path, tracker, getAnonymousName);\n if (handle) {\n scopeHandles.set(path, handle);\n }\n },\n exit(path) {\n const handle = scopeHandles.get(path);\n if (handle) {\n tracker.exitScope(handle);\n scopeHandles.delete(path);\n }\n },\n });\n\n return metadata;\n};\n\nconst collectExportBindings = (program: t.Program): ExportBindingMap => {\n const bindings: ExportBindingMap = new Map();\n\n for (const statement of program.body) {\n // ESM exports: export const foo = ...\n if (t.isExportNamedDeclaration(statement) && statement.declaration) {\n const { declaration } = statement;\n if (t.isVariableDeclaration(declaration)) {\n for (const declarator of declaration.declarations) {\n if (t.isIdentifier(declarator.id)) {\n bindings.set(declarator.id.name, declarator.id.name);\n }\n }\n continue;\n }\n\n if ((t.isFunctionDeclaration(declaration) || t.isClassDeclaration(declaration)) && declaration.id) {\n bindings.set(declaration.id.name, declaration.id.name);\n }\n continue;\n }\n\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (t.isExpressionStatement(statement) && t.isAssignmentExpression(statement.expression)) {\n const exportName = getCommonJsExportName(statement.expression.left);\n if (exportName) {\n bindings.set(exportName, exportName);\n }\n }\n }\n\n return bindings;\n};\n\nconst getCommonJsExportName = (node: t.LVal | t.OptionalMemberExpression): string | null => {\n if (!t.isMemberExpression(node) || node.computed) {\n return null;\n }\n\n // Check if it's exports.foo or module.exports.foo\n const isExports = t.isIdentifier(node.object, { name: \"exports\" });\n const isModuleExports =\n t.isMemberExpression(node.object) &&\n t.isIdentifier(node.object.object, { name: \"module\" }) &&\n t.isIdentifier(node.object.property, { name: \"exports\" });\n\n if (!isExports && !isModuleExports) {\n return null;\n }\n\n // Extract property name\n if (t.isIdentifier(node.property)) {\n return node.property.name;\n }\n if (t.isStringLiteral(node.property)) {\n return node.property.value;\n }\n\n return null;\n};\n\nconst createAnonymousNameFactory = (): ((kind: string) => string) => {\n const counters = new Map<string, number>();\n return (kind) => {\n const count = counters.get(kind) ?? 0;\n counters.set(kind, count + 1);\n return `${kind}#${count}`;\n };\n};\n\nconst isGqlDefinitionCall = (node: t.Node): node is t.CallExpression =>\n t.isCallExpression(node) &&\n t.isMemberExpression(node.callee) &&\n isGqlReference(node.callee.object) &&\n node.arguments.length > 0 &&\n t.isArrowFunctionExpression(node.arguments[0]);\n\nconst isGqlReference = (expr: t.Expression | t.Super): boolean => {\n if (t.isIdentifier(expr, { name: \"gql\" })) {\n return true;\n }\n if (!t.isMemberExpression(expr) || expr.computed) {\n return false;\n }\n if (\n (t.isIdentifier(expr.property) && expr.property.name === \"gql\") ||\n (t.isStringLiteral(expr.property) && expr.property.value === \"gql\")\n ) {\n return true;\n }\n return isGqlReference(expr.object);\n};\n\nconst resolveTopLevelExport = (\n callPath: NodePath<t.CallExpression>,\n exportBindings: ExportBindingMap,\n): { readonly isExported: true; readonly exportBinding: string } | null => {\n // ESM: const foo = gql.default(...); export { foo };\n const declarator = callPath.parentPath;\n if (declarator?.isVariableDeclarator()) {\n const { id } = declarator.node;\n if (t.isIdentifier(id)) {\n const exportBinding = exportBindings.get(id.name);\n if (exportBinding) {\n return { isExported: true, exportBinding };\n }\n }\n }\n\n // CommonJS: exports.foo = gql.default(...);\n const assignment = callPath.parentPath;\n if (assignment?.isAssignmentExpression()) {\n const exportName = getCommonJsExportName(assignment.node.left);\n if (exportName && exportBindings.has(exportName)) {\n return { isExported: true, exportBinding: exportName };\n }\n }\n\n return null;\n};\n\nconst maybeEnterScope = (\n path: NodePath<t.Node>,\n tracker: CanonicalPathTracker,\n getAnonymousName: (kind: string) => string,\n): ScopeHandle | null => {\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (path.isAssignmentExpression()) {\n const exportName = getCommonJsExportName(path.node.left);\n if (exportName) {\n return tracker.enterScope({ segment: exportName, kind: \"variable\", stableKey: `var:${exportName}` });\n }\n }\n\n if (path.isVariableDeclarator() && t.isIdentifier(path.node.id)) {\n const name = path.node.id.name;\n return tracker.enterScope({ segment: name, kind: \"variable\", stableKey: `var:${name}` });\n }\n\n if (path.isArrowFunctionExpression()) {\n const name = getAnonymousName(\"arrow\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: \"arrow\" });\n }\n\n if (path.isFunctionDeclaration() || path.isFunctionExpression()) {\n const explicitName = path.node.id?.name;\n const name = explicitName ?? getAnonymousName(\"function\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: `func:${name}` });\n }\n\n if (path.isClassDeclaration()) {\n const explicitName = path.node.id?.name;\n const name = explicitName ?? getAnonymousName(\"class\");\n return tracker.enterScope({ segment: name, kind: \"class\", stableKey: `class:${name}` });\n }\n\n if (path.isClassMethod() && t.isIdentifier(path.node.key)) {\n const name = path.node.key.name;\n return tracker.enterScope({ segment: name, kind: \"method\", stableKey: `member:${name}` });\n }\n\n if (path.isClassProperty() && t.isIdentifier(path.node.key)) {\n const name = path.node.key.name;\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `member:${name}` });\n }\n\n if (path.isObjectProperty()) {\n const key = path.node.key;\n const name = t.isIdentifier(key) ? key.name : t.isStringLiteral(key) ? key.value : null;\n if (name) {\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `prop:${name}` });\n }\n }\n\n return null;\n};\n","import { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport type { BuilderArtifactElement, CanonicalId } from \"@soda-gql/builder\";\nimport type {\n GqlCallInlineOperation,\n GqlCallModel,\n GqlCallOperation,\n GqlCallSlice,\n PluginAnalysisArtifactMissingError,\n PluginAnalysisMetadataMissingError,\n PluginAnalysisUnsupportedArtifactTypeError,\n PluginError,\n} from \"@soda-gql/plugin-common\";\nimport { resolveCanonicalId } from \"@soda-gql/plugin-common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\n\nexport type ArtifactLookup = (canonicalId: CanonicalId) => BuilderArtifactElement | undefined;\n\n// Babel-specific GqlCall types\nexport type BabelGqlCallModel = GqlCallModel<t.CallExpression> & { readonly nodePath: NodePath<t.CallExpression> };\nexport type BabelGqlCallSlice = GqlCallSlice<t.CallExpression> & { readonly nodePath: NodePath<t.CallExpression> };\nexport type BabelGqlCallOperation = GqlCallOperation<t.CallExpression> & { readonly nodePath: NodePath<t.CallExpression> };\nexport type BabelGqlCallInlineOperation = GqlCallInlineOperation<t.CallExpression> & {\n readonly nodePath: NodePath<t.CallExpression>;\n};\n\nexport type BabelGqlCall = BabelGqlCallModel | BabelGqlCallSlice | BabelGqlCallOperation | BabelGqlCallInlineOperation;\n\nexport type ExtractGqlCallArgs = {\n readonly nodePath: NodePath<t.CallExpression>;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly builderCall: t.CallExpression;\n readonly getArtifact: ArtifactLookup;\n};\n\nexport const extractGqlCall = ({\n nodePath,\n filename,\n metadata,\n builderCall,\n getArtifact,\n}: ExtractGqlCallArgs): Result<BabelGqlCall, PluginError> => {\n const callExpression = nodePath.node;\n\n const meta = metadata.get(callExpression);\n if (!meta) {\n return err(createMetadataMissingError({ filename }));\n }\n\n const canonicalId = resolveCanonicalId(filename, meta.astPath);\n const artifact = getArtifact(canonicalId);\n\n if (!artifact) {\n return err(createArtifactMissingError({ filename, canonicalId }));\n }\n\n if (artifact.type === \"model\") {\n return ok({ nodePath, canonicalId, builderCall, type: \"model\", artifact });\n }\n\n if (artifact.type === \"slice\") {\n return ok({ nodePath, canonicalId, builderCall, type: \"slice\", artifact });\n }\n\n if (artifact.type === \"operation\") {\n return ok({ nodePath, canonicalId, builderCall, type: \"operation\", artifact });\n }\n\n if (artifact.type === \"inlineOperation\") {\n return ok({ nodePath, canonicalId, builderCall, type: \"inlineOperation\", artifact });\n }\n\n return err(\n createUnsupportedArtifactTypeError({\n filename,\n canonicalId,\n artifactType: (artifact as { type: string }).type,\n }),\n );\n};\n\ntype MetadataErrorInput = { readonly filename: string };\ntype ArtifactMissingErrorInput = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype UnsupportedArtifactTypeInput = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\nconst createMetadataMissingError = ({ filename }: MetadataErrorInput): PluginAnalysisMetadataMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_METADATA_NOT_FOUND\",\n message: `No GraphQL metadata found for ${filename}`,\n cause: { filename },\n filename,\n});\n\nconst createArtifactMissingError = ({\n filename,\n canonicalId,\n}: ArtifactMissingErrorInput): PluginAnalysisArtifactMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n message: `No builder artifact found for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId },\n filename,\n canonicalId,\n});\n\nconst createUnsupportedArtifactTypeError = ({\n filename,\n canonicalId,\n artifactType,\n}: UnsupportedArtifactTypeInput): PluginAnalysisUnsupportedArtifactTypeError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n message: `Unsupported builder artifact type \"${artifactType}\" for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId, artifactType },\n filename,\n canonicalId,\n artifactType,\n});\n\nexport const findGqlBuilderCall = (callPath: NodePath<t.CallExpression>): t.CallExpression | null =>\n resolveBuilderCall(callPath.node);\n\nconst resolveBuilderCall = (call: t.CallExpression): t.CallExpression | null => {\n if (!isGqlMemberExpression(call.callee)) {\n return null;\n }\n\n if (call.arguments.length !== 1) {\n return null;\n }\n\n const factoryArg = call.arguments[0];\n if (!t.isArrowFunctionExpression(factoryArg)) {\n return null;\n }\n\n return extractBuilderCall(factoryArg);\n};\n\nconst isGqlMemberExpression = (callee: t.Expression | t.V8IntrinsicIdentifier): callee is t.MemberExpression => {\n return t.isMemberExpression(callee) && isSimpleProperty(callee.property) && isGqlReference(callee.object);\n};\n\nconst isSimpleProperty = (property: t.Expression | t.PrivateName): property is t.Identifier | t.StringLiteral =>\n t.isIdentifier(property) || (t.isStringLiteral(property) && property.value.length > 0);\n\nconst isGqlReference = (expr: t.Expression | t.Super): boolean => {\n if (t.isIdentifier(expr, { name: \"gql\" })) {\n return true;\n }\n if (!t.isMemberExpression(expr) || expr.computed) {\n return false;\n }\n if (\n (t.isIdentifier(expr.property) && expr.property.name === \"gql\") ||\n (t.isStringLiteral(expr.property) && expr.property.value === \"gql\")\n ) {\n return true;\n }\n return isGqlReference(expr.object);\n};\n\nconst extractBuilderCall = (factory: t.ArrowFunctionExpression): t.CallExpression | null => {\n if (t.isCallExpression(factory.body)) {\n return factory.body;\n }\n\n if (!t.isBlockStatement(factory.body)) {\n return null;\n }\n\n for (const statement of factory.body.body) {\n if (t.isReturnStatement(statement) && statement.argument && t.isCallExpression(statement.argument)) {\n return statement.argument;\n }\n }\n\n return null;\n};\n","import type { Expression } from \"@babel/types\";\nimport * as t from \"@babel/types\";\nimport type { PluginError, PluginTransformUnsupportedValueTypeError } from \"@soda-gql/plugin-common\";\nimport { err, ok, type Result } from \"neverthrow\";\n\nconst createUnsupportedValueTypeError = (valueType: string): PluginTransformUnsupportedValueTypeError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n message: `Unsupported value type: ${valueType}`,\n cause: { valueType },\n valueType,\n});\n\nexport const buildLiteralFromValue = (value: unknown): Result<Expression, PluginError> => {\n if (value === null) {\n return ok(t.nullLiteral());\n }\n if (typeof value === \"string\") {\n return ok(t.stringLiteral(value));\n }\n if (typeof value === \"number\") {\n return ok(t.numericLiteral(value));\n }\n if (typeof value === \"boolean\") {\n return ok(t.booleanLiteral(value));\n }\n if (Array.isArray(value)) {\n const elements: Expression[] = [];\n for (const item of value) {\n const result = buildLiteralFromValue(item);\n if (result.isErr()) {\n return result;\n }\n elements.push(result.value);\n }\n return ok(t.arrayExpression(elements));\n }\n if (typeof value === \"object\") {\n const properties: t.ObjectProperty[] = [];\n for (const [key, val] of Object.entries(value)) {\n const result = buildLiteralFromValue(val);\n if (result.isErr()) {\n return result;\n }\n properties.push(t.objectProperty(t.identifier(key), result.value));\n }\n return ok(t.objectExpression(properties));\n }\n return err(createUnsupportedValueTypeError(typeof value));\n};\n\nexport const clone = <T extends t.Node>(node: T): T => t.cloneNode(node, true) as T;\n\nexport const cloneCallExpression = (node: t.CallExpression): t.CallExpression =>\n t.callExpression(clone(node.callee), node.arguments.map(clone));\n\nexport const stripTypeAnnotations = (node: t.Node): void => {\n if (\"typeParameters\" in node) {\n delete node.typeParameters;\n }\n if (\"typeAnnotation\" in node) {\n delete node.typeAnnotation;\n }\n if (\"returnType\" in node) {\n delete node.returnType;\n }\n};\n\nexport const buildObjectExpression = <K extends string>(\n properties: Record<K, t.Expression | t.PatternLike>,\n): t.ObjectExpression =>\n t.objectExpression(\n Object.entries<t.Expression | t.PatternLike>(properties).map(([key, value]) => t.objectProperty(t.identifier(key), value)),\n );\n","import { types as t } from \"@babel/core\";\nimport type { RuntimeComposedOperationInput, RuntimeModelInput, RuntimeSliceInput } from \"@soda-gql/core/runtime\";\nimport type { PluginError, PluginTransformMissingBuilderArgError } from \"@soda-gql/plugin-common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type { BabelGqlCallInlineOperation, BabelGqlCallModel, BabelGqlCallOperation, BabelGqlCallSlice } from \"./analysis\";\nimport { buildObjectExpression, clone } from \"./ast\";\n\nconst createMissingBuilderArgError = ({\n filename,\n builderType,\n argName,\n}: {\n filename: string;\n builderType: string;\n argName: string;\n}): PluginTransformMissingBuilderArgError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_MISSING_BUILDER_ARG\",\n message: `${builderType} requires a ${argName} argument`,\n cause: { filename, builderType, argName },\n filename,\n builderType,\n argName,\n});\n\nexport const buildModelRuntimeCall = ({\n artifact,\n builderCall,\n filename,\n}: BabelGqlCallModel & { filename: string }): Result<t.Expression, PluginError> => {\n const [, , normalize] = builderCall.arguments;\n if (!normalize || !t.isExpression(normalize)) {\n return err(createMissingBuilderArgError({ filename, builderType: \"model\", argName: \"normalize\" }));\n }\n\n return ok(\n t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"model\")), [\n buildObjectExpression({\n prebuild: buildObjectExpression<keyof RuntimeModelInput[\"prebuild\"]>({\n typename: t.stringLiteral(artifact.prebuild.typename),\n }),\n runtime: buildObjectExpression<keyof RuntimeModelInput[\"runtime\"]>({\n normalize: clone(normalize),\n }),\n }),\n ]),\n );\n};\n\nexport const buildSliceRuntimeCall = ({\n artifact,\n builderCall,\n filename,\n}: BabelGqlCallSlice & { filename: string }): Result<t.Expression, PluginError> => {\n const [, , projectionBuilder] = builderCall.arguments;\n if (!projectionBuilder || !t.isExpression(projectionBuilder)) {\n return err(createMissingBuilderArgError({ filename, builderType: \"slice\", argName: \"projectionBuilder\" }));\n }\n\n return ok(\n t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"slice\")), [\n buildObjectExpression({\n prebuild: buildObjectExpression<keyof RuntimeSliceInput[\"prebuild\"]>({\n operationType: t.stringLiteral(artifact.prebuild.operationType),\n }),\n runtime: buildObjectExpression<keyof RuntimeSliceInput[\"runtime\"]>({\n buildProjection: clone(projectionBuilder),\n }),\n }),\n ]),\n );\n};\n\nexport const buildComposedOperationRuntimeComponents = ({\n artifact,\n builderCall,\n filename,\n}: BabelGqlCallOperation & { filename: string }): Result<\n { referenceCall: t.Expression; runtimeCall: t.Expression },\n PluginError\n> => {\n const [, slicesBuilder] = builderCall.arguments;\n if (!slicesBuilder || !t.isExpression(slicesBuilder)) {\n return err(createMissingBuilderArgError({ filename, builderType: \"composed operation\", argName: \"slicesBuilder\" }));\n }\n\n const runtimeCall = t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"composedOperation\")), [\n buildObjectExpression({\n prebuild: t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(artifact.prebuild)),\n ]),\n runtime: buildObjectExpression<keyof RuntimeComposedOperationInput[\"runtime\"]>({\n getSlices: clone(slicesBuilder),\n }),\n }),\n ]);\n\n const referenceCall = t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"getComposedOperation\")), [\n t.stringLiteral(artifact.prebuild.operationName),\n ]);\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n\nexport const buildInlineOperationRuntimeComponents = ({\n artifact,\n}: BabelGqlCallInlineOperation & { filename: string }): Result<\n { referenceCall: t.Expression; runtimeCall: t.Expression },\n PluginError\n> => {\n const runtimeCall = t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"inlineOperation\")), [\n buildObjectExpression({\n prebuild: t.callExpression(t.memberExpression(t.identifier(\"JSON\"), t.identifier(\"parse\")), [\n t.stringLiteral(JSON.stringify(artifact.prebuild)),\n ]),\n runtime: buildObjectExpression({}),\n }),\n ]);\n\n const referenceCall = t.callExpression(t.memberExpression(t.identifier(\"gqlRuntime\"), t.identifier(\"getInlineOperation\")), [\n t.stringLiteral(artifact.prebuild.operationName),\n ]);\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n","import type { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport type { PluginError } from \"@soda-gql/plugin-common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type { ArtifactLookup, BabelGqlCall } from \"./analysis\";\nimport { extractGqlCall, findGqlBuilderCall } from \"./analysis\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\nimport {\n buildComposedOperationRuntimeComponents,\n buildInlineOperationRuntimeComponents,\n buildModelRuntimeCall,\n buildSliceRuntimeCall,\n} from \"./runtime\";\n\ntype TransformCallExpressionArgs = {\n readonly callPath: NodePath<t.CallExpression>;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n};\n\ntype TransformCallExpressionResult =\n | { readonly transformed: false }\n | { readonly transformed: true; readonly runtimeCall?: t.Expression };\n\nexport const transformCallExpression = ({\n callPath,\n filename,\n metadata,\n getArtifact,\n}: TransformCallExpressionArgs): Result<TransformCallExpressionResult, PluginError> => {\n const builderCall = findGqlBuilderCall(callPath);\n if (!builderCall) {\n return ok({ transformed: false });\n }\n\n const gqlCallResult = extractGqlCall({\n nodePath: callPath,\n filename,\n metadata,\n builderCall,\n getArtifact,\n });\n\n if (gqlCallResult.isErr()) {\n return err(gqlCallResult.error);\n }\n\n const gqlCall = gqlCallResult.value;\n\n return replaceWithRuntimeCall(callPath, gqlCall, filename);\n};\n\nconst replaceWithRuntimeCall = (\n callPath: NodePath<t.CallExpression>,\n gqlCall: BabelGqlCall,\n filename: string,\n): Result<TransformCallExpressionResult, PluginError> => {\n if (gqlCall.type === \"model\") {\n const result = buildModelRuntimeCall({ ...gqlCall, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n callPath.replaceWith(result.value);\n return ok({ transformed: true });\n }\n\n if (gqlCall.type === \"slice\") {\n const result = buildSliceRuntimeCall({ ...gqlCall, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n callPath.replaceWith(result.value);\n return ok({ transformed: true });\n }\n\n if (gqlCall.type === \"operation\") {\n const result = buildComposedOperationRuntimeComponents({ ...gqlCall, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n callPath.replaceWith(referenceCall);\n return ok({ transformed: true, runtimeCall });\n }\n\n if (gqlCall.type === \"inlineOperation\") {\n const result = buildInlineOperationRuntimeComponents({ ...gqlCall, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n callPath.replaceWith(referenceCall);\n return ok({ transformed: true, runtimeCall });\n }\n\n return ok({ transformed: false });\n};\n\nexport const insertRuntimeCalls = (programPath: NodePath<t.Program>, runtimeCalls: readonly t.Expression[]): void => {\n if (runtimeCalls.length === 0) {\n return;\n }\n\n programPath.traverse({\n ImportDeclaration(importDeclPath) {\n if (importDeclPath.node.source.value === \"@soda-gql/runtime\") {\n importDeclPath.insertAfter([...runtimeCalls]);\n }\n },\n });\n};\n","/**\n * Babel implementation of the TransformAdapter interface.\n *\n * This adapter wraps the existing Babel-specific transformation logic\n * for soda-gql zero-runtime transformations.\n */\n\nimport type { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport { createGraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { formatPluginError } from \"@soda-gql/plugin-common\";\nimport { ensureGqlRuntimeImport, removeGraphqlSystemImports } from \"./ast/imports\";\nimport { collectGqlDefinitionMetadata } from \"./ast/metadata\";\nimport { transformCallExpression } from \"./ast/transformer\";\nimport type { TransformPassResult, TransformProgramContext } from \"./types\";\n\n/**\n * Creates a Babel transformer with a single transform() method.\n * This matches the pattern used in the TypeScript plugin.\n */\nexport const createTransformer = ({\n programPath,\n types,\n config,\n}: {\n readonly programPath: NodePath<t.Program>;\n readonly types: typeof t;\n readonly config: ResolvedSodaGqlConfig;\n}) => {\n // Create graphql system identify helper using builder's implementation\n const graphqlSystemIdentifyHelper = createGraphqlSystemIdentifyHelper(config);\n\n /**\n * Check if a node is a require() or __webpack_require__() call.\n */\n const isRequireCall = (node: t.Node): boolean => {\n if (!types.isCallExpression(node)) {\n return false;\n }\n\n const callee = node.callee;\n return types.isIdentifier(callee) && (callee.name === \"require\" || callee.name === \"__webpack_require__\");\n };\n\n /**\n * Find the last statement that loads a module (import or require).\n * Handles both ESM imports and CommonJS require() calls.\n */\n const findLastModuleLoader = (): NodePath<t.Statement> | null => {\n const bodyPaths = programPath.get(\"body\");\n let lastLoader: NodePath<t.Statement> | null = null;\n\n for (const path of bodyPaths) {\n // ESM: import declaration\n if (path.isImportDeclaration()) {\n lastLoader = path;\n continue;\n }\n\n // CommonJS: const foo = require(\"bar\") or const foo = __webpack_require__(123)\n if (path.isVariableDeclaration()) {\n for (const declarator of path.node.declarations) {\n if (declarator.init && isRequireCall(declarator.init)) {\n lastLoader = path;\n break;\n }\n }\n continue;\n }\n\n // CommonJS: require(\"bar\") or __webpack_require__(123) as standalone expression\n if (path.isExpressionStatement()) {\n if (isRequireCall(path.node.expression)) {\n lastLoader = path;\n }\n }\n }\n\n return lastLoader;\n };\n\n return {\n transform: (context: TransformProgramContext): TransformPassResult => {\n const metadata = collectGqlDefinitionMetadata({\n programPath,\n filename: context.filename,\n });\n\n const runtimeCalls: t.Expression[] = [];\n let transformed = false;\n\n // Transform all gql call expressions\n programPath.traverse({\n CallExpression: (callPath) => {\n const result = transformCallExpression({\n callPath,\n filename: context.filename,\n metadata,\n getArtifact: context.artifactLookup,\n });\n\n if (result.isErr()) {\n // Log error and continue - don't fail the entire build for a single error\n console.error(`[@soda-gql/babel-plugin] ${formatPluginError(result.error)}`);\n return;\n }\n\n const transformResult = result.value;\n if (transformResult.transformed) {\n transformed = true;\n\n if (transformResult.runtimeCall) {\n runtimeCalls.push(transformResult.runtimeCall);\n }\n }\n },\n });\n\n if (!transformed) {\n return { transformed: false, runtimeArtifacts: undefined };\n }\n\n // Ensure runtime import\n ensureGqlRuntimeImport(programPath);\n\n // Insert runtime side effects immediately if any\n if (runtimeCalls.length > 0) {\n const statements = runtimeCalls.map((expr) => types.expressionStatement(expr));\n const lastLoaderPath = findLastModuleLoader();\n\n if (lastLoaderPath) {\n lastLoaderPath.insertAfter(statements);\n } else {\n programPath.unshiftContainer(\"body\", statements);\n }\n }\n\n // Clean up: remove graphql system imports and recrawl scope\n programPath.scope.crawl();\n removeGraphqlSystemImports(programPath, graphqlSystemIdentifyHelper, context.filename);\n\n return {\n transformed: true,\n runtimeArtifacts: undefined,\n };\n },\n };\n};\n","import type { PluginObj, PluginPass } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport type { BuilderArtifact, CanonicalId } from \"@soda-gql/builder\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { createPluginSession, type PluginOptions, type PluginSession } from \"@soda-gql/plugin-common\";\nimport { createTransformer } from \"./transformer\";\n\ntype PluginPassState = PluginPass & {\n _artifact?: BuilderArtifact | null;\n};\n\nconst fallbackPlugin = (): PluginObj => ({\n name: \"@soda-gql/babel-plugin\",\n visitor: {\n Program() {\n // No-op fallback\n },\n },\n});\n\nexport const createPlugin = ({ pluginSession }: { pluginSession: PluginSession }): PluginObj<PluginPassState> => ({\n name: \"@soda-gql/babel-plugin\",\n\n async pre() {\n this._artifact = await pluginSession.getArtifactAsync();\n },\n\n visitor: {\n Program(programPath: NodePath<t.Program>, state) {\n const filename = state.file?.opts?.filename;\n if (!filename) {\n return;\n }\n\n const artifact = state._artifact;\n if (!artifact) {\n return;\n }\n\n // Create Babel transformer instance\n const transformer = createTransformer({\n programPath,\n types: t,\n config: pluginSession.config,\n });\n\n // Transform using single method call (matches TypeScript plugin pattern)\n transformer.transform({\n filename,\n artifactLookup: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n });\n },\n },\n});\n\nexport const createSodaGqlPlugin = (_babel: unknown, options: PluginOptions = {}): PluginObj => {\n // Create plugin session synchronously (no async pre())\n const pluginSession = createPluginSession(options, \"@soda-gql/babel-plugin\");\n\n return pluginSession ? createPlugin({ pluginSession }) : fallbackPlugin();\n};\n\n/**\n * Create a Babel plugin with an already-built artifact.\n * Use this when the artifact is pre-built (e.g., by a bundler plugin).\n */\nexport const createPluginWithArtifact = ({\n artifact,\n config,\n}: {\n artifact: BuilderArtifact;\n config: ResolvedSodaGqlConfig;\n}): PluginObj => ({\n name: \"@soda-gql/babel-plugin\",\n\n visitor: {\n Program(programPath: NodePath<t.Program>, state) {\n const filename = state.file?.opts?.filename;\n if (!filename) {\n return;\n }\n\n // Create Babel transformer instance\n const transformer = createTransformer({\n programPath,\n types: t,\n config,\n });\n\n // Transform using single method call (matches TypeScript plugin pattern)\n transformer.transform({\n filename,\n artifactLookup: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n });\n },\n },\n});\n","/**\n * Babel plugin entrypoint for soda-gql.\n *\n * This module provides Babel transformer integration for soda-gql\n * zero-runtime transformations.\n */\n\nexport * from \"./plugin\";\n\nimport { createSodaGqlPlugin } from \"./plugin\";\n\nexport { createSodaGqlPlugin };\nexport default createSodaGqlPlugin;\n"],"mappings":";;;;;;;AAIA,MAAM,iBAAiB;;;;;AA8CvB,MAAa,0BAA0B,gBAAqC;CAC1E,MAAM,WAAW,YAAY,KAAK,KAAK,MACpC,cAAc,UAAU,SAAS,uBAAuB,UAAU,OAAO,UA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,MAAM,gBAAgB,oBAAoB,SAAS,yBAAyB;AAE5E,QAAO,gBAAgB,aAAa,EAAE,eAAe,CAAC,GAAG,gBAAgB;;;;;;AAO3E,MAAa,4BAA4B,EACvC,UACA,cAIgB;CAChB,MAAM;CAEN,SAAS,EACP,QAAQ,aAAkC,OAAO;EAC/C,MAAM,WAAW,MAAM,MAAM,MAAM;AACnC,MAAI,CAAC,SACH;AAWF,EAPoB,kBAAkB;GACpC;GACOA;GACP;GACD,CAAC,CAGU,UAAU;GACpB;GACA,iBAAiB,gBAA6B,SAAS,SAAS;GACjE,CAAC;IAEL;CACF;;;;ACrFD,kBAAe"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["t"],"sources":["../src/plugin.ts"],"sourcesContent":["import type { PluginObj, PluginPass } from \"@babel/core\";\nimport { types as t } from \"@babel/core\";\nimport type { NodePath } from \"@babel/traverse\";\nimport { createTransformer } from \"@soda-gql/babel-transformer\";\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { createPluginSession, type PluginOptions, type PluginSession } from \"@soda-gql/plugin-common\";\n\ntype PluginPassState = PluginPass & {\n _artifact?: BuilderArtifact | null;\n};\n\nconst fallbackPlugin = (): PluginObj => ({\n name: \"@soda-gql/babel-plugin\",\n visitor: {\n Program() {\n // No-op fallback\n },\n },\n});\n\nexport const createPlugin = ({ pluginSession }: { pluginSession: PluginSession }): PluginObj<PluginPassState> => ({\n name: \"@soda-gql/babel-plugin\",\n\n async pre() {\n this._artifact = await pluginSession.getArtifactAsync();\n },\n\n visitor: {\n Program(programPath: NodePath<t.Program>, state) {\n const filename = state.file?.opts?.filename;\n if (!filename) {\n return;\n }\n\n const artifact = state._artifact;\n if (!artifact) {\n return;\n }\n\n // Create Babel transformer instance\n const transformer = createTransformer({\n programPath,\n types: t,\n config: pluginSession.config,\n });\n\n // Transform using single method call (matches TypeScript plugin pattern)\n transformer.transform({\n filename,\n artifactLookup: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n });\n },\n },\n});\n\nexport const createSodaGqlPlugin = (_babel: unknown, options: PluginOptions = {}): PluginObj => {\n // Create plugin session synchronously (no async pre())\n const pluginSession = createPluginSession(options, \"@soda-gql/babel-plugin\");\n\n return pluginSession ? createPlugin({ pluginSession }) : fallbackPlugin();\n};\n\n/**\n * Create a Babel plugin with an already-built artifact.\n * Use this when the artifact is pre-built (e.g., by a bundler plugin).\n */\nexport const createPluginWithArtifact = ({\n artifact,\n config,\n}: {\n artifact: BuilderArtifact;\n config: ResolvedSodaGqlConfig;\n}): PluginObj => ({\n name: \"@soda-gql/babel-plugin\",\n\n visitor: {\n Program(programPath: NodePath<t.Program>, state) {\n const filename = state.file?.opts?.filename;\n if (!filename) {\n return;\n }\n\n // Create Babel transformer instance\n const transformer = createTransformer({\n programPath,\n types: t,\n config,\n });\n\n // Transform using single method call (matches TypeScript plugin pattern)\n transformer.transform({\n filename,\n artifactLookup: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n });\n },\n },\n});\n"],"mappings":";;;;;AAaA,MAAM,wBAAmC;CACvC,MAAM;CACN,SAAS,EACP,UAAU,IAGX;CACF;AAED,MAAa,gBAAgB,EAAE,qBAAmF;CAChH,MAAM;CAEN,MAAM,MAAM;AACV,OAAK,YAAY,MAAM,cAAc,kBAAkB;;CAGzD,SAAS,EACP,QAAQ,aAAkC,OAAO;EAC/C,MAAM,WAAW,MAAM,MAAM,MAAM;AACnC,MAAI,CAAC,SACH;EAGF,MAAM,WAAW,MAAM;AACvB,MAAI,CAAC,SACH;AAWF,EAPoB,kBAAkB;GACpC;GACOA;GACP,QAAQ,cAAc;GACvB,CAAC,CAGU,UAAU;GACpB;GACA,iBAAiB,gBAA6B,SAAS,SAAS;GACjE,CAAC;IAEL;CACF;AAED,MAAa,uBAAuB,QAAiB,UAAyB,EAAE,KAAgB;CAE9F,MAAM,gBAAgB,oBAAoB,SAAS,yBAAyB;AAE5E,QAAO,gBAAgB,aAAa,EAAE,eAAe,CAAC,GAAG,gBAAgB;;;;;;AAO3E,MAAa,4BAA4B,EACvC,UACA,cAIgB;CAChB,MAAM;CAEN,SAAS,EACP,QAAQ,aAAkC,OAAO;EAC/C,MAAM,WAAW,MAAM,MAAM,MAAM;AACnC,MAAI,CAAC,SACH;AAWF,EAPoB,kBAAkB;GACpC;GACOA;GACP;GACD,CAAC,CAGU,UAAU;GACpB;GACA,iBAAiB,gBAA6B,SAAS,SAAS;GACjE,CAAC;IAEL;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/babel-plugin",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Babel plugin for soda-gql transformations",
|
|
4
5
|
"type": "module",
|
|
5
6
|
"private": false,
|
|
6
7
|
"license": "MIT",
|
|
@@ -12,12 +13,32 @@
|
|
|
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
|
+
"babel",
|
|
22
|
+
"babel-plugin"
|
|
23
|
+
],
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/whatasoda/soda-gql.git",
|
|
27
|
+
"directory": "packages/babel-plugin"
|
|
28
|
+
},
|
|
29
|
+
"homepage": "https://github.com/whatasoda/soda-gql#readme",
|
|
30
|
+
"bugs": {
|
|
31
|
+
"url": "https://github.com/whatasoda/soda-gql/issues"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
15
36
|
"main": "./dist/index.mjs",
|
|
16
37
|
"module": "./dist/index.mjs",
|
|
17
38
|
"types": "./dist/index.d.mts",
|
|
18
39
|
"exports": {
|
|
19
40
|
".": {
|
|
20
|
-
"@soda-gql": "
|
|
41
|
+
"@soda-gql": "./@x-index.ts",
|
|
21
42
|
"types": "./dist/index.d.mts",
|
|
22
43
|
"import": "./dist/index.mjs",
|
|
23
44
|
"require": "./dist/index.cjs",
|
|
@@ -26,19 +47,16 @@
|
|
|
26
47
|
"./package.json": "./package.json"
|
|
27
48
|
},
|
|
28
49
|
"dependencies": {
|
|
29
|
-
"@soda-gql/
|
|
30
|
-
"@soda-gql/
|
|
31
|
-
"@soda-gql/config": "0.
|
|
32
|
-
"@soda-gql/
|
|
33
|
-
"@soda-gql/plugin-common": "0.1.0",
|
|
50
|
+
"@soda-gql/babel-transformer": "0.2.0",
|
|
51
|
+
"@soda-gql/builder": "0.2.0",
|
|
52
|
+
"@soda-gql/config": "0.2.0",
|
|
53
|
+
"@soda-gql/plugin-common": "0.2.0",
|
|
34
54
|
"@babel/core": "^7.24.0",
|
|
35
|
-
"@babel/parser": "^7.24.0",
|
|
36
55
|
"@babel/traverse": "^7.24.0",
|
|
37
|
-
"@babel/types": "^7.24.0"
|
|
38
|
-
"neverthrow": "^8.1.1"
|
|
56
|
+
"@babel/types": "^7.24.0"
|
|
39
57
|
},
|
|
40
58
|
"devDependencies": {
|
|
41
|
-
"@soda-gql/tsc-transformer": "0.
|
|
59
|
+
"@soda-gql/tsc-transformer": "0.2.0"
|
|
42
60
|
},
|
|
43
61
|
"peerDependencies": {}
|
|
44
62
|
}
|