npm 레지스트리에서 특정 패키지에 대한 메타데이터 및 기타 정보를 볼 수 있습니다. 이 명령으로 패키지의 최신 버전, 패키지의 종속성, 작성자 및 라이선스 정보, 기타 세부 정보를 확인할 수 있습니다.
# 이전 버전 리스트를 확인하고 싶을때
npm view cowsay versions
# 각 버전이 게시된 시간을 확인
npm view cowsay time
Footnotes
-
설치된 npm 패키지의 버전을 확인하는 방법에 대한 가이드 ↩
// 현재 실행된 stage 값을 참조하기
// 하지만 스크립트를 따로 작성하는게 더 효율적으로 보인다.
{
"scripts": {
"dev:hello": "echo ${npm_lifecycle_event#dev:}"
}
}
- yarnpkg - Is there a way to get the name of the npm script passed to the command specified by that script? - Stack Overflow1
- scripts | npm Docs2
Footnotes
-
npm 스크립트의 이름을 얻는 방법에 대한 질문과
npm_lifecycle_event환경 변수를 사용하는 방법으로 제안 ↩ -
package.json 파일에서 스크립트를 사용하는 방법에 대한 개요, 기본 제공 환경 변수 목록도 포함 — “the
npm_lifecycle_eventenvironment variable is set to whichever stage of the cycle is being executed.” 스크립트는sh로 돌아서 bash 전용${var//a/b}대신 POSIX${var#prefix}를 쓴다 — “Scripts are run by passing the line as a script argument tosh.” ↩
같은 이름은 dependencies 에 한 번만 들어간다 — <별칭>@npm:<이름>@<버전> 으로 별칭을 달면 여러 버전이 나란히 설치된다.1
yarn add react-tooltip-5@npm:react-tooltip@5.8.3
{
"react-tooltip-5": "npm:react-tooltip@5.8.3"
}
- how to install multiple versions of package using npm - Stack Overflow
- How to install multiple versions of a npm package at the same time/project - DEV Community
Footnotes
-
npm-install | npm Docs:
npm install <alias>@npm:<name>— “Install a package under a custom alias. Allows multiple versions of a same-name package side-by-side, …” / “Aliasing works only on your project and does not rename packages in transitive dependencies.” ↩
yalc - 로컬 Node 모듈을 다른 프로젝트에서 바로 테스트. npm link보다 문제 적음 (파일 복사 방식) — symlink 대신 publish 될 파일만 전역 저장소로 복사하고, 앱은 그걸 .yalc 로 끌어온다.1
npm i -g yalc
# 패키지에서
yalc publish # ~/.yalc에 저장
yalc push # = publish --push: 저장 + 연결된 모든 프로젝트에 반영
# 앱에서
yalc add my-module
yalc remove my-module && npm install # 정리
watch 모드: "dev": "tsup src/index.ts --watch --onSuccess 'yalc push'"
.gitignore: .yalc, yalc.lock
Footnotes
-
yalc README: “When you run
yalc publishin the package directory, it grabs only files that should be published to NPM and puts them in a special global store (located, for example, in~/.yalc).” / “yalc publish --pushwill publish your package to the store and propagate all changes to existingyalcpackage installations …” / “yalc push- is a use shortcut command for push operation …” ↩
npm install 실패 시 플래그 선택
# 1. Node 버전 불일치 (engines 필드) — npm 은 기본이 경고(EBADENGINE)뿐
# 막혔다면 engine-strict 가 켜진 것. --ignore-engines 는 yarn 플래그라 npm 은 무시한다
npm install --engine-strict=false
# 2. peer dependencies 충돌 (가장 흔함)
npm install --legacy-peer-deps
# 3. 마지막 수단 (권장 안함)
npm install --force
--legacy-peer-deps가 필요한 상황
{
"react": "^18.2.0",
// 라이브러리가 아직 React 18 공식 지원 안 하지만 실제로는 동작함.
"react-beautiful-dnd": "^13.1.1" // peer: react@^16.8 || ^17
}
# 프로젝트 전체 적용
echo "legacy-peer-deps=true" > .npmrc
- package.json engines - npm: “Unless the user has set the
engine-strictconfig flag, this field is advisory only and will only produce warnings when your package is installed as a dependency.” - legacy-peer-deps - npm: “Causes npm to completely ignore
peerDependencieswhen building a package tree, as in npm versions 3 through 6.”
file: 로 파일 시스템의 패키지 디렉터리를 의존성으로 건다 — npm install --save ../foo/bar 로 설치하면 상대 경로로 이렇게 저장된다.1
{
"dependencies": {
"bar": "file:../foo/bar"
}
}
Footnotes
-
package.json | npm Docs: “As of version 2.0.0 you can provide a path to a local directory that contains a package.” / “in which case they will be normalized to a relative path and added to your
package.json.” ↩