@nomiclabs/buidler
Version:
Buidler is an extensible developer tool that helps smart contract developers increase productivity by reliably bringing together the tools they want.
65 lines • 2.91 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = __importDefault(require("chalk"));
const debug_1 = __importDefault(require("debug"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path = __importStar(require("path"));
const constants_1 = require("../../internal/constants");
const reporter_1 = require("../../internal/sentry/reporter");
const log = debug_1.default("buidler:core:compilation-watcher");
async function watchCompilerOutput(provider, solcConfig, paths) {
const chokidar = await Promise.resolve().then(() => __importStar(require("chokidar")));
const compilerVersion = solcConfig.version;
const solcInputPath = path.join(paths.cache, constants_1.SOLC_INPUT_FILENAME);
const solcOutputPath = path.join(paths.cache, constants_1.SOLC_OUTPUT_FILENAME);
const addCompilationResult = async () => {
if (!(await fs_extra_1.default.pathExists(path.join(paths.cache, constants_1.SOLC_INPUT_FILENAME)))) {
return false;
}
if (!(await fs_extra_1.default.pathExists(path.join(paths.cache, constants_1.SOLC_OUTPUT_FILENAME)))) {
return false;
}
try {
log("Adding new compilation result to the node");
const compilerInput = await fs_extra_1.default.readJSON(solcInputPath, {
encoding: "utf8",
});
const compilerOutput = await fs_extra_1.default.readJSON(solcOutputPath, {
encoding: "utf8",
});
await provider.send("buidler_addCompilationResult", [
compilerVersion,
compilerInput,
compilerOutput,
]);
}
catch (error) {
console.warn(chalk_1.default.yellow("There was a problem adding the new compiler result. Run Buidler with --verbose to learn more."));
log("Last compilation result couldn't be added. Please report this to help us improve Buidler.\n", error);
reporter_1.Reporter.reportError(error);
}
};
log(`Watching changes on '${solcOutputPath}'`);
chokidar
.watch(solcOutputPath, {
ignoreInitial: true,
awaitWriteFinish: {
stabilityThreshold: 250,
pollInterval: 50,
},
})
.on("add", addCompilationResult)
.on("change", addCompilationResult);
}
exports.watchCompilerOutput = watchCompilerOutput;
//# sourceMappingURL=watch.js.map
;