Skip to content

feat: add possibility to amend configuration in a plugin#5124

Merged
marcoscaceres merged 8 commits intospeced:mainfrom
Logius-standaarden:amend-configuration-in-utils
Apr 12, 2026
Merged

feat: add possibility to amend configuration in a plugin#5124
marcoscaceres merged 8 commits intospeced:mainfrom
Logius-standaarden:amend-configuration-in-utils

Conversation

@TimvdLippe
Copy link
Copy Markdown
Collaborator

We have a preProcess plugin that needs to store some information for later use when a document is rendered. Currently, it is not possible to update the initialUserConfig config object, since any update to the config object is ignored. These updates in plugins are visible to other plugins, but not to the rendered document.

There is a way to update the object with "amend-user-config", but that requires publishing to the internal system. That system isn't accessible to a plugin.

Therefore, add a new method that can be called with an Object that forwards it to the internal publication system. That way, a plugin can update configuration (like some of the core plugins do) and update the initialUserConfig.

@TimvdLippe TimvdLippe requested a review from sidvishnoi March 26, 2026 12:24
@TimvdLippe TimvdLippe force-pushed the amend-configuration-in-utils branch 2 times, most recently from 4246477 to 001cf3d Compare March 26, 2026 12:32
We have a `preProcess` plugin that needs to store some information
for later use when a document is rendered. Currently, it is not
possible to update the `initialUserConfig` config object, since
any update to the `config` object is ignored. These updates in
plugins are visible to other plugins, but not to the rendered
document.

There is a way to update the object with `"amend-user-config"`,
but that requires publishing to the internal system. That system
isn't accessible to a plugin.

Therefore, add a new method that can be called with an `Object`
that forwards it to the internal publication system. That way,
a plugin can update configuration (like some of the core plugins
do) and update the `initialUserConfig`.
@TimvdLippe TimvdLippe force-pushed the amend-configuration-in-utils branch from 001cf3d to 04fa3c6 Compare March 26, 2026 12:33
@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

I don't think these test failures are related to my change

@marcoscaceres
Copy link
Copy Markdown
Contributor

@TimvdLippe, should be ok after rebase.

Copy link
Copy Markdown
Contributor

@marcoscaceres marcoscaceres left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case is legitimate and the implementation is correct — pub("amend-user-config", ...) is exactly what core plugins use (e.g. caniuse.js), and routing it through makePluginUtils is the right pattern.

A few things worth addressing:

Type is too wide

/** @type {(configUpdates: Object) => void} */

Object (uppercase) is the constructor type and accepts null in some contexts. The other entries in makePluginUtils use more specific types. Suggest:

/** @type {(configUpdates: Record<string, unknown>) => void} */

Missing test

There's no test verifying that calling utils.amendConfiguration({ key: "value" }) from a preProcess function results in that key appearing in #initialUserConfig. The existing include-config-spec.js tests would be the right place to add one.

Missing docs

preProcess and postProcess docs mention the utils argument but don't document what's on it. Worth adding amendConfiguration to those pages (and the wiki) so authors know it exists.

The type nit and docs are minor — happy to see this land once there's a test.

@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

Your comments appear to contradict each other. Based on the first comment, I would assume that a rebase is sufficient. However, your second comment (presumably generated by AI) implies that more work is needed. Then your third comment only picks one of the points of the AI comment, which I need to do after the PR merge.

Can you please give me guidance which action I should take?

@marcoscaceres
Copy link
Copy Markdown
Contributor

Lol, sorry! the first comment was right. Deleted the second.

@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

include-config-spec.js is a unit test and doesn't play nicely with preProcess plugins. In fact, I think it is broken, since when I wrote it as a unit test, it would fail as doc.defaultView is null.

Instead, I added to the existing integration test for preProcess plugins.

@TimvdLippe TimvdLippe changed the title Add possibility to amend configuration in a plugin feat: add possibility to amend configuration in a plugin Mar 30, 2026
@marcoscaceres
Copy link
Copy Markdown
Contributor

I’ll take a look

@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

Do you mind doing that as a follow-up so that we can merge as-is? The implementation at least looks good

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables pre-/post-process plugins to update the document’s emitted initialUserConfig (via the existing internal amend-user-config pubsub topic) by exposing a new helper on the plugin utils object.

Changes:

  • Add utils.amendConfiguration() to makePluginUtils() to publish config updates to "amend-user-config".
  • Extend the pre-process spec fixture to call amendConfiguration() during preProcess.
  • Add a spec assertion that initialUserConfig reflects the amended configuration.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/spec/core/pre-process-spec.js Adds a test asserting initialUserConfig contains the amended value.
tests/spec/core/pre-process-spec.html Adds a preProcess function that calls utils.amendConfiguration() with updates.
src/core/utils.js Exposes amendConfiguration() on the plugin utils object via pubsub.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

TimvdLippe and others added 2 commits April 7, 2026 07:09
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@TimvdLippe TimvdLippe requested a review from marcoscaceres April 7, 2026 08:19
@marcoscaceres
Copy link
Copy Markdown
Contributor

Hey @TimvdLippe — could you rebase onto main? I'll merge once it's up to date.

@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

Sure, clicked the update button.

@marcoscaceres
Copy link
Copy Markdown
Contributor

Gah, sorry, one more time (I needed to land a hotfix before). I think there’s also a checkbox somewhere in GitHub that allows me also to do the updates.

@TimvdLippe
Copy link
Copy Markdown
Collaborator Author

https://github.com/orgs/community/discussions/5634

Currently, if a PR is created from a fork living under an organisation (rather than an individual) it's not possible to allow edits by maintainers.

That's the case with ours, since I created it from the Logius-Standaarden fork :/

@marcoscaceres marcoscaceres merged commit 855090b into speced:main Apr 12, 2026
18 of 23 checks passed
@marcoscaceres
Copy link
Copy Markdown
Contributor

All good... merged to avoid the rebase ping pong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants