14

I wrote a npm module which can be installed globally dm-npm.

I like to use co in that module.

How can i told the module that it runs with the harmony flag when started globally?

Here is the package.json:

{
  "name": "dm-npm",
  "version": "0.0.3",
  "description": "npm helper",
  "main": "index.js",
  "scripts": {
    "test": "mocha --reporter nyan",
    "start": "node --harmony ./bin/dm-npm"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/divramod/dm-npm.git"
  },
  "keywords": [
    "npm",
    "template"
  ],
  "author": "",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/divramod/dm-npm/issues"
  },
  "homepage": "https://github.com/divramod/dm-npm",
  "devDependencies": {
    "chai": "^2.1.0",
    "mocha": "^2.1.0"
  },
  "dependencies": {
    "co": "^4.4.0",
    "co-prompt": "^1.0.0",
    "colors": "~1.0.3",
    "shelljs": "^0.3.0"
  },
  "bin": {
    "dmnpm": "./bin/dm-npm"
  }
}

i got the following error message when running with a co function:

> $ dmnpm init                                                                                                                         
/usr/local/lib/node_modules/dm-npm/index.js:152
co(function*() {
           ^
SyntaxError: Unexpected token *
    at exports.runInThisContext (vm.js:73:16)
    at Module._compile (module.js:443:25)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (/usr/local/lib/node_modules/dm-npm/bin/dm-npm:3:1)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)

it is caused by

co(function*() {
    var projectName =
        yield prompt('project name: '.blue);
    process.stdin.pause();
});
divramod
  • 1,284
  • 2
  • 16
  • 33
  • A module can't dictate what command line flags node.js is started with. If that's what you're asking, then the user of the module will just have to start node.js with the `--harmony` flag and your module's documentation will just have to inform them of that. – jfriend00 Feb 27 '15 at 03:29
  • i am starting the module from the command line. i created an alias in my zshrc "alias node='node --harmony'" but i have the same problem. in which place can i define that node always runs with harmony flag? – divramod Feb 27 '15 at 04:38

1 Answers1

10

#!/usr/bin/env node --harmony

on the top of script works for me, in your case in /bin/dm-npm

Gary Ascuy
  • 116
  • 1
  • 4