Skip to content

Commit

Permalink
Merge pull request #310 from Comandeer/t/304
Browse files Browse the repository at this point in the history
  • Loading branch information
Comandeer authored Jul 29, 2023
2 parents 3aa5ef4 + 409ad32 commit c74a269
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 71 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

---

## [0.23.0]
### Changed
* [#304]: **BREAKING CHANGE**: updated dependencies:

| Dependency | Old version | New version |
| --------------------------- | ----------- | ----------- |
| ⭐ `chalk` | N/A | `^5.3.0` |
| ☠️ `console-control-strings` | `^1.1.0` | N/A |

New dependencies are marked with the "⭐" emoji.

Dependencies with major version change are marked with the "⚠️" emoji.

Removed dependencies are marked with the "☠️" emoji.

## [0.22.1] – 2023-07-28
### Fixed
* [#303]: incorrect package published on GitHub.
Expand Down Expand Up @@ -357,8 +372,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
[#279]: https://github.com/Comandeer/rollup-lib-bundler/issues/279
[#300]: https://github.com/Comandeer/rollup-lib-bundler/issues/300
[#303]: https://github.com/Comandeer/rollup-lib-bundler/issues/303
[#304]: https://github.com/Comandeer/rollup-lib-bundler/issues/304
[#306]: https://github.com/Comandeer/rollup-lib-bundler/issues/306

[0.23.0]: https://github.com/Comandeer/rollup-lib-bundler/compare/v0.22.1...v0.23.0
[0.22.1]: https://github.com/Comandeer/rollup-lib-bundler/compare/v0.22.0...v0.22.1
[0.22.0]: https://github.com/Comandeer/rollup-lib-bundler/compare/v0.21.0...v0.22.0
[0.21.0]: https://github.com/Comandeer/rollup-lib-bundler/compare/v0.20.0...v0.21.0
Expand Down
2 changes: 1 addition & 1 deletion ava.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const config = {
},
// https://github.com/avajs/ava/issues/2947
workerThreads: false,
timeout: '30s',
timeout: '60s',
files: [
'tests/**/*.{js,ts}',
'!tests/**/{__fixtures__,__helpers__}/**'
Expand Down
129 changes: 85 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.2",
"@rollup/plugin-virtual": "^3.0.1",
"chalk": "^5.3.0",
"console-control-strings": "^1.1.0",
"globby": "^13.2.2",
"magic-string": "^0.30.1",
Expand Down
12 changes: 4 additions & 8 deletions src/OutputController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Console } from 'node:console';
import { stdout, stderr } from 'node:process';
import Spinner from '@comandeer/cli-spinner';
import consoleControlStrings from 'console-control-strings';
import chalk from 'chalk';

export type OnWarnCallback = ( warning: string | Warning ) => void;

Expand All @@ -25,10 +25,6 @@ interface Warning {
message?: string;
}

const boldYellow: string = consoleControlStrings.color( [ 'yellow', 'bold' ] );
const boldRed: string = consoleControlStrings.color( [ 'bold', 'red' ] );
const colorReset: string = consoleControlStrings.color( 'reset' );

export default class OutputController {
#console: ConsoleLike;
#spinner: SpinnerLike;
Expand All @@ -40,7 +36,7 @@ export default class OutputController {
warning = warning.message;
}

return `${ boldYellow }⚠️ Warning!⚠️ ${ warning as string }${ colorReset }`;
return chalk.yellow.bold( `⚠️ Warning!⚠️ ${ warning as string }` );
}

static createError( { name, message, stack }: StackableError ): string {
Expand All @@ -50,8 +46,8 @@ export default class OutputController {

const newStack = stackParts.join( '\n' );

return `${ boldRed }🚨Error🚨
${ name }: ${ message }${ colorReset }
return `${ chalk.red.bold( `🚨Error🚨
${ name }: ${ message }` ) }
${ newStack }`;
}

Expand Down
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
import { rimraf } from 'rimraf';
import consoleControlStrings from 'console-control-strings';
import chalk from 'chalk';
import bundler from './bundler.js';
import OutputController from './OutputController.js';
import packageParser from './packageParser.js';
import getDistDirPaths from './utils/getDistDirPaths.js';
import { RollupWarning } from 'rollup';

const boldGreen: string = consoleControlStrings.color( [ 'bold', 'green' ] );
const boldRed: string = consoleControlStrings.color( [ 'bold', 'red' ] );
const colorReset: string = consoleControlStrings.color( 'reset' );

export default async function rlb(): Promise<void> {
const outputController = new OutputController();

Expand All @@ -31,10 +27,10 @@ export default async function rlb(): Promise<void> {
packageInfo
} );

outputController.addLog( `${ boldGreen }Bundling complete!${ colorReset }` );
outputController.addLog( chalk.green.bold( 'Bundling complete!' ) );
} catch ( error ) {
outputController.displayError( error );
outputController.addLog( `${ boldRed }Bundling failed!${ colorReset }` );
outputController.addLog( chalk.red.bold( 'Bundling failed!' ) );
} finally {
await outputController.hideSpinner();
outputController.display();
Expand Down
18 changes: 7 additions & 11 deletions tests/OutputController.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import consoleControlStrings from 'console-control-strings';
import chalk from 'chalk';
import test from 'ava';
import testWithSinonSandbox from './__helpers__/macros/testWithSinonSandbox.js';
import OutputController from '../src/OutputController.js';
import createDummyConsole from './__helpers__/createDummyConsole.js';
import createDummySpinner from './__helpers__/createDummySpinner.js';

const boldYellow: string = consoleControlStrings.color( [ 'yellow', 'bold' ] );
const boldRed: string = consoleControlStrings.color( [ 'bold', 'red' ] );
const colorReset: string = consoleControlStrings.color( 'reset' );

test( 'OutputController is a class', ( t ) => {
t.is( typeof OutputController, 'function' );
} );
Expand Down Expand Up @@ -81,15 +77,15 @@ test( 'OutputController#constructor() allows passing custom spinner object', ( t
} );

test( 'OutputController.createWarning() creates a warning', ( t ) => {
const expected = `${ boldYellow }⚠️ Warning!⚠️ hublabubla${ colorReset }`;
const expected = chalk.yellow.bold( '⚠️ Warning!⚠️ hublabubla' );
const actual = OutputController.createWarning( 'hublabubla' );

t.deepEqual( actual, expected );
} );

test( 'OutputController.createError() creates an error with a stack', ( t ) => {
const expected = `${ boldRed }🚨Error🚨
Error: hublabubla${ colorReset }
const expected = `${ chalk.red.bold( `🚨Error🚨
Error: hublabubla` ) }
2
3`;
const error = new Error( 'hublabubla' );
Expand All @@ -102,8 +98,8 @@ Error: hublabubla${ colorReset }
} );

test( 'OutputController.createError() creates an error without a stack', ( t ) => {
const expected = `${ boldRed }🚨Error🚨
Error: hublabubla${ colorReset }
const expected = `${ chalk.red.bold( `🚨Error🚨
Error: hublabubla` ) }
`;
const error = new Error( 'hublabubla' );

Expand All @@ -116,7 +112,7 @@ Error: hublabubla${ colorReset }

test( 'OutputController#addWarning() uses warning#message property as a warning content', ( t ) => {
const expected = [
`${ boldYellow }⚠️ Warning!⚠️ hublabubla${ colorReset }\n`
chalk.yellow.bold( '⚠️ Warning!⚠️ hublabubla\n' )
];
const warning = {
message: 'hublabubla'
Expand Down

0 comments on commit c74a269

Please sign in to comment.