Skip to content

Commit 47542f6

Browse files
committed
feat(scripts): replace chalk with picocolors
1 parent daf6648 commit 47542f6

File tree

8 files changed

+48
-37
lines changed

8 files changed

+48
-37
lines changed

scripts/build.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import {strict as assert} from 'assert';
99
import {createRequire} from 'module';
1010
import * as path from 'path';
1111
import util from 'util';
12-
import chalk from 'chalk';
1312
import dedent from 'dedent';
1413
import fs from 'graceful-fs';
14+
import pico from 'picocolors';
1515
import webpack from 'webpack';
1616
import {
1717
ERROR,
@@ -24,7 +24,7 @@ import {
2424
const require = createRequire(import.meta.url);
2525

2626
async function buildNodePackages() {
27-
process.stdout.write(chalk.inverse(' Bundling packages \n'));
27+
process.stdout.write(pico.inverse(' Bundling packages \n'));
2828

2929
const buildConfigs = createBuildConfigs();
3030

scripts/buildTs.mjs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
import {strict as assert} from 'assert';
99
import * as os from 'os';
1010
import * as path from 'path';
11-
import chalk from 'chalk';
1211
import execa from 'execa';
1312
import {glob} from 'glob';
1413
import fs from 'graceful-fs';
1514
import pLimit from 'p-limit';
15+
import pico from 'picocolors';
1616
import stripJsonComments from 'strip-json-comments';
1717
import {getPackagesWithTsConfig} from './buildUtils.mjs';
1818

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

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

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

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

162-
console.log(chalk.inverse(' Building TypeScript definition files '));
162+
console.log(pico.inverse(' Building TypeScript definition files '));
163163

164164
try {
165165
await execa('yarn', args, {stdio: 'inherit'});
166166
console.log(
167-
chalk.inverse.green(' Successfully built TypeScript definition files '),
167+
pico.inverse(
168+
pico.green(' Successfully built TypeScript definition files '),
169+
),
168170
);
169171
} catch (error) {
170172
console.error(
171-
chalk.inverse.red(' Unable to build TypeScript definition files '),
173+
pico.inverse(pico.red(' Unable to build TypeScript definition files ')),
172174
);
173175
throw error;
174176
}
175177

176-
console.log(chalk.inverse(' Validating TypeScript definition files '));
178+
console.log(pico.inverse(' Validating TypeScript definition files '));
177179

178180
// we want to limit the number of processes we spawn
179181
const cpus = Math.max(
@@ -219,8 +221,8 @@ try {
219221
.filter(([, content]) => content.length > 0)
220222
.filter(hit => hit.length > 0)
221223
.map(([file, references]) =>
222-
chalk.red(
223-
`${chalk.bold(
224+
pico.red(
225+
`${pico.bold(
224226
file,
225227
)} has the following non-node type references:\n\n${references}\n`,
226228
),
@@ -251,12 +253,14 @@ try {
251253
);
252254
} catch (error) {
253255
console.error(
254-
chalk.inverse.red(' Unable to validate TypeScript definition files '),
256+
pico.inverse(pico.red(' Unable to validate TypeScript definition files ')),
255257
);
256258

257259
throw error;
258260
}
259261

260262
console.log(
261-
chalk.inverse.green(' Successfully validated TypeScript definition files '),
263+
pico.inverse(
264+
pico.green(' Successfully validated TypeScript definition files '),
265+
),
262266
);

scripts/buildUtils.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import {strict as assert} from 'assert';
99
import {createRequire} from 'module';
1010
import * as path from 'path';
1111
import {fileURLToPath} from 'url';
12-
import chalk from 'chalk';
1312
import fs from 'graceful-fs';
13+
import pico from 'picocolors';
1414
import {sync as readPkg} from 'read-pkg';
1515
import webpack from 'webpack';
1616
import nodeExternals from 'webpack-node-externals';
@@ -22,8 +22,8 @@ export const PACKAGES_DIR = path.resolve(
2222
);
2323
const require = createRequire(import.meta.url);
2424

25-
export const OK = chalk.reset.inverse.bold.green(' DONE ');
26-
export const ERROR = chalk.reset.inverse.bold.red(' BOOM ');
25+
export const OK = pico.reset(pico.inverse(pico.bold(pico.green(' DONE '))));
26+
export const ERROR = pico.reset(pico.inverse(pico.bold(pico.red(' BOOM '))));
2727

2828
export const typeOnlyPackages = new Set([
2929
'babel-preset-jest',

scripts/bundleTs.mjs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
Extractor,
1414
ExtractorConfig,
1515
} from '@microsoft/api-extractor';
16-
import chalk from 'chalk';
1716
import {ESLint} from 'eslint';
1817
import {glob} from 'glob';
1918
import fs from 'graceful-fs';
19+
import pico from 'picocolors';
2020
import pkgDir from 'pkg-dir';
2121
import {rimraf} from 'rimraf';
2222
import {copyrightSnippet, getPackagesWithTsConfig} from './buildUtils.mjs';
@@ -32,7 +32,7 @@ const packagesToBundle = getPackagesWithTsConfig().filter(
3232
p => !excludedPackages.has(p.pkg.name),
3333
);
3434

35-
console.log(chalk.inverse(' Extracting TypeScript definition files '));
35+
console.log(pico.inverse(' Extracting TypeScript definition files '));
3636

3737
const sharedExtractorConfig = {
3838
$schema:
@@ -118,7 +118,6 @@ let compilerState;
118118
await Promise.all(
119119
packagesToBundle.map(async ({packageDir, pkg}) => {
120120
const configFile = path.resolve(packageDir, 'api-extractor.json');
121-
122121
await fs.promises.writeFile(
123122
configFile,
124123
JSON.stringify(
@@ -151,7 +150,9 @@ await Promise.all(
151150

152151
if (!extractorResult.succeeded || extractorResult.warningCount > 0) {
153152
console.error(
154-
chalk.inverse.red(' Unable to extract TypeScript definition files '),
153+
pico.inverse(
154+
pico.red(' Unable to extract TypeScript definition files '),
155+
),
155156
);
156157
throw new Error(
157158
`API Extractor completed with ${extractorResult.errorCount} errors and ${extractorResult.warningCount} warnings`,
@@ -232,5 +233,7 @@ await Promise.all(
232233
);
233234

234235
console.log(
235-
chalk.inverse.green(' Successfully extracted TypeScript definition files '),
236+
pico.inverse(
237+
pico.green(' Successfully extracted TypeScript definition files '),
238+
),
236239
);

scripts/lintTs.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
import * as os from 'os';
1111
import * as path from 'path';
1212
import * as url from 'url';
13-
import chalk from 'chalk';
1413
import {ESLint} from 'eslint';
1514
import pLimit from 'p-limit';
15+
import pico from 'picocolors';
1616
import {getPackagesWithTsConfig} from './buildUtils.mjs';
1717

1818
// we want to limit the number of processes we spawn
@@ -178,7 +178,7 @@ try {
178178
);
179179
} catch (error) {
180180
console.error(
181-
chalk.inverse.red(' Unable to lint using TypeScript info files '),
181+
pico.inverse(pico.red(' Unable to lint using TypeScript info files ')),
182182
);
183183

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

194194
console.error(
195-
chalk.inverse.red(' Unable to lint using TypeScript info files '),
195+
pico.inverse(pico.red(' Unable to lint using TypeScript info files ')),
196196
);
197197

198198
process.exitCode = 1;
199199
} else {
200200
console.log(
201-
chalk.inverse.green(' Successfully linted using TypeScript info files '),
201+
pico.inverse(
202+
pico.green(' Successfully linted using TypeScript info files '),
203+
),
202204
);
203205
}

scripts/verifyOldTs.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import {createRequire} from 'module';
99
import * as path from 'path';
1010
import {fileURLToPath} from 'url';
11-
import chalk from 'chalk';
1211
import execa from 'execa';
1312
import fs from 'graceful-fs';
13+
import pico from 'picocolors';
1414
import stripJsonComments from 'strip-json-comments';
1515
/* eslint-disable import/order */
1616
import tempy from 'tempy';
@@ -73,15 +73,15 @@ function smoketest() {
7373
execa.sync('yarn', ['tsc', '--project', '.'], {cwd, stdio: 'inherit'});
7474

7575
console.log(
76-
chalk.inverse.green(
77-
` Successfully compiled Jest with TypeScript ${tsVersion} `,
76+
pico.inverse(
77+
pico.green(` Successfully compiled Jest with TypeScript ${tsVersion} `),
7878
),
7979
);
8080
} finally {
8181
fs.rmSync(cwd, {force: true, recursive: true});
8282
}
8383
}
8484

85-
console.log(chalk.inverse(` Running smoketest using TypeScript@${tsVersion} `));
85+
console.log(pico.inverse(` Running smoketest using TypeScript@${tsVersion} `));
8686
smoketest();
87-
console.log(chalk.inverse.green(' Successfully ran smoketest '));
87+
console.log(pico.inverse(pico.green(' Successfully ran smoketest ')));

scripts/verifyPnP.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77

88
import * as path from 'path';
99
import {fileURLToPath} from 'url';
10-
import chalk from 'chalk';
1110
import dedent from 'dedent';
1211
import execa from 'execa';
1312
import fs from 'graceful-fs';
1413
import yaml from 'js-yaml';
14+
import pico from 'picocolors';
1515
import tempy from 'tempy';
1616

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

78-
console.log(chalk.inverse.green(' Successfully ran Jest with PnP linker '));
78+
console.log(
79+
pico.inverse(pico.green(' Successfully ran Jest with PnP linker ')),
80+
);
7981
} finally {
8082
fs.rmSync(cwd, {force: true, recursive: true});
8183
}

scripts/watch.mjs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
* Watch files for changes and rebuild (copy from 'src/' to `build/`) if changed
1010
*/
1111

12-
import chalk from 'chalk';
12+
import pico from 'picocolors';
1313
import webpack from 'webpack';
1414
import {createWebpackConfigs} from './buildUtils.mjs';
1515

1616
const compiler = webpack(createWebpackConfigs());
1717

1818
let hasBuilt = false;
1919

20-
console.log(chalk.inverse(' Bundling packages '));
20+
console.log(pico.inverse(' Bundling packages '));
2121

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

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

2929
if (error) {
@@ -41,7 +41,7 @@ compiler.watch({}, (error, stats) => {
4141
console.warn('warning', warning.message);
4242
}
4343
} else {
44-
console.log(chalk.red('->'), chalk.green('Rebuilt packages'));
44+
console.log(pico.red('->'), pico.green('Rebuilt packages'));
4545
}
4646
}
4747
});

0 commit comments

Comments
 (0)