Skip to content

Commit

Permalink
fix: sandboxing issue
Browse files Browse the repository at this point in the history
  • Loading branch information
noomorph committed Nov 25, 2023
1 parent 279313d commit bced9fe
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 10 deletions.
13 changes: 3 additions & 10 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import type { BunyanLikeLogger } from './decorator';
import { Bunyamin } from './decorator';
import { noopLogger } from './noopLogger';
import realm from './realm';

export * from './noopLogger';
export * from './traceEventStream';
export * from './uniteTraceEvents';
export * from './wrapLogger';
export * from './is-debug';

const threadGroups: any[] = [];
export const bunyamin = new Bunyamin<BunyanLikeLogger>({ logger: noopLogger(), threadGroups });
export const nobunyamin = new Bunyamin<BunyanLikeLogger>({
logger: noopLogger(),
threadGroups,
immutable: true,
});
export const bunyamin = realm.bunyamin;
export const nobunyamin = realm.nobunyamin;

export default bunyamin;
31 changes: 31 additions & 0 deletions src/realm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import type { BunyanLikeLogger } from './decorator';
import { Bunyamin } from './decorator';
import { noopLogger } from './noopLogger';

type Realm = {
bunyamin: Bunyamin<BunyanLikeLogger>;
nobunyamin: Bunyamin<BunyanLikeLogger>;
};

function create() {
const threadGroups: any[] = [];

Check warning on line 11 in src/realm.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const bunyamin = new Bunyamin<BunyanLikeLogger>({ logger: noopLogger(), threadGroups });
const nobunyamin = new Bunyamin<BunyanLikeLogger>({
logger: noopLogger(),
threadGroups,
immutable: true,
});

return { bunyamin, nobunyamin };
}

function getCached(): Realm | undefined {
return (globalThis as any).__BUNYAMIN__;

Check warning on line 23 in src/realm.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
}

function setCached(realm: Realm) {
(globalThis as any).__BUNYAMIN__ = realm;

Check warning on line 27 in src/realm.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
return realm;
}

export default setCached(getCached() ?? create());

0 comments on commit bced9fe

Please sign in to comment.