Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use determinstic output file hashes based on git commit #1952

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion packages/config/src/lib/createConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const path = require('path');
const fs = require('fs');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const searchIgnoredStyles = require('@redhat-cloud-services/frontend-components-config-utilities/search-ignored-styles');
const childProcess = require('child_process');

import { LogType, ProxyOptions, fecLogger, proxy } from '@redhat-cloud-services/frontend-components-config-utilities';
type Configuration = import('webpack').Configuration;
Expand Down Expand Up @@ -96,7 +97,20 @@ export const createConfig = ({
fecLogger(LogType.warn, `The _unstableHotReload option in shared webpack config is deprecated. Use hotReload config instead.`);
}
const internalHotReload = !!(typeof hotReload !== 'undefined' ? hotReload : _unstableHotReload);
const filenameMask = `js/[name].${!internalHotReload && useFileHash ? `[fullhash].` : ''}js`;

// Set our file hashing to use the git commit hash
// If git command fails, fall back to Webpack's [fullhash]
// We do this so that we get deterministic file names for each commit
let outputFileHash;
try {
// Try to execute the git command
const gitOutput = childProcess.execSync('git rev-parse HEAD').toString().trim();
outputFileHash = gitOutput;
} catch (error) {
// If git command fails, fall back to Webpack's [fullhash]
outputFileHash = '[fullhash]';
}
const filenameMask = `js/[name].${!internalHotReload && useFileHash ? `${outputFileHash}.` : ''}js`;

const outputPath = `${rootFolder || ''}/dist`;

Expand Down