fix: switch commands.json -> commands.js#668
Merged
Conversation
e7a7ec0 to
b615dba
Compare
freitagbr
requested changes
Feb 28, 2017
commands.js
Outdated
| @@ -0,0 +1,29 @@ | |||
| exports.list = [ | |||
Contributor
There was a problem hiding this comment.
exports is initially assigned to module.exports. This is why reassigning exports doesn't export anything, because exports is now whatever you assigned it to, and not module.exports.
Anyways, I think it makes more sense to use module.exports here, because all we want to export is the array.
Member
Author
There was a problem hiding this comment.
Ah, ok. That explanation makes sense. I'll try that instead.
scripts/generate-docs.js
Outdated
| // Insert the docs for all the registered commands | ||
| docs = docs.replace(/\/\/@commands\n/g, function () { | ||
| return require('../commands.json').map(function (commandName) { | ||
| return require('../commands').list.map(function (commandName) { |
Contributor
There was a problem hiding this comment.
If module.exports is used in commands.js, this will become require('../commands').map(...).
shell.js
Outdated
|
|
||
| // Load all default commands | ||
| require('./commands.json').forEach(function (command) { | ||
| require('./commands').list.forEach(function (command) { |
WebPack has issues with importing JSON directly and using JavaScript methods on it. For this reason, using the `.forEach()` method on the imported JSON array caused a method-not-found error. Instead, we can make this a real JavaScript array by keeping it in a JavaScript file and exporting it as a field. It should be noted that exporting it as `exports = [...]` does not work, because Node won't actually interpret it as a JavaScript array (with the required methods). So instead we can export it as `exports.list = [...]` and access the `list` field to get the real JavaScript array of command names. Fixes #667
b615dba to
b087b8f
Compare
Member
Author
|
@freitagbr PTAL |
Contributor
|
LGTM, CI failures are unrelated. |
freitagbr
approved these changes
Feb 28, 2017
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WebPack has issues with importing JSON directly and using JavaScript
methods on it. For this reason, using the
.forEach()method on theimported JSON array caused a method-not-found error.
Instead, we can make this a real JavaScript array by keeping it in a
JavaScript file and exporting it as a field.
Fixes #667