Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade typescript to ^4.2.0 and fix lint issues #1156

Merged
merged 45 commits into from
May 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
77f84d2
Upgrade typescript to ^4.2.0 and fix lint issues
PiotrKozlowski Apr 28, 2021
910476d
Upgrade react-scripts to ^4.0.3
PiotrKozlowski Apr 28, 2021
13ab6ad
Add craco and set url: false in css-loader
PiotrKozlowski Apr 28, 2021
03c181a
Fix lint issues
PiotrKozlowski Apr 28, 2021
be76f0b
Fix part of unit tests
PiotrKozlowski Apr 28, 2021
6630820
Fix another part of unit tests
PiotrKozlowski Apr 28, 2021
fd5550d
Handle ServiceWorker in a new way
PiotrKozlowski Apr 29, 2021
004d7c7
Fix ts errors
PiotrKozlowski Apr 29, 2021
d38ceab
Fix new lint errors
PiotrKozlowski Apr 29, 2021
9d12d67
revert this lint fix due to compilation errors - it should be fixed a…
PiotrKozlowski Apr 29, 2021
e2042d9
Move also service-worker.js.map to books folder
PiotrKozlowski Apr 29, 2021
5b77f29
Fix one more lint error and test
PiotrKozlowski Apr 29, 2021
3fb7cb7
Merge branch 'master' into issue-1469
staxly[bot] Apr 29, 2021
947941c
change AnyRoute signature and add assertNonNullableArray util
PiotrKozlowski Apr 30, 2021
fab6a17
Merge branch 'issue-1469' of github.com:openstax/rex-web into issue-1469
PiotrKozlowski Apr 30, 2021
4521533
small fix for test
PiotrKozlowski Apr 30, 2021
118f7b8
Merge branch 'master' into issue-1469
staxly[bot] Apr 30, 2021
3f38210
Merge branch 'master' into issue-1469
staxly[bot] May 3, 2021
86e5457
Do not use any for animationEvent function
PiotrKozlowski May 4, 2021
b58f604
update loadFont helper
PiotrKozlowski May 4, 2021
789ea7f
Update serviceWorker.ts
PiotrKozlowski May 4, 2021
d85a8fd
remove unused workbox plugins
PiotrKozlowski May 4, 2021
4d1fcc2
Revert "remove unused workbox plugins"
PiotrKozlowski May 6, 2021
eed4309
Merge branch 'master' into issue-1469
PiotrKozlowski May 6, 2021
797c68f
Use craco to move service-worker.js to build/books/
PiotrKozlowski May 6, 2021
d8ea5e4
Remove check for process.env.PUBLIC_URL
PiotrKozlowski May 6, 2021
5be0e06
Default value for process.env.PUBLIC_URL
PiotrKozlowski May 6, 2021
b82a166
remove unused workbox plugins
PiotrKozlowski May 4, 2021
814fc2b
Check if PUBLIC_URL is undefined instead of falsy
PiotrKozlowski May 6, 2021
9efe6bb
Merge branch 'master' into issue-1469
staxly[bot] May 7, 2021
5a86df1
Merge branch 'master' into issue-1469
staxly[bot] May 7, 2021
2c584be
Merge branch 'master' into issue-1469
staxly[bot] May 7, 2021
9f15760
Merge branch 'master' into issue-1469
staxly[bot] May 10, 2021
6942aa2
requested changes
PiotrKozlowski May 11, 2021
598605c
Merge branch 'master' into issue-1469
PiotrKozlowski May 11, 2021
6464dba
remove assertNonNullable
PiotrKozlowski May 11, 2021
a3fd8df
Update @openstax/types
PiotrKozlowski May 12, 2021
a74703b
Do not use deprecated matchMedia.add/removeListener methods
PiotrKozlowski May 12, 2021
8499773
add global KeyboardEventConstructor
jarosik10 Apr 30, 2021
e461755
fix lint and tests
jarosik10 Apr 30, 2021
f055aea
smaller fixes
PiotrKozlowski May 12, 2021
2e23eb9
No need to mock navigation state in Home.spec.tsx
PiotrKozlowski May 12, 2021
d31dc68
Add @babel/plugin-proposal-optional-chaining to babel-config.js
PiotrKozlowski May 12, 2021
497bcec
Update node_modules cache
PiotrKozlowski May 12, 2021
5c58dcd
requested changes
PiotrKozlowski May 13, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
id: node_modules
with:
path: node_modules
key: node_modules5
key: node_modules6
- run: yarn install
- name: Find Deployment
id: find-deployment
Expand Down Expand Up @@ -62,7 +62,7 @@ jobs:
id: node_modules
with:
path: node_modules
key: node_modules5
key: node_modules6
- run: yarn install
- run: ./script/validate-modified-books.bash
env:
Expand All @@ -86,7 +86,7 @@ jobs:
id: node_modules
with:
path: node_modules
key: node_modules5
key: node_modules6
- run: yarn install
- run: yarn ci:test:${{ matrix.suite }}
- uses: actions/upload-artifact@v2
Expand All @@ -107,6 +107,6 @@ jobs:
id: node_modules
with:
path: node_modules
key: node_modules5
key: node_modules6
- run: yarn install
- run: yarn lint
39 changes: 39 additions & 0 deletions craco.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const path = require('path');

