Skip to content

Commit bdbe7e9

Browse files
authored
feat: npm workspaces (#326)
* feat: npm workspaces Signed-off-by: Miroslav Bajtoš <[email protected]> * fix CI + move `standard` to monorepo root Signed-off-by: Miroslav Bajtoš <[email protected]> * monorepo package name Signed-off-by: Miroslav Bajtoš <[email protected]> * ci: run CI for all pull requests Signed-off-by: Miroslav Bajtoš <[email protected]> * move mocha to sub-packages Signed-off-by: Miroslav Bajtoš <[email protected]> * add standard to child workspaces Signed-off-by: Miroslav Bajtoš <[email protected]> * fix CI step to migrate the DB Signed-off-by: Miroslav Bajtoš <[email protected]> * Rework Dockerfile to use `npm start --workspace` Signed-off-by: Miroslav Bajtoš <[email protected]> * ci: fix build-publish Signed-off-by: Miroslav Bajtoš <[email protected]> * fix dependabot Signed-off-by: Miroslav Bajtoš <[email protected]> * another fix for Dependabot Signed-off-by: Miroslav Bajtoš <[email protected]> * fix build-publish to test publish, not api Signed-off-by: Miroslav Bajtoš <[email protected]> * add postgrator to spark-publish dev-dependencies Signed-off-by: Miroslav Bajtoš <[email protected]> * minor fixes Signed-off-by: Miroslav Bajtoš <[email protected]> --------- Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent c7d99f5 commit bdbe7e9

File tree

9 files changed

+173
-90
lines changed

9 files changed

+173
-90
lines changed

.github/dependabot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ updates:
33
- package-ecosystem: "npm"
44
directories:
55
- "/"
6-
- "/spark-publish"
76
schedule:
87
interval: "daily"
98
time: "09:00"
109
timezone: "Europe/Berlin"
10+
versioning-strategy: increase
1111
commit-message:
1212
prefix: "deps"
1313
prefix-development: "deps(dev)"

.github/workflows/ci.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ on:
33
push:
44
branches: [main]
55
pull_request:
6-
branches: [main]
76

87
jobs:
98
build-api:
@@ -25,13 +24,14 @@ jobs:
2524
env:
2625
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
2726
GLIF_TOKEN: ${{ secrets.GLIF_TOKEN }}
27+
NPM_CONFIG_WORKSPACE: spark-api
2828
steps:
2929
- uses: actions/checkout@v4
3030
- uses: actions/setup-node@v4
3131
with:
3232
node-version: 20
3333
- run: npm ci
34-
- run: npm run test:api
34+
- run: npm test
3535

3636
build-publish:
3737
runs-on: ubuntu-latest
@@ -51,14 +51,25 @@ jobs:
5151
--health-retries 5
5252
env:
5353
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres
54+
NPM_CONFIG_WORKSPACE: spark-publish
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: actions/setup-node@v4
58+
with:
59+
node-version: 20
60+
- run: npm ci
61+
- run: node bin/migrate.js
62+
- run: npm test
63+
64+
lint-all:
65+
runs-on: ubuntu-latest
5466
steps:
5567
- uses: actions/checkout@v4
5668
- uses: actions/setup-node@v4
5769
with:
5870
node-version: 20
5971
- run: npm ci
60-
- run: npm run migrate
61-
- run: npm run test:publish
72+
- run: npm run lint
6273

6374
docker-build:
6475
runs-on: ubuntu-latest
@@ -94,7 +105,7 @@ jobs:
94105

95106
deploy-api:
96107
if: github.ref == 'refs/heads/main'
97-
needs: [build-api, build-publish, docker-build, docker-build]
108+
needs: [build-api, build-publish, docker-build]
98109
runs-on: ubuntu-latest
99110
steps:
100111
- uses: actions/checkout@v4
@@ -123,7 +134,7 @@ jobs:
123134
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
124135
deploy-publish:
125136
if: github.ref == 'refs/heads/main'
126-
needs: [build-api, build-publish, docker-build, docker-build]
137+
needs: [build-api, build-publish, docker-build]
127138
runs-on: ubuntu-latest
128139
steps:
129140
- uses: actions/checkout@v4

.mocharc.cjs

Lines changed: 0 additions & 15 deletions
This file was deleted.

Dockerfile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,13 @@ RUN apt-get update -qq && \
2626
# to install all modules: "npm install --production=false".
2727
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
2828
COPY --link package-lock.json package.json ./
29-
RUN npm ci
29+
30+
# We cannot use a wildcard until `COPY --parents` is stabilised
31+
# See https://docs.docker.com/reference/dockerfile/#copy---parents
32+
COPY --link spark-api/package.json ./spark-api/
33+
COPY --link spark-publish/package.json ./spark-publish/
34+
35+
RUN npm ci --workspaces
3036

3137
# Copy application code
3238
COPY --link . .
@@ -44,6 +50,6 @@ ARG SERVICE
4450

4551
# ARGs are not preserved at runtime, we need to store the value
4652
# as a default value of an ENV var
47-
ENV SCRIPT="start:${SERVICE}"
53+
ENV WORKSPACE="spark-${SERVICE}"
4854

49-
CMD npm run ${SCRIPT}
55+
CMD npm start --workspace ${WORKSPACE}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ docker run -d --name spark-db \
8989
Start the API service:
9090

9191
```bash
92-
npm run start:api
92+
npm start --workspace spark-api
9393
```
9494

9595
Run tests and linters:
9696

9797
```bash
98-
npm run test:api
98+
npm test --workspace spark-api
99+
npm run lint --workspace spark-api
99100
```
100101

101102
## Deployment

package-lock.json

Lines changed: 62 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,20 @@
11
{
2-
"name": "@filecoin-station/spark-api",
2+
"name": "@filecoin-station/spark-api-monorepo",
33
"private": true,
4-
"version": "0.0.0",
54
"license": "MIT",
65
"repository": "filecoin-station/spark-api",
76
"type": "module",
8-
"description": "API for SPARK",
7+
"workspaces": [
8+
"spark-api",
9+
"spark-publish"
10+
],
911
"scripts": {
1012
"migrate": "node bin/migrate.js",
11-
"start:api": "node spark-api/bin/spark.js",
12-
"start:publish": "node spark-publish/bin/spark-publish.js",
13-
"test:api": "mocha spark-api/test/**/*.js",
14-
"test:publish": "mocha spark-publish/test/**/*.js",
15-
"test": "standard && mocha"
13+
"lint": "standard",
14+
"test": "npm run lint && npm test --workspaces"
1615
},
1716
"devDependencies": {
18-
"@flydotio/dockerfile": "^0.5.7",
19-
"light-my-request": "^5.13.0",
20-
"mocha": "^10.4.0",
21-
"standard": "^17.1.0",
22-
"varint": "^6.0.0"
23-
},
24-
"dependencies": {
25-
"@filecoin-station/spark-impact-evaluator": "^1.0.0",
26-
"@glif/filecoin-address": "^3.0.5",
27-
"@influxdata/influxdb-client": "^1.33.2",
28-
"@ipld/car": "^5.3.0",
29-
"@sentry/node": "^8.5.0",
30-
"@ucanto/core": "^10.0.1",
31-
"@ucanto/principal": "^9.0.1",
32-
"@web3-storage/access": "^18.3.2",
33-
"@web3-storage/w3up-client": "^13.1.1",
34-
"compare-versions": "^6.1.0",
35-
"ethers": "^6.12.1",
36-
"http-assert": "^1.5.0",
37-
"http-responders": "^2.0.2",
38-
"multiformats": "^13.1.0",
39-
"p-retry": "^6.2.0",
40-
"p-timeout": "^6.1.2",
41-
"pg": "^8.11.5",
42-
"postgrator": "^7.2.0",
43-
"raw-body": "^2.5.2"
17+
"standard": "^17.1.0"
4418
},
4519
"standard": {
4620
"env": [

spark-api/package.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "@filecoin-station/spark-api",
3+
"private": true,
4+
"version": "0.0.0",
5+
"license": "MIT",
6+
"repository": "filecoin-station/spark-api",
7+
"type": "module",
8+
"description": "API for SPARK",
9+
"scripts": {
10+
"start": "node bin/spark.js",
11+
"lint": "standard",
12+
"test": "mocha"
13+
},
14+
"devDependencies": {
15+
"light-my-request": "^5.13.0",
16+
"mocha": "^10.4.0",
17+
"standard": "^17.1.0",
18+
"varint": "^6.0.0"
19+
},
20+
"dependencies": {
21+
"@filecoin-station/spark-impact-evaluator": "^1.0.0",
22+
"@glif/filecoin-address": "^3.0.5",
23+
"@sentry/node": "^8.5.0",
24+
"compare-versions": "^6.1.0",
25+
"ethers": "^6.12.1",
26+
"http-assert": "^1.5.0",
27+
"http-responders": "^2.0.2",
28+
"multiformats": "^13.1.0",
29+
"pg": "^8.11.5",
30+
"postgrator": "^7.2.0",
31+
"raw-body": "^2.5.2"
32+
},
33+
"standard": {
34+
"env": [
35+
"mocha"
36+
]
37+
}
38+
}

spark-publish/package.json

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"start": "node bin/spark-publish.js",
5+
"lint": "standard",
6+
"test": "mocha"
7+
},
8+
"dependencies": {
9+
"@filecoin-station/spark-impact-evaluator": "^1.0.0",
10+
"@glif/filecoin-address": "^3.0.5",
11+
"@influxdata/influxdb-client": "^1.33.2",
12+
"@ipld/car": "^5.3.0",
13+
"@sentry/node": "^8.4.0",
14+
"@ucanto/core": "^10.0.1",
15+
"@ucanto/principal": "^9.0.1",
16+
"@web3-storage/access": "^18.3.2",
17+
"@web3-storage/w3up-client": "^13.1.1",
18+
"ethers": "^6.12.1",
19+
"p-retry": "^6.2.0",
20+
"p-timeout": "^6.1.2",
21+
"pg": "^8.11.5"
22+
},
23+
"devDependencies": {
24+
"@flydotio/dockerfile": "^0.5.7",
25+
"mocha": "^10.4.0",
26+
"multiformats": "^13.1.0",
27+
"postgrator": "^7.2.0",
28+
"standard": "^17.1.0"
29+
},
30+
"standard": {
31+
"env": [
32+
"mocha"
33+
]
34+
}
35+
}

0 commit comments

Comments
 (0)