From 345c15d9fed45f3184ef431fadec6e9bb6ec69fd Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Fri, 19 Aug 2022 09:37:17 -0700 Subject: [PATCH] chore: code style parity with locker (#377) --- scripts/rollup/configs/base.cjs | 13 +++++++++---- scripts/rollup/plugins/babel-output.cjs | 24 +++++++++++++----------- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/scripts/rollup/configs/base.cjs b/scripts/rollup/configs/base.cjs index a6162b44..8ce72d5d 100644 --- a/scripts/rollup/configs/base.cjs +++ b/scripts/rollup/configs/base.cjs @@ -4,6 +4,11 @@ const mergeOptions = require('merge-options'); const typescriptPlugin = require('@rollup/plugin-typescript'); const { getBabelOutputPlugin } = require('../plugins/babel-output.cjs'); +const mergeOptionsConfig = { + concatArrays: true, + ignoreUndefined: true, +}; + function createConfig({ // prettier-ignore input = 'src/index.ts', @@ -13,7 +18,7 @@ function createConfig({ const isCJS = format === 'cjs'; return mergeOptions.call( - { concatArrays: true }, + mergeOptionsConfig, { input, external: [], @@ -36,10 +41,10 @@ function createConfig({ } module.exports = { - rollupConfig(options = {}) { + rollupConfig(providedOptions) { return [ - createConfig({ ...options, format: 'es' }), - createConfig({ ...options, format: 'cjs' }), + createConfig({ ...providedOptions, format: 'es' }), + createConfig({ ...providedOptions, format: 'cjs' }), ]; }, }; diff --git a/scripts/rollup/plugins/babel-output.cjs b/scripts/rollup/plugins/babel-output.cjs index bb1c1804..7e8cf3f0 100644 --- a/scripts/rollup/plugins/babel-output.cjs +++ b/scripts/rollup/plugins/babel-output.cjs @@ -8,15 +8,16 @@ const path = require('path'); const rootPath = path.resolve(__dirname, '../../../'); +const mergeOptionsConfig = { + ignoreUndefined: true, +}; + module.exports = { - getBabelOutputPlugin(providedOptions = {}) { - const options = { - __proto__: null, - ...providedOptions, - }; - const { banner, footer } = options; - delete options.banner; - delete options.footer; + getBabelOutputPlugin(providedOptions) { + const clonedOptions = { ...providedOptions }; + const { banner, footer } = clonedOptions; + delete clonedOptions.banner; + delete clonedOptions.footer; let babelOutputHooks; return { name: 'babel-output', @@ -31,14 +32,15 @@ module.exports = { // https://github.com/babel/babel/blob/v7.15.6/packages/babel-core/src/config/files/configuration.ts#L24 const configPath = // prettier-ignore - options.configFile ?? + clonedOptions.configFile ?? (await globby([`${path.resolve('.babelrc')}{,.js,.cjs,.mjs,.json}`]))[0] ?? (await globby([`${path.resolve(rootPath, 'babel.config')}{.js,.cjs,.mjs,.json}`]))[0]; const config = path.extname(configPath) === '.json' ? await fs.readJSON(configPath) : (await import(configPath)).default; - const mergedOptions = mergeOptions( + const mergedOptions = mergeOptions.call( + mergeOptionsConfig, { allowAllFormats: true, babelrc: false, @@ -47,7 +49,7 @@ module.exports = { presets: [], }, config, - options, + clonedOptions, { configFile: false, }