Open pdehaan opened 9 years ago
Basically something like this (but I guess in CoffeeScript):
'use strict';
var exists = require('fs').existsSync;
var pkg = require('./package.json');
if (pkg.main) {
checkFile(pkg.main);
}
if (pkg.bin) {
switch (typeof pkg.bin) {
case 'string':
checkFile(pkg.bin);
break;
case 'object':
Object.keys(pkg.bin).forEach(function (key) {
checkFile(pkg.bin[key]);
});
break;
}
}
function checkFile(file) {
if (!exists(file)) {
console.error('%s doesn\'t exist.', file);
}
}
Not sure if there are other fields in package.json that may point to specific paths, but those would probably be good to lint to, if any of this is a good idea.
I put this in the backlog for the next version :-)
I've seen this in a few of our project's lately, so it'd be nice if the
finepack
tool could check if the file specified inmain
andbin
paths are valid (something likefs.existsSync()
or whatever).For example, I think by default npm sets the
main
script to "index.js". In my case, the index file is set to "indexxxx.js" which doesn't exist. It'd be nice if finepack could display a warning or error.