Skip to content

Commit 6c97162

Browse files
committed
update 01-workspaces
1 parent 4f2fcde commit 6c97162

17 files changed

Lines changed: 1322 additions & 1389 deletions

File tree

07-cloud/04-turborepo/00-boilerplate/house-helpers/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
"name": "@my-org/house-helpers",
33
"version": "1.0.0",
44
"private": true,
5+
"sideEffects": false,
56
"author": "Lemoncode",
67
"license": "MIT",
7-
"types": "src/index.ts",
88
"type": "module",
9-
"main": "src/index.ts",
9+
"exports": {
10+
".": "./src/index.ts"
11+
},
1012
"devDependencies": {
1113
"typescript": "^5.8.2"
1214
}

07-cloud/04-turborepo/00-boilerplate/house-helpers/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"moduleResolution": "bundler",
66
"skipLibCheck": true,
77
"isolatedModules": true,
8+
"esModuleInterop": true,
89
"outDir": "dist",
910
"jsx": "react-jsx"
1011
},

07-cloud/04-turborepo/00-boilerplate/motto-helpers/package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22
"name": "@my-org/motto-helpers",
33
"version": "1.0.0",
44
"private": false,
5+
"sideEffects": false,
56
"author": "Lemoncode",
67
"license": "MIT",
78
"files": [
89
"dist"
910
],
1011
"type": "module",
11-
"module": "./dist/motto-helpers.js",
12-
"main": "./dist/motto-helpers.umd.cjs",
12+
"module": "./dist/index.js",
13+
"main": "./dist/index.umd.cjs",
1314
"types": "./dist/index.d.ts",
1415
"exports": {
1516
".": {
16-
"import": "./dist/motto-helpers.js",
17-
"require": "./dist/motto-helpers.umd.cjs",
18-
"types": "./dist/index.d.ts"
17+
"types": "./dist/index.d.ts",
18+
"import": "./dist/index.js",
19+
"require": "./dist/index.umd.cjs"
1920
}
2021
},
2122
"scripts": {

07-cloud/04-turborepo/00-boilerplate/motto-helpers/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"moduleResolution": "bundler",
66
"skipLibCheck": true,
77
"isolatedModules": true,
8+
"esModuleInterop": true,
89
"outDir": "dist",
910
"jsx": "react-jsx"
1011
},

07-cloud/04-turborepo/00-boilerplate/motto-helpers/vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ export default defineConfig({
77
lib: {
88
entry: "src/index.ts",
99
name: "MottoHelpers",
10+
fileName: "index",
1011
},
1112
},
1213
});
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
node_modules
22
dist
3-
.turbo

07-cloud/04-turborepo/01-workspaces/README.md

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,11 @@
22

33
In this example, we are going to learn how we can work with `npm` workspaces.
44

5-
We will start from `00-boilerplate`.
5+
We will start from `scratch` but we will copy some projects from `00-boilerplate`.
66

77
## Steps to build it
88

9-
Let's start by creating the main `package.json` (we can use `npm init -y` to create it and then edit it):
10-
11-
```bash
12-
npm init -y
13-
14-
```
15-
16-
Let's edit:
9+
Let's start by creating the main `package.json`:
1710

1811
_./package.json_
1912

@@ -31,7 +24,6 @@ _./.gitignore_
3124
```
3225
node_modules
3326
dist
34-
.turbo
3527
3628
```
3729

@@ -81,7 +73,7 @@ npm install
8173

8274
```
8375

84-
Let's remove the `my-workspace` project and copy the `house-helpers` and `motto-helpers` projects from the `00-boilerplate` folder.
76+
Let's remove the `my-workspace` project, the root `package-lock.json` and copy the `house-helpers` and `motto-helpers` projects from the `00-boilerplate` folder.
8577

8678
Let's run `npm install` again:
8779

@@ -90,7 +82,7 @@ npm install
9082

9183
```
9284

