-
Notifications
You must be signed in to change notification settings - Fork 43
add the doc for using local packages in development with yalc #340
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
Merged
+156
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,156 @@ | ||
| --- | ||
| title: Local Package Development | ||
| description: Learn how to develop and test local packages with tsci dev using yalc and other linking tools | ||
| --- | ||
|
|
||
| ## Overview | ||
|
|
||
| When developing tscircuit projects, you may want to test changes to local packages without publishing them to npm. The `tsci dev` command automatically detects and uploads local packages, making local development seamless. | ||
|
|
||
| Currently supported methods: | ||
| - **yalc** - Recommended for most use cases | ||
| - More linking methods (like `bun link`) coming soon! | ||
|
|
||
| ## What is Yalc? | ||
|
|
||
| [Yalc](https://github.com/wclr/yalc) is a tool for managing local package dependencies. It's a better alternative to `npm link` that creates a local package store and symlinks packages into your project's `node_modules`. | ||
|
|
||
| ## Installation | ||
|
|
||
| First, install yalc globally: | ||
|
|
||
| ```bash | ||
| npm install -g yalc | ||
| # or | ||
| bun install -g yalc | ||
| ``` | ||
|
|
||
| ## Basic Workflow | ||
|
|
||
| ### 1. Build and Publish Your Local Package | ||
|
|
||
| In the package you're developing `@<username>/<package-name>` (e.g., `@tscircuit/pico`): | ||
|
|
||
| ```bash | ||
| cd path/to/your/local/package | ||
|
|
||
| # Build the package first | ||
| bun run build | ||
| # or npm run build | ||
|
|
||
| # Then publish to yalc | ||
| yalc publish | ||
| ``` | ||
|
|
||
| This builds the package and publishes the distribution files to your local yalc store. | ||
|
|
||
| **Note**: You must build the package before publishing with yalc, as it publishes the compiled output (typically in `dist/` or `lib/`), not the source files. | ||
|
|
||
| ### 2. Link the Package to Your Project | ||
|
|
||
| In your tscircuit project: | ||
|
|
||
| ```bash | ||
| cd path/to/your/tscircuit-project | ||
| yalc add @tscircuit/pico | ||
| ``` | ||
|
|
||
| This will: | ||
| - Add the package to your `node_modules` | ||
| - Update your `package.json` with a `file:.yalc/@tscircuit/pico` reference | ||
| - Create a `.yalc` directory with the package contents | ||
|
|
||
| ### 3. Start Development | ||
|
|
||
| Run the dev server as usual: | ||
|
|
||
| ```bash | ||
| tsci dev index.circuit.tsx | ||
| ``` | ||
|
|
||
| The dev server will automatically detect that `@tscircuit/pico` is a local package (via the `file:.yalc/` reference) and upload it along with your component files. | ||
|
|
||
| ### 4. Update Your Local Package | ||
|
|
||
| When you make changes to your local package: | ||
|
|
||
| ```bash | ||
| # In the local package directory | ||
| bun run build # Rebuild with your changes | ||
| yalc push # Push updates to all linked projects | ||
| ``` | ||
|
|
||
| This will rebuild and update all linked projects. You may need to restart `tsci dev` to pick up the changes. | ||
|
|
||
| ## How It Works | ||
|
|
||
| The `tsci dev` command automatically uploads packages from `node_modules` **only if** they meet these criteria: | ||
|
|
||
| 1. The package is referenced in `package.json` with a `file:.yalc/` path | ||
| 2. The package exists in your `node_modules` directory | ||
|
|
||
| Regular npm packages (like `react`, `lodash`, etc.) are **not** uploaded to keep bundle sizes small and development fast. | ||
|
|
||
| ## Example | ||
|
|
||
| Here's a complete example of developing a custom component library: | ||
|
|
||
| **Your local library** (`my-components`): | ||
| ```tsx | ||
| // my-components/src/index.ts | ||
| export const MyCustomChip = (props: any) => { | ||
| return <chip name="U1" footprint="0805" /> | ||
| } | ||
| ``` | ||
|
|
||
| **Publish it locally**: | ||
| ```bash | ||
| bun run build | ||
| yalc publish | ||
| ``` | ||
|
|
||
| **Use it in your project**: | ||
| ```bash | ||
| cd my-tscircuit-project | ||
| yalc add my-components | ||
| ``` | ||
|
|
||
| **Your component**: | ||
| ```tsx | ||
| // circuit.tsx | ||
| import { MyCustomChip } from "my-components" | ||
|
|
||
| export default () => ( | ||
| <board width="10mm" height="10mm"> | ||
| <MyCustomChip /> | ||
| </board> | ||
| ) | ||
| ``` | ||
|
|
||
| **Start dev server**: | ||
| ```bash | ||
| tsci dev circuit.tsx | ||
| ``` | ||
|
|
||
| Now both your component and the `my-components` package code will be uploaded to the dev server! | ||
|
|
||
| ## Removing Yalc Packages | ||
|
|
||
| To remove a yalc package and restore the npm version: | ||
|
|
||
| ```bash | ||
| yalc remove @tscircuit/pico | ||
| npm install @tscircuit/pico | ||
| ``` | ||
|
|
||
| Or remove all yalc packages: | ||
|
|
||
| ```bash | ||
| yalc remove --all | ||
| ``` | ||
|
|
||
| ## Tips | ||
|
|
||
| - Use `yalc push` instead of `yalc publish` when updating packages - it's faster and automatically updates linked projects | ||
| - The `.yalc` directory and `yalc.lock` file should be added to `.gitignore` | ||
| - Remember to test with the published npm version before releasing to ensure compatibility | ||
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.
not important for the first PR, but we should use "@tsci/myuser.mycircuit" to promote the usage of our registry