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

removed tsc-alias #6796

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft

removed tsc-alias #6796

wants to merge 15 commits into from

Conversation

kurtisassad
Copy link
Contributor

@kurtisassad kurtisassad commented Feb 20, 2024

Link to Issue

Closes: #6362

Description of Changes

  • Remove tsc alias

Test Plan

  • Run build of commonwealth via yarn build && yarn bundle && yarn start-external-webpack and ensured it ran correctly. (Side note, this doesn't work because it runs the .ts file instead of the .js)
  • Run yarn build && cd packages/commonwealth && NODE_ENV=production NODE_OPTIONS=--max-old-space-size=$(../../scripts/get-max-old-space-size.sh) node --enable-source-maps ./build/server.js and ensured it ran correctly.
  • Run build of discord listener and consumer, made sure that it ran correctly
  • Run build of snapshot-listener, made sure that it ran correctly via node ./build/index.js

(dev experience)

  • Added a 'server/...' type import on the server side. Ensured that it threw an error at static typecheck time.

@kurtisassad kurtisassad marked this pull request as ready for review February 20, 2024 14:49
@Rotorsoft
Copy link
Contributor

@kurtisassad I was expecting this PR to have a bunch of import renames and removing the "*" path in commonwealth/tsconfig.json

 "paths": {
      "@hicommonwealth/*": ["../../libs/*/src"],
      "*": ["./*", "shared/*", "client/scripts/*"]
    }

The purpose of tsc-alias is to replace the "*" paths following the tsc build step. It was used to reference folders located outside the commonwealth root directory, however, after the refactoring saga, all references are now contained within the root directory, and we can solve it with relative paths. This is not a critical issue though, and we can postpone if too much work involved.

@kurtisassad
Copy link
Contributor Author

@Rotorsoft It seems that we actually didn't need tsc-alias as the backend builds fine without it. We had never used that type of * alias on the backend (It is only used on the frontend, but webpack handles it, not tsc-alias).

I see what you are saying about the aliases on the backend though. These can be fixed in a subsequent PR in order to separate the concerns.

Copy link
Collaborator

@timolegros timolegros left a comment

Choose a reason for hiding this comment

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

We shouldn't remove tsc-alias if we don't first remove "*": ["./*", "shared/*", "client/scripts/*"] from paths. The current implementation breaks on deployment since paths like /server/... or /shared/... will pass type-checks + build but fail when executed. Additionally, even if we refactor existing instances of such imports, the paths property in the tsconfig allows for new imports using such patterns which would again break when deployed.

To replicate the above error you need to run server.js not server.ts (see Procfile).

@kurtisassad
Copy link
Contributor Author

kurtisassad commented Feb 28, 2024

@timolegros Seems a little strange, since running the server.js works for me. I will try running it on staging

Ah nvm, was running start-external-webpack, which doesn't run the exact production build since it still runs server.ts, not the js variant

@kurtisassad kurtisassad marked this pull request as ready for review February 28, 2024 16:32
@kurtisassad kurtisassad force-pushed the ka.tsc-alias-removal branch 2 times, most recently from f6421e8 to d3c5797 Compare February 28, 2024 16:34
Copy link
Collaborator

@timolegros timolegros left a comment

Choose a reason for hiding this comment

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

As mentioned in my previous review, removing the tsc-alias dependent imports does make the build work but merging this is dangerous since future tsc-alias dependent imports are still allowed. As such we could accidentally deploy a broken build without realizing it because we don't run server.js in testing/CI.

@kurtisassad
Copy link
Contributor Author

@timolegros I added in a tsconfig for the server to override this so that it throws an error if we use this pattern on the server.

The issue from a full refactor is that the client uses this pattern a lot, it will be a huge refactor. Anyways with these minimal changes the tsc-alias is no longer needed, because webpack handles the recursive imports on the client side.

@@ -4,7 +4,7 @@
"private": true,
"scripts": {
"add-component-showcase": "npx ts-node -T ./scripts/add-component-showcase.ts",
"build": "tsc -b && tsc-alias",
"build": "tsc -b",
"clean": "rm -rf build",
"check-types": "tsc --noEmit",
Copy link
Collaborator

@timolegros timolegros Feb 29, 2024

Choose a reason for hiding this comment

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

This (check-types) would use the packages/commonwealth/tsconfig.json config so it would pass with the bad imports no? Likely need to temporarily have 2 tsc --noEmit checks here -> one for the client and one for the server.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah so this might be a problem. Basically we don't get any build errors from adding these imports, but we do get editor visual errors:
image

The only issue with having a separate check-types is that tsc won't actually work because the folder that you are type checking are not allowed to have imports outside the root (In this case we have server importing modules from other packages like @hicommonwealth/core). So I am not sure the solution for this one. Maybe its better just to settle for the editor errors.

Copy link
Collaborator

@timolegros timolegros Mar 26, 2024

Choose a reason for hiding this comment

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

@kurtisassad per convo we should definitely not settle for editor errors. I'm not exactly sure what the solution is here but we should hop in a huddle with @Rotorsoft and figure this out this week.

# Conflicts:
#	packages/commonwealth/main.ts
#	packages/commonwealth/server/routes/communities/get_communities_handler.ts
# Conflicts:
#	packages/commonwealth/main.ts
#	packages/commonwealth/package.json
#	packages/commonwealth/server/controllers/server_comments_methods/search_comments.ts
#	packages/commonwealth/server/controllers/server_communities_methods/search_communities.ts
#	packages/commonwealth/server/routes/profiles/search_profiles_handler.ts
#	packages/commonwealth/server/util/queries.ts
#	packages/commonwealth/test/integration/api/index.spec.ts
# Conflicts:
#	packages/commonwealth/server/routes/viewGlobalActivity.ts
@timolegros
Copy link
Collaborator

@kurtisassad I created an import from shared/ on the server and yarn check-types-server did no throw an error. Also, we may want to modify the sanity.sh script to include type-checking the server once it is fixed.

@timolegros timolegros mentioned this pull request Apr 16, 2024
@Rotorsoft
Copy link
Contributor

@timolegros are you considering the type checking discussed here in #7407 ?

@rbennettcw
Copy link
Contributor

Some conflicts

@ForestMars ForestMars marked this pull request as draft April 19, 2024 20:11
@ForestMars
Copy link
Contributor

ForestMars commented Apr 19, 2024

Setting back to draft pending conficts.

@jnaviask
Copy link
Collaborator

@kurtisassad what happened with this PR?

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.

Remove tsc-alias
6 participants