Skip to content

Commit

Permalink
chore: code style parity with locker (#377)
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton authored Aug 19, 2022
1 parent 9719c14 commit 345c15d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
13 changes: 9 additions & 4 deletions scripts/rollup/configs/base.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -13,7 +18,7 @@ function createConfig({
const isCJS = format === 'cjs';

return mergeOptions.call(
{ concatArrays: true },
mergeOptionsConfig,
{
input,
external: [],
Expand All @@ -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' }),
];
},
};
24 changes: 13 additions & 11 deletions scripts/rollup/plugins/babel-output.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
Expand All @@ -47,7 +49,7 @@ module.exports = {
presets: [],
},
config,
options,
clonedOptions,
{
configFile: false,
}
Expand Down

0 comments on commit 345c15d

Please sign in to comment.