Structure repo as workspaces for creation of "shared" package#604
Open
Structure repo as workspaces for creation of "shared" package#604
Conversation
- Also remove shared path in tsconfig
- Also remove tsconfig "paths" definition
…, create package for `shared`
|
|
Member
|
[diff-counting] Significant lines: 948. |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR makes some changes to the overall structure of the codebase, bringing it more in line with modern standards for monorepos.
Context: The npm workspaces feature was created for use in codebases exactly like ours: with a main
package.jsonon the outside, with more specificpackage.jsonfiles in each subfolder to define separate packages. Currently, eachpackage.jsonis separate: they get their ownpackage-lock.jsonandnode_modules. This makes it hard to share files.In this PR, the main
package.json's name ofcarriage-webis used as a base for the workspace. The backend is renamed fromcarriage-web-backendto@carriage-web/server, while the frontend is renamed fromcarriage-webto@carriage-web/frontend. In this new structure, a singlepackage-lock.jsonandnode_modulesis stored in the primarycarriage-webfolder, allowing for deduplication.This change also allows for the easy creation of a new package,
shared. This shared gets its ownpackage.json, so it can have its own dependencies, and is imported by the frontend and backend. As a result, type and enum definitions that are meant to be shared between the two packages are moved to this shared package. In the frontend and backend, the dependency is defined with a asterisk "*", telling npm to use local copy of the package in the workspace:package.json
file.ts
CAUTION: We must be careful to avoid placing sensitive code in the shared package, as it can be seen by users!
enumsdon't seem to work well across thesharedbarrier with Create React App. This problem is fixed when using Vite, however. For that reason, we might want to consider Replace Create React App with Vite #605 before this PR.Test Plan
Typescript's linting and compiling should be very useful in testing that this migration was successful. However, we will also need to manually comb through the webpage and make sure things are still working with this change, especially pieces of shared code that convert to real javascript such as functions and enums.
Breaking Changes
package-lock.jsonfolders in favor of a single consolidated file. Could this have caused multiple packages to upgrade? I'm not sure.node_modulesfolder, as this change also deduplicates that folder.