Normalize newline characters reading README in scripts (#7292)

This commit is contained in:
Álvaro Mondéjar 2022-03-31 06:30:30 -06:00 committed by GitHub
parent 38cc1af542
commit 44064880b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View File

@ -6,7 +6,7 @@
*/ */
import fakeDiff from 'fake-diff'; import fakeDiff from 'fake-diff';
import { getIconsDataString } from '../utils.js'; import { getIconsDataString, normalizeNewlines } from '../utils.js';
/** /**
* Contains our tests so they can be isolated from each other. * Contains our tests so they can be isolated from each other.
@ -47,7 +47,7 @@ const TESTS = {
/* Check the formatting of the data file */ /* Check the formatting of the data file */
prettified: async (data, dataString) => { prettified: async (data, dataString) => {
const normalizedDataString = dataString.replace(/\r\n/g, '\n'); const normalizedDataString = normalizeNewlines(dataString);
const dataPretty = `${JSON.stringify(data, null, ' ')}\n`; const dataPretty = `${JSON.stringify(data, null, ' ')}\n`;
if (normalizedDataString !== dataPretty) { if (normalizedDataString !== dataPretty) {

View File

@ -118,13 +118,23 @@ export const getIconsData = async () => {
export const getDirnameFromImportMeta = (importMetaUrl) => export const getDirnameFromImportMeta = (importMetaUrl) =>
path.dirname(fileURLToPath(importMetaUrl)); path.dirname(fileURLToPath(importMetaUrl));
/**
* Replace Windows newline characters by Unix ones.
* @param {String} text The text to replace
*/
export const normalizeNewlines = (text) => {
return text.replace(/\r\n/g, '\n');
};
/** /**
* Get information about third party extensions. * Get information about third party extensions.
*/ */
export const getThirdPartyExtensions = async () => { export const getThirdPartyExtensions = async () => {
const __dirname = getDirnameFromImportMeta(import.meta.url); const __dirname = getDirnameFromImportMeta(import.meta.url);
const readmePath = path.resolve(__dirname, '..', 'README.md'); const readmePath = path.resolve(__dirname, '..', 'README.md');
const readmeContent = await fs.readFile(readmePath, 'utf8'); const readmeContent = normalizeNewlines(
await fs.readFile(readmePath, 'utf8'),
);
return readmeContent return readmeContent
.split('## Third-Party Extensions\n\n')[1] .split('## Third-Party Extensions\n\n')[1]
.split('\n\n')[0] .split('\n\n')[0]