fix: make internally-invoked built-in transforms overridable#97
Merged
Conversation
timfish
requested review from
a team,
bizob2828,
jsumners-nr and
rochdev
and removed request for
rochdev
July 15, 2026 19:36
isaacs
approved these changes
Jul 16, 2026
| * into the program body, also ensuring the import is present. | ||
| * | ||
| * @param {{ channelName: string, module: { name: string }, dcModule: string, sourceType: 'module'|'script' }} state | ||
| * @param {{ channelName: string, module: { name: string }, dcModule: string, sourceType: 'module'|'script', transforms: Record<string, Function> }} state |
Contributor
There was a problem hiding this comment.
(not the change being made here, I realize, but the same line) shouldn't this be moduleType? Doesn't seem to match the code it's about.
rochdev
reviewed
Jul 16, 2026
| * aliases resolved to local names) plus runtime fields added by the | ||
| * transformer for the current file. | ||
| */ | ||
| export type TransformState = InstrumentationConfig & { |
Contributor
There was a problem hiding this comment.
Technically, anything can be added to the state. Would that be a problem if a user of the library is also using TypeScript?
Contributor
Author
There was a problem hiding this comment.
Good point. I've improved the types to:
export type KnownState = InstrumentationConfig & {
dcModule: string;
moduleType: ModuleType;
moduleVersion: string;
operator: string;
transforms: Record<string, CustomTransform>;
functionIndex?: number;
};
export type CustomTransform<ExtraState = Record<string, unknown>> = (state: KnownState & ExtraState, node: Node, parent: Node, ancestry: Node[]) => void;This means that downstream users can:
- Discover and access all the known properties
- Set/get any other properties freely (due to
Record<string, unknown>default generic type) - Override the generic type to make accessing of their custom state more type-safe
rochdev
approved these changes
Jul 16, 2026
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.
Built-in transforms called each other by direct reference on the module object (e.g.
tracingChannelDeclaration→tracingChannelImport), so custom transforms registered viaaddTransformwere bypassed on those internal calls.Internal calls now dispatch through a merged transforms map (built-ins plus registered overrides) carried on
state.transforms, so overriding any built-in transform includingtracingChannelImportandtracingChannelDeclarationtakes effect everywhere.Moving the transforms to the state also allows transforms to chain other transforms.
Why might anyone want to override these?
Orchestrion currently only handles the publishing side of the diagnostics channel. It would be great to conditionally initialise the subscriber side too. This change would allow us to override
tracingChannelImportto inject our initialisation code.