Skip to content

Commit c94d268

Browse files
Merge pull request #497 from jogelin/nx-publish-alignment
chore: Use Nx to publish libraries locally/npm and align scripts
2 parents bb87266 + 23d0f95 commit c94d268

File tree

18 files changed

+376
-149
lines changed

18 files changed

+376
-149
lines changed

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,78 @@
22

33
- [Readme for Module Federation](./libs/mf/README.md)
44
- [Readme for Native Federation](./libs/native-federation/README.md)
5+
6+
## Local Development
7+
8+
<details>
9+
<summary>Playground App</summary>
10+
11+
You can test directly the libraries by using the playground application:
12+
13+
1. Start the `host` application:
14+
```shell
15+
npx nx run playground:serve
16+
```
17+
2. Start the `remote` application:
18+
```shell
19+
npx nx run mfe1:serve --port 3001
20+
```
21+
22+
By using that approach you can test your modifications on the libraries.
23+
24+
</details>
25+
26+
<details>
27+
<summary>Test Library on external repository</summary>
28+
29+
If you want to test the modifications directly on your application, you can follow the steps:
30+
31+
1. Start the local registry [Verdaccio](https://verdaccio.org/):
32+
```shell
33+
npx nx run local-registry
34+
```
35+
2. Then you can publish the libraries by using:
36+
37+
- For Module federation:
38+
```shell
39+
npm run publish-local:mf
40+
```
41+
- For Native federation:
42+
43+
```shell
44+
npm run publish-local:nf
45+
```
46+
47+
This will first `build` the libraries and `publish` them to [http://localhost:4873](http://localhost:4873)
48+
49+
3. Then just re-run the `install` on the other repo with you favorite package manager.
50+
51+
By default, the version from the `package.json` will be used. However, you can provide the version for a specific library by using:
52+
53+
```shell
54+
npx nx run native-federation:publish-local -- --ver=17.0.8
55+
```
56+
57+
</details>
58+
<details>
59+
<summary>Publish Libraries</summary>
60+
61+
Follow these steps to publish all libraries on `npm`:
62+
63+
- For Module federation:
64+
```shell
65+
npm run publish:mf
66+
```
67+
- For Native federation:
68+
```shell
69+
npm run publish:nf
70+
```
71+
This will first `build` the libraries and `publish` them to `npm registry`.
72+
73+
By default, the version from the `package.json` will be used and the tag will be `next`. However, you can provide the version and the tag for a specific library by using:
74+
75+
```shell
76+
npx nx run native-federation:publish -- --ver=17.0.8 --tag=latest
77+
```
78+
79+
</details>

libs/mf-runtime/project.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"targets": {
88
"build": {
99
"executor": "@nx/angular:package",
10+
"outputs": ["{workspaceRoot}/dist/libs/mf-runtime"],
1011
"options": {
1112
"tsConfig": "libs/mf-runtime/tsconfig.lib.json",
1213
"project": "libs/mf-runtime/ng-package.json"
@@ -33,7 +34,21 @@
3334
"options": {
3435
"jestConfig": "libs/mf-runtime/jest.config.ts"
3536
}
37+
},
38+
"publish": {
39+
"dependsOn": ["build"],
40+
"executor": "nx:run-commands",
41+
"options": {
42+
"command": "node tools/scripts/publish.mjs mf-runtime npm {args.ver} {args.tag}"
43+
}
44+
},
45+
"publish-local": {
46+
"dependsOn": ["build"],
47+
"executor": "nx:run-commands",
48+
"options": {
49+
"command": "node tools/scripts/publish.mjs mf-runtime verdaccio {args.ver}"
50+
}
3651
}
3752
},
38-
"tags": []
53+
"tags": ["org:angular-architects", "scope:mf"]
3954
}

libs/mf-tools/project.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"targets": {
88
"build": {
99
"executor": "@nx/angular:package",
10+
"outputs": ["{workspaceRoot}/dist/libs/mf-tools"],
1011
"options": {
1112
"tsConfig": "libs/mf-tools/tsconfig.lib.json",
1213
"project": "libs/mf-tools/ng-package.json"
@@ -33,7 +34,21 @@
3334
"options": {
3435
"jestConfig": "libs/mf-tools/jest.config.ts"
3536
}
37+
},
38+
"publish": {
39+
"dependsOn": ["build"],
40+
"executor": "nx:run-commands",
41+
"options": {
42+
"command": "node tools/scripts/publish.mjs mf-tools npm {args.ver} {args.tag}"
43+
}
44+
},
45+
"publish-local": {
46+
"dependsOn": ["build"],
47+
"executor": "nx:run-commands",
48+
"options": {
49+
"command": "node tools/scripts/publish.mjs mf-tools verdaccio {args.ver}"
50+
}
3651
}
3752
},
38-
"tags": []
53+
"tags": ["org:angular-architects", "scope:mf"]
3954
}

libs/mf/post-build.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const index = fs.readFileSync(path.join(__dirname, 'src/index.ts'), {
5+
encoding: 'utf-8',
6+
});
7+
fs.writeFileSync(
8+
path.join(__dirname, '../../dist/libs/mf/src/index.js'),
9+
index
10+
);
11+
12+
const nguniversal = fs.readFileSync(
13+
path.join(__dirname, 'src/nguniversal.ts'),
14+
{
15+
encoding: 'utf-8',
16+
}
17+
);
18+
fs.writeFileSync(
19+
path.join(__dirname, '../../dist/libs/mf/src/nguniversal.js'),
20+
nguniversal
21+
);

libs/mf/project.json

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,6 @@
44
"sourceRoot": "libs/mf/src",
55
"projectType": "library",
66
"targets": {
7-
"lint": {
8-
"executor": "@nx/eslint:lint",
9-
"options": {
10-
"lintFilePatterns": ["libs/mf/**/*.ts"]
11-
},
12-
"outputs": ["{options.outputFile}"]
13-
},
14-
"test": {
15-
"executor": "@nx/jest:jest",
16-
"outputs": ["{workspaceRoot}/coverage/libs/mf"],
17-
"options": {
18-
"jestConfig": "libs/mf/jest.config.ts"
19-
}
20-
},
217
"build": {
228
"executor": "@nx/js:tsc",
239
"outputs": ["{options.outputPath}"],
@@ -71,7 +57,47 @@
7157
}
7258
]
7359
}
60+
},
61+
"post-build": {
62+
"dependsOn": ["build"],
63+
"executor": "nx:run-commands",
64+
"outputs": [
65+
"{options.outputPath}/src/index.js",
66+
"{options.outputPath}/src/nguniversal.ts"
67+
],
68+
"options": {
69+
"cwd": "libs/mf",
70+
"command": "node post-build.js"
71+
}
72+
},
73+
"lint": {
74+
"executor": "@nx/eslint:lint",
75+
"options": {
76+
"lintFilePatterns": ["libs/mf/**/*.ts"]
77+
},
78+
"outputs": ["{options.outputFile}"]
79+
},
80+
"test": {
81+
"executor": "@nx/jest:jest",
82+
"outputs": ["{workspaceRoot}/coverage/libs/mf"],
83+
"options": {
84+
"jestConfig": "libs/mf/jest.config.ts"
85+
}
86+
},
87+
"publish": {
88+
"dependsOn": ["build", "post-build"],
89+
"executor": "nx:run-commands",
90+
"options": {
91+
"command": "node tools/scripts/publish.mjs mf npm {args.ver} {args.tag}"
92+
}
93+
},
94+
"publish-local": {
95+
"dependsOn": ["build", "post-build"],
96+
"executor": "nx:run-commands",
97+
"options": {
98+
"command": "node tools/scripts/publish.mjs mf verdaccio {args.ver}"
99+
}
74100
}
75101
},
76-
"tags": []
102+
"tags": ["org:angular-architects", "scope:mf"]
77103
}

