Skip to content
This repository has been archived by the owner on Nov 27, 2019. It is now read-only.

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

Open
pdehaan opened this issue Oct 3, 2016 · 5 comments
Open

Comments

@pdehaan
Copy link
Contributor

pdehaan commented Oct 3, 2016

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

  • my name was changed. (pre: "jpm-init-tester", post: "jpm-init-test")
  • my description was changed. (pre: "stuff and things", post: "A basic add-on")
  • my version was changed. (pre: "1.0.0", post: "0.0.1")
  • my keywords were changed. (pre: ["foo", "bar"], post: ["jetpack"])
  • my license was changed. (pre: "WTFPL", post: "MIT")
  • my author was deleted.
  • my scripts were deleted.
  • my dependencies and devDependencies were deleted.
@freaktechnik
Copy link
Contributor

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
Copy link

Croydon commented Oct 3, 2016

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
Copy link
Contributor Author

pdehaan commented Oct 3, 2016

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
Copy link
Contributor

kumar303 commented Oct 4, 2016

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

@pdehaan
Copy link
Contributor Author

pdehaan commented Oct 4, 2016

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 mozilla/shield-study-cli#14 and I was curious why you prefer the ember new behavior over the current jpm init or something else. /cc @gregglind

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants