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

#9430: tsconfig references refactor #9522

Merged
merged 14 commits into from
Nov 14, 2024
Merged

Conversation

fungairino
Copy link
Collaborator

@fungairino fungairino commented Nov 13, 2024

What does this PR do?

Discussion

  • We could go with a "buildless" approach for our TS configuration but this over the long run will make our type checking a lot slower

Demo

  • Verified that tsc --build --watch recompiles only the utils directory when changes are made to it, and leaves the whole extension project untouched

Future Work

  • Add @nx/js plugin to handle ts tasks and auto updating tsconfig references
  • Make our eslint config situation better

Checklist

  • FIx lint issue
  • Fix knip issue

For more information on our expectations for the PR process, see the
code review principles doc

@fungairino fungairino self-assigned this Nov 13, 2024
Copy link

codecov bot commented Nov 13, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.79%. Comparing base (8318d74) to head (f6bfacf).
Report is 507 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9522      +/-   ##
==========================================
+ Coverage   74.24%   75.79%   +1.54%     
==========================================
  Files        1332     1422      +90     
  Lines       40817    42917    +2100     
  Branches     7634     7902     +268     
==========================================
+ Hits        30306    32529    +2223     
+ Misses      10511    10388     -123     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

github-actions bot commented Nov 13, 2024

Playwright test results

passed  152 passed
flaky  2 flaky
skipped  2 skipped

Details

report  Open report ↗︎
stats  156 tests across 51 suites
duration  11 minutes, 18 seconds
commit  f6bfacf
info  For more information on how to debug and view this report, see our readme

Flaky tests

msedge › tests/runtime/localIntegrations.spec.ts › Local Integrations Page › #8067: blank numeric text integration configuration field validated on save
msedge › tests/workshop/createMod.spec.ts › can create a new mod from a yaml definition and update it

Skipped tests

chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
msedge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@fungairino fungairino marked this pull request as ready for review November 13, 2024 22:31
@@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { getInvalidPath } from "@/debugUtils";
import { getInvalidPath } from "./debugUtils";
Copy link
Contributor

@twschiller twschiller Nov 13, 2024

Choose a reason for hiding this comment

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

What's the import convention from inside the browser-extension workspace? Or do we have to wait for @nx/js to set that up?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is imported in the browser-extension like so:
import { getInvalidPath } from "@pixiebrix/utils/src/debugUtils";

I removed this following the suggested tsconfigs from nx, but I think we could add back the following in the libraries/utils tsconfig if we wanted:

  "compilerOptions": {
    "paths": {
      "@/*": ["src/*"]

I don't feel too strongly either way about this.

Copy link
Contributor

@twschiller twschiller Nov 14, 2024

Choose a reason for hiding this comment

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

I'm not a big fan of the src directory appearing in the import, but it wouldn't be deal breaker. @pixiebrix/utils/debugUtils would seem the cleanest to me (like you're importing a normal package)

I'm generally not a fan of relative imports (for reasons, e.g., listed on the lint rule https://www.npmjs.com/package/eslint-plugin-no-relative-import-paths), but with the same directory a potential exception

Where in the slicing are we introducing an actual cross-workspace import to the build?

Update: I see that the example import is here:

See comment on top-level npm run watch: #9522 (comment)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not a big fan of the src directory appearing in the import, but it wouldn't be deal breaker. @pixiebrix/utils/debugUtils would seem the cleanest to me (like you're importing a normal package)

This should be simple enough to update with an exported index file as a follow-up

@twschiller
Copy link
Contributor

twschiller commented Nov 14, 2024

@fungairino I'm getting an error on top-level npm run watch. Am I supposed to be able to run that? (Would that require defining a watch target in the library to also have the tsc watch the files there? Is this related to your comment: "We could go with a "buildless" approach for our TS configuration...")

src/pageEditor/store/editor/editorSlice.ts:37:32 - error TS6305: Output file '/Users/tschiller/projects/pixiebrix-extension/libraries/utils/dist/debugUtils.d.ts' has not been built from source file '/Users/tschiller/projects/pixiebrix-extension/libraries/utils/src/debugUtils.ts'.

37 import { getInvalidPath } from "@pixiebrix/utils/src/debugUtils";

SO chatter here: https://stackoverflow.com/questions/55115705/typescript-project-with-references

IntelliJ can resolve the usage. But typescript not happy about the type:
image

@twschiller twschiller changed the title tsconfig references refactor #9430: tsconfig references refactor Nov 14, 2024
@twschiller twschiller added this to the 2.2.1 milestone Nov 14, 2024
@fungairino
Copy link
Collaborator Author

I'm getting an error on top-level npm run watch

See discussion in slack https://pixiebrix.slack.com/archives/C080KB9R76G/p1731595386835629

Devs will need to have a running tsc watch process to see updates from underlying libraries in apps if they are making changes across projects concurrently. I'll make sure to communicate this out.

I pushed up a change to update the root level watch script so it should now correctly run tsc progressively across the projects in the monorepo.

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

Comment on lines +38 to +41
"libraries/*": {
entry: "src/*.ts!",
project: "**/*.ts",
},
Copy link
Collaborator

@grahamlangford grahamlangford Nov 14, 2024

Choose a reason for hiding this comment

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

Should we really be making every file in the src folder an entry? What if a utility function exports a helper function for testing but shouldn't be used outside the library?

Suggested change
"libraries/*": {
entry: "src/*.ts!",
project: "**/*.ts",
},
"libraries/*": {
// Files with a `!` suffix are included in production mode and default run
entry: "src/index.ts!",
project: ["src/**/*.ts!", "!src/**/*.d.ts!"],
},

This way we force engineers to define in the index.ts exactly what functions are available outside the library

Second, NX recommends we call the library either util or util-*: https://nx.dev/concepts/decisions/project-dependency-rules#utility-libraries

Copy link
Collaborator

Choose a reason for hiding this comment

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

I tested the original code by creating a testFn.ts that exported a simple function and a testFn.test.ts that imported it. It's used nowhere else. The current config doesn't catch it when running production mode. The suggested config does.

Copy link
Collaborator

@grahamlangford grahamlangford Nov 14, 2024

Choose a reason for hiding this comment

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

Wait, I checked whether the @internal disable would work, looks like it doesn't

Works with a more realistic test scenario (function exported from debugUtils but not index.ts instead)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I totally agree with this suggestion, I will make this change in a follow-up since this aligns with the same feedback that Todd left further up on avoiding importing from the src directory.

@fungairino fungairino merged commit f0cb378 into main Nov 14, 2024
25 checks passed
@fungairino fungairino deleted the tsconfig-references-refactor branch November 14, 2024 19:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Slice 2: Add nx initial config and commands
3 participants