How to use @0x/sol-resolver - 10 common examples

To help you get started, we’ve selected a few @0x/sol-resolver examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
private _getPathsToWatch(): string[] {
        const contractNames = this.getContractNamesToCompile();
        const spyResolver = new SpyResolver(this._resolver);
        for (const contractName of contractNames) {
            const contractSource = spyResolver.resolve(contractName);
            // NOTE: We ignore the return value here. We don't want to compute the source tree hash.
            // We just want to call a SpyResolver on each contracts and it's dependencies and
            // this is a convenient way to reuse the existing code that does that.
            // We can then get all the relevant paths from the `spyResolver` below.
            getSourceTreeHash(spyResolver, contractSource.path);
        }
        const pathsToWatch = _.uniq(spyResolver.resolvedContractSources.map(cs => cs.absolutePath));
        return pathsToWatch;
    }
    /**
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
private async _compileContractsAsync(contractNames: string[], shouldPersist: boolean): Promise {
        // batch input contracts together based on the version of the compiler that they require.
        const versionToInputs: VersionToInputs = {};

        // map contract paths to data about them for later verification and persistence
        const contractPathToData: ContractPathToData = {};

        const solcJSReleases = await getSolcJSReleasesAsync(this._isOfflineMode);
        const resolvedContractSources = [];
        for (const contractName of contractNames) {
            const spyResolver = new SpyResolver(this._resolver);
            const contractSource = spyResolver.resolve(contractName);
            const sourceTreeHashHex = getSourceTreeHash(spyResolver, contractSource.path).toString('hex');
            const contractData = {
                contractName: path.basename(contractName, constants.SOLIDITY_FILE_EXTENSION),
                currentArtifactIfExists: await getContractArtifactIfExistsAsync(this._artifactsDir, contractName),
                sourceTreeHashHex: `0x${sourceTreeHashHex}`,
            };
            if (!this._shouldCompile(contractData)) {
                continue;
            }
            contractPathToData[contractSource.path] = contractData;
            const solcVersion =
                this._solcVersionIfExists === undefined
                    ? semver.maxSatisfying(_.keys(solcJSReleases), parseSolidityVersionRange(contractSource.source))
                    : this._solcVersionIfExists;
            if (solcVersion === null) {
github 0xProject / 0x-monorepo / packages / contracts-gen / src / contracts-gen.ts View on Github external
compilerJSON.contracts = _.map(contracts, contract => {
            if (contract.endsWith(SOLIDITY_EXTENSION)) {
                // If it's already a relative path - NO-OP.
                return contract;
            } else {
                // If it's just a contract name - resolve it and rewrite.
                return new NameResolver(contractsDir).resolve(contract).path;
            }
        });
        compilerJSON.contracts = _.sortBy(compilerJSON.contracts);
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
process.env.SOLCJS_PATH !== undefined
                ? getSolcJSVersionFromPath(process.env.SOLCJS_PATH)
                : passedOpts.solcVersion || config.solcVersion;
        this._compilerSettings = {
            ...DEFAULT_COMPILER_SETTINGS,
            ...config.compilerSettings,
            ...passedOpts.compilerSettings,
        };
        this._artifactsDir = passedOpts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR;
        this._specifiedContracts = passedOpts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER;
        this._useDockerisedSolc =
            passedOpts.useDockerisedSolc || config.useDockerisedSolc || DEFAULT_USE_DOCKERISED_SOLC;
        this._isOfflineMode = passedOpts.isOfflineMode || config.isOfflineMode || DEFAULT_IS_OFFLINE_MODE;
        this._shouldSaveStandardInput =
            passedOpts.shouldSaveStandardInput || config.shouldSaveStandardInput || DEFAULT_SHOULD_SAVE_STANDARD_INPUT;
        this._nameResolver = new NameResolver(this._contractsDir);
        const resolver = new FallthroughResolver();
        resolver.appendResolver(new URLResolver());
        resolver.appendResolver(new NPMResolver(this._contractsDir));
        resolver.appendResolver(new RelativeFSResolver(this._contractsDir));
        resolver.appendResolver(new FSResolver());
        resolver.appendResolver(this._nameResolver);
        this._resolver = resolver;
    }
    /**
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / artifact_adapters / sol_compiler_artifact_adapter.ts View on Github external
? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
            : {};
        if (_.isUndefined(artifactsPath) && _.isUndefined(config.artifactsDir)) {
            throw new Error(`artifactsDir not found in ${CONFIG_FILE}`);
        }
        this._artifactsPath = (artifactsPath || config.artifactsDir) as string;
        if (_.isUndefined(sourcesPath) && _.isUndefined(config.contractsDir)) {
            throw new Error(`contractsDir not found in ${CONFIG_FILE}`);
        }
        this._sourcesPath = (sourcesPath || config.contractsDir) as string;
        this._resolver = new FallthroughResolver();
        this._resolver.appendResolver(new URLResolver());
        const packagePath = path.resolve('');
        this._resolver.appendResolver(new NPMResolver(packagePath));
        this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath));
        this._resolver.appendResolver(new FSResolver());
    }
    public async collectContractsDataAsync(): Promise {
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
...config.compilerSettings,
            ...passedOpts.compilerSettings,
        };
        this._artifactsDir = passedOpts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR;
        this._specifiedContracts = passedOpts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER;
        this._useDockerisedSolc =
            passedOpts.useDockerisedSolc || config.useDockerisedSolc || DEFAULT_USE_DOCKERISED_SOLC;
        this._isOfflineMode = passedOpts.isOfflineMode || config.isOfflineMode || DEFAULT_IS_OFFLINE_MODE;
        this._shouldSaveStandardInput =
            passedOpts.shouldSaveStandardInput || config.shouldSaveStandardInput || DEFAULT_SHOULD_SAVE_STANDARD_INPUT;
        this._nameResolver = new NameResolver(this._contractsDir);
        const resolver = new FallthroughResolver();
        resolver.appendResolver(new URLResolver());
        resolver.appendResolver(new NPMResolver(this._contractsDir));
        resolver.appendResolver(new RelativeFSResolver(this._contractsDir));
        resolver.appendResolver(new FSResolver());
        resolver.appendResolver(this._nameResolver);
        this._resolver = resolver;
    }
    /**
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
? getSolcJSVersionFromPath(process.env.SOLCJS_PATH)
                : passedOpts.solcVersion || config.solcVersion;
        this._compilerSettings = {
            ...DEFAULT_COMPILER_SETTINGS,
            ...config.compilerSettings,
            ...passedOpts.compilerSettings,
        };
        this._artifactsDir = passedOpts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR;
        this._specifiedContracts = passedOpts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER;
        this._useDockerisedSolc =
            passedOpts.useDockerisedSolc || config.useDockerisedSolc || DEFAULT_USE_DOCKERISED_SOLC;
        this._isOfflineMode = passedOpts.isOfflineMode || config.isOfflineMode || DEFAULT_IS_OFFLINE_MODE;
        this._shouldSaveStandardInput =
            passedOpts.shouldSaveStandardInput || config.shouldSaveStandardInput || DEFAULT_SHOULD_SAVE_STANDARD_INPUT;
        this._nameResolver = new NameResolver(this._contractsDir);
        const resolver = new FallthroughResolver();
        resolver.appendResolver(new URLResolver());
        resolver.appendResolver(new NPMResolver(this._contractsDir));
        resolver.appendResolver(new RelativeFSResolver(this._contractsDir));
        resolver.appendResolver(new FSResolver());
        resolver.appendResolver(this._nameResolver);
        this._resolver = resolver;
    }
    /**
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / artifact_adapters / sol_compiler_artifact_adapter.ts View on Github external
constructor(artifactsPath?: string, sourcesPath?: string) {
        super();
        const config: CompilerOptions = fs.existsSync(CONFIG_FILE)
            ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
            : {};
        if (_.isUndefined(artifactsPath) && _.isUndefined(config.artifactsDir)) {
            throw new Error(`artifactsDir not found in ${CONFIG_FILE}`);
        }
        this._artifactsPath = (artifactsPath || config.artifactsDir) as string;
        if (_.isUndefined(sourcesPath) && _.isUndefined(config.contractsDir)) {
            throw new Error(`contractsDir not found in ${CONFIG_FILE}`);
        }
        this._sourcesPath = (sourcesPath || config.contractsDir) as string;
        this._resolver = new FallthroughResolver();
        this._resolver.appendResolver(new URLResolver());
        const packagePath = path.resolve('');
        this._resolver.appendResolver(new NPMResolver(packagePath));
        this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath));
        this._resolver.appendResolver(new FSResolver());
    }
    public async collectContractsDataAsync(): Promise {
github 0xProject / 0x-monorepo / packages / sol-tracing-utils / src / artifact_adapters / sol_compiler_artifact_adapter.ts View on Github external
super();
        const config: CompilerOptions = fs.existsSync(CONFIG_FILE)
            ? JSON.parse(fs.readFileSync(CONFIG_FILE).toString())
            : {};
        if (_.isUndefined(artifactsPath) && _.isUndefined(config.artifactsDir)) {
            throw new Error(`artifactsDir not found in ${CONFIG_FILE}`);
        }
        this._artifactsPath = (artifactsPath || config.artifactsDir) as string;
        if (_.isUndefined(sourcesPath) && _.isUndefined(config.contractsDir)) {
            throw new Error(`contractsDir not found in ${CONFIG_FILE}`);
        }
        this._sourcesPath = (sourcesPath || config.contractsDir) as string;
        this._resolver = new FallthroughResolver();
        this._resolver.appendResolver(new URLResolver());
        const packagePath = path.resolve('');
        this._resolver.appendResolver(new NPMResolver(packagePath));
        this._resolver.appendResolver(new RelativeFSResolver(this._sourcesPath));
        this._resolver.appendResolver(new FSResolver());
    }
    public async collectContractsDataAsync(): Promise {
github 0xProject / 0x-monorepo / packages / sol-compiler / src / compiler.ts View on Github external
this._compilerSettings = {
            ...DEFAULT_COMPILER_SETTINGS,
            ...config.compilerSettings,
            ...passedOpts.compilerSettings,
        };
        this._artifactsDir = passedOpts.artifactsDir || config.artifactsDir || DEFAULT_ARTIFACTS_DIR;
        this._specifiedContracts = passedOpts.contracts || config.contracts || ALL_CONTRACTS_IDENTIFIER;
        this._useDockerisedSolc =
            passedOpts.useDockerisedSolc || config.useDockerisedSolc || DEFAULT_USE_DOCKERISED_SOLC;
        this._isOfflineMode = passedOpts.isOfflineMode || config.isOfflineMode || DEFAULT_IS_OFFLINE_MODE;
        this._shouldSaveStandardInput =
            passedOpts.shouldSaveStandardInput || config.shouldSaveStandardInput || DEFAULT_SHOULD_SAVE_STANDARD_INPUT;
        this._nameResolver = new NameResolver(this._contractsDir);
        const resolver = new FallthroughResolver();
        resolver.appendResolver(new URLResolver());
        resolver.appendResolver(new NPMResolver(this._contractsDir));
        resolver.appendResolver(new RelativeFSResolver(this._contractsDir));
        resolver.appendResolver(new FSResolver());
        resolver.appendResolver(this._nameResolver);
        this._resolver = resolver;
    }
    /**

@0x/sol-resolver

Import resolver for smart contracts dependencies

Apache-2.0
Latest version published 2 years ago

Package Health Score

64 / 100
Full package analysis