93-
Notice that the `package-lock.json` has been updated with the `house-helpers` and `motto-helpers` projects dependencies and the symlinks have been created ( inside `node_modules/@my-org` folder).
85+
Notice that the `package-lock.json` has been updated with the `house-helpers` and `motto-helpers` projects dependencies and the symlinks have been created (inside `node_modules/@my-org` folder).
9486

9587
> NOTE: also, we only have the root `node_modules` folder and the `package-lock.json` file, not inside each project.
9688
@@ -103,9 +95,10 @@ _./helpers/house-helpers/package.json_
10395
```json
10496
{
10597
...
106-
"types": "src/index.ts",
10798
"type": "module",
108-
"main": "src/index.ts",
99+
"exports": {
100+
".": "./src/index.ts"
101+
},
109102
}
110103

111104
```
@@ -120,14 +113,14 @@ _./helpers/motto-helpers/package.json_
120113
{
121114
...
122115
"type": "module",
123-
"module": "./dist/motto-helpers.js",
124-
"main": "./dist/motto-helpers.umd.cjs",
116+
"module": "./dist/index.js",
117+
"main": "./dist/index.umd.cjs",
125118
"types": "./dist/index.d.ts",
126119
"exports": {
127120
".": {
128-
"import": "./dist/motto-helpers.js",
129-
"require": "./dist/motto-helpers.umd.cjs",
130-
"types": "./dist/index.d.ts"
121+
"types": "./dist/index.d.ts",
122+
"import": "./dist/index.js",
123+
"require": "./dist/index.umd.cjs"
131124
}
132125
},
133126
"scripts": {
@@ -139,13 +132,6 @@ _./helpers/motto-helpers/package.json_
139132

140133
```
141134

142-
Delete the `package-lock.json` file to force `npm` to create a new one:
143-
144-
```bash
145-
rm package-lock.json
146-
147-
```
148-
149135
This project has the `house-helpers` project as a dependency because we are sharing the `House` enum type. We are going to install it using the workspace :
150136

151137
```bash
@@ -244,13 +230,7 @@ npm install
244230
Every app will have the `house-helpers` and `motto-helpers` projects as dependencies. Let's install them using the workspace:
245231

246232
```bash
247-
npm install @my-org/house-helpers @my-org/motto-helpers -w @my-org/house-baratheon
248-
249-
npm install @my-org/house-helpers @my-org/motto-helpers -w @my-org/house-lannister
250-
251-
npm install @my-org/house-helpers @my-org/motto-helpers -w @my-org/house-stark
252-
253-
npm install @my-org/house-helpers @my-org/motto-helpers -w @my-org/house-targaryen
233+
npm install @my-org/house-helpers @my-org/motto-helpers -w @my-org/house-baratheon -w @my-org/house-lannister -w @my-org/house-stark -w @my-org/house-targaryen
254234

255235
```
256236

@@ -278,7 +258,7 @@ export default App;
278258

279259
```
280260

281-
> NOTE: Rest app projects are updated.
261+
> NOTE: The rest app projects are updated.
282262
283263
If we want to run all the projects at the same time, [npm has some flags](https://docs.npmjs.com/cli/v7/using-npm/workspaces#ignoring-missing-scripts) to run multiple workspaces commands at the same time:
284264

@@ -289,6 +269,15 @@ npm start --workspaces --if-present
289269

290270
> But it doesn't work with watch mode because it blocks the execution on the first project.
291271
272+
Another option is to run the commands in parallel using the `&` operator:
273+
274+
```bash
275+
npm start -w @my-org/house-stark & npm start -w @my-org/house-targaryen
276+
277+
```
278+
279+
> But it doesn't work if put it in the `package.json` > `scripts` fiel on windows because it using the `cmd` shell by default and it doesn't support the `&` operator.
280+
292281
Let's install a third party library [npm-run-all](https://www.npmjs.com/package/npm-run-all) to run commands in parallel:
293282

294283
```bash

07-cloud/04-turborepo/01-workspaces/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/01-workspaces/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/01-workspaces/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)