feat: support plugin configuration in bsconfig and CLI#1706
Draft
TwitchBronBron wants to merge 2 commits into
Draft
feat: support plugin configuration in bsconfig and CLI#1706TwitchBronBron wants to merge 2 commits into
TwitchBronBron wants to merge 2 commits into
Conversation
Allow `plugins` entries in `bsconfig.json` to be objects with `src`, optional `name`, and optional `config` (inline object or path to a JSONC file) in addition to the existing string shorthand. Introduces a new `Plugin.onSetConfiguration(config)` lifecycle hook that fires on every plugin immediately after load. CLI flags of the form `--plugin.<name>.<key>=<value>` deep-merge on top of the bsconfig plugin config. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
|
Should this be in v1? If not, can we change some stuff to match what v1 is doing with plugins? For Example changing event names.. "onSetConfiguration" -> "setConfiguration" (verb_noun format) |
… plugin overrides - Pre-tokenize argv for --plugin <src> [<name>] pairs (yargs can't natively distinguish a name positional from another src in an array form). - Add `pluginOverrides` runtime field with replace/merge semantics: bare --plugin.<id>=<value> fully replaces the bsconfig config (loading a JSONC file if the value is a path); --plugin.<id>.<prop>=<value> deep-merges. - Resolve override identifiers with strict precedence: bsconfig user-supplied `name` → factory `name` → bsconfig `src`. A higher-priority match wins outright; ambiguity at the chosen level hard-fails with a clear message. - Add a flat-key parser supporting double-quoted segments at any position so ids/props containing dots can be addressed without escaping. - Document the new CLI behavior and naming precedence in docs/plugins.md. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
bsconfig.jsonpluginsentries can now be objects:{ src, name?, config? }.configis either an inline object or a path to a JSONC file (parsed with comments).Plugin.onSetConfiguration(config)lifecycle hook fires on every plugin immediately after load (string-shorthand plugins receive{}).--plugin <src> [<name>]pair syntax to load and name a plugin in one flag (repeatable). Coexists with the existing--plugins(plural) array form.--plugin.<id>.<prop>=<value>deep-merges on top of the bsconfig-provided config. A bare--plugin.<id>=<value>(no dotted path) replaces the bsconfigconfigentirely (loading a JSONC file if the value is a path); the two forms can be combined.<id>is resolved with strict precedence: bsconfig user-suppliedname→ factoryname→ bsconfigsrc. A higher-priority match wins outright; ambiguity at the chosen level hard-fails with a clear message."@scope/x","id.with.dots") are supported at any position in the dotted key so ids or props containing dots can be addressed without escaping.docs/plugins.mdto cover naming precedence, replace vs. merge, and quoting rules, with worked examples for each.Implementation notes
util.loadPluginsnow returnsArray<{ plugin, config, entry }>so the caller can match a plugin against its original bsconfig identity.pluginOverrides?: Record<string, { replace?, merge? }>runtime field onBsConfig(CLI-only — not loaded frombsconfig.json).util.ts:extractPluginEntriesFromArgv— pre-tokenizes argv for--plugin <src> [<name>]pairs before yargs runs (yargs can't natively distinguish a name positional from another src in an array form).parsePluginOverrideKey— tokenizes a dotted key, honoring"..."quoting at any segment.extractPluginOverridesFromArgv— walks an argv map and builds the structuredpluginOverridesobject.deepMerge,resolvePluginConfig(loads JSONC).ProgramBuilder.loadPluginsdoes the override resolution: matches each<id>via the precedence above, appliesreplacefirst (resolving JSONC paths), then deep-mergesmergeon top, then dispatchesonSetConfiguration.util.resolvePathsRelativeTohandlesPluginDefinitionobjects so relativesrcand (file-path)configresolve against the cwd/bsconfig directory. Pair entries collected by the pre-tokenizer flow through this same path resolution.Test plan
npm run buildcleannpm run lintcleannpm run test:nocover— 2633 passing, 0 failing (+ 40 new test cases acrossutil.spec.tsandProgramBuilder.spec.ts)onSetConfigurationreceives the merged values--plugin <src> <name>pair syntax, with and without an inline name--plugin.<id>.<prop>=<value>merge override--plugin.<id>=./config.jsonctotal replacement, plus replace+merge combo🤖 Generated with Claude Code