Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 .changeset/clever-feet-move.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@manypkg/cli": minor
---

Respect line endings of package.json files on windows
14 changes: 9 additions & 5 deletions packages/cli/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ import detectIndent from "detect-indent";
export async function writePackage(pkg: Package) {
let pkgRaw = await fs.readFile(path.join(pkg.dir, "package.json"), "utf-8");
let indent = detectIndent(pkgRaw).indent || " ";
return fs.writeFile(
path.join(pkg.dir, "package.json"),
JSON.stringify(pkg.packageJson, null, indent) +
(pkgRaw.endsWith("\n") ? "\n" : "")
);
// Determine original EOL style and whether there was a trailing newline
const eol = pkgRaw.includes("\r\n") ? "\r\n" : "\n";
// Stringify and then normalize EOLs to match the original file
let json = JSON.stringify(pkg.packageJson, null, indent);
json = eol !== "\n" ? json.replace(/\n/g, eol) : json;
if (pkgRaw.endsWith("\n") /* true for both LF and CRLF */) {
json += eol;
}
return fs.writeFile(path.join(pkg.dir, "package.json"), json);
}

export async function install(toolType: string, cwd: string) {
Expand Down