gatsby-codemods
Advanced tools
Comparing version 1.0.0-rc.1 to 1.0.0-rc.2
@@ -6,2 +6,10 @@ # Change Log | ||
<a name="1.0.0-rc.2"></a> | ||
# [1.0.0-rc.2](https://github.com/gatsbyjs/gatsby/compare/gatsby-codemods@1.0.0-rc.1...gatsby-codemods@1.0.0-rc.2) (2018-09-04) | ||
### Features | ||
- add a navigateTo -> navigate codemod ([#7532](https://github.com/gatsbyjs/gatsby/issues/7532)) ([5f679fa](https://github.com/gatsbyjs/gatsby/commit/5f679fa)) | ||
<a name="1.0.0-rc.1"></a> | ||
@@ -8,0 +16,0 @@ |
{ | ||
"name": "gatsby-codemods", | ||
"version": "1.0.0-rc.1", | ||
"version": "1.0.0-rc.2", | ||
"description": "Stub description for gatsby-codemods", | ||
@@ -34,3 +34,3 @@ "main": "index.js", | ||
}, | ||
"gitHead": "a8a4c69c97d9d7f59a7bfb50e7d1fbd463d2e012" | ||
"gitHead": "c87e937182589c4ddc07ffd5ba9dadba94c88cc7" | ||
} |
@@ -71,2 +71,27 @@ ## gatsby-codemods | ||
#### `navigate-calls` | ||
Change the deprecated `navigateTo` method from `gatsby-link` to `navigate` from the `gatsby` module. | ||
See the [Gatsby v2 migration guide for details on when to use this](https://next.gatsbyjs.org/docs/migrating-from-v1-to-v2/#change-navigateto-to-navigate). | ||
```sh | ||
jscodeshift -t node_modules/gatsby-codemods/dist/transforms/navigate-calls.js <path> | ||
``` | ||
Example result: | ||
```diff | ||
import React from "react" | ||
- import { navigateTo } from "gatsby-link" | ||
+ import { navigate } from "gatsby" | ||
// Don't use navigate with an onClick btw :-) | ||
// Generally just use the `<Link>` component. | ||
export default props => ( | ||
- <div onClick={() => navigateTo(`/`)}>Click to go to home</div> | ||
+ <div onClick={() => navigate(`/`)}>Click to go to home</div> | ||
) | ||
``` | ||
### More scripts | ||
@@ -73,0 +98,0 @@ |
@@ -7,3 +7,2 @@ "use strict"; | ||
/* eslint-disable */ | ||
// TODO: update codemod to make this test pass | ||
const query = graphql` | ||
@@ -10,0 +9,0 @@ query { |
@@ -9,3 +9,2 @@ "use strict"; | ||
/* eslint-disable */ | ||
// TODO: update codemod to make this test pass | ||
const query = _gatsby.graphql` | ||
@@ -12,0 +11,0 @@ query { |
@@ -42,3 +42,7 @@ "use strict"; | ||
if (!existingImport.length) { | ||
root.find(j.Program).get(`body`, 0).insertBefore(j.importDeclaration([j.importSpecifier(j.identifier(IMPORT_NAME))], j.literal(MODULE_NAME))); | ||
const first = root.find(j.Program).get(`body`, 0); | ||
const comments = first.node.comments.splice(0); | ||
const importStatement = j.importDeclaration([j.importSpecifier(j.identifier(IMPORT_NAME))], j.literal(MODULE_NAME)); | ||
importStatement.comments = comments; | ||
root.find(j.Program).get(`body`, 0).insertBefore(importStatement); | ||
return; | ||
@@ -114,3 +118,9 @@ } | ||
importKind: `value` | ||
}).length > 0; | ||
}).length > 0 || root.find(j.VariableDeclarator, { | ||
init: { | ||
callee: { | ||
name: `require` | ||
} | ||
} | ||
}).length === 0; | ||
@@ -117,0 +127,0 @@ if (useImportSyntax) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
21123
30
523
101