Skip to content

Coffee fix - #55

Closed
bitmage wants to merge 2 commits into
strongloop:masterfrom
TorchlightSoftware:coffee-fix
Closed

bitmage wants to merge 2 commits into
strongloop:masterfrom
TorchlightSoftware:coffee-fix

Conversation

@bitmage

@bitmage bitmage commented Oct 14, 2014

Copy link
Copy Markdown
Contributor

coffee-script files (or any other custom extensions for 'require') will not be loaded if there is a JSON file in the same location. This is because of the load order:

http://nodejs.org/api/modules.html#modules_all_together

Custom extensions get tried only after the builtin ones have been exhausted.

My fix is to take the list of files which had already been obtained, and filter it to exclude .json files, and any files that don't match the basename. I then take the first matching file and try a require.resolve on it.

bitmage added 2 commits October 13, 2014 22:50
Signed-off-by: bitmage <brandonjmason@gmail.com>
Signed-off-by: bitmage <brandonjmason@gmail.com>
@slnode

slnode commented Oct 14, 2014

Copy link
Copy Markdown

Can one of the admins verify this patch? To accept patch and trigger a build add comment ".ok\W+to\W+test."

@bitmage bitmage mentioned this pull request Oct 14, 2014
@bajtos

bajtos commented Oct 14, 2014

Copy link
Copy Markdown
Member

@slnode ok to test

@bajtos

bajtos commented Oct 14, 2014

Copy link
Copy Markdown
Member

@bitmage thank you for submitting a pull request, kudos for starting with a failing test!

I see two problems in your implementation:

  1. It will load any file that has an extension different from .json, even if the extension is not supported by Node and the file cannot be loaded. A better option would be to duplicate the algorithm used by node core, but remove .json the list of extensions (see require.extensions). BTW the .node extensions used by native (compiled) add-ons should be excluded too.
  2. Consider the two-step boot process used for the isomorphic client running in a browser, where the first step collects files that should be browserified. Since this is run from within Gulp/Gulp, require.extensions most likely don't include .coffee. A possible solution is to add an option like sourceExtensions that will allow users to customise the list of extensions that are recognised as source code files.

Here is what I would like you to do:

  1. Start by reworking the current implementation to use require.extensions.
  2. Add an option to customise the list extensions used by the algo from the step 1.
  3. Write a test verifying that coffee-script files are correctly transpiled and bundled by browserify. (Hint: https://www.npmjs.org/package/coffeeify)

@ritch ritch added the waiting label Oct 15, 2014
@bitmage

bitmage commented Oct 20, 2014

Copy link
Copy Markdown
Contributor Author
  1. Yeah, agreed. I was trying for feature parity without too much extra code, but a list based off require.extensions would be preferred.
  2. I think this responsibility is assumed directly by CoffeeScript, or any other language compiling to JS. The prescribed step for coffeescript is to call:
require('coffee-script/register');

Which adds the .coffee extension to require.extensions. See implementation here:

https://github.com/jashkenas/coffeescript/blob/master/lib/coffee-script/register.js#L19..L23

People using coffee-script should be familiar with this. I typically add it to my Gruntfile, index.js or whatever other entry point I have, so I don't have to worry about it in the rest of the app. I can document this if you would like. What would be a good place in the documentation? Maybe a side section about coffee-script/other compiled languages?

.3. Yes, I can do that. I am using browserify/coffeeify already in my build process and it's working fine. I wasn't sure how you guys would feel about having coffee-script stuff in your dev dependencies, but it's no problem to implement. :-)

Thanks for the detailed feedback. I'll try to have these changes incorporated by the end of the week.

@bitmage

bitmage commented Oct 20, 2014

Copy link
Copy Markdown
Contributor Author

Also, I've signed the CLA (and signed each commit as requested), but it is still showing me an error saying I haven't. Not sure what to do about that.

@bajtos

bajtos commented Oct 20, 2014

Copy link
Copy Markdown
Member

Also, I've signed the CLA (and signed each commit as requested), but it is still showing me an error saying I haven't. Not sure what to do about that.

It should be enough to sign the CLA via the web interface. I don't know why it did not update the status of your commits. My hope is that when you push new commits, the CLA tool will re-run the check and make it all green.

@bajtos

bajtos commented Oct 20, 2014

Copy link
Copy Markdown
Member

People using coffee-script should be familiar with this. I typically add it to my Gruntfile, index.js or whatever other entry point I have, so I don't have to worry about it in the rest of the app. I can document this if you would like. What would be a good place in the documentation? Maybe a side section about coffee-script/other compiled languages?

A side section is perfect. We are keeping most of our docs in Confluence, which is unfortunately not publicly editable. Can you write the docs as a gist and add a link here?

I am using browserify/coffeeify already in my build process and it's working fine. I wasn't sure how you guys would feel about having coffee-script stuff in your dev dependencies, but it's no problem to implement.

Adding coffee-stuff to dev dependencies is fine. It is a much better alternative compared to not having test coverage for coffee-based apps.

I'll try to have these changes incorporated by the end of the week.

Excellent. Please leave a comment when the patch is ready for another review. GH does not send notifications on new commits, a comment is needed.

@bitmage

bitmage commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

Sounds good. Is this the markup format you are using?

https://confluence.atlassian.com/display/DOC/Confluence+Wiki+Markup

I think the CLA problem is because the email I used in my git config is different than the one linked to my github account. Is there any way to sign with an email other than my github account? Otherwise, I may have to recommit on another branch and abandon this one.

@bajtos

bajtos commented Oct 21, 2014

Copy link
Copy Markdown
Member

Sounds good. Is this the markup format you are using?
https://confluence.atlassian.com/display/DOC/Confluence+Wiki+Markup

Probably yes. It will be better if you use Markdown, we can reformat as we move the content to Confluence.

On the second thought, it will be best if you can add a file docs/coffee.md as part of the pull request. That way I can review the docs and leave line comments where needed.

I think the CLA problem is because the email I used in my git config is different than the one linked to my github account. Is there any way to sign with an email other than my github account? Otherwise, I may have to recommit on another branch and abandon this one.

@rmg can you help here please? @bitmage has signed our CLA, but CLA-hub is still complaining about his PR.

@bitmage

bitmage commented Oct 21, 2014

Copy link
Copy Markdown
Contributor Author

I redid the pull request here:

#59

I think the CLA issues are resolved. Please review my additional changes as well.

Thanks!

@bitmage bitmage closed this Oct 21, 2014
@bitmage bitmage mentioned this pull request Oct 21, 2014
@rmg

rmg commented Oct 21, 2014

Copy link
Copy Markdown
Member

The CLA hub is tied to github credentials so you would need to add your git config user.email address to your github account as an alternate email address.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants