Skip to content

Enforce LF line endings everywhere #128

New issue

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

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

Already on GitHub? # to your account

Merged
merged 2 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text eol=lf

*.png binary
*.jpg binary
*.gif binary
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"files.eol": "\n"
}
40 changes: 20 additions & 20 deletions src/api/queue.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { WalkerState } from "../types";
type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
/**
* This is a custom stateless queue to track concurrent async fs calls.
* It increments a counter whenever a call is queued and decrements it
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
*/
export class Queue {
private count: number = 0;
constructor(private readonly onQueueEmpty: OnQueueEmptyCallback) {}
enqueue() {
this.count++;
}
dequeue(error: Error | null, output: WalkerState) {
if (--this.count <= 0 || error) this.onQueueEmpty(error, output);
}
}
import { WalkerState } from "../types";

type OnQueueEmptyCallback = (error: Error | null, output: WalkerState) => void;
/**
* This is a custom stateless queue to track concurrent async fs calls.
* It increments a counter whenever a call is queued and decrements it
* as soon as it completes. When the counter hits 0, it calls onQueueEmpty.
*/
export class Queue {
private count: number = 0;
constructor(private readonly onQueueEmpty: OnQueueEmptyCallback) {}

enqueue() {
this.count++;
}

dequeue(error: Error | null, output: WalkerState) {
if (--this.count <= 0 || error) this.onQueueEmpty(error, output);
}
}
86 changes: 43 additions & 43 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,43 +1,43 @@
import { sep, normalize, resolve } from "path";
import { PathSeparator } from "./types";
export function cleanPath(path: string) {
let normalized = normalize(path);
// we have to remove the last path separator
// to account for / root path
if (normalized.length > 1 && normalized[normalized.length - 1] === sep)
normalized = normalized.substring(0, normalized.length - 1);
return normalized;
}
const SLASHES_REGEX = /[\\/]/g;
export function convertSlashes(path: string, separator: PathSeparator) {
return path.replace(SLASHES_REGEX, separator);
}
export function normalizePath(
path: string,
options: {
resolvePaths?: boolean;
normalizePath?: boolean;
pathSeparator: PathSeparator;
}
) {
const { resolvePaths, normalizePath, pathSeparator } = options;
const pathNeedsCleaning =
(process.platform === "win32" && path.includes("/")) ||
path.startsWith(".");
if (resolvePaths) path = resolve(path);
if (normalizePath || pathNeedsCleaning) path = cleanPath(path);
if (path === ".") return "";
const needsSeperator = path[path.length - 1] !== pathSeparator;
return convertSlashes(
needsSeperator ? path + pathSeparator : path,
pathSeparator
);
}
import { sep, normalize, resolve } from "path";
import { PathSeparator } from "./types";

export function cleanPath(path: string) {
let normalized = normalize(path);

// we have to remove the last path separator
// to account for / root path
if (normalized.length > 1 && normalized[normalized.length - 1] === sep)
normalized = normalized.substring(0, normalized.length - 1);

return normalized;
}

const SLASHES_REGEX = /[\\/]/g;
export function convertSlashes(path: string, separator: PathSeparator) {
return path.replace(SLASHES_REGEX, separator);
}

export function normalizePath(
path: string,
options: {
resolvePaths?: boolean;
normalizePath?: boolean;
pathSeparator: PathSeparator;
}
) {
const { resolvePaths, normalizePath, pathSeparator } = options;
const pathNeedsCleaning =
(process.platform === "win32" && path.includes("/")) ||
path.startsWith(".");

if (resolvePaths) path = resolve(path);
if (normalizePath || pathNeedsCleaning) path = cleanPath(path);

if (path === ".") return "";

const needsSeperator = path[path.length - 1] !== pathSeparator;
return convertSlashes(
needsSeperator ? path + pathSeparator : path,
pathSeparator
);
}
Loading