Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Responsible for consuming and syncing with the server/local cache
import localforage from 'localforage';
import _debug from '@codesandbox/common/lib/utils/debug';
import Manager from './manager';
import { SCRIPT_VERSION } from '..';
const debug = _debug('cs:compiler:cache');
const host = process.env.CODESANDBOX_HOST;
const MAX_CACHE_SIZE = 1024 * 1024 * 7;
let APICacheUsed = false;
try {
localforage.config({
name: 'CodeSandboxApp',
storeName: 'sandboxes', // Should be alphanumeric, with underscores.
description:
'Cached transpilations of the sandboxes, for faster initialization time.',
});
// Prewarm store
localforage.keys();
import { getSandboxId } from '@codesandbox/common/lib/utils/url-generator';
import setupConsole from 'sandbox-hooks/console';
import setupHistoryListeners from 'sandbox-hooks/url-listeners';
import {
listenForPreviewSecret,
getPreviewSecret,
} from 'sandbox-hooks/preview-secret';
import { show404 } from 'sandbox-hooks/not-found-screen';
import compile, { getCurrentManager } from './compile';
// Call this before importing React (or any other packages that might import React).
initialize(window);
const host = process.env.CODESANDBOX_HOST;
const debug = _debug('cs:sandbox');
export const SCRIPT_VERSION =
document.currentScript && document.currentScript.src;
debug('Booting sandbox');
requirePolyfills().then(() => {
registerServiceWorker('/sandbox-service-worker.js', {});
function sendReady() {
dispatch({ type: 'initialized' });
}
async function handleMessage(data, source) {
if (source) {
if (data.type === 'compile') {
import history from 'app/utils/history';
import { createOvermind } from 'overmind';
import { Provider as ActualOvermindProvider } from 'overmind-react';
import React from 'react';
import { ApolloProvider } from 'react-apollo';
import { DndProvider } from 'react-dnd';
import { render } from 'react-dom';
import { Router } from 'react-router-dom';
import { ThemeProvider } from 'styled-components';
import { config } from './overmind';
import { Provider as OvermindProvider } from './overmind/Provider';
import { Routes as App } from './pages';
import HTML5Backend from './pages/common/HTML5BackendWithFolderSupport';
const debug = _debug('cs:app');
window.setImmediate = (func, delay) => setTimeout(func, delay);
window.addEventListener('unhandledrejection', e => {
if (e && e.reason && e.reason.name === 'Canceled') {
// This is an error from vscode that vscode uses to cancel some actions
// We don't want to show this to the user
e.preventDefault();
}
});
window.__isTouch = !matchMedia('(pointer:fine)').matches;
const overmind = createOvermind(config, {
devtools:
(window.opener && window.opener !== window) || !window.chrome
import { notificationState } from '@codesandbox/common/lib/utils/notifications';
import { NotificationStatus, Toasts } from '@codesandbox/notifications';
import { useOvermind } from 'app/overmind';
import Loadable from 'app/utils/Loadable';
import React, { useEffect } from 'react';
import { Redirect, Route, Switch, withRouter } from 'react-router-dom';
import { ErrorBoundary } from './common/ErrorBoundary';
import { Modals } from './common/Modals';
import Dashboard from './Dashboard';
import { DevAuthPage } from './DevAuth';
import { Container, Content } from './elements';
import { NewSandbox } from './NewSandbox';
import { Sandbox } from './Sandbox';
const routeDebugger = _debug('cs:app:router');
const SignInAuth = Loadable(() =>
import(/* webpackChunkName: 'page-sign-in' */ './SignInAuth')
);
const SignIn = Loadable(() =>
import(/* webpackChunkName: 'page-sign-in' */ './SignIn')
);
const Live = Loadable(() =>
import(/* webpackChunkName: 'page-sign-in' */ './Live').then(module => ({
default: module.LivePage,
}))
);
const ZeitSignIn = Loadable(() =>
import(/* webpackChunkName: 'page-zeit' */ './ZeitAuth')
);
const PreviewAuth = Loadable(() =>
import registerServiceWorker from '@codesandbox/common/lib/registerServiceWorker';
import requirePolyfills from '@codesandbox/common/lib/load-dynamic-polyfills';
import { getModulePath } from '@codesandbox/common/lib/sandbox/modules';
import { generateFileFromSandbox } from '@codesandbox/common/lib/templates/configuration/package-json';
import { getSandboxId } from '@codesandbox/common/lib/utils/url-generator';
import setupConsole from 'sandbox-hooks/console';
import setupHistoryListeners from 'sandbox-hooks/url-listeners';
import compile, { getCurrentManager } from './compile';
// Call this before importing React (or any other packages that might import React).
initialize(window);
const host = process.env.CODESANDBOX_HOST;
const debug = _debug('cs:sandbox');
export const SCRIPT_VERSION =
document.currentScript && document.currentScript.src;
debug('Booting sandbox');
requirePolyfills().then(() => {
registerServiceWorker('/sandbox-service-worker.js', {});
function sendReady() {
dispatch({ type: 'initialized' });
}
async function handleMessage(data, source) {
if (source) {
if (data.type === 'compile') {
evalBoilerplates,
findBoilerplate,
} from './boilerplates';
import loadDependencies from './npm';
import { consumeCache, saveCache, deleteAPICache } from './eval/cache';
import { showRunOnClick } from './status-screen/run-on-click';
import { Module } from './eval/entities/module';
import TranspiledModule from './eval/transpiled-module';
let initializedResizeListener = false;
let manager: Manager | null = null;
let actionsEnabled = false;
const debug = _debug('cs:compiler');
export function areActionsEnabled() {
return actionsEnabled;
}
export function getCurrentManager(): Manager | null {
return manager;
}
export function getHTMLParts(html: string) {
if (html.includes('')) {
const bodyMatcher = /([\s\S]*)<\/body>/m;
const headMatcher = /([\s\S]*)<\/head>/m;
const headMatch = html.match(headMatcher);
const bodyMatch = html.match(bodyMatcher);
roomInfo: RoomInfo;
};
type JoinChannelTransformedResponse = JoinChannelResponse & {
sandbox: Sandbox;
};
declare global {
interface Window {
socket: any;
}
}
const identifier = uuid.v4();
const sentMessages = new Map();
const debug = _debug('cs:socket');
let channel = null;
let messageIndex = 0;
let clients: ReturnType;
let _socket: Socket = null;
let provideJwtToken = null;
export default {
initialize(options: Options) {
const live = this;
clients = clientsFactory(
(moduleShortid, revision, operation) => {
live.send('operation', {
moduleShortid,
operation,
findBoilerplate,
} from './boilerplates';
import loadDependencies from './npm';
import { consumeCache, saveCache, deleteAPICache } from './eval/cache';
import { showRunOnClick } from './status-screen/run-on-click';
import { Module } from './eval/entities/module';
import { ParsedConfigurationFiles } from '@codesandbox/common/lib/templates/template';
import TranspiledModule from './eval/transpiled-module';
let initializedResizeListener = false;
let manager: Manager | null = null;
let actionsEnabled = false;
const debug = _debug('cs:compiler');
export function areActionsEnabled() {
return actionsEnabled;
}
export function getCurrentManager(): Manager | null {
return manager;
}
export function getHTMLParts(html: string) {
if (html.includes('')) {
const bodyMatcher = /([\s\S]*)<\/body>/m;
const headMatcher = /([\s\S]*)<\/head>/m;
const headMatch = html.match(headMatcher);
const bodyMatch = html.match(bodyMatcher);
import { SourceMap } from './transpilers/utils/get-source-map';
import ModuleError from './errors/module-error';
import ModuleWarning from './errors/module-warning';
import { WarningStructure } from './transpilers/utils/worker-warning-handler';
import resolveDependency from './loaders/dependency-resolver';
import evaluate from './loaders/eval';
import Manager, { HMRStatus } from './manager';
import HMR from './hmr';
import { splitQueryFromPath } from './utils/query-path';
declare const BrowserFS: any;
const debug = _debug('cs:compiler:transpiled-module');
export type ChildModule = Module & {
parent: Module;
};
class ModuleSource {
fileName: string;
compiledCode: string;
sourceMap: SourceMap | undefined;
sourceEqualsCompiled: boolean;
constructor(
fileName: string,
compiledCode: string,
sourceMap: SourceMap | undefined,
sourceEqualsCompiled = false
import { actions, dispatch } from 'codesandbox-api';
import _debug from '@codesandbox/common/lib/utils/debug';
import { getAbsoluteDependencies } from '@codesandbox/common/lib/utils/dependencies';
import dependenciesToQuery from './dependencies-to-query';
import delay from '../utils/delay';
import setScreen from '../status-screen';
type Dependencies = {
[dependency: string]: string;
};
const RETRY_COUNT = 60;
const debug = _debug('cs:sandbox:packager');
const VERSION = 1;
const BUCKET_URL =
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test'
? 'https://d1jyvh0kxilfa7.cloudfront.net'
: 'https://dev-packager-packages.codesandbox.io';
const NEW_PACKAGER_URL =
'https://aiwi8rnkp5.execute-api.eu-west-1.amazonaws.com/prod/packages';
const PACKAGER_URL =
process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'test'
? 'https://drq28qbjmc.execute-api.eu-west-1.amazonaws.com/prod/packages'
: 'https://xi5p9f7czk.execute-api.eu-west-1.amazonaws.com/dev/packages';