Skip to content

Commit

Permalink
refactor: replace chalk with picocolors
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperchupuDev authored Oct 14, 2024
1 parent 18ed3cf commit dcd140e
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 33 deletions.
48 changes: 22 additions & 26 deletions lib/help.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import chalk from 'chalk';
import { pc } from './colors';

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (16.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (16.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (16.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 1 in lib/help.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.

export default function help() {
// eslint-disable-next-line no-console
console.log(`
${chalk.bold('pkg')} [options] <input>
${pc.bold('pkg')} [options] <input>
${chalk.dim('Options:')}
${pc.dim('Options:')}
-h, --help output usage information
-v, --version output pkg version
Expand All @@ -23,29 +23,25 @@ export default function help() {
--no-dict comma-separated list of packages names to ignore dictionaries. Use --no-dict * to disable all dictionaries
-C, --compress [default=None] compression algorithm = Brotli or GZip
${chalk.dim('Examples:')}
${pc.dim('Examples:')}
${chalk.gray('–')} Makes executables for Linux, macOS and Windows
${chalk.cyan('$ pkg index.js')}
${chalk.gray('–')} Takes package.json from cwd and follows 'bin' entry
${chalk.cyan('$ pkg .')}
${chalk.gray('–')} Makes executable for particular target machine
${chalk.cyan('$ pkg -t node14-win-arm64 index.js')}
${chalk.gray('–')} Makes executables for target machines of your choice
${chalk.cyan('$ pkg -t node16-linux,node18-linux,node18-win index.js')}
${chalk.gray(
'–',
)} Bakes '--expose-gc' and '--max-heap-size=34' into executable
${chalk.cyan('$ pkg --options "expose-gc,max-heap-size=34" index.js')}
${chalk.gray('–')} Consider packageA and packageB to be public
${chalk.cyan('$ pkg --public-packages "packageA,packageB" index.js')}
${chalk.gray('–')} Consider all packages to be public
${chalk.cyan('$ pkg --public-packages "*" index.js')}
${chalk.gray('–')} Bakes '--expose-gc' into executable
${chalk.cyan('$ pkg --options expose-gc index.js')}
${chalk.gray(
'–',
)} reduce size of the data packed inside the executable with GZip
${chalk.cyan('$ pkg --compress GZip index.js')}
${pc.gray('–')} Makes executables for Linux, macOS and Windows
${pc.cyan('$ pkg index.js')}
${pc.gray('–')} Takes package.json from cwd and follows 'bin' entry
${pc.cyan('$ pkg .')}
${pc.gray('–')} Makes executable for particular target machine
${pc.cyan('$ pkg -t node14-win-arm64 index.js')}
${pc.gray('–')} Makes executables for target machines of your choice
${pc.cyan('$ pkg -t node16-linux,node18-linux,node18-win index.js')}
${pc.gray('–')} Bakes '--expose-gc' and '--max-heap-size=34' into executable
${pc.cyan('$ pkg --options "expose-gc,max-heap-size=34" index.js')}
${pc.gray('–')} Consider packageA and packageB to be public
${pc.cyan('$ pkg --public-packages "packageA,packageB" index.js')}
${pc.gray('–')} Consider all packages to be public
${pc.cyan('$ pkg --public-packages "*" index.js')}
${pc.gray('–')} Bakes '--expose-gc' into executable
${pc.cyan('$ pkg --options expose-gc index.js')}
${pc.gray('–')} reduce size of the data packed inside the executable with GZip
${pc.cyan('$ pkg --compress GZip index.js')}
`);
}
4 changes: 2 additions & 2 deletions lib/refiner.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import path from 'path';
import chalk from 'chalk';
import { pc } from './colors';

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (16.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (16.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (16.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 2 in lib/refiner.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.
import {
STORE_LINKS,
retrieveDenominator,
Expand Down Expand Up @@ -43,7 +43,7 @@ function purgeTopDirectories(records: FileRecords) {

if (links3) {
delete records[file];
log.debug(chalk.cyan('Deleting record file :', file));
log.debug(pc.cyan(`Deleting record file: ${file}`));
found = true;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
toNormalizedRealPath,
} from './common';

import { pc } from './colors';

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (16.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (16.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (16.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (18.x, ubuntu-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (18.x, windows-latest)

Cannot find module './colors' or its corresponding type declarations.

Check failure on line 26 in lib/walker.ts

View workflow job for this annotation

GitHub Actions / test (18.x, macos-latest)

Cannot find module './colors' or its corresponding type declarations.
import { follow } from './follow';
import { log, wasReported } from './log';
import * as detector from './detector';
Expand Down Expand Up @@ -818,7 +819,7 @@ class Walker {
`%2: ${record.file}`,
]);
} else {
log[level](`${chalk.yellow(failure.message)} in ${record.file}`);
log[level](`${pc.yellow(failure.message)} in ${record.file}`);
}

return;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
"@babel/parser": "7.23.0",
"@babel/types": "7.23.0",
"@yao-pkg/pkg-fetch": "3.5.13",
"chalk": "^4.1.2",
"fs-extra": "^9.1.0",
"globby": "^11.1.0",
"into-stream": "^6.0.0",
"minimatch": "9.0.4",
"minimist": "^1.2.6",
"multistream": "^4.1.0",
"picocolors": "^1.1.0",
"prebuild-install": "7.1.1",
"resolve": "^1.22.0",
"stream-meter": "^1.0.4"
Expand Down
6 changes: 3 additions & 3 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

'use strict';

const chalk = require('chalk');
const globby = require('globby');
const path = require('path');
const pc = require('picocolors');
const utils = require('./utils.js');
const host = 'node' + process.version.match(/^v(\d+)/)[1];
let target = process.argv[2] || 'host';
Expand Down Expand Up @@ -73,8 +73,8 @@ files.sort().some(function (file) {
});
} catch (error) {
console.log();
console.log(`> ${chalk.red('Error!')} ${error.message}`);
console.log(`> ${chalk.red('Error!')} ${file} FAILED (in ${target})`);
console.log(`> ${pc.red('Error!')} ${error.message}`);
console.log(`> ${pc.red('Error!')} ${file} FAILED (in ${target})`);
process.exit(2);
}
console.log(file, 'ok');
Expand Down
4 changes: 4 additions & 0 deletions test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ module.exports.pkg.sync = function (args, opts) {
args.unshift(binPath);
assert(es5, 'RUN BABEL FIRST!'); // args.unshift('-r', 'babel-register');
if (Array.isArray(opts)) opts = { stdio: opts };
// spawn uses process.env if no opts.env is provided, we need to manually add it if set
if (!opts) opts = { env: { NO_COLOR: '1', ...process.env } };
else if (!opts.env || !opts.env.NO_COLOR)
opts.env = { NO_COLOR: '1', ...process.env, ...opts.env };
try {
const ss = module.exports.spawn.sync;
return ss('node', args, opts);
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3751,6 +3751,11 @@ picocolors@^1.0.0, picocolors@^1.0.1:
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.1.tgz#a8ad579b571952f0e5d25892de5445bcfe25aaa1"
integrity sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==

picocolors@^1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.1.0.tgz#5358b76a78cde483ba5cef6a9dc9671440b27d59"
integrity sha512-TQ92mBOW0l3LeMeyLV6mzy/kWr8lkd/hp3mTg7wYK7zJhuBStmGMBG0BdeDZS/dZx1IukaX6Bk11zcln25o1Aw==

picomatch@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
Expand Down

0 comments on commit dcd140e

Please sign in to comment.