From d288bce9c6bf754c9803edc40a094ccf9147088f Mon Sep 17 00:00:00 2001 From: "chentao.arthur" Date: Tue, 7 Sep 2021 12:06:42 +0800 Subject: [PATCH] feat: modify default export --- .../browser-snapshot/__tests__/sandbox.spec.ts | 4 ++-- .../browser-snapshot/src/globalExtensions.ts | 4 ++-- packages/runtime/browser-snapshot/src/index.ts | 13 +++++-------- packages/runtime/browser-snapshot/src/sandbox.ts | 2 +- packages/runtime/browser-vm/__tests__/dom.spec.ts | 2 +- packages/runtime/browser-vm/src/index.ts | 4 ++-- packages/runtime/garfish/src/index.ts | 6 +++--- packages/runtime/router/src/index.ts | 2 +- 8 files changed, 17 insertions(+), 20 deletions(-) diff --git a/packages/runtime/browser-snapshot/__tests__/sandbox.spec.ts b/packages/runtime/browser-snapshot/__tests__/sandbox.spec.ts index a4e9b2dd3..608546078 100644 --- a/packages/runtime/browser-snapshot/__tests__/sandbox.spec.ts +++ b/packages/runtime/browser-snapshot/__tests__/sandbox.spec.ts @@ -1,4 +1,4 @@ -import { SnapshotSandbox } from '../src/sandbox'; +import { Sandbox } from '../src/sandbox'; describe('test sandbox ', () => { it('dom sandbox', () => { @@ -12,7 +12,7 @@ describe('test sandbox ', () => { some: 'test delete', }; - const sb = new SnapshotSandbox('app1', [], obj); + const sb = new Sandbox('app1', [], obj); const st = document.createElement('style'); st.style.cssText = 'background: red;'; diff --git a/packages/runtime/browser-snapshot/src/globalExtensions.ts b/packages/runtime/browser-snapshot/src/globalExtensions.ts index 9906fb01b..52a74ca7e 100644 --- a/packages/runtime/browser-snapshot/src/globalExtensions.ts +++ b/packages/runtime/browser-snapshot/src/globalExtensions.ts @@ -1,4 +1,4 @@ -import { SnapshotSandbox } from './sandbox'; +import { Sandbox } from './sandbox'; declare module '@garfish/core' { export namespace interfaces { @@ -9,7 +9,7 @@ declare module '@garfish/core' { } export interface App { - snapshotSandbox?: SnapshotSandbox; + snapshotSandbox?: Sandbox; } export interface Plugin { diff --git a/packages/runtime/browser-snapshot/src/index.ts b/packages/runtime/browser-snapshot/src/index.ts index 6f59ccf47..7e510bcf2 100644 --- a/packages/runtime/browser-snapshot/src/index.ts +++ b/packages/runtime/browser-snapshot/src/index.ts @@ -1,7 +1,9 @@ -import { SnapshotSandbox } from './sandbox'; +import { Sandbox } from './sandbox'; import { interfaces } from '@garfish/core'; import './globalExtensions'; +export { Sandbox as default } from './sandbox'; + export interface SandboxConfig { snapshot?: boolean; disableWith?: boolean; @@ -13,7 +15,7 @@ interface BrowserConfig { protectVariable?: PropertyKey[]; } -export default function BrowserSnapshot(op?: BrowserConfig) { +export function GarfishBrowserSnapshot(op?: BrowserConfig) { return function (Garfish: interfaces.Garfish): interfaces.Plugin { const config: BrowserConfig = op || { open: true }; @@ -37,10 +39,7 @@ export default function BrowserSnapshot(op?: BrowserConfig) { if (appInstance) { // existing if (appInstance.snapshotSandbox) return; - const sandbox = new SnapshotSandbox( - appInfo.name, - config.protectVariable, - ); + const sandbox = new Sandbox(appInfo.name, config.protectVariable); appInstance.snapshotSandbox = sandbox; } }, @@ -57,5 +56,3 @@ export default function BrowserSnapshot(op?: BrowserConfig) { return options; }; } - -export { SnapshotSandbox } from './sandbox'; diff --git a/packages/runtime/browser-snapshot/src/sandbox.ts b/packages/runtime/browser-snapshot/src/sandbox.ts index a2913a278..81504a8c0 100644 --- a/packages/runtime/browser-snapshot/src/sandbox.ts +++ b/packages/runtime/browser-snapshot/src/sandbox.ts @@ -5,7 +5,7 @@ import { PatchInterval } from './patchers/interval'; import { PatchGlobalVal } from './patchers/variable'; import { PatchWebpackJsonp } from './patchers/webpackjsonp'; -export class SnapshotSandbox { +export class Sandbox { public type = 'snapshot'; public isRunning: Boolean = false; private patchList: Array< diff --git a/packages/runtime/browser-vm/__tests__/dom.spec.ts b/packages/runtime/browser-vm/__tests__/dom.spec.ts index 0f2e29af4..d0d22c8c9 100644 --- a/packages/runtime/browser-vm/__tests__/dom.spec.ts +++ b/packages/runtime/browser-vm/__tests__/dom.spec.ts @@ -1,4 +1,4 @@ -import { Sandbox } from '../src/index'; +import { Sandbox } from '../src/sandbox'; // Garfish 使用 Proxy 对 dom 进行了劫持, 同时对调用 dom 的函数做了劫持, 修正 dom 节点的类型 // 对调用 dom 的相关方法进行测试 diff --git a/packages/runtime/browser-vm/src/index.ts b/packages/runtime/browser-vm/src/index.ts index 0eb6ea256..35a788640 100644 --- a/packages/runtime/browser-vm/src/index.ts +++ b/packages/runtime/browser-vm/src/index.ts @@ -2,7 +2,7 @@ import { interfaces } from '@garfish/core'; import { warn, isPlainObject } from '@garfish/utils'; import { Sandbox } from './sandbox'; import { Module, SandboxOptions } from './types'; -export { Sandbox } from './sandbox'; +export { Sandbox as default } from './sandbox'; // export declare module declare module '@garfish/core' { @@ -64,7 +64,7 @@ const compatibleOldModulesType = (modules): Array => { }; // Default export Garfish plugin -export default function BrowserVm() { +export function GarfishBrowserVm() { return function (Garfish: interfaces.Garfish): interfaces.Plugin { // Garfish apis Garfish.getGlobalObject = () => { diff --git a/packages/runtime/garfish/src/index.ts b/packages/runtime/garfish/src/index.ts index 711928cd2..14e1d042e 100644 --- a/packages/runtime/garfish/src/index.ts +++ b/packages/runtime/garfish/src/index.ts @@ -1,7 +1,7 @@ import { Garfish } from '@garfish/core'; -import GarfishRouter from '@garfish/router'; -import GarfishBrowserVm from '@garfish/browser-vm'; -import GarfishBrowserSnapshot from '@garfish/browser-snapshot'; +import { GarfishRouter } from '@garfish/router'; +import { GarfishBrowserVm } from '@garfish/browser-vm'; +import { GarfishBrowserSnapshot } from '@garfish/browser-snapshot'; import { def, warn, diff --git a/packages/runtime/router/src/index.ts b/packages/runtime/router/src/index.ts index 89c47230e..26d690b25 100644 --- a/packages/runtime/router/src/index.ts +++ b/packages/runtime/router/src/index.ts @@ -38,7 +38,7 @@ interface Options { onNotMatchRouter?: (path: string) => Promise | void; } -export default function Router(_args?: Options) { +export function GarfishRouter(_args?: Options) { return function (Garfish: interfaces.Garfish): interfaces.Plugin { Garfish.apps = {}; Garfish.router = router;