Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@channel.io/bezier-icons npm package #1366

Merged
merged 41 commits into from
May 30, 2023

Conversation

sungik-choi
Copy link
Contributor

@sungik-choi sungik-choi commented May 25, 2023

Self Checklist

  • I wrote a PR title in English.
  • I added an appropriate label to the PR.
  • I wrote a commit message in English.
  • I wrote a commit message according to the Conventional Commits specification.
  • I added the appropriate changeset for the changes.
  • [Component] I wrote a unit test about the implementation.
  • [Component] I wrote a storybook document about the implementation.
  • [Component] I tested the implementation in various browsers.
    • Windows: Chrome, Edge, (Optional) Firefox
    • macOS: Chrome, Edge, Safari, (Optional) Firefox
  • [New Component] I added my username to the correct directory in the CODEOWNERS file.

Related Issue

Summary

@channel.io/bezier-icons npm package를 추가합니다.

Details

  • Icon source와 해당 유틸만을 관리하는 bezier-icons 패키지를 추가합니다.
  • 자세한 구현에 대한 코멘트는 셀프 코드 리뷰로 남깁니다.

Next

Breaking change or not (Yes/No)

No

References

@sungik-choi sungik-choi self-assigned this May 25, 2023
@changeset-bot
Copy link

changeset-bot bot commented May 25, 2023

🦋 Changeset detected

Latest commit: c1b237a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@channel.io/bezier-icons Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Patch and project coverage have no change.

Comparison is base (d6f35d4) 84.23% compared to head (c1b237a) 84.23%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1366   +/-   ##
=======================================
  Coverage   84.23%   84.23%           
=======================================
  Files         309      309           
  Lines        3913     3913           
  Branches      804      804           
=======================================
  Hits         3296     3296           
  Misses        546      546           
  Partials       71       71           

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Dogdriip Dogdriip self-requested a review May 26, 2023 07:52
/**
* @type {import('rollup').PluginImpl}
*/
function svgBuild(options = {}) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

빌드 과정에서 icon generate를 실행합니다. bezier-react에선 내부적으로 아이콘을 참조해야했기 때문에 svg react component를 생성해서 가지고 있어야 했습니다. 아이콘 패키지에선 내부적으로 아이콘을 참조하지 않기 때문에, svg react component를 소스로 가지고 있을 필요가 없습니다.

  1. svgo 라이브러리를 통해 svg를 최적화하고
  2. 최적화된 svg를 svgr/core 라이브러리를 통해 svg react component로 변환합니다
  3. 빌드가 완료된 이후엔 원하는 경로에 svg assets들을 생성합니다. (svg assets을 직접 사용하고자 하는 케이스 지원)

Comment on lines +275 to +284
/**
* Module resolution is not working well inside the virtual module, so use the alias plugin to resolve the module manually.
*/
alias({
entries: [{
find: config.input.utils,
replacement: utilBasePath,
}],
}),
babel({
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

virtual을 통해 엔트리 모듈을 생성했을 때, 내부 utils 모듈을 참조하는 것이 잘 되지 않았습니다. 주석에 적힌대로, alias 플러그인을 통해 직접 path를 resolve하여 해결했습니다.


const ICONS_OBJECT = 'icons'

const entryModuleContent = `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

엔트리 모듈을 작성합니다.

  • 개별 아이콘을 import 합니다.
  • (Legacy) icons 객체를 생성합니다. (Record<IconName, BezierIcon>)
  • icons 객체와 개별 아이콘을 export 합니다.
  • utils 를 export 합니다.

export * from '${config.input.utils}'
`

const entryTypesContent = `
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입 선언을 직접 작성합니다.

  • IconSource
  • BezierIcon
    • { __type: ‘BezierIcon’ } 브랜디드 타입을 추가합니다.
    • 기존엔 아이콘 심볼을 포함한 타입이 BezierIcon 이었지만, utils 모듈에 있는 아이콘 심볼의 타입을 타입 선언 파일에 포함할 수 없습니다.
    • isBezierIcon 과 함께 타입 체킹의 용도로 임의 타입을 지정합니다.
    • createBezierIcon, isBezierIcon 모두 내부 구현에서 실제로 심볼 여부를 체크하기 때문에 문제가 없습니다. (utils.ts, utils.test.tsx 참고)
  • IconName
  • 개별 Icon 타입
  • icons 객체 타입

/**
* @type {import('rollup').PluginImpl}
*/
function emitFile({ fileName, source }) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

커스텀하게 작성한 d.ts 파일을 생성하기 위한 간단한 커스텀 플러그인입니다.

Comment on lines +1 to +6
/**
* The type is custom generated during the build process,
* so set the type inside this module to 'any'.
*/

const BEZIER_ICON_SYMBOL = Symbol('bezier.icon')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

주석에 적은대로 타입은 빌드 시 커스텀하게 d.ts 파일을 생성하기 때문에, 자바스크립트처럼 사용했습니다. 동작은 테스트 코드를 통해 검증됩니다.

@sungik-choi sungik-choi changed the base branch from next-v1 to main May 30, 2023 04:42
@sungik-choi sungik-choi merged commit 0291f4a into channel-io:main May 30, 2023
@sungik-choi sungik-choi deleted the feat/bezier-icons branch May 30, 2023 10:40
@yangwooseong yangwooseong added the bezier-icons Issue or PR related to bezier-icons label May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bezier-icons Issue or PR related to bezier-icons
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create bezier-icon package
3 participants