Add support for the extends keyword - #1306
Open
Sam Frost (SamuelFrost) wants to merge 5 commits into
Open
Sam Frost (SamuelFrost) wants to merge 5 commits into
Sam Frost (SamuelFrost) wants to merge 5 commits into
Conversation
Allow one devcontainer.json to inherit another using the existing image metadata merge logic, rebasing the approach from spec#22 and CLI#311 onto current main.
2 tasks
Author
|
@microsoft-github-policy-service agree |
Optional extendsMergeMode on devcontainer.json selects image-metadata combine (default) or overlay-style override when resolving extends.
Cover override merge in configContainer tests and devcontainer up against the packaged CLI, with lightweight ubuntu fixtures and CI matrix entry.
Override merge now fully replaces each set top-level property from the child config instead of shallow-merging object maps and hostRequirements.
Remove extends up e2e tests and CI matrix entry; slim extends fixtures and colocate mergeDevContainerConfigs tests with imageMetadata.
Sam Frost (SamuelFrost)
marked this pull request as ready for review
September 24, 2026 08:53
Author
|
Requesting review from Christof Marti (@chrmarti), joshspicer, Samruddhi Khandale (@samruddhikhandale), Chuck Lantz (@Chuxel), and @devcontainers/maintainers when you have bandwidth. This implements spec#22 / supersedes CLI #311: Behavior (short):
Companion spec PR: devcontainers/spec#772 Where to look:
Happy to adjust anything that should match maintainer expectations before spec PR #772 merges. Thanks! |
This branch has not been deployed
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
Implements configuration inheritance from spec#22: a
devcontainer.jsoncan inherit another JSON or JSONC file in the same repository viaextends, with optionalextendsMergeMode(combine|override).This reapplies PR #311 on current
main. The default merge path follows review on CLI #311: reuse image metadata merge logic, notdeepmerge.Companion spec PR: devcontainers/spec#772
Does not bump the package version (release PR separately).
Changes
readDevContainerConfigObject(configContainer.ts): parse config, resolveextendsrecursively with cycle detection (seen), validate path and merge mode, merge parent + current file, stripextends/extendsMergeModefrom the resolved object before substitution and workspace setup inreadDevContainerConfigFile.extends: relative path only (resolved from the declaring file); absolute paths and URL-like schemes rejected; stripped from merged output.extendsMergeMode(on the file that declaresextends, defaultcombine):combine: same rules as image metadata merge (forwardPortsunion,hostRequirementsmax, object map key merge, and so on).override: all set top-level keys replace values from extends target; omitted keys keep the resolved parent.mergeDevContainerConfigs(imageMetadata.ts): shared merge implementation forextendsand image-metadata layering.DevContainerExtendsMergeModeand optionalextends/extendsMergeModeonDevContainerConfig(configuration.ts).src/test/configContainer.test.ts—readDevContainerConfigFilewith fixtures undersrc/test/configs/extends/(default combine, nested chain, cycle, missing parent, invalid merge mode, override mode).src/test/imageMetadata.test.ts— top-levelmergeDevContainerConfigsunit tests (combineandoverride), sibling todescribe('Image Metadata')so they do not run the Docker/npm install hook.Technical choices (from CLI #311 review)
Christof Marti, Josh Spicer, and Chuck Lantz asked to align
extendswith image metadata merge for the default path so inheriting a file matches combining a prebuilt image’s metadata with a projectdevcontainer.json.Relative-path-only matches spec#22 (same repository). Nested
extendsis supported with cycle detection (CLI #311 left nested references unresolved).Test plan
env TS_NODE_PROJECT=src/test/tsconfig.json npx mocha -r ts-node/register --exit src/test/configContainer.test.tsenv TS_NODE_PROJECT=src/test/tsconfig.json npx mocha -r ts-node/register --exit src/test/imageMetadata.test.ts -g mergeDevContainerConfigsyarn type-checkyarn lintconfigContainer.test.tsruns in the catch-alltests-matrixshard (src/test/**/*.test.tswith excludes); no dedicated matrix row for extends.Additional decisions (beyond original CLI #311 and changes requested during the review)
extendsMergeMode(combinedefault,override) instead of merge-only behavior7c7d1cac4e9697Follow-up
After maintainer approval,
CONTRIBUTING.mdasks for a docs PR to the devcontainer.json reference in vscode-docs.Implements spec#22. Supersedes CLI #311.