본문으로 건너뛰기
버전: 7.x

package.json

패키지의 매니페스트 파일입니다. 여기에는 의존성, 제목, 작성자 등을 포함한 모든 패키지의 메타데이터가 포함됩니다. 이것은 pnpm을 포함한 모든 주요 Node.js 패키지 관리자에서 유지되는 표준입니다.

engines

소프트웨어가 작동하는 Node 및 pnpm의 버전을 지정할 수 있습니다.

{
"engines": {
"node": ">=10",
"pnpm": ">=3"
}
}

로컬 개발 중에 버전이 engines 필드에 지정된 버전과 일치하지 않으면 pnpm은 항상 오류 메시지와 함께 실패합니다.

사용자가 engine-strict 구성 플래그를 설정하지 않은 경우( .npmrc참조), 이 필드는 권고 사항일 뿐이며 패키지가 의존성으로 설치된 경우에만 경고를 생성합니다.

dependenciesMeta

dependenciesMeta.*.injected

If this is set to true for a local dependency, the package will be hard linked to the modules directory, not symlinked.

For instance, the following package.json in a workspace will create a symlink to button in the node_modules directory of card:

{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0"
}
}

But what if button has react in its peer dependencies? If all projects in the monorepo use the same version of react, then no problem. But what if button is required by card that uses react@16 and form with react@17? Without using inject, you'd have to choose a single version of react and install it as dev dependency of button. But using the injected field you can inject button to a package, and button will be installed with the react version of that package.

So this will be the package.json of card:

{
"name": "card",
"dependencies": {
"button": "workspace:1.0.0",
"react": "16"
},
"dependenciesMeta": {
"button": {
"injected": true
}
}
}

button will be hard linked into the dependencies of card, and react@16 will be symlinked to the dependencies of card/node_modules/button.

And this will be the package.json of form:

{
"name": "form",
"dependencies": {
"button": "workspace:1.0.0",
"react": "17"
},
"dependenciesMeta": {
"button": {
"injected": true
}
}
}

button will be hard linked into the dependencies of form, and react@17 will be symlinked to the dependencies of form/node_modules/button.

peerDependenciesMeta

This field lists some extra information related to the dependencies listed in the peerDependencies field.

peerDependenciesMeta.*.optional

If this is set to true, the selected peer dependency will be marked as optional by the package manager. Therefore, the consumer omitting it will no longer be reported as an error.

예:

{
"peerDependencies": {
"foo": "1"
},
"peerDependenciesMeta": {
"foo": {
"optional": true
},
"bar": {
"optional": true
}
}
}

Note that even though bar was not specified in peerDependencies, it is marked as optional. pnpm will therefore assume that any version of bar is fine. However, foo is optional, but only to the required version specification.

publishConfig

It is possible to override some fields in the manifest before the package is packed. The following fields may be overridden:

To override a field, add the publish version of the field to publishConfig.

For instance, the following package.json:

{
"name": "foo",
"version": "1.0.0",
"main": "src/index.ts",
"publishConfig": {
"main": "lib/index.js",
"typings": "lib/index.d.ts"
}
}

Will be published as:

{
"name": "foo",
"version": "1.0.0",
"main": "lib/index.js",
"typings": "lib/index.d.ts"
}

publishConfig.executableFiles

By default, for portability reasons, no files except those listed in the bin field will be marked as executable in the resulting package archive. The executableFiles field lets you declare additional fields that must have the executable flag (+x) set even if they aren't directly accessible through the bin field.

{
"publishConfig": {
"executableFiles": [
"./dist/shim.js"
]
}
}

publishConfig.directory

You also can use the field publishConfig.directory to customize the published subdirectory relative to the current package.json.

It is expected to have a modified version of the current package in the specified directory (usually using third party build tools).

이 예시에서 "dist" 폴더에는 package.json이 포함되어야 합니다.

{
"name": "foo",
"version": "1.0.0",
"publishConfig": {
"directory": "dist"
}
}

pnpm.overrides

This field allows you to instruct pnpm to override any dependency in the dependency graph. This is useful to enforce all your packages to use a single version of a dependency, backport a fix, or replace a dependency with a fork.

Note that the overrides field can only be set at the root of the project.

An example of the "pnpm"."overrides" field:

{
"pnpm": {
"overrides": {
"foo": "^1.0.0",
"quux": "npm:@myorg/quux@^1.0.0",
"bar@^2.1.0": "3.0.0",
"qar@1>zoo": "2"
}
}
}

