This repository has been archived by the owner on Jan 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Warn when importing vanilla contracts package (#1335)
* Warn when importing vanilla contracts package Users should only install contracts from oz/contracts-eth-package, not oz/contracts. Warn about this when an import for the vanilla contracts package is found. * Implement suggestions by @frangio
- Loading branch information
1 parent
28226a5
commit 3f2dd99
Showing
7 changed files
with
70 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Contract from '../artifacts/Contract'; | ||
import ContractAST from '../utils/ContractAST'; | ||
|
||
let VANILLA_CONTRACTS = '@openzeppelin/contracts/'; | ||
|
||
export function importsVanillaContracts(contract: Contract, buildArtifacts?: any): string[] | undefined { | ||
const ast = new ContractAST(contract, buildArtifacts, { nodesFilter: [] }); | ||
const illegalImports = [...ast.getImports()] | ||
.filter(i => i.startsWith(VANILLA_CONTRACTS)) | ||
.map(i => i.slice(VANILLA_CONTRACTS.length)) | ||
.map(i => i.replace(/^contracts\//, '')); | ||
|
||
return illegalImports.length > 0 ? illegalImports : undefined; | ||
} | ||
|
||
// Used for testing purposes; | ||
export function setVanillaContractsPackageName(value: string) { | ||
VANILLA_CONTRACTS = value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters