Skip to content

Commit

Permalink
feat: add debugger
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Mar 6, 2020
1 parent 061ce1e commit d2c090d
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions bin/runner.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const get = require("lodash.get");

module.exports = flags => {
const debug = require("../lib/debug");
debug.config(flags.debug);

if (flags.watchspawn || get(flags, "debug.spawn")) {
require("../lib/spawnHook").hook();
}
Expand Down
6 changes: 6 additions & 0 deletions lib/createInlinePluginCreator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const wait = require("./wait");
const getCommitsFiltered = require("./getCommitsFiltered");
const getManifest = require("./getManifest");
const hasChangedDeep = require("./hasChangedDeep");
const debug = require("./debug");

/**
* Create an inline plugin creator for a multirelease.
Expand All @@ -30,9 +31,12 @@ function createInlinePluginCreator(packages, multiContext) {
* @internal
*/
const updateManifestDeps = (pkg, path) => {
const dbg = debug.create("deps");

// Get and parse manifest file contents.
const manifest = getManifest(path);

dbg("name=", manifest.name);
// Loop through localDeps to update dependencies/devDependencies/peerDependencies in manifest.
pkg._localDeps.forEach(d => {
// Get version of dependency.
Expand All @@ -46,6 +50,8 @@ function createInlinePluginCreator(packages, multiContext) {
if (manifest.dependencies.hasOwnProperty(d.name)) manifest.dependencies[d.name] = release.version;
if (manifest.devDependencies.hasOwnProperty(d.name)) manifest.devDependencies[d.name] = release.version;
if (manifest.peerDependencies.hasOwnProperty(d.name)) manifest.peerDependencies[d.name] = release.version;

dbg("dep.name=", d.name, "dep.version=", release.version);
});

// Write package.json back out.
Expand Down
22 changes: 22 additions & 0 deletions lib/debug.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const get = require("lodash.get");
const getLogger = require("./getLogger");
const logger = getLogger({
stdout: process.stdout,
stderr: process.stderr
});

let opts;

const createDebugger = prefix => (...input) => {
const enabled = get(opts, "debug" + (prefix ? "." + prefix : ""));

if (enabled) {
return logger.log(...input);
}
};

const debug = createDebugger();
debug.config = flags => (opts = flags);
debug.create = createDebugger;

module.exports = debug;

0 comments on commit d2c090d

Please sign in to comment.