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

Migrate to colorette 2.0.x #2956

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@typescript-eslint/parser": "^4.14.1",
"@webpack-cli/migrate": "^1.1.2",
"coffeescript": "^2.5.1",
"colorette": "^1.2.1",
"colorette": "^2.0.2",
"concat-stream": "^2.0.0",
"cz-customizable": "^6.3.0",
"del-cli": "^3.0.1",
Expand Down
2 changes: 1 addition & 1 deletion packages/generators/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"plugin-template"
],
"dependencies": {
"colorette": "^1.2.1",
"colorette": "^2.0.2",
"yeoman-environment": "^2.10.3",
"yeoman-generator": "^4.12.0"
},
Expand Down
4 changes: 3 additions & 1 deletion packages/generators/src/init-generator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { blue, yellow } from "colorette";
import { createColors } from "colorette";
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
import path from "path";

Expand All @@ -7,6 +7,8 @@ import { getInstaller, getTemplate } from "./utils/helpers";
import * as Question from "./utils/scaffold-utils";
import handlers from "./handlers";

const { blue, yellow } = createColors();

/**
*
* Generator for initializing a webpack config
Expand Down
18 changes: 17 additions & 1 deletion packages/webpack-cli/lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
let colorette = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid recreating colorette instance on every getter call. We could simply import default colouring operations, but these would default to always on and ignore configuration overrides.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We decided to classify the always-color behavior as a bug after all (jorgebucaran/colorette#72). If you don't really care about the new createColors API, you may continue using Colorette as you were before, just upgrade to 2.0.5 or later.


module.exports = {

get colors() {
return require("colorette");
if (!colorette || colorette.options.changed) {
const col = require('colorette');
const options = {
changed: false,
enabled: colorette? colorette.options.enabled : true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems some weird, colorette already has logic for enabled, why we need check colorette?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See existing code at

cli.utils.colors.options.changed = true;

From my understanding this is an existing solution to trigger changes in the behaviour of instance, returned by getter. Alternatively, we can expose a method that would instantly recreate instance, stored here, to avoid this.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should rewrite logic, because we already cache module, we can keep changed on object level

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

caching module is not enough, we need to store initialized coloretto instance as well

}

colorette = {
...col.createColors({ useColor: options.enabled }),
options,
}
}

return colorette;
},

get levenshtein() {
Expand Down
2 changes: 1 addition & 1 deletion packages/webpack-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@webpack-cli/configtest": "^1.0.4",
"@webpack-cli/info": "^1.3.0",
"@webpack-cli/serve": "^1.5.2",
"colorette": "^1.2.1",
"colorette": "^2.0.2",
"commander": "^7.0.0",
"execa": "^5.0.0",
"fastest-levenshtein": "^1.0.12",
Expand Down
3 changes: 2 additions & 1 deletion scripts/prepareSuite.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// eslint-disable-next-line node/no-unpublished-require
const execa = require("execa");
// eslint-disable-next-line node/no-unpublished-require
const { red, green } = require("colorette");
const { createColors } = require("colorette");
const collectTestFolders = require("./utils");

const { red, green } = createColors();
const PACKAGE = "package.json";

const getFoldersWithPackage = (stats, file) => {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3361,6 +3361,11 @@ colorette@^1.2.1, colorette@^1.2.2:
resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.4.0.tgz#5190fbb87276259a86ad700bff2c6d6faa3fca40"
integrity sha512-Y2oEozpomLn7Q3HFP7dpww7AtMJplbM9lGZP6RDfHqmbeRjiwRg4n6VM6j4KLmRke85uWEI7JqF17f3pqdRA0g==

colorette@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/colorette/-/colorette-2.0.2.tgz#f04cbc7f59ffc4f33ba4da0702dd4c8a68885d91"
integrity sha512-iO5Ycn8HKVhTGGKpwJtyzrrvOGI9YC4u4dppP5yKSGP47ApaZNwX7ne4PtgpTzq+JBwQh6FrdAfCSYTBQe1+FA==

colors@1.0.3:
version "1.0.3"
resolved "https://registry.yarnpkg.com/colors/-/colors-1.0.3.tgz#0433f44d809680fdeb60ed260f1b0c262e82a40b"
Expand Down