-
Notifications
You must be signed in to change notification settings - Fork 47
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
Add assertion utility function #1602
Conversation
|
Chromatic Report🚀 Congratulations! Your build was successful! |
unused module로 타입 체크가 실패하는데, 이후 PR에서 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어플리케이션에서 NODE_ENV='development' 으로 환경변수 주고 베지어를 사용하면 베지어 안에서도 NODE_ENV='development'로 인식하는게 맞을지 궁금하네요. 그 때 베지어는 이미 빌드된 패키지라서 베지어를 빌드할 때 주는 환경변수 (지금 없는 것 같은데 맞나요..?)를 사용하지 않나 라는 의문이 들었습니다.
라이브러리를 빌드하더라도 process.env가 라이브러리 빌드 시점의 NODE_ENV로 바인딩이 되지 않을거라 생각했어요. 여기는 테스트 결과 esm build : function isDev() {
return process.env.NODE_ENV !== 'production';
}
class AssertionException extends Error {
constructor(message) {
super();
this.name = 'AssertionException';
this.message = message ?? 'assertion failed';
}
}
function assert(predicate, message) {
if (predicate) {
return;
}
if (isDev()) {
throw new AssertionException(message);
}
}
export { assert }; test export function assert(
predicate: boolean,
message?: string,
): asserts predicate {
console.log('process.env.NODE_ENV: ', process.env.NODE_ENV)
if (predicate) {
return
}
if (isDev()) {
throw new AssertionException(message)
}
}
|
Self Checklist
Summary
개발자들의 디버깅 용이성, deprecated된 속성 등을 잘 파악할 수 있는 유틸 함수들을 추가합니다.
Details
process.env.NODE_ENV !== 'production'
인 케이스를 개발 환경으로 정의하고, 이 케이스에서만 에러를 보여주도록 합니다.createContext
유틸에 assert 함수를 적용합니다.Breaking change? (Yes/No)
No
References