Skip to content

Commit

Permalink
add blank-line-removal plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
lobsterkatie committed Apr 27, 2022
1 parent b5c39e2 commit 5a0d4ab
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rollup/npmHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import deepMerge from 'deepmerge';
import {
makeConstToVarPlugin,
makeNodeResolvePlugin,
makeRemoveBlankLinesPlugin,
makeRemoveESLintCommentsPlugin,
makeSucrasePlugin,
} from './plugins/index.js';
Expand All @@ -28,6 +29,7 @@ export function makeBaseNPMConfig(options = {}) {
const sucrasePlugin = makeSucrasePlugin();
const constToVarPlugin = makeConstToVarPlugin();
const removeESLintCommentsPlugin = makeRemoveESLintCommentsPlugin();
const removeBlankLinesPlugin = makeRemoveBlankLinesPlugin();

return {
input: entrypoints,
Expand Down Expand Up @@ -68,7 +70,7 @@ export function makeBaseNPMConfig(options = {}) {
interop: esModuleInterop ? 'auto' : 'esModule',
},

plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin],
plugins: [nodeResolvePlugin, sucrasePlugin, constToVarPlugin, removeESLintCommentsPlugin, removeBlankLinesPlugin],

// don't include imported modules from outside the package in the final output
external: [
Expand Down
16 changes: 16 additions & 0 deletions rollup/plugins/npmPlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,19 @@ export function makeRemoveESLintCommentsPlugin() {
],
});
}

/**
* Create a plugin to strip multiple consecutive blank lines, with or without whitespace in them. from the output.
*
* @returns A `rollup-plugin-re` instance.
*/
export function makeRemoveBlankLinesPlugin() {
return regexReplace({
patterns: [
{
test: /\n(\n\s*)+\n/g,
replace: '\n\n',
},
],
});
}

0 comments on commit 5a0d4ab

Please sign in to comment.