aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-resolver
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-resolver')
-rw-r--r--packages/sol-resolver/CHANGELOG.json41
-rw-r--r--packages/sol-resolver/CHANGELOG.md12
-rw-r--r--packages/sol-resolver/package.json8
-rw-r--r--packages/sol-resolver/src/index.ts1
-rw-r--r--packages/sol-resolver/src/resolvers/fs_resolver.ts5
-rw-r--r--packages/sol-resolver/src/resolvers/name_resolver.ts10
-rw-r--r--packages/sol-resolver/src/resolvers/npm_resolver.ts20
-rw-r--r--packages/sol-resolver/src/resolvers/relative_fs_resolver.ts7
-rw-r--r--packages/sol-resolver/src/resolvers/spy_resolver.ts25
-rw-r--r--packages/sol-resolver/src/resolvers/url_resolver.ts5
-rw-r--r--packages/sol-resolver/src/types.ts1
11 files changed, 104 insertions, 31 deletions
diff --git a/packages/sol-resolver/CHANGELOG.json b/packages/sol-resolver/CHANGELOG.json
index a6ff84237..74c4d39c5 100644
--- a/packages/sol-resolver/CHANGELOG.json
+++ b/packages/sol-resolver/CHANGELOG.json
@@ -1,5 +1,46 @@
[
{
+ "version": "1.2.1",
+ "changes": [
+ {
+ "note": "Add `absolutePath` to `ContractSource` type",
+ "pr": 1461
+ },
+ {
+ "note": "Add `SpyResolver` that records all resolved contracts data",
+ "pr": 1461
+ }
+ ]
+ },
+ {
+ "version": "1.1.1",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ],
+ "timestamp": 1544739608
+ },
+ {
+ "version": "1.1.0",
+ "changes": [
+ {
+ "note": "NPMResolver now supports scoped packages",
+ "pr": 1311
+ }
+ ],
+ "timestamp": 1544570656
+ },
+ {
+ "timestamp": 1542821676,
+ "version": "1.0.17",
+ "changes": [
+ {
+ "note": "Dependencies updated"
+ }
+ ]
+ },
+ {
"version": "1.0.16",
"changes": [
{
diff --git a/packages/sol-resolver/CHANGELOG.md b/packages/sol-resolver/CHANGELOG.md
index f8c5a7692..98435be19 100644
--- a/packages/sol-resolver/CHANGELOG.md
+++ b/packages/sol-resolver/CHANGELOG.md
@@ -5,6 +5,18 @@ Edit the package's CHANGELOG.json file only.
CHANGELOG
+## v1.1.1 - _December 13, 2018_
+
+ * Dependencies updated
+
+## v1.1.0 - _December 11, 2018_
+
+ * NPMResolver now supports scoped packages (#1311)
+
+## v1.0.17 - _November 21, 2018_
+
+ * Dependencies updated
+
## v1.0.16 - _November 9, 2018_
* Dependencies updated
diff --git a/packages/sol-resolver/package.json b/packages/sol-resolver/package.json
index 7572072c4..0163765d9 100644
--- a/packages/sol-resolver/package.json
+++ b/packages/sol-resolver/package.json
@@ -1,6 +1,6 @@
{
"name": "@0x/sol-resolver",
- "version": "1.0.16",
+ "version": "1.1.1",
"engines": {
"node": ">=6.12"
},
@@ -23,15 +23,15 @@
},
"homepage": "https://github.com/0xProject/0x-monorepo/packages/resolver/README.md",
"devDependencies": {
- "@0x/tslint-config": "^1.0.10",
+ "@0x/tslint-config": "^2.0.0",
"make-promises-safe": "^1.1.0",
"shx": "^0.2.2",
"tslint": "5.11.0",
"typescript": "3.0.1"
},
"dependencies": {
- "@0x/types": "^1.2.1",
- "@0x/typescript-typings": "^3.0.4",
+ "@0x/types": "^1.4.1",
+ "@0x/typescript-typings": "^3.0.6",
"lodash": "^4.17.5"
},
"publishConfig": {
diff --git a/packages/sol-resolver/src/index.ts b/packages/sol-resolver/src/index.ts
index a86053259..f55aca070 100644
--- a/packages/sol-resolver/src/index.ts
+++ b/packages/sol-resolver/src/index.ts
@@ -5,5 +5,6 @@ export { NPMResolver } from './resolvers/npm_resolver';
export { FSResolver } from './resolvers/fs_resolver';
export { RelativeFSResolver } from './resolvers/relative_fs_resolver';
export { NameResolver } from './resolvers/name_resolver';
+export { SpyResolver } from './resolvers/spy_resolver';
export { EnumerableResolver } from './resolvers/enumerable_resolver';
export { Resolver } from './resolvers/resolver';
diff --git a/packages/sol-resolver/src/resolvers/fs_resolver.ts b/packages/sol-resolver/src/resolvers/fs_resolver.ts
index 63fc3448e..86128023d 100644
--- a/packages/sol-resolver/src/resolvers/fs_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/fs_resolver.ts
@@ -9,10 +9,7 @@ export class FSResolver extends Resolver {
public resolveIfExists(importPath: string): ContractSource | undefined {
if (fs.existsSync(importPath) && fs.lstatSync(importPath).isFile()) {
const fileContent = fs.readFileSync(importPath).toString();
- return {
- source: fileContent,
- path: importPath,
- };
+ return { source: fileContent, path: importPath, absolutePath: importPath };
}
return undefined;
}
diff --git a/packages/sol-resolver/src/resolvers/name_resolver.ts b/packages/sol-resolver/src/resolvers/name_resolver.ts
index d6ac6a499..aee326fb7 100644
--- a/packages/sol-resolver/src/resolvers/name_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/name_resolver.ts
@@ -20,10 +20,7 @@ export class NameResolver extends EnumerableResolver {
if (contractName === lookupContractName) {
const absoluteContractPath = path.join(this._contractsDir, filePath);
const source = fs.readFileSync(absoluteContractPath).toString();
- contractSource = {
- source,
- path: filePath,
- };
+ contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
return true;
}
return undefined;
@@ -36,10 +33,7 @@ export class NameResolver extends EnumerableResolver {
const onFile = (filePath: string) => {
const absoluteContractPath = path.join(this._contractsDir, filePath);
const source = fs.readFileSync(absoluteContractPath).toString();
- const contractSource = {
- source,
- path: filePath,
- };
+ const contractSource = { source, path: filePath, absolutePath: absoluteContractPath };
contractSources.push(contractSource);
};
this._traverseContractsDir(this._contractsDir, onFile);
diff --git a/packages/sol-resolver/src/resolvers/npm_resolver.ts b/packages/sol-resolver/src/resolvers/npm_resolver.ts
index a2df0dcad..3c1d09557 100644
--- a/packages/sol-resolver/src/resolvers/npm_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/npm_resolver.ts
@@ -1,4 +1,5 @@
import * as fs from 'fs';
+import * as _ from 'lodash';
import * as path from 'path';
import { ContractSource } from '../types';
@@ -13,18 +14,25 @@ export class NPMResolver extends Resolver {
}
public resolveIfExists(importPath: string): ContractSource | undefined {
if (!importPath.startsWith('/')) {
- const [packageName, ...other] = importPath.split('/');
+ let packageName;
+ let packageScopeIfExists;
+ let other;
+ if (_.startsWith(importPath, '@')) {
+ [packageScopeIfExists, packageName, ...other] = importPath.split('/');
+ } else {
+ [packageName, ...other] = importPath.split('/');
+ }
const pathWithinPackage = path.join(...other);
let currentPath = this._packagePath;
const ROOT_PATH = '/';
while (currentPath !== ROOT_PATH) {
- const lookupPath = path.join(currentPath, 'node_modules', packageName, pathWithinPackage);
+ const packagePath = _.isUndefined(packageScopeIfExists)
+ ? packageName
+ : path.join(packageScopeIfExists, packageName);
+ const lookupPath = path.join(currentPath, 'node_modules', packagePath, pathWithinPackage);
if (fs.existsSync(lookupPath) && fs.lstatSync(lookupPath).isFile()) {
const fileContent = fs.readFileSync(lookupPath).toString();
- return {
- source: fileContent,
- path: lookupPath,
- };
+ return { source: fileContent, path: importPath, absolutePath: lookupPath };
}
currentPath = path.dirname(currentPath);
}
diff --git a/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts b/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts
index ed96040d3..cfff145f9 100644
--- a/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/relative_fs_resolver.ts
@@ -13,13 +13,10 @@ export class RelativeFSResolver extends Resolver {
}
// tslint:disable-next-line:prefer-function-over-method
public resolveIfExists(importPath: string): ContractSource | undefined {
- const filePath = path.join(this._contractsDir, importPath);
+ const filePath = path.resolve(path.join(this._contractsDir, importPath));
if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
const fileContent = fs.readFileSync(filePath).toString();
- return {
- source: fileContent,
- path: importPath,
- };
+ return { source: fileContent, path: importPath, absolutePath: filePath };
}
return undefined;
}
diff --git a/packages/sol-resolver/src/resolvers/spy_resolver.ts b/packages/sol-resolver/src/resolvers/spy_resolver.ts
new file mode 100644
index 000000000..5582d771a
--- /dev/null
+++ b/packages/sol-resolver/src/resolvers/spy_resolver.ts
@@ -0,0 +1,25 @@
+import * as _ from 'lodash';
+
+import { ContractSource } from '../types';
+
+import { Resolver } from './resolver';
+
+/**
+ * This resolver is a passthrough proxy to any resolver that records all the resolved contracts sources.
+ * You can access them later using the `resolvedContractSources` public field.
+ */
+export class SpyResolver extends Resolver {
+ public resolvedContractSources: ContractSource[] = [];
+ private readonly _resolver: Resolver;
+ constructor(resolver: Resolver) {
+ super();
+ this._resolver = resolver;
+ }
+ public resolveIfExists(importPath: string): ContractSource | undefined {
+ const contractSourceIfExists = this._resolver.resolveIfExists(importPath);
+ if (!_.isUndefined(contractSourceIfExists)) {
+ this.resolvedContractSources.push(contractSourceIfExists);
+ }
+ return contractSourceIfExists;
+ }
+}
diff --git a/packages/sol-resolver/src/resolvers/url_resolver.ts b/packages/sol-resolver/src/resolvers/url_resolver.ts
index 180b0c9f6..ef300e6db 100644
--- a/packages/sol-resolver/src/resolvers/url_resolver.ts
+++ b/packages/sol-resolver/src/resolvers/url_resolver.ts
@@ -11,10 +11,7 @@ export class URLResolver extends Resolver {
if (importPath.startsWith(FILE_URL_PREXIF)) {
const filePath = importPath.substr(FILE_URL_PREXIF.length);
const fileContent = fs.readFileSync(filePath).toString();
- return {
- source: fileContent,
- path: importPath,
- };
+ return { source: fileContent, path: importPath, absolutePath: filePath };
}
return undefined;
}
diff --git a/packages/sol-resolver/src/types.ts b/packages/sol-resolver/src/types.ts
index 41492622d..b4ba164c8 100644
--- a/packages/sol-resolver/src/types.ts
+++ b/packages/sol-resolver/src/types.ts
@@ -1,6 +1,7 @@
export interface ContractSource {
source: string;
path: string;
+ absolutePath: string;
}
export interface ContractSources {