Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added debug mode emitting underlying configuration #122

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

FND
Copy link
Contributor

@FND FND commented Oct 3, 2019

this might be useful for debugging, but also for recreating the
corresponding configuration elsewhere (e.g. test cases, migrating away
from faucet etc.)

(sample below)

use cases:

  • @tbse had expressed apprehension WRT potential lock-in, understandably arguing it should be possible to migrate away from faucet (which is perfectly in line with faucet's philosophy). However, turns out directly generating Rollup/Babel configuration files isn't trivial because the programmatic APIs are (slightly) different and because serializing our configuration object afterwards would be unhelpful WRT plugin functions and their respective configuration. So instead we're emitting our configuration as we generate it, allowing informed users to manually-but-easily recreate it elsewhere.
  • When playing with Svelte, but also when creating minimal test cases, I often found myself arduously recreating Rollup configuration that essentially looked the same as faucet's. This should simplify that process somewhat.
sample output
$ FAUCET_ENV=DEBUG npm run compile
> faucet --compact

[DEBUG] ESNext transpilation
[DEBUG] JSX transpilation
transpiling JavaScript for IE 11
[DEBUG] transpiler plugin: @babel/plugin-transform-react-jsx {
    "pragma": "createElement"
}
[DEBUG] plugin: rollup-plugin-babel {
    "exclude": [
        "node_modules/promiscuous/**",
        "node_modules/document-register-element/**"
    ],
    "presets": [
        [
            "@babel/preset-env",
            {
                "modules": false,
                "targets": {
                    "browsers": [
                        "IE 11"
                    ]
                }
            }
        ]
    ],
    "plugins": [
        [
            "@babel/plugin-transform-react-jsx",
            {
                "pragma": "createElement"
            }
        ]
    ]
}
[DEBUG] plugin: rollup-plugin-node-resolve {
    "mainFields": [
        "module",
        "jsnext:main",
        "main"
    ],
    "extensions": [
        ".js",
        ".jsx"
    ]
}
[DEBUG] plugin: rollup-plugin-commonjs {
    "include": "node_modules/**"
}
[DEBUG] plugin: rollup-plugin-terser {
    "compress": false,
    "mangle": false
}
[DEBUG] Rollup settings: {
    "sourcemap": false,
    "compact": true,
    "plugins": [
        {
            "name": "babel"
        },
        {
            "name": "node-resolve"
        },
        {
            "name": "commonjs"
        },
        {
            "name": "terser"
        }
    ],
    "format": "iife"
}

@FND FND requested a review from moonglum October 3, 2019 10:15
// TODO: move into faucet-core
exports.DEBUG = process.env.FAUCET_ENV === "DEBUG";
exports.debug = exports.DEBUG === false ? noop : (...msg) => {
msg = msg.map(arg => (arg && !arg.substr) ? JSON.stringify(arg, null, 4) : arg);
Copy link
Contributor Author

@FND FND Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON.stringify avoids [Object] being emitted for nested objects

it also happens to filter out plugin functions, which might be good or bad

@@ -2,6 +2,13 @@

let NOTIFY = '(typeof alert !== "undefined" ? alert : console.error)';

// TODO: move into faucet-core
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume we agree?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@@ -2,6 +2,13 @@

let NOTIFY = '(typeof alert !== "undefined" ? alert : console.error)';

// TODO: move into faucet-core
exports.DEBUG = process.env.FAUCET_ENV === "DEBUG";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this allows avoiding unnecessary computation by making it conditional:

if(DEBUG) {
    debug(new CryptoMiner());
}

(more likely to be used as a one-liner though: DEBUG && debug(…))

@moonglum
Copy link
Member

moonglum commented Oct 7, 2019

Interesting approach 👌 @tbse would that satisfy your use case?

this might be useful for debugging, but also for recreating the
corresponding configuration elsewhere (e.g. independent test cases,
migrating away from faucet etc.)
@FND FND force-pushed the master branch 4 times, most recently from 3e9a3cd to a4b1278 Compare January 8, 2020 06:48
@moonglum moonglum changed the base branch from master to main March 8, 2022 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants