mozilla-jetpack / jpm

Jetpack Manager for Node.js
https://www.npmjs.org/package/jpm
Mozilla Public License 2.0
164 stars 75 forks source link

jpm init overwrites my package.json file and deletes a bunch of values #591

Open pdehaan opened 8 years ago

pdehaan commented 8 years ago

Found in:

$ ./node_modules/.bin/jpm --version # 1.2.0

After running jpm init on a non-empty folder (it only had a package.json and locally installed jpm in node_modules), I noticed that jpm seems to have its own set of default values and doesn't respect previous values in package.json that it's attempting to overwrite, leading to data loss. This could be kind of dangerous, if I was publishing this module to npm, since you'd potentially be publishing as an unexpected version number, or the incorrect package name.

Steps to reproduce:

  1. Start a new project via $ npm init -y which uses default values.
  2. Tweak the values (ie: change the package.json name, add a description and some keywords, etc).
  3. Run jpm init.

    Actual results:

Before running jpm init, my beautiful hypothetical package.json looked like:

{
  "name": "jpm-init-tester",
  "description": "stuff and things",
  "version": "1.0.0",
  "author": "Peter deHaan <peter@deseloper.com> (https://about.me/peterdehaan)",
  "dependencies": {},
  "devDependencies": {
    "jpm": "1.2.0"
  },
  "keywords": [
    "foo",
    "bar"
  ],
  "license": "WTFPL",
  "main": "index.js",
  "scripts": {
    "start": "node index",
    "test": "echo \"Error: no test specified\" && exit 1"
  }
}

After running jpm init, my package.json looks like:

{
  "name": "jpm-init-test",
  "description": "A basic add-on",
  "version": "0.0.1",
  "engines": {
    "firefox": ">=38.0a1",
    "fennec": ">=38.0a1"
  },
  "keywords": [
    "jetpack"
  ],
  "license": "MIT",
  "main": "index.js",
  "title": "My Jetpack Addon"
}

TL;DR

freaktechnik commented 8 years ago

From what I understand jpm init is only supposed to run against an empty directory. I guess it doesn't complain about it, but that's what it's intended use is. It will essentially write a new package.json based on your choices in the jpm init wizzard (plus some good default values, like the jetpack keyword).

Croydon commented 8 years ago

A very easy solution would be just to check if there is a package.json and if there is just don't execute the command?

pdehaan commented 8 years ago

Or else tweak the lib/init-input.js file to read the current directory's package.json (if it exists) and use those values as the defaults, and then fall back to the current hard-coded values.

kumar303 commented 8 years ago

I kinda hate jpm init. I would much rather have something like ember new.

pdehaan commented 8 years ago

I kinda hate jpm init. I would much rather have something like ember new.

Ah, interesting! I've never tried Ember, but I'll check out their ember new scaffolding. We were actually discussing initialization templates over in https://github.com/mozilla/shield-study-cli/issues/14 and I was curious why you prefer the ember new behavior over the current jpm init or something else. /cc @gregglind