How to use the @codesandbox/common/lib/sandbox/modules.getModulePath 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 / overmind / effects / zip / create-zip / index.ts View on Github external
const filteredModules = modules.filter(module => {
    // Relative path
    const path = getModulePath(modules, directories, module.id).substring(1);
    return !ignorer.ignores(path);
  });
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / Monaco / index.js View on Github external
setTimeout(async () => {
        if (modelCache[id]) {
          const sandbox = this.sandbox;
          const path = getModulePath(sandbox.modules, sandbox.directories, id);

          modelCache[id].viewState = this.editor.saveViewState();
          if (modelCache[id].lib) {
            // We let Monaco know what the latest code is of this file by removing
            // the old extraLib definition and defining a new one.
            modelCache[id].lib.dispose();
            modelCache[id].lib = this.addLib(currentModule.code || '', path);
          }
        }

        await this.openNewModel(nextModule);
        this.editor.focus();
        resolve();
      }, 50);
    });
github codesandbox / codesandbox-client / packages / app / src / app / overmind / internalActions.ts View on Github external
const sandbox = state.editor.currentSandbox;
  const existingPackageJson = sandbox.modules.find(
    module => module.directoryShortid == null && module.title === 'package.json'
  );

  if (sandbox.owned && !existingPackageJson) {
    const optimisticId = effects.utils.createOptimisticId();
    const optimisticModule = createOptimisticModule({
      id: optimisticId,
      title: 'package.json',
      code: generatePackageJsonFromSandbox(sandbox),
      path: '/package.json',
    });

    state.editor.currentSandbox.modules.push(optimisticModule as Module);
    optimisticModule.path = getModulePath(
      sandbox.modules,
      sandbox.directories,
      optimisticId
    );

    // We grab the module from the state to continue working with it (proxy)
    const module = sandbox.modules[sandbox.modules.length - 1];

    effects.vscode.sandboxFsSync.writeFile(state.editor.modulesByPath, module);

    try {
      const updatedModule = await effects.api.createModule(sandbox.id, module);

      module.id = updatedModule.id;
      module.shortid = updatedModule.shortid;
    } catch (error) {
github codesandbox / codesandbox-client / packages / app / src / app / pages / Sandbox / Editor / Workspace / Files / index.js View on Github external
getModulePath = moduleId => {
    try {
      const sandbox = this.props.store.editor.currentSandbox;
      return getModulePath(sandbox.modules, sandbox.directories, moduleId);
    } catch (e) {
      return '';
    }
  };
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / editorManager / index.ts View on Github external
openModule(module: Module) {
    if (module.id) {
      const sandbox = this.options.getCurrentSandbox();
      const path = getModulePath(
        sandbox.modules,
        sandbox.directories,
        module.id
      );

      if (path && getCurrentModelPath(this.editor) !== path) {
        this.editor.openFile(path);
      }
    }
  }
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / VSCode / index.tsx View on Github external
openModule = (module: Module) => {
    if (module.id) {
      const path = getModulePath(
        this.sandbox.modules,
        this.sandbox.directories,
        module.id
      );

      if (this.getCurrentModelPath() !== path) {
        this.editor.openFile(path);
      }
    }
  };
github codesandbox / codesandbox-client / packages / app / src / app / store / modules / files / actions.js View on Github external
export function setDefaultNewCode({ state, props }) {
  if (!props.optimisticModule || props.optimisticModule.code) {
    return {};
  }

  const sandbox = state.get('editor.currentSandbox');

  const path = getModulePath(
    sandbox.modules,
    sandbox.directories,
    props.optimisticModule.id
  );

  const template = getDefinition(sandbox.template);
  const config = template.configurationFiles[path];

  if (
    config &&
    (config.generateFileFromSandbox ||
      config.getDefaultCode ||
      config.generateFileFromState)
  ) {
    let code = '';
github codesandbox / codesandbox-client / packages / app / src / app / overmind / effects / vscode / utils.ts View on Github external
export function getVSCodePath(sandbox: Sandbox, moduleId: string) {
  return `/sandbox${getModulePath(
    sandbox.modules,
    sandbox.directories,
    moduleId
  )}`;
}
github codesandbox / codesandbox-client / packages / app / src / app / components / CodeEditor / index.tsx View on Github external
}}
        >
          
        
      );
    }

    const dependencies = getDependencies(sandbox);

    const template = getDefinition(sandbox.template);
    const modulePath = getModulePath(
      sandbox.modules,
      sandbox.directories,
      module.id
    );
    const config = template.configurationFiles[modulePath];

    if (
      !settings.experimentVSCode &&
      config &&
      getUI(config.type) &&
      this.state.showConfigUI
    ) {
      return (