libs/native-federation-core/project.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@
1717
]
1818
}
1919
},
20-
"publish": {
21-
"executor": "nx:run-commands",
22-
"options": {
23-
"command": "node tools/scripts/publish.mjs native-federation-core {args.ver} {args.tag}"
24-
},
25-
"dependsOn": [
26-
{
27-
"target": "build"
28-
}
29-
]
30-
},
3120
"lint": {
3221
"executor": "@nx/eslint:lint",
3322
"outputs": ["{options.outputFile}"],
@@ -41,7 +30,21 @@
4130
"options": {
4231
"jestConfig": "libs/native-federation-core/jest.config.ts"
4332
}
33+
},
34+
"publish": {
35+
"dependsOn": ["build"],
36+
"executor": "nx:run-commands",
37+
"options": {
38+
"command": "node tools/scripts/publish.mjs native-federation-core npm {args.ver} {args.tag}"
39+
}
40+
},
41+
"publish-local": {
42+
"dependsOn": ["build"],
43+
"executor": "nx:run-commands",
44+
"options": {
45+
"command": "node tools/scripts/publish.mjs native-federation-core verdaccio {args.ver}"
46+
}
4447
}
4548
},
46-
"tags": []
49+
"tags": ["org:softarc", "scope:nf"]
4750
}

