Skip to content

Set line endings for project files (package.json) touched by tsdown #832

@DesselBane

Description

@DesselBane

Clear and concise description of the problem

I use (and love) the exports feature of tsdown. However tsdown always writes LF line endings which causes the package.json files to to show up as changed until I stage them and git converts the line endings back to CRLF.

Would be cool if this could be changed in the options.

Suggested solution

In the options of tsdown there should be an option to set the line endings like

const options {
  endOfLine: '\n' | '\r\n' | 'auto'
}

where auto would use \n on unix and \r\n on windows

Alternative

No response

Additional context

To circumvent this I currently use a build:done hook which ensures the line endings are correct for the current OS

export async function fixLineEndingsHook() {
	const packageJsonBuff = await readFile("./package.json", null);
	const packageJsonContents = packageJsonBuff.toString();

	const lineEndingFrom = platform() === "win32" ? /(?<!\r)\n/g : /\r\n/g;
	const lineEndingTo = platform() === "win32" ? "\r\n" : "\n";

	const packageJsonFixed = packageJsonContents.replaceAll(lineEndingFrom, lineEndingTo);

	await writeFile("./package.json", packageJsonFixed);
}

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Priority

    None yet

    Start date

    None yet

    Target date

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions