Hacker News new | past | comments | ask | show | jobs | submit login

Check in your lock file.



Done. Then I delete it, and `npm install`. Then commit. The majority of people I have worked with do that. On Friday some dude was saying "shrinkwrap v2 is not shrinkwrap v1" and the advice was "delete it and npm install" then commit. (Payment company software manager).


Yes, this is fairly common in my experience. Whenever local build fails, a lot of troubleshooting advices says to nuke node_modules and lock file.


Anyone recommend a build check to block PR's from including fully rebuilt lockfiles? Other than a high LOC, it's too easy for this to slip through.


In my experience this is probably not viable. A single, valid update to a direct dependency can bring dozens or even hundreds of updated sub-dependencies. And an audit fix will often update just the lockfile. Maybe I lack imagination, but I can’t think of a workable heuristic for determining how the lockfile was changed.

I think, instead, it would be good to move in a different direction for sub-dependencies generally. A rough sketch:

1. Packages state their dependencies as they do currently.

2. When released, they’re built and bundled by the package manager host.

3. Included in the bundle is a manifest of the dependencies used, specific imports used, and a hash for each (recursively until exhausted).

4. On install, identical code (same hash/same bundled result) is deduplicated.

5. A human readable record of dependencies and imports used is produced. It’s important that it’s human readable, because:

6. This should not be filtered out in diffs. It should be subject to review just like any other change.

All of this is pretty complex, and there are probably ways to reduce that complexity. But it has some obvious advantages:

- Only your direct dependencies are installed. Tons of bloat can be stripped out.

- Even deduplication can be performed on the package manager’s servers. And hashes aren’t a particularly expensive lookup.

- It would go a long way towards addressing audit fatigue: if your dependencies’ bundles don’t include affected code, the audit doesn’t apply; if they do, you can be reasonably confident the audit is valid.

- A (wild guess) huge amount of the time, sub-dependency changes will require little to no review. Their stable parts will seldom change, and the parts shared among several dependencies could be reviewed as one unit.

- Lock files themselves just need to track direct dependencies (and even then, only to support semver ranges).


What you're describing is more in spirit with the intent of a lockfile and worth exploring by package managers. But I do think a heuristic could be conceived for the lockfile-was-rebuilt situation: If a single top-level dependency declared with ^ or ~ was present in the lockfile when the existing resolution was still valid.

Ideally the onus is on the package manager to provide metadata in the lockfile for the strategies it took when generating.


use yarn instead, the lockfile is much better.


Problem with yarn is that it doesn't actually use dependencies' lock files... So once you publish your library to npm your lock file doesn't do anything whatsoever.


That makes a lot of sense for file sizes—otherwise, common dependencies patch versions apart would be duplicated many time, and it would block you from upgrading a library's dependency for a security fix. You still get the important part of reproducible builds for your program. Rust's Cargo behaves the same way.


I think that checking in your lock file is an actual best practice




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: