How to use the @codesandbox/common/lib/sandbox/modules.resolveModule function in @codesandbox/common

To help you get started, we’ve selected a few @codesandbox/common 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 / app / components / CodeEditor / VSCode / index.tsx View on Github external
((container, extraProps) => {
        const currentModule = resolveModule(
          modulePath,
          this.sandbox.modules,
          this.sandbox.directories
        );
        return render(
          
            
          ,
github codesandbox / codesandbox-client / packages / app / src / embed / components / Content / index.tsx View on Github external
setCurrentModuleFromPath = (path: string) => {
    try {
      const module = resolveModule(
        path,
        this.props.sandbox.modules,
        this.props.sandbox.directories
      );

      this.setCurrentModule(module.id);
    } catch (e) {
      /* Ignore */
    }
  };
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / VSCode / index.tsx View on Github external
openedModels.forEach(fileModel => {
      const path = fileModel.resource.path;

      if (!path.startsWith('/sandbox') || !fileModel.isDirty()) {
        return;
      }

      const module = resolveModule(
        path.replace(/^\/sandbox/, ''),
        this.sandbox.modules,
        this.sandbox.directories
      );

      if (
        module &&
        this.props.isModuleSynced(module.shortid) &&
        fileModel.isDirty
      ) {
        // Do a revert to remove the dirty state and get the code from the FS, since in Cerebral
        // we're already synced
        fileModel.revert();
      }
    });
  };
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / ModelsHandler.ts View on Github external
return model.onDidChangeContent(e => {
      if (this.isApplyingOperation) {
        return;
      }

      const { path } = model.uri;
      try {
        const module = resolveModule(
          path.replace(/^\/sandbox/, ''),
          sandbox.modules,
          sandbox.directories
        );

        this.onChangeCallback({
          moduleShortid: module.shortid,
          title: module.title,
          code: model.getValue(),
          event: e,
          model,
        });
      } catch (err) {
        // This can throw when a file is deleted and you add new code to it. When
        // saving it a new file is created
      }
github codesandbox / codesandbox-client / packages / app / src / app / overmind / namespaces / editor / actions.ts View on Github external
state.editor.errors.forEach(error => {
          try {
            const module = resolveModule(
              error.path,
              state.editor.currentSandbox.modules,
              state.editor.currentSandbox.directories
            );

            module.errors = [];
          } catch (e) {
            // Module doesn't exist anymore
          }
        });
        newErrors.forEach(error => {
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / VSCode / index.tsx View on Github external
getPrettierConfig = () => {
    try {
      const module = resolveModule(
        '/.prettierrc',
        this.sandbox.modules,
        this.sandbox.directories
      );

      const parsedCode = JSON.parse(module.code || '');

      return parsedCode;
    } catch (e) {
      return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
    }
  };
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / VSCode / index.tsx View on Github external
model => {
        if (this.modelListeners[model.uri.path] === undefined) {
          let module: Module;
          try {
            module = resolveModule(
              model.uri.path.replace(/^\/sandbox/, ''),
              this.sandbox.modules,
              this.sandbox.directories
            );
          } catch (e) {
            return;
          }

          const listener = model.onDidChangeContent(e => {
            const path = model.uri.path;
            try {
              const module = resolveModule(
                path.replace(/^\/sandbox/, ''),
                this.sandbox.modules,
                this.sandbox.directories
              );
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / editorManager / index.ts View on Github external
private getPrettierConfig = () => {
    try {
      const sandbox = this.options.getCurrentSandbox();
      const module = resolveModule(
        '/.prettierrc',
        sandbox.modules,
        sandbox.directories
      );

      return JSON.parse(module.code || '');
    } catch (e) {
      return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
    }
  };
}
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / index.ts View on Github external
private getPrettierConfig = () => {
    try {
      const sandbox = this.options.getCurrentSandbox();
      const module = resolveModule(
        '/.prettierrc',
        sandbox.modules,
        sandbox.directories
      );

      return JSON.parse(module.code || '');
    } catch (e) {
      return this.settings.prettierConfig || DEFAULT_PRETTIER_CONFIG;
    }
  };
github codesandbox / codesandbox-client / packages / app / src / app / overmind / namespaces / editor / actions.ts View on Github external
newCorrections.forEach(correction => {
          const module = resolveModule(
            correction.path,
            state.editor.currentSandbox.modules,
            state.editor.currentSandbox.directories
          );

          module.corrections.push(correction);
        });
        state.editor.corrections = newCorrections;