Skip to content

Commit 9e1e6c4

Browse files
committed
feat: add hash to pie.manifest.json
1 parent bf6521a commit 9e1e6c4

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/install/index.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ const findResolution = (result: InstallResult, value: string): string => {
7878
return out.version;
7979
};
8080

81+
const hashCode = (str: string): string => {
82+
let res = 0;
83+
const len = str.length;
84+
for (let i = 0; i < len; i++) {
85+
res = res * 31 + str.charCodeAt(i);
86+
// tslint:disable-next-line:no-bitwise
87+
res = res & res;
88+
}
89+
return res.toString();
90+
};
91+
8192
export default class Install {
8293
constructor(private rootDir: string, private config: RawConfig) {}
8394

@@ -109,10 +120,21 @@ export default class Install {
109120
};
110121
});
111122

123+
const infoString = info
124+
.map(i => `${i.pie}@${i.version.resolved}`)
125+
.join(',');
126+
127+
const manifest = {
128+
hash: hashCode(infoString),
129+
hashString: infoString,
130+
info
131+
};
132+
112133
writeFileSync(
113134
join(this.rootDir, 'pie.manifest.json'),
114-
JSON.stringify(info, null, ' ')
135+
JSON.stringify(manifest, null, ' ')
115136
);
137+
116138
resolve(null);
117139
});
118140
}

0 commit comments

Comments
 (0)