forked from redwoodjs/redwood
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'chore/rename-entry-client' of github.com:dac09/redwood …
…into chore/rename-entry-client * 'chore/rename-entry-client' of github.com:dac09/redwood: Move fastify.logger.infos to fastify.logger.traces (redwoodjs#8590) Make the fastify logger respect the LOG_LEVEL value set in the env (redwoodjs#8588) feat: Update the SDL types lib (redwoodjs#8586) Fix the codegen path for the GraphQL context objcet (redwoodjs#8585) chore(deps): update dependency @clerk/types to v3.42.0 (redwoodjs#8584) feat(codemod): Add codemod for js to jsx conversion (redwoodjs#8551)
- Loading branch information
Showing
71 changed files
with
1,135 additions
and
69 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
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
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
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
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
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
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
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
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
47 changes: 47 additions & 0 deletions
47
packages/codemods/src/codemods/v6.x.x/convertJsToJsx/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,47 @@ | ||
# Convert Js To Jsx | ||
|
||
**Description** | ||
|
||
Vite works best when you avoid using `.js` files which actually contain JSX inside them. They should ideally be given the `.jsx` extension. Features such as hot reloading is unavailable in cases where you use `.js` where `.jsx` is more appropriate. | ||
|
||
This codemod examines all files ending in `.js` within your `web/src` and renames any files which contains JSX to end with `.jsx` instead of `.js`. | ||
|
||
**NOTE**: The contents of your files are untouched. This only affects the extension. | ||
|
||
**Examples** | ||
|
||
For example the following `App.js`: | ||
```js | ||
import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' | ||
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' | ||
|
||
import FatalErrorPage from 'src/pages/FatalErrorPage' | ||
import Routes from 'src/Routes' | ||
|
||
import './index.css' | ||
|
||
const App = () => ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<RedwoodProvider titleTemplate="%PageTitle | %AppTitle"> | ||
<RedwoodApolloProvider> | ||
<Routes /> | ||
</RedwoodApolloProvider> | ||
</RedwoodProvider> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
export default App | ||
``` | ||
would become `App.jsx` as it clearly contains JSX. | ||
|
||
However a file such as `TestCell.mock.js`: | ||
```js | ||
// Define your own mock data here: | ||
export const standard = (/* vars, { ctx, req } */) => ({ | ||
test: { | ||
id: 42, | ||
}, | ||
}) | ||
``` | ||
would remain `TestCell.mock.js` as it does not contain JSX. | ||
|
19 changes: 19 additions & 0 deletions
19
...codemods/src/codemods/v6.x.x/convertJsToJsx/__testfixtures__/example/input/web/src/App.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,19 @@ | ||
import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' | ||
import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' | ||
|
||
import FatalErrorPage from 'src/pages/FatalErrorPage' | ||
import Routes from 'src/Routes' | ||
|
||
import './index.css' | ||
|
||
const App = () => ( | ||
<FatalErrorBoundary page={FatalErrorPage}> | ||
<RedwoodProvider titleTemplate="%PageTitle | %AppTitle"> | ||
<RedwoodApolloProvider> | ||
<Routes /> | ||
</RedwoodApolloProvider> | ||
</RedwoodProvider> | ||
</FatalErrorBoundary> | ||
) | ||
|
||
export default App |
21 changes: 21 additions & 0 deletions
21
...emods/src/codemods/v6.x.x/convertJsToJsx/__testfixtures__/example/input/web/src/Routes.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,21 @@ | ||
// In this file, all Page components from 'src/pages` are auto-imported. Nested | ||
// directories are supported, and should be uppercase. Each subdirectory will be | ||
// prepended onto the component name. | ||
// | ||
// Examples: | ||
// | ||
// 'src/pages/HomePage/HomePage.js' -> HomePage | ||
// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage | ||
|
||
import { Router, Route } from '@redwoodjs/router' | ||
|
||
const Routes = () => { | ||
return ( | ||
<Router> | ||
<Route path="/test" page={TestPage} name="test" /> | ||
<Route notfound page={NotFoundPage} /> | ||
</Router> | ||
) | ||
} | ||
|
||
export default Routes |
19 changes: 19 additions & 0 deletions
19
...x.x/convertJsToJsx/__testfixtures__/example/input/web/src/components/TestCell/TestCell.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,19 @@ | ||
export const QUERY = gql` | ||
query FindTestQuery($id: Int!) { | ||
test: test(id: $id) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Empty = () => <div>Empty</div> | ||
|
||
export const Failure = ({ error }) => ( | ||
<div style={{ color: 'red' }}>Error: {error?.message}</div> | ||
) | ||
|
||
export const Success = ({ test }) => { | ||
return <div>{JSON.stringify(test)}</div> | ||
} |
6 changes: 6 additions & 0 deletions
6
...onvertJsToJsx/__testfixtures__/example/input/web/src/components/TestCell/TestCell.mock.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,6 @@ | ||
// Define your own mock data here: | ||
export const standard = (/* vars, { ctx, req } */) => ({ | ||
test: { | ||
id: 42, | ||
}, | ||
}) |
20 changes: 20 additions & 0 deletions
20
...ertJsToJsx/__testfixtures__/example/input/web/src/components/TestCell/TestCell.stories.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,20 @@ | ||
import { Loading, Empty, Failure, Success } from './TestCell' | ||
import { standard } from './TestCell.mock' | ||
|
||
export const loading = () => { | ||
return Loading ? <Loading /> : <></> | ||
} | ||
|
||
export const empty = () => { | ||
return Empty ? <Empty /> : <></> | ||
} | ||
|
||
export const failure = (args) => { | ||
return Failure ? <Failure error={new Error('Oh no')} {...args} /> : <></> | ||
} | ||
|
||
export const success = (args) => { | ||
return Success ? <Success {...standard()} {...args} /> : <></> | ||
} | ||
|
||
export default { title: 'Cells/TestCell' } |
41 changes: 41 additions & 0 deletions
41
...onvertJsToJsx/__testfixtures__/example/input/web/src/components/TestCell/TestCell.test.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,41 @@ | ||
import { render } from '@redwoodjs/testing/web' | ||
import { Loading, Empty, Failure, Success } from './TestCell' | ||
import { standard } from './TestCell.mock' | ||
|
||
// Generated boilerplate tests do not account for all circumstances | ||
// and can fail without adjustments, e.g. Float and DateTime types. | ||
// Please refer to the RedwoodJS Testing Docs: | ||
// https://redwoodjs.com/docs/testing#testing-cells | ||
// https://redwoodjs.com/docs/testing#jest-expect-type-considerations | ||
|
||
describe('TestCell', () => { | ||
it('renders Loading successfully', () => { | ||
expect(() => { | ||
render(<Loading />) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('renders Empty successfully', async () => { | ||
expect(() => { | ||
render(<Empty />) | ||
}).not.toThrow() | ||
}) | ||
|
||
it('renders Failure successfully', async () => { | ||
expect(() => { | ||
render(<Failure error={new Error('Oh no')} />) | ||
}).not.toThrow() | ||
}) | ||
|
||
// When you're ready to test the actual output of your component render | ||
// you could test that, for example, certain text is present: | ||
// | ||
// 1. import { screen } from '@redwoodjs/testing/web' | ||
// 2. Add test: expect(screen.getByText('Hello, world')).toBeInTheDocument() | ||
|
||
it('renders Success successfully', async () => { | ||
expect(() => { | ||
render(<Success test={standard().test} />) | ||
}).not.toThrow() | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
...tJsToJsx/__testfixtures__/example/input/web/src/components/TestComponent/TestComponent.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,10 @@ | ||
const TestComponent = () => { | ||
return ( | ||
<div> | ||
<h2>{'TestComponent'}</h2> | ||
<p>{'Find me in ./web/src/components/TestComponent/TestComponent.js'}</p> | ||
</div> | ||
) | ||
} | ||
|
||
export default TestComponent |
21 changes: 21 additions & 0 deletions
21
.../__testfixtures__/example/input/web/src/components/TestComponent/TestComponent.stories.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,21 @@ | ||
// When you've added props to your component, | ||
// pass Storybook's `args` through this story to control it from the addons panel: | ||
// | ||
// ```jsx | ||
// export const generated = (args) => { | ||
// return <TestComponent {...args} /> | ||
// } | ||
// ``` | ||
// | ||
// See https://storybook.js.org/docs/react/writing-stories/args. | ||
|
||
import TestComponent from './TestComponent' | ||
|
||
export const generated = () => { | ||
return <TestComponent /> | ||
} | ||
|
||
export default { | ||
title: 'Components/TestComponent', | ||
component: TestComponent, | ||
} |
14 changes: 14 additions & 0 deletions
14
...Jsx/__testfixtures__/example/input/web/src/components/TestComponent/TestComponent.test.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,14 @@ | ||
import { render } from '@redwoodjs/testing/web' | ||
|
||
import TestComponent from './TestComponent' | ||
|
||
// Improve this test with help from the Redwood Testing Doc: | ||
// https://redwoodjs.com/docs/testing#testing-components | ||
|
||
describe('TestComponent', () => { | ||
it('renders successfully', () => { | ||
expect(() => { | ||
render(<TestComponent />) | ||
}).not.toThrow() | ||
}) | ||
}) |
Empty file.
15 changes: 15 additions & 0 deletions
15
...mods/src/codemods/v6.x.x/convertJsToJsx/__testfixtures__/example/input/web/src/index.html
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,15 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<link rel="icon" type="image/png" href="/favicon.png" /> | ||
</head> | ||
|
||
<body> | ||
<!-- Please keep this div empty --> | ||
<div id="redwood-app"></div> | ||
</body> | ||
|
||
</html> |
5 changes: 5 additions & 0 deletions
5
....x/convertJsToJsx/__testfixtures__/example/input/web/src/layouts/TestLayout/TestLayout.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,5 @@ | ||
const TestLayout = ({ children }) => { | ||
return <>{children}</> | ||
} | ||
|
||
export default TestLayout |
Oops, something went wrong.