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.

66 lines
10 KiB

4 years ago
  1. "use strict";
  2. var _object = _interopRequireDefault(require("object.omit"));
  3. var _deepmerge = _interopRequireDefault(require("deepmerge"));
  4. var _core = require("@babel/core");
  5. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  6. function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
  7. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  8. function arrayMerge(source = [], overrides = []) {
  9. return [...new Set([...source, ...overrides])];
  10. }
  11. function mergeArray(source = [], overrides = [], resolve, deepmergeOpts) {
  12. return [...source, ...overrides].reduce((reduction, override) => {
  13. const overrideName = resolve(Array.isArray(override) ? override[0] : override);
  14. const overrideOptions = Array.isArray(override) ? override[1] : {};
  15. const base = reduction.find(base => {
  16. const baseName = resolve(Array.isArray(base) ? base[0] : base);
  17. return baseName === overrideName || baseName.includes(overrideName);
  18. });
  19. const index = reduction.includes(base) ? reduction.indexOf(base) : reduction.length;
  20. const baseName = base ? resolve(Array.isArray(base) ? base[0] : base) : overrideName;
  21. const baseOptions = Array.isArray(base) ? base[1] : {};
  22. const options = (0, _deepmerge.default)(baseOptions, overrideOptions, _objectSpread({
  23. arrayMerge,
  24. isMergeableObject: value => Array.isArray(value)
  25. }, deepmergeOpts));
  26. reduction[index] = Object.keys(options).length ? [baseName, options] : baseName;
  27. return reduction;
  28. }, []);
  29. }
  30. function babelMerge(source = {}, overrides = {}, deepmergeOpts) {
  31. const plugins = mergeArray(source.plugins, overrides.plugins, _core.resolvePlugin, deepmergeOpts);
  32. const presets = mergeArray(source.presets, overrides.presets, _core.resolvePreset, deepmergeOpts);
  33. const sourceEnv = source.env || {};
  34. const overridesEnv = overrides.env || {};
  35. return Object.assign(presets.length ? {
  36. presets
  37. } : {}, plugins.length ? {
  38. plugins
  39. } : {}, _deepmerge.default.all([(0, _object.default)(source, ['plugins', 'presets', 'env']), (0, _object.default)(overrides, ['plugins', 'presets', 'env']), ...[...new Set([...Object.keys(sourceEnv), ...Object.keys(overridesEnv)])].map(name => ({
  40. env: {
  41. [name]: babelMerge(sourceEnv[name], overridesEnv[name], deepmergeOpts)
  42. }
  43. }))], _objectSpread({
  44. arrayMerge
  45. }, deepmergeOpts)));
  46. }
  47. Object.defineProperty(babelMerge, 'all', {
  48. value: (values = [], deepmergeOpts) => values.reduce((acc, value) => {
  49. if (value) {
  50. Object.assign(acc, babelMerge(acc, value, deepmergeOpts));
  51. }
  52. return acc;
  53. }, {})
  54. });
  55. module.exports = babelMerge;
  56. //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi4uL3NyYy9pbmRleC5qcyJdLCJuYW1lcyI6WyJhcnJheU1lcmdlIiwic291cmNlIiwib3ZlcnJpZGVzIiwiU2V0IiwibWVyZ2VBcnJheSIsInJlc29sdmUiLCJkZWVwbWVyZ2VPcHRzIiwicmVkdWNlIiwicmVkdWN0aW9uIiwib3ZlcnJpZGUiLCJvdmVycmlkZU5hbWUiLCJBcnJheSIsImlzQXJyYXkiLCJvdmVycmlkZU9wdGlvbnMiLCJiYXNlIiwiZmluZCIsImJhc2VOYW1lIiwiaW5jbHVkZXMiLCJpbmRleCIsImluZGV4T2YiLCJsZW5ndGgiLCJiYXNlT3B0aW9ucyIsIm9wdGlvbnMiLCJpc01lcmdlYWJsZU9iamVjdCIsInZhbHVlIiwiT2JqZWN0Iiwia2V5cyIsImJhYmVsTWVyZ2UiLCJwbHVna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