Skip to content

Commit

Permalink
update zx
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed Jun 14, 2022
1 parent 83e5a92 commit 18fdb83
Show file tree
Hide file tree
Showing 21 changed files with 61 additions and 51 deletions.
16 changes: 13 additions & 3 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,11 @@ const base = {
// restrict what can be thrown as an exception
'no-throw-literal': ERROR,
// disallow usage of expressions in statement position
'no-unused-expressions': [ERROR, { allowShortCircuit: true, allowTernary: true }],
'no-unused-expressions': [ERROR, {
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true,
}],
// disallow unused labels
'no-unused-labels': ERROR,
// disallow unnecessary catch clauses
Expand Down Expand Up @@ -1241,17 +1245,23 @@ module.exports = {
argv: READONLY,
cd: READONLY,
chalk: READONLY,
echo: READONLY,
fetch: READONLY,
fs: READONLY,
globby: READONLY,
glob: READONLY,
nothrow: READONLY,
os: READONLY,
path: READONLY,
question: READONLY,
require: READONLY,
sleep: READONLY,
stdin: READONLY,
which: READONLY,
within: READONLY,
YAML: READONLY,
},
rules: {
// disallow use of console
// allow use of console
'no-console': OFF,
},
},
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"test262-harness": "^10.0.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"zx": "^6.2.5"
"zx": "^7.0.0"
},
"license": "MIT",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build-compat-data.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,4 @@ await Promise.all([
}`),
]);

console.log(chalk.green('compat data rebuilt'));
echo(chalk.green('compat data rebuilt'));
4 changes: 2 additions & 2 deletions scripts/build-compat-entries.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function getModulesForEntryPoint(path, parent) {
return helpers.intersection(result.flat(1), modules);
}

const entriesList = await globby([
const entriesList = await glob([
'packages/core-js/index.js',
'packages/core-js/actual/**/*.js',
'packages/core-js/es/**/*.js',
Expand All @@ -41,4 +41,4 @@ const entriesMap = helpers.sortObjectByKey(Object.fromEntries(await Promise.all(

await fs.writeJson('packages/core-js-compat/entries.json', entriesMap, { spaces: ' ' });

console.log(chalk.green('entries data rebuilt'));
echo(chalk.green('entries data rebuilt'));
2 changes: 1 addition & 1 deletion scripts/build-compat-modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ fs.writeJson('packages/core-js-compat/modules-by-versions.json', {
...modulesByVersions,
}, { spaces: ' ' });

console.log(chalk.green('modules-by-versions data rebuilt'));
echo(chalk.green('modules-by-versions data rebuilt'));
2 changes: 1 addition & 1 deletion scripts/bundle.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const PATH = DENO ? 'deno/corejs/' : 'packages/core-js-bundle/';

function log(kind, name, code) {
const size = (code.length / 1024).toFixed(2);
console.log(chalk.green(`${ kind }: ${ chalk.cyan(`${ PATH }${ name }.js`) }, size: ${ chalk.cyan(`${ size }KB`) }`));
echo(chalk.green(`${ kind }: ${ chalk.cyan(`${ PATH }${ name }.js`) }, size: ${ chalk.cyan(`${ size }KB`) }`));
}

async function bundle({ bundled, minified, options = {} }) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/check-compat-data-mapping.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function latest(array) {
function assert(condition, engine) {
if (!condition) {
updated = false;
console.log(chalk.red(`${ chalk.cyan(engine) } mapping should be updated`));
echo(chalk.red(`${ chalk.cyan(engine) } mapping should be updated`));
}
}

Expand Down Expand Up @@ -62,4 +62,4 @@ assert(operaMobile.engine <= latest(mapping.ChromeToOperaMobile)[0], 'Opera Mobi
assert(cmp(coerce(ios.version), '<=', coerce(latest(mapping.SafariToIOS)[1])), 'iOS Safari');
assert(samsung.engine <= latest(mapping.ChromeToSamsung)[0], 'Samsung Internet');

if (updated) console.log(chalk.green('updates of compat data mapping not required'));
if (updated) echo(chalk.green('updates of compat data mapping not required'));
6 changes: 3 additions & 3 deletions scripts/check-compat-data-modules-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ if (minor || patch) { // ignore for pre-releases
for (const mod of modulesByVersions[zero]) {
if (!set.has(mod)) {
ok = false;
console.log(chalk.red(`${ chalk.cyan(mod) } should be added to modules-by-versions`));
echo(chalk.red(`${ chalk.cyan(mod) } should be added to modules-by-versions`));
}
}
}

if (!ok) throw console.log(chalk.red('\nmodules-by-versions should be updated'));
console.log(chalk.green('modules-by-versions checked'));
if (!ok) throw echo(chalk.red('\nmodules-by-versions should be updated'));
echo(chalk.green('modules-by-versions checked'));
8 changes: 4 additions & 4 deletions scripts/check-compat-tests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ const ignore = new Set([
const missed = modules.filter(it => !(tested.has(it) || tested.has(it.replace(/^esnext\./, 'es.')) || ignore.has(it)));

for (const it of tested) {
if (!modulesSet.has(it)) console.log(chalk.red(`added extra compat data test: ${ chalk.cyan(it) }`));
if (!modulesSet.has(it)) echo(chalk.red(`added extra compat data test: ${ chalk.cyan(it) }`));
}

if (missed.length) {
console.log(chalk.red('some of compat data tests missed:'));
for (const it of missed) console.log(chalk.cyan(it));
} else console.log(chalk.green('adding of compat data tests not required'));
echo(chalk.red('some of compat data tests missed:'));
for (const it of missed) echo(chalk.cyan(it));
} else echo(chalk.green('adding of compat data tests not required'));
6 changes: 3 additions & 3 deletions scripts/check-dependencies.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const ignoreInPackages = new Set([
'webpack',
]);

await Promise.all((await globby(['package.json', 'packages/*/package.json'])).map(async path => {
await Promise.all((await glob(['package.json', 'packages/*/package.json'])).map(async path => {
const pkg = JSON.parse(await fs.readFile(path));
const dependencies = await getDependencies(pkg);
const devDependencies = await getDependencies(pkg, { dev: true });
Expand All @@ -33,9 +33,9 @@ await Promise.all((await globby(['package.json', 'packages/*/package.json'])).ma
}
}
if (Object.keys(dependencies).length) {
console.log(chalk.cyan(`${ pkg.name ?? 'root' }:`));
echo(chalk.cyan(`${ pkg.name ?? 'root' }:`));
console.table(dependencies);
}
}));

console.log(chalk.green('dependencies checked'));
echo(chalk.green('dependencies checked'));
10 changes: 5 additions & 5 deletions scripts/check-unused-modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ async function jsModulesFrom(path) {

function log(set, kind) {
if (set.size) {
console.log(chalk.red(`found some unused ${ kind }:`));
set.forEach(it => console.log(chalk.cyan(it)));
} else console.log(chalk.green(`unused ${ kind } not found`));
echo(chalk.red(`found some unused ${ kind }:`));
set.forEach(it => echo(chalk.cyan(it)));
} else echo(chalk.green(`unused ${ kind } not found`));
}

const globalModules = await jsModulesFrom('packages/core-js/modules');
Expand All @@ -25,7 +25,7 @@ globalModules.forEach(it => definedModules.has(it) && globalModules.delete(it));
log(globalModules, 'modules');

const internalModules = await jsModulesFrom('packages/core-js/internals');
const allModules = await globby('packages/core-js?(-pure)/**/*.js');
const allModules = await glob('packages/core-js?(-pure)/**/*.js');

await Promise.all(allModules.map(async path => {
for (const dependency of konan(String(await fs.readFile(path))).strings) {
Expand All @@ -35,7 +35,7 @@ await Promise.all(allModules.map(async path => {

log(internalModules, 'internal modules');

const pureModules = new Set(await globby('packages/core-js-pure/override/**/*.js'));
const pureModules = new Set(await glob('packages/core-js-pure/override/**/*.js'));

await Promise.all([...pureModules].map(async path => {
if (await fs.pathExists(path.replace('-pure/override', ''))) pureModules.delete(path);
Expand Down
12 changes: 6 additions & 6 deletions scripts/clean-and-copy.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ function options(overwrite) {
};
}

await Promise.all((await globby([
await Promise.all((await glob([
'tests/bundles/*',
// TODO: drop it from `core-js@4`
'packages/core-js/features',
'packages/core-js-pure/!(override|.npmignore|package.json|README.md)',
], { onlyFiles: false })).map(path => rm(path, { force: true, recursive: true })));

console.log(chalk.green('old copies removed'));
echo(chalk.green('old copies removed'));

// TODO: drop it from `core-js@4`
const files = await globby('packages/core-js/full/**/*.js');
const files = await glob('packages/core-js/full/**/*.js');

for (const filename of files) {
const newFilename = filename.replace('full', 'features');
Expand All @@ -30,13 +30,13 @@ for (const filename of files) {
await writeFile(newFilename, `module.exports = require('${ href }');\n`);
}

console.log(chalk.green('created /features/ entries'));
echo(chalk.green('created /features/ entries'));

await copy('packages/core-js', 'packages/core-js-pure', options(false));

const license = [
'deno/corejs/LICENSE',
...(await globby('packages/*/package.json')).map(path => path.replace(/package\.json$/, 'LICENSE')),
...(await glob('packages/*/package.json')).map(path => path.replace(/package\.json$/, 'LICENSE')),
];

await Promise.all([
Expand All @@ -45,4 +45,4 @@ await Promise.all([
...license.map(path => copy('LICENSE', path, options(true))),
]);

console.log(chalk.green(`copied ${ chalk.cyan(copied) } files`));
echo(chalk.green(`copied ${ chalk.cyan(copied) } files`));
2 changes: 1 addition & 1 deletion scripts/downloads-by-versions.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ for (let [patch, downloads] of Object.entries(core)) {
}

function log(kind, map) {
console.log(green(`downloads for 7 days by ${ cyan(kind) } releases:`));
echo(green(`downloads for 7 days by ${ cyan(kind) } releases:`));
console.table(Object.keys(map).sort().reduce((memo, version) => {
const downloads = map[version];
memo[version] = { downloads, '%': `${ (downloads / total * 100).toFixed(2).padStart(5) } %` };
Expand Down
2 changes: 1 addition & 1 deletion scripts/generate-indexes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ await generateNamespaceIndex('full', /^(?:es|esnext|web)\./);
await generateTestsIndex('tests', 'core-js');
await generateTestsIndex('pure', 'core-js-pure');

console.log(chalk.green('indexes generated'));
echo(chalk.green('indexes generated'));
8 changes: 4 additions & 4 deletions scripts/update-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const builderConfig = await readFile(BUILDER_CONFIG, 'utf8');
await writeFile(BUILDER_CONFIG, builderConfig.replaceAll(OLD_YEAR, CURRENT_YEAR));

const packages = await readdir('packages');
for (const PATH of await globby('packages/*/package.json')) {
for (const PATH of await glob('packages/*/package.json')) {
const pkg = await readJson(PATH, 'utf8');
pkg.version = NEW_VERSION;
for (const field of ['dependencies', 'devDependencies']) {
Expand All @@ -56,6 +56,6 @@ if (NEW_VERSION !== PREV_VERSION) {
})`));
}

