Skip to content

Commit 226169a

Browse files
committed
'bump'
1 parent 35807ac commit 226169a

File tree

4 files changed

+55
-7
lines changed

4 files changed

+55
-7
lines changed

lib/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ var $path;
105105
return pathUtil.join(...paths).replace(/\\/g, '/');
106106
}
107107
$path.join = join;
108+
function normalize(path) {
109+
path = path
110+
// Replace all / duplicates, but not near the protocol
111+
.replace(/(?<![:/])\/{2,}/g, '/')
112+
// Use forward slashes
113+
.replace(/\\/g, '/')
114+
// Replace "foo/./bar" with single slash: "foo/bar"
115+
.replace(/\/\.\//g, '/');
116+
while (true) {
117+
let next = path.replace(/([^\/]+)\/\.\.\//g, (match, p1) => {
118+
if (p1 !== '..' && p1 !== '.') {
119+
return '';
120+
}
121+
return match;
122+
});
123+
if (next === path) {
124+
// nothing to collapse
125+
break;
126+
}
127+
path = next;
128+
}
129+
return path;
130+
}
131+
$path.normalize = normalize;
108132
})($path = exports.$path || (exports.$path = {}));
109133
//# sourceMappingURL=$path.js.map
110134
//# sourceMappingURL=$path.ts.map;
@@ -237,7 +261,7 @@ const taskArgsStore = { compileAll: false };
237261
const app = new _0xweb_1.App();
238262
await (0, alot_1.default)(contracts)
239263
.forEachAsync(async (contract, i) => {
240-
console.log(`Generate ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
264+
console.log(`Generate ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
241265
const params = [
242266
`install`, `${contract.path}`,
243267
'--name', contract.name,
@@ -299,7 +323,7 @@ async function getCompiledAbis(config, compileSolOutput) {
299323
return shouldInstall;
300324
}
301325
if (sources != null) {
302-
return x.sourceFile.toLowerCase().startsWith(`file://${sources.toLowerCase()}`);
326+
return _path_1.$path.normalize(x.sourceFile).toLowerCase().startsWith(`file://${_path_1.$path.normalize(sources).toLowerCase()}`);
303327
}
304328
return false;
305329
})

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.26",
4+
"version": "0.1.27",
55
"main": "./lib/index.js",
66
"author": {
77
"name": "Alex Kit",

src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ subtask(TASK_0xWEB_GENERATE)
141141
const app = new App();
142142
await alot(contracts)
143143
.forEachAsync(async (contract, i) => {
144-
console.log(`Generate ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
144+
console.log(`Generate ${contract.name}(${contract.path}) ${i}/${contracts.length}`);
145145
const params = [
146146
`install`, `${contract.path}`,
147147
'--name', contract.name,
@@ -189,9 +189,9 @@ async function getCompiledAbis(config: {
189189
// system path directory with the contract sources
190190
sources: string
191191
}
192-
'0xweb': {
192+
'0xweb'?: {
193193
// SOL files or contract names as CSV
194-
install: string
194+
install?: string
195195
}
196196
}, compileSolOutput: {
197197
artifactsEmittedPerJob: {
@@ -227,7 +227,7 @@ async function getCompiledAbis(config: {
227227
return shouldInstall;
228228
}
229229
if (sources != null) {
230-
return x.sourceFile.toLowerCase().startsWith(`file://${sources.toLowerCase()}`);
230+
return $path.normalize(x.sourceFile).toLowerCase().startsWith(`file://${$path.normalize(sources).toLowerCase()}`);
231231
}
232232
return false;
233233
})

src/utils/$path.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,28 @@ export namespace $path {
1111
export function join (...paths: string[]) {
1212
return pathUtil.join(...paths).replace(/\\/g, '/');
1313
}
14+
export function normalize (path: string) {
15+
path = path
16+
// Replace all / duplicates, but not near the protocol
17+
.replace(/(?<![:/])\/{2,}/g, '/')
18+
// Use forward slashes
19+
.replace(/\\/g, '/')
20+
// Replace "foo/./bar" with single slash: "foo/bar"
21+
.replace(/\/\.\//g, '/')
22+
;
23+
while (true) {
24+
let next = path.replace(/([^\/]+)\/\.\.\//g, (match, p1) => {
25+
if (p1 !== '..' && p1 !== '.') {
26+
return '';
27+
}
28+
return match;
29+
});
30+
if (next === path) {
31+
// nothing to collapse
32+
break;
33+
}
34+
path = next;
35+
}
36+
return path;
37+
}
1438
}

0 commit comments

Comments
 (0)