Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gitignored package-lock.json #213

Closed
satazor opened this issue Oct 25, 2017 · 6 comments
Closed

gitignored package-lock.json #213

satazor opened this issue Oct 25, 2017 · 6 comments

Comments

@satazor
Copy link

satazor commented Oct 25, 2017

I prefer to gitignore the package-lock.json for libraries. I commit the package-lock.json only for apps.
When the package lock is gitignored, when running standard-version this happens:

✔ committing package-lock.json and package.json and CHANGELOG.md
The following paths are ignored by one of your .gitignore files:
package-lock.json
Use -f if you really want to add them.

Command failed: git add package.json package-lock.json CHANGELOG.md
The following paths are ignored by one of your .gitignore files:
package-lock.json
Use -f if you really want to add them.

Using -f will add the package-log to source control which I don't want. Ideally, standard-version could detect that the file is gitignored and skip it.

Thoughts?

@nexdrew
Copy link
Member

nexdrew commented Nov 21, 2017

@satazor Hey, I ran into this same problem today, bit of a pain.

Besides manually running npm i --no-package-lock (to avoid the creation of the lock file at all) or adding package-lock.json to the git repo, here are a couple workarounds/hacks I tested that were successful:

  1. Rename package-lock.json on prebump and rename it back on posttag

    Define a standard-version lifecycle script in your package.json that looks like this:

    "standard-version": {
      "scripts": {
        "prebump": "mv package-lock.json package-lock-IGNORE.json",
        "posttag": "mv package-lock-IGNORE.json package-lock.json"
      }
    }

    This maintains the integrity of the lock file but temporarily hides it when running standard-version.

    I put this as the first option because it still allows you to get the benefit of using package-lock.json file locally, though that value is arguably moot when not shared.

  2. Remove package-lock.json on postshrinkwrap

    Define an npm postshrinkwrap script that looks like this:

    "scripts": {
      "postshrinkwrap": "rm -f package-lock.json",
      "release": "standard-version"
    }

    This just subverts the normal lock file writing process that occurs with a typical npm i (npm will create the file and then immediately delete it on install). This works whether you're using standard-version or not.

    (Note that I also tried to do this with a postinstall script, but postinstall runs before npm creates the lock file.)

  3. Remove package-lock.json on prebump

    Define a standard-version lifecycle script in your package.json that looks like this:

    "standard-version": {
      "scripts": {
        "prebump": "rm -f package-lock.json"
      }
    }

    This just removes the file when you go to cut a new release. The next time you run npm i, the lock file will be recreated.

That being said, it would obviously be nice if standard-version detected that the file is git-ignored, but until we can add that, one of the above options is probably the best we can do. HTH!

@satazor
Copy link
Author

satazor commented Nov 22, 2017

@nextdrew thanks for your suggestions, haven’t really thought of them. Nicely done. Regarding windows support, replacing rm with rimraf works?

@nexdrew
Copy link
Member

nexdrew commented Nov 22, 2017

@satazor Yes, good point, rimraf package-lock.json should work cross-platform.

@bcoe
Copy link
Member

bcoe commented Nov 29, 2017

@nexdrew @satazor slick; perhaps a good topic for putting in docs/advanced.md?

@danielo515
Copy link

Hello,
I'm also suffering this problem. Is the package-lock already ignored or should I go for the prebump workaround ?

@jbottigliero
Copy link
Member

jbottigliero commented Oct 19, 2021

With #230 (and likely some updates since), standard-version will respect .gitignore. Since the package-lock.json is a bit of a special case (default bumpFile), I've expanded our test to make sure it is ignored as expected when found in a local .gitignore.

Thanks to all who contributed to this initial fix/feature! ✌️

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

No branches or pull requests

5 participants