Skip to content

Commit 11c1f93

Browse files
authored
chore: upgrade mustache and other deps (#508)
* chore: ignore pdf.js lib in public/assets * chore: upgrade mustache and other deps * chore: upgrade rollup TS plugin * chore: upgrade ts-loader
1 parent 1fe45d8 commit 11c1f93

File tree

19 files changed

+205
-200
lines changed

19 files changed

+205
-200
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
build
21
ibm-credentials.env
32
.env.local
3+
build
4+
public/assets/**

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@
2222
"@commitlint/config-conventional": "^11.0.0",
2323
"@testing-library/jest-dom": "^5.16.1",
2424
"@testing-library/react": "^11.2.7",
25-
"@testing-library/react-hooks": "^7.0.2",
25+
"@testing-library/react-hooks": "^8.0.1",
2626
"@types/babel__preset-env": "^7.9.2",
2727
"@types/classnames": "^2.2.9",
2828
"@types/debounce": "^1.2.0",
2929
"@types/dompurify": "^3.0.2",
3030
"@types/jest": "^24.0.18",
3131
"@types/lodash": "^4.14.141",
3232
"@types/md5": "2.3.2",
33-
"@types/mustache": "^0.8.32",
33+
"@types/mustache": "^4.2.2",
3434
"@types/node": "^16.18.23",
3535
"@types/react": "^17.0.38",
3636
"@types/react-dom": "^17.0.11",
@@ -74,7 +74,7 @@
7474
"regenerator-runtime": "^0.13.3",
7575
"seedrandom": "^3.0.5",
7676
"source-map-explorer": "2.0.1",
77-
"ts-loader": "^6.2.1",
77+
"ts-loader": "^9.4.2",
7878
"typescript": "^3.8.2",
7979
"vue": "^2.6.11",
8080
"webpack": "5.72.1",

packages/discovery-react-components/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@
3333
"dependencies": {
3434
"@react-hook/size": "^2.1.2",
3535
"buffer": "^6.0.3",
36-
"classnames": "^2.2.6",
37-
"debounce": "^1.2.0",
36+
"classnames": "^2.3.2",
37+
"debounce": "^1.2.1",
3838
"dompurify": "^3.0.2",
39-
"entities": "^4.4.0",
39+
"entities": "^4.5.0",
4040
"htmlparser2": "^4.0.0",
4141
"lodash": "^4.17.21",
42-
"mustache": "^3.1.0",
42+
"mustache": "^4.2.0",
4343
"pdfjs-dist": "2.6.347",
4444
"react-error-boundary": "^1.2.5",
4545
"react-resize-detector": "^4.2.1",
@@ -73,7 +73,7 @@
7373
"rollup": "^2.57.0",
7474
"rollup-plugin-string": "^3.0.0",
7575
"rollup-plugin-terser": "^7.0.2",
76-
"rollup-plugin-typescript2": "^0.30.0",
76+
"rollup-plugin-typescript2": "^0.34.1",
7777
"sass-embedded": "^1.52.2",
7878
"sass-loader": "^12.3.0",
7979
"style-loader": "^1.3.0",

packages/discovery-react-components/rollup.config.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ const COMMON_PLUGINS = [
5959
include: [pdfWorkerRegex]
6060
}),
6161
typescript({
62-
rollupCommonJSResolveHack: true,
6362
clean: true,
6463
tsconfig: 'tsconfig.prod.json'
6564
})

packages/discovery-react-components/src/components/CIDocument/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ export interface ItemMap {
4848

4949
export type EnrichedHtml = EnrichedHtmlContract | EnrichedHtmlInvoice | EnrichedHtmlPurchaseOrder;
5050

51-
interface EnrichedHtmlContract {
51+
export interface EnrichedHtmlContract {
5252
contract: Contract;
5353
}
54-
interface EnrichedHtmlInvoice {
54+
export interface EnrichedHtmlInvoice {
5555
invoice: Invoice;
5656
}
57-
interface EnrichedHtmlPurchaseOrder {
57+
export interface EnrichedHtmlPurchaseOrder {
5858
purchase_order: PurchaseOrder;
5959
}
6060

packages/discovery-react-components/src/components/CIDocument/utils/__tests__/elementFromPoint.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('elementFromPoint returns expected mock element', () => {
4242
});
4343

4444
it('runs elementsFromPoint function for standard web browsers', () => {
45-
document.elementsFromPoint = (x: number, y: number): Element[] => {
45+
document.elementsFromPoint = (_x: number, _y: number): Element[] => {
4646
return mockElements as unknown as Element[];
4747
};
4848

@@ -51,7 +51,7 @@ describe('elementFromPoint returns expected mock element', () => {
5151
});
5252

5353
it('runs elementFromPointMs function for MS Edge browser', () => {
54-
(document as MsDocument).msElementsFromPoint = (x: number, y: number): HTMLElement[] => {
54+
(document as MsDocument).msElementsFromPoint = (_x: number, _y: number): HTMLElement[] => {
5555
return mockElements as unknown as HTMLElement[];
5656
};
5757

@@ -61,7 +61,7 @@ describe('elementFromPoint returns expected mock element', () => {
6161

6262
it('runs elementFromPointFallback function for older browsers', () => {
6363
let nextElementIndex = 0;
64-
document.elementFromPoint = (x: number, y: number): Element | null => {
64+
document.elementFromPoint = (_x: number, _y: number): Element | null => {
6565
return nextElementIndex < mockElements.length
6666
? (mockElements[nextElementIndex++] as unknown as Element)
6767
: null;
@@ -73,7 +73,7 @@ describe('elementFromPoint returns expected mock element', () => {
7373

7474
it('runs elementFromPointFallback and fails to find element', () => {
7575
let nextElementIndex = 0;
76-
document.elementFromPoint = (x: number, y: number): Element | null => {
76+
document.elementFromPoint = (_x: number, _y: number): Element | null => {
7777
return nextElementIndex < mockElements.length
7878
? (mockElements[nextElementIndex++] as unknown as Element)
7979
: null;

packages/discovery-react-components/src/components/DocumentPreview/__tests__/DocumentPreview.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ describe('DocumentPreview', () => {
190190
const results = {
191191
matching_results: 1,
192192
results: [selectedResult]
193-
};
193+
} as unknown as DiscoveryV2.QueryResponse;
194194

195195
render(
196196
<DiscoverySearch
@@ -239,7 +239,7 @@ describe('DocumentPreview', () => {
239239
const results = {
240240
matching_results: 1,
241241
results: [selectedResult]
242-
};
242+
} as unknown as DiscoveryV2.QueryResponse;
243243

244244
render(
245245
<DiscoverySearch
@@ -289,7 +289,7 @@ describe('DocumentPreview', () => {
289289
const results = {
290290
matching_results: 1,
291291
results: [selectedResult]
292-
};
292+
} as unknown as DiscoveryV2.QueryResponse;
293293

294294
render(
295295
<DiscoverySearch

packages/discovery-react-components/src/components/DocumentPreview/components/PdfHighlight/utils/common/TextNormalizer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ function normalizeText(text: string): string {
145145
export class TextNormalizer {
146146
readonly rawText: string;
147147
readonly normalizedText: string;
148-
private readonly normalizationMappings: SpanMapping[];
148+
readonly normalizationMappings: SpanMapping[];
149149

150150
constructor(rawText: string) {
151151
this.rawText = rawText;

packages/discovery-react-components/src/components/DocumentPreview/components/SimpleDocument/__tests__/SimpleDocument.test.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import React from 'react';
22
import { act, render, BoundFunction, GetByText } from '@testing-library/react';
3+
import DiscoveryV2 from 'ibm-watson/discovery/v2';
34
import 'utils/test/createRange.mock';
4-
import SimpleDocument from '../SimpleDocument';
5+
import { wrapWithContext } from 'utils/testingUtils';
56
import docArrayJson from 'components/DocumentPreview/__fixtures__/ArtEffectsTextArray.json';
67
import { SearchApiIFC, SearchContextIFC } from 'components/DiscoverySearch/DiscoverySearch';
7-
import { wrapWithContext } from 'utils/testingUtils';
8+
import SimpleDocument from '../SimpleDocument';
89

910
const noop = (): any => {
1011
throw new Error();
@@ -16,7 +17,7 @@ describe('SimpleDocument', () => {
1617
extracted_metadata: {
1718
filename: 'i_am_a_file'
1819
}
19-
};
20+
} as unknown as DiscoveryV2.QueryResult;
2021

2122
beforeAll(() => {
2223
window.HTMLElement.prototype.scrollIntoView = jest.fn();
@@ -29,6 +30,8 @@ describe('SimpleDocument', () => {
2930
document={minimalDoc}
3031
setHideToolbarControls={(): void => {}}
3132
setLoading={(): void => {}}
33+
loading={false}
34+
hideToolbarControls={false}
3235
/>
3336
);
3437
});
@@ -42,9 +45,11 @@ describe('SimpleDocument', () => {
4245
act(() => {
4346
({ getByText } = render(
4447
<SimpleDocument
45-
document={docArrayJson}
48+
document={docArrayJson as unknown as DiscoveryV2.QueryResult}
4649
setLoading={(): void => {}}
4750
setHideToolbarControls={(): void => mock('setHideToolbarControls called')}
51+
loading={false}
52+
hideToolbarControls={false}
4853
/>
4954
));
5055
});
@@ -59,7 +64,7 @@ describe('SimpleDocument', () => {
5964
const documentText = 'This is the text of the document.';
6065
const customDoc = {
6166
body_field: documentText
62-
};
67+
} as unknown as DiscoveryV2.QueryResult;
6368
const context: Partial<SearchContextIFC> = {
6469
componentSettings: {
6570
fields_shown: {
@@ -79,6 +84,8 @@ describe('SimpleDocument', () => {
7984
document={customDoc}
8085
setHideToolbarControls={(): void => {}}
8186
setLoading={(): void => {}}
87+
loading={false}
88+
hideToolbarControls={false}
8289
/>,
8390
api,
8491
context
@@ -96,7 +103,7 @@ describe('SimpleDocument', () => {
96103
const customDoc = {
97104
body_field: bodyText,
98105
passage_field: passageText
99-
};
106+
} as unknown as DiscoveryV2.QueryResult;
100107

101108
const context: Partial<SearchContextIFC> = {
102109
componentSettings: {
@@ -126,6 +133,8 @@ describe('SimpleDocument', () => {
126133
highlight={highlight}
127134
setHideToolbarControls={(): void => {}}
128135
setLoading={(): void => {}}
136+
loading={false}
137+
hideToolbarControls={false}
129138
/>,
130139
api,
131140
context

packages/discovery-react-components/src/components/DocumentPreview/utils/__tests__/documentData.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { QueryResult } from 'ibm-watson/discovery/v2';
12
import { detectPreviewType, getTextMappings, isCsvFile, isJsonFile } from '../documentData';
23
import jsonDoc from '../../__fixtures__/Art Effects Koya Creative Base TSA 2008.pdf.json';
34

45
describe('documentData', () => {
56
const noMetadata = {
67
extracted_metadata: {}
7-
};
8+
} as unknown as QueryResult;
89

910
let consoleError: jest.SpyInstance<any, any>;
1011

@@ -73,7 +74,7 @@ describe('documentData', () => {
7374
extracted_metadata: {
7475
file_type: 'json'
7576
}
76-
};
77+
} as unknown as QueryResult;
7778
it('returns true if the document is a JSON file', () => {
7879
const docTypeJson = isJsonFile(jsonFileType);
7980
expect(docTypeJson).toEqual(true);
@@ -83,7 +84,7 @@ describe('documentData', () => {
8384
extracted_metadata: {
8485
file_type: 'csv'
8586
}
86-
};
87+
} as unknown as QueryResult;
8788
it('returns true if the document is a CSV file', () => {
8889
const docTypeJson = isCsvFile(csvFileType);
8990
expect(docTypeJson).toEqual(true);
@@ -93,7 +94,7 @@ describe('documentData', () => {
9394
extracted_metadata: {
9495
file_type: true
9596
}
96-
};
97+
} as unknown as QueryResult;
9798
it('returns false if the file type provided is not a string', () => {
9899
const falseDocType = isJsonFile(noStringFileType);
99100
expect(falseDocType).toEqual(false);

0 commit comments

Comments
 (0)