Skip to content

Commit

Permalink
fix: dynamically require os for edge runtime compatibility (#1262)
Browse files Browse the repository at this point in the history
  • Loading branch information
shellscape committed Nov 29, 2023
1 parent 107f273 commit dee95d7
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/options/format.js
@@ -1,7 +1,16 @@
var systemLineBreak = require('os').EOL;

var override = require('../utils/override');

function getSystemLineBreak() {
var systemLineBreak = '\n';
try {
var os = require('os');
systemLineBreak = os.EOL;
} catch (_) {
// no op
}
return systemLineBreak;
}

var Breaks = {
AfterAtRule: 'afterAtRule',
AfterBlockBegins: 'afterBlockBegins',
Expand All @@ -17,7 +26,7 @@ var Breaks = {
var BreakWith = {
CarriageReturnLineFeed: '\r\n',
LineFeed: '\n',
System: systemLineBreak
System: getSystemLineBreak()
};

var IndentWith = {
Expand Down Expand Up @@ -193,7 +202,7 @@ function mapBreakWith(value) {
case BreakWith.LineFeed:
return BreakWith.LineFeed;
default:
return systemLineBreak;
return BreakWith.System;
}
}

Expand Down

0 comments on commit dee95d7

Please sign in to comment.