Skip to content

Commit d9f3522

Browse files
committed
cleanups
Signed-off-by: Karthik Ganeshram <[email protected]>
1 parent 3ed91ff commit d9f3522

File tree

3 files changed

+9
-16
lines changed

3 files changed

+9
-16
lines changed

packages/build-tools/src/build.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import { readFile } from 'node:fs/promises';
12
import {
2-
calculateFileChecksum,
3+
calculateChecksum,
34
fileExists,
45
getExistingBuildData,
56
} from './utils.js';
@@ -11,7 +12,7 @@ export function getBuildDataPath(src: string): string {
1112
export async function ShouldComponentize(
1213
src: string, outputPath: string, componentizeVersion: string, runtimeArgs: string, targetWitChecksum: string
1314
) {
14-
const sourceChecksum = await calculateFileChecksum(src);
15+
const sourceChecksum = await calculateChecksum(await readFile(src));
1516
const existingBuildData = await getExistingBuildData(getBuildDataPath(src));
1617

1718
if (

packages/build-tools/src/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ import { componentize } from '@bytecodealliance/componentize-js';
44
import { version as componentizeVersion } from '@bytecodealliance/componentize-js';
55
import { getPackagesWithWasiDeps, processWasiDeps } from './wasiDepsParser.js';
66
import {
7-
calculateCheckSum,
8-
calculateFileChecksum,
7+
calculateChecksum,
98
saveBuildData,
109
} from './utils.js';
1110
import { getCliArgs } from './cli.js';
@@ -55,8 +54,7 @@ async function main() {
5554
'combined-wit:[email protected]',
5655
);
5756

58-
// Calcuilate the checksum of the inline wit
59-
let inlineWitChecksum = await calculateCheckSum(inlineWit);
57+
let inlineWitChecksum = await calculateChecksum(inlineWit);
6058
// Small optimization to skip componentization if the source file hasn't changed
6159
if (!(await ShouldComponentize(src, outputPath, componentizeVersion, runtimeArgs, inlineWitChecksum))) {
6260
console.log(
@@ -88,7 +86,7 @@ async function main() {
8886
// Save the checksum of the input file along with the componentize version
8987
await saveBuildData(
9088
getBuildDataPath(src),
91-
await calculateFileChecksum(src),
89+
await calculateChecksum(await readFile(src)),
9290
componentizeVersion,
9391
runtimeArgs,
9492
inlineWitChecksum,

packages/build-tools/src/utils.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,17 @@ import { access, writeFile } from 'node:fs/promises';
44

55

66
// Function to calculate file checksum
7-
export async function calculateFileChecksum(filePath: string) {
7+
export async function calculateChecksum(content: string | Buffer) {
88
try {
9-
const fileBuffer = await readFile(filePath);
109
const hash = createHash('sha256');
11-
hash.update(fileBuffer);
10+
hash.update(content);
1211
return hash.digest('hex');
1312
} catch (error) {
14-
console.error(`Error calculating checksum for file ${filePath}:`, error);
13+
console.error(`Error calculating checksum:`, error);
1514
throw error;
1615
}
1716
}
1817

19-
export function calculateCheckSum(data: string | Buffer): string {
20-
const hash = createHash('sha256');
21-
hash.update(data);
22-
return hash.digest('hex');
23-
}
2418

2519
// Function to check if a file exists
2620
export async function fileExists(filePath: string) {

0 commit comments

Comments
 (0)