Skip to content

Commit

Permalink
fix: add root package.json to hash if exists
Browse files Browse the repository at this point in the history
  • Loading branch information
hmdoganjf committed Sep 18, 2023
1 parent 1310bec commit 251c647
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@jotforminc/zenith",
"packageManager": "[email protected]",
"version": "0.10.1",
"version": "0.10.2",
"description": "",
"main": "./build/index.js",
"files": [
Expand Down
11 changes: 10 additions & 1 deletion src/classes/Hasher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Hash, createHash } from 'crypto';
import { readdirSync, readFileSync, existsSync } from 'fs';
import * as path from 'path';
import { ROOT_PATH } from '../utils/constants';
import ConfigHelperInstance from './ConfigHelper';
import { DebugJSON } from '../types/ConfigTypes';
import { isEmpty } from '../utils/functions';
Expand Down Expand Up @@ -53,7 +54,15 @@ export class Hasher {

getHash(directoryPath: string, script?: string, debug?: boolean, compareWith?: string, constantDeps?: Array<string>, isFirst = true): string {
const hasher = createHash('sha256');
if (isFirst && script) hasher.update(script);
if (isFirst && script) {
hasher.update(script);

const packageJSONPath = path.join(ROOT_PATH, 'package.json');
if (existsSync(packageJSONPath)) {
const rootPackageJSONString = readFileSync(packageJSONPath, { encoding: 'utf-8' });
hasher.update(rootPackageJSONString);
}
}
const directory = readdirSync(directoryPath, { withFileTypes: true });
if (directory.length === 0) return '';
if (isFirst) {
Expand Down

0 comments on commit 251c647

Please sign in to comment.