npm 패키지들에 대한 정보와 버전에 대한 정보를 담고 있는 json 파일이다. 필수적으로 name과 version에 대한 정도가 명시되어야 한다.
이외에 description, keywords, license, bugs, dependencies, devDependencies 등과 같은 내용으로 구성되어 있다.
dependencies
npm install —save 명령어를 통해 node_modules 디렉터리에 패키지를 설치함과 동시에 package.json 의 dependencies에 package name과 version이 등록된다. devDependencies의 경우 개발 모드일 때만 의존하는 패키지 목록을 저장한다.
node_modules 디렉터리에 설치된 package 폴더의 정보를 package-lock.json 안에 담는다.
문제점
package들은 계속해서 version을 갱신할 것이며, 각 package들은 다른 package에 종속되어 있는 경우도 많다. 예를 들어 A package는 B package를 install하여 사용하고 있고, B package는 C package를 install하여 사용하고 있다. 이때, A package 개발자가 B package 개발자와 다른 경우, A package 개발자는 B package의 version을 관리할 수 있지만, C package의 버전은 건들지 못한다.
즉, 똑같은 조건 하에서 설치가 거의 불가능하며, 같은 version의 package라도 그것이 의존하는 package에는 다른 version이 존재할 수 있다.
해결책
이러한 잠재적 문제를 방지하기 위해 package-lock.json이 등장한 것이다.
{
"name": "multer",
"description": "Middleware for handling `multipart/form-data`.",
"version": "1.4.4",
"contributors": [
"Hage Yaapa <captain@hacksparrow.com> (<http://www.hacksparrow.com>)",
"Jaret Pfluger <https://github.com/jpfluger>",
"Linus Unnebäck <linus@folkdatorn.se>"
],
"license": "MIT",
"repository": "expressjs/multer",
"keywords": [
"form",
"post",
"multipart",
"form-data",
"formdata",
"express",
"middleware"
],
"dependencies": {
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.4",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",
"type-is": "^1.6.4",
"xtend": "^4.0.0"
},
"devDependencies": {
"deep-equal": "^2.0.3",
"express": "^4.13.1",
"form-data": "^1.0.0-rc1",
"fs-temp": "^1.1.2",
"mocha": "^3.5.3",
"rimraf": "^2.4.1",
"standard": "^14.3.3",
"testdata-w3c-json-form": "^1.0.0"
},
"engines": {
"node": ">= 0.10.0"
},
"files": [
"LICENSE",
"index.js",
"storage/",
"lib/"
],
"scripts": {
"test": "standard && mocha"
}
}
"node_modules/multer": {
"version": "1.4.4",
"resolved": "<https://registry.npmjs.org/multer/-/multer-1.4.4.tgz>",
"integrity": "sha512-2wY2+xD4udX612aMqMcB8Ws2Voq6NIUPEtD1be6m411T4uDH/VtL9i//xvcyFlTVfRdaBsk7hV5tgrGQqhuBiw==",
"deprecated": "Multer 1.x is affected by CVE-2022-24434. This is fixed in v1.4.4-lts.1 which drops support for versions of Node.js before 6. Please upgrade to at least Node.js 6 and version 1.4.4-lts.1 of Multer. If you need support for older versions of Node.js, we are open to accepting patches that would fix the CVE on the main 1.x release line, whilst maintaining compatibility with Node.js 0.10.",
"dependencies": {
"append-field": "^1.0.0",
"busboy": "^0.2.11",
"concat-stream": "^1.5.2",
"mkdirp": "^0.5.4",
"object-assign": "^4.1.1",
"on-finished": "^2.3.0",
"type-is": "^1.6.4",
"xtend": "^4.0.0"
},
"engines": {
"node": ">= 0.10.0"
}
},
위 코드는 multer package를 예시로 든 것이다. 보면 package-lock.json에 multer package가 사용하는 package들의 정보가 저장되어있다. 이는 하위 package들의 version도 같이 저장해주기 때문에, 하위 package들의 version이 다를 수 있는 문제를 해결해준다.
package-lock.json은 node_modules나 package.json이 생성되거나 수정될 때 자동적으로 만들어지며, 종속성 업데이트에 관계없이 동일한 트리를 생성하여 개발자들이 같은 의존성을 설치할 수 있도록 보장해준다.