설정 종속성
설정 종속성을 사용하면 여러 프로젝트에서 설정 파일, 설정, 훅을 공유하고 중앙에서 관리할 수 있습니다. 설정 종속성은 모든 일반 종속성("dependencies", "devDependencies", "optionalDependencies")보다 먼저 설치되므로, 사용자 정의 훅, 패치, 카탈로그 항목을 설정하는 데 적합합니다.
설정 종속성을 사용하면 모든 훅, 설정, 패치, 오버라이드, 카탈로그, 규칙을 한 곳에서 관리하고 여러 저장소에서 사용할 수 있습니다.
설정 종속성의 이름이 pnpm-plugin-*, @*/pnpm-plugin-* 또는 @pnpm/plugin-* 패턴을 따르는 경우, pnpm은 패키지 루트에서 pnpmfile.mjs(없으면 pnpmfile.cjs)를 자동으로 불러옵니다.
Config dependencies must come from an npm registry. pnpm verifies them against their registry before installing them, so installing a new or changed config dependency offline requires cached registry metadata. A config dependency pinned with version+integrity keeps that integrity as its pin. minimumReleaseAge applies to config dependencies that are not pinned with version+integrity. pnpm installs them before any updateConfig hook runs, so a minimumReleaseAgeExclude entry added by a hook does not cover them.
Removing a package from configDependencies removes its installed link and unused lockfile entries on the next pnpm install. This also applies when you remove the entire setting. Run without --frozen-lockfile to update the lockfile after changing the declarations.
How to add a config dependency#
설정 종속성은 pnpm-workspace.yaml에 정의됩니다. Their integrity checksums are stored in pnpm-lock.yaml (in a dedicated env lockfile document).
예를 들어, pnpm add --config my-configs를 실행하면 pnpm-workspace.yaml에 다음 항목이 추가됩니다:
configDependencies:
my-configs: "1.0.0"
중요:
- 설정 종속성은 자체적인 일반
dependencies를 가질 수 없습니다. They can declareoptionalDependencies, but only one level deep.optionalDependenciesofoptionalDependenciesare ignored. - 설정 종속성은 라이프사이클 스크립트(
preinstall,postinstall등)를 정의할 수 없습니다.
optionalDependencies를 통한 플랫폼별 바이너리#
설정 종속성은 esbuild나 swc 같은 도구에서 사용하는 것과 동일한 패턴으로 optionalDependencies를 통해 플랫폼별 바이너리를 제공할 수 있습니다. 각 플랫폼 바이너리 패키지는 os, cpu 및/또는 libc 필드로 지원하는 플랫폼을 선언하며, pnpm은 현재 호스트와 일치하는 변형만 설치합니다. 일치하는 바이너리는 글로벌 가상 스토어에서 상위 설정 종속성 옆에 심볼릭 링크되므로, 설정 종속성 내부에서 require('my-config-platform-arch')가 런타임에 해석됩니다.
해당 env lockfile은 호스트 플랫폼과 관계없이 모든 플랫폼 변형을 기록하므로, lockfile은 여러 머신 간에 이식 가능한 상태로 유지됩니다.
Each entry in optionalDependencies must be declared with an exact version (e.g. "1.2.3"). Ranges ("^1.0.0", "~1.0.0") and tags ("latest") are rejected. 이를 통해 설정 종속성 설치의 재현성이 유지됩니다: integrity로 고정된 상위 패키지의 경우, 해석된 하위 종속성이 머신마다 달라질 수 없습니다.
사용#
Installing dependencies used in hooks#
설정 종속성은 .pnpmfile.mjs의 훅이 로드되기 전에 설치되므로, 설정 패키지에서 로직을 가져올 수 있습니다.
예시:
import { readPackage } from './node_modules/.pnpm-config/my-hooks/index.mjs'
export const hooks = {
readPackage
}
Updating pnpm settings dynamically#
Using the updateConfig hook, you can dynamically update pnpm's settings using config dependencies.
예를 들어, 다음 pnpmfile은 pnpm 설정에 새 catalog 항목을 추가합니다:
export const hooks = {
updateConfig (config) {
config.catalogs.default ??= {}
config.catalogs.default['is-odd'] = '1.0.0'
return config
}
}
이를 설정 종속성으로 설치하면:
pnpm add --config @myorg/pnpm-plugin-my-catalogs
다음을 실행할 수 있습니다:
pnpm add is-odd@catalog:
이렇게 하면 is-odd@1.0.0이 설치되고 package.json에 다음이 추가됩니다:
{
"dependencies": {
"is-odd": "catalog:"
}
}
이를 통해 여러 프로젝트에서 중앙 집중식 설정과 종속성 버전을 쉽게 유지 관리하고 공유할 수 있습니다.
Loading patch files#
설정 종속성 내부에 저장된 patch files를 참조할 수 있습니다.
예시:
configDependencies:
my-patches: "1.0.0"
patchedDependencies:
react: "node_modules/.pnpm-config/my-patches/react.patch"