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

fix: fix eslint error #2740

Merged
merged 2 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/loader/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { Sandbox } from '@qiankunjs/sandbox';
import { qiankunHeadTagName } from '@qiankunjs/sandbox';
import type { BaseTranspilerOpts } from '@qiankunjs/shared';
import {
Expand Down Expand Up @@ -25,7 +26,7 @@ type Entry = HTMLEntry;
export type ImportOpts = {
decoder?: (chunk: string) => string;
nodeTransformer?: typeof transpileAssets;
} & BaseTranspilerOpts;
} & BaseTranspilerOpts & { sandbox?: Sandbox };

/**
* @param entry
Expand Down
4 changes: 0 additions & 4 deletions packages/qiankun/src/core/loadApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,6 @@ export default async function loadApp<T extends ObjectType>(
}

function initContainer(container: HTMLElement, appName: string, sandboxCfg: AppConfiguration['sandbox']): void {
if (!container) {
throw new QiankunError('container is not existed');
}

while (container.firstChild) {
container.removeChild(container.firstChild);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sandbox/src/core/compartment/globalProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function shouldSkipProperty(global: WindowProxy, p: string | number): boolean {
if (isIE11()) {
// https://github.com/kuitos/import-html-entry/pull/32,最小化 try 范围
try {
return global[p as number] && typeof window !== 'undefined' && global[p as number].parent === window;
return !!global[p as keyof WindowProxy] && typeof window !== 'undefined' && global[p as number].parent === window;
} catch (err) {
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/sandbox/src/core/compartment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare global {
interface Window {
__compartment_window__?: Window;

[p: CompartmentGlobalId]: WindowProxy;
[p: CompartmentGlobalId]: WindowProxy | undefined;
}
}

Expand Down
3 changes: 2 additions & 1 deletion packages/sandbox/src/core/sandbox/globals.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// generated from https://github.com/sindresorhus/globals/blob/main/globals.json es2015 part
// only init its values while Proxy is supported
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
export const globals = window.Proxy
? [
'Array',
Expand Down Expand Up @@ -60,4 +61,4 @@ export const globals = window.Proxy
'WeakMap',
'WeakSet',
].filter((p) => /* just keep the available properties in current window context */ p in window)
: [];
: [];
1 change: 1 addition & 0 deletions packages/sandbox/src/core/sandbox/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function createSandboxContainer(
) {
const { globalContext, extraGlobals = {} } = opts;
let sandbox: Sandbox;
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
if (window.Proxy) {
sandbox = new StandardSandbox(appName, extraGlobals, globalContext);
} else {
Expand Down
5 changes: 1 addition & 4 deletions packages/sandbox/src/patchers/dynamicAppend/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ export function isHijackingTag(tagName?: string) {
* @param element
*/
export function isStyledComponentsLike(element: HTMLStyleElement) {
return (
!element.textContent &&
((element.sheet as CSSStyleSheet)?.cssRules.length || getStyledElementCSSRules(element)?.length)
);
return !element.textContent && (element.sheet?.cssRules.length || getStyledElementCSSRules(element)?.length);
}

const appsCounterMap = new Map<string, { bootstrappingPatchCount: number; mountingPatchCount: number }>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ declare global {
}

interface Window {
__sandboxConfigWeakMap__: WeakMap<Sandbox, SandboxConfig>;
__currentLockingSandbox__: Sandbox;
__sandboxConfigWeakMap__?: WeakMap<Sandbox, SandboxConfig>;
__currentLockingSandbox__?: Sandbox;
}

interface Document {
Expand Down Expand Up @@ -260,7 +260,7 @@ export function patchStandardSandbox(
if (typeof refNo === 'number' && refNo !== -1) {
// the reference node may be dynamic script comment which is not rebuilt while remounting thus reference node no longer exists
// in this case, we should append the style element to the end of mountDom
const refNode = mountDom.childNodes[refNo] || null;
const refNode = mountDom.childNodes[refNo];
rawHeadInsertBefore.call(mountDom, stylesheetElement, refNode);
return true;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sandbox/src/patchers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function patchAtBootstrapping(appName: string, getContainer: () => HTMLEl
[SandboxType.Snapshot]: [],
} as const;

return patchersInSandbox[sandbox.type]?.map((patch) => patch());
return patchersInSandbox[sandbox.type].map((patch) => patch());
}

export function patchAtMounting(appName: string, getContainer: () => HTMLElement, sandbox: Sandbox): Free[] {
Expand All @@ -35,5 +35,5 @@ export function patchAtMounting(appName: string, getContainer: () => HTMLElement
[SandboxType.Snapshot]: basePatchers,
};

return patchersInSandbox[sandbox.type]?.map((patch) => patch());
return patchersInSandbox[sandbox.type].map((patch) => patch());
}
21 changes: 9 additions & 12 deletions packages/sandbox/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ export function isConstructable(fn: CallableFunction): fn is CallableFunction {

if (hasPrototypeMethods) return true;

const cachedValue = fnRegexCheckCacheMap.get(fn);
if (typeof cachedValue !== 'undefined') {
return cachedValue;
const cachedResult = fnRegexCheckCacheMap.get(fn);
if (typeof cachedResult !== 'undefined') {
return cachedResult;
}

let constructable: boolean = hasPrototypeMethods;
if (!constructable) {
// fn.toString has a significant performance overhead, if hasPrototypeMethods check not passed, we will check the function string with regex
const fnString = fn.toString();
const constructableFunctionRegex = /^function\b\s[A-Z].*/;
const classRegex = /^class\b/;
constructable = constructableFunctionRegex.test(fnString) || classRegex.test(fnString);
}
// fn.toString has a significant performance overhead, if hasPrototypeMethods check not passed, we will check the function string with regex
const fnString = fn.toString();
const constructableFunctionRegex = /^function\b\s[A-Z].*/;
const classRegex = /^class\b/;
const constructable = constructableFunctionRegex.test(fnString) || classRegex.test(fnString);

fnRegexCheckCacheMap.set(fn, constructable);
return constructable;
Expand Down Expand Up @@ -56,7 +53,7 @@ export function isCallable(fn: unknown): fn is CallableFunction {
const frozenPropertyCacheMap = new WeakMap<object, Record<PropertyKey, boolean>>();

export function isPropertyFrozen(target: object, p?: PropertyKey): boolean {
if (!target || !p) {
if (!p) {
return false;
}

Expand Down
8 changes: 3 additions & 5 deletions packages/shared/src/assets-transpilers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@
* @author Kuitos
* @since 2023-08-26
*/
// import type { Sandbox } from '@qiankunjs/sandbox';
import type { BaseLoaderOpts } from '../common';

import type { MatchResult } from '../module-resolver';

export type BaseTranspilerOpts = BaseLoaderOpts & {
moduleResolver?: (url: string) => MatchResult | undefined;
// TODO: 先把 sandbox 类型设置如下,解除和 @qiankunjs/loader 相互依赖的问题
// eslint-disable-next-line @typescript-eslint/no-explicit-any
sandbox?: Record<string, any>;
sandbox?: {
makeEvaluateFactory(source: string, sourceURL?: string): string;
};
};

export type AssetsTranspilerOpts = BaseTranspilerOpts & { rawNode: Node };
Expand Down