Skip to content

Commit d7ab19e

Browse files
author
JH
committed
chore: improve configs, dockerfile, ci and pnpm workspace
1 parent 2b2315a commit d7ab19e

15 files changed

+4952
-2749
lines changed

.dockerignore

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
node_modules
2+
Dockerfile
3+
compose.yaml
4+
.git
5+
.gitignore
6+
*.md
7+
dist
8+
.github
9+
.vscode
10+
.next
11+
lib/lib

.editorconfig

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
end_of_line = lf
8+
insert_final_newline = true
9+
indent_style = space
10+
indent_size = 2
11+
charset = utf-8
12+
trim_trailing_whitespace = true

.eslintrc.json

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"root": true,
23
"env": {
34
"browser": true,
45
"es2021": true,
@@ -7,10 +8,10 @@
78
},
89
"extends": [
910
"eslint:recommended",
11+
"plugin:react/recommended",
1012
"plugin:react/jsx-runtime",
1113
"plugin:@typescript-eslint/recommended",
12-
"prettier",
13-
"plugin:prettier/recommended"
14+
"prettier"
1415
],
1516
"parser": "@typescript-eslint/parser",
1617
"parserOptions": {
@@ -20,7 +21,7 @@
2021
},
2122
"sourceType": "module"
2223
},
23-
"plugins": ["react", "@typescript-eslint"],
24+
"plugins": ["@typescript-eslint"],
2425
"rules": {
2526
"react/display-name": "off"
2627
},
@@ -29,5 +30,5 @@
2930
"version": "detect"
3031
}
3132
},
32-
"ignorePatterns": ["node_modules/", "dist/", "lib/", ".next/"]
33+
"ignorePatterns": ["node_modules", "dist", "lib/lib", ".next"]
3334
}

.github/workflows/test.yml

+10-4
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,23 @@ jobs:
1111
name: Run tests with Node.js ${{ matrix.node-version }}
1212

1313
steps:
14-
- uses: actions/checkout@v3
15-
- uses: pnpm/action-setup@v2
14+
- name: Checkout
15+
uses: actions/checkout@v4
16+
17+
- name: Install pnpm
18+
uses: pnpm/action-setup@v3
1619
with:
1720
version: 8
18-
- uses: actions/setup-node@v3
1921

22+
- name: Setup node
23+
uses: actions/setup-node@v4
2024
with:
2125
node-version: ${{ matrix.node-version }}
2226
cache: "pnpm"
27+
2328
- run: pnpm config --global set dedupe-peer-dependents=false
2429
- run: pnpm --filter=react-esi install
30+
- run: pnpm --filter=react-esi run lint
31+
- run: pnpm --filter=react-esi run typecheck
2532
- run: pnpm --filter=react-esi run build
2633
- run: pnpm --filter=react-esi run test
27-
- run: pnpm --filter=react-esi run lint

.gitignore

+34-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
14
node_modules
2-
/coverage
5+
.pnp
6+
.pnp.js
7+
.pnpm-store
8+
9+
# testing
10+
coverage
11+
12+
# next.js
13+
.next/
14+
out/
15+
16+
# production
17+
build
318
dist
419
lib/lib
5-
.pnpm-store
20+
21+
# misc
22+
.DS_Store
23+
*.pem
24+
25+
# debug
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# local env files
31+
.env*.local
32+
33+
# vercel
34+
.vercel
35+
36+
# typescript
37+
*.tsbuildinfo

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
link-workspace-packages=false

.prettierignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
**/node_modules
55
**/.next
66
**/dist
7-
**/lib/lib
7+
/lib/lib

.prettierrc.json

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
11
{
2-
"printWidth": 80,
3-
"endOfLine": "auto",
4-
"semi": true,
5-
"singleQuote": false,
6-
"trailingComma": "none"
2+
"trailingComma": "es5"
73
}

.vscode/extensions.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"recommendations": [
3+
"dbaeumer.vscode-eslint",
4+
"esbenp.prettier-vscode",
5+
"orta.vscode-jest"
6+
]
7+
}

.vscode/settings.json

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"jest.outputConfig": {
3+
"clearOnRun": "none",
4+
"revealOn": "demand",
5+
"revealWithFocus": "none"
6+
},
7+
"testing.openTesting": "neverOpen",
8+
"eslint.workingDirectories": ["lib/", "examples/express/", "examples/next/"],
9+
"editor.codeActionsOnSave": {
10+
"source.eslint.fixAll": "explicit",
11+
"source.fixAll": "explicit"
12+
},
13+
"editor.formatOnSave": true,
14+
"editor.defaultFormatter": "esbenp.prettier-vscode",
15+
"eslint.validate": [
16+
"javascript",
17+
"javascriptreact",
18+
"typescript",
19+
"typescriptreact"
20+
]
21+
}

Dockerfile

+66-23
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,74 @@
1-
FROM node:20 AS base
1+
FROM node:20-slim AS base
22
ENV PNPM_HOME="/pnpm"
33
ENV PATH="$PNPM_HOME:$PATH"
4-
RUN corepack enable
5-
COPY . /app
6-
WORKDIR /app
4+
RUN corepack enable pnpm
75

8-
FROM base AS prod-deps
9-
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
106

11-
FROM base AS build
7+
# Express
8+
FROM base AS deps-express
9+
WORKDIR /home/node/repo
10+
11+
COPY ./package.json ./pnpm-lock.yaml ./pnpm-workspace.yaml ./
12+
COPY ./examples/express/package.json ./examples/express/
13+
COPY ./lib/package.json ./lib/
14+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
15+
16+
17+
FROM base AS build-express
18+
WORKDIR /home/node/repo
19+
COPY --from=deps-express /home/node/repo ./
20+
21+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
22+
23+
COPY . /home/node/repo
24+
25+
RUN pnpm --filter !esi-next run build
26+
RUN pnpm deploy --filter esi-express --prod /home/node/esi-express
27+
28+
FROM base AS esi-express
29+
COPY --from=build-express /home/node/esi-express /home/node/esi-express
30+
WORKDIR /home/node/esi-express
31+
USER node
32+
EXPOSE 3000
33+
CMD [ "node", "dist/server.js" ]
34+
35+
36+
37+
# Nextjs
38+
FROM base AS deps-next
39+
WORKDIR /home/node/repo
40+
41+
COPY ./package.json ./pnpm-lock.yaml ./pnpm-workspace.yaml ./
42+
COPY ./examples/next/package.json ./examples/next/
43+
COPY ./lib/package.json ./lib/
1244
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
13-
RUN pnpm run -r build
1445

15-
FROM base AS lib
16-
COPY --from=prod-deps /app/lib/node_modules/ /app/lib/node_modules
17-
COPY --from=build /app/lib/dist /app/lib/dist
1846

19-
FROM lib AS express
20-
COPY --from=prod-deps /app/examples/express/node_modules/ /app/examples/express/node_modules
21-
COPY --from=build /app/examples/express/dist /app/examples/express/dist
22-
WORKDIR /app/examples/express
47+
FROM base AS build-next
48+
WORKDIR /home/node/repo
49+
COPY --from=deps-next /home/node/repo ./
50+
COPY . /home/node/repo
51+
52+
ENV NEXT_TELEMETRY_DISABLED 1
53+
RUN pnpm --filter !esi-express run build
54+
RUN pnpm deploy --filter esi-next --prod /home/node/esi-next
55+
56+
57+
FROM base AS esi-next
58+
WORKDIR /home/node/esi-next
59+
60+
ENV NODE_ENV production
61+
ENV NEXT_TELEMETRY_DISABLED 1
62+
63+
# Set the correct permission for prerender cache
64+
RUN mkdir .next
65+
RUN chown node:node .next
66+
COPY --from=build-next --chown=node:node /home/node/esi-next/public ./public
67+
COPY --from=build-next --chown=node:node /home/node/esi-next/node_modules ./node_modules
68+
COPY --from=build-next --chown=node:node /home/node/esi-next/.next/standalone ./
69+
COPY --from=build-next --chown=node:node /home/node/esi-next/dist ./dist
70+
COPY --from=build-next --chown=node:node /home/node/esi-next/.next/static ./.next/static
71+
72+
USER node
2373
EXPOSE 3000
24-
CMD [ "pnpm", "start" ]
25-
26-
FROM lib AS next
27-
COPY --from=prod-deps /app/packages/app2/node_modules/ /app/packages/app2/node_modules
28-
COPY --from=build /app/packages/app2/dist /app/packages/app2/dist
29-
WORKDIR /app/packages/app2
30-
EXPOSE 30001
31-
CMD [ "pnpm", "start" ]
74+
CMD [ "node", "dist/server.js" ]

README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Also, React ESI allows the specification of different Time To Live (TTL) per Rea
1919
The cache server fetches and stores in the cache all the needed fragments (the HTML corresponding to every React component), builds the final page and sends it to the browser.
2020
React ESI also allows components to (re-)render client-side without any specific configuration.
2121

22-
![ESI example](https://raw.githubusercontent.com/varnish/Varnish-Book/3bd8894181f5e42f628967d04f40116498d1f7f2/ui/img/esi.png )
22+
![ESI example](https://raw.githubusercontent.com/varnish/Varnish-Book/3bd8894181f5e42f628967d04f40116498d1f7f2/ui/img/esi.png)
2323

2424
> Schema from [The Varnish Book](https://info.varnish-software.com/resources/varnish-6-by-example-book)
2525
@@ -101,7 +101,7 @@ export default class MyFragment extends React.Component {
101101
() =>
102102
resolve({
103103
...props, // Props coming from index.js, passed through the internal URL
104-
dataFromAnAPI: "Hello there"
104+
dataFromAnAPI: "Hello there",
105105
}),
106106
2000
107107
);
@@ -121,7 +121,6 @@ To serve the fragments, React ESI provides a ready-to-use controller compatible
121121

122122
Alternatively, here is a full example using [a Next.js server](https://github.com/dunglas/react-esi/tree/main/examples/next):
123123

124-
125124
## Features
126125

127126
- Support Varnish, Cloudflare Workers, Akamai, Fastly, and any other cache systems having ESI support

package.json

+24-4
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,29 @@
55
"repository": "https://github.com/dunglas/react-esi",
66
"license": "MIT",
77
"author": "Kévin Dunglas",
8-
"scripts": {},
9-
"packageManager": "[email protected]",
8+
"scripts": {
9+
"lint": "eslint .",
10+
"lint:fix": "eslint . --fix",
11+
"format": "prettier --write ."
12+
},
13+
"packageManager": "[email protected]",
1014
"engines": {
11-
"node": ">=18.12.0"
15+
"node": ">=20.11.0"
16+
},
17+
"pnpm": {
18+
"overrides": {
19+
"@types/react": "18.2.64",
20+
"@types/react-dom": "18.2.21",
21+
"typescript": "5.3.3"
22+
}
23+
},
24+
"devDependencies": {
25+
"@types/node": "^20.11.25",
26+
"eslint": "^8.57.0",
27+
"eslint-config-prettier": "^9.1.0",
28+
"eslint-plugin-react": "^7.34.0",
29+
"prettier": "^3.2.5",
30+
"typescript": "~5.3.3",
31+
"typescript-eslint": "^7.1.1"
1232
}
13-
}
33+
}

0 commit comments

Comments
 (0)