Skip to content

Instantly share code, notes, and snippets.

@sillygwailo
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sillygwailo/20c18e877f1d0569e954 to your computer and use it in GitHub Desktop.
Save sillygwailo/20c18e877f1d0569e954 to your computer and use it in GitHub Desktop.
Compiling a forked Node.js module written in CoffeeScript
  1. I have a fork of a Node.js module on GitHub that is a depenency of an app.
  2. That module is written in CoffeeScript. When 'npm install' downloads it, it doesn't compile the module. This is a problem when deploying the app to Heroku, because I can't compile it when deploying to Heroku.
  3. Furthermore, compiling the module has its own depenencies. The dependencies need to be installed before it can be installed.
  4. If I manually run 'npm install' in the forked module's directory inside node_modules, then 'grunt prepublish', everything will work.
  5. I need to automate step #4 when installing the app. How do I do that?

The app in question is https://github.com/sillygwailo/Slack-Twitter If you run npm install in that directory, the slack-client module will not get compiled.

A Solution?

The soution to this was to do the following:

  1. Make 'grunt' and 'grunt-cli' dependencies of the app.
  2. Move the module's dependencies in its package.json file from 'devDependencies' to just 'dependencies'.
  3. Create a postinstall "script", which amounts to:
  • cd node_modules/moduledirectory # change into the module's directory
  • npm install # install the module's dependencies
  • ../grunt-cli/bin grunt prepublish # run grunt, provided by the app's dependencies, to compile the CoffeeScript module

All this became moot once the module accepted my pull request. Suffice to say, it is possible to compile a forked version of a Node.js module written in CoffeeScript without committing the compiled JavaScript to your fork

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