Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow partial configs in environment overrides #1026

Merged
merged 6 commits into from
Feb 4, 2025

Conversation

jpage-godaddy
Copy link
Contributor

Summary

Fix the TypeScript types so that you don't have to do a full set of config keys in environment overrides to avoid TypeScript errors.

Changelog

Test Plan

Added type test

Fix the TypeScript types so that you don't have to do a full set of config keys in environment overrides
@jpage-godaddy jpage-godaddy requested a review from a team as a code owner January 31, 2025 19:49
@@ -118,7 +118,7 @@ createCommand.action = async function run(appname, options, command) {

const pluginGasket = makeGasket({
...context.presetConfig,
plugins: context.presets.concat(context.presetConfig.plugins)
plugins: context.presetConfig.plugins.concat(context.presets)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is just an annoying limitation of TypeScript. Because context.presets is of type Array<Plugin> it cannot concatenate in Array<Plugin | { default: Plugin }> because concat is defined such where the return value is supposed to be the same as the original array. However, it can do this in the reverse order. I assume that the order of plugins doesn't matter.

@@ -38,7 +38,7 @@ export class Gasket {
// prune nullish and/or empty plugins
config.plugins = config.plugins
.filter(Boolean)
.map(plugin => plugin.default || plugin) // quality of life for cjs apps
.map(plugin => 'default' in plugin ? plugin.default : plugin) // quality of life for cjs apps
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TypeScript is able to use an in check to narrow a type; seeing if a default property is falsy doesn't do the same, so the old expression wasn't able to be resolved as a Plugin object.

@agerard-godaddy agerard-godaddy merged commit 02c4748 into main Feb 4, 2025
2 checks passed
@agerard-godaddy agerard-godaddy deleted the fix-config-partiality branch February 4, 2025 14:52
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