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

lint main and bin file paths #3

Open
pdehaan opened this issue Mar 8, 2015 · 2 comments
Open

lint main and bin file paths #3

pdehaan opened this issue Mar 8, 2015 · 2 comments

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Mar 8, 2015

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
Copy link
Contributor Author

pdehaan commented Mar 8, 2015

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants