pr05 Typescript #3: Migrate client/utils folder#3553
pr05 Typescript #3: Migrate client/utils folder#3553raclim merged 76 commits intoprocessing:developfrom
Conversation
| const S3_BUCKET_URL_BASE = getConfig('S3_BUCKET_URL_BASE', { | ||
| throwErrorIfNotFound: true | ||
| }); | ||
| const S3_BUCKET = getConfig('S3_BUCKET', { throwErrorIfNotFound: true }); |
There was a problem hiding this comment.
@khanniie what do you think of this update?
getConfig options param now has throwErrorIfNotFound, which throws and error if the value is not found (or is an empty string)
This allows the compiler to throw errors immediately when attempting a local build if these things are missing
I've done a search for all instances where getConfig is used and made a guess of what I think would be useful to fail at compile-time if the config variable doesn't exist, but this is totally a guess
There was a problem hiding this comment.
tysm!! appreciate you making the change! doesn't really affect the implementation but are we sure it's the compiler throwing the error and not the console at runtime? either way i think it's good we're throwing an error instead of letting it fail silently
There was a problem hiding this comment.
Hmm I just tried this manually by removing API_URL from my local env and it didn't seem to throw in my local build, so I'm going to remove this!
Will look into doing the thing you mentioned where we have another module that checks for 'required' env variables at compile or build time
| )}`; | ||
| previewScripts.src = `${ | ||
| window.location.origin | ||
| }${getConfig('PREVIEW_SCRIPTS_URL', { nullishString: true })}`; |
There was a problem hiding this comment.
@khanniie I don't have this in my local env, which is auto gen from the env.example, so I assumed this was not fail-on-not-found worthy, what do you think?
There was a problem hiding this comment.
hmmmm tbh I don't really know if it's necessary or not, maybe @raclim would know?
There was a problem hiding this comment.
I think it's created in server/views/previewIndex.js for rendering the preview! I think this is currently okay as is for now
client/utils/getConfig.ts
Outdated
| warn: !isTestEnvironment, | ||
| nullishString: false, | ||
| throwErrorIfNotFound: false, | ||
| throwErrorInTestEnv: false |
There was a problem hiding this comment.
@khanniie
Without this, I wasn't able to test if getConfig throws errors when we set {throwErrorIfNotFound: true} because the env is 'test' when we run the test
What do you think, is there another way to set the env of the test run for a single test?
Another alternative would be to do {throwErrorIfNotFound: !isTestEnv} for whereever we're using getConfig, but I was thinking maybe that's not the cleanest to keep doing that when we use the function
There was a problem hiding this comment.
not sure if i understood the question exactly right, but i think there are ways to set the env for tests! i think you can override the values in the module?
https://stackoverflow.com/questions/48042200/invalidate-node-cache-when-using-jest
^ not sure if this above works for your case but we can definitely look into mocks / stubs for env if that's what you were wondering
999c62a to
8b3fee5
Compare
client/components/SkipLink.tsx
Outdated
| @@ -3,8 +3,8 @@ import classNames from 'classnames'; | |||
| import { useTranslation } from 'react-i18next'; | |||
|
|
|||
| type SkipLinkProps = { | |||
There was a problem hiding this comment.
this should be interface i think?
khanniie
left a comment
There was a problem hiding this comment.
it's looking really good!!! I had a few more tiny comments but overall thank you so much for your hard work!
| const S3_BUCKET_URL_BASE = getConfig('S3_BUCKET_URL_BASE', { | ||
| throwErrorIfNotFound: true | ||
| }); | ||
| const S3_BUCKET = getConfig('S3_BUCKET', { throwErrorIfNotFound: true }); |
There was a problem hiding this comment.
tysm!! appreciate you making the change! doesn't really affect the implementation but are we sure it's the compiler throwing the error and not the console at runtime? either way i think it's good we're throwing an error instead of letting it fail silently
| )}`; | ||
| previewScripts.src = `${ | ||
| window.location.origin | ||
| }${getConfig('PREVIEW_SCRIPTS_URL', { nullishString: true })}`; |
There was a problem hiding this comment.
hmmmm tbh I don't really know if it's necessary or not, maybe @raclim would know?
client/utils/dispatcher.ts
Outdated
| * - type: 'START', 'STOP' etc | ||
| * - payload: additional data for that message type | ||
| */ | ||
| export type Message = { |
client/utils/evaluateExpression.ts
Outdated
| @@ -0,0 +1,44 @@ | |||
| type EvalResult = { | |||
client/utils/getConfig.ts
Outdated
| throwErrorIfNotFound?: boolean; | ||
| } | ||
|
|
||
| const defaultGetConfigOptions: GetConfigOptions = { |
There was a problem hiding this comment.
can we make this constant case? https://google.github.io/styleguide/tsguide.html#identifiers-constants
client/utils/getConfig.ts
Outdated
| warn: !isTestEnvironment, | ||
| nullishString: false, | ||
| throwErrorIfNotFound: false, | ||
| throwErrorInTestEnv: false |
There was a problem hiding this comment.
not sure if i understood the question exactly right, but i think there are ways to set the env for tests! i think you can override the values in the module?
https://stackoverflow.com/questions/48042200/invalidate-node-cache-when-using-jest
^ not sure if this above works for your case but we can definitely look into mocks / stubs for env if that's what you were wondering
khanniie
left a comment
There was a problem hiding this comment.
thank you so much for all the work!!
raclim
left a comment
There was a problem hiding this comment.
Thanks so much for your work on this @clairep94 and for your review @khanniie! I think this overall feels, good and will merge this in!
pr05 Typescript Migration 3: Migrate the client/utils folder
IMPORTANT: Should be reviewed after #3540 for clarity
Context:
Rebuild of Pr05/migrate client utils clairep94/p5.js-web-editor#5 --> forgot to do
git mvfor the first few files and directly renamed, so this looks like deleting and creating a new file for git, and erases the previous history.Migrate as much of the client/utils folder with the following steps:
git mv someUtil.js someUtil.ts. If possible, commit without theno-verifyflag, otherwise withno-verify.I forgot to add
no-verifyto my commit message in some of these initial onesChanges:
Please see annotations on files
Notes:
I have verified that this pull request:
npm run lint)npm run test)developbranch.Fixes #123