7finney/code-remix

Plugins have to deal with relative path

Closed this issue · 1 comments

All the plugins need to see only the relative path (workspace path is the root path) and no absolute path should be involved.

This issue was identified while using sourcify plugin, we tried to verify a contrract, which was working ok, but the fileName that the sourcify backend has stored into its server was the absolute path /home/name/folder1/workspace although this should be a relative path

some more information:

this.print("Compilation started!")
    const fileName = window.activeTextEditor ? window.activeTextEditor.document.fileName : undefined;
    this.print(`Compiling ${fileName} ...`);
    const editorContent = window.activeTextEditor ? window.activeTextEditor.document.getText() : undefined;
    const sources: ISources = {};
    if (fileName) {
      sources[fileName] = {
        content: editorContent,
      };
    }

you are resolving the content, so you can resolve using absolute path (that you can construct with "workspace path + relative path" and send to solc a relative path
same here:

try {
            const o = { encoding: "UTF-8" };
            // hack for compiler imports to work (do not change)
            const p = pathString ? path.resolve(pathString, filePath) : path.resolve(pathString, filePath);
            const content = fs.readFileSync(p, o);
            return content;
        } catch (error) {
            // @ts-ignore
            process.send({ error });
            throw error;
        }
    }

solc ask you to resolve a relative path, you can infer the absolute path from it