How to use codesandbox-api - 10 common examples

To help you get started, we’ve selected a few codesandbox-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpiled-module.ts View on Github external
this.warnings.forEach(warning => {
        console.warn(warning.message); // eslint-disable-line no-console
        dispatch(
          actions.correction.show(warning.message, {
            line: warning.lineNumber,
            column: warning.columnNumber,
            path: warning.path,
            source: warning.source,
            severity: warning.severity || 'warning',
          })
        );
      });
    }
github codesandbox / codesandbox-client / src / sandbox / index.js View on Github external
}

        try {
          dispatch({
            type: 'eval-result',
            error,
            result: transformJSON(result),
          });
        } catch (e) {
          console.error(e);
        }
      }
    }
  }

  listen(handleMessage);

  sendReady();
  setupHistoryListeners();
  setupConsole();

  if (process.env.NODE_ENV === 'test' || isStandalone) {
    // We need to fetch the sandbox ourselves...
    const id = getId();
    window
      .fetch(host + `/api/v1/sandboxes/${id}`)
      .then(res => res.json())
      .then(res => camelizeKeys(res))
      .then(x => {
        const mainModule = findMainModule(
          x.data.modules,
          x.data.directories,
github codesandbox / codesandbox-client / packages / app / src / sandbox / compile-old.js View on Github external
async function compile({
  sandboxId,
  modules,
  entry,
  externalResources,
  dependencies,
  hasActions,
  isModuleView = false,
  template,
}) {
  const startTime = Date.now();
  try {
    clearErrorTransformers();
    initializeErrorTransformers();
    unmount(manager && manager.webpackHMR);
  } catch (e) {
    console.error(e);
  }

  actionsEnabled = hasActions;
  handleExternalResources(externalResources);

  try {
    const { manifest, isNewCombination } = await loadDependencies(dependencies);

    if (isNewCombination && !firstLoad) {
      // Just reset the whole manager if it's a new combination
      manager = null;
    }
github codesandbox / codesandbox-client / src / sandbox / compile.js View on Github external
async function compile({
  sandboxId,
  modules,
  directories,
  module,
  changedModule,
  externalResources,
  dependencies,
  hasActions,
  isModuleView = false,
  template,
}) {
  try {
    clearErrorTransformers();
    initializeErrorTransformers();
    unmount();
  } catch (e) {
    console.error(e);
  }

  actionsEnabled = hasActions;
  handleExternalResources(externalResources);

  try {
    // We convert the modules to a format the manager understands
    const managerModules = modules.map(m => ({
      path: getModulePath(modules, directories, m.id),
      code: m.code,
    }));
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpiled-module.ts View on Github external
this.warnings.forEach(warning => {
        console.warn(warning.message); // eslint-disable-line no-console
        dispatch(
          actions.correction.show(warning.message, {
            line: warning.lineNumber,
            column: warning.columnNumber,
            path: warning.path,
            source: warning.source,
            severity: warning.severity || 'warning',
          })
        );
      });
    }
github codesandbox / codesandbox-client / src / sandbox / eval / transpiled-module.js View on Github external
this.warnings.forEach(warning => {
              console.warn(warning.message); // eslint-disable-line no-console
              dispatch(
                actions.correction.show(warning.message, {
                  line: warning.lineNumber,
                  column: warning.columnNumber,
                  path: warning.path,
                  source: warning.source,
                  severity: 'warning',
                })
              );
            });
          }
github codesandbox / codesandbox-client / packages / sandbox-hooks / react-error-overlay / overlay.js View on Github external
if (!tModule && relevantFrame) {
        const fileName =
          relevantFrame._originalFileName || relevantFrame.fileName || '';
        tModule = manager.resolveTranspiledModule(
          fileName.replace(location.origin, ''),
          '/'
        );
      }

      if (!tModule) {
        return;
      }

      try {
        const transformation = transformError(
          errRef.error,
          tModule,
          manager.getTranspiledModules()
        );

        if (transformation) {
          const newError = new Error(transformation.name || errRef.error.name);
          newError.message = transformation.message;
          newError.suggestions = transformation.suggestions;
          newError.originalName = errRef.error.name;
          newError.originalMessage = errRef.error.message;
          errRef.error = newError;
        }
      } catch (ex) {
        /* just catch */
        console.error(ex);
github codesandbox / codesandbox-client / src / sandbox / react-error-overlay / overlay.js View on Github external
if (!tModule && relevantFrame) {
        const fileName =
          relevantFrame._originalFileName || relevantFrame.fileName || '';
        tModule = manager.resolveTranspiledModule(
          fileName.replace(location.origin, ''),
          '/'
        );
      }

      if (!tModule) {
        return;
      }

      try {
        const transformation = transformError(
          errRef.error,
          tModule,
          manager.getTranspiledModules()
        );

        if (transformation) {
          errRef.error.originalName = errRef.error.name;
          errRef.error.originalMessage = errRef.error.message;

          errRef.error.name = transformation.name || errRef.error.name;
          errRef.error.message = transformation.message;
          errRef.error.suggestions = transformation.suggestions;
        }
      } catch (ex) {
        /* just catch */
        console.error(ex);
github codesandbox / codesandbox-client / packages / app / src / sandbox / compile-old.js View on Github external
if (!initializedResizeListener) {
      initializeResizeListener();
    }

    // Testing
    const ttt = Date.now();
    const testRunner = manager.testRunner;
    try {
      testRunner.initialize();
      testRunner.findTests(modules);
      await testRunner.runTests();
      const aggregatedResults = testRunner.reportResults();
      debug(`Test Evaluation time: ${Date.now() - ttt}ms`);

      dispatch({
        type: 'test-result',
        result: Encode(aggregatedResults),
      });
      // End - Testing
    } catch (error) {
      dispatch({
        type: 'test-result',
        error: testRunner.reportError(error),
      });
    }

    debug(`Total time: ${Date.now() - startTime}ms`);

    dispatch({
      type: 'success',
    });
github codesandbox / codesandbox-client / packages / app / src / sandbox / eval / transpilers / worker-transpiler.ts View on Github external
const { data } = newMessage;

      if (data) {
        if (data.type === 'error') {
          const reconstructedError = parseWorkerError(data.error);

          this.runCallbacks(callbacks, reconstructedError);
        }

        if (data.type === 'warning') {
          loaderContext.emitWarning(data.warning);
          return;
        }

        if (data.type === 'clear-warnings') {
          dispatch(actions.correction.clear(data.path, data.source));
        }

        if (data.type === 'resolve-async-transpiled-module') {
          // This one is to add an asynchronous transpiled module

          const { id, path, options } = data;

          try {
            const tModule = await loaderContext.resolveTranspiledModuleAsync(
              path,
              options
            );
            worker.postMessage({
              type: 'resolve-async-transpiled-module-response',
              id,
              found: true,

codesandbox-api

[![styled with prettier](https://img.shields.io/badge/styled_with-prettier-ff69b4.svg)](https://github.com/prettier/prettier) [![Greenkeeper badge](https://badges.greenkeeper.io/alexjoverm/typescript-library-starter.svg)](https://greenkeeper.io/) [![Travi

MIT
Latest version published 3 years ago

Package Health Score

73 / 100
Full package analysis

Similar packages