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

Commit

Permalink
More pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
njgheorghita committed Oct 30, 2020
1 parent de6f7a2 commit 3ad36aa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 39 deletions.
13 changes: 6 additions & 7 deletions packages/ethpm-v3/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ async function resolveEthpmUri(options, provider) {

// update provider if it doesn't match chain id in ethpm uri
if (
connectedChainId != ethpmUri.chainId &&
options.ethpm.registry.network != "development"
connectedChainId !== ethpmUri.chainId &&
options.ethpm.registry.network !== "development"
) {
const targetNetwork = SUPPORTED_CHAIN_IDS[ethpmUri.chainId];
if (typeof targetNetwork === "undefined") {
Expand Down Expand Up @@ -196,11 +196,10 @@ function fetchInstalledBuildDependencies(workingDirectory) {
} catch (err) {
return {};
}
const installedBuildDependencies = {};
Object.keys(ethpmLock).forEach(key => {
installedBuildDependencies[key] = ethpmLock[key].resolved_uri;
});
return installedBuildDependencies;
return Object.keys(ethpmLock).reduce((accumulator, key) => {
accumulator[key] = ethpmLock[key].resolved_uri;
return accumulator;
}, {});
}

function convertContractTypeToContractSchema(
Expand Down
7 changes: 4 additions & 3 deletions packages/resolver/lib/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const expect = require("@truffle/expect");
const provision = require("@truffle/provisioner");

import { ResolverSource } from "./source";
import { EthPMv1, NPM, GlobalNPM, FS, Truffle } from "./sources";
import { EthPMv3, NPM, GlobalNPM, FS, Truffle } from "./sources";

export class Resolver {
options: any;
Expand All @@ -14,7 +14,8 @@ export class Resolver {

this.options = options;
this.sources = [
new EthPMv1(options.working_directory),
//new EthPMv1(options.working_directory),
new EthPMv3(options.working_directory),
new NPM(options.working_directory),
new GlobalNPM(),
new FS(options.working_directory, options.contracts_build_directory)
Expand Down Expand Up @@ -70,7 +71,7 @@ export class Resolver {
return {
body,
filePath,
source,
source
};
}
}
54 changes: 26 additions & 28 deletions packages/resolver/lib/sources/ethpm-v3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class EthPMv3 implements ResolverSource {
}

require(importPath: string) {
if (importPath.indexOf(".") === 0 || importPath.indexOf("/") === 0) {
if (importPath.startsWith(".") || importPath.startsWith("/")) {
return null;
}

Expand All @@ -26,12 +26,12 @@ export class EthPMv3 implements ResolverSource {

// We haven't compiled our own version. Assemble from data in the manifest.
var separator = importPath.indexOf("/");
var package_name = importPath.substring(0, separator);
var packageName = importPath.substring(0, separator);

var install_directory = path.join(this.workingDirectory, "_ethpm_packages");
var installDirectory = path.join(this.workingDirectory, "_ethpm_packages");
var manifest: any = path.join(
install_directory,
package_name,
installDirectory,
packageName,
"manifest.json"
);

Expand Down Expand Up @@ -80,8 +80,8 @@ export class EthPMv3 implements ResolverSource {

async resolve(importPath: string) {
var separator = importPath.indexOf("/");
var package_name = importPath.substring(0, separator);
var internal_path = importPath.substring(separator + 1);
var packageName = importPath.substring(0, separator);
var internalPath = importPath.substring(separator + 1);
var installDir = this.workingDirectory;

// If nothing's found, body returns `undefined`
Expand All @@ -90,42 +90,40 @@ export class EthPMv3 implements ResolverSource {

while (true) {
// check for root level ethpm sources
var file_path = path.join(
var filePath = path.join(
installDir,
"_ethpm_packages",
package_name,
packageName,
"_src",
internal_path
internalPath
);

try {
body = fs.readFileSync(file_path, { encoding: "utf8" });
body = fs.readFileSync(filePath, { encoding: "utf8" });
break;
} catch (err) {}

file_path = path.join(
filePath = path.join(
installDir,
"installed_contracts",
package_name,
packageName,
"contracts",
internal_path
internalPath
);

try {
body = fs.readFileSync(file_path, { encoding: "utf8" });
body = fs.readFileSync(filePath, { encoding: "utf8" });
break;
} catch (err) {}

if (matches.length > 0) {
if (matches.length === 1) {
try {
body = fs.readFileSync(
path.join(installDir, "_ethpm_packages", matches[0]),
{ encoding: "utf8" }
);
break;
} catch (err) {}
}
if (matches.length === 1) {
try {
body = fs.readFileSync(
path.join(installDir, "_ethpm_packages", matches[0]),
{ encoding: "utf8" }
);
break;
} catch (err) {}
}

// Recurse outwards until impossible
Expand All @@ -145,14 +143,14 @@ export class EthPMv3 implements ResolverSource {
// that when this path is evaluated this source is used again.
resolveDependencyPath(importPath: string, dependencyPath: string) {
var dirname = path.dirname(importPath);
var resolved_dependency_path = path.join(dirname, dependencyPath);
var resolvedDependencyPath = path.join(dirname, dependencyPath);

// Note: We use `path.join()` here to take care of path idiosyncrasies
// like joining "something/" and "./something_else.sol". However, this makes
// paths OS dependent, and on Windows, makes the separator "\". Solidity
// needs the separator to be a forward slash. Let's massage that here.
resolved_dependency_path = resolved_dependency_path.replace(/\\/g, "/");
resolvedDependencyPath = resolvedDependencyPath.replace(/\\/g, "/");

return resolved_dependency_path;
return resolvedDependencyPath;
}
}
2 changes: 1 addition & 1 deletion packages/resolver/lib/sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { EthPMv1 } from "./ethpm-v1"; // todo: remove?
export { EthPMv1 } from "./ethpm-v1";
export { EthPMv3 } from "./ethpm-v3";
export { NPM } from "./npm";
export { GlobalNPM } from "./globalnpm";
Expand Down

0 comments on commit 3ad36aa

Please sign in to comment.