Skip to content

Commit

Permalink
feat: modify default export
Browse files Browse the repository at this point in the history
  • Loading branch information
imtaotao committed Sep 7, 2021
1 parent 8bf693f commit d288bce
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions packages/runtime/browser-snapshot/__tests__/sandbox.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SnapshotSandbox } from '../src/sandbox';
import { Sandbox } from '../src/sandbox';

describe('test sandbox ', () => {
it('dom sandbox', () => {
Expand All @@ -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;';
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/browser-snapshot/src/globalExtensions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SnapshotSandbox } from './sandbox';
import { Sandbox } from './sandbox';

declare module '@garfish/core' {
export namespace interfaces {
Expand All @@ -9,7 +9,7 @@ declare module '@garfish/core' {
}

export interface App {
snapshotSandbox?: SnapshotSandbox;
snapshotSandbox?: Sandbox;
}

export interface Plugin {
Expand Down
13 changes: 5 additions & 8 deletions packages/runtime/browser-snapshot/src/index.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 };

Expand All @@ -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;
}
},
Expand All @@ -57,5 +56,3 @@ export default function BrowserSnapshot(op?: BrowserConfig) {
return options;
};
}

export { SnapshotSandbox } from './sandbox';
2 changes: 1 addition & 1 deletion packages/runtime/browser-snapshot/src/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/browser-vm/__tests__/dom.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Sandbox } from '../src/index';
import { Sandbox } from '../src/sandbox';

// Garfish 使用 Proxy 对 dom 进行了劫持, 同时对调用 dom 的函数做了劫持, 修正 dom 节点的类型
// 对调用 dom 的相关方法进行测试
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/browser-vm/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down Expand Up @@ -64,7 +64,7 @@ const compatibleOldModulesType = (modules): Array<Module> => {
};

// Default export Garfish plugin
export default function BrowserVm() {
export function GarfishBrowserVm() {
return function (Garfish: interfaces.Garfish): interfaces.Plugin {
// Garfish apis
Garfish.getGlobalObject = () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime/garfish/src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/router/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ interface Options {
onNotMatchRouter?: (path: string) => Promise<void> | void;
}

export default function Router(_args?: Options) {
export function GarfishRouter(_args?: Options) {
return function (Garfish: interfaces.Garfish): interfaces.Plugin {
Garfish.apps = {};
Garfish.router = router;
Expand Down

0 comments on commit d288bce

Please sign in to comment.