Skip to content

Commit b4c539a

Browse files
icd2k3jschrader-nr
andauthored
chore: remove support for rr 4, dependencies, and build improvements (#122)
* chore: remove support for rr 4, dependencies, and build improvements * fix: small improvement to UMD build * chore: remove unnecessary dependency Co-authored-by: Justin Schrader <[email protected]>
1 parent 9d2e185 commit b4c539a

File tree

9 files changed

+1186
-1772
lines changed

9 files changed

+1186
-1772
lines changed

.yarn/releases/yarn-berry.cjs renamed to .yarn/releases/yarn-2.4.2.cjs

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

.yarnrc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ plugins:
44
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.cjs
55
spec: "@yarnpkg/plugin-interactive-tools"
66

7-
yarnPath: .yarn/releases/yarn-berry.cjs
7+
yarnPath: .yarn/releases/yarn-2.4.2.cjs

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</p>
1010

1111
<p align="center">
12-
A small (~1.6kb gzip), flexible, <a href="https://reactjs.org/docs/higher-order-components.html">higher order component</a> for rendering breadcrumbs with <a href="https://github.com/ReactTraining/react-router">react-router</a> 4 & 5
12+
A small (~1.3kb compressed & gzipped), flexible, <a href="https://reactjs.org/docs/higher-order-components.html">higher order component</a> for rendering breadcrumbs with <a href="https://github.com/ReactTraining/react-router">react-router</a> 5
1313
</p>
1414

1515
<hr/>
@@ -75,9 +75,9 @@ Start seeing generated breadcrumbs right away with this simple example ([codesan
7575
import withBreadcrumbs from 'react-router-breadcrumbs-hoc';
7676

7777
const Breadcrumbs = ({ breadcrumbs }) => (
78-
<React.Fragment>
78+
<>
7979
{breadcrumbs.map(({ breadcrumb }) => breadcrumb)}
80-
</React.Fragment>
80+
</>
8181
)
8282

8383
export default withBreadcrumbs()(Breadcrumbs);

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ module.exports = function(api) {
99
'@babel/preset-react',
1010
'@babel/preset-typescript'
1111
],
12-
plugins: [],
12+
plugins: ['@babel/plugin-transform-runtime'],
1313
};
1414
};

package.json

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-router-breadcrumbs-hoc",
3-
"version": "3.4.0",
3+
"version": "4.0.0",
44
"description": "small, flexible, higher order component for rendering breadcrumbs with react-router 4.x",
55
"repository": "icd2k3/react-router-breadcrumbs-hoc",
66
"main": "dist/cjs/index.js",
@@ -21,49 +21,46 @@
2121
"license": "MIT",
2222
"peerDependencies": {
2323
"react": ">=16.8",
24-
"react-router": ">=4"
24+
"react-router": ">=5"
2525
},
2626
"devDependencies": {
2727
"@babel/cli": "^7.14.3",
2828
"@babel/core": "^7.14.3",
29-
"@babel/preset-env": "^7.14.2",
29+
"@babel/plugin-transform-runtime": "^7.14.3",
30+
"@babel/preset-env": "^7.14.4",
3031
"@babel/preset-react": "^7.13.13",
3132
"@babel/preset-typescript": "^7.13.0",
3233
"@commitlint/cli": "^12.1.4",
3334
"@commitlint/config-conventional": "^12.1.4",
34-
"@rollup/plugin-commonjs": "^19.0.0",
35-
"@rollup/plugin-node-resolve": "^13.0.0",
36-
"@types/node": "^15.6.1",
37-
"@types/react": "^17.0.8",
38-
"@types/react-dom": "^17.0.5",
39-
"@types/react-router": "^5.1.14",
40-
"@typescript-eslint/eslint-plugin": "^4.25.0",
41-
"@typescript-eslint/parser": "^4.25.0",
35+
"@rollup/plugin-babel": "^5.3.0",
36+
"@rollup/plugin-typescript": "^8.2.1",
37+
"@types/react": "^17.0.9",
38+
"@types/react-dom": "^17.0.6",
39+
"@types/react-router": "^5.1.15",
40+
"@typescript-eslint/eslint-plugin": "^4.26.1",
41+
"@typescript-eslint/parser": "^4.26.1",
4242
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
4343
"babel-eslint": "^10.1.0",
44-
"babel-jest": "^27.0.1",
4544
"coveralls": "^3.1.0",
4645
"enzyme": "^3.11.0",
47-
"eslint": "^7.27.0",
46+
"eslint": "^7.28.0",
4847
"eslint-config-airbnb": "^18.2.1",
49-
"eslint-plugin-import": "^2.23.3",
48+
"eslint-plugin-import": "^2.23.4",
5049
"eslint-plugin-jsx-a11y": "^6.4.1",
51-
"eslint-plugin-react": "^7.23.2",
52-
"eslint-plugin-react-hooks": "^4.2.0",
50+
"eslint-plugin-react": "^7.24.0",
5351
"husky": "^6.0.0",
54-
"jest": "^27.0.1",
52+
"jest": "^27.0.4",
5553
"jsdom": "^16.6.0",
5654
"jsdom-global": "^3.0.2",
5755
"pinst": "^2.1.6",
5856
"prop-types": "^15.7.2",
5957
"react": "17.0.2",
6058
"react-dom": "17.0.2",
6159
"react-router": "^5.2.0",
62-
"rollup": "^2.50.1",
63-
"rollup-plugin-babel": "^4.4.0",
60+
"rollup": "^2.51.1",
61+
"rollup-plugin-size": "^0.2.2",
6462
"rollup-plugin-terser": "^7.0.2",
65-
"rollup-plugin-typescript2": "^0.30.0",
66-
"typescript": "4.1.5"
63+
"typescript": "4.3.2"
6764
},
6865
"keywords": [
6966
"react",

rollup.config.js

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,51 @@
1-
import babel from 'rollup-plugin-babel';
2-
import commonjs from '@rollup/plugin-commonjs';
3-
import resolve from '@rollup/plugin-node-resolve';
4-
import typescript from 'rollup-plugin-typescript2';
5-
import ts from 'typescript';
1+
import babel from '@rollup/plugin-babel';
2+
import typescript from '@rollup/plugin-typescript';
3+
import size from 'rollup-plugin-size';
64
import { terser } from 'rollup-plugin-terser';
75

86
const pkg = require('./package.json');
97

10-
const external = Object.keys(pkg.peerDependencies);
8+
const external = Object.keys(pkg.peerDependencies).concat(/@babel\/runtime/);
119

1210
const extensions = ['.js', '.tsx'];
1311

14-
const plugins = [
15-
typescript({
16-
useTsconfigDeclarationDir: true,
17-
tsconfigOverride: {
18-
typescript: ts,
19-
compilerOptions: {
20-
module: 'es2015',
21-
},
22-
},
23-
}),
12+
const sharedPlugins = [
13+
typescript(),
2414
babel({
15+
babelHelpers: 'runtime',
2516
exclude: 'node_modules/**',
2617
extensions,
2718
}),
28-
resolve({
29-
mainFields: ['module', 'main', 'umd'],
30-
extensions,
31-
}),
19+
size(),
3220
];
3321

3422
const formats = [
35-
{ format: 'cjs', file: pkg.main, plugins: plugins.concat([commonjs(), terser()]) },
36-
{ format: 'umd', file: pkg.umd, plugins: plugins.concat([commonjs(), terser()]) },
37-
{ format: 'es', file: pkg.module, plugins },
23+
{ format: 'umd', file: pkg.umd, plugins: sharedPlugins.concat([terser({ format: { comments: false } })]) },
24+
{ format: 'cjs', file: pkg.main, plugins: sharedPlugins },
25+
{ format: 'es', file: pkg.module, plugins: sharedPlugins },
3826
];
3927

4028
const globals = {
4129
react: 'React',
4230
'react-router': 'ReactRouter',
4331
};
4432

45-
export default formats.map((item) => ({
33+
export default formats.map(({ plugins, file, format }) => ({
4634
input: 'src/index.tsx',
47-
plugins: item.plugins,
35+
plugins,
4836
external,
4937
output: {
5038
exports: 'named',
51-
file: item.file,
52-
format: item.format,
39+
file,
40+
format,
5341
name: 'react-router-breadcrumbs-hoc',
54-
globals,
55-
sourcemap: true,
42+
globals: format !== 'umd'
43+
? globals
44+
: {
45+
...globals,
46+
'@babel/runtime/helpers/toConsumableArray': '_toConsumableArray',
47+
'@babel/runtime/helpers/defineProperty': '_defineProperty',
48+
'@babel/runtime/helpers/objectWithoutProperties': '_objectWithoutProperties',
49+
},
5650
},
5751
}));

src/index.tsx

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020

2121
import React, { createElement } from 'react';
22-
import { useLocation, matchPath, withRouter } from 'react-router';
22+
import { useLocation, matchPath } from 'react-router';
2323

2424
const DEFAULT_MATCH_OPTIONS = { exact: true };
2525
const NO_BREADCRUMB = 'NO_BREADCRUMB';
@@ -269,48 +269,30 @@ const flattenRoutes = (routes: BreadcrumbsRoute[]) => (routes)
269269
}, [] as BreadcrumbsRoute[]);
270270

271271
/**
272-
* This is the main default HOC wrapper component. There is some
273-
* logic in here for legacy react-router v4 support
272+
* Accepts optional routes array and options and returns an array of
273+
* breadcrumbs.
274+
*
275+
* @example
276+
* import withBreadcrumbs from 'react-router-breadcrumbs-hoc';
277+
* const Breadcrumbs = ({ breadcrumbs }) => (
278+
* <>{breadcrumbs.map(({ breadcrumb }) => breadcrumb)}</>
279+
* )
280+
* export default withBreadcrumbs()(Breadcrumbs);
274281
*/
275-
export default (
282+
const withBreadcrumbs = (
276283
routes?: BreadcrumbsRoute[],
277284
options?: Options,
278285
) => (
279286
Component: React.ComponentType<{
280287
breadcrumbs: Array<React.ReactNode | string>
281288
}>,
282-
) => {
283-
const sharedBreadcrumbProps = {
289+
) => (props: any) => React.createElement(Component, {
290+
...props,
291+
breadcrumbs: getBreadcrumbs({
284292
options,
285293
routes: flattenRoutes(routes || []),
286-
};
287-
288-
// use the location hook if available (5.x)
289-
/* istanbul ignore else */
290-
if (useLocation) {
291-
return (props: any) => React.createElement(Component, {
292-
...props,
293-
breadcrumbs: getBreadcrumbs({
294-
...sharedBreadcrumbProps,
295-
location: useLocation(),
296-
}),
297-
});
298-
}
294+
location: useLocation(),
295+
}),
296+
});
299297

300-
// fallback to withRouter for older react-router versions (4.x)
301-
/* istanbul ignore next */
302-
return withRouter(
303-
(props: { location: Location }) => {
304-
// eslint-disable-next-line no-console
305-
console.warn('[react-router-breadcrumbs-hoc]: react-router v4 support will be deprecated in the next major release. Please consider upgrading react-router and react-router-dom to >= 5.1.0');
306-
307-
return createElement(Component, {
308-
...props,
309-
breadcrumbs: getBreadcrumbs({
310-
...sharedBreadcrumbProps,
311-
location: props.location,
312-
}),
313-
});
314-
},
315-
);
316-
};
298+
export default withBreadcrumbs;

tsconfig.json

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
{
22
"compilerOptions": {
3-
"allowJs": true,
4-
"checkJs": true,
53
"esModuleInterop": true,
4+
"forceConsistentCasingInFileNames": true,
65
"jsx": "react",
7-
"lib": ["es2015", "dom"],
8-
"module": "commonjs",
6+
"module": "esnext",
97
"moduleResolution": "node",
10-
"noEmit": true,
11-
"noImplicitAny": true,
12-
"noImplicitReturns": true,
13-
"noImplicitThis": true,
14-
"noUnusedLocals": true,
15-
"noUnusedParameters": true,
16-
"outDir": "./dist",
17-
"strictFunctionTypes": true,
18-
"strictNullChecks": true,
19-
"strictPropertyInitialization": true,
20-
"target": "es5",
21-
"declaration": true,
22-
"declarationDir": "./dist"
8+
"outDir": "dist",
9+
"removeComments": true,
10+
"strict": true,
11+
"target": "es6"
2312
},
2413
"files": [
2514
"src/index.tsx"

0 commit comments

Comments
 (0)