Kikobeats / finepack

Organizes and maintains readable your JSON files.
MIT License
19 stars 7 forks source link

lint `main` and `bin` file paths #3

Open pdehaan opened 9 years ago

pdehaan commented 9 years ago

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 in main and bin paths are valid (something like fs.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.

{
  "name": "espree-test",
  "description": "",
  "version": "1.0.0",
  "author": "peter",
  "dependencies": {
    "canonical-json": "0.0.4",
    "espree": "1.11.0"
  },
  "license": "WTFPL",
  "main": "indexxxx.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}
pdehaan commented 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.

Kikobeats commented 9 years ago

I put this in the backlog for the next version :-)