市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
787 B

  1. import isPlainObject from 'is-plain-obj';
  2. import {FD_SPECIFIC_OPTIONS} from '../arguments/specific.js';
  3. // Deep merge specific options like `env`. Shallow merge the other ones.
  4. export const mergeOptions = (boundOptions, options) => {
  5. const newOptions = Object.fromEntries(
  6. Object.entries(options).map(([optionName, optionValue]) => [
  7. optionName,
  8. mergeOption(optionName, boundOptions[optionName], optionValue),
  9. ]),
  10. );
  11. return {...boundOptions, ...newOptions};
  12. };
  13. const mergeOption = (optionName, boundOptionValue, optionValue) => {
  14. if (DEEP_OPTIONS.has(optionName) && isPlainObject(boundOptionValue) && isPlainObject(optionValue)) {
  15. return {...boundOptionValue, ...optionValue};
  16. }
  17. return optionValue;
  18. };
  19. const DEEP_OPTIONS = new Set(['env', ...FD_SPECIFIC_OPTIONS]);