Skip to content

Commit 451523e

Browse files
committed
'bump'
1 parent 2b1a39a commit 451523e

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

lib/index.js

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,12 +145,16 @@ const taskArgsStore = { compileAll: false };
145145
.addOptionalParam('root', 'Overrides root directory. If sources is also overridden must be the sub-folder of the sources dir')
146146
.addOptionalParam('package', 'Compile the contracts within a specific mono-repo package. Artifacts and 0xc classes will be placed in the package directory')
147147
.addOptionalParam('tsgen', 'Skip the TypeScript class generation', true, config_1.types.boolean)
148+
.addOptionalParam('install', 'CSV sol path to install, default installs all compiled contracts from sources')
148149
.addFlag('watch', 'Watch sources directory and reruns compilation task on changes')
149150
.setAction(async (compilationArgs, { run, config, artifacts }, runSuper) => {
150151
ConfigHelper.resetPaths(config.paths);
151152
if (compilationArgs.tsgen === false) {
152153
config['0xweb'].tsgen = false;
153154
}
155+
if (compilationArgs.install != null) {
156+
config['0xweb'].install = compilationArgs.install;
157+
}
154158
if (compilationArgs.package != null) {
155159
config['0xweb'].package = compilationArgs.package;
156160
if (compilationArgs.artifacts == null) {
@@ -271,33 +275,54 @@ const taskArgsStore = { compileAll: false };
271275
await runSuper();
272276
});
273277
async function getCompiledAbis(config, compileSolOutput) {
278+
var _a, _b, _c;
279+
const sources = config.paths.sources;
280+
const installs = (_c = (_b = (_a = config['0xweb']) === null || _a === void 0 ? void 0 : _a.install) === null || _b === void 0 ? void 0 : _b.split(',').map(x => x.trim())) !== null && _c !== void 0 ? _c : null;
274281
const emittedArtifacts = (0, alot_1.default)(compileSolOutput.artifactsEmittedPerJob).mapMany((a) => {
275282
return (0, alot_1.default)(a.artifactsEmittedPerFile).mapMany((artifactPerFile) => {
276283
return (0, alot_1.default)(artifactPerFile.artifactsEmitted).map((artifactName) => {
277284
return {
278-
name: artifactName,
285+
// Contract Name
286+
artifactName: artifactName,
287+
// Contract local path, aka import
288+
sourceName: artifactPerFile.file.sourceName,
289+
// Contract system path, aka file path
279290
sourceFile: 'file://' + artifactPerFile.file.absolutePath
280291
};
281292
})
282-
.filter(x => x.sourceFile.includes('@openzeppelin') === false)
293+
.filter(x => {
294+
if (installs != null) {
295+
let shouldInstall = installs.some(toInstall => {
296+
var _a;
297+
return x.artifactName === toInstall || ((_a = x.sourceName) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === toInstall.toLowerCase();
298+
});
299+
return shouldInstall;
300+
}
301+
if (sources != null) {
302+
return x.sourceFile.toLowerCase().startsWith(`file://${sources}`);
303+
}
304+
return false;
305+
})
306+
//.filter(x => x.sourceFile.includes('@openzeppelin') === false)
283307
.toArray();
284308
}).toArray();
285309
}).toArray();
286-
let namesHash = (0, alot_1.default)(emittedArtifacts).toDictionary(x => x.name);
310+
let namesHash = (0, alot_1.default)(emittedArtifacts).toDictionary(x => x.artifactName);
287311
let files = await atma_io_1.Directory.readFilesAsync(`file://${config.paths.artifacts}/`, '**.json');
288312
let compileAll = taskArgsStore.compileAll;
289313
let arr = files
290314
.map(file => {
291315
let path = file.uri.toString();
292-
let match = /(?<name>[^\\\/]+)\.sol[\\\/]/.exec(path);
316+
let match = /(?<sourceFileName>[^\\\/]+)\.sol[\\\/]/.exec(path);
293317
if (match == null) {
294318
return null;
295319
}
296-
let name = match.groups.name;
320+
// assume artifactName === sourceFileName @TODO consider to handle different file-contract names
321+
let name = match.groups.sourceFileName;
297322
if (compileAll !== true && name in namesHash === false) {
298323
return null;
299324
}
300-
if (new RegExp(`${name}\\.json$`).test(path) === false) {
325+
if (new RegExp(`[\\\/]${name}\\.json$`).test(path) === false) {
301326
return null;
302327
}
303328
return {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@0xweb/hardhat",
33
"description": "0xweb plugin for Hardhat",
4-
"version": "0.1.24",
4+
"version": "0.1.25",
55
"main": "./lib/index.js",
66
"author": {
77
"name": "Alex Kit",

src/index.ts

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
2121
.addOptionalParam('root', 'Overrides root directory. If sources is also overridden must be the sub-folder of the sources dir')
2222
.addOptionalParam('package', 'Compile the contracts within a specific mono-repo package. Artifacts and 0xc classes will be placed in the package directory')
2323
.addOptionalParam('tsgen', 'Skip the TypeScript class generation', true, types.boolean)
24+
.addOptionalParam('install', 'CSV sol path to install, default installs all compiled contracts from sources')
2425
.addFlag('watch', 'Watch sources directory and reruns compilation task on changes')
2526

2627
.setAction(async (
@@ -30,6 +31,7 @@ task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
3031
root?: string
3132
watch?: boolean
3233
tsgen?: boolean
34+
install?: string
3335
package?: string
3436
},
3537
{ run, config, artifacts },
@@ -41,6 +43,9 @@ task(TASK_COMPILE, 'Compiles the entire project, building all artifacts')
4143
if (compilationArgs.tsgen === false) {
4244
config['0xweb'].tsgen = false;
4345
}
46+
if (compilationArgs.install != null) {
47+
config['0xweb'].install = compilationArgs.install;
48+
}
4449
if (compilationArgs.package != null) {
4550
config['0xweb'].package = compilationArgs.package;
4651

@@ -177,7 +182,18 @@ task(TASK_CLEAN, 'Clears the cache and deletes all artifacts')
177182
await runSuper()
178183
});
179184

180-
async function getCompiledAbis(config: { paths: { artifacts: string } }, compileSolOutput: {
185+
async function getCompiledAbis(config: {
186+
paths: {
187+
// system path directory with the artifacts output
188+
artifacts: string
189+
// system path directory with the contract sources
190+
sources: string
191+
}
192+
'0xweb': {
193+
// SOL files or contract names as CSV
194+
install: string
195+
}
196+
}, compileSolOutput: {
181197
artifactsEmittedPerJob: {
182198
artifactsEmittedPerFile: {
183199
file: {
@@ -188,36 +204,55 @@ async function getCompiledAbis(config: { paths: { artifacts: string } }, compile
188204
}[]
189205
}[]
190206
}): Promise<{ name: string, path: string }[]> {
207+
const sources = config.paths.sources;
208+
const installs = config['0xweb']?.install?.split(',').map(x => x.trim()) ?? null;
191209

192210
const emittedArtifacts = alot(compileSolOutput.artifactsEmittedPerJob).mapMany((a) => {
193211
return alot(a.artifactsEmittedPerFile).mapMany((artifactPerFile) => {
194212
return alot(artifactPerFile.artifactsEmitted).map((artifactName) => {
195213
return {
196-
name: artifactName,
214+
// Contract Name
215+
artifactName: artifactName,
216+
// Contract local path, aka import
217+
sourceName: artifactPerFile.file.sourceName,
218+
// Contract system path, aka file path
197219
sourceFile: 'file://' + artifactPerFile.file.absolutePath
198220
};
199221
})
200-
.filter(x => x.sourceFile.includes('@openzeppelin') === false)
222+
.filter(x => {
223+
if (installs != null) {
224+
let shouldInstall = installs.some(toInstall => {
225+
return x.artifactName === toInstall || x.sourceName?.toLowerCase() === toInstall.toLowerCase()
226+
});
227+
return shouldInstall;
228+
}
229+
if (sources != null) {
230+
return x.sourceFile.toLowerCase().startsWith(`file://${sources}`);
231+
}
232+
return false;
233+
})
234+
//.filter(x => x.sourceFile.includes('@openzeppelin') === false)
201235
.toArray();
202236
}).toArray();
203237
}).toArray();
204238

205-
let namesHash = alot(emittedArtifacts).toDictionary(x => x.name);
239+
let namesHash = alot(emittedArtifacts).toDictionary(x => x.artifactName);
206240
let files = await Directory.readFilesAsync(`file://${config.paths.artifacts}/`, '**.json');
207241
let compileAll = taskArgsStore.compileAll;
208242
let arr = files
209243
.map(file => {
210244
let path = file.uri.toString();
211245

212-
let match = /(?<name>[^\\\/]+)\.sol[\\\/]/.exec(path);
246+
let match = /(?<sourceFileName>[^\\\/]+)\.sol[\\\/]/.exec(path);
213247
if (match == null) {
214248
return null;
215249
}
216-
let name = match.groups.name;
250+
// assume artifactName === sourceFileName @TODO consider to handle different file-contract names
251+
let name = match.groups.sourceFileName;
217252
if (compileAll !== true && name in namesHash === false) {
218253
return null;
219254
}
220-
if (new RegExp(`${name}\\.json$`).test(path) === false) {
255+
if (new RegExp(`[\\\/]${name}\\.json$`).test(path) === false) {
221256
return null;
222257
}
223258

0 commit comments

Comments
 (0)