libs/native-federation-esbuild/project.json

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,6 @@
1717
]
1818
}
1919
},
20-
"publish": {
21-
"executor": "nx:run-commands",
22-
"options": {
23-
"command": "node tools/scripts/publish.mjs native-federation-esbuild {args.ver} {args.tag}"
24-
},
25-
"dependsOn": [
26-
{
27-
"target": "build"
28-
}
29-
]
30-
},
3120
"lint": {
3221
"executor": "@nx/eslint:lint",
3322
"outputs": ["{options.outputFile}"],
@@ -41,7 +30,21 @@
4130
"options": {
4231
"jestConfig": "libs/native-federation-esbuild/jest.config.ts"
4332
}
33+
},
34+
"publish": {
35+
"dependsOn": ["build"],
36+
"executor": "nx:run-commands",
37+
"options": {
38+
"command": "node tools/scripts/publish.mjs native-federation-esbuild npm {args.ver} {args.tag}"
39+
}
40+
},
41+
"publish-local": {
42+
"dependsOn": ["build"],
43+
"executor": "nx:run-commands",
44+
"options": {
45+
"command": "node tools/scripts/publish.mjs native-federation-esbuild verdaccio {args.ver}"
46+
}
4447
}
4548
},
46-
"tags": []
49+
"tags": ["org:softarc", "scope:nf"]
4750
}

libs/native-federation-runtime/project.json

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@
3636
"libs/native-federation-runtime/**/*.html"
3737
]
3838
}
39+
},
40+
"publish": {
41+
"dependsOn": ["build"],
42+
"executor": "nx:run-commands",
43+
"options": {
44+
"command": "node tools/scripts/publish.mjs native-federation-runtime npm {args.ver} {args.tag}"
45+
}
46+
},
47+
"publish-local": {
48+
"dependsOn": ["build"],
49+
"executor": "nx:run-commands",
50+
"options": {
51+
"command": "node tools/scripts/publish.mjs native-federation-runtime verdaccio {args.ver}"
52+
}
3953
}
4054
},
41-
"tags": []
55+
"tags": ["org:softarc", "scope:nf"]
4256
}

libs/native-federation/post-build.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
4+
const index = fs.readFileSync(path.join(__dirname, 'src/index.ts'), {
5+
encoding: 'utf-8',
6+
});
7+
fs.writeFileSync(
8+
path.join(__dirname, '../../dist/libs/native-federation/src/index.js'),
9+
index
10+
);

libs/native-federation/project.json

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@
4747
]
4848
}
4949
},
50+
"post-build": {
51+
"dependsOn": ["build"],
52+
"executor": "nx:run-commands",
53+
"outputs": ["{options.outputPath}/src/index.js"],
54+
"options": {
55+
"cwd": "libs/native-federation",
56+
"command": "node post-build.js"
57+
}
58+
},
5059
"lint": {
5160
"executor": "@nx/eslint:lint",
5261
"outputs": ["{options.outputFile}"],
@@ -65,7 +74,21 @@
6574
"options": {
6675
"jestConfig": "libs/native-federation/jest.config.ts"
6776
}
77+
},
78+
"publish": {
79+
"dependsOn": ["build", "post-build"],
80+
"executor": "nx:run-commands",
81+
"options": {
82+
"command": "node tools/scripts/publish.mjs native-federation npm {args.ver} {args.tag}"
83+
}
84+
},
85+
"publish-local": {
86+
"dependsOn": ["build", "post-build"],
87+
"executor": "nx:run-commands",
88+
"options": {
89+
"command": "node tools/scripts/publish.mjs native-federation verdaccio {args.ver}"
90+
}
6891
}
6992
},
70-
"tags": []
93+
"tags": ["org:angular-architects", "scope:nf"]
7194
}

0 commit comments

Comments
 (0)