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

refactor: use tsconfig monorepo #132

Merged
merged 10 commits into from
Oct 25, 2023
Merged

Conversation

himself65
Copy link
Contributor

@himself65 himself65 commented Sep 19, 2023

Add top-level ts config that includes all submodules, which restricts the type and isolated type context. If some files are missing or wrong-typed, it will throw the error.

@vercel
Copy link

vercel bot commented Sep 19, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview 💬 Add feedback Oct 24, 2023 11:17pm

@codesandbox-ci
Copy link

codesandbox-ci bot commented Sep 19, 2023

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit bf3e9da:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
React Configuration
React TypeScript Configuration

packages/waku/src/types.d.ts Show resolved Hide resolved
packages/waku/src/config.ts Outdated Show resolved Hide resolved
packages/create-waku/src/cli.ts Show resolved Hide resolved
.github/workflows/cd.yml Outdated Show resolved Hide resolved
Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

I'm sorry, I had pending comments that I thought I submitted, but it's actually not.

tsconfig.json Outdated Show resolved Hide resolved
examples/01_counter/tsconfig.json Outdated Show resolved Hide resolved
@dai-shi
Copy link
Owner

dai-shi commented Oct 6, 2023

Please make changes minimal as I'm working on #136 too.

@himself65
Copy link
Contributor Author

I will continue work on this today

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

This looks very nice.
I haven't used "references" before.
My preference is to have things as minimal as possible.
Some of tsconfig properties are new to me, and I can't judge, but please keep that in mind.

@@ -20,6 +20,21 @@ jobs:
- run: pnpm install --frozen-lockfile
- run: pnpm test

type-check:
Copy link
Owner

Choose a reason for hiding this comment

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

We run tsc in pnpm test, so it's not necessary here?

Comment on lines +12 to +13
"outDir": "./dist",
"rootDir": "./src"
Copy link
Owner

Choose a reason for hiding this comment

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

Not sure why they are required, but maybe they are?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is required otherwise the output file structure will be

- dist
  - src
    - xxx.js

instead of

- dist
- xxx.js

It's not needed here since waku build is real output files. But just some habit for me.

But it's necessary for packages/waku since we're monorepo tsconfig now

Copy link
Owner

Choose a reason for hiding this comment

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

hm, that makes sense.

{
"path": "./tsconfig.node.json"
}
]
Copy link
Owner

Choose a reason for hiding this comment

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

Why do we need this in 02_async, not in 01_counter?
I do not understand why two tsconfig files are required, instead of one.

Copy link
Contributor Author

@himself65 himself65 Oct 24, 2023

Choose a reason for hiding this comment

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

because vite.config.ts is actually in a different environment with files in ./src.

For example, you cannot include src files in config because of two ts configs with different files included

image

This is good for mono repo because sometimes you will mistakenly include files across the packages

Also it will be compiled to the different outputDir based on tsconfig.

01_counter doesn't have two configs because there is no vite.config.ts

Copy link
Owner

Choose a reason for hiding this comment

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

Thanks for the explanation. We will revisit this later.

packages/create-waku/tsconfig.json Outdated Show resolved Hide resolved
packages/waku/src/types.d.ts Show resolved Hide resolved
packages/waku/tsconfig.json Outdated Show resolved Hide resolved
tsconfig.json Show resolved Hide resolved
@himself65
Copy link
Contributor Author

You can read the document here: https://www.typescriptlang.org/docs/handbook/project-references.html

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

Looking good. I feel like I need to learn some more later.

Comment on lines 16 to 17
// React Server Async Component type
"react/experimental"
Copy link
Owner

Choose a reason for hiding this comment

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

Can we put this also in the source code as inline comment? Just a preference, but it looks more explicit.

Copy link
Owner

Choose a reason for hiding this comment

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

This is remaining. Also in 10_dynamicroute.

packages/waku/src/types.d.ts Show resolved Hide resolved
Comment on lines 6 to 7
"module": "ESNext",
"moduleResolution": "bundler",
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is correct for cli tools. I think it should be nodenext, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

bundler is better? Since you are using esbuild here

https://www.typescriptlang.org/tsconfig#moduleResolution

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For now i think change it to nodenext wont affect anything

Copy link
Owner

Choose a reason for hiding this comment

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

Oh, I forgot that we use esbuild in cli. Yeah, let's use nodenext if we can. Using esbuild is only a temporary solution anyway.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see a error and its seems correct
image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In this case, create-waku is cjs module but we import a ESM module, I'm not sure the purpose of you're importing this

Copy link
Owner

Choose a reason for hiding this comment

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

importing fs-extra/esm ?
@vasucp1207 introduced it.
Maybe we should refactor it. My intention is everything should be ESM and no CJS in this repo. (and our plan was to avoid esbuild eventually.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see, i can do that but it's too far away from this PR

Copy link
Owner

Choose a reason for hiding this comment

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

That would be great. Feel free to open a new PR.

Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

we are almost there.

Comment on lines 16 to 17
// React Server Async Component type
"react/experimental"
Copy link
Owner

Choose a reason for hiding this comment

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

This is remaining. Also in 10_dynamicroute.

package.json Outdated Show resolved Hide resolved
Copy link
Owner

@dai-shi dai-shi left a comment

Choose a reason for hiding this comment

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

LGTM
Thanks for your contribution!

@dai-shi dai-shi merged commit 39aadeb into dai-shi:main Oct 25, 2023
5 checks passed
@himself65 himself65 deleted the himself65/ts-monorepo branch October 25, 2023 02:15
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.

2 participants