Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4195 from trufflesuite/denormalize
Browse files Browse the repository at this point in the history
Bug fix: Use backslashes on Windows while resolving imports
  • Loading branch information
haltman-at authored Jul 21, 2021
2 parents a9b92d5 + 9f01dac commit 63ef5c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/compile-common/src/profiler/getImports.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import debugModule from "debug";
import path from "path";
const debug = debugModule("compile-common:profiler:getImports");

//HACK: do *not* import ResolvedSource from @truffle/resolver because
Expand Down Expand Up @@ -36,5 +37,7 @@ export async function getImports({
// here, that's now the responsibility of the individual resolverSource to check
return (await Promise.all(imports.map(
dependencyPath => source.resolveDependencyPath(filePath, dependencyPath)
))).filter(path => path); //filter out Vyper failures
))).filter(sourcePath => sourcePath) //filter out Vyper failures
.map(sourcePath => sourcePath.replace(/\//g, path.sep)); //make sure to use
//backslash on Windows (for same reason as in requiredSources.ts)
}
8 changes: 8 additions & 0 deletions packages/compile-common/src/profiler/requiredSources.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import debugModule from "debug";
import path from "path";
const debug = debugModule("compile-common:profiler:requiredSources");

import {
Expand Down Expand Up @@ -37,6 +38,13 @@ export async function requiredSources({
debug("allPaths: %O", allPaths);
debug("updatedPaths: %O", updatedPaths);

//before anything else: on Windows, make sure all paths are in native form
//(with backslashes) rather than slashes. otherwise, resolution of relative
//paths can cause aliasing; you can end up with one source with slashes (as
//given) and one with backslashes (due to relative import resolution).
allPaths = allPaths.map(sourcePath => sourcePath.replace(/\//g, path.sep));
updatedPaths = updatedPaths.map(sourcePath => sourcePath.replace(/\//g, path.sep));

// Solidity test files might have been injected. Include them in the known set.
updatedPaths.forEach(_path => {
if (!allPaths.includes(_path)) {
Expand Down

0 comments on commit 63ef5c8

Please sign in to comment.