Skip to content

Commit 8d4a37a

Browse files
committed
update 02
1 parent 68f6588 commit 8d4a37a

File tree

14 files changed

+1307
-947
lines changed

14 files changed

+1307
-947
lines changed

07-cloud/04-turborepo/02-turborepo/README.md

Lines changed: 82 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install
1515
Let's replace `npm-run-all` by `turborepo`:
1616

1717
```bash
18-
npm uninstall npm-run-all --save-dev
18+
npm uninstall npm-run-all
1919

2020
npm install turbo --save-dev
2121

@@ -30,7 +30,7 @@ _./turbo.json_
3030
```json
3131
{
3232
"$schema": "https://turbo.build/schema.json",
33-
"pipeline": {
33+
"tasks": {
3434
"start": {
3535
"cache": false,
3636
"persistent": true
@@ -52,6 +52,7 @@ _./package.json_
5252

5353
```diff
5454
...
55+
+ "packageManager": "npm@10.0.0",
5556
"scripts": {
5657
- "start": "run-p start:*",
5758
+ "start": "turbo start"
@@ -64,6 +65,8 @@ _./package.json_
6465
...
6566
```
6667

68+
> [Add a packageManager](https://turbo.build/repo/docs/getting-started/add-to-existing-repository#add-a-packagemanager-field-to-root-packagejson)
69+
6770
Run it:
6871

6972
```bash
@@ -78,7 +81,7 @@ _./turbo.json_
7881
```diff
7982
{
8083
"$schema": "https://turbo.build/schema.json",
81-
"pipeline": {
84+
"tasks": {
8285
"start": {
8386
"cache": false,
8487
"persistent": true
@@ -114,87 +117,39 @@ _./helpers/motto-helpers/package.json_
114117
```diff
115118
...
116119
"scripts": {
117-
"start": "run-p -l type-check:watch \"build -- --watch\"",
118120
- "build": "npm run type-check && vite build",
119121
+ "build": "vite build",
120-
"type-check": "tsc --noEmit",
121-
"type-check:watch": "npm run type-check -- --watch --preserveWatchOutput"
122+
"type-check": "tsc --noEmit"
122123
},
123124
...
124125
```
125126

126-
Run it:
127-
128-
```bash
129-
npm run build
130-
131-
```
132-
133-
> NOTES:
134-
>
135-
> Run multiple times to check that it is cached.
136-
>
137-
> Add some error in `motto-helpers` to check that the process is stopped.
127+
Let's add the `.turbo` folder to `.gitignore`:
138128

139-
If we want to apply the same approach to the `type-check:watch` command, we can run [multiple tasks](https://turbo.build/repo/docs/core-concepts/monorepos/running-tasks#turborepo-can-multitask) in parallel:
140-
141-
_./helpers/motto-helpers/package.json_
129+
_./.gitignore_
142130

143131
```diff
144-
...
145-
"scripts": {
146-
- "start": "run-p -l type-check:watch \"build -- --watch\"",
147-
+ "start": "npm run build -- --watch",
148-
"build": "vite build",
149-
"type-check": "tsc --noEmit",
150-
"type-check:watch": "npm run type-check -- --watch --preserveWatchOutput"
151-
},
152-
...
153-
```
154-
155-
Update `turbo.json`:
156-
157-
_./turbo.json_
132+
node_modules
133+
dist
134+
+.turbo
158135

159-
```diff
160-
...
161-
"start": {
162-
"cache": false,
163-
"persistent": true
164-
},
165-
+ "type-check:watch": {},
166-
"build": {
167-
...
168-
```
169-
170-
Update `package.json`:
171-
172-
_./package.json_
173-
174-
```diff
175-
...
176-
"scripts": {
177-
- "start": "turbo start",
178-
+ "start": "turbo start type-check:watch",
179-
"build": "turbo build"
180-
},
181-
...
182136
```
183137

184-
Uninstall `npm-run-all` in `motto-helpers`:
185-
186-
```bash
187-
npm uninstall npm-run-all --save-dev -w @my-org/motto-helpers
188-
189-
```
138+
> [Edit .gitignore](https://turbo.build/repo/docs/getting-started/add-to-existing-repository#edit-gitignore)
190139
191140
Run it:
192141

193142
```bash
194-
npm start
143+
npm run build
195144

196145
```
197146

147+
> NOTES:
148+
>
149+
> Run multiple times to check that it is cached.
150+
>
151+
> Add some error in `motto-helpers` to check that the process is stopped.
152+
198153
If we have more than one project where we need to run the `build` command, and they depend on each other, it will automatically resolve the execution order according to the dependencies.
199154

200155
Let's update the `house-helpers` project to add the `build` command:
@@ -212,30 +167,27 @@ _./helpers/house-helpers/package.json_
212167
"version": "1.0.0",
213168
- "private": true,
214169
+ "private": false,
170+
"sideEffects": false,
215171
"author": "Lemoncode",
216172
"license": "MIT",
217-
- "types": "src/index.ts",
218-
- "type": "module",
219-
- "main": "src/index.ts",
220173
+ "files": [
221174
+ "dist"
222175
+ ],
223-
+ "type": "module",
224-
+ "module": "dist/house-helpers.js",
225-
+ "main": "dist/house-helpers.umd.cjs",
176+
"type": "module",
177+
+ "module": "dist/index.js",
178+
+ "main": "dist/index.umd.cjs",
226179
+ "types": "dist/index.d.ts",
227-
+ "exports": {
180+
"exports": {
181+
- ".": "./src/index.ts"
228182
+ ".": {
229-
+ "import": "./dist/house-helpers.js",
230-
+ "require": "./dist/house-helpers.umd.cjs",
231-
+ "types": "./dist/index.d.ts"
232-
+ }
233-
+ },
183+
+ "types": "./dist/index.d.ts",
184+
+ "import": "./dist/index.js",
185+
+ "require": "./dist/index.umd.cjs"
186+
+ },
187+
},
234188
+ "scripts": {
235-
+ "start": "npm run build -- --watch",
236189
+ "build": "vite build",
237190
+ "type-check": "tsc --noEmit",
238-
+ "type-check:watch": "npm run type-check -- --watch --preserveWatchOutput"
239191
+ },
240192
...
241193

@@ -255,6 +207,7 @@ export default defineConfig({
255207
lib: {
256208
entry: "src/index.ts",
257209
name: "HouseHelpers",
210+
fileName: "index",
258211
},
259212
},
260213
});
@@ -264,7 +217,7 @@ export default defineConfig({
264217
Run it:
265218

266219
```bash
267-
npm start
220+
npm run build
268221

269222
```
270223

@@ -279,12 +232,11 @@ _./turbo.json_
279232
```diff
280233
{
281234
"$schema": "https://turbo.build/schema.json",
282-
"pipeline": {
235+
"tasks": {
283236
"start": {
284237
"cache": false,
285238
"persistent": true,
286239
},
287-
"type-check:watch": {},
288240
"build": {
289241
"outputs": ["dist/**/*"],
290242
- "dependsOn": ["type-check"]
@@ -305,7 +257,7 @@ _./turbo.json_
305257
```diff
306258
{
307259
"$schema": "https://turbo.build/schema.json",
308-
"pipeline": {
260+
"tasks": {
309261
"start": {
310262
"cache": false,
311263
"persistent": true
@@ -330,29 +282,28 @@ npm run build
330282

331283
```
332284

333-
Knowing the above, we could have some errors if we are running the `start` command without running the `build` command before (for example if we remove the dist folder on helpers):
285+
Knowing the above, we can build the helpers projects before starting the applications:
334286

335287

336288
```bash
337289
npm start
338290

339291
```
340292

293+
341294
Let's update it:
342295

296+
343297
_./turbo.json_
344298

345299
```diff
346300
{
347301
"$schema": "https://turbo.build/schema.json",
348-
"pipeline": {
302+
"tasks": {
349303
"start": {
350304
"cache": false,
351305
"persistent": true,
352-
+ "dependsOn": ["build"]
353-
},
354-
"type-check:watch": {
355-
+ "dependsOn": ["build"]
306+
+ "dependsOn": ["^build"]
356307
},
357308
"build": {
358309
"outputs": ["dist/**/*"],
@@ -368,6 +319,30 @@ _./turbo.json_
368319

369320
> NOTE: We cannot use a `watch mode` command such as `dependsOn` because it will block the process.
370321
322+
Update the `package.json`:
323+
324+
_./package.json_
325+
326+
```diff
327+
...
328+
"scripts": {
329+
"start": "turbo start",
330+
+ "start": "turbo watch start",
331+
...
332+
333+
```
334+
335+
> [Using watch](https://turbo.build/repo/docs/reference/watch)
336+
337+
Run it:
338+
339+
```bash
340+
npm start
341+
342+
```
343+
344+
> Make some changes in `house-helpers` and `motto-helpers` to check that the process is restarted.
345+
371346
Finally, if we only want to run a command for some projects, we can do it using the [filter](https://turbo.build/repo/docs/core-concepts/monorepos/filtering#multiple-filters) flag:
372347

373348

@@ -378,6 +353,24 @@ npm start -- --filter=@my-org/house-stark
378353

379354
> Another filter example if we want projects inside folder: `--filter='./helpers/*'`
380355
356+
Or even run multiple tasks at the same time:
357+
358+
_./package.json_
359+
360+
```diff
361+
...
362+
"scripts": {
363+
"start": "turbo watch start",
364+
- "build": "turbo build"
365+
+ "build": "turbo build test"
366+
},
367+
...
368+
369+
```
370+
371+
> [Multiple tasks](https://turbo.build/repo/docs/crafting-your-repository/running-tasks#running-multiple-tasks)
372+
373+
381374
# About Basefactor + Lemoncode
382375

383376
We are an innovating team of Javascript experts, passionate about turning your ideas into robust products.

07-cloud/04-turborepo/02-turborepo/apps/baratheon/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"dependencies": {
1010
"@my-org/house-helpers": "^1.0.0",
1111
"@my-org/motto-helpers": "^1.0.0",
12-
"react": "^18.2.0",
13-
"react-dom": "^18.2.0"
12+
"react": "^19.0.0",
13+
"react-dom": "^19.0.0"
1414
},
1515
"devDependencies": {
16-
"@types/react": "^18.2.66",
17-
"@types/react-dom": "^18.2.22",
18-
"@vitejs/plugin-react": "^4.2.1",
19-
"typescript": "^5.4.2",
20-
"vite": "^5.1.6"
16+
"@types/react": "^19.0.10",
17+
"@types/react-dom": "^19.0.4",
18+
"@vitejs/plugin-react": "^4.3.4",
19+
"typescript": "^5.8.2",
20+
"vite": "^6.2.0"
2121
}
2222
}

07-cloud/04-turborepo/02-turborepo/apps/lannister/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"dependencies": {
1010
"@my-org/house-helpers": "^1.0.0",
1111
"@my-org/motto-helpers": "^1.0.0",
12-
"react": "^18.2.0",
13-
"react-dom": "^18.2.0"
12+
"react": "^19.0.0",
13+
"react-dom": "^19.0.0"
1414
},
1515
"devDependencies": {
16-
"@types/react": "^18.2.66",
17-
"@types/react-dom": "^18.2.22",
18-
"@vitejs/plugin-react": "^4.2.1",
19-
"typescript": "^5.4.2",
20-
"vite": "^5.1.6"
16+
"@types/react": "^19.0.10",
17+
"@types/react-dom": "^19.0.4",
18+
"@vitejs/plugin-react": "^4.3.4",
19+
"typescript": "^5.8.2",
20+
"vite": "^6.2.0"
2121
}
2222
}

07-cloud/04-turborepo/02-turborepo/apps/stark/package.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
"dependencies": {
1010
"@my-org/house-helpers": "^1.0.0",
1111
"@my-org/motto-helpers": "^1.0.0",
12-
"react": "^18.2.0",
13-
"react-dom": "^18.2.0"
12+
"react": "^19.0.0",
13+
"react-dom": "^19.0.0"
1414
},
1515
"devDependencies": {
16-
"@types/react": "^18.2.66",
17-
"@types/react-dom": "^18.2.22",
18-
"@vitejs/plugin-react": "^4.2.1",
19-
"typescript": "^5.4.2",
20-
"vite": "^5.1.6"
16+
"@types/react": "^19.0.10",
17+
"@types/react-dom": "^19.0.4",
18+
"@vitejs/plugin-react": "^4.3.4",
19+
"typescript": "^5.8.2",
20+
"vite": "^6.2.0"
2121
}
2222
}

0 commit comments

Comments
 (0)