@soda-gql/builder 0.12.3 → 0.12.4
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 +13 -13
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin-support.cjs +5 -5
- package/dist/plugin-support.cjs.map +1 -1
- package/dist/plugin-support.d.cts +5 -0
- package/dist/plugin-support.d.cts.map +1 -1
- package/dist/plugin-support.d.mts +5 -0
- package/dist/plugin-support.d.mts.map +1 -1
- package/dist/plugin-support.mjs +5 -5
- package/dist/plugin-support.mjs.map +1 -1
- package/dist/{service-DXvoj0YF.mjs → service-B7nDi5Q3.mjs} +44 -26
- package/dist/service-B7nDi5Q3.mjs.map +1 -0
- package/dist/service-Do9da7Cm.d.mts.map +1 -1
- package/dist/service-vzMbq7Pe.d.cts.map +1 -1
- package/dist/{service-CNpxn4cF.cjs → service-yfybXKla.cjs} +44 -26
- package/dist/service-yfybXKla.cjs.map +1 -0
- package/package.json +5 -5
- package/dist/service-CNpxn4cF.cjs.map +0 -1
- package/dist/service-DXvoj0YF.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin-support.mjs","names":[],"sources":["../src/plugin/errors.ts","../src/plugin/shared-state.ts","../src/plugin/session.ts","../src/plugin/utils/canonical-id.ts"],"sourcesContent":["/**\n * Error types and formatters for plugin-babel.\n * Simplified from plugin-shared to include only types actually used by the Babel transformer.\n */\n\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { BuilderError } from \"../types\";\n\ntype OptionsInvalidBuilderConfig = { readonly code: \"INVALID_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsMissingBuilderConfig = { readonly code: \"MISSING_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsConfigLoadFailed = { readonly code: \"CONFIG_LOAD_FAILED\"; readonly message: string };\n\ntype BuilderEntryNotFound = Extract<BuilderError, { code: \"ENTRY_NOT_FOUND\" }>;\ntype BuilderDocDuplicate = Extract<BuilderError, { code: \"DOC_DUPLICATE\" }>;\ntype BuilderCircularDependency = Extract<BuilderError, { code: \"GRAPH_CIRCULAR_DEPENDENCY\" }>;\ntype BuilderModuleEvaluationFailed = Extract<BuilderError, { code: \"RUNTIME_MODULE_LOAD_FAILED\" }>;\ntype BuilderWriteFailed = Extract<BuilderError, { code: \"WRITE_FAILED\" }>;\n\ntype AnalysisMetadataMissingCause = { readonly filename: string };\ntype AnalysisArtifactMissingCause = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype AnalysisUnsupportedArtifactTypeCause = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype PluginErrorBase<Code extends string, Cause> = {\n readonly type: \"PluginError\";\n readonly code: Code;\n readonly message: string;\n readonly cause: Cause;\n};\n\nexport type PluginOptionsInvalidBuilderConfigError = PluginErrorBase<\n \"OPTIONS_INVALID_BUILDER_CONFIG\",\n OptionsInvalidBuilderConfig | OptionsMissingBuilderConfig | OptionsConfigLoadFailed\n> & { readonly stage: \"normalize-options\" };\n\nexport type PluginBuilderEntryNotFoundError = PluginErrorBase<\"SODA_GQL_BUILDER_ENTRY_NOT_FOUND\", BuilderEntryNotFound> & {\n readonly stage: \"builder\";\n readonly entry: string;\n};\n\nexport type PluginBuilderDocDuplicateError = PluginErrorBase<\"SODA_GQL_BUILDER_DOC_DUPLICATE\", BuilderDocDuplicate> & {\n readonly stage: \"builder\";\n readonly name: string;\n readonly sources: readonly string[];\n};\n\nexport type PluginBuilderCircularDependencyError = PluginErrorBase<\n \"SODA_GQL_BUILDER_CIRCULAR_DEPENDENCY\",\n BuilderCircularDependency\n> & { readonly stage: \"builder\"; readonly chain: readonly string[] };\n\nexport type PluginBuilderModuleEvaluationFailedError = PluginErrorBase<\n \"SODA_GQL_BUILDER_MODULE_EVALUATION_FAILED\",\n BuilderModuleEvaluationFailed\n> & { readonly stage: \"builder\"; readonly filePath: string; readonly astPath: string };\n\nexport type PluginBuilderWriteFailedError = PluginErrorBase<\"SODA_GQL_BUILDER_WRITE_FAILED\", BuilderWriteFailed> & {\n readonly stage: \"builder\";\n readonly outPath: string;\n};\n\nexport type PluginBuilderUnexpectedError = PluginErrorBase<\"SODA_GQL_BUILDER_UNEXPECTED\", unknown> & {\n readonly stage: \"builder\";\n};\n\nexport type PluginAnalysisMetadataMissingError = PluginErrorBase<\"SODA_GQL_METADATA_NOT_FOUND\", AnalysisMetadataMissingCause> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n};\n\nexport type PluginAnalysisArtifactMissingError = PluginErrorBase<\n \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n AnalysisArtifactMissingCause\n> & { readonly stage: \"analysis\"; readonly filename: string; readonly canonicalId: CanonicalId };\n\nexport type PluginAnalysisUnsupportedArtifactTypeError = PluginErrorBase<\n \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n AnalysisUnsupportedArtifactTypeCause\n> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype TransformMissingBuilderArgCause = { readonly filename: string; readonly builderType: string; readonly argName: string };\ntype TransformUnsupportedValueTypeCause = { readonly valueType: string };\ntype TransformAstVisitorFailedCause = { readonly filename: string; readonly reason: string };\n\nexport type PluginTransformMissingBuilderArgError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_MISSING_BUILDER_ARG\",\n TransformMissingBuilderArgCause\n> & {\n readonly stage: \"transform\";\n readonly filename: string;\n readonly builderType: string;\n readonly argName: string;\n};\n\nexport type PluginTransformUnsupportedValueTypeError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n TransformUnsupportedValueTypeCause\n> & { readonly stage: \"transform\"; readonly valueType: string };\n\nexport type PluginTransformAstVisitorFailedError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_AST_VISITOR_FAILED\",\n TransformAstVisitorFailedCause\n> & { readonly stage: \"transform\"; readonly filename: string; readonly reason: string };\n\n/**\n * Union of all plugin error types.\n */\nexport type PluginError =\n | PluginOptionsInvalidBuilderConfigError\n | PluginBuilderEntryNotFoundError\n | PluginBuilderDocDuplicateError\n | PluginBuilderCircularDependencyError\n | PluginBuilderModuleEvaluationFailedError\n | PluginBuilderWriteFailedError\n | PluginBuilderUnexpectedError\n | PluginAnalysisMetadataMissingError\n | PluginAnalysisArtifactMissingError\n | PluginAnalysisUnsupportedArtifactTypeError\n | PluginTransformMissingBuilderArgError\n | PluginTransformUnsupportedValueTypeError\n | PluginTransformAstVisitorFailedError;\n\n/**\n * Format a PluginError into a human-readable message.\n */\nexport const formatPluginError = (error: PluginError): string => {\n const codePrefix = `[${error.code}]`;\n const stageInfo = \"stage\" in error ? ` (${error.stage})` : \"\";\n return `${codePrefix}${stageInfo} ${error.message}`;\n};\n\n/**\n * Type guard for PluginError.\n */\nexport const isPluginError = (value: unknown): value is PluginError => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n value.type === \"PluginError\" &&\n \"code\" in value &&\n \"message\" in value\n );\n};\n\n/**\n * Assertion helper for unreachable code paths.\n * This is the ONLY acceptable throw in plugin code.\n */\nexport const assertUnreachable = (value: never, context?: string): never => {\n throw new Error(`[INTERNAL] Unreachable code path${context ? ` in ${context}` : \"\"}: received ${JSON.stringify(value)}`);\n};\n","import type { BuilderArtifact } from \"../artifact/types\";\nimport type { BuilderService } from \"../service\";\nimport type { PluginSession } from \"./session\";\n\n/**\n * Transformer type for code transformation.\n * - 'babel': Use Babel plugin (default, wider compatibility)\n * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)\n */\nexport type TransformerType = \"babel\" | \"swc\";\n\n/**\n * Minimal interface for SWC transformer.\n * Matches the Transformer interface from @soda-gql/swc.\n */\nexport interface SwcTransformerInterface {\n transform(input: { sourceCode: string; sourcePath: string; inputSourceMap?: string }): {\n transformed: boolean;\n sourceCode: string;\n sourceMap?: string;\n };\n}\n\n/**\n * Shared state between bundler plugins and loaders.\n * Enables efficient artifact sharing across build pipeline stages.\n */\nexport type SharedState = {\n pluginSession: PluginSession | null;\n currentArtifact: BuilderArtifact | null;\n moduleAdjacency: Map<string, Set<string>>;\n generation: number;\n swcTransformer: SwcTransformerInterface | null;\n transformerType: TransformerType | null;\n builderService: BuilderService | null;\n};\n\n// Global state for sharing between plugin and loader\nconst sharedStates = new Map<string, SharedState>();\n\n/**\n * Get shared state for a given project (identified by config path or cwd).\n */\nexport const getSharedState = (key: string): SharedState => {\n let state = sharedStates.get(key);\n if (!state) {\n state = {\n pluginSession: null,\n currentArtifact: null,\n moduleAdjacency: new Map(),\n generation: 0,\n swcTransformer: null,\n transformerType: null,\n builderService: null,\n };\n sharedStates.set(key, state);\n }\n return state;\n};\n\n/**\n * Update shared artifact.\n */\nexport const setSharedArtifact = (\n key: string,\n artifact: BuilderArtifact | null,\n moduleAdjacency?: Map<string, Set<string>>,\n): void => {\n const state = getSharedState(key);\n state.currentArtifact = artifact;\n if (moduleAdjacency) {\n state.moduleAdjacency = moduleAdjacency;\n }\n state.generation++;\n};\n\n/**\n * Get shared artifact.\n */\nexport const getSharedArtifact = (key: string): BuilderArtifact | null => {\n return getSharedState(key).currentArtifact;\n};\n\n/**\n * Get shared plugin session.\n */\nexport const getSharedPluginSession = (key: string): PluginSession | null => {\n return getSharedState(key).pluginSession;\n};\n\n/**\n * Set shared plugin session.\n */\nexport const setSharedPluginSession = (key: string, session: PluginSession | null): void => {\n getSharedState(key).pluginSession = session;\n};\n\n/**\n * Get the state key from config path or cwd.\n */\nexport const getStateKey = (configPath?: string): string => {\n return configPath ?? process.cwd();\n};\n\n/**\n * Set shared SWC transformer.\n */\nexport const setSharedSwcTransformer = (key: string, transformer: SwcTransformerInterface | null): void => {\n getSharedState(key).swcTransformer = transformer;\n};\n\n/**\n * Get shared SWC transformer.\n */\nexport const getSharedSwcTransformer = (key: string): SwcTransformerInterface | null => {\n return getSharedState(key).swcTransformer;\n};\n\n/**\n * Set shared transformer type.\n */\nexport const setSharedTransformerType = (key: string, transformerType: TransformerType | null): void => {\n getSharedState(key).transformerType = transformerType;\n};\n\n/**\n * Get shared transformer type.\n */\nexport const getSharedTransformerType = (key: string): TransformerType | null => {\n return getSharedState(key).transformerType;\n};\n\n/**\n * Get shared BuilderService.\n */\nexport const getSharedBuilderService = (key: string): BuilderService | null => {\n return getSharedState(key).builderService;\n};\n\n/**\n * Set shared BuilderService.\n */\nexport const setSharedBuilderService = (key: string, service: BuilderService | null): void => {\n getSharedState(key).builderService = service;\n};\n","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { loadArtifactSync } from \"../artifact/loader\";\nimport type { BuilderArtifact } from \"../artifact/types\";\nimport { formatBuilderErrorForCLI } from \"../errors/formatter\";\nimport type { BuilderService } from \"../service\";\nimport { createBuilderService } from \"../service\";\nimport { getSharedBuilderService, getStateKey, setSharedBuilderService } from \"./shared-state\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: boolean;\n /**\n * Whether to fail the build on error.\n * When true (default), throws an error that fails the bundler build.\n * When false, logs the error and continues (graceful degradation).\n */\n readonly failOnError?: boolean;\n};\n\n/**\n * Plugin session containing builder service and configuration.\n */\nexport type PluginSession = {\n readonly config: ResolvedSodaGqlConfig;\n readonly getArtifact: () => BuilderArtifact | null;\n readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;\n /**\n * Whether the session is using a pre-built artifact.\n * When true, artifacts are loaded from a file instead of built dynamically.\n */\n readonly isPrebuiltMode: boolean;\n};\n\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n *\n * @param options - Plugin options\n * @param pluginName - Name of the plugin for error messages\n * @throws Error if failOnError is true and config load fails\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n const failOnError = options.failOnError ?? true;\n\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load config: ${configResult.error.message}`;\n console.error(errorMsg, {\n code: configResult.error.code,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n if (failOnError) {\n throw new Error(errorMsg);\n }\n return null;\n }\n\n const config = configResult.value;\n\n // Check if pre-built artifact mode is enabled\n if (config.artifact?.path) {\n const artifactResult = loadArtifactSync(config.artifact.path);\n\n if (artifactResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load pre-built artifact: ${artifactResult.error.message}`;\n console.error(errorMsg, {\n code: artifactResult.error.code,\n filePath: artifactResult.error.filePath,\n });\n if (failOnError) {\n throw new Error(errorMsg);\n }\n return null;\n }\n\n const prebuiltArtifact = artifactResult.value;\n console.log(`[${pluginName}] Using pre-built artifact: ${config.artifact.path}`);\n\n return {\n config,\n getArtifact: () => prebuiltArtifact,\n getArtifactAsync: async () => prebuiltArtifact,\n isPrebuiltMode: true,\n };\n }\n\n // Dynamic build mode\n const stateKey = getStateKey(options.configPath);\n\n // Use global BuilderService cache to share FileTracker state across plugin instances\n const ensureBuilderService = (): BuilderService => {\n const existing = getSharedBuilderService(stateKey);\n if (existing) {\n return existing;\n }\n\n const service = createBuilderService({ config });\n setSharedBuilderService(stateKey, service);\n return service;\n };\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * This ensures the artifact is always up-to-date with the latest source files.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`);\n }\n return null;\n }\n return buildResult.value;\n };\n\n /**\n * Async version of getArtifact.\n * Supports async metadata factories and parallel element evaluation.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifactAsync = async (): Promise<BuilderArtifact | null> => {\n const builderService = ensureBuilderService();\n const buildResult = await builderService.buildAsync();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`);\n }\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n getArtifactAsync,\n isPrebuiltMode: false,\n };\n};\n","/**\n * Utility for working with canonical IDs.\n */\n\nimport { resolve } from \"node:path\";\nimport { type CanonicalId, createCanonicalId } from \"@soda-gql/common\";\n\n/**\n * Options for resolving a canonical ID.\n */\nexport type ResolveCanonicalIdOptions = {\n /**\n * Base directory for relative path computation.\n * When provided, the canonical ID will use a path relative to this directory.\n */\n readonly baseDir?: string;\n};\n\n/**\n * Resolve a canonical ID from a filename and AST path.\n *\n * @param filename - The source file path (absolute or relative)\n * @param astPath - The AST path within the file\n * @param options - Optional settings including baseDir for relative paths\n * @returns A canonical ID in the format `{path}::{astPath}`\n */\nexport const resolveCanonicalId = (filename: string, astPath: string, options?: ResolveCanonicalIdOptions): CanonicalId => {\n const { baseDir } = options ?? {};\n if (baseDir) {\n return createCanonicalId(filename, astPath, { baseDir });\n }\n return createCanonicalId(resolve(filename), astPath);\n};\n"],"mappings":";;;;;;;;;AAqIA,MAAa,qBAAqB,UAA+B;CAC/D,MAAM,aAAa,IAAI,MAAM,KAAK;CAClC,MAAM,YAAY,WAAW,QAAQ,KAAK,MAAM,MAAM,KAAK;AAC3D,QAAO,GAAG,aAAa,UAAU,GAAG,MAAM;;;;;AAM5C,MAAa,iBAAiB,UAAyC;AACrE,QACE,OAAO,UAAU,YACjB,U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O;;;;;;;;CAST,MAAM,oBAA4C;EAChD,MAAM,iBAAiB,sBAAsB;EAC7C,MAAM,cAAc,eAAe,OAAO;AAC1C,MAAI,YAAY,OAAO,EAAE;GACvB,MAAM,iBAAiB,yBAAyB,YAAY,MAAM;AAClE,WAAQ,MAAM,IAAI,WAAW,mBAAmB,iBAAiB;AACjE,OAAI,aAAa;AACf,UAAM,IAAI,MAAM,IAAI,WAAW,IAAI,YAAY,MAAM,UAAU;;AAEjE,UAAO;;AAET,SAAO,YAAY;;;;;;;;CASrB,MAAM,mBAAmB,YAA6C;EACpE,MAAM,iBAAiB,sBAAsB;EAC7C,MAAM,cAAc,MAAM,eAAe,YAAY;AACrD,MAAI,YAAY,OAAO,EAAE;GACvB,MAAM,iBAAiB,yBAAyB,YAAY,MAAM;AAClE,WAAQ,MAAM,IAAI,WAAW,mBAAmB,iBAAiB;AACjE,OAAI,aAAa;AACf,UAAM,IAAI,MAAM,IAAI,WAAW,IAAI,YAAY,MAAM,UAAU;;AAEjE,UAAO;;AAET,SAAO,YAAY;;AAGrB,QAAO;EACL;EACA;EACA;EACA,gBAAgB;EACjB;;;;;;;;;;;;;;;;ACtIH,MAAa,sBAAsB,UAAkB,SAAiB,YAAqD;CACzH,MAAM,EAAE,YAAY,WAAW,EAAE;AACjC,KAAI,SAAS;AACX,SAAO,kBAAkB,UAAU,SAAS,EAAE,SAAS,CAAC;;AAE1D,QAAO,kBAAkB,QAAQ,SAAS,EAAE,QAAQ"}
|
|
1
|
+
{"version":3,"file":"plugin-support.mjs","names":[],"sources":["../src/plugin/errors.ts","../src/plugin/shared-state.ts","../src/plugin/session.ts","../src/plugin/utils/canonical-id.ts"],"sourcesContent":["/**\n * Error types and formatters for plugin-babel.\n * Simplified from plugin-shared to include only types actually used by the Babel transformer.\n */\n\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { BuilderError } from \"../types\";\n\ntype OptionsInvalidBuilderConfig = { readonly code: \"INVALID_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsMissingBuilderConfig = { readonly code: \"MISSING_BUILDER_CONFIG\"; readonly message: string };\ntype OptionsConfigLoadFailed = { readonly code: \"CONFIG_LOAD_FAILED\"; readonly message: string };\n\ntype BuilderEntryNotFound = Extract<BuilderError, { code: \"ENTRY_NOT_FOUND\" }>;\ntype BuilderDocDuplicate = Extract<BuilderError, { code: \"DOC_DUPLICATE\" }>;\ntype BuilderCircularDependency = Extract<BuilderError, { code: \"GRAPH_CIRCULAR_DEPENDENCY\" }>;\ntype BuilderModuleEvaluationFailed = Extract<BuilderError, { code: \"RUNTIME_MODULE_LOAD_FAILED\" }>;\ntype BuilderWriteFailed = Extract<BuilderError, { code: \"WRITE_FAILED\" }>;\n\ntype AnalysisMetadataMissingCause = { readonly filename: string };\ntype AnalysisArtifactMissingCause = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype AnalysisUnsupportedArtifactTypeCause = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype PluginErrorBase<Code extends string, Cause> = {\n readonly type: \"PluginError\";\n readonly code: Code;\n readonly message: string;\n readonly cause: Cause;\n};\n\nexport type PluginOptionsInvalidBuilderConfigError = PluginErrorBase<\n \"OPTIONS_INVALID_BUILDER_CONFIG\",\n OptionsInvalidBuilderConfig | OptionsMissingBuilderConfig | OptionsConfigLoadFailed\n> & { readonly stage: \"normalize-options\" };\n\nexport type PluginBuilderEntryNotFoundError = PluginErrorBase<\"SODA_GQL_BUILDER_ENTRY_NOT_FOUND\", BuilderEntryNotFound> & {\n readonly stage: \"builder\";\n readonly entry: string;\n};\n\nexport type PluginBuilderDocDuplicateError = PluginErrorBase<\"SODA_GQL_BUILDER_DOC_DUPLICATE\", BuilderDocDuplicate> & {\n readonly stage: \"builder\";\n readonly name: string;\n readonly sources: readonly string[];\n};\n\nexport type PluginBuilderCircularDependencyError = PluginErrorBase<\n \"SODA_GQL_BUILDER_CIRCULAR_DEPENDENCY\",\n BuilderCircularDependency\n> & { readonly stage: \"builder\"; readonly chain: readonly string[] };\n\nexport type PluginBuilderModuleEvaluationFailedError = PluginErrorBase<\n \"SODA_GQL_BUILDER_MODULE_EVALUATION_FAILED\",\n BuilderModuleEvaluationFailed\n> & { readonly stage: \"builder\"; readonly filePath: string; readonly astPath: string };\n\nexport type PluginBuilderWriteFailedError = PluginErrorBase<\"SODA_GQL_BUILDER_WRITE_FAILED\", BuilderWriteFailed> & {\n readonly stage: \"builder\";\n readonly outPath: string;\n};\n\nexport type PluginBuilderUnexpectedError = PluginErrorBase<\"SODA_GQL_BUILDER_UNEXPECTED\", unknown> & {\n readonly stage: \"builder\";\n};\n\nexport type PluginAnalysisMetadataMissingError = PluginErrorBase<\"SODA_GQL_METADATA_NOT_FOUND\", AnalysisMetadataMissingCause> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n};\n\nexport type PluginAnalysisArtifactMissingError = PluginErrorBase<\n \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n AnalysisArtifactMissingCause\n> & { readonly stage: \"analysis\"; readonly filename: string; readonly canonicalId: CanonicalId };\n\nexport type PluginAnalysisUnsupportedArtifactTypeError = PluginErrorBase<\n \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n AnalysisUnsupportedArtifactTypeCause\n> & {\n readonly stage: \"analysis\";\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\ntype TransformMissingBuilderArgCause = { readonly filename: string; readonly builderType: string; readonly argName: string };\ntype TransformUnsupportedValueTypeCause = { readonly valueType: string };\ntype TransformAstVisitorFailedCause = { readonly filename: string; readonly reason: string };\n\nexport type PluginTransformMissingBuilderArgError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_MISSING_BUILDER_ARG\",\n TransformMissingBuilderArgCause\n> & {\n readonly stage: \"transform\";\n readonly filename: string;\n readonly builderType: string;\n readonly argName: string;\n};\n\nexport type PluginTransformUnsupportedValueTypeError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n TransformUnsupportedValueTypeCause\n> & { readonly stage: \"transform\"; readonly valueType: string };\n\nexport type PluginTransformAstVisitorFailedError = PluginErrorBase<\n \"SODA_GQL_TRANSFORM_AST_VISITOR_FAILED\",\n TransformAstVisitorFailedCause\n> & { readonly stage: \"transform\"; readonly filename: string; readonly reason: string };\n\n/**\n * Union of all plugin error types.\n */\nexport type PluginError =\n | PluginOptionsInvalidBuilderConfigError\n | PluginBuilderEntryNotFoundError\n | PluginBuilderDocDuplicateError\n | PluginBuilderCircularDependencyError\n | PluginBuilderModuleEvaluationFailedError\n | PluginBuilderWriteFailedError\n | PluginBuilderUnexpectedError\n | PluginAnalysisMetadataMissingError\n | PluginAnalysisArtifactMissingError\n | PluginAnalysisUnsupportedArtifactTypeError\n | PluginTransformMissingBuilderArgError\n | PluginTransformUnsupportedValueTypeError\n | PluginTransformAstVisitorFailedError;\n\n/**\n * Format a PluginError into a human-readable message.\n */\nexport const formatPluginError = (error: PluginError): string => {\n const codePrefix = `[${error.code}]`;\n const stageInfo = \"stage\" in error ? ` (${error.stage})` : \"\";\n return `${codePrefix}${stageInfo} ${error.message}`;\n};\n\n/**\n * Type guard for PluginError.\n */\nexport const isPluginError = (value: unknown): value is PluginError => {\n return (\n typeof value === \"object\" &&\n value !== null &&\n \"type\" in value &&\n value.type === \"PluginError\" &&\n \"code\" in value &&\n \"message\" in value\n );\n};\n\n/**\n * Assertion helper for unreachable code paths.\n * This is the ONLY acceptable throw in plugin code.\n */\nexport const assertUnreachable = (value: never, context?: string): never => {\n throw new Error(`[INTERNAL] Unreachable code path${context ? ` in ${context}` : \"\"}: received ${JSON.stringify(value)}`);\n};\n","import type { BuilderArtifact } from \"../artifact/types\";\nimport type { BuilderService } from \"../service\";\nimport type { PluginSession } from \"./session\";\n\n/**\n * Transformer type for code transformation.\n * - 'babel': Use Babel plugin (default, wider compatibility)\n * - 'swc': Use SWC transformer (faster, requires @soda-gql/swc)\n */\nexport type TransformerType = \"babel\" | \"swc\";\n\n/**\n * Minimal interface for SWC transformer.\n * Matches the Transformer interface from @soda-gql/swc.\n */\nexport interface SwcTransformerInterface {\n transform(input: { sourceCode: string; sourcePath: string; inputSourceMap?: string }): {\n transformed: boolean;\n sourceCode: string;\n sourceMap?: string;\n errors: ReadonlyArray<{ readonly code: string; readonly message: string; readonly stage: string }>;\n };\n}\n\n/**\n * Shared state between bundler plugins and loaders.\n * Enables efficient artifact sharing across build pipeline stages.\n */\nexport type SharedState = {\n pluginSession: PluginSession | null;\n currentArtifact: BuilderArtifact | null;\n moduleAdjacency: Map<string, Set<string>>;\n generation: number;\n swcTransformer: SwcTransformerInterface | null;\n transformerType: TransformerType | null;\n builderService: BuilderService | null;\n};\n\n// Global state for sharing between plugin and loader\nconst sharedStates = new Map<string, SharedState>();\n\n/**\n * Get shared state for a given project (identified by config path or cwd).\n */\nexport const getSharedState = (key: string): SharedState => {\n let state = sharedStates.get(key);\n if (!state) {\n state = {\n pluginSession: null,\n currentArtifact: null,\n moduleAdjacency: new Map(),\n generation: 0,\n swcTransformer: null,\n transformerType: null,\n builderService: null,\n };\n sharedStates.set(key, state);\n }\n return state;\n};\n\n/**\n * Update shared artifact.\n */\nexport const setSharedArtifact = (\n key: string,\n artifact: BuilderArtifact | null,\n moduleAdjacency?: Map<string, Set<string>>,\n): void => {\n const state = getSharedState(key);\n state.currentArtifact = artifact;\n if (moduleAdjacency) {\n state.moduleAdjacency = moduleAdjacency;\n }\n state.generation++;\n};\n\n/**\n * Get shared artifact.\n */\nexport const getSharedArtifact = (key: string): BuilderArtifact | null => {\n return getSharedState(key).currentArtifact;\n};\n\n/**\n * Get shared plugin session.\n */\nexport const getSharedPluginSession = (key: string): PluginSession | null => {\n return getSharedState(key).pluginSession;\n};\n\n/**\n * Set shared plugin session.\n */\nexport const setSharedPluginSession = (key: string, session: PluginSession | null): void => {\n getSharedState(key).pluginSession = session;\n};\n\n/**\n * Get the state key from config path or cwd.\n */\nexport const getStateKey = (configPath?: string): string => {\n return configPath ?? process.cwd();\n};\n\n/**\n * Set shared SWC transformer.\n */\nexport const setSharedSwcTransformer = (key: string, transformer: SwcTransformerInterface | null): void => {\n getSharedState(key).swcTransformer = transformer;\n};\n\n/**\n * Get shared SWC transformer.\n */\nexport const getSharedSwcTransformer = (key: string): SwcTransformerInterface | null => {\n return getSharedState(key).swcTransformer;\n};\n\n/**\n * Set shared transformer type.\n */\nexport const setSharedTransformerType = (key: string, transformerType: TransformerType | null): void => {\n getSharedState(key).transformerType = transformerType;\n};\n\n/**\n * Get shared transformer type.\n */\nexport const getSharedTransformerType = (key: string): TransformerType | null => {\n return getSharedState(key).transformerType;\n};\n\n/**\n * Get shared BuilderService.\n */\nexport const getSharedBuilderService = (key: string): BuilderService | null => {\n return getSharedState(key).builderService;\n};\n\n/**\n * Set shared BuilderService.\n */\nexport const setSharedBuilderService = (key: string, service: BuilderService | null): void => {\n getSharedState(key).builderService = service;\n};\n","/**\n * Plugin session management for all plugins.\n * Unified from plugin-babel and plugin-swc implementations.\n */\n\nimport { loadConfig, type ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { loadArtifactSync } from \"../artifact/loader\";\nimport type { BuilderArtifact } from \"../artifact/types\";\nimport { formatBuilderErrorForCLI } from \"../errors/formatter\";\nimport type { BuilderService } from \"../service\";\nimport { createBuilderService } from \"../service\";\nimport { getSharedBuilderService, getStateKey, setSharedBuilderService } from \"./shared-state\";\n\n/**\n * Plugin options shared across all plugins.\n */\nexport type PluginOptions = {\n readonly configPath?: string;\n readonly enabled?: boolean;\n /**\n * Whether to fail the build on error.\n * When true (default), throws an error that fails the bundler build.\n * When false, logs the error and continues (graceful degradation).\n */\n readonly failOnError?: boolean;\n};\n\n/**\n * Plugin session containing builder service and configuration.\n */\nexport type PluginSession = {\n readonly config: ResolvedSodaGqlConfig;\n readonly getArtifact: () => BuilderArtifact | null;\n readonly getArtifactAsync: () => Promise<BuilderArtifact | null>;\n /**\n * Whether the session is using a pre-built artifact.\n * When true, artifacts are loaded from a file instead of built dynamically.\n */\n readonly isPrebuiltMode: boolean;\n};\n\n/**\n * Create plugin session by loading config and creating cached builder service.\n * Returns null if disabled or config load fails.\n *\n * @param options - Plugin options\n * @param pluginName - Name of the plugin for error messages\n * @throws Error if failOnError is true and config load fails\n */\nexport const createPluginSession = (options: PluginOptions, pluginName: string): PluginSession | null => {\n const enabled = options.enabled ?? true;\n const failOnError = options.failOnError ?? true;\n\n if (!enabled) {\n return null;\n }\n\n const configResult = loadConfig(options.configPath);\n if (configResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load config: ${configResult.error.message}`;\n console.error(errorMsg, {\n code: configResult.error.code,\n filePath: configResult.error.filePath,\n cause: configResult.error.cause,\n });\n if (failOnError) {\n throw new Error(errorMsg, { cause: configResult.error });\n }\n return null;\n }\n\n const config = configResult.value;\n\n // Check if pre-built artifact mode is enabled\n if (config.artifact?.path) {\n const artifactResult = loadArtifactSync(config.artifact.path);\n\n if (artifactResult.isErr()) {\n const errorMsg = `[${pluginName}] Failed to load pre-built artifact: ${artifactResult.error.message}`;\n console.error(errorMsg, {\n code: artifactResult.error.code,\n filePath: artifactResult.error.filePath,\n });\n if (failOnError) {\n throw new Error(errorMsg, { cause: artifactResult.error });\n }\n return null;\n }\n\n const prebuiltArtifact = artifactResult.value;\n console.log(`[${pluginName}] Using pre-built artifact: ${config.artifact.path}`);\n\n return {\n config,\n getArtifact: () => prebuiltArtifact,\n getArtifactAsync: async () => prebuiltArtifact,\n isPrebuiltMode: true,\n };\n }\n\n // Dynamic build mode\n const stateKey = getStateKey(options.configPath);\n\n // Use global BuilderService cache to share FileTracker state across plugin instances\n const ensureBuilderService = (): BuilderService => {\n const existing = getSharedBuilderService(stateKey);\n if (existing) {\n return existing;\n }\n\n const service = createBuilderService({ config });\n setSharedBuilderService(stateKey, service);\n return service;\n };\n\n /**\n * Build artifact on every invocation (like tsc-plugin).\n * This ensures the artifact is always up-to-date with the latest source files.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifact = (): BuilderArtifact | null => {\n const builderService = ensureBuilderService();\n const buildResult = builderService.build();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`, { cause: buildResult.error });\n }\n return null;\n }\n return buildResult.value;\n };\n\n /**\n * Async version of getArtifact.\n * Supports async metadata factories and parallel element evaluation.\n *\n * @throws Error if failOnError is true and build fails\n */\n const getArtifactAsync = async (): Promise<BuilderArtifact | null> => {\n const builderService = ensureBuilderService();\n const buildResult = await builderService.buildAsync();\n if (buildResult.isErr()) {\n const formattedError = formatBuilderErrorForCLI(buildResult.error);\n console.error(`[${pluginName}] Build failed:\\n${formattedError}`);\n if (failOnError) {\n throw new Error(`[${pluginName}] ${buildResult.error.message}`, { cause: buildResult.error });\n }\n return null;\n }\n return buildResult.value;\n };\n\n return {\n config,\n getArtifact,\n getArtifactAsync,\n isPrebuiltMode: false,\n };\n};\n","/**\n * Utility for working with canonical IDs.\n */\n\nimport { resolve } from \"node:path\";\nimport { type CanonicalId, createCanonicalId } from \"@soda-gql/common\";\n\n/**\n * Options for resolving a canonical ID.\n */\nexport type ResolveCanonicalIdOptions = {\n /**\n * Base directory for relative path computation.\n * When provided, the canonical ID will use a path relative to this directory.\n */\n readonly baseDir?: string;\n};\n\n/**\n * Resolve a canonical ID from a filename and AST path.\n *\n * @param filename - The source file path (absolute or relative)\n * @param astPath - The AST path within the file\n * @param options - Optional settings including baseDir for relative paths\n * @returns A canonical ID in the format `{path}::{astPath}`\n */\nexport const resolveCanonicalId = (filename: string, astPath: string, options?: ResolveCanonicalIdOptions): CanonicalId => {\n const { baseDir } = options ?? {};\n if (baseDir) {\n return createCanonicalId(filename, astPath, { baseDir });\n }\n return createCanonicalId(resolve(filename), astPath);\n};\n"],"mappings":";;;;;;;;;AAqIA,MAAa,qBAAqB,UAA+B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"}
|
|
@@ -61,7 +61,8 @@ const BuilderArtifactOperationSchema = z.object({
|
|
|
61
61
|
operationName: z.string(),
|
|
62
62
|
schemaLabel: z.string(),
|
|
63
63
|
document: z.unknown(),
|
|
64
|
-
variableNames: z.array(z.string())
|
|
64
|
+
variableNames: z.array(z.string()),
|
|
65
|
+
metadata: z.unknown().optional()
|
|
65
66
|
})
|
|
66
67
|
});
|
|
67
68
|
const BuilderArtifactFragmentSchema = z.object({
|
|
@@ -1076,7 +1077,7 @@ const createIntermediateRegistry = ({ analyses } = {}) => {
|
|
|
1076
1077
|
const stack = [];
|
|
1077
1078
|
const factory = modules.get(filePath);
|
|
1078
1079
|
if (!factory) {
|
|
1079
|
-
throw
|
|
1080
|
+
throw builderErrors.runtimeModuleLoadFailed(filePath, "", `Module not found or yet to be registered: ${filePath}`);
|
|
1080
1081
|
}
|
|
1081
1082
|
stack.push({
|
|
1082
1083
|
filePath,
|
|
@@ -1114,11 +1115,11 @@ const createIntermediateRegistry = ({ analyses } = {}) => {
|
|
|
1114
1115
|
continue;
|
|
1115
1116
|
}
|
|
1116
1117
|
}
|
|
1117
|
-
throw
|
|
1118
|
+
throw builderErrors.internalInvariant(`Circular dependency detected: ${depPath}`, filePath);
|
|
1118
1119
|
}
|
|
1119
1120
|
const depFactory = modules.get(depPath);
|
|
1120
1121
|
if (!depFactory) {
|
|
1121
|
-
throw
|
|
1122
|
+
throw builderErrors.runtimeModuleLoadFailed(depPath, "", `Module not found or yet to be registered: ${depPath}`);
|
|
1122
1123
|
}
|
|
1123
1124
|
stack.push({
|
|
1124
1125
|
filePath: depPath,
|
|
@@ -1130,7 +1131,7 @@ const createIntermediateRegistry = ({ analyses } = {}) => {
|
|
|
1130
1131
|
}
|
|
1131
1132
|
const result = evaluated.get(filePath);
|
|
1132
1133
|
if (!result) {
|
|
1133
|
-
throw
|
|
1134
|
+
throw builderErrors.runtimeModuleLoadFailed(filePath, "", `Module evaluation failed: ${filePath}`);
|
|
1134
1135
|
}
|
|
1135
1136
|
return result;
|
|
1136
1137
|
};
|
|
@@ -1185,7 +1186,7 @@ const createIntermediateRegistry = ({ analyses } = {}) => {
|
|
|
1185
1186
|
const scheduler = createSyncScheduler();
|
|
1186
1187
|
const result = scheduler.run(() => evaluateElementsGen());
|
|
1187
1188
|
if (result.isErr()) {
|
|
1188
|
-
throw
|
|
1189
|
+
throw builderErrors.internalInvariant(`Element evaluation failed: ${result.error.message}`, "registry.evaluate");
|
|
1189
1190
|
}
|
|
1190
1191
|
return buildArtifacts();
|
|
1191
1192
|
};
|
|
@@ -1204,7 +1205,7 @@ const createIntermediateRegistry = ({ analyses } = {}) => {
|
|
|
1204
1205
|
const scheduler = createAsyncScheduler();
|
|
1205
1206
|
const result = await scheduler.run(() => evaluateElementsGen());
|
|
1206
1207
|
if (result.isErr()) {
|
|
1207
|
-
throw
|
|
1208
|
+
throw builderErrors.internalInvariant(`Element evaluation failed: ${result.error.message}`, "registry.evaluateAsync");
|
|
1208
1209
|
}
|
|
1209
1210
|
return buildArtifacts();
|
|
1210
1211
|
};
|
|
@@ -1326,17 +1327,31 @@ function executeGraphqlSystemModule(modulePath) {
|
|
|
1326
1327
|
if (cachedModulePath === modulePath && cachedGql !== null) {
|
|
1327
1328
|
return { gql: cachedGql };
|
|
1328
1329
|
}
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1330
|
+
let bundledCode;
|
|
1331
|
+
try {
|
|
1332
|
+
bundledCode = readFileSync(modulePath, "utf-8");
|
|
1333
|
+
} catch (error) {
|
|
1334
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1335
|
+
throw builderErrors.runtimeModuleLoadFailed(modulePath, "", `Failed to read GraphQL system module: ${message}`, error);
|
|
1336
|
+
}
|
|
1337
|
+
try {
|
|
1338
|
+
const sandbox = createSandbox(modulePath);
|
|
1339
|
+
new Script(bundledCode, { filename: modulePath }).runInNewContext(sandbox);
|
|
1340
|
+
const finalExports = sandbox.module.exports;
|
|
1341
|
+
const exportedGql = finalExports.gql ?? finalExports.default;
|
|
1342
|
+
if (exportedGql === undefined) {
|
|
1343
|
+
throw builderErrors.runtimeModuleLoadFailed(modulePath, "", `No 'gql' export found in GraphQL system module: ${modulePath}`);
|
|
1344
|
+
}
|
|
1345
|
+
cachedGql = exportedGql;
|
|
1346
|
+
cachedModulePath = modulePath;
|
|
1347
|
+
return { gql: cachedGql };
|
|
1348
|
+
} catch (error) {
|
|
1349
|
+
if (isBuilderError(error)) {
|
|
1350
|
+
throw error;
|
|
1351
|
+
}
|
|
1352
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1353
|
+
throw builderErrors.runtimeModuleLoadFailed(modulePath, "", `GraphQL system module execution failed: ${message}`, error);
|
|
1354
|
+
}
|
|
1340
1355
|
}
|
|
1341
1356
|
/**
|
|
1342
1357
|
* Build intermediate modules from dependency graph.
|
|
@@ -1366,7 +1381,7 @@ const generateIntermediateModules = function* ({ analyses, targetFiles, graphqlS
|
|
|
1366
1381
|
sourceCode
|
|
1367
1382
|
});
|
|
1368
1383
|
if (transpiledCodeResult.isErr()) {
|
|
1369
|
-
|
|
1384
|
+
throw transpiledCodeResult.error;
|
|
1370
1385
|
}
|
|
1371
1386
|
const transpiledCode = transpiledCodeResult.value;
|
|
1372
1387
|
const script = new Script(transpiledCode);
|
|
@@ -1401,8 +1416,11 @@ const setupIntermediateModulesContext = ({ intermediateModules, graphqlSystemPat
|
|
|
1401
1416
|
try {
|
|
1402
1417
|
script.runInContext(vmContext);
|
|
1403
1418
|
} catch (error) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1419
|
+
if (isBuilderError(error)) {
|
|
1420
|
+
throw error;
|
|
1421
|
+
}
|
|
1422
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
1423
|
+
throw builderErrors.runtimeModuleLoadFailed(filePath, "", `Error evaluating intermediate module: ${message}`, error);
|
|
1406
1424
|
}
|
|
1407
1425
|
}
|
|
1408
1426
|
return registry;
|
|
@@ -2571,7 +2589,7 @@ const isGqlDefinitionCall = (identifiers, callExpression) => {
|
|
|
2571
2589
|
return false;
|
|
2572
2590
|
}
|
|
2573
2591
|
const [factory] = callExpression.arguments;
|
|
2574
|
-
if (!factory || !ts.isArrowFunction(factory)) {
|
|
2592
|
+
if (!factory || !(ts.isArrowFunction(factory) || ts.isFunctionExpression(factory))) {
|
|
2575
2593
|
return false;
|
|
2576
2594
|
}
|
|
2577
2595
|
return true;
|
|
@@ -6068,7 +6086,7 @@ const createBuilderSession = (options) => {
|
|
|
6068
6086
|
}
|
|
6069
6087
|
return finalizeBuild(result.value, currentScan);
|
|
6070
6088
|
} catch (error) {
|
|
6071
|
-
if (error
|
|
6089
|
+
if (isBuilderError(error)) {
|
|
6072
6090
|
return err(error);
|
|
6073
6091
|
}
|
|
6074
6092
|
throw error;
|
|
@@ -6098,7 +6116,7 @@ const createBuilderSession = (options) => {
|
|
|
6098
6116
|
}
|
|
6099
6117
|
return finalizeBuild(result.value, currentScan);
|
|
6100
6118
|
} catch (error) {
|
|
6101
|
-
if (error
|
|
6119
|
+
if (isBuilderError(error)) {
|
|
6102
6120
|
return err(error);
|
|
6103
6121
|
}
|
|
6104
6122
|
throw error;
|
|
@@ -6217,7 +6235,7 @@ function* buildGen(input) {
|
|
|
6217
6235
|
* If the cause is already a BuilderError, return it directly to preserve error codes.
|
|
6218
6236
|
*/
|
|
6219
6237
|
const convertSchedulerError = (error) => {
|
|
6220
|
-
if (error.cause
|
|
6238
|
+
if (isBuilderError(error.cause)) {
|
|
6221
6239
|
return error.cause;
|
|
6222
6240
|
}
|
|
6223
6241
|
return builderErrors.internalInvariant(error.message, "scheduler", error.cause);
|
|
@@ -6255,4 +6273,4 @@ const createBuilderService = ({ config, entrypointsOverride }) => {
|
|
|
6255
6273
|
|
|
6256
6274
|
//#endregion
|
|
6257
6275
|
export { getSeverity as _, createGraphqlSystemIdentifyHelper as a, BuilderArtifactSchema as b, BuilderEffects as c, formatBuilderErrorForCLI as d, formatBuilderErrorStructured as f, diagnosticMessages as g, createStandardDiagnostic as h, extractModuleAdjacency as i, FileReadEffect as l, createDiagnostic as m, createBuilderSession as n, __clearGqlCache as o, builderErrors as p, collectAffectedFiles as r, executeSandbox as s, createBuilderService as t, FileStatEffect as u, loadArtifact as v, loadArtifactSync as y };
|
|
6258
|
-
//# sourceMappingURL=service-
|
|
6276
|
+
//# sourceMappingURL=service-B7nDi5Q3.mjs.map
|