refactoring

This commit is contained in:
Denis Pushkarev
2026-04-26 17:27:12 +07:00
parent 2e54cf995e
commit bab441b962
5 changed files with 18 additions and 17 deletions
+7 -2
View File
@@ -2,11 +2,16 @@ import { minify } from 'terser';
import builder from 'core-js-builder';
import config from 'core-js-builder/config.js';
function namedArg(name, fallback) {
const idx = argv._.indexOf(name);
return idx === -1 ? fallback : argv._[idx + 1];
}
const { cyan, green } = chalk;
const DENO = argv._.includes('deno');
const ESMODULES = argv._.includes('esmodules');
const BUNDLED_NAME = argv._.includes('bundled-name') ? argv._[argv._.indexOf('bundled-name') + 1] : 'index';
const MINIFIED_NAME = argv._.includes('minified-name') ? argv._[argv._.indexOf('minified-name') + 1] : 'minified';
const BUNDLED_NAME = namedArg('bundled-name', 'index');
const MINIFIED_NAME = namedArg('minified-name', 'minified');
const PATH = DENO ? 'deno/corejs/' : 'packages/core-js-bundle/';
function log(kind, name, code) {
+1 -1
View File
@@ -31,7 +31,7 @@ function modernV8ToChrome(string) {
}
function latest(array) {
return array[array.length - 1];
return array.at(-1);
}
function assert(condition, engine) {
+5 -5
View File
@@ -33,12 +33,12 @@ for (let [patch, downloads] of Object.entries(core)) {
function log(kind, map) {
echo(green(`downloads for 7 days by ${ cyan(kind) } releases:`));
console.table(Object.entries(map).toSorted(([a], [b]) => {
console.table(Object.fromEntries(Object.entries(map).toSorted(([a], [b]) => {
return cmp(coerce(a), '>', coerce(b)) ? 1 : -1;
}).reduce((memo, [version, downloads]) => {
memo[version] = { downloads, '%': `${ (downloads / total * 100).toFixed(2).padStart(5) } %` };
return memo;
}, {}));
}).map(([version, downloads]) => [
version,
{ downloads, '%': `${ (downloads / total * 100).toFixed(2).padStart(5) } %` },
])));
}
log('patch', downloadsByPatch);
+2 -2
View File
@@ -13,14 +13,14 @@ const ignore = new Set([
'tests/unit-bun',
]);
const folders = [''].concat(...await Promise.all([
const folders = ['', ...(await Promise.all([
'packages',
'scripts',
'tests',
].map(async parent => {
const dir = await readdir(parent);
return dir.map(name => `${ parent }/${ name }`);
})));
}))).flat()];
await Promise.all(folders.map(async folder => {
if (!ignore.has(folder)) try {
+3 -7
View File
@@ -109,10 +109,7 @@ let fileMetadata = {};
function metadata(markdown) {
const { attributes, body } = fm(markdown);
fileMetadata = {};
for (const prop of Object.keys(attributes)) {
fileMetadata[prop] = attributes[prop];
}
fileMetadata = { ...attributes };
return body;
}
@@ -297,8 +294,7 @@ async function build() {
let currentVersion = '';
let versionsMenu = '';
let isChangelog;
for (let i = 0; i < mdFiles.length; i++) {
const mdPath = mdFiles[i];
for (const mdPath of mdFiles) {
const content = await readFile(mdPath, 'utf8');
isDocs = mdPath.includes('/docs');
isChangelog = mdPath.includes('/changelog');
@@ -337,7 +333,7 @@ async function build() {
anchor.innerHTML = '<svg viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path d="m7.775 3.275 1.25-1.25a3.5 3.5 0 1 1 4.95 4.95l-2.5 2.5a3.5 3.5 0 0 1-4.95 0 .751.751 0 0 1 .018-1.042.751.751 0 0 1 1.042-.018 1.998 1.998 0 0 0 2.83 0l2.5-2.5a2.002 2.002 0 0 0-2.83-2.83l-1.25 1.25a.751.751 0 0 1-1.042-.018.751.751 0 0 1-.018-1.042Zm-4.69 9.64a1.998 1.998 0 0 0 2.83 0l1.25-1.25a.751.751 0 0 1 1.042.018.751.751 0 0 1 .018 1.042l-1.25 1.25a3.5 3.5 0 1 1-4.95-4.95l2.5-2.5a3.5 3.5 0 0 1 4.95 0 .751.751 0 0 1-.018 1.042.751.751 0 0 1-1.042.018 1.998 1.998 0 0 0-2.83 0l-2.5 2.5a1.998 1.998 0 0 0 0 2.83Z"></path></svg>';
newHeading.append(anchor);
newHeading.classList.add('with-anchor');
resultHtml = resultHtml.split(heading.outerHTML).join(newHeading.outerHTML);
resultHtml = resultHtml.replaceAll(heading.outerHTML, newHeading.outerHTML);
});
}