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

[POC] refactor: hide internal modules #4249

Closed
wants to merge 1 commit into from

Conversation

wzhudev
Copy link
Member

@wzhudev wzhudev commented Sep 30, 2019

这个 PR 的意义是测试我们能否隐藏一些内部实现的模块,避免被用户所感知。

在实现二级入口的时候留下了一个问题:


重新导出二级入口的内容

在确保二级入口能够正确打包之后,我们还必须确保一级入口能够重新导出(re-export)所有二级入口的内容,以保持对旧的引入方式的兼容。方法是修改 ng-zorro-antd.module.ts 中对组件的导出方式:

+ export * from 'ng-zorro-antd/affix';
- export * from './affix/';

然而 ng-packagr 的一个 bug 会造成导出同名变量的冲突。原因是,ngc 要求导出一个 module 下所有的 directive component service 和子 module,如果开发者没有在入口文件中显式的导出它们,ngc 就会隐式地导出,例如 date picker 组件的入口文件 ng-zorro-antd-date-picker.d.ts 里就有一些隐式导出的 component 和 module:

export * from './public-api';
export { AbstractPickerComponent as ɵp } from './abstract-picker.component';
export { DateRangePickerComponent as ɵo } from './date-range-picker.component';
export { HeaderPickerComponent as ɵr } from './header-picker.component';
export { CalendarFooterComponent as ɵd } from './lib/calendar/calendar-footer.component';
export { CalendarHeaderComponent as ɵb } from './lib/calendar/calendar-header.component';
export { CalendarInputComponent as ɵc } from './lib/calendar/calendar-input.component';
export { OkButtonComponent as ɵe } from './lib/calendar/ok-button.component';
export { TimePickerButtonComponent as ɵf } from './lib/calendar/time-picker-button.component';
export { TodayButtonComponent as ɵg } from './lib/calendar/today-button.component';
export { DateTableComponent as ɵh } from './lib/date/date-table.component';
export { DecadePanelComponent as ɵl } from './lib/decade/decade-panel.component';
export { LibPackerModule as ɵa } from './lib/lib-packer.module';
export { MonthPanelComponent as ɵj } from './lib/month/month-panel.component';
export { MonthTableComponent as ɵk } from './lib/month/month-table.component';
export { DateRangePopupComponent as ɵn } from './lib/popups/date-range-popup.component';
export { InnerPopupComponent as ɵm } from './lib/popups/inner-popup.component';
export { YearPanelComponent as ɵi } from './lib/year/year-panel.component';
export { NzPickerComponent as ɵq } from './picker.component';

这在没有二级入口的情况下不会触发 bug,但是如果我们在一级入口重新导出,而且其他 module 也有这种隐式导出的话,就会发生导出重名变量的冲突。解决的办法是显式地导出这些变量。然而这带来了另外一个问题,即一些内部实现的东西也暴露给用户了。

比较合理解决方案是 ng-packagr 给 SEP 起一个有两级结构的 alias,比如 alias as θda 而不是 as θa。我们会在以后尝试修复掉这个瑕疵。


原文在这里

这个 PR 旨在修复该瑕疵,向用户隐藏内部,特别是较为复杂组件的细节。


This pull request is to hide some implementation details from users, especially those of complicated components.

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

[ ] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[x] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Application (the showcase website) / infrastructure changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

@pr-triage pr-triage bot added the PR: draft label Sep 30, 2019
@netlify
Copy link

netlify bot commented Sep 30, 2019

Deploy preview for ng-zorro-master ready!

Built with commit 8ec836d

https://deploy-preview-4249--ng-zorro-master.netlify.com

@codecov
Copy link

codecov bot commented Sep 30, 2019

Codecov Report

Merging #4249 into master will decrease coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4249      +/-   ##
==========================================
- Coverage   92.31%   92.31%   -0.01%     
==========================================
  Files         519      519              
  Lines       10963    10963              
  Branches     1984     1984              
==========================================
- Hits        10121    10120       -1     
  Misses        419      419              
- Partials      423      424       +1
Impacted Files Coverage Δ
components/time-picker/time-holder.ts 95.61% <0%> (-0.88%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5868ff3...8ec836d. Read the comment docs.

@wzhudev wzhudev marked this pull request as ready for review October 14, 2019 02:11
@pr-triage pr-triage bot removed the PR: draft label Oct 14, 2019
@auto-assign auto-assign bot requested a review from hsuanxyz October 14, 2019 02:11
@wzhudev wzhudev changed the title chore: hide internal modules refactor: hide internal modules Oct 14, 2019
@wzhudev wzhudev changed the title refactor: hide internal modules [POC] refactor: hide internal modules Oct 16, 2019
@wzhudev
Copy link
Member Author

wzhudev commented Oct 16, 2019

这里只是一个实验,大家可以在修改自己的组件时决定是否需要隐藏内部实现。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants