Remove require("os") from helpers to reduce dependencies for browser scenarios.

This commit is contained in:
David Anson 2021-12-27 03:41:43 +00:00 committed by GitHub
parent 9ec14f13a1
commit fd24b9552b
4 changed files with 20 additions and 20 deletions

View file

@ -25,12 +25,11 @@ module.exports = webpackEmptyContext;
/*!*****************************!*\ /*!*****************************!*\
!*** ../helpers/helpers.js ***! !*** ../helpers/helpers.js ***!
\*****************************/ \*****************************/
/***/ ((module, __unused_webpack_exports, __webpack_require__) => { /***/ ((module) => {
"use strict"; "use strict";
// @ts-check // @ts-check
var os = __webpack_require__(/*! os */ "?591e");
// Regular expression for matching common newline characters // Regular expression for matching common newline characters
// See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
var newLineRe = /\r\n?|\n/g; var newLineRe = /\r\n?|\n/g;
@ -655,9 +654,10 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
* Gets the most common line ending, falling back to the platform default. * Gets the most common line ending, falling back to the platform default.
* *
* @param {string} input Markdown content to analyze. * @param {string} input Markdown content to analyze.
* @param {string} [platform] Platform identifier (process.platform).
* @returns {string} Preferred line ending. * @returns {string} Preferred line ending.
*/ */
function getPreferredLineEnding(input) { function getPreferredLineEnding(input, platform) {
var cr = 0; var cr = 0;
var lf = 0; var lf = 0;
var crlf = 0; var crlf = 0;
@ -678,7 +678,8 @@ function getPreferredLineEnding(input) {
}); });
var preferredLineEnding = null; var preferredLineEnding = null;
if (!cr && !lf && !crlf) { if (!cr && !lf && !crlf) {
preferredLineEnding = os.EOL; preferredLineEnding =
((platform || process.platform) === "win32") ? "\r\n" : "\n";
} }
else if ((lf >= crlf) && (lf >= cr)) { else if ((lf >= crlf) && (lf >= cr)) {
preferredLineEnding = "\n"; preferredLineEnding = "\n";
@ -4343,16 +4344,6 @@ module.exports = markdownit;
/***/ }), /***/ }),
/***/ "?591e":
/*!********************!*\
!*** os (ignored) ***!
\********************/
/***/ (() => {
/* (ignored) */
/***/ }),
/***/ "?ec0a": /***/ "?ec0a":
/*!********************!*\ /*!********************!*\
!*** fs (ignored) ***! !*** fs (ignored) ***!

View file

@ -44,7 +44,6 @@ function config(options) {
"resolve": { "resolve": {
"fallback": { "fallback": {
"fs": false, "fs": false,
"os": false,
"path": false, "path": false,
"util": false "util": false
} }

View file

@ -2,8 +2,6 @@
"use strict"; "use strict";
const os = require("os");
// Regular expression for matching common newline characters // Regular expression for matching common newline characters
// See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js // See NEWLINES_RE in markdown-it/lib/rules_core/normalize.js
const newLineRe = /\r\n?|\n/g; const newLineRe = /\r\n?|\n/g;
@ -680,9 +678,10 @@ module.exports.emphasisMarkersInContent = emphasisMarkersInContent;
* Gets the most common line ending, falling back to the platform default. * Gets the most common line ending, falling back to the platform default.
* *
* @param {string} input Markdown content to analyze. * @param {string} input Markdown content to analyze.
* @param {string} [platform] Platform identifier (process.platform).
* @returns {string} Preferred line ending. * @returns {string} Preferred line ending.
*/ */
function getPreferredLineEnding(input) { function getPreferredLineEnding(input, platform) {
let cr = 0; let cr = 0;
let lf = 0; let lf = 0;
let crlf = 0; let crlf = 0;
@ -703,7 +702,8 @@ function getPreferredLineEnding(input) {
}); });
let preferredLineEnding = null; let preferredLineEnding = null;
if (!cr && !lf && !crlf) { if (!cr && !lf && !crlf) {
preferredLineEnding = os.EOL; preferredLineEnding =
((platform || process.platform) === "win32") ? "\r\n" : "\n";
} else if ((lf >= crlf) && (lf >= cr)) { } else if ((lf >= crlf) && (lf >= cr)) {
preferredLineEnding = "\n"; preferredLineEnding = "\n";
} else if (crlf >= cr) { } else if (crlf >= cr) {

View file

@ -387,7 +387,7 @@ test("forEachInlineCodeSpan", (t) => {
}); });
test("getPreferredLineEnding", (t) => { test("getPreferredLineEnding", (t) => {
t.plan(17); t.plan(19);
const testCases = [ const testCases = [
[ "", os.EOL ], [ "", os.EOL ],
[ "\r", "\r" ], [ "\r", "\r" ],
@ -412,6 +412,16 @@ test("getPreferredLineEnding", (t) => {
const actual = helpers.getPreferredLineEnding(input); const actual = helpers.getPreferredLineEnding(input);
t.is(actual, expected, "Incorrect line ending returned."); t.is(actual, expected, "Incorrect line ending returned.");
}); });
t.is(
helpers.getPreferredLineEnding("", "linux"),
"\n",
"Incorrect line ending for linux"
);
t.is(
helpers.getPreferredLineEnding("", "win32"),
"\r\n",
"Incorrect line ending for win32"
);
}); });
test("applyFix", (t) => { test("applyFix", (t) => {