Skip to content

Commit

Permalink
feat: Reconfigure logging with 'log' utility
Browse files Browse the repository at this point in the history
  • Loading branch information
medikoo committed Nov 29, 2019
1 parent 1ce9ab7 commit a53f9a9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 25 deletions.
10 changes: 6 additions & 4 deletions bin/webmake.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

"use strict";

require("log-node")({ defaultNamespace: "webmake" });

const count = require("es5-ext/object/count")
, { resolve } = require("path")
, log = require("log").get("webmake")
, webmake = require("..");

const { isArray } = Array, { now } = Date;
Expand Down Expand Up @@ -58,9 +61,8 @@ webmake(input, options).done(parser => {
process.stdout.write(parser);
return;
}
process.stdout.write(
`Done [${ parser.modulesFiles.length } modules from ${
count(parser.packages)
} packages in ${ (time / 1000).toFixed(2) }s]\n`
log.notice(
"Done [%d modules from %d packages in %ds]", parser.modulesFiles.length,
count(parser.packages), (time / 1000).toFixed(2)
);
});
21 changes: 10 additions & 11 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ const aFrom = require("es5-ext/arra
, getRequire = require("next/module/get-require")
, findRoot = require("next/module/find-package-root")
, { readFile } = require("fs2/read-file")
, findRequires = require("find-requires");
, findRequires = require("find-requires")
, log = require("log").get("webmake");

const { isArray } = Array
, { create, keys } = Object
Expand Down Expand Up @@ -77,9 +78,7 @@ const parseDependencies = function (text, filename, ignoreErrors) {
"DYNAMIC_REQUIRE"
);
}
console.warn(
`Not parsable require call (ignored): \`${ node.raw }\` at ${ filename }:${ node.line }`
);
log.warn("Not parsable require call (ignored): %s at %s:%d", node.raw, filename, node.line);
return false;
});
};
Expand Down Expand Up @@ -319,7 +318,7 @@ const parser = {
})(() => path.slice(0, -extname(path).length).replace(/\\/gu, "/"));
},
readFile(filename, name, scope, tree) {
// console.log("PC", filename);
log.debug("read %s", filename);
const read = this.cache ? readFileDataCached : readFileData;
return read(filename, this, filename.split(sep).slice(-2 - tree.length).join("/"))(data => {
this.modulesFiles.push(filename);
Expand All @@ -330,7 +329,7 @@ const parser = {
});
},
resolve(fromfile, currentDirname, scope, tree, dep) {
// console.log("R", dep.value);
log.debug("resolve %s", dep.value);
tree = aFrom(tree);
if (dep.value[0] === ".") {
return this.resolveLocal(fromfile, currentDirname, scope, tree, dep);
Expand All @@ -339,7 +338,7 @@ const parser = {
},
resolveLocal(fromfile, dirpath, scope, tree, dep, orgFn, lScope) {
const filename = dep.localFilename || dep.value, { extNames } = this;
// console.log("RL", filename, dirpath, fromfile, tree.length);
log.debug("resolve local %s %s %s %d", filename, dirpath, fromfile, tree.length);

if (!lScope) lScope = scope;
if (!orgFn) orgFn = filename;
Expand Down Expand Up @@ -472,7 +471,7 @@ const parser = {
);
},
resolveExternal(fromfile, fileDirname, scope, dep) {
// console.log("RE", dep.value);
log.debug("resolve external %s", dep.value);
const org = dep.value, lScope = scope;
let filename = join(dep.value), tree, currentRequire, main, path, ext;

Expand Down Expand Up @@ -524,7 +523,7 @@ const parser = {
" path, it will be picked up by Webmake.\n"
);
}
console.warn(`Require of native ${ stringify(name) } approached (ignored)`);
log.warn("Require of native %s approached (ignored)", name);
return null;
}
}
Expand Down Expand Up @@ -556,12 +555,12 @@ const parser = {
promise.aside(currentModule => { this.modules[name] = currentModule; });
return promise;
})()(currentScope => {
// console.log('RFT', name, this.modules[name] === scope);
log.debug("RFT %s %o", name, this.modules[name] === scope);
if (!currentScope) return null;
tree = [];
if (name === filename) filename = currentScope[":mainpath:"] || "index";
else filename = filename.slice(name.length + 1);
// console.log("RE", name, scope, filename);
log.debug("RE %s %o %s", name, scope, filename);
dep.localFilename = filename;
return this.resolveLocal(
fromfile, this.packages[name], currentScope, tree, dep, org, lScope
Expand Down
13 changes: 3 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
"es5-ext": "^0.10.53",
"find-requires": "^1.0.0",
"fs2": "^0.3.7",
"log": "^6.0.0",
"log-node": "^7.0.0",
"memoizee": "^0.4.14",
"ncjsm": "^4.0.1",
"next": "^0.4.1",
Expand Down Expand Up @@ -67,16 +69,7 @@
"extends": "medikoo/node",
"root": true,
"rules": {
"max-lines": "off",
"no-console": [
"error",
{
"allow": [
"warn",
"error"
]
}
]
"max-lines": "off"
}
},
"prettier": {
Expand Down

0 comments on commit a53f9a9

Please sign in to comment.