ams-npm-pro
暂无简介
- License 许可
- MIT
- 最近更新
- 2026-11-07
- Stars
- ★ 0
- Forks
- 1
03 SKILL.md 正文
npm Pro
A practical guide to npm done well: workspaces, lockfile discipline, script conventions, safe publishing (provenance, 2FA, access tokens), and security hygiene — squeezing reliability out of the default package manager.
Overview
npm ships with Node and remains the baseline every other manager is compared against. Its weaknesses are well-known (slower installs, flat node_modules allowing phantom deps), but with discipline — lockfiles committed, ci in pipelines, workspaces for monorepos, provenance for publishing — it's a perfectly solid choice, and its registry compatibility is universal.
When to use
- Default choice for libraries (max compatibility with consumers' tooling).
- Small-to-medium projects where install speed isn't the bottleneck.
- Publishing packages to the npm registry.
- Teams that prefer zero extra tooling beyond Node.
Core concepts
package-lock.json. Commit it (apps and libraries — libraries benefit too for reproducible dev/CI).npm ciinstalls exactly from the lockfile;npm installmay update it.- Workspaces.
workspaces: ["apps/*", "packages/*"]in root package.json;npm run build -w web/--workspace;npm run test --workspacesfor all. - Scripts.
pre/posthooks,npxfor one-off binaries. Keep scripts composable (buildcallsbuild:types,build:js). - Provenance.
--provenanceon publish attests the package was built in CI from a specific commit — verifiable supply-chain metadata. Enable it. - Access control. Scoped packages default to restricted;
--access publicfor open-source. 2FA required for publishing on accounts (use it; automation via granular tokens). overrides. Force dependency versions (CVE fixes, dedupe). Powerful, temporary by intent — revisit regularly.npm audit/npm audit fix. Vulnerability scanning;fixbumps within semver ranges. For major bumps, do it deliberately.
Practical workflow
1. Setup.
npm init -y
# package.json: "packageManager": "npm@10.x" (corepack pin)
npm install --save-exact # or configure save-exact=true to avoid ^ drift
2. Daily commands.
npm ci # CI / clean installs (fast, deterministic)
npm install lodash # add (updates lockfile)
npm uninstall lodash
npm update # bump within semver ranges
npm dedupe # flatten duplicates
npm ls react # inspect why a version is present
npm explain lodash # dependency chain detail
npm outdated # what can be bumped
npx tsc --noEmit # run a binary without installing
3. Workspaces.
npm run build --workspace=packages/ui
npm run test --workspaces --if-present
npm exec --workspace=apps/web -- eslint src
4. Publishing a library.
npm version patch # bump + tag
npm publish --provenance --access public
Pre-publish checklist: files field set (don't ship tests/config), .npmignore/.gitignore sane, npm pack --dry-run to inspect the tarball, README documents install + usage.
5. CI.
- run: npm ci
- run: npm run lint && npm run test --workspaces --if-present
- run: npm publish --provenance # on release tags only
Common pitfalls
npm installin CI. Slow and non-deterministic vs the lockfile.npm cialways in CI.- Uncommitted lockfile. "Works on my machine" across the team. Commit
package-lock.json, always. - Phantom dependencies. Flat
node_moduleslets you import undeclared packages — works locally, breaks for consumers or under stricter managers. Declare everything you import. - Publishing too much. Shipping
src, tests, and configs bloats installs. Usefiles: ["dist"]and verify withnpm pack --dry-run. - No 2FA / long-lived tokens in CI. Use granular access tokens with publish-only scope, stored as CI secrets; enable 2FA on the account.
latestdist-tag accidents. Publishing a beta aslatestupgrades everyone unintentionally. Use--tag betafor prereleases.- Ignoring
npm audit. Run it in CI; triage highs/criticals.audit fixfirst, manual bumps for the rest. - Postinstall scripts from deps. A supply-chain risk vector. Review new dependencies' install scripts; consider
--ignore-scriptswith explicit allowlists for trusted packages. - Version drift via
^.^1.2.3floats within majors — fine for apps with lockfiles, surprising for libraries' consumers.save-exactfor apps; thoughtful ranges for libraries.
04 同仓库更多 Skills
web-scrape
Turn web pages into LLM-ready markdown via the Firecrawl API (renders JS, anti-bot handling). Use when browser_open/fetch fails on JS-heavy pages, or when you need clean markdown/structured extraction from a site. Requires FIRECRAWL_API_KEY.
design-taste-frontend
tasteskill v2, the anti-slop frontend skill. Art direction for websites, distilled from a study of 247 curated gallery sites (One Page Love, Awwwards Sites of the Day). Deals researched directions (idea, composition, type, palette, photographs, section blueprints) from a library, enforces a strict no-slop house style with a real-browser inspector, and runs a look-and-fix loop on screenshots. Use this whenever you build, design, redesign, restyle, polish or review a landing page, marketing site, portfolio, product page, one-pager, hero or any public-facing web page, in any stack (HTML/CSS, React, Next.js, Vue, Svelte, Astro, Tailwind) — also when the user says a page looks generic, templated, "AI-made", sloppy, or asks to make it look designed, premium, award-level or less like every other site. Not for dashboards or app screens.
test-driven-development
Use when implementing any feature or bugfix, before writing implementation code
systematic-debugging
Use when encountering any bug, test failure, or unexpected behavior, before proposing fixes
requesting-code-review
Use when completing tasks, implementing major features, or before merging to verify work meets requirements
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).