if (CURRENT_YEAR !== OLD_YEAR) console.log(chalk.green('the year updated'));
if (NEW_VERSION !== PREV_VERSION) console.log(chalk.green('the version updated'));
else if (CURRENT_YEAR === OLD_YEAR) console.log(chalk.red('bump is not required'));
if (CURRENT_YEAR !== OLD_YEAR) echo(chalk.green('the year updated'));
if (NEW_VERSION !== PREV_VERSION) echo(chalk.green('the version updated'));
else if (CURRENT_YEAR === OLD_YEAR) echo(chalk.red('bump is not required'));
8 changes: 4 additions & 4 deletions scripts/usage.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -55,21 +55,21 @@ await Promise.all(Array(Math.ceil(os.cpus().length / 2)).fill().map(async () =>
tested++;
if (core) withCoreJS++;

console.log(`${ cyan(`${ site }:`) } ${ core
echo`${ cyan(`${ site }:`) } ${ core
? green(`\`core-js\` is detected, ${ versions.length > 1
? `${ cyan(versions.length) } versions: ${ cyan(versions.join(', ')) }`
: `version ${ cyan(versions[0]) }` }`)
: gray('`core-js` is not detected') }`);
: gray('`core-js` is not detected') }`;
} catch {
const attempting = (attempts.get(site) | 0) + 1;
attempts.set(site, attempting);
if (attempting < 3) sites.push(site);
else console.log(red(`${ cyan(`${ site }:`) } problems with access`));
else echo(red(`${ cyan(`${ site }:`) } problems with access`));
await sleep(3e3);
}

return browser?.close();
}));

