-
-
Notifications
You must be signed in to change notification settings - Fork 25
feat(chalk-to-util-styletext): add workflow #256
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
base: main
Are you sure you want to change the base?
feat(chalk-to-util-styletext): add workflow #256
Conversation
|
don't miss to do a For dependency removal I'm asking the Codemod team. because on V0 when the tools was JS only and there was a simple thing to manage dep |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some code style
|
@AugustinMauroy the PR is still a draft, no need to nitpick yet |
😅 oops I'm flash macqueen. Nop kidding just inattentive |
|
@AugustinMauroy I've pushed a few commits which I believe address some of the earlier comments. From the original Github issue, 7/8 test cases are passing. The one test case remaining is the complex chaining example. const styles = level === "error" ? chalk.red.bold : chalk.yellow;const styles =
level === "error"
? (text) => styleText(["red", "bold"], text)
: (text) => styleText("yellow", text);I have a rough idea/implementation locally for this, but it's a bit nasty and I'm not sure I like it. But I'm keen to get feedback on this initial approach and understand if there are possibly better ways of implementing. |
|
I'm going to review your current code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WOW clean. About complex thing I didn't have any idea now I'm getting tired. But you do a great job here.
Missing tests/support about import.
const mychalk = require('chalk');const { red }. = require(-'chalk');maybe hardconst { red; foo }. = require(-"chalk");const foo = await import('chalk');const { red } = await import('chalk')import * as chalk from 'chalk'import { red } from 'chalk';import { red as colorRed 'chalk';
For dependcy par you I'll need custom thing (new step on workflow.yaml):
- step that have JSSG
child_process&fscapacity enabled - function that use FS to detect which package manager it's use (
npm,yarn,pnpm) - new function on package-json utility that removes dep
So jssg step will be architecture as: - get the package manager
- remove dep with the utility function
- run the good child process
for this part I can take over the pr to help you.
https://docs.codemod.com/cli/packages/building-workflows#steps
https://docs.codemod.com/jssg/security
| // Pattern 1: chalk.method(text) -> styleText("method", text) | ||
| const method = methodMatch.text(); | ||
| const text = textMatch.text(); | ||
| const styleMethod = COMPAT_MAP[method] || method; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if the method is valid node style thing ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an example of what you mean?
the reason behind COMPAT_MAP is really to handle the naming differences between chalk and styleText. I haven't done an exhaustive comparison yet, but the obvious one was overlined vs overline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my question is "Is there a chalk method that does not exist at all under node? " if yes what happened for the modified code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few cases that are not currently handled in the PR yet.
chalkStderr(ref: https://github.com/search?q=chalkStderr&type=code&p=1)chalk.hex(ref: https://github.com/search?q=chalk.hex&type=code)chalk. rgb(ref: https://github.com/search?q=chalk.rgb+&type=code)chalk.ansi256(ref: https://github.com/search?q=chalk.ansi256&type=code)new Chalk(...)chalk.levelchalk.visible
How should we handle those?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
before the initialization of styleMethod we should check if the method is hex OR rgb OR ansi256 if yes warn the user that is not migratable. And advice them to use "standard" colors
TIP root.filename() give the relative path from the cwd of the proccessed file.
For other methods idk maybe also warn but I'm not sure how to advice the user
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added a test case for unsupported features: feat(chalk-to-util-styletext): add unsupported features test
I'm not sure how we should warn the user though in this case. We could add a TODO comment explaining why it wasn't transformed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
console.warn("${fileName}:${row}:${col} use a chalk method that didn't have any 1:1 equivalent in util.styleText please review this line")
…oll/userland-migrations into feat/chalk-styletext-migration
Related issue
Fixes #198
Test cases
const mychalk = require('chalk');const { red }. = require(-'chalk');maybe hardconst { red; foo }. = require(-"chalk");const foo = await import('chalk');const { red } = await import('chalk')import * as chalk from 'chalk'import { red } from 'chalk';import { red as colorRed 'chalk';