🎨 format code (#1003)

This commit is contained in:
Kuitos 2020-10-15 23:23:49 +08:00 committed by GitHub
parent 261eef8f84
commit 96ebf72bf0
18 changed files with 47 additions and 47 deletions

View File

@ -4,3 +4,6 @@
/docs
/es
/lib
/coverage
.cache
examples

View File

@ -39,8 +39,8 @@
"lint": "yarn lint:js && yarn lint:prettier",
"lint:js": "eslint --cache --ext .js,.jsx,.ts,.tsx --format=pretty ./src",
"lint:fix": "yarn lint:js -- --fix",
"lint:prettier": "check-prettier lint",
"prettier": "prettier -c --write **/*",
"lint:prettier": "prettier -c ./src/**/*",
"prettier": "prettier --write ./src/**/*",
"docs:dev": "dumi dev",
"docs:build": "dumi build",
"ci": "yarn lint && yarn test",
@ -74,7 +74,6 @@
"@types/vfile-message": "1.x",
"@umijs/fabric": "^2.0.7",
"babel-plugin-import": "^1.12.1",
"check-prettier": "^1.0.3",
"cross-env": "^7.0.2",
"dumi": "^1.1.0-beta.24",
"father-build": "^1.7.0",
@ -83,7 +82,7 @@
"lint-staged": "^9.4.2",
"np": "^5.0.3",
"npm-run-all": "^4.1.5",
"prettier": "^1.18.2",
"prettier": "^2.1.2",
"rimraf": "^3.0.0",
"ts-jest": "^25.2.1",
"typescript": "^3.4.5"
@ -96,12 +95,10 @@
},
"lint-staged": {
"**/*.{js,ts,json,css,md}": [
"yarn prettier",
"git add"
"prettier -w"
],
"**/*.{js,ts}": [
"yarn lint:fix",
"git add"
"yarn lint:fix"
]
},
"jest": {

View File

@ -16,11 +16,11 @@ export function registerMicroApps<T extends object = {}>(
lifeCycles?: FrameworkLifeCycles<T>,
) {
// Each app only needs to be registered once
const unregisteredApps = apps.filter(app => !microApps.some(registeredApp => registeredApp.name === app.name));
const unregisteredApps = apps.filter((app) => !microApps.some((registeredApp) => registeredApp.name === app.name));
microApps = [...microApps, ...unregisteredApps];
unregisteredApps.forEach(app => {
unregisteredApps.forEach((app) => {
const { name, activeRule, loader = noop, props, ...appConfig } = app;
registerApplication({

View File

@ -311,7 +311,7 @@ export async function loadApp<T extends object>(
offGlobalStateChange,
}: Record<string, Function> = getMicroAppStateActions(appInstanceId);
const parcelConfigGetter: ParcelConfigObjectGetter = remountContainer => {
const parcelConfigGetter: ParcelConfigObjectGetter = (remountContainer) => {
const parcelConfig: ParcelConfigObject = {
name: appInstanceId,
bootstrap,
@ -341,7 +341,7 @@ export async function loadApp<T extends object>(
mountSandbox,
// exec the chain after rendering to keep the behavior with beforeLoad
async () => execHooksChain(toArray(beforeMount), app, global),
async props => mount({ ...props, container: appWrapperGetter(), setGlobalState, onGlobalStateChange }),
async (props) => mount({ ...props, container: appWrapperGetter(), setGlobalState, onGlobalStateChange }),
// finish loading after app mounted
async () => render({ element: appWrapperElement, loading: false, remountContainer }, 'mounted'),
async () => execHooksChain(toArray(afterMount), app, global),
@ -360,7 +360,7 @@ export async function loadApp<T extends object>(
],
unmount: [
async () => execHooksChain(toArray(beforeUnmount), app, global),
async props => unmount({ ...props, container: appWrapperGetter() }),
async (props) => unmount({ ...props, container: appWrapperGetter() }),
unmountSandbox,
async () => execHooksChain(toArray(afterUnmount), app, global),
async () => {

View File

@ -77,7 +77,7 @@ function prefetch(entry: Entry, opts?: ImportEntryOpts): void {
function prefetchAfterFirstMounted(apps: AppMetadata[], opts?: ImportEntryOpts): void {
window.addEventListener('single-spa:first-mount', function listener() {
const notLoadedApps = apps.filter(app => getAppStatus(app.name) === NOT_LOADED);
const notLoadedApps = apps.filter((app) => getAppStatus(app.name) === NOT_LOADED);
if (process.env.NODE_ENV === 'development') {
const mountedApps = getMountedApps();
@ -103,7 +103,7 @@ export function doPrefetchStrategy(
prefetchStrategy: PrefetchStrategy,
importEntryOpts?: ImportEntryOpts,
) {
const appsName2Apps = (names: string[]): AppMetadata[] => apps.filter(app => names.includes(app.name));
const appsName2Apps = (names: string[]): AppMetadata[] => apps.filter((app) => names.includes(app.name));
if (Array.isArray(prefetchStrategy)) {
prefetchAfterFirstMounted(appsName2Apps(prefetchStrategy as string[]), importEntryOpts);

View File

@ -214,7 +214,7 @@ test('document accessing should modify the attachDocProxySymbol value every time
expect(d1).toBe(document);
});
test('document attachDocProxySymbol mark should be remove before next tasl', done => {
test('document attachDocProxySymbol mark should be remove before next tasl', (done) => {
const { proxy } = new ProxySandbox('doc-symbol');
const d1 = proxy.document;
expect(documentAttachProxyMap.get(d1)).toBe(proxy);
@ -225,10 +225,10 @@ test('document attachDocProxySymbol mark should be remove before next tasl', don
});
});
test('document should work well with MutationObserver', done => {
test('document should work well with MutationObserver', (done) => {
const docProxy = new ProxySandbox('doc').proxy;
const observer = new MutationObserver(mutations => {
const observer = new MutationObserver((mutations) => {
if (mutations[0]) {
expect(mutations[0].target).toBe(document.body);
observer.disconnect();

View File

@ -68,7 +68,7 @@ export function createSandbox(
// must rebuild the side effects which added at bootstrapping firstly to recovery to nature state
if (sideEffectsRebuildersAtBootstrapping.length) {
sideEffectsRebuildersAtBootstrapping.forEach(rebuild => rebuild());
sideEffectsRebuildersAtBootstrapping.forEach((rebuild) => rebuild());
}
/* ------------------------------------------ 2. 开启全局变量补丁 ------------------------------------------*/
@ -78,7 +78,7 @@ export function createSandbox(
/* ------------------------------------------ 3. 重置一些初始化时的副作用 ------------------------------------------*/
// 存在 rebuilder 则表明有些副作用需要重建
if (sideEffectsRebuildersAtMounting.length) {
sideEffectsRebuildersAtMounting.forEach(rebuild => rebuild());
sideEffectsRebuildersAtMounting.forEach((rebuild) => rebuild());
}
// clean up rebuilders
@ -91,7 +91,7 @@ export function createSandbox(
async unmount() {
// record the rebuilders of window side effects (event listeners or timers)
// note that the frees of mounting phase are one-off as it will be re-init at next mounting
sideEffectsRebuilders = [...bootstrappingFreers, ...mountingFreers].map(free => free());
sideEffectsRebuilders = [...bootstrappingFreers, ...mountingFreers].map((free) => free());
sandbox.inactive();
},

View File

@ -53,7 +53,7 @@ export class ScopedCSS {
return;
}
const mutator = new MutationObserver(mutations => {
const mutator = new MutationObserver((mutations) => {
for (let i = 0; i < mutations.length; i += 1) {
const mutation = mutations[i];
@ -83,7 +83,7 @@ export class ScopedCSS {
private rewrite(rules: CSSRule[], prefix: string = '') {
let css = '';
rules.forEach(rule => {
rules.forEach((rule) => {
switch (rule.type) {
case RuleType.STYLE:
css += this.ruleStyle(rule as CSSStyleRule, prefix);
@ -135,11 +135,11 @@ export class ScopedCSS {
}
// handle grouping selector, a,span,p,div { ... }
cssText = cssText.replace(/^[\s\S]+{/, selectors =>
cssText = cssText.replace(/^[\s\S]+{/, (selectors) =>
selectors.replace(/(^|,\n?)([^,]+)/g, (item, p, s) => {
// handle div,body,span { ... }
if (rootSelectorRE.test(item)) {
return item.replace(rootSelectorRE, m => {
return item.replace(rootSelectorRE, (m) => {
// do not discard valid previous character, such as body,html or *:not(:root)
const whitePrevChars = [',', '('];

View File

@ -44,7 +44,7 @@ const styledComponentCSSRulesMap = new WeakMap<HTMLStyleElement, CSSRuleList>();
const dynamicScriptAttachedCommentMap = new WeakMap<HTMLScriptElement, Comment>();
export function recordStyledComponentsCSSRules(styleElements: HTMLStyleElement[]): void {
styleElements.forEach(styleElement => {
styleElements.forEach((styleElement) => {
/*
With a styled-components generated style element, we need to record its cssRules for restore next re-mounting time.
We're doing this because the sheet of style element is going to be cleaned automatically by browser after the style element dom removed from document.
@ -267,11 +267,11 @@ export function patchHTMLDynamicAppendPrototypeFunctions(
) {
HTMLHeadElement.prototype.removeChild = getNewRemoveChild(
rawHeadRemoveChild,
element => containerConfigGetter(element).appWrapperGetter,
(element) => containerConfigGetter(element).appWrapperGetter,
);
HTMLBodyElement.prototype.removeChild = getNewRemoveChild(
rawBodyRemoveChild,
element => containerConfigGetter(element).appWrapperGetter,
(element) => containerConfigGetter(element).appWrapperGetter,
);
}
@ -289,7 +289,7 @@ export function rebuildCSSRules(
styleSheetElements: HTMLStyleElement[],
reAppendElement: (stylesheetElement: HTMLStyleElement) => void,
) {
styleSheetElements.forEach(stylesheetElement => {
styleSheetElements.forEach((stylesheetElement) => {
// re-append the dynamic stylesheet to sub-app container
// Using document.head.appendChild ensures that appendChild invocation can also directly use the HTMLHeadElement.prototype.appendChild method which is overwritten at mounting phase
reAppendElement(stylesheetElement);

View File

@ -40,7 +40,7 @@ export function patchLooseSandbox(
and remove them after the url change triggered and qiankun app is unmouting
see https://github.com/ReactTraining/history/blob/master/modules/createHashHistory.js#L222-L230
*/
() => checkActivityFunctions(window.location).some(name => name === appName),
() => checkActivityFunctions(window.location).some((name) => name === appName),
() => ({
appName,
appWrapperGetter,
@ -70,7 +70,7 @@ export function patchLooseSandbox(
// the dynamic style sheet would be removed automatically while unmoutting
return function rebuild() {
rebuildCSSRules(dynamicStyleSheetElements, stylesheetElement =>
rebuildCSSRules(dynamicStyleSheetElements, (stylesheetElement) =>
// Using document.head.appendChild ensures that appendChild invocation can also directly use the HTMLHeadElement.prototype.appendChild method which is overwritten at mounting phase
document.head.appendChild.call(appWrapperGetter(), stylesheetElement),
);

View File

@ -75,8 +75,8 @@ export function patchStrictSandbox(
const unpatchDocumentCreate = patchDocumentCreateElement();
const unpatchDynamicAppendPrototypeFunctions = patchHTMLDynamicAppendPrototypeFunctions(
element => elementAttachContainerConfigMap.has(element),
element => elementAttachContainerConfigMap.get(element)!,
(element) => elementAttachContainerConfigMap.has(element),
(element) => elementAttachContainerConfigMap.get(element)!,
);
if (!mounting) bootstrappingPatchCount++;
@ -102,7 +102,7 @@ export function patchStrictSandbox(
// the dynamic style sheet would be removed automatically while unmoutting
return function rebuild() {
rebuildCSSRules(dynamicStyleSheetElements, stylesheetElement =>
rebuildCSSRules(dynamicStyleSheetElements, (stylesheetElement) =>
rawHeadAppendChild.call(appWrapperGetter(), stylesheetElement),
);
};

View File

@ -41,12 +41,12 @@ export default function patch() {
if (historyListeners.length) {
rebuild = () => {
// 必须使用 window.g_history.listen 的方式重新绑定 listener从而能保证 rebuild 这部分也能被捕获到,否则在应用卸载后无法正确的移除这部分副作用
historyListeners.forEach(listener => (window as any).g_history.listen(listener));
historyListeners.forEach((listener) => (window as any).g_history.listen(listener));
};
}
// 卸载余下的 listener
historyUnListens.forEach(unListen => unListen());
historyUnListens.forEach((unListen) => unListen());
// restore
if ((window as any).g_history && isFunction((window as any).g_history.listen)) {

View File

@ -38,7 +38,7 @@ export function patchAtMounting(
],
};
return patchersInSandbox[sandbox.type]?.map(patch => patch());
return patchersInSandbox[sandbox.type]?.map((patch) => patch());
}
export function patchAtBootstrapping(
@ -60,7 +60,7 @@ export function patchAtBootstrapping(
],
};
return patchersInSandbox[sandbox.type]?.map(patch => patch());
return patchersInSandbox[sandbox.type]?.map((patch) => patch());
}
export { css };

View File

@ -13,7 +13,7 @@ export default function patch(global: Window) {
let intervals: number[] = [];
global.clearInterval = (intervalId: number) => {
intervals = intervals.filter(id => id !== intervalId);
intervals = intervals.filter((id) => id !== intervalId);
return rawWindowClearInterval(intervalId);
};
@ -24,7 +24,7 @@ export default function patch(global: Window) {
};
return function free() {
intervals.forEach(id => global.clearInterval(id));
intervals.forEach((id) => global.clearInterval(id));
global.setInterval = rawWindowInterval;
global.clearInterval = rawWindowClearInterval;

View File

@ -36,7 +36,7 @@ export default function patch(global: WindowProxy) {
return function free() {
listenerMap.forEach((listeners, type) =>
[...listeners].forEach(listener => global.removeEventListener(type, listener)),
[...listeners].forEach((listener) => global.removeEventListener(type, listener)),
);
global.addEventListener = rawAddEventListener;
global.removeEventListener = rawRemoveEventListener;

View File

@ -73,11 +73,11 @@ function createFakeWindow(global: Window) {
> A property cannot be reported as non-configurable, if it does not exists as an own property of the target object or if it exists as a configurable own property of the target object.
*/
Object.getOwnPropertyNames(global)
.filter(p => {
.filter((p) => {
const descriptor = Object.getOwnPropertyDescriptor(global, p);
return !descriptor?.configurable;
})
.forEach(p => {
.forEach((p) => {
const descriptor = Object.getOwnPropertyDescriptor(global, p);
if (descriptor) {
const hasGetter = Object.prototype.hasOwnProperty.call(descriptor, 'get');
@ -150,7 +150,7 @@ export default class ProxySandbox implements SandBox {
}
if (--activeSandboxCount === 0) {
variableWhiteList.forEach(p => {
variableWhiteList.forEach((p) => {
if (this.proxy.hasOwnProperty(p)) {
// @ts-ignore
delete window[p];

View File

@ -38,7 +38,7 @@ export default class SnapshotSandbox implements SandBox {
active() {
// 记录当前快照
this.windowSnapshot = {} as Window;
iter(window, prop => {
iter(window, (prop) => {
this.windowSnapshot[prop] = window[prop];
});
@ -53,7 +53,7 @@ export default class SnapshotSandbox implements SandBox {
inactive() {
this.modifyPropsMap = {};
iter(window, prop => {
iter(window, (prop) => {
if (window[prop] !== this.windowSnapshot[prop]) {
// 记录变更,恢复环境
this.modifyPropsMap[prop] = window[prop];

View File

@ -11,7 +11,7 @@ export function toArray<T>(array: T | T[]): T[] {
}
export function sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise((resolve) => setTimeout(resolve, ms));
}
/**