-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(upgrade): add codemod, rewrite imports to
@carbon/react
(#10523)
* wip: augment updates to include migrations, add prompts, run migrate functions * wip(cli): add separate migrate command, run all migrations during upgrade * wip: add migrate command file * fix(cli): await migrate calls, use flatMap for gathering migrations * chore(project): move transforms from codemods package to upgrade package * chore(project): remove codemods directory, update transforms arch doc * chore: update yarn.lock removing codemods package * feat(upgrade): add imports-to-unified-package migration, associated runner updates * feat(upgrade): add imports-to-unified-package migration, associated runner updates * chore(upgrade): ignore future updates to test file in sample project * fix(upgrade): add transformDir argument to migrate() call * chore(upgrade): don't hoist dependencies all the way up to the monorepo * chore(upgrade): minor code cleanup * chore(project): run yarn dedupe * fix(upgrade): remove prompt for migrations, clean up, review feedback * fix(upgrade): use execa to invoke jscodeshift, gather jscodeshift bin directly * chore(project): run yarn dedupe * test(codemod): imports-to-unified-package tests * feat(upgrade): provide codemod to rewrite imports to '@carbon/react' * chore: re-add execa as a dep * test(upgrade): handle syntax/formatting changes from output, correct filename * Update packages/upgrade/transforms/imports-to-unified-package.js Co-authored-by: Josh Black <josh@josh.black> * Update packages/upgrade/transforms/imports-to-unified-package.js Co-authored-by: Josh Black <josh@josh.black> * Update packages/upgrade/transforms/imports-to-unified-package.js Co-authored-by: Josh Black <josh@josh.black> * fix(upgrade): rename import rewrite codemod * fix(upgrade): rename import rewrite codemod * fix(upgrade): clarify code comment * fix(upgrade): correct replace syntax method Co-authored-by: Josh Black <josh@josh.black> Co-authored-by: Abbey Hart <abbeyhrt@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
de76f3a
commit 98d46e1
Showing
6 changed files
with
90 additions
and
19 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
packages/upgrade/fixtures/sample-project/example-imports-to-unified-package.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,12 @@ | ||
/** | ||
* DO NOT COMMIT CHANGES TO THIS FILE. | ||
* THIS FILE IS INTENDED TO BE MODIFIED LOCALLY | ||
* BY A MIGRATION(CODEMOD) VIA THE CLI AS AN EXAMPLE. | ||
*/ | ||
|
||
/* eslint-disable */ | ||
import { Button } from 'carbon-components-react'; | ||
import { Tile, Tooltip } from 'carbon-components-react'; | ||
import CodeSnippet from 'carbon-components-react'; | ||
import Something from 'somewhere-else'; | ||
/* eslint-enable */ |
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
8 changes: 8 additions & 0 deletions
8
...rade/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.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,8 @@ | ||
//prettier-ignore | ||
import { Button } from 'carbon-components-react'; | ||
//prettier-ignore | ||
import { Tile, Tooltip } from 'carbon-components-react'; | ||
//prettier-ignore | ||
import CodeSnippet from 'carbon-components-react'; | ||
import Something from 'somewhere-else'; | ||
import { SomethingElse } from 'somewhere-else'; |
8 changes: 8 additions & 0 deletions
8
...ade/transforms/__testfixtures__/update-carbon-components-react-import-to-scoped.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,8 @@ | ||
//prettier-ignore | ||
import { Button } from "@carbon/react"; | ||
//prettier-ignore | ||
import { Tile, Tooltip } from "@carbon/react"; | ||
//prettier-ignore | ||
import CodeSnippet from "@carbon/react"; | ||
import Something from 'somewhere-else'; | ||
import { SomethingElse } from 'somewhere-else'; |
12 changes: 12 additions & 0 deletions
12
packages/upgrade/transforms/__tests__/update-carbon-components-react-import-to-scoped.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,12 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const { defineTest } = require('jscodeshift/dist/testUtils'); | ||
|
||
defineTest(__dirname, 'update-carbon-components-react-import-to-scoped'); |
33 changes: 33 additions & 0 deletions
33
packages/upgrade/transforms/update-carbon-components-react-import-to-scoped.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,33 @@ | ||
/** | ||
* Copyright IBM Corp. 2016, 2020 | ||
* | ||
* This source code is licensed under the Apache-2.0 license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* Rewrites imports from 'carbon-components-react' to '@carbon/react' | ||
* | ||
* Transforms: | ||
* | ||
* import { Button } from 'carbon-components-react'; | ||
* | ||
* Into: | ||
* | ||
* import { Button } from "@carbon/react"; | ||
*/ | ||
|
||
export const parser = 'babel'; | ||
|
||
export default function transformer(file, api) { | ||
const j = api.jscodeshift; | ||
|
||
return j(file.source) | ||
.find(j.ImportDeclaration, { | ||
source: { | ||
value: 'carbon-components-react', | ||
}, | ||
}) | ||
.forEach((path) => { | ||
path.get('source').replace(j.stringLiteral('@carbon/react')); | ||
}) | ||
.toSource(); | ||
} |