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

Add support of non '.js' main #1291

Merged
merged 1 commit into from
Nov 22, 2015
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
23 changes: 17 additions & 6 deletions lib/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -759,17 +759,28 @@ exports.createMain = function(pkg, pjson, downloadDir) {
return true;
}

if (main) {
if (main.startsWith('./'))
main = main.substr(2);
if (main.endsWith('.js'))
main = main.substr(0, main.length - 3);
if (!main)
return false;

if (main.startsWith('./')) {
main = main.substr(2);
}

return new Promise(function(resolve) {
// Check to see if main points to an actual file or not
// i.e. does it include extension.
mainPath = path.resolve(downloadDir, main);
fs.exists(mainPath, resolve);
});
}).then(function(exists) {
if (exists)
return exists;

main = main || 'index';

// try the package.json main
return new Promise(function(resolve) {
// `main` does not have extension (or it does not point to an actual file).
// Try again with `.js` extension
mainPath = path.resolve(downloadDir, main + '.js');
fs.exists(mainPath, resolve);
});
Expand Down