Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const filteredModules = modules.filter(module => {
// Relative path
const path = getModulePath(modules, directories, module.id).substring(1);
return !ignorer.ignores(path);
});
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);
});
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) {
getModulePath = moduleId => {
try {
const sandbox = this.props.store.editor.currentSandbox;
return getModulePath(sandbox.modules, sandbox.directories, moduleId);
} catch (e) {
return '';
}
};
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);
}
}
}
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);
}
}
};
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 = '';
export function getVSCodePath(sandbox: Sandbox, moduleId: string) {
return `/sandbox${getModulePath(
sandbox.modules,
sandbox.directories,
moduleId
)}`;
}
}}
>
);
}
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 (