メインコンテンツまでスキップ

インストール

任意のパッケージマネージャーで @powerduck/conf-patch をインストールします。

要件​

  • Node.js: >= 22.12.0
  • TypeScript: 任意です。完全な型宣言が同梱されているため、@types/... は不要です。

インストール​

npm install @powerduck/conf-patch
yarn add @powerduck/conf-patch
pnpm add @powerduck/conf-patch

実行時の依存関係​

conf-patch には、インストール時に自動で追加される 3 つの実行時依存関係があります。

パッケージバージョン用途
@powerduck/openapi-parser^0.3.12OpenAPI/Swagger の検証(validateOpenAPISpec、validateOpenAPIFile)。
jsonc-parser^3.3.1JSON と JSONC の増分テキスト編集。
yaml^2.9.0YAML の AST 解析と変更。

これらを直接操作する必要はありません。

2 つのエントリーポイント​

パッケージは 2 つのサブパスエクスポートを提供します。実行環境に合わせて選んでください。

メインエントリー — @powerduck/conf-patch​

ファイル層(readConfigFile、writeConfigFile、patchConfigFile、setConfigValue、deleteConfigValue、withFileLock、releaseAllLocalLocks)、コア層、OpenAPI 検証を含みます。Node.js と Electron で使用してください。node:fs、node:path、node:crypto に依存します。

コアのサブパス — @powerduck/conf-patch/core​

ブラウザー対応のコア層のみを公開します。patchContent、setContentValue、deleteContentValue、アサーションヘルパー、コア型が含まれます。Node.js 依存はなく、ブラウザー、Edge Functions、Service Worker にバンドルできます。

ヒント

ブラウザー向けには必ず @powerduck/conf-patch/core からインポートしてください。ファイル層と node:fs への依存をバンドルから除外できます。

モジュール形式:CJS と ESM​

パッケージは "type": "module" を設定していないため、.js はデフォルトで CommonJS として扱われます。package.json の exports は import と require を対応するビルドへ明示的に解決します。

エントリーCJS (require)ESM (import)型
メインエントリーdist/index.jsdist/index.mjsdist/index.d.ts
コアのサブパスdist/core.jsdist/core.mjsdist/core.d.ts

CommonJS(Node.js / Electron メインプロセス)​

// Full library (includes file IO)
const { setConfigValue, readConfigFile } = require("@powerduck/conf-patch");

// Core layer only (browser-safe, no fs dependency)
const { patchContent, setContentValue } = require("@powerduck/conf-patch/core");

ES Modules(新しい Node.js / ブラウザー / バンドラー)​

// Full library
import { setConfigValue, readConfigFile } from "@powerduck/conf-patch";

// Core layer only (browser-safe)
import { patchContent, setContentValue } from "@powerduck/conf-patch/core";

インストールの確認​

# Check the installed version
npm list @powerduck/conf-patch

# Verify the main entry loads
node -e "const lib = require('@powerduck/conf-patch'); console.log('exports:', Object.keys(lib).length);"

# Verify the core subpath loads
node -e "const core = require('@powerduck/conf-patch/core'); console.log('core exports:', Object.keys(core).length);"

次のステップ​