Skip to content
This repository has been archived by the owner on Jan 13, 2024. It is now read-only.

Commit

Permalink
dont warn Cannot resolve on non-toplevel. fixes #48 sort of
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed Aug 1, 2017
1 parent 1986f6d commit 0ae96a4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/walker.js
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ class Walker {

try {
detector.detect(body, (node, trying) => {
const { hasDictionary } = record.marker;
const { toplevel } = record.marker;
let d = detector.visitor_SUCCESSFUL(node);
if (d) {
if (d.mustExclude) return false;
Expand All @@ -320,7 +320,7 @@ class Walker {
d = detector.visitor_NONLITERAL(node);
if (d) {
if (d.mustExclude) return false;
const debug = hasDictionary || d.mayExclude || trying;
const debug = !toplevel || d.mayExclude || trying;
const level = debug ? 'debug' : 'warn';
log[level](`Cannot resolve '${d.alias}'`, [ record.file,
'Dynamic require may fail at run time, because the requested file',
Expand All @@ -332,7 +332,7 @@ class Walker {
d = detector.visitor_MALFORMED(node);
if (d) {
// there is no 'mustExclude'
const debug = hasDictionary || trying;
const debug = !toplevel || trying;
const level = debug ? 'debug' : 'warn'; // there is no 'mayExclude'
log[level](`Malformed requirement for '${d.alias}'`, [ record.file ]);
return false;
Expand Down
6 changes: 1 addition & 5 deletions test/test-50-should-disclose-package/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const standard = 'stdout';
function rightReducer (mappy, line, index, right) {
if ((line.indexOf('Cannot resolve') >= 0) ||
(line.indexOf('The file was included') >= 0)) {
let name = path.basename(right[index + 1]);
if (right[index].indexOf(' Warning ') >= 0) name += ' (w)';
const name = path.basename(right[index + 1]);
let value = right[index].split(' as ')[1] || '';
value = value || right[index].split(' Warning ')[1];
if (mappy[name]) assert.equal(mappy[name], value);
Expand Down Expand Up @@ -53,11 +52,8 @@ for (const pub of [ false, true ]) {
assert.equal(lines,
'connect.js = DISCLOSED code (with sources)\n' +
'has-no-license.js = bytecode (no sources)\n' +
'has-no-license.js (w) = Cannot resolve \'hasNoLicenseNonLiteral\'\n' +
'has-permissive-license.js = DISCLOSED code (with sources)\n' +
'has-permissive-license.js (w) = Cannot resolve \'hasPermissiveLicenseNonLiteral\'\n' +
'has-strict-license.js = bytecode (no sources)\n' +
'has-strict-license.js (w) = Cannot resolve \'hasStrictLicenseNonLiteral\'\n' +
'package.json = DISCLOSED code (with sources)\n' +
(pub ? 'test-x-index.js = DISCLOSED code (with sources)\n' :
'test-x-index.js = bytecode (no sources)\n')
Expand Down

0 comments on commit 0ae96a4

Please sign in to comment.