console.log(green(`\n\`core-js\` is detected on ${ cyan(withCoreJS) } from ${ cyan(tested) } tested websites, ${
echo(green(`\n\`core-js\` is detected on ${ cyan(withCoreJS) } from ${ cyan(tested) } tested websites, ${
cyan(`${ (withCoreJS / tested * 100).toFixed(2) }%`) }, problems with access to ${ cyan(limit - tested) } websites`));
6 changes: 3 additions & 3 deletions tests/commonjs-entries-content.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ subset('core-js/stage/3', /^es\.string\.at|esnext\./);
subset('core-js/stage/4', /^es\.string\.at|esnext\./);

async function unexpectedInnerNamespace(namespace, unexpected) {
const paths = await globby(`packages/core-js/${ namespace }/**/*.js`);
const paths = await glob(`packages/core-js/${ namespace }/**/*.js`);
await Promise.all(paths.map(async path => {
for (const dependency of konan(String(await fs.readFile(path))).strings) {
if (unexpected.test(dependency)) {
console.log(chalk.red(`${ chalk.cyan(path) }: found unexpected dependency: ${ chalk.cyan(dependency) }`));
echo(chalk.red(`${ chalk.cyan(path) }: found unexpected dependency: ${ chalk.cyan(dependency) }`));
}
}
}));
Expand All @@ -155,4 +155,4 @@ await Promise.all([
unexpectedInnerNamespace('full', /\/(?:es|stable)\//),
]);

console.log(chalk.green('entry points content tested'));
echo(chalk.green('entry points content tested'));
6 changes: 3 additions & 3 deletions tests/commonjs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,9 @@ for (const NS of ['full', 'features']) {

load('modules/esnext.string.at-alternative');

console.log(chalk.green(`tested ${ chalk.cyan(tested.size) } commonjs entry points`));
echo(chalk.green(`tested ${ chalk.cyan(tested.size) } commonjs entry points`));

if (expected.size) {
console.log(chalk.red('not tested entries:'));
expected.forEach(it => console.log(chalk.cyan(it)));
echo(chalk.red('not tested entries:'));
expected.forEach(it => echo(chalk.cyan(it)));
}
2 changes: 1 addition & 1 deletion tests/compat-tools/compat.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,4 @@ deepStrictEqual(compat({
},
}, 'some targets');

console.log(chalk.green('compat tool tested'));
echo(chalk.green('compat tool tested'));
2 changes: 1 addition & 1 deletion tests/compat-tools/get-modules-list-for-target-version.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ throws(() => getModulesListForTargetVersion('x'), TypeError, 'x');
throws(() => getModulesListForTargetVersion('*'), TypeError, '*');
throws(() => getModulesListForTargetVersion(), TypeError, 'no arg');

console.log(chalk.green('get-modules-list-for-target-version tested'));
echo(chalk.green('get-modules-list-for-target-version tested'));
2 changes: 1 addition & 1 deletion tests/compat-tools/targets-parser.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ deepStrictEqual(targetsParser({
['samsung', '4'],
]), 'mixed');

console.log(chalk.green('targets parser tested'));
echo(chalk.green('targets parser tested'));

0 comments on commit 18fdb83

Please sign in to comment.