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

fix(importer): support nodejs module default main file "index.js" when "main" is missing in package.json #842

Merged
merged 1 commit into from
Apr 29, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/importer/strategies/amodro.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ const path = require('path');
const amodroTrace = require('../../build/amodro-trace');
const cjsTransform = require('../../build/amodro-trace/read/cjs');

// nodejs default main is index.js
const DEFAULT_MAIN = 'index.js';

let AmodroStrategy = class {

static inject() { return ['package']; }
Expand All @@ -16,7 +19,15 @@ let AmodroStrategy = class {

applies() {
if (!this.package.main) {
logger.debug('This package did not specify a "main" file in package.json. Skipping');
let defaultMainPath = path.join(process.cwd(), 'node_modules', this.package.name, DEFAULT_MAIN);

if (fs.existsSync(defaultMainPath)) {
this.package.main = DEFAULT_MAIN;
return true;
}

logger.debug('This package neither specified a "main" file in package.json, ' +
'nor provided default ' + DEFAULT_MAIN + ' file. Skipping');
return false;
}

Expand Down