MCPcopy Index your code
hub / github.com/betaorbust/babel-plugin-groundskeeper-willie

github.com/betaorbust/babel-plugin-groundskeeper-willie @v2.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v2.0.0 ↗ · + Follow
26 symbols 30 edges 23 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Groundskeeper Willie Babel Plugin

NPM Version

This project is a Babel plugin encompassing and expanding the functionality of the very useful Groundskeeper utility. Remaking Groundskeeper's features as a Babel plugin gives ongoing support to ES2015+, while greatly reducing runtime for those already using Babel in their build process.

This plugin will:

  • Remove console statements, so your production code doesn't junk up the console, but your development code can be as verbose as you wish.

  • To keep specific console statements, you can disable Groundskeeper Willie by adding a line disable directive, which makes it significantly more flexible compared to babel-plugin-transform-remove-console

Source:

javascript console.log(`I'll be removed.`); console.log(`I'll be preserved!`); // groundskeeper-willie-disable-line

Result:

javascript console.log(`I'll be preserved!`); // groundskeeper-willie-disable-line

  • Remove debugger statements, so you don't accidentally ship halting code.

  • Same as above, you can disable this in specific cases with a line disable directive.

Source:

javascript () => { debugger; do.something(); debugger; // groundskeeper-willie-disable-line }

Result:

javascript () => { do.something(); debugger; // groundskeeper-willie-disable-line }

  • Remove code between comment <pragmas>, so you can use your debug code in development, but strip it out in production.

Source:

javascript module.exports = { prodFunction() { /* ... */ }, // <testCode> testFunction() { /* ... */ }, //</testCode> otherProdCode() { /* ... */ }, };

Result:

javascript module.exports = { prodFunction() { /* ... */ }, otherProdCode() { /* ... */ }, };

Complete Example:

Input:

Here we have a file that has some development code, a console, etc.

module.exports = {
    appCode(){
        console.log(`We're running with scissors!`);
        return [
            'included',
            /*<otherPragma>*/
            'excluded',
            /*</otherPragma>*/
            'also included'];
    }
};

//<debug>
module.exports.debugCode = {
    do.debugging.things.that.should.not.be.in.production();
}
//</debug>

Output:

When run with the Groundskeeper Willie plugin, we'll get back:

module.exports = {
    appCode() {
        return ['included', 'also included'];
    },
};

Why would you do that?

Right now, we (at Netflix) use pragmas so that our developer logging, debug code, and other related exports can live alongside the production code, but, at distribution time, we can ship down the smallest payload, without junking up the console, or sending extra unused code.

What's a pragma?

For the purposes of our little plugin, pragmas are comments that have an opening tag, and a closing tag, with a provided name. The pragma may appear in either a line comment or a block comment, and look like HTML/XML-esq open and close tags.

//<thisIsAPragma>
const removed = code.that.will.be.removed();
//</thisIsAPragma>
return ['included', /* <other> */ 'excluded', /* </other> */ 'also included'];

Plugin Options

The following are the available options with their default values.

{
    "plugins": [
        [
            "groundskeeper-willie",
            {
                "removeConsole": true,
                "removeDebugger": true,
                "removePragma": true
            }
        ]
    ]
}

removeConsole

If you wish to leave in all console statements, set this to false.

removeDebugger

If you wish to leave in all debugger statements, set this to false.

removePragma

If you wish to leave in all pragmas-wrapped code, stet this to false.

Extension points exported contracts — how you extend this code

Babel (Interface)
(no doc)
src/index.ts
PluginOptions (Interface)
(no doc)
src/index.ts

Core symbols most depended-on inside this repo

isLineDisableComment
called by 1
src/helpers.ts
love
called by 0
test/fixtures/respect-removePragma-option/expected.js
love
called by 0
test/fixtures/respect-removePragma-option/actual.js
love
called by 0
test/fixtures/respect-removeDebugger-option/expected.js
love
called by 0
test/fixtures/respect-removeDebugger-option/actual.js
like
called by 0
test/fixtures/remove-debugger-calls/expected.js
like
called by 0
test/fixtures/remove-debugger-calls/actual.js
plugin
called by 0
src/index.ts

Shape

Function 24
Interface 2

Languages

TypeScript100%

Modules by API surface

src/index.ts7 symbols
src/helpers.ts5 symbols
examples/examples-before.js4 symbols
examples/examples-after.js3 symbols
test/index.test.js1 symbols
test/fixtures/respect-removePragma-option/expected.js1 symbols
test/fixtures/respect-removePragma-option/actual.js1 symbols
test/fixtures/respect-removeDebugger-option/expected.js1 symbols
test/fixtures/respect-removeDebugger-option/actual.js1 symbols
test/fixtures/remove-debugger-calls/expected.js1 symbols
test/fixtures/remove-debugger-calls/actual.js1 symbols

For agents

$ claude mcp add babel-plugin-groundskeeper-willie \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page