Skip to content

Commit

Permalink
fix(gatsby): Use vendored @reach/router (#29772)
Browse files Browse the repository at this point in the history
* fix(gatsby): Use vendored @reach/router

* Add typescript alias

* Add esm alias

* Fix tsconfig paths

* CHange imports inside gatsby

* Jest support

* Update peerdeps

Co-authored-by: gatsbybot <mathews.kyle+gatsbybot@gmail.com>
  • Loading branch information
ascorbic and gatsbybot authored Feb 26, 2021
1 parent eb31801 commit 8754e0c
Show file tree
Hide file tree
Showing 14 changed files with 28 additions and 36 deletions.
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module.exports = {
},
moduleNameMapper: {
"^highlight.js$": `<rootDir>/node_modules/highlight.js/lib/index.js`,
"^@reach/router(.*)": `<rootDir>/node_modules/@gatsbyjs/reach-router$1`,
},
snapshotSerializers: [`jest-serializer-path`],
collectCoverageFrom: coverageDirs,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"cross-env": "^7.0.3"
},
"peerDependencies": {
"@reach/router": "^1.3.3",
"@gatsbyjs/reach-router": "^1.3.5",
"react": "^16.9.0 || ^17.0.0",
"react-dom": "^16.9.0 || ^17.0.0"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-link/src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import PropTypes from "prop-types"
import React from "react"
import { Link, Location } from "@reach/router"
import { resolve } from "@reach/router/lib/utils"
import { resolve } from "@gatsbyjs/reach-router/lib/utils"

import { parsePath } from "./parse-path"

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-react-router-scroll/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"license": "MIT",
"main": "index.js",
"peerDependencies": {
"@reach/router": "^1.0.0",
"@gatsbyjs/reach-router": "^1.3.5",
"react": "^16.9.0 || ^17.0.0",
"react-dom": "^16.9.0 || ^17.0.0"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby/cache-dir/__tests__/find-path.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ describe(`find-path`, () => {

it(`should only process a request once`, () => {
jest.resetModules()
jest.mock(`@reach/router/lib/utils`)
jest.mock(`@gatsbyjs/reach-router/lib/utils`)
const findPath = require(`../find-path`).findPath
const setMatchPaths = require(`../find-path`).setMatchPaths
const pick = require(`@reach/router/lib/utils`).pick
const pick = require(`@gatsbyjs/reach-router/lib/utils`).pick

setMatchPaths([
{
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/cache-dir/find-path.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { pick } from "@reach/router/lib/utils"
import { pick } from "@gatsbyjs/reach-router/lib/utils"
import stripPrefix from "./strip-prefix"
import normalizePagePath from "./normalize-page-path"

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@mikaelkristiansson/domready": "^1.0.10",
"@nodelib/fs.walk": "^1.2.4",
"@pmmmwh/react-refresh-webpack-plugin": "^0.4.3",
"@reach/router": "^1.3.4",
"@gatsbyjs/reach-router": "^1.3.5",
"@types/http-proxy": "^1.17.4",
"@typescript-eslint/eslint-plugin": "^4.15.2",
"@typescript-eslint/parser": "^4.15.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/__tests__/requires-writer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { joinPath } = require(`gatsby-core-utils`)
const requiresWriter = require(`../requires-writer`)
const { match } = require(`@reach/router/lib/utils`)
const { match } = require(`@gatsbyjs/reach-router/lib/utils`)

const now = Date.now()

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/bootstrap/requires-writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs-extra"
import crypto from "crypto"
import { slash } from "gatsby-core-utils"
import reporter from "gatsby-cli/lib/reporter"
import { match } from "@reach/router/lib/utils"
import { match } from "@gatsbyjs/reach-router/lib/utils"
import { joinPath } from "gatsby-core-utils"
import { store, emitter } from "../redux/"
import { IGatsbyState, IGatsbyPage } from "../redux/types"
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from "fs-extra"
import compression from "compression"
import express from "express"
import chalk from "chalk"
import { match as reachMatch } from "@reach/router/lib/utils"
import { match as reachMatch } from "@gatsbyjs/reach-router/lib/utils"
import onExit from "signal-exit"
import report from "gatsby-cli/lib/reporter"

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/src/utils/find-page-by-path.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { IGatsbyPage, IGatsbyState } from "../redux/types"
import { match } from "@reach/router/lib/utils"
import { match } from "@gatsbyjs/reach-router/lib/utils"

export function findPageByPath(
state: IGatsbyState,
Expand Down
5 changes: 3 additions & 2 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ module.exports = async (
// Gatsby main router changes it, to keep v2 behaviour.
// We will need to most likely remove this for v3.
{
test: require.resolve(`@reach/router/es/index`),
test: require.resolve(`@gatsbyjs/reach-router/es/index`),
type: `javascript/auto`,
use: [{
loader: require.resolve(`./reach-router-add-basecontext-export-loader`),
Expand Down Expand Up @@ -424,6 +424,7 @@ module.exports = async (
// relative path imports are used sometimes
// See https://stackoverflow.com/a/49455609/6420957 for more details
"@babel/runtime": getPackageRoot(`@babel/runtime`),
"@reach/router": getPackageRoot(`@gatsbyjs/reach-router`),
"react-lifecycles-compat": directoryPath(
`.cache/react-lifecycles-compat.js`
),
Expand All @@ -448,7 +449,7 @@ module.exports = async (
stage === `build-html` || stage === `develop-html` ? `node` : `web`
if (target === `web`) {
resolve.alias[`@reach/router`] = path.join(
path.dirname(require.resolve(`@reach/router/package.json`)),
getPackageRoot(`@gatsbyjs/reach-router`),
`es`
)
}
Expand Down
5 changes: 4 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
"noFallthroughCasesInSwitch": true,
"resolveJsonModule": true,
"esModuleInterop": true,
"jsx": "preserve"
"jsx": "preserve",
"paths": {
"@reach/router/*": ["./node_modules/@gatsbyjs/reach-router/*"]
}
},
"exclude": ["peril/*", "examples/*"]
}
31 changes: 9 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,15 @@
resolved "https://registry.yarnpkg.com/@feedback-fish/react/-/react-1.2.1.tgz#b4d226f310df936517e9e5e82397806a5df4e2d8"
integrity sha512-4YFD2hE93xBIT/Ko0x0l6UB0OyaxJcWKLGrnznsUVoLE5Q9vB8I1LEbMySYyuvbU9ul3yM3FjGkVZhYVPdwEyA==

"@gatsbyjs/reach-router@^1.3.5":
version "1.3.5"
resolved "https://registry.yarnpkg.com/@gatsbyjs/reach-router/-/reach-router-1.3.5.tgz#e5d86b341957611153279da353d0a39a82f34a8e"
integrity sha512-O7sTZajwCtbjuuUYwjEZdSw7CmAxA6ugDaXtw4hfKoTfj4RZUAB8nYRlecUVuNAQbgHiXJSx2jKfu1hmE9mggA==
dependencies:
invariant "^2.2.3"
prop-types "^15.6.1"
react-lifecycles-compat "^3.0.4"

"@gatsbyjs/webpack-hot-middleware@^2.25.2":
version "2.25.2"
resolved "https://registry.yarnpkg.com/@gatsbyjs/webpack-hot-middleware/-/webpack-hot-middleware-2.25.2.tgz#bad1a8bfacc2a0ff4f2c991f8aee488e2f38294a"
Expand Down Expand Up @@ -4444,16 +4453,6 @@
prop-types "^15.7.2"
tslib "^1.11.2"

"@reach/router@^1.3.4":
version "1.3.4"
resolved "https://registry.yarnpkg.com/@reach/router/-/router-1.3.4.tgz#d2574b19370a70c80480ed91f3da840136d10f8c"
integrity sha512-+mtn9wjlB9NN2CNnnC/BRYtwdKBfSyyasPYraNAyvaV1occr/5NnB4CVzjEZipNHwYebQwcndGUmpFzxAUoqSA==
dependencies:
create-react-context "0.3.0"
invariant "^2.2.3"
prop-types "^15.6.1"
react-lifecycles-compat "^3.0.4"

"@reach/tabs@0.10.3":
version "0.10.3"
resolved "https://registry.yarnpkg.com/@reach/tabs/-/tabs-0.10.3.tgz#392461762b33af2476d26b3018e1489260532b85"
Expand Down Expand Up @@ -9688,14 +9687,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4:
safe-buffer "^5.0.1"
sha.js "^2.4.8"

create-react-context@0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/create-react-context/-/create-react-context-0.3.0.tgz#546dede9dc422def0d3fc2fe03afe0bc0f4f7d8c"
integrity sha512-dNldIoSuNSvlTJ7slIKC/ZFGKexBMBrrcc+TTe1NdmROnaASuLPvqpwj9v4XS4uXZ8+YPu0sNmShX2rXI5LNsw==
dependencies:
gud "^1.0.0"
warning "^4.0.3"

createerror@1.1.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/createerror/-/createerror-1.1.0.tgz#2a711f589cc7ca38586414398856b8a30ea4a06b"
Expand Down Expand Up @@ -14044,10 +14035,6 @@ growly@^1.3.0:
version "1.3.0"
resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081"

gud@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/gud/-/gud-1.0.0.tgz#a489581b17e6a70beca9abe3ae57de7a499852c0"

gulp-header@^1.7.1:
version "1.8.12"
resolved "https://registry.yarnpkg.com/gulp-header/-/gulp-header-1.8.12.tgz#ad306be0066599127281c4f8786660e705080a84"
Expand Down

0 comments on commit 8754e0c

Please sign in to comment.