-
Notifications
You must be signed in to change notification settings - Fork 1k
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
chore(jobs): Mostly nitpicky changes to the Jobs PR #11328
Conversation
|
||
import { getPaths } from '@redwoodjs/project-config' | ||
|
||
// This plugin is responsible for injecting the import path and name of a job | ||
// into the object that is passed to createJob. This is later used by adapters | ||
// and workers to import the job. | ||
|
||
export default function ({ types: _t }: { types: typeof types }): PluginObj { |
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.
Following our code standards of only using underscore (_foo
) for unused variables
@@ -95,7 +95,7 @@ const tasks = async ({ force }) => { | |||
fs.mkdirSync(getPaths().api.jobs) | |||
} catch (e) { | |||
// ignore directory already existing | |||
if (!e.message.match('file already exists')) { | |||
if (!/file already exists/.test(e.message)) { |
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.
If you need to know if a string matches a regular expression RegExp, use RegExp.prototype.test().
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.
Yeah I hate this syntax, it feels backwards to me. In real life I'd say "Is this car red?" Not "Is the color red what this car is?" GROSS If you start with a regex object (because it was passed in as an argument, or you constructed the regex from other variables) you can use test()
, but if you start with the string you can use match()
.
But if it's more performant or whatever, we can make it test()
instead.
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.
Can't argue with that... I also think it reads backwards 🙁 But it is the recommended way!
BUT I changed the code to pass { recursive: true }
, which makes it so that no error is thrown if the directory already exists. So now we don't have to worry about any error messages 🎉
const workerArgs: string[] = [] | ||
workerArgs.push('--index', index.toString()) | ||
workerArgs.push('--id', id.toString()) | ||
const workerArgs = ['--index', index.toString(), '--id', id.toString()] |
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.
Mainly wanted to get rid of the explicit string[]
type annotation
@@ -16,8 +16,8 @@ import { prepareForRollback } from '../../../lib/rollback' | |||
import { yargsDefaults } from '../helpers' | |||
import { validateName, templateForComponentFile } from '../helpers' | |||
|
|||
// Makes sure the name ends up looking like: `WelcomeNotice` even if the user | |||
// called it `welcome-notice` or `welcomeNoticeJob` or anything else |
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 just thought "anything else" was maybe a little too over reaching 😆
Ran into a few things I wanted to fix when I was reviewing the Jobs PR. This PR addresses most of those things. A few more are left as review comments on the Jobs PR itself