Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate chalk.constructor() in favor of new chalk.Instance() #322

Merged
merged 10 commits into from
Mar 12, 2019
Prev Previous commit
Next Next commit
Fix code style. Only new-cap linting errors remain
  • Loading branch information
tom-sherman committed Jan 27, 2019
commit cf981e6c4415291cae9134877949ce27d3e20123
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ function chalkFactory(options) {
Object.setPrototypeOf(chalk, Chalk.prototype);
Object.setPrototypeOf(chalk.template, chalk);

chalk.template.constructor = () => {throw new Error('Chalk.constructor() is deprecated. Use new Chalk.instance() instead.')};
chalk.template.constructor = () => {
throw new Error('Chalk.constructor() is deprecated. Use new Chalk.instance() instead.');
};
chalk.template.instance = ChalkClass;

return chalk.template;
Expand Down
14 changes: 7 additions & 7 deletions test/constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ import test from 'ava';
const chalk = require('..');

test('Chalk.constructor should throw an expected error', t => {
const expectedError = t.throws(() => {
chalk.constructor();
});
const expectedError = t.throws(() => {
chalk.constructor();
});

t.is(expectedError.message, 'Chalk.constructor() is deprecated. Use new Chalk.instance() instead.');
t.is(expectedError.message, 'Chalk.constructor() is deprecated. Use new Chalk.instance() instead.');

t.throws(() => {
new chalk.constructor();
});
t.throws(() => {
new chalk.constructor(); // eslint-disable-line no-new
});
});