You may specify the package the overriden dependency belongs to by separating the package selector from the dependency selector with a ">", for example qar@1>zoo will only override the zoo dependency of qar@1, not for any other dependencies.

pnpm.packageExtensions

The packageExtensions fields offer a way to extend the existing package definitions with additional information. For example, if react-redux should have react-dom in its peerDependencies but it has not, it is possible to patch react-redux using packageExtensions:

{
"pnpm": {
"packageExtensions": {
"react-redux": {
"peerDependencies": {
"react-dom": "*"
}
}
}
}
}

The keys in packageExtensions are package names or package names and semver ranges, so it is possible to patch only some versions of a package:

{
"pnpm": {
"packageExtensions": {
"react-redux@1": {
"peerDependencies": {
"react-dom": "*"
}
}
}
}
}

The following fields may be extended using packageExtensions: dependencies, optionalDependencies, peerDependencies, and peerDependenciesMeta.

A bigger example:

{
"pnpm": {
"packageExtensions": {
"express@1": {
"optionalDependencies": {
"typescript": "2"
}
},
"fork-ts-checker-webpack-plugin": {
"dependencies": {
"@babel/core": "1"
},
"peerDependencies": {
"eslint": ">= 6"
},
"peerDependenciesMeta": {
"eslint": {
"optional": true
}
}
}
}
}
}
tip

Yarn과 함께 우리는 생태계에서 손상된 패키지를 패치하기 위해 packageExtensions 의 데이터베이스를 유지 관리합니다. packageExtensions을 사용하는 경우, PR 업스트림을 보내고 확장을 @yarnpkg/extensions 데이터베이스에 제공하는 것을 고려하십시오.

pnpm.peerDependencyRules

pnpm.peerDependencyRules.ignoreMissing

pnpm will not print warnings about missing peer dependencies from this list.

For instance, with the following configuration, pnpm will not print warnings if a dependency needs react but react is not installed:

{
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": ["react"]
}
}
}

패키지 이름 패턴도 사용할 수 있습니다.

{
"pnpm": {
"peerDependencyRules": {
"ignoreMissing": ["@babel/*", "@eslint/*"]
}
}
}

pnpm.peerDependencyRules.allowedVersions

Unmet peer dependency warnings will not be printed for peer dependencies of the specified range.

For instance, if you have some dependencies that need react@16 but you know that they work fine with react@17, then you may use the following configuration:

{
"pnpm": {
"peerDependencyRules": {
"allowedVersions": {
"react": "17"
}
}
}
}

This will tell pnpm that any dependency that has react in its peer dependencies should allow react v17 to be installed.

pnpm.peerDependencyRules.allowAny

버전 7.3.0에서 추가됨

allowAny은 패키지 이름 패턴의 배열이며, 패턴과 일치하는 모든 피어 의존성은 peerDependencies에 지정된 범위에 관계없이 모든 버전에서 확인됩니다. For instance:

{
"pnpm": {
"peerDependencyRules": {
"allowAny": ["@babel/*", "eslint"]
}
}
}

위의 설정은 @babel/ 패키지 또는 eslint와 관련된 피어 의존성에 버전 불일치 경고를 음소거합니다.

pnpm.neverBuiltDependencies

This field allows to ignore the builds of specific dependencies. The "preinstall", "install", and "postinstall" scripts of the listed packages will not be executed during installation.

An example of the "pnpm"."neverBuiltDependencies" field:

{
"pnpm": {
"neverBuiltDependencies": ["fsevents", "level"]
}
}

pnpm.onlyBuiltDependencies

A list of package names that are allowed to be executed during installation. If this field exists, only the listed packages will be able to run install scripts.

예시:

{
"pnpm": {
"onlyBuiltDependencies": ["fsevents"]
}
}

pnpm.allowedDeprecatedVersions

버전 7.2.0에서 추가됨

이 설정을 사용하면 특정 패키지의 사용 중단 경고를 음소거할 수 있습니다.

예시:

{
"pnpm": {
"allowedDeprecatedVersions": {
"express": "1",
"request": "*"
}
}
}

위의 구성으로 pnpm은 request 의 모든 버전과 express의 버전 1에 대한 사용 중단 경고를 출력하지 않습니다.

pnpm.patchedDependencies

버전 7.4.0에서 추가됨

이 필드는 pnpm patch-commit을 실행할 때 자동으로 추가/업데이트됩니다. 키가 패키지 이름과 정확한 버전이어야 하는 딕셔너리입니다. 값은 패치 파일에 대한 상대 경로여야 합니다.

예시:

{
"pnpm": {
"express@4.18.1": "patches/express@4.18.1.patch"
}
}