Skip to content

Commit a09c124

Browse files
authored
feat(create-rstack): add pnpm workspace template (#580)
1 parent c9a453c commit a09c124

27 files changed

Lines changed: 350 additions & 9 deletions

‎packages/create-rstack/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ npx create-rstack --dir my-project --template app-vanilla-ts --no-git
5050
- `lib-solid-ts` - TypeScript Solid library
5151
- `doc` - Basic documentation site
5252
- `doc-i18n` - Multilingual documentation site
53+
- `pnpm` - pnpm workspace
5354
- `turborepo` - Turborepo
5455
- `nx` - Nx
5556

‎packages/create-rstack/src/index.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const templateNames = [
4343
'lib-solid-ts',
4444
'doc',
4545
'doc-i18n',
46+
'pnpm',
4647
'turborepo',
4748
'nx',
4849
];
@@ -57,7 +58,7 @@ const resolveTemplateName = (template: string): string => {
5758

5859
const getTemplateName = async ({ template }: Argv): Promise<string> => {
5960
if (typeof template === 'string') {
60-
if (/^(?:app|lib|doc|turborepo|nx)(?:-|$)/u.test(template)) {
61+
if (/^(?:app|lib|doc|pnpm|turborepo|nx)(?:-|$)/u.test(template)) {
6162
return resolveTemplateName(template);
6263
}
6364

@@ -81,6 +82,7 @@ const getTemplateName = async ({ template }: Argv): Promise<string> => {
8182
await select({
8283
message: 'Select monorepo tool',
8384
options: [
85+
{ value: 'pnpm', label: 'pnpm workspace' },
8486
{ value: 'turborepo', label: 'Turborepo', hint: 'pnpm' },
8587
{ value: 'nx', label: 'Nx', hint: 'pnpm' },
8688
],
@@ -239,6 +241,6 @@ await create({
239241
builtinTools: [],
240242
getTemplateName,
241243
getPackageManager: ({ templateName }) =>
242-
['turborepo', 'nx'].includes(templateName) ? 'pnpm' : undefined,
244+
['pnpm', 'turborepo', 'nx'].includes(templateName) ? 'pnpm' : undefined,
243245
onGitResolved: injectStagedSetup,
244246
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# pnpm workspace + Rstack
2+
3+
## Setup
4+
5+
```bash
6+
pnpm install
7+
```
8+
9+
## Structure
10+
11+
- `apps/web`: React application.
12+
- `packages/ui`: Shared UI components.
13+
- `tsconfig.base.json`: Shared TypeScript configuration.
14+
15+
## Scripts
16+
17+
Run from the repository root:
18+
19+
- `pnpm run build`: Build all packages in dependency order.
20+
- `pnpm run dev`: Build shared packages, then start the web app and watch the shared UI package.
21+
- `pnpm run test`: Build shared packages, then run tests.
22+
- `pnpm run check`: Run lint, formatting, and TypeScript checks.
23+
- `pnpm run lint`: Lint the workspace.
24+
- `pnpm run format`: Format the workspace.
25+
26+
Run `pnpm run build` before `pnpm run check`.
27+
28+
Use `pnpm --filter <package-name> <script>` to run a script in one package.
29+
30+
## Learn more
31+
32+
- [Rstack CLI monorepo guide](https://rstack.rs/guide/monorepo)
33+
- [pnpm workspace documentation](https://pnpm.io/workspaces)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "web",
3+
"version": "0.0.0",
4+
"private": true,
5+
"type": "module",
6+
"scripts": {
7+
"build": "rs build",
8+
"dev": "rs dev",
9+
"preview": "rs preview",
10+
"test": "rs test"
11+
},
12+
"dependencies": {
13+
"@repo/ui": "workspace:^",
14+
"react": "^19.3.0",
15+
"react-dom": "^19.3.0"
16+
},
17+
"devDependencies": {
18+
"@rsbuild/plugin-react": "^2.1.1",
19+
"@testing-library/dom": "^10.4.2",
20+
"@testing-library/jest-dom": "^7.0.1",
21+
"@testing-library/react": "^16.3.3",
22+
"@types/react": "^19.3.0",
23+
"@types/react-dom": "^19.3.0",
24+
"happy-dom": "^21.0.1"
25+
}
26+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Configuration guide: https://rstack.rs/config
2+
import { define } from 'rstack';
3+
4+
define.app(async () => {
5+
const { pluginReact } = await import('@rsbuild/plugin-react');
6+
return {
7+
plugins: [pluginReact()],
8+
};
9+
});
10+
11+
define.test({
12+
setupFiles: ['./tests/rstest.setup.ts'],
13+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { Button } from '@repo/ui/button';
2+
3+
export function App() {
4+
return (
5+
<main>
6+
<h1>Web</h1>
7+
<p>pnpm workspace + Rstack CLI</p>
8+
<p>Edit apps/web/src/App.tsx to get started.</p>
9+
<Button onClick={() => window.alert('Hello from @repo/ui!')}>
10+
Shared button
11+
</Button>
12+
<nav>
13+
<a href="https://rstack.rs">Rstack documentation</a>
14+
</nav>
15+
</main>
16+
);
17+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
body {
2+
margin: 0;
3+
font-family: system-ui, sans-serif;
4+
color: #202124;
5+
background: #f8f9fa;
6+
}
7+
8+
main {
9+
max-width: 640px;
10+
margin: 15vh auto;
11+
padding: 24px;
12+
}
13+
14+
button {
15+
padding: 10px 16px;
16+
border: 0;
17+
border-radius: 8px;
18+
color: white;
19+
background: #5755d9;
20+
cursor: pointer;
21+
}
22+
23+
nav {
24+
display: flex;
25+
gap: 20px;
26+
margin-top: 24px;
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { StrictMode } from 'react';
2+
import { createRoot } from 'react-dom/client';
3+
import { App } from './App';
4+
import './index.css';
5+
6+
const root = document.getElementById('root');
7+
if (root) {
8+
createRoot(root).render(
9+
<StrictMode>
10+
<App />
11+
</StrictMode>,
12+
);
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { expect, test } from 'rstack/test';
2+
import { render, screen } from '@testing-library/react';
3+
import { App } from '../src/App';
4+
5+
test('renders the web app with the shared UI package', () => {
6+
render(<App />);
7+
expect(screen.getByRole('heading', { name: 'Web' })).toBeInTheDocument();
8+
expect(
9+
screen.getByRole('button', { name: 'Shared button' }),
10+
).toBeInTheDocument();
11+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from 'rstack/test';
2+
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';
3+
4+
expect.extend(jestDomMatchers);

0 commit comments

Comments
 (0)