-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Codemod to Update Fatal Error Page to support Development version (…
…#4577) * Adds tests (current fails due to paths) * Console logging to debug * Remove console debugging * Remove commented out console debugging Co-authored-by: Dominic Saadi <[email protected]>
- Loading branch information
1 parent
f740275
commit 23bf323
Showing
7 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
packages/codemods/src/codemods/v47.x/updateDevFatalErrorPage/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Update Development Fatal Error Page | ||
|
||
| | | | ||
|:--------|:-----------------| | ||
| version | `0.46` -> `0.47` | | ||
|
||
Replaces the web side `FatalErrorPage` with a version that with helpful debugging details in development. | ||
|
||
``` | ||
web | ||
├── src | ||
│ ├── pages | ||
│ │ ├── FatalErrorPage | ||
│ │ │ └── FatalErrorPage.tsx | ||
``` | ||
|
||
No jscodeshift is involved. | ||
|
||
|
53 changes: 53 additions & 0 deletions
53
...alErrorPage/__testfixtures__/default/input/web/src/pages/FatalErrorPage/FatalErrorPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This page will be rendered when an error makes it all the way to the top of the | ||
// application without being handled by a Javascript catch statement or React error | ||
// boundary. | ||
// | ||
// You can modify this page as you wish, but it is important to keep things simple to | ||
// avoid the possibility that it will cause its own error. If it does, Redwood will | ||
// still render a generic error page, but your users will prefer something a bit more | ||
// thoughtful. =) | ||
|
||
export default () => ( | ||
<main> | ||
<style | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
html, body { | ||
margin: 0; | ||
} | ||
html * { | ||
box-sizing: border-box; | ||
} | ||
main { | ||
display: flex; | ||
align-items: center; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; | ||
text-align: center; | ||
background-color: #E2E8F0; | ||
height: 100vh; | ||
} | ||
section { | ||
background-color: white; | ||
border-radius: 0.25rem; | ||
width: 32rem; | ||
padding: 1rem; | ||
margin: 0 auto; | ||
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); | ||
} | ||
h1 { | ||
font-size: 2rem; | ||
margin: 0; | ||
font-weight: 500; | ||
line-height: 1; | ||
color: #2D3748; | ||
} | ||
`, | ||
}} | ||
/> | ||
<section> | ||
<h1> | ||
<span>Something went wrong</span> | ||
</h1> | ||
</section> | ||
</main> | ||
) |
60 changes: 60 additions & 0 deletions
60
...lErrorPage/__testfixtures__/default/output/web/src/pages/FatalErrorPage/FatalErrorPage.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// This page will be rendered when an error makes it all the way to the top of the | ||
// application without being handled by a Javascript catch statement or React error | ||
// boundary. | ||
// | ||
// You can modify this page as you wish, but it is important to keep things simple to | ||
// avoid the possibility that it will cause its own error. If it does, Redwood will | ||
// still render a generic error page, but your users will prefer something a bit more | ||
// thoughtful. =) | ||
|
||
// Ensures that production builds do not include the error page | ||
let RedwoodDevFatalErrorPage = undefined | ||
if (process.env.NODE_ENV === 'development') { | ||
RedwoodDevFatalErrorPage = require('@redwoodjs/web').DevFatalErrorPage | ||
} | ||
|
||
export default RedwoodDevFatalErrorPage || | ||
(() => ( | ||
<main> | ||
<style | ||
dangerouslySetInnerHTML={{ | ||
__html: ` | ||
html, body { | ||
margin: 0; | ||
} | ||
html * { | ||
box-sizing: border-box; | ||
} | ||
main { | ||
display: flex; | ||
align-items: center; | ||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif; | ||
text-align: center; | ||
background-color: #E2E8F0; | ||
height: 100vh; | ||
} | ||
section { | ||
background-color: white; | ||
border-radius: 0.25rem; | ||
width: 32rem; | ||
padding: 1rem; | ||
margin: 0 auto; | ||
box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06); | ||
} | ||
h1 { | ||
font-size: 2rem; | ||
margin: 0; | ||
font-weight: 500; | ||
line-height: 1; | ||
color: #2D3748; | ||
} | ||
`, | ||
}} | ||
/> | ||
<section> | ||
<h1> | ||
<span>Something went wrong</span> | ||
</h1> | ||
</section> | ||
</main> | ||
)) |
7 changes: 7 additions & 0 deletions
7
...mods/src/codemods/v47.x/updateDevFatalErrorPage/__tests__/updateDevFatalErrorPage.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { updateDevFatalErrorPage } from '../updateDevFatalErrorPage' | ||
|
||
describe('updateDevFatalErrorPage', () => { | ||
it('Replaces the FatalErrorPage with a new version that includes development info', async () => { | ||
await matchFolderTransform(updateDevFatalErrorPage, 'default') | ||
}) | ||
}) |
45 changes: 45 additions & 0 deletions
45
packages/codemods/src/codemods/v47.x/updateDevFatalErrorPage/updateDevFatalErrorPage.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import fg from 'fast-glob' | ||
import fetch from 'node-fetch' | ||
|
||
import getRWPaths from '../../../lib/getRWPaths' | ||
|
||
export const updateDevFatalErrorPage = async () => { | ||
const rwPaths = getRWPaths() | ||
|
||
/** | ||
* An object where the keys are resolved filenames and the values are (for the most part) URLs to fetch. | ||
* | ||
* @remarks | ||
* | ||
*/ | ||
const webFatalErrorPagesDir = path.join(rwPaths.web.pages, 'FatalErrorPage') | ||
|
||
const dirs = { | ||
[webFatalErrorPagesDir]: { | ||
[path.join(webFatalErrorPagesDir, 'FatalErrorPage')]: | ||
'https://raw.githubusercontent.com/redwoodjs/redwood/main/packages/create-redwood-app/template/web/src/pages/FatalErrorPage/FatalErrorPage.tsx', | ||
}, | ||
} | ||
|
||
/** | ||
* Now we just fetch and replace files | ||
*/ | ||
for (const [_dir, filenamesToUrls] of Object.entries(dirs)) { | ||
const isTSProject = | ||
fg.sync('api/tsconfig.json').length > 0 || | ||
fg.sync('web/tsconfig.json').length > 0 | ||
|
||
for (const [filename, url] of Object.entries(filenamesToUrls)) { | ||
const res = await fetch(url) | ||
|
||
const text = await res.text() | ||
|
||
const newFatalErrorPage = `${filename}.${isTSProject ? 'tsx' : 'js'}` | ||
|
||
fs.writeFileSync(newFatalErrorPage, text) | ||
} | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...ages/codemods/src/codemods/v47.x/updateDevFatalErrorPage/updateDevFatalErrorPage.yargs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import task from 'tasuku' | ||
|
||
import { updateDevFatalErrorPage } from './updateDevFatalErrorPage' | ||
|
||
export const command = 'update-dev-fatal-error-page' | ||
export const description = | ||
'(v0.46->v0.47) Update Fatal Error Page with development version from the create-redwood-app template' | ||
|
||
export const handler = () => { | ||
task('Update Fatal Error Page with development version', async () => { | ||
await updateDevFatalErrorPage() | ||
}) | ||
} |