Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function pullImageIfNecessary(
docker: BuidlerDocker,
image: Image,
cachePath: string
) {
if (!(await docker.hasPulledImage(image))) {
console.log(
`Pulling Docker image ${BuidlerDocker.imageToRepoTag(image)}...`
);
await docker.pullImage(image);
console.log(`Image pulled`);
} else {
await checkForImageUpdates(docker, image, cachePath);
}
}
async function checkForImageUpdates(
docker: BuidlerDocker,
image: Image,
cachePath: string
) {
if (!(await shouldCheckForUpdates(image, cachePath))) {
return;
}
if (!(await docker.isImageUpToDate(image))) {
console.log(
`Updating Docker image ${BuidlerDocker.imageToRepoTag(image)}...`
);
await docker.pullImage(image);
console.log(`Image updated`);
}
await saveLastUpdateCheckDate(image, cachePath);
}
export async function compile(vyperConfig: VyperConfig, paths: ProjectPaths) {
const vyperVersion = vyperConfig.version;
const dockerImage = {
repository: VYPER_DOCKER_REPOSITORY,
tag: vyperVersion
};
await validateDockerIsInstalled();
const docker = await handleCommonErrors(BuidlerDocker.create());
await handleCommonErrors(
pullImageIfNecessary(docker, dockerImage, paths.cache)
);
const files = await getVyperSources(paths);
let someContractFailed = false;
for (const file of files) {
const pathFromCWD = path.relative(process.cwd(), file);
const pathFromSources = path.relative(paths.sources, file);
if (await isAlreadyCompiled(file, paths, vyperVersion, files)) {
console.log(pathFromCWD, "is already compiled");
continue;
async function getLastUpdateCheckDate(
image: Image,
cachePath: string
): Promise {
const file = path.join(cachePath, VYPER_DOCKER_IMAGES_LAST_UPDATE_CHECK_FILE);
if (!(await fsExtra.pathExists(file))) {
return undefined;
}
const updates = await fsExtra.readJSON(file);
return updates[BuidlerDocker.imageToRepoTag(image)];
}
if (error instanceof DockerHubConnectionError) {
throw new BuidlerPluginError(
`Error connecting to Docker Hub.
Please check your internet connection.`,
error
);
}
if (error instanceof DockerServerError) {
throw new BuidlerPluginError("Docker error", error);
}
if (error instanceof ImageDoesntExistError) {
throw new BuidlerPluginError(
`Docker image ${BuidlerDocker.imageToRepoTag(
error.image
)} doesn't exist.
Make sure you chose a valid Vyper version.`
);
}
throw error;
}
}
async function saveLastUpdateCheckDate(image: Image, cachePath: string) {
let updates: { [repoTag: string]: number };
const file = path.join(cachePath, VYPER_DOCKER_IMAGES_LAST_UPDATE_CHECK_FILE);
if (!(await fsExtra.pathExists(file))) {
updates = {};
} else {
updates = await fsExtra.readJSON(file);
}
updates[BuidlerDocker.imageToRepoTag(image)] = +new Date();
await fsExtra.ensureDir(path.dirname(file));
await fsExtra.writeJSON(file, updates);
}
async function validateDockerIsInstalled() {
if (!(await BuidlerDocker.isInstalled())) {
throw new BuidlerPluginError(
`Docker Desktop is not installed.
Please install it by following the instructions on https://www.docker.com/get-started`
);
}
}