Skip to content

Commit

Permalink
fix: allows files to be correctly compared across operating systems
Browse files Browse the repository at this point in the history
  • Loading branch information
RodEsp committed Jun 10, 2022
1 parent 60d357a commit 9c6c478
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions utils/standardize-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

const { join } = require('path');
const { readFileSync, unlinkSync, copyFileSync, statSync, writeFileSync } = require('fs');
const { readFileSync, unlinkSync, copyFileSync, writeFileSync } = require('fs');
const log = require('./log');
const exists = require('./exists');
const { resolveConfig } = require('./sf-config');
Expand All @@ -21,10 +21,13 @@ const FILE_NAME_MOCHARC = 'mocharc.json';

function isDifferent(sourcePath, targetPath) {
try {
if (statSync(sourcePath).size !== statSync(targetPath).size) {
return true;
}
return readFileSync(sourcePath, 'utf8') !== readFileSync(targetPath, 'utf8');
// Using .replace() to normalize line endings across operating systems.
// eslint-disable-next-line no-control-regex
const sourceFile = readFileSync(sourcePath, 'utf8').replace(new RegExp('\r\n', 'g'), '\n');
// eslint-disable-next-line no-control-regex
const targetFile = readFileSync(targetPath, 'utf8').replace(new RegExp('\r\n', 'g'), '\n');

return sourceFile !== targetFile;
} catch (error) {
/* do nothing */
}
Expand Down

0 comments on commit 9c6c478

Please sign in to comment.