Skip to content

Commit

Permalink
fix: sf-clean too
Browse files Browse the repository at this point in the history
  • Loading branch information
cristiand391 committed Jun 4, 2024
1 parent 036327b commit 9200779
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
13 changes: 11 additions & 2 deletions bin/sf-clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

const { readFileSync } = require('fs');
const { join } = require('path');
const { EOL } = require('node:os');
const shell = require('../utils/shelljs');
const log = require('../utils/log');
const loadRootPath = require('../utils/load-root-path');
Expand All @@ -25,11 +24,21 @@ const gitignorePath = loadRootPath('.gitignore');
if (gitignorePath) {
const VALID_SEGMENTS = ['CLEAN', 'CLEAN ALL'];
const gitignore = readFileSync(join(gitignorePath, '.gitignore'), 'utf8');

// respect the file EOL (`CRLF` or `LF`).
//
// we can't use node's `os.EOL` because that assumes:
// * unix only uses `CL`
// * win only uses `CRLF`
//
// when all 4 scenarios are completely valid
const originalEOL = gitignore.includes('\r\n') ? '\r\n' : '\n';

const segments = gitignore
// Segments are defined by "# --" in the gitignore
.split('# --')
// Turn each segment into list of valid gitignore lines
.map((segment) => segment.split(EOL).filter((line) => line && !line.startsWith('#')))
.map((segment) => segment.split(originalEOL).filter((line) => line && !line.startsWith('#')))
// Maps segment name to list of valid gitignore lines
.reduce((map, segment) => {
const segmentName = (segment.shift() || '').trim();
Expand Down
7 changes: 7 additions & 0 deletions utils/standardize-files.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ function writeGitignore(targetDir) {
const relevantPatterns = IGNORES.filter((entry) => !entry.plugin || (entry.plugin && isAPlugin));
let original = readFileSync(gitignoreTargetPath, 'utf-8');

// respect the file EOL (`CRLF` or `LF`).
//
// we can't use node's `os.EOL` because that assumes:
// * unix only uses `CL`
// * win only uses `CRLF`
//
// when all 4 scenarios are completely valid
const originalEOL = original.includes('\r\n') ? '\r\n' : '\n';

const segments = original
Expand Down

0 comments on commit 9200779

Please sign in to comment.