Skip to content

Read jshint version from package.json #5908

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

Merged
merged 1 commit into from
Apr 4, 2015

Conversation

timvandermeij
Copy link
Contributor

Resolves another TODO in the codebase.

@@ -1459,7 +1459,15 @@ target.lint = function() {
var jshintPath = path.normalize('./node_modules/.bin/jshint');
if (!test('-f', jshintPath)) {
echo('jshint is not installed -- installing...');
exec('npm install [email protected]'); // TODO read version from package.json
// Read the jshint version to be installed from package.json.
fs.readFile('package.json', 'utf8', function (error, data) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please read the file synchronously instead, i.e. change fs.readFile to fs.readFileSync, since the code below relies on jshint being immediately available?
Otherwise, when jshint isn't installed, linting will fail and require you to do node make lint twice (once to install, and once to actually lint).

Obviously, you could make the rest of the code async to handle this. But given that jshint should only need to be installed once, I don't think we should complicate the rest of the function unnecessarily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I think this also makes the code a bit cleaner and indeed it fixes the problem that one would have to re-run node make lint when it was not yet installed. I have tested this with jshint installed, with jshint uninstalled and with jshint uninstalled and no package.json and all possibilities yield an expected result now. Excellent, thank you!

var configuration = JSON.parse(rawConfiguration);
exec('npm install jshint@' + configuration.devDependencies.jshint);
} catch(e) {
echo('package.json does not exist -- aborting...');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: You might want to return or throw after this line, so that the code actually aborts, otherwise the print statement is slightly wrong :-)

Super-nit: How about adding a space between catch and (e) { above? :-P

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Not sure how I managed to miss that... Both issues have been fixed :-)

@timvandermeij
Copy link
Contributor Author

/botio lint

@pdfjsbot
Copy link

pdfjsbot commented Apr 4, 2015

From: Bot.io (Linux)


Received

Command cmd_lint from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/704e857ebf64d03/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 4, 2015

From: Bot.io (Windows)


Received

Command cmd_lint from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/b37e94837a2ffb6/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Apr 4, 2015

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/704e857ebf64d03/output.txt

Total script time: 0.84 mins

  • Lint: Passed

@pdfjsbot
Copy link

pdfjsbot commented Apr 4, 2015

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/b37e94837a2ffb6/output.txt

Total script time: 0.95 mins

  • Lint: Passed

Snuffleupagus added a commit that referenced this pull request Apr 4, 2015
Read jshint version from package.json
@Snuffleupagus Snuffleupagus merged commit b85a51d into mozilla:master Apr 4, 2015
@Snuffleupagus
Copy link
Collaborator

Really good, thanks for doing this!

@timvandermeij timvandermeij deleted the read-package-json branch April 4, 2015 16:17
timvandermeij added a commit to timvandermeij/pdf.js that referenced this pull request Apr 5, 2015
The previous commit implements a check for ShellJS and otherwise prompts the user to run "npm install". New clones of the codebase will need "npm install" for ShellJS and therefore automatically install jshint. Existing clones of the codebase will also need "npm install" again since ShellJS needs to be installed using NPM as it is not in the "external" folder anymore. Since everyone will get this prompt and install everything automatically, we will never reach this code path anymore.

This patch makes mozilla#5908 obsolete and reduces code complexity for the lint target. Thanks to @Snuffleupagus for noticing this!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants