Kristian
Kristian

Reputation: 21810

using a coffeescript node module in a nodejs project

I am playing with a node module called filings

when I first used it, I did a git clone to get that project into a local directory, where I ran npm install and then grunt to build all of the coffeescripts into JS and get dependencies installed.

That works fine and I end up with a /lib directory with 13 files in it.

Now, i'm trying to use that module within a separate node project, so I installed it with npm install filings and a node_modules/filings/lib directory was created, but it only has 6 files in it, and a bunch of functionality is missing.

I've never installed a coffeescript node module into a regular node project before, is there something I can do to get it to properly build within my project?

Upvotes: 0

Views: 137

Answers (2)

hereandnow78
hereandnow78

Reputation: 14434

coffee-script require (generally spoken)

you can require coffee-script files from a javascript-file if you use coffee-script/register before.

therefore you need to install coffee-script locally:

$ npm install coffee-script --save

and use it in your code:

require('coffee-script/register');
require('youre-coffee-script-module');

using the filings-module

basic setup of filings

the module itself has its main-script set to ./lib/filings.js

the lib-folder is compiled by the grunt-task publish

the publish-Task itself is triggered via the prepublish-script. so anytime the package-auther publishes his package via npm publish the lib-sources are build, an afterwards the compiled package is published.

in the .npmignore file all the source and testfiles are ignore, and therefore not published to npm!

how to fix your problem

i just see 2 more or less clean possibilities:

  1. open an issue, and ask the package-auther to publish a new version to npm

  2. create a fork, and use the fork

a) fork the repo

b1) add a postinstall-Property which runs the grunt-default-task grunt:

"scripts": {
  "postinstall": "grunt"
}

or b2) create a index.js file where you require the coffee-sources like i pointed out above

c) install the package from your repo: npm install git+ssh://[email protected]:YOURGITHUBUSERNAME/filings.git

d) maybe create a pull-request if you do version b2

Upvotes: 1

stdob--
stdob--

Reputation: 29172

This is a problem with the package on npmjs.org: If we clone a module from the repository, install it, and make package with npm pack then we get a very different contents of the package to install than the package manager on the site:

http://registry.npmjs.org/filings/-/filings-0.2.0.tgz

Upvotes: 1

Related Questions