Skip to content
cccskills
FreePublished on GitHub

add-npm-package

modules/npm/packages/ に新しい npm/pnpm パッケージを追加するスキル

The English summary is being prepared. Showing the original description.

See how to install

Files included (1)

  • SKILL.md3.9 KB

SKILL.md (original)

Review the instructions the agent will receive before you install.

npm パッケージ追加スキル

modules/npm/packages/ に新しいパッケージの .nix ファイルを作成し、home-manager switch で反映する。

手順

1. 最新バージョンの確認

curl -s https://api.github.com/repos/<owner>/<repo>/releases/latest | grep '"tag_name"'

2. src.hash の取得

ダミーハッシュを入れてビルドし、エラーから正しい値を読み取る。

src = pkgs.fetchFromGitHub {
  owner = "<owner>";
  repo = "<repo>";
  rev = "v${version}";
  hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";  # ダミー
};
nix-build /tmp/test.nix 2>&1 | grep "got:"
# → got: sha256-xxxxx  ← この値を使う

3. pnpmDeps.hash の取得 (pnpm プロジェクトの場合)

まず lockfile のバージョンを確認する:

curl -s https://raw.githubusercontent.com/<owner>/<repo>/v<version>/pnpm-lock.yaml | head -1
# lockfileVersion: '9.0' → fetcherVersion = 1
lockfileVersionfetcherVersion
'9.0' (pnpm v9以降)1
'6.0' 以前不要 (省略)

同様にダミーハッシュで失敗させて取得:

pnpmDeps = pkgs.pnpm.fetchDeps {
  pname = "<pname>";
  inherit version src;
  fetcherVersion = 1;
  hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";  # ダミー
};

4. buildPhase の確認

package.json の scripts を確認し、CLI と Web UI の両方をビルドするスクリプトを選ぶ:

curl -s https://raw.githubusercontent.com/<owner>/<repo>/v<version>/package.json \
  | python3 -c "import json,sys; d=json.load(sys.stdin); [print(k,':',v) for k,v in d.get('scripts',{}).items()]"
  • CLI のみのツールなら build:cli 相当のスクリプトで十分
  • Web UI を持つツール (ブラウザを開くもの) は build など全体をビルドするスクリプトを使う

5. bin のエントリポイント確認

curl -s https://raw.githubusercontent.com/<owner>/<repo>/v<version>/package.json \
  | python3 -c "import json,sys; d=json.load(sys.stdin); print(d.get('bin'))"

6. .nix ファイルの作成

modules/npm/packages/<pname>.nix:

{ pkgs }:
let
  version = "<x.y.z>";
  src = pkgs.fetchFromGitHub {
    owner = "<owner>";
    repo = "<repo>";
    rev = "v${version}";
    hash = "sha256-<src-hash>";
  };
  pnpmDeps = pkgs.pnpm.fetchDeps {
    pname = "<pname>";
    inherit version src;
    fetcherVersion = 1;
    hash = "sha256-<pnpm-deps-hash>";
  };
in
pkgs.stdenv.mkDerivation {
  pname = "<pname>";
  inherit version src;
  nativeBuildInputs = [
    pkgs.nodejs_22
    pkgs.pnpmConfigHook
    pkgs.makeWrapper
  ];
  inherit pnpmDeps;
  buildPhase = ''
    pnpm run build
  '';
  installPhase = ''
    mkdir -p $out/lib/<pname> $out/bin
    cp -r dist node_modules package.json $out/lib/<pname>/
    find $out/lib/<pname>/node_modules -xtype l -delete
    makeWrapper ${pkgs.nodejs_22}/bin/node $out/bin/<pname> \
      --add-flags "$out/lib/<pname>/dist/<entrypoint>.js"
  '';
}

モノレポ構成の注意: pnpm workspace でローカルパッケージへの symlink が node_modules に含まれる場合がある。find -xtype l -delete で broken symlink を削除すること。

7. フォーマットとビルド確認

nixfmt modules/npm/packages/<pname>.nix
git add modules/npm/
home-manager build --flake .

8. 動作確認と反映

home-manager switch --flake .
<pname> --help

npm プロジェクト (pnpm でない) の場合

pnpmDeps の代わりに buildNpmPackage を使う:

pkgs.buildNpmPackage {
  pname = "<pname>";
  inherit version src;
  nodejs = pkgs.nodejs_22;
  npmDepsHash = "sha256-<hash>";  # 同様にダミーで取得
}

Reviews

No reviews yet. Tell others what you thought.

Comments

No login needed. Share how it worked for you, ask a question, or note where it did not run.

No comments yet. Be the first to write one.

Comments are published right away. Do not include personal information such as email addresses or phone numbers. Up to 2 URLs.

0 / 1,000 characters

This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.

More skills from this repository

install/ 配下に新しいセットアップ用シェルスクリプトを追加するスキル

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

GitHub issue を新規作成・下書きするとき、または既存 issue の本文を書き直すときに必ず使うスキル。「issue を作って」「issue 化して」「これを issue にまとめて」のような依頼で発火し、`gh issue create` を直接呼ぶ前に必ず参照する。人間が合意した内容だけを、意味を足さずに issue へ残すための基準を定める。

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

GitHub に Pull Request を作成するスキル。ユーザーが「PRを作って」「プルリクエストを出して」「PR作成して」と言ったとき、またはコミット済みの変更をレビューに出したいときに使用する。

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

ドメインモデル、可視性、操作可能性、不変条件、層境界、API 設計に関わる実装時に使う。不正な状態や誤った呼び出し方を、型、関数の境界、ドメイン語彙で表し、正しい使い方が自然になる設計へ寄せるためのスキル。

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

コミットやPR作成の前に、作業ブランチが適切かどうかを確認・切り替えるスキル。git-commit や create-pr からサブルーチンとして呼び出される。

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

コードを実装・修正・リファクタリングするすべてのタスクで使うスキル。純粋関数を中心に設計し、副作用(DB、HTTP、ファイル、時刻、乱数、ログなど)を境界へ寄せ、データ変換、エラー表現、コレクション操作、可変状態の扱いを既存コードに合う形で整理する。ユーザーが明示的に指示しなくても、言語を問わず、コードを書き始める前に発火する。設定値やドキュメントだけの変更では不要。

The English summary is being prepared. Showing the original description.

rito528/dotfiles2Updated Oct 18, 2026

See all skills by rito528

Report a problem with this skill