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

feat: add jest recipe #4

Merged
merged 7 commits into from
Jul 8, 2024
Merged

feat: add jest recipe #4

merged 7 commits into from
Jul 8, 2024

Conversation

km1chno
Copy link
Collaborator

@km1chno km1chno commented Jul 3, 2024

  • exported installing dependencies and adding scripts to package.json to extensions: extensions/dependencies.ts and extensions/scripts.ts,
  • added recipe for running jest in PR.

@km1chno km1chno self-assigned this Jul 3, 2024
Copy link
Collaborator

@maciekstosio maciekstosio left a comment

Choose a reason for hiding this comment

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

Imo it looks better 🎉 Please take a look at comments above.

src/extensions/addScript.ts Outdated Show resolved Hide resolved
src/commands/react-native-ci-cli.ts Outdated Show resolved Hide resolved
src/extensions/dependencies.ts Outdated Show resolved Hide resolved
src/extensions/dependencies.ts Outdated Show resolved Hide resolved
src/extensions/dependencies.ts Outdated Show resolved Hide resolved
src/extensions/addScript.ts Outdated Show resolved Hide resolved
@km1chno km1chno changed the base branch from feat-add-ESLint-recipe to main July 5, 2024 11:34
import isGitDirty from 'is-git-dirty'

const command: GluegunCommand = {
name: 'react-native-ci-cli',
run: async (toolbox) => {
const { intro, confirm, outro } = await import('@clack/prompts')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

So I don't really like it, but the story is the following. When trying to use p-map, it turned out that it is a ES module and therefore it has to be imported, not required. The problem is that with tsconfig we had, specifically with module: commonjs and moduleResolution: node, the transpiler automatically converted import syntax to require, resulting in an error.

According to https://www.typescriptlang.org/docs/handbook/modules/reference.html#node16-nodenext, the recommended way to handle such cases is to change module and moduleResolution to node16 and target to es2022 and then use static import for CommonJS dependencies and dynamic asynchronous import(...) for ESM.

We could just not use p-map, but the problem would eventually come back since a lot of packages are ESM only. Also, I still don't understand it that well, because clack is ESM and importing it worked just fine with the old tsconfig. I guess since module: commonjs is not recommended (according to the link above), maybe it is just not consistent.

Let me know what you think and whether you had such problems in the past and may know a better solution:)

Copy link
Collaborator

Choose a reason for hiding this comment

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

The current solution looks good to me - It's always a pain, so I'd suggest looking for modules that are not ESM

Copy link
Collaborator

Choose a reason for hiding this comment

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

I played with it for a bit and it might be tricky to set it up. Clack works probably because it is transpired to both .cjs and .mjs, I tried to import just pMap with dynamic import but it doesn't work probably due to microsoft/TypeScript#43329. Tbh, dynamic imports everywhere look massy, I would revert to using you helper instead of pMap, just if you could extract it to some util and maybe try to write using async/await. What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

After discussion with @maciekstosio, we decided to revert back to previous tsconfig and just not use p-map since it's easily avoidable. If in the future we will need a crucial ESM only dependency, then we will migrate to module: node16. I reverted the changes in 1e39c1e

src/recipies/jest.ts Outdated Show resolved Hide resolved
src/recipies/lint.ts Outdated Show resolved Hide resolved

const executorResults = await Promise.all(
executors.map((executor) => executor(toolbox))
const executorResults = await executors.reduce(
Copy link
Collaborator

Choose a reason for hiding this comment

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

One last think, let's put it in some utils (not necessarly extension as I think it's not strictly related tool for CLI)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

extracted to /src/utils/sequentialPromiseMap.ts in 7ddc6c5

Copy link
Collaborator

@maciekstosio maciekstosio left a comment

Choose a reason for hiding this comment

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

lgtm, great work! 🎉

@maciekstosio maciekstosio merged commit 12cfec0 into main Jul 8, 2024
@km1chno km1chno deleted the feat-add-jest-recipe branch August 6, 2024 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants