fix(compiler): resolve emitter options for subpath exports - #11746
Open
Tanvir Alam (tanvir-ux) wants to merge 2 commits into
Open
fix(compiler): resolve emitter options for subpath exports#11746Tanvir Alam (tanvir-ux) wants to merge 2 commits into
Tanvir Alam (tanvir-ux) wants to merge 2 commits into
Conversation
Prefer the tspconfig emitter specifier when looking up options so packages exposed as subpath exports receive their configured options. Fixes microsoft#10200
|
Azure Pipelines: Successfully started running 1 pipeline(s). 1 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes @typespec/compiler emitter option resolution when emitters are exposed via subpath exports (e.g. @org/pkg/typescript), by preferring the emitter specifier from tspconfig.yaml/CLI options while retaining backwards compatibility via fallback to the package/library name.
Changes:
- Update
loadEmitter()to resolve emitter options using the emit specifier first, then fall back tometadata.name. - Add compiler tests covering subpath-export emitters (specifier-keyed options + package-name fallback).
- Add a Chronus changelog entry for the compiler fix.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
packages/compiler/src/core/program.ts |
Adjusts emitter options lookup order to support subpath export specifiers. |
packages/compiler/test/core/emitter-options.test.ts |
Adds regression tests for subpath-export emitter option resolution behavior. |
.chronus/changes/fix-subpath-emitter-options-2026-8-22.md |
Changelog entry documenting the compiler fix. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
636
to
638
| if (emitterOutputDir === undefined) { | ||
| emitterOutputDir = [options.outputDir, metadata.name].filter(isDefined).join("/"); | ||
| } |
Comment on lines
+632
to
+635
| let { "emitter-output-dir": emitterOutputDir, ...emitterOptions } = | ||
| emittersOptions[metadata.name ?? emitterNameOrPath] ?? {}; | ||
| emittersOptions[emitterNameOrPath] ?? | ||
| (metadata.name !== undefined ? emittersOptions[metadata.name] : undefined) ?? | ||
| {}; |
Author
|
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
packages/compiler/src/core/program.ts:645
- Default
emitterOutputDiris still derived frommetadata.name(package.json name for module emitters). With multiple subpath-export emitters from the same package, this can route different emitters into the same default output directory unless users explicitly setemitter-output-dir. Consider using the emit specifier for module emitters to avoid collisions.
if (emitterOutputDir === undefined) {
emitterOutputDir = [options.outputDir, metadata.name].filter(isDefined).join("/");
}
Comment on lines
+630
to
+634
| // Prefer the specifier from tspconfig so subpath exports get matching options. | ||
| // Fall back to package.json name for file emitters and older configs. | ||
| const optionsFromSpecifier = emittersOptions[emitterNameOrPath]; | ||
| const optionsFromPackageName = | ||
| metadata.name !== undefined ? emittersOptions[metadata.name] : undefined; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
loadEmitter()looked up tspconfig options withmetadata.namefrom the parentpackage.json, so emitters exposed as subpath exports (e.g.@org/pkg/typescript) never matched the key users actually wrote.Prefer the emit specifier, then fall back to the package name so file emitters and older configs still work.
Fixes #10200