module.exports = {
plugins: [{
plugin: {
// Based on https://github.com/kevinsperrine/craco-workbox/blob/master/lib/index.js
overrideWebpackConfig: ({ webpackConfig, context: { env, paths } }) => {
if (env === "production") {
try {
const workboxConfig = require(path.join(
paths.appPath,
"workbox.config.js"
));

webpackConfig.plugins.forEach(plugin => {
if (plugin.constructor.name === "InjectManifest") {
plugin.config = workboxConfig(plugin.config);
}
});
} catch (error) {
console.log("[craco.config.js - overrideWebpackConfig]");
console.log(error.stack);
process.exit(1);
}
}

return webpackConfig;
}
},
}],
style: {
css: {
loaderOptions: {
// https://github.com/openstax/unified/issues/1469
url: false,
TomWoodward marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
};
23 changes: 15 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@craco/craco": "^6.1.2",
"@formatjs/intl-pluralrules": "^4.0.6",
"@openstax/highlighter": "^1.9.0",
"@openstax/open-search-client": "0.1.0",
Expand All @@ -27,7 +28,7 @@
"react-intl": "^5.12.0",
"react-loadable": "^5.5.0",
"react-redux": "^7.1.0",
"react-scripts": "3.4.4",
"react-scripts": "^4.0.3",
"redux": "^4.0.1",
"redux-sentry-middleware": "^0.2.2",
"reselect": "^4.0.0",
Expand All @@ -36,10 +37,15 @@
"styled-components": "^4.3.2",
"styled-icons": "^8.1.0",
"typesafe-actions": "^4.4.2",
"typescript": "3.9.6",
"typescript": "^4.2.0",
"url": "^0.11.0",
"uuid": "^3.4.0",
"weak-map": "^1.0.5"
"weak-map": "^1.0.5",
"workbox-core": "^5.1.3",
"workbox-expiration": "^5.1.3",
"workbox-precaching": "^5.1.3",
"workbox-routing": "^5.1.3",
"workbox-strategies": "^5.1.3"
},
"scripts": {
"trust-localhost": "./script/trust-localhost.bash",
Expand All @@ -49,12 +55,12 @@
"lint:css": "stylelint 'src/**/*.tsx'",
"lint:bash": "shellcheck $(find . -type f \\( -iname '*\\.sh' -or -iname '*\\.bash' \\) | grep -v 'node_modules' )",
"prestart": "npm run-script build:css",
"start": "HTTPS=${HTTPS:-true} react-scripts start",
"start": "HTTPS=${HTTPS:-true} craco start",
"start:static": "export REACT_APP_ENV=${REACT_APP_ENV:-test} && npm run-script build && npm run-script prerender && npm run-script server",
"clean": "rm -rf ./build",
"build": "npm run-script build:css && npm run-script build:js && ./script/doctor-workbox.bash",
"build": "npm run-script build:css && npm run-script build:js",
"build:css": "lessc --source-map --source-map-include-source ./generic-styles/index.less ./src/content.css",
"build:js": "export REACT_APP_ENV=${REACT_APP_ENV:-production} && GENERATE_SOURCEMAP=${GENERATE_SOURCEMAP:-true} react-scripts build",
"build:js": "export REACT_APP_ENV=${REACT_APP_ENV:-production} && GENERATE_SOURCEMAP=${GENERATE_SOURCEMAP:-true} craco build",
"build:clean": "npm run-script clean && npm run-script build",
"prerender": "REACT_APP_ENV=${REACT_APP_ENV:-production} node ./script/entry prerender/index",
"server": "REACT_APP_ENV=${REACT_APP_ENV:-development} node ./script/entry server/cli",
Expand All @@ -76,7 +82,7 @@
"test:prerender:browser": "REACT_APP_ENV=test SERVER_MODE=built jest --testPathPattern=\"(\\.|/)browserspec\\.tsx?\" --config jest-puppeteer.config.json -i",
"test:prerender:screenshots": "REACT_APP_ENV=test SERVER_MODE=built jest --testPathPattern=\"(\\.|/)screenshotspec\\.tsx?\" --config jest-puppeteer.config.json",
"test:lighthouse-manual": "REACT_APP_ENV=test lighthouse --view --config-path=./src/test/audits/index.js",
"analyze:bundle": "react-scripts build && source-map-explorer 'build/static/js/*.js' -m",
"analyze:bundle": "craco build && source-map-explorer 'build/static/js/*.js' -m",
"analyze:dom": "node ./script/entry.js domVisitor",
"heroku-postbuild": "npm run-script build:clean"
},
Expand All @@ -93,12 +99,13 @@
"@babel/core": "^7.0.0-0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-object-rest-spread": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.13.12",
"@babel/plugin-transform-runtime": "^7.1.0",
"@babel/preset-env": "^7.1.6",
"@babel/preset-react": "^7.0.0",
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0",
"@openstax/types": "^1.0.3",
"@openstax/types": "^2.0.0",
"@types/color": "^3.0.0",
"@types/express": "^4.16.0",
"@types/flat": "^0.0.28",
Expand Down
84 changes: 0 additions & 84 deletions script/doctor-workbox.bash

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const TabHiddenDropDown = styled((
const container = React.useRef<HTMLElement>(null);
const toggleElement = React.useRef<HTMLElement>(null);

useFocusLost(container, isOpen, () => setOpen(false));
useFocusLost(container, isOpen, React.useCallback(() => setOpen(false), [setOpen]));
useOnEsc(container, isOpen, () => {
setOpen(false);
if (toggleElement.current) { toggleElement.current.focus(); }
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/BookBanner.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('BookBanner', () => {
resetModules();

window = assertWindow();
delete window.location;
delete (window as any).location;

window.location = {
assign: jest.fn(),
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/NudgeStudyTools/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const NudgeStudyTools = () => {
if (positions) {
document.body.style.overflow = 'hidden';
}
return () => { document.body.style.overflow = null; };
return () => { document.body.style.overflow = ''; };
// document will not change
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [positions]);
Expand Down
4 changes: 2 additions & 2 deletions src/app/content/components/NudgeStudyTools/utils.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ClientRect, HTMLElement } from '@openstax/types/lib.dom';
import { DOMRect, HTMLElement } from '@openstax/types/lib.dom';
import * as Cookies from 'js-cookie';
import React from 'react';
import { Provider } from 'react-redux';
Expand All @@ -17,7 +17,7 @@ describe('usePositions', () => {
let store: Store;
// tslint:disable-next-line: variable-name
let Component: (props: { isMobile: boolean }) => JSX.Element;
const mockRect = { bottom: 228, height: 25, left: 951, right: 1233, top: 203, width: 282 } as any as ClientRect;
const mockRect = { bottom: 228, height: 25, left: 951, right: 1233, top: 203, width: 282 } as any as DOMRect;

beforeEach(() => {
const document = assertDocument();
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/Page.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ describe('Page', () => {
event.initMouseEvent('click',
event.cancelBubble,
event.cancelable,
event.view,
assertWindow(),
event.detail,
event.screenX,
event.screenY,
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/Page/contentLinkHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export const contentLinkHandler = (anchor: HTMLAnchorElement, getProps: () => Co
return;
}

const base = new URL(assertWindow().location);
const base = new URL(assertWindow().location.href);
TomWoodward marked this conversation as resolved.
Show resolved Hide resolved
base.hash = '';
base.search = '';

Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/Page/highlightManager.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('highlightManager', () => {
});

afterEach(() => {
delete window.document.getSelection;
delete (window as any).document.getSelection;
});

it('CardList is rendered initially', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/components/Page/highlightManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const onSelectHighlight = (
}

if (services.getProp().hasUnsavedHighlight && !await showConfirmation()) {
assertWindow().getSelection().removeAllRanges();
assertWindow().getSelection()?.removeAllRanges();
return;
}

Expand Down
2 changes: 2 additions & 0 deletions src/app/content/components/utils/allImagesLoaded.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ describe('allImagesLoaded', () => {
finished = false;
element = assertDocument().createElement('div');
img = assertDocument().createElement('img');

Object.defineProperty(img, 'complete', { value: false, writable: true });
});

it('resolves when passed an element with no images', async() => {
Expand Down
2 changes: 2 additions & 0 deletions src/app/content/content.prerenderspec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ describe('content', () => {
['[data-testid="toc"]', 'style'],
['[data-testid="search-results-sidebar"]', 'style'],
['[data-testid="loader"] path', 'style'],
// img src is changed from data:image/svg+xml;base64... to static path
['[data-testid="navbar"] img', 'src'],
].forEach(([selector, attribute]) => {
root.querySelectorAll(selector).forEach((element) =>
element.removeAttribute(attribute)
Expand Down
19 changes: 9 additions & 10 deletions src/app/content/highlights/components/CardWrapper.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ const dispatchKeyDownEvent = (
key: string,
target?: HTMLElement
) => {
const keyboardEvent = window.document.createEvent('KeyboardEvent');
keyboardEvent.initKeyboardEvent('keydown', true, true, window, key, 0, '', false, '');
const keyboardEvent = new KeyboardEvent('keydown', { bubbles: true, cancelable: true, key, view: window });
if (target) {
Object.defineProperty(keyboardEvent, 'target', { value: target });
}
Expand Down Expand Up @@ -178,23 +177,23 @@ describe('CardWrapper', () => {

// Update state with a height
renderer.act(() => {
card1.props.onHeightChange({ current: { offsetHeight: 100 }});
card2.props.onHeightChange({ current: { offsetHeight: 100 }});
card1.props.onHeightChange({ current: { offsetHeight: 100 } });
card2.props.onHeightChange({ current: { offsetHeight: 100 } });
});
// We are starting at 100 because of getHighlightTopOffset mock
expect(card1.props.topOffset).toEqual(100);
expect(card2.props.topOffset).toEqual(100 + 100 + remsToPx(cardMarginBottom));

// Noops when height is the same
renderer.act(() => {
card1.props.onHeightChange({ current: { offsetHeight: 100 }});
card1.props.onHeightChange({ current: { offsetHeight: 100 } });
});
expect(card1.props.topOffset).toEqual(100);
expect(card2.props.topOffset).toEqual(100 + 100 + remsToPx(cardMarginBottom));

// Handle null value
renderer.act(() => {
card1.props.onHeightChange({ current: { offsetHeight: null }});
card1.props.onHeightChange({ current: { offsetHeight: null } });
});
// First card have null height so secondcard starts at the highlight top offset
expect(card1.props.topOffset).toEqual(100);
Expand Down Expand Up @@ -228,10 +227,10 @@ describe('CardWrapper', () => {

// Update state with a height
renderer.act(() => {
card1.props.onHeightChange({ current: { offsetHeight: 50 }});
card2.props.onHeightChange({ current: { offsetHeight: 50 }});
card3.props.onHeightChange({ current: { offsetHeight: 50 }});
card4.props.onHeightChange({ current: { offsetHeight: 50 }});
card1.props.onHeightChange({ current: { offsetHeight: 50 } });
card2.props.onHeightChange({ current: { offsetHeight: 50 } });
card3.props.onHeightChange({ current: { offsetHeight: 50 } });
card4.props.onHeightChange({ current: { offsetHeight: 50 } });
});
expect(card1.props.topOffset).toEqual(0); // first card have only 50px height + 20px margin bottom
expect(card2.props.topOffset).toEqual(100); // so the second cards starts and the highlight level which is 100
Expand Down
2 changes: 1 addition & 1 deletion src/app/content/highlights/components/CardWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const Wrapper = ({highlights, className, container, highlighter}: WrapperProps)

// Clear shouldFocusCard when focus is lost from the CardWrapper.
// If we don't do this then card related for the focused highlight will be focused automatically.
useFocusLost(element, shouldFocusCard, () => setShouldFocusCard(false));
useFocusLost(element, shouldFocusCard, React.useCallback(() => setShouldFocusCard(false), [setShouldFocusCard]));

const onHeightChange = React.useCallback((id: string, ref: React.RefObject<HTMLElement>) => {
const height = ref.current && ref.current.offsetHeight;
Expand Down
Loading