Skip to content

Commit

Permalink
feat(scripts): replace chalk with picocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
ishon19 committed Aug 5, 2024
1 parent daf6648 commit 47542f6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 37 deletions.
4 changes: 2 additions & 2 deletions scripts/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import {strict as assert} from 'assert';
import {createRequire} from 'module';
import * as path from 'path';
import util from 'util';
import chalk from 'chalk';
import dedent from 'dedent';
import fs from 'graceful-fs';
import pico from 'picocolors';
import webpack from 'webpack';
import {
ERROR,
Expand All @@ -24,7 +24,7 @@ import {
const require = createRequire(import.meta.url);

async function buildNodePackages() {
process.stdout.write(chalk.inverse(' Bundling packages \n'));
process.stdout.write(pico.inverse(' Bundling packages \n'));

const buildConfigs = createBuildConfigs();

Expand Down
28 changes: 16 additions & 12 deletions scripts/buildTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
import {strict as assert} from 'assert';
import * as os from 'os';
import * as path from 'path';
import chalk from 'chalk';
import execa from 'execa';
import {glob} from 'glob';
import fs from 'graceful-fs';
import pLimit from 'p-limit';
import pico from 'picocolors';
import stripJsonComments from 'strip-json-comments';
import {getPackagesWithTsConfig} from './buildUtils.mjs';

Expand Down Expand Up @@ -102,7 +102,7 @@ for (const {packageDir, pkg} of packagesWithTs) {

if (hasJestTestUtils) {
throw new Error(
chalk.red(
pico.red(
`Package '${pkg.name}' declares '@jest/test-utils' as dependency, but it must be declared as dev dependency`,
),
);
Expand All @@ -129,7 +129,7 @@ for (const {packageDir, pkg} of packagesWithTs) {

if (hasJestTestUtils && testUtilsReferences.length === 0) {
throw new Error(
chalk.red(
pico.red(
`Package '${
pkg.name
}' declares '@jest/test-utils' as dev dependency, but it is not referenced in:\n\n${tsConfigPaths.join(
Expand All @@ -141,7 +141,7 @@ for (const {packageDir, pkg} of packagesWithTs) {

if (!hasJestTestUtils && testUtilsReferences.length > 0) {
throw new Error(
chalk.red(
pico.red(
`Package '${
pkg.name
}' does not declare '@jest/test-utils' as dev dependency, but it is referenced in:\n\n${testUtilsReferences.join(
Expand All @@ -159,21 +159,23 @@ const args = [
...process.argv.slice(2),
];

console.log(chalk.inverse(' Building TypeScript definition files '));
console.log(pico.inverse(' Building TypeScript definition files '));

try {
await execa('yarn', args, {stdio: 'inherit'});
console.log(
chalk.inverse.green(' Successfully built TypeScript definition files '),
pico.inverse(
pico.green(' Successfully built TypeScript definition files '),
),
);
} catch (error) {
console.error(
chalk.inverse.red(' Unable to build TypeScript definition files '),
pico.inverse(pico.red(' Unable to build TypeScript definition files ')),
);
throw error;
}

console.log(chalk.inverse(' Validating TypeScript definition files '));
console.log(pico.inverse(' Validating TypeScript definition files '));

// we want to limit the number of processes we spawn
const cpus = Math.max(
Expand Down Expand Up @@ -219,8 +221,8 @@ try {
.filter(([, content]) => content.length > 0)
.filter(hit => hit.length > 0)
.map(([file, references]) =>
chalk.red(
`${chalk.bold(
pico.red(
`${pico.bold(
file,
)} has the following non-node type references:\n\n${references}\n`,
),
Expand Down Expand Up @@ -251,12 +253,14 @@ try {
);
} catch (error) {
console.error(
chalk.inverse.red(' Unable to validate TypeScript definition files '),
pico.inverse(pico.red(' Unable to validate TypeScript definition files ')),
);

throw error;
}

console.log(
chalk.inverse.green(' Successfully validated TypeScript definition files '),
pico.inverse(
pico.green(' Successfully validated TypeScript definition files '),
),
);
6 changes: 3 additions & 3 deletions scripts/buildUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {strict as assert} from 'assert';
import {createRequire} from 'module';
import * as path from 'path';
import {fileURLToPath} from 'url';
import chalk from 'chalk';
import fs from 'graceful-fs';
import pico from 'picocolors';
import {sync as readPkg} from 'read-pkg';
import webpack from 'webpack';
import nodeExternals from 'webpack-node-externals';
Expand All @@ -22,8 +22,8 @@ export const PACKAGES_DIR = path.resolve(
);
const require = createRequire(import.meta.url);

export const OK = chalk.reset.inverse.bold.green(' DONE ');
export const ERROR = chalk.reset.inverse.bold.red(' BOOM ');
export const OK = pico.reset(pico.inverse(pico.bold(pico.green(' DONE '))));
export const ERROR = pico.reset(pico.inverse(pico.bold(pico.red(' BOOM '))));

export const typeOnlyPackages = new Set([
'babel-preset-jest',
Expand Down
13 changes: 8 additions & 5 deletions scripts/bundleTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import {
Extractor,
ExtractorConfig,
} from '@microsoft/api-extractor';
import chalk from 'chalk';
import {ESLint} from 'eslint';
import {glob} from 'glob';
import fs from 'graceful-fs';
import pico from 'picocolors';
import pkgDir from 'pkg-dir';
import {rimraf} from 'rimraf';
import {copyrightSnippet, getPackagesWithTsConfig} from './buildUtils.mjs';
Expand All @@ -32,7 +32,7 @@ const packagesToBundle = getPackagesWithTsConfig().filter(
p => !excludedPackages.has(p.pkg.name),
);

console.log(chalk.inverse(' Extracting TypeScript definition files '));
console.log(pico.inverse(' Extracting TypeScript definition files '));

const sharedExtractorConfig = {
$schema:
Expand Down Expand Up @@ -118,7 +118,6 @@ let compilerState;
await Promise.all(
packagesToBundle.map(async ({packageDir, pkg}) => {
const configFile = path.resolve(packageDir, 'api-extractor.json');

await fs.promises.writeFile(
configFile,
JSON.stringify(
Expand Down Expand Up @@ -151,7 +150,9 @@ await Promise.all(

if (!extractorResult.succeeded || extractorResult.warningCount > 0) {
console.error(
chalk.inverse.red(' Unable to extract TypeScript definition files '),
pico.inverse(
pico.red(' Unable to extract TypeScript definition files '),
),
);
throw new Error(
`API Extractor completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings`,
Expand Down Expand Up @@ -232,5 +233,7 @@ await Promise.all(
);

console.log(
chalk.inverse.green(' Successfully extracted TypeScript definition files '),
pico.inverse(
pico.green(' Successfully extracted TypeScript definition files '),
),
);
10 changes: 6 additions & 4 deletions scripts/lintTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
import * as os from 'os';
import * as path from 'path';
import * as url from 'url';
import chalk from 'chalk';
import {ESLint} from 'eslint';
import pLimit from 'p-limit';
import pico from 'picocolors';
import {getPackagesWithTsConfig} from './buildUtils.mjs';

// we want to limit the number of processes we spawn
Expand Down Expand Up @@ -178,7 +178,7 @@ try {
);
} catch (error) {
console.error(
chalk.inverse.red(' Unable to lint using TypeScript info files '),
pico.inverse(pico.red(' Unable to lint using TypeScript info files ')),
);

throw error;
Expand All @@ -192,12 +192,14 @@ if (allLintResults.length > 0) {
console.error(resultText);

console.error(
chalk.inverse.red(' Unable to lint using TypeScript info files '),
pico.inverse(pico.red(' Unable to lint using TypeScript info files ')),
);

process.exitCode = 1;
} else {
console.log(
chalk.inverse.green(' Successfully linted using TypeScript info files '),
pico.inverse(
pico.green(' Successfully linted using TypeScript info files '),
),
);
}
10 changes: 5 additions & 5 deletions scripts/verifyOldTs.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import {createRequire} from 'module';
import * as path from 'path';
import {fileURLToPath} from 'url';
import chalk from 'chalk';
import execa from 'execa';
import fs from 'graceful-fs';
import pico from 'picocolors';
import stripJsonComments from 'strip-json-comments';
/* eslint-disable import/order */
import tempy from 'tempy';
Expand Down Expand Up @@ -73,15 +73,15 @@ function smoketest() {
execa.sync('yarn', ['tsc', '--project', '.'], {cwd, stdio: 'inherit'});

console.log(
chalk.inverse.green(
` Successfully compiled Jest with TypeScript ${tsVersion} `,
pico.inverse(
pico.green(` Successfully compiled Jest with TypeScript ${tsVersion} `),
),
);
} finally {
fs.rmSync(cwd, {force: true, recursive: true});
}
}

console.log(chalk.inverse(` Running smoketest using TypeScript@${tsVersion} `));
console.log(pico.inverse(` Running smoketest using TypeScript@${tsVersion} `));
smoketest();
console.log(chalk.inverse.green(' Successfully ran smoketest '));
console.log(pico.inverse(pico.green(' Successfully ran smoketest ')));
6 changes: 4 additions & 2 deletions scripts/verifyPnP.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@

import * as path from 'path';
import {fileURLToPath} from 'url';
import chalk from 'chalk';
import dedent from 'dedent';
import execa from 'execa';
import fs from 'graceful-fs';
import yaml from 'js-yaml';
import pico from 'picocolors';
import tempy from 'tempy';

const rootDirectory = path.resolve(
Expand Down Expand Up @@ -75,7 +75,9 @@ try {
});
execa.sync('yarn', ['jest'], {cwd, stdio: 'inherit'});

console.log(chalk.inverse.green(' Successfully ran Jest with PnP linker '));
console.log(
pico.inverse(pico.green(' Successfully ran Jest with PnP linker ')),
);
} finally {
fs.rmSync(cwd, {force: true, recursive: true});
}
8 changes: 4 additions & 4 deletions scripts/watch.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@
* Watch files for changes and rebuild (copy from 'src/' to `build/`) if changed
*/

import chalk from 'chalk';
import pico from 'picocolors';
import webpack from 'webpack';
import {createWebpackConfigs} from './buildUtils.mjs';

const compiler = webpack(createWebpackConfigs());

let hasBuilt = false;

console.log(chalk.inverse(' Bundling packages '));
console.log(pico.inverse(' Bundling packages '));

compiler.watch({}, (error, stats) => {
if (!hasBuilt) {
hasBuilt = true;

console.log(chalk.red('->'), chalk.cyan('Watching for changes…'));
console.log(pico.red('->'), pico.cyan('Watching for changes…'));
}

if (error) {
Expand All @@ -41,7 +41,7 @@ compiler.watch({}, (error, stats) => {
console.warn('warning', warning.message);
}
} else {
console.log(chalk.red('->'), chalk.green('Rebuilt packages'));
console.log(pico.red('->'), pico.green('Rebuilt packages'));
}
}
});

0 comments on commit 47542f6

Please sign in to comment.