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 'codemod/replace-svg-as-components' of github.com:dac09/…
…redwood into codemod/replace-svg-as-components * 'codemod/replace-svg-as-components' of github.com:dac09/redwood: chore(deps): update react monorepo (redwoodjs#8677) chore(deps): update dependency postcss to v8.4.24 (redwoodjs#8675) chore(deps): update dependency esbuild to v0.18.6 (redwoodjs#8670) chore(deps): update dependency dependency-cruiser to v13.0.4 (redwoodjs#8674) chore(deps): update dependency autoprefixer to v10.4.14 (redwoodjs#8668) chore(deps): update dependency @clerk/clerk-react to v4.20.5 (redwoodjs#8672) Fix typos in documentation (redwoodjs#8659) fix(docs): Fix & make verifyOwnership consistent (redwoodjs#8596) chore(deps): update dependency vite to v4.1.5 [security] (redwoodjs#8671) fix(deps): update dependency react-hook-form to v7.45.0 (redwoodjs#8664) chore(studio): update tremor to v3 (redwoodjs#8645) fix(deps): update dependency webpack to v5.87.0 (redwoodjs#8549) fix(deps): update dependency dotenv to v16.3.1 (redwoodjs#8663) chore(deps): update dependency @clerk/clerk-react to v4.20.4 (redwoodjs#8662) fix(vite): Change config for mantine and chakra to use export default (redwoodjs#8639) fix(deps): update storybook monorepo to v7.0.22 (redwoodjs#8652) Fix failing v5 codemod for DevFatalErrorPage (redwoodjs#8661)
- Loading branch information
Showing
78 changed files
with
2,290 additions
and
2,006 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
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
13 changes: 13 additions & 0 deletions
13
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/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,13 @@ | ||
|
||
``` | ||
npx @redwoodjs/codemods@canary update-theme-config | ||
``` | ||
# Update Theme Config | ||
Modifies the config files specifically for mantine and chakra-ui to use ESM syntax to export the theme. | ||
|
||
```diff | ||
// This is common JS lets get rid of it! | ||
- module.exports = {/**....your theme **/} | ||
+ const theme = {/**....your theme **/} | ||
+ export default theme | ||
``` |
3 changes: 3 additions & 0 deletions
3
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/__testfixtures__/default.input.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,3 @@ | ||
// This object will be used to override Mantine theme defaults. | ||
// See https://mantine.dev/theming/mantine-provider/#theme-object for theming options | ||
module.exports = {} |
4 changes: 4 additions & 0 deletions
4
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/__testfixtures__/default.output.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,4 @@ | ||
// This object will be used to override Mantine theme defaults. | ||
// See https://mantine.dev/theming/mantine-provider/#theme-object for theming options | ||
const theme = {} | ||
export default theme |
5 changes: 5 additions & 0 deletions
5
.../codemods/src/codemods/v6.x.x/updateThemeConfig/__testfixtures__/identifierTheme.input.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 customTheme = { | ||
bazinga: 'kittens' | ||
} | ||
|
||
module.exports = customTheme |
5 changes: 5 additions & 0 deletions
5
...codemods/src/codemods/v6.x.x/updateThemeConfig/__testfixtures__/identifierTheme.output.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 customTheme = { | ||
bazinga: 'kittens' | ||
} | ||
|
||
export default customTheme |
9 changes: 9 additions & 0 deletions
9
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/__tests__/updateThemeConfig.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,9 @@ | ||
describe('updateThemeConfig', () => { | ||
it('Converts from module.exports to export default ', async () => { | ||
await matchTransformSnapshot('updateThemeConfig', 'default') | ||
}) | ||
|
||
it('Handles when config is an identifier', async () => { | ||
await matchTransformSnapshot('updateThemeConfig', 'identifierTheme') | ||
}) | ||
}) |
49 changes: 49 additions & 0 deletions
49
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.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,49 @@ | ||
import type { FileInfo, API } from 'jscodeshift' | ||
|
||
export default function transform(file: FileInfo, api: API) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
// Find all module.exports assignments | ||
root | ||
.find(j.AssignmentExpression, { | ||
left: { | ||
type: 'MemberExpression', | ||
object: { type: 'Identifier', name: 'module' }, | ||
property: { type: 'Identifier', name: 'exports' }, | ||
}, | ||
}) | ||
.forEach((path) => { | ||
const configObject = path.value.right | ||
|
||
let themeObjectName = 'theme' | ||
|
||
if (j.Identifier.check(configObject)) { | ||
// If it already is an identifier, reuse it | ||
// modules.exports = theme -> export default theme | ||
// Note that export default statement is added outside this if statement | ||
themeObjectName = configObject.name | ||
|
||
// Remove module.exports assignment | ||
j(path).remove() | ||
} else { | ||
// Create const declaration with the exported object | ||
const declaration = j.variableDeclaration('const', [ | ||
j.variableDeclarator(j.identifier(themeObjectName), configObject), | ||
]) | ||
|
||
// Replace module.exports assignment with the const declaration | ||
// module.exports = {...} -> const theme = {...} | ||
j(path).replaceWith(declaration) | ||
} | ||
|
||
// Add export default statement | ||
const exportDefaultStatement = j.exportDefaultDeclaration( | ||
j.identifier(themeObjectName) | ||
) | ||
|
||
j(path.parentPath).insertAfter(exportDefaultStatement) | ||
}) | ||
|
||
return root.toSource() | ||
} |
28 changes: 28 additions & 0 deletions
28
packages/codemods/src/codemods/v6.x.x/updateThemeConfig/updateThemeConfig.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,28 @@ | ||
import path from 'path' | ||
|
||
import fg from 'fast-glob' | ||
import task, { TaskInnerAPI } from 'tasuku' | ||
|
||
import { getPaths } from '@redwoodjs/project-config' | ||
|
||
import runTransform from '../../../lib/runTransform' | ||
|
||
export const command = 'update-theme-config' | ||
export const description = | ||
'(v5.x.x->v6.x.x) Converts mantine and chakra UI configs to use ESM syntax' | ||
|
||
export const handler = () => { | ||
task('Update Theme Config', async ({ setOutput }: TaskInnerAPI) => { | ||
const targetPaths = fg.sync('{chakra,mantine}.config.{js,jsx,tsx,ts}', { | ||
cwd: getPaths().web.config, | ||
absolute: true, | ||
}) | ||
|
||
await runTransform({ | ||
transformPath: path.join(__dirname, 'updateThemeConfig.js'), | ||
targetPaths, | ||
}) | ||
|
||
setOutput('All done! Run `yarn rw lint --fix` to prettify your code') | ||
}) | ||
} |
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
Oops, something went wrong.