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

Commit

Permalink
better check for missing 'main' entry. fixes #162
Browse files Browse the repository at this point in the history
  • Loading branch information
igorklopov committed Jul 26, 2017
1 parent 36f00e9 commit e022659
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 17 deletions.
32 changes: 15 additions & 17 deletions lib/walker.js
Expand Up @@ -219,7 +219,8 @@ class Walker {
if (dependencies[dependency]) {
derivatives.push({
alias: dependency,
aliasType: ALIAS_AS_RESOLVABLE
aliasType: ALIAS_AS_RESOLVABLE,
fromDependencies: true
});
}
}
Expand Down Expand Up @@ -395,10 +396,10 @@ class Walker {
return config;
};

let newFile1, failure;
let newFile, failure;

try {
newFile1 = await follow(derivative.alias, {
newFile = await follow(derivative.alias, {
basedir: path.dirname(record.file),
// default is extensions: ['.js'], but
// it is not enough because 'typos.json'
Expand Down Expand Up @@ -436,12 +437,8 @@ class Walker {
}
// 'babel-runtime' === 'babel-runtime'
if (short === derivative.alias) {
// 1) not near 2) pure package name as alias
// 3) failure to obtain 'main' entry file
// 4) on the other hand newPackage is ok,
// this means we deal with babel-runtime-like
// main-less package. hence no warnings
mainNotFound = failure && newPackage;
mainNotFound = failure && newMarker &&
newMarker.config && !newMarker.config.main;
}
}

Expand All @@ -458,20 +455,21 @@ class Walker {
}

if (failure) {
let { message } = failure;
if (mainNotFound && newMarker.config) {
const { name } = newMarker.config.name;
message = `Package.json.main entry not found in ${name}`;
}
const { hasDictionary } = record.marker;
const debug = hasDictionary || derivative.mayExclude || mainNotFound;
const debug = hasDictionary || derivative.mayExclude ||
(mainNotFound && derivative.fromDependencies);
const level = debug ? 'debug' : 'warn';
log[level](message, [ record.file ]);
if (mainNotFound) {
const message = 'Entry \'main\' not found in %1';
log[level](message, [ newPackage, record.file ]);
} else {
log[level](failure.message, [ record.file ]);
}
return;
}

this.append({
file: newFile1,
file: newFile,
marker: newMarker || record.marker,
store: STORE_BLOB,
reason: record.file
Expand Down
33 changes: 33 additions & 0 deletions test/test-50-invalid-package-json-2/main.js
@@ -0,0 +1,33 @@
#!/usr/bin/env node

'use strict';

const assert = require('assert');
const path = require('path');
const utils = require('../utils.js');

assert(!module.parent);
assert(__dirname === process.cwd());

const target = process.argv[2] || 'host';
const input = './test-x-index.js';
const output = './test-output.exe';
const standard = 'stdout';

let right;

const inspect = (standard === 'stdout')
? [ 'inherit', 'pipe', 'inherit' ]
: [ 'inherit', 'inherit', 'pipe' ];

right = utils.pkg.sync([
'--target', target,
'--output', output, input
], inspect);

assert(right.indexOf('\x1B\x5B') < 0, 'colors detected');
assert(right.indexOf('Warning') >= 0);
assert(right.indexOf('Entry \'main\' not found') >= 0);
assert(right.indexOf('crusader' + path.sep + 'package.json') >= 0);

utils.vacuum.sync(output);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions test/test-50-invalid-package-json-2/test-x-index.js
@@ -0,0 +1,3 @@
'use strict';

require('crusader');

0 comments on commit e022659

Please sign in to comment.