Skip to content

fix(build-cli): Use correct line endings #24594

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

Merged
merged 5 commits into from
Jun 7, 2025
Merged
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
4 changes: 3 additions & 1 deletion build-tools/packages/build-cli/src/commands/check/layers.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import path from "node:path";
import { Flags } from "@oclif/core";

import { BaseCommand, LayerGraph } from "../../library/index.js";
// eslint-disable-next-line import/no-internal-modules -- AB#8118 tracks removing the barrel files and importing directly from the submodules, including disabling this rule.
import { writeFileWithLineFeeds } from "../../library/text.js";

const packagesMdFileName = "PACKAGES.md";

@@ -46,7 +48,7 @@ export class CheckLayers extends BaseCommand<typeof CheckLayers> {
// Write human-readable package list organized by layer
if (flags.md !== undefined) {
const packagesMdFilePath: string = path.join(resolvedRoot, flags.md, packagesMdFileName);
await writeFile(
await writeFileWithLineFeeds(
packagesMdFilePath,
layerGraph.generatePackageLayersMarkdown(resolvedRoot),
);
Original file line number Diff line number Diff line change
@@ -3,12 +3,13 @@
* Licensed under the MIT License.
*/

import { writeFile } from "node:fs/promises";
import path from "node:path";
import type { Package } from "@fluidframework/build-tools";
import { Flags } from "@oclif/core";
import execa from "execa";
import { PackageCommand } from "../../BasePackageCommand.js";
// eslint-disable-next-line import/no-internal-modules -- AB#8118 tracks removing the barrel files and importing directly from the submodules, including disabling this rule.
import { writeFileWithLineFeeds } from "../../library/text.js";

/**
* JSON results from running npm pack --json.
@@ -96,6 +97,6 @@ export default class GeneratePackListCommand extends PackageCommand<
});

const output = files.join("\n");
await writeFile(outFile, output);
await writeFileWithLineFeeds(outFile, output);
}
}
4 changes: 3 additions & 1 deletion build-tools/packages/build-cli/src/library/layerGraph.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@
*/

import assert from "node:assert";
import { EOL as newline } from "node:os";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { Package } from "@fluidframework/build-tools";
@@ -15,6 +14,9 @@ const traceLayerCheck = registerDebug("layer-check");

const __dirname = path.dirname(fileURLToPath(import.meta.url));

// Always use LF since that's our repo standard.
const newline = "\n";

interface ILayerInfo {
deps?: string[];
packages?: string[];
17 changes: 16 additions & 1 deletion build-tools/packages/build-cli/src/library/text.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { readFile } from "node:fs/promises";
import { readFile, writeFile } from "node:fs/promises";

/**
* Indent text by prepending spaces.
@@ -28,3 +28,18 @@ export async function readLines(filePath: string): Promise<string[]> {
const lines = content.split(/\r?\n/);
return lines.filter((line) => line.trim() !== "");
}

/**
* Writes to a file, replacing any CRLF line-endings with LF. If the file data is not a string, this function behaves
* the same as writeFile.
*/
export async function writeFileWithLineFeeds(
...args: Parameters<typeof writeFile>
): Promise<void> {
const [filePath, data, options] = args; // Destructure positional arguments
return writeFile(
filePath,
typeof data === "string" ? data.replace(/\r\n/g, "\n") : data,
options,
);
}