-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add pnpm workspace for submodule local linking #157
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
Draft
garrity-miepub
wants to merge
1
commit into
main
Choose a base branch
from
feat/pnpm-workspace-submodules
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| link-workspace-packages = true |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -242,5 +242,10 @@ | |
| }, | ||
| "engines": { | ||
| "node": ">=18.0.0" | ||
| }, | ||
| "pnpm": { | ||
| "overrides": { | ||
| "@mieweb/ui": "link:." | ||
| } | ||
| } | ||
| } | ||
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,180 @@ | ||||||
| # Packages (Submodules as Workspace Members) | ||||||
|
|
||||||
| This directory contains git submodules that are automatically integrated into the | ||||||
| `@mieweb/ui` pnpm workspace. When a submodule depends on `@mieweb/ui`, the | ||||||
| workspace resolves it to the **local source** instead of fetching from npm — | ||||||
| giving you live, un-published changes during development. | ||||||
|
|
||||||
| When any of these packages are **cloned standalone** (outside this repo), there | ||||||
| is no workspace — they fall back to the published `@mieweb/ui` version from npm. | ||||||
| No code changes are needed — the same `package.json` works in both contexts. | ||||||
|
|
||||||
| ## How it works | ||||||
|
|
||||||
| Three files in the repo root make this possible: | ||||||
|
|
||||||
| ### 1. `pnpm-workspace.yaml` | ||||||
|
|
||||||
| Declares every directory under `packages/` as a workspace member: | ||||||
|
|
||||||
| ```yaml | ||||||
| packages: | ||||||
| - "packages/*" | ||||||
| ``` | ||||||
|
|
||||||
| ### 2. `.npmrc` | ||||||
|
|
||||||
| Enables workspace linking in pnpm v10+ (where it defaults to `false`): | ||||||
|
|
||||||
| ```ini | ||||||
| link-workspace-packages = true | ||||||
| ``` | ||||||
|
|
||||||
| ### 3. `pnpm.overrides` in `package.json` | ||||||
|
|
||||||
| Because the root `@mieweb/ui` package has a `file:` dev-dependency on | ||||||
| `datavis` (for Storybook/builds), pnpm detects a **cyclic workspace | ||||||
| dependency** and falls back to the npm registry version. The override forces | ||||||
| the local link: | ||||||
|
|
||||||
| ```jsonc | ||||||
| // package.json (root) | ||||||
| "pnpm": { | ||||||
| "overrides": { | ||||||
| "@mieweb/ui": "link:." | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| This override only exists in the workspace root. When a submodule is cloned | ||||||
| standalone, there is no override — it installs `@mieweb/ui` from npm normally. | ||||||
|
|
||||||
| ### Resolution summary | ||||||
|
|
||||||
| | Context | What happens to `"@mieweb/ui": "^0.2.2"` | | ||||||
| |---|---| | ||||||
| | **Inside this repo** (workspace active) | Resolved to the local root via `link:` — you always get the latest source. | | ||||||
| | **Cloned standalone** (no workspace root) | Installed from the npm registry as usual. | | ||||||
|
|
||||||
| No special syntax like `workspace:` is required in the submodule's | ||||||
| `package.json`. The standard semver range (`^0.2.2`) works everywhere. | ||||||
|
|
||||||
| ## Existing submodules | ||||||
|
|
||||||
| | Submodule | Path | Depends on `@mieweb/ui` | | ||||||
| |---|---|---| | ||||||
| | `@mieweb/datavis` | `packages/datavis` | Yes | | ||||||
|
|
||||||
| ## Adding a new submodule | ||||||
|
|
||||||
| ### 1. Add the git submodule | ||||||
|
|
||||||
| ```bash | ||||||
| git submodule add https://github.com/mieweb/<repo>.git packages/<repo> | ||||||
| ``` | ||||||
|
|
||||||
| This updates `.gitmodules` and creates the `packages/<repo>` directory. | ||||||
|
|
||||||
| ### 2. Declare the dependency in the submodule's `package.json` | ||||||
|
|
||||||
| In the submodule's own `package.json`, list `@mieweb/ui` with a normal semver | ||||||
| range (not `workspace:`): | ||||||
|
|
||||||
| ```json | ||||||
| { | ||||||
| "dependencies": { | ||||||
| "@mieweb/ui": "^0.2.2" | ||||||
| } | ||||||
| } | ||||||
| ``` | ||||||
|
|
||||||
| This is the only thing needed. Because `pnpm-workspace.yaml` includes | ||||||
| `packages/*`, pnpm already knows about the new package. | ||||||
|
|
||||||
| ### 3. Install from the workspace root | ||||||
|
|
||||||
| ```bash | ||||||
| pnpm install | ||||||
| ``` | ||||||
|
|
||||||
| pnpm will symlink `@mieweb/ui` into the submodule's `node_modules` pointing at | ||||||
| the workspace root (via the override in the root `package.json`). You can verify: | ||||||
|
|
||||||
| ```bash | ||||||
| node -e "console.log(require('fs').realpathSync('packages/<repo>/node_modules/@mieweb/ui'))" | ||||||
| # → /path/to/ui (the workspace root) | ||||||
| ``` | ||||||
|
|
||||||
| ### 4. If the root depends on the new submodule | ||||||
|
|
||||||
| If the root `package.json` adds a `file:` or `workspace:` dependency on the new | ||||||
| submodule (e.g. for Storybook stories), this creates a **cyclic dependency**: | ||||||
|
|
||||||
| ``` | ||||||
| @mieweb/ui → packages/<repo> → @mieweb/ui | ||||||
| ``` | ||||||
|
|
||||||
| The existing `pnpm.overrides` in the root already handles this — it forces | ||||||
| `@mieweb/ui` to resolve as `link:.` for all workspace members regardless of | ||||||
| cycles. No additional configuration is needed. | ||||||
|
|
||||||
| ### 4. (Optional) Submodule uses npm internally | ||||||
|
||||||
| ### 4. (Optional) Submodule uses npm internally | |
| ### 5. (Optional) Submodule uses npm internally |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc states submodules should depend on
@mieweb/uivia a normal semver range (e.g.^0.2.2) so the samepackage.jsonworks when cloned standalone. However, the generatedpnpm-lock.yamlin this PR showspackages/dataviscurrently has@mieweb/uiwithspecifier: link:../.., which would not work outside the workspace. Either update the documentation to reflect the current state (and any exceptions), or ensure the submodule dependency is expressed as a semver range so standalone clones behave as described.