Skip to content

Commit

Permalink
feat: add loglevel to sandpack opts (#378)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored Feb 18, 2022
1 parent 0f7e0a9 commit a3216e8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions sandpack-client/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getTemplate } from "codesandbox-import-utils/lib/create-sandbox/templates";
import isEqual from "lodash.isequal";
import { SandpackLogLevel } from ".";

import Protocol from "./file-resolver-protocol";
import { IFrameProtocol } from "./iframe-protocol";
Expand Down Expand Up @@ -30,6 +31,10 @@ export interface ClientOptions {
* Location of the bundler.
*/
bundlerURL?: string;
/**
* Level of logging to do in the bundler
*/
logLevel?: SandpackLogLevel;
/**
* Relative path that the iframe loads (eg: /about)
*/
Expand Down Expand Up @@ -289,6 +294,7 @@ export class SandpackClient {
showLoadingScreen: this.options.showLoadingScreen ?? true,
skipEval: this.options.skipEval || false,
clearConsoleDisabled: !this.options.clearConsoleOnFirstCompile,
logLevel: this.options.logLevel,
});
}

Expand Down
9 changes: 9 additions & 0 deletions sandpack-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ export interface ModuleSource {
sourceMap: unknown | undefined;
}

export enum SandpackLogLevel {
None = 0,
Error = 10,
Warning = 20,
Info = 30,
Debug = 40,
}

export interface ErrorStackFrame {
columnNumber: number;
fileName: string;
Expand Down Expand Up @@ -175,6 +183,7 @@ export type SandpackMessage = BaseSandpackMessage &
skipEval: boolean;
clearConsoleDisabled?: boolean;
reactDevTools?: ReactDevToolsMode;
logLevel?: SandpackLogLevel;
}
| {
type: "refresh";
Expand Down
3 changes: 3 additions & 0 deletions sandpack-react/src/contexts/sandpackContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import type {
SandpackMessage,
UnsubscribeFunction,
ReactDevToolsMode,
SandpackLogLevel,
} from "@codesandbox/sandpack-client";
import {
SandpackClient,
Expand Down Expand Up @@ -72,6 +73,7 @@ export interface SandpackProviderProps {

// bundler options
bundlerURL?: string;
logLevel?: SandpackLogLevel;
startRoute?: string;
skipEval?: boolean;
fileResolver?: FileResolver;
Expand Down Expand Up @@ -409,6 +411,7 @@ class SandpackProvider extends React.PureComponent<
{
externalResources: this.props.externalResources,
bundlerURL: this.props.bundlerURL,
logLevel: this.props.logLevel,
startRoute: this.props.startRoute,
fileResolver: this.props.fileResolver,
skipEval: this.props.skipEval,
Expand Down

0 comments on commit a3216e8

Please sign in to comment.