Ch 04. pub.dev에 패키지 배포하기
pub.dev는 Dart와 Flutter의 공식 패키지 저장소입니다. 누구나 무료로 패키지를 배포할 수 있고, 전 세계 개발자들이 바로 사용할 수 있습니다. dart pub publish 명령 하나로 배포가 완료됩니다. 하지만 그 전에 준비해야 할 것들이 있습니다.
배포 전 체크리스트
배포 전에 다음 항목을 모두 확인합니다.
첫째, pubspec.yaml이 올바른지 확인합니다.
# 수정: pubspec.yamlname: dart_validatordescription: A comprehensive validation utility library for Dart. Validates emails, phone numbers, URLs, passwords, and more.version: 0.1.0homepage: https://github.com/yourusername/dart_validatorenvironment: sdk: '>=3.0.0 <4.0.0'dev_dependencies: lints: ^3.0.0 test: ^1.24.0
description은 60자 이상이어야 pub.dev 점수에서 감점되지 않습니다. homepage는 패키지를 찾을 수 있는 URL을 입력합니다.
둘째, LICENSE 파일이 있는지 확인합니다.
// 새 파일: LICENSE
MIT License
Copyright (c) 2024 Your Name
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT 라이선스가 가장 많이 사용됩니다. BSD, Apache 2.0도 pub.dev에서 인식됩니다. 라이선스 파일이 없으면 pub.dev 점수에서 30점이 감점됩니다.
pana로 사전 점수 확인
실제 배포 전에 pana로 점수를 미리 확인합니다.
dart pub global activate panapana --no-warning .
출력 예시입니다.
Package analysis of dart_validator:
Scores:
Pub Points: 120 / 130
Issues:
[*] 10/10: Package is platform independent.
[*] 20/20: Provides documentation.
[*] 20/20: Passes static analysis.
...
점수가 낮은 항목을 확인하고 배포 전에 수정합니다. 가장 흔한 감점 요인은 dartdoc 커버리지 부족, 라이선스 누락, SDK 버전 범위 문제입니다.
dry-run으로 배포 시뮬레이션
실제로 배포하지 않고 과정만 시뮬레이션합니다.
dart pub publish --dry-run
어떤 파일이 배포 패키지에 포함되는지, 문제가 있는지 확인할 수 있습니다.
Publishing dart_validator 0.1.0 to https://pub.dartlang.org:
|-- .dart_tool/
|-- CHANGELOG.md
|-- LICENSE
|-- README.md
|-- analysis_options.yaml
|-- example/
| '-- dart_validator_example.dart
|-- lib/
| |-- dart_validator.dart
| '-- src/
| |-- password_strength.dart
| |-- validation_result.dart
| |-- validator_chain.dart
| '-- validators.dart
|-- pubspec.yaml
'-- test/
|-- password_strength_test.dart
|-- validation_result_test.dart
|-- validator_chain_test.dart
'-- validators_test.dart
Package has 0 warnings.
경고(warnings)가 0이면 배포 준비가 완료된 것입니다.
불필요한 파일을 배포 패키지에서 제외하려면 .pubignore 파일을 만듭니다.
// 새 파일: .pubignore
coverage/
doc/
*.sh
실제 배포
dart pub publish
처음 배포할 때는 Google 계정 인증이 필요합니다. 터미널에 URL이 표시되면 브라우저에서 열어서 로그인합니다.
Publishing dart_validator 0.1.0 to https://pub.dartlang.org:
Looks great! Are you ready to upload your package (y/n)?
y를 입력하면 배포가 시작됩니다. 보통 수 초 내에 완료됩니다.
배포가 완료되면 pub.dev에서 바로 확인할 수 있습니다.
https://pub.dev/packages/dart_validator
단, 처음 배포된 패키지는 "verified publisher"가 없으면 pub.dev 점수가 낮게 표시됩니다. Publisher 인증은 별도로 진행해야 합니다.
pub.dev 점수 이해하기
pub.dev는 각 패키지에 최대 130점의 점수를 부여합니다. 점수 구성은 다음과 같습니다.
| 항목 | 점수 | 내용 |
|---|---|---|
| Follow Dart file conventions | 10 | pubspec.yaml 필수 필드 |
| Provide documentation | 20 | dartdoc 커버리지, README |
| Platform support | 20 | 플랫폼 독립성 |
| Pass static analysis | 50 | 분석 오류 없음 |
| Support up-to-date dependencies | 20 | 최신 SDK, 의존성 |
| Null safety | 10 | null safety 지원 |
100점 이상이면 pub.dev에서 "likes" 버튼 옆에 점수가 표시됩니다.
배포 실패 대응
배포 후 심각한 버그를 발견한 경우, pub.dev에서는 배포된 버전을 삭제할 수 없습니다. 대신 "retracted"(철회) 상태로 표시할 수 있습니다.
dart pub publish --retract
철회된 버전은 pub.dev에 존재하지만, 새로운 프로젝트에서 자동으로 선택되지 않습니다. 기존에 이미 해당 버전을 사용 중인 프로젝트는 계속 사용할 수 있습니다. 철회 후 버그를 수정한 새 버전을 배포하는 것이 올바른 대응입니다.
이번 챕터 정리
- 배포 전에 pubspec.yaml, LICENSE, dartdoc 커버리지를 확인했습니다.
pana로 pub.dev 점수를 미리 확인하는 방법을 배웠습니다.dart pub publish --dry-run으로 배포 시뮬레이션을 실행했습니다.- 실제 배포는
dart pub publish명령 하나로 완료됩니다.
다음 챕터에서는 배포한 패키지를 유지보수하는 방법, 시맨틱 버저닝, breaking change 처리를 다룹니다.