-
Notifications
You must be signed in to change notification settings - Fork 11
/
.projenrc.ts
371 lines (330 loc) · 9.91 KB
/
.projenrc.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
import { github, web } from "projen";
import { workflows } from "projen/lib/github";
const PROXY_URL = "https://constructs.dev/";
const project = new web.ReactTypeScriptProject({
defaultReleaseBranch: "main",
name: "construct-hub-webapp",
projenrcTs: true,
// Author metadata
authorEmail: "[email protected]",
authorName: "Amazon Web Services, Inc.",
// Repository information
repository: "https://github.com/cdklabs/construct-hub-webapp.git",
// since this is an app project, we need to enable these explicitly
// in order to be able to publish this as an npm module.
releaseToNpm: true,
releaseWorkflow: true,
package: true,
tsconfig: {
compilerOptions: {
target: "es6",
},
},
minNodeVersion: "18.20.0",
eslint: true,
prettier: true,
deps: [
"@chakra-ui/anatomy",
"@chakra-ui/icons",
"@chakra-ui/react",
"@chakra-ui/theme-tools",
"@emotion/react@^11",
"@emotion/styled@^11",
"hast-util-sanitize",
"@jsii/spec",
"copy-to-clipboard", // Used by Chakra-UI, included for testing
"date-fns",
"framer-motion@^4",
"jsii-reflect",
"lunr",
"node-emoji",
"prism-react-renderer",
"react-query",
"react-helmet",
"react-markdown",
"react-router-dom",
"rehype-raw",
"rehype-sanitize",
"remark-emoji",
"remark-gfm",
"semver",
"spdx-license-list",
// PWA Functionality
"workbox-core",
"workbox-expiration",
"workbox-precaching",
"workbox-routing",
"workbox-strategies",
],
devDeps: [
"@types/lunr",
"@types/node-emoji",
"@types/[email protected]",
"@types/[email protected]",
"@types/[email protected]",
"@types/[email protected]",
"@types/semver",
"eslint-plugin-jsx-a11y",
"eslint-plugin-prefer-arrow",
"eslint-plugin-react-hooks",
"eslint-plugin-react",
"react-app-rewired",
"jsii-docgen",
"util",
],
autoApproveOptions: {
allowedUsernames: ["cdklabs-automation"],
secret: "GITHUB_TOKEN",
},
autoApproveUpgrades: true,
});
project.package.addField("jest", {
collectCoverage: true,
});
project.package.addField("resolutions", {
// addressing https://github.com/advisories/GHSA-rp65-9cf3-cjxr forcefully until
// react-scripts fixes the dependency chain.
// if test pass, we should be ok with this override, even though its a different major version.
"nth-check": "2.0.1",
// addressing https://github.com/facebook/react/issues/24304
"@types/react": "17.0.72",
// not sure why this is needed, but some dependencies have a transient dependency
// on wrap-ansi@8 which is an ESM module. When performing `yarn upgrade npm-check-updates`
// yarn gets confused somehow and uses the @8 one which causes things to break
"wrap-ansi": "7.0.0",
});
project.gitignore.addPatterns("/.vscode/");
project.npmignore?.addPatterns("/.vscode/");
(function addCypress() {
project.addDevDeps("cypress");
project.addTask("cypress:open", {
exec: "cypress open",
description: "open the cypress test runner UI",
});
project.addTask("cypress:run", {
exec: "cypress run",
description: "run the cypress suite in CLI",
});
project.gitignore.addPatterns("cypress/videos/", "cypress/screenshots/");
project.eslint?.addIgnorePattern("cypress/");
// Express is used to create a local proxy server used in CI + local build testing
(function addExpress() {
project.addDevDeps("express", "express-http-proxy");
project.addTask("proxy-server", {
exec: "node ./scripts/proxy-server",
});
project.addTask("proxy-server:ci", {
exec: "npx react-app-rewired build && CI=true yarn proxy-server",
});
})();
const cypressRunSteps = [
{
name: "Checkout",
uses: "actions/checkout@v3",
},
{
name: "Cypress Run",
uses: "cypress-io/github-action@v3",
env: {
DEBUG: "@cypress/github-action",
},
with: {
start: "yarn proxy-server:ci",
"wait-on": "http://localhost:3000",
"wait-on-timeout": 150,
},
},
{
uses: "actions/upload-artifact@v3",
if: "failure()",
with: {
name: "cypress-screenshots",
path: "cypress/screenshots",
},
},
{
uses: "actions/upload-artifact@v3",
if: "always()",
with: {
name: "cypress-videos",
path: "cypress/videos",
},
},
];
const integWorkflow = project.github?.addWorkflow("integ")!;
const e2e = "e2e";
integWorkflow.on({ workflowDispatch: {}, pullRequest: {} });
integWorkflow.addJob(e2e, {
name: e2e,
runsOn: ["ubuntu-latest"],
permissions: {
checks: github.workflows.JobPermission.WRITE,
contents: github.workflows.JobPermission.READ,
},
steps: cypressRunSteps,
});
project.autoMerge?.addConditions(`status-success=${e2e}`);
// Set up a canary that tests that the latest code on our main branch
// works against data on https://constructs.dev.
//
// We need to use the version of the front-end from the main branch
// and not the version that is live, otherwise it's possible for newer
// tests to run against an older (incompatible) version of the frontend
// due to deployment delays and give us false positives.
const e2eCanary = project.github?.addWorkflow("e2e-canary")!;
e2eCanary.on({
schedule: [
{
cron: "*/30 * * * *", // run every 30 minutes
},
],
workflowDispatch: {},
});
e2eCanary.addJobs({
test: {
name: "constructs.dev canary",
runsOn: ["ubuntu-latest"],
permissions: {
checks: github.workflows.JobPermission.WRITE,
contents: github.workflows.JobPermission.READ,
},
steps: [
...cypressRunSteps,
{
name: "Create failure issue",
if: "failure()",
uses: "imjohnbo/issue-bot@v3",
with: {
labels: "failed-release",
title: `E2E Canary for https://constructs.dev failed.`,
body: "See https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}",
},
env: {
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}",
},
},
],
},
});
})();
(function addJest() {
project.addDevDeps(
// "jest",
// "babel-jest",
// "ts-node",
"@testing-library/react",
"@testing-library/jest-dom",
"@testing-library/react-hooks",
"@testing-library/user-event"
);
project.addTask("test:unit", {
// exec: "jest",
exec: "npx react-app-rewired test",
});
project.addTask("test:update", {
exec: "npx react-app-rewired test -u",
});
project.eslint?.addIgnorePattern("jest.config.ts");
})();
// This task is used to analyze dead code
(function addAnalyzeExports() {
project.addDevDeps("ts-unused-exports");
project.addTask("analyze-exports", { exec: "node scripts/analyze-exports" });
})();
// npm tarball will only include the contents of the "build"
// directory, which is the output of our static website.
project.npmignore?.addPatterns("!/build");
project.npmignore?.addPatterns("/public");
// Ignore local config.json
project.npmignore?.addPatterns("/build/config.json");
project.gitignore.addPatterns("/public/config.json");
// test fixtures
project.npmignore?.addPatterns("src/__fixtures__");
// these are development assemblies fetched specifically
// by each developer.
project.gitignore.exclude("public/data");
// Proxy requests to awscdk.io for local testing
project.package.addField("proxy", PROXY_URL);
// setup linting for create-react-app specific tools
project.eslint?.addRules({
"import/no-extraneous-dependencies": [
"error",
{
devDependencies: ["**/setupTests.ts", "**/*.test.tsx", "**/*.test.ts"],
optionalDependencies: false,
peerDependencies: true,
},
],
});
// React specific overrides
project.eslint?.addOverride({
files: ["src/**/*.tsx", "src/**/*.ts"],
extends: [
"plugin:react/recommended",
"plugin:react-hooks/recommended",
"plugin:jsx-a11y/recommended",
],
settings: {
react: {
version: "detect",
},
},
plugins: ["jsx-a11y", "prefer-arrow"],
rules: {
"@typescript-eslint/no-use-before-define": ["error"],
"no-use-before-define": "off",
"prefer-arrow/prefer-arrow-functions": [
"error",
{
singleReturnOnly: false,
},
],
"react/jsx-sort-props": ["warn"],
"react/prop-types": ["off"],
"react/react-in-jsx-scope": ["off"],
},
} as any);
// rewire cra tasks, all apart from eject.
rewireCRA(project.tasks.tryFind("build"));
rewireCRA(project.tasks.tryFind("test"));
rewireCRA(project.tasks.tryFind("dev"));
// trigger construct-hub to pick up changes from construct-hub-webapp
// whenever a new release is made
project.release?.addJobs({
upgrade_construct_hub: {
name: "Upgrade construct-hub",
runsOn: ["ubuntu-latest"],
permissions: {
actions: workflows.JobPermission.WRITE,
},
needs: ["release", "release_github", "release_npm"],
steps: [
{
name: "Trigger upgrade workflow",
run: 'gh api -X POST /repos/cdklabs/construct-hub/actions/workflows/upgrade-main.yml/dispatches --field ref="main"',
env: {
GITHUB_TOKEN: "${{ secrets.PROJEN_GITHUB_TOKEN }}",
},
},
],
},
});
// replace default service worker script with no-op worker
const replaceWorker = project.addTask("replace-worker");
replaceWorker.exec("cp src/no-op-sw.js build/service-worker.js");
replaceWorker.exec("rm build/service-worker.js.map");
project.compileTask.spawn(replaceWorker);
project.synth();
/**
* Rewire a create-react-app task to use 'react-app-rewired` instead of 'react-scripts'
* so that our configuration overrides will take affect.
*
* @see https://www.npmjs.com/package/react-app-rewired
*/
function rewireCRA(craTask: any) {
for (const step of craTask.steps) {
if (step.exec && step.exec.startsWith("react-scripts")) {
step.exec = step.exec.replace("react-scripts", "react-app-rewired");
}
}
}