Skip to content

Commit 0551f03

Browse files
authored
feat: Move react-virtual into vendored dependencies (#2071)
1 parent 6e03e44 commit 0551f03

17 files changed

+111
-60
lines changed

.eslintrc.js

+5
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ module.exports = {
174174
message:
175175
'`d3-scale` gets shipped as a bundled dependency. Use `src/internal/vendor/d3-scale` as import source.',
176176
},
177+
{
178+
group: ['react-virtual', '!**/vendor/react-virtual'],
179+
message:
180+
'`react-virtual` gets shipped as a bundled dependency. Use `src/internal/vendor/react-virtual` as import source.',
181+
},
177182
],
178183
},
179184
],

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ src/index.ts
99
src/test-utils/dom/index.ts
1010
src/test-utils/selectors
1111
src/internal/generated/custom-css-properties/index.*
12-
vendor/generated-third-party-licenses.txt
12+
vendor/generated-*.txt

package-lock.json

+9-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
"mnth": "^2.0.0",
4444
"react-keyed-flatten-children": "^1.3.0",
4545
"react-transition-group": "^4.4.2",
46-
"react-virtual": "^2.8.2",
4746
"tslib": "^2.4.0",
4847
"weekstart": "^1.1.0"
4948
},
@@ -120,6 +119,7 @@
120119
"react-dom": "^16.14.0",
121120
"react-router-dom": "^5.3.0",
122121
"react-test-renderer": "^16.14.0",
122+
"react-virtual": "^2.8.2",
123123
"replace-in-files": "^3.0.0",
124124
"rimraf": "^5.0.5",
125125
"rollup": "^3.5.1",

src/area-chart/__tests__/area-chart-model-utils.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { ChartScale, NumericChartScale } from '../../internal/components/cartesian-chart/scales';
4-
import { ChartModel } from '../model';
3+
import { ChartScale, NumericChartScale } from '../../../lib/components/internal/components/cartesian-chart/scales';
4+
import { ChartModel } from '../../../lib/components/area-chart/model';
55
import {
66
computeDomainX,
77
computeDomainY,
88
computePlotPoints,
99
findClosest,
1010
circleIndex,
1111
isSeriesValid,
12-
} from '../model/utils';
12+
} from '../../../lib/components/area-chart/model/utils';
1313

1414
function getPointIndices(matrix: ChartModel.PlotPoint<number>[][]) {
1515
const indices = [];

src/area-chart/__tests__/area-chart-use-chart-model.test.tsx

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
// SPDX-License-Identifier: Apache-2.0
33
import React, { useState, useImperativeHandle, useRef } from 'react';
44

5-
import useChartModel, { UseChartModelProps } from '../model/use-chart-model';
5+
import useChartModel, { UseChartModelProps } from '../../../lib/components/area-chart/model/use-chart-model';
66
import { ElementWrapper } from '@cloudscape-design/test-utils-core/dom';
7-
import { ChartDataTypes } from '../../internal/components/cartesian-chart/interfaces';
7+
import { KeyCode } from '@cloudscape-design/test-utils-core/utils';
8+
import { ChartDataTypes } from '../../../lib/components/internal/components/cartesian-chart/interfaces';
89
import { act, render, fireEvent } from '@testing-library/react';
9-
import { AreaChartProps } from '../interfaces';
10-
import { KeyCode } from '../../internal/keycode';
11-
import { useReaction } from '../async-store';
12-
import { ChartModel } from '../model';
10+
import { AreaChartProps } from '../../../lib/components/area-chart/interfaces';
11+
import { useReaction } from '../../../lib/components/area-chart/async-store';
12+
import { ChartModel } from '../../../lib/components/area-chart/model';
1313
import PlotPoint = ChartModel.PlotPoint;
1414

1515
class UseChartModelWrapper extends ElementWrapper {

src/internal/hooks/use-virtual/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import React, { useEffect, useMemo, useRef } from 'react';
4-
import { useVirtual as useVirtualDefault, VirtualItem } from 'react-virtual';
4+
import { useVirtual as useVirtualDefault, VirtualItem } from '../../vendor/react-virtual';
55

66
const MAX_ITEM_MOUNTS = 100;
77

src/internal/vendor/__tests__/__snapshots__/d3-scale-third-party-licences.test.ts.snap src/internal/vendor/__tests__/__snapshots__/third-party-licences.test.ts.snap

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`d3-scale-third-party-licenses.txt content stays unchanged without any d3-scale version changes 1`] = `
3+
exports[`Vendor licenses attribution for d3-scale 1`] = `
44
"Name: d3-array
55
Version: 3.2.1
66
License: ISC
@@ -222,3 +222,38 @@ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
222222
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
223223
THIS SOFTWARE."
224224
`;
225+
226+
exports[`Vendor licenses attribution for react-virtual 1`] = `
227+
"Name: react-virtual
228+
Version: 2.10.4
229+
License: MIT
230+
Private: false
231+
Description: Hooks for virtualizing scrollable elements in React
232+
Repository: undefined
233+
Homepage: https://github.com/tannerlinsley/react-virtual#readme
234+
Author: tannerlinsley
235+
License Copyright:
236+
===
237+
238+
MIT License
239+
240+
Copyright (c) 2019 Tanner Linsley
241+
242+
Permission is hereby granted, free of charge, to any person obtaining a copy
243+
of this software and associated documentation files (the \\"Software\\"), to deal
244+
in the Software without restriction, including without limitation the rights
245+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
246+
copies of the Software, and to permit persons to whom the Software is
247+
furnished to do so, subject to the following conditions:
248+
249+
The above copyright notice and this permission notice shall be included in all
250+
copies or substantial portions of the Software.
251+
252+
THE SOFTWARE IS PROVIDED \\"AS IS\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
253+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
254+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
255+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
256+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
257+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
258+
SOFTWARE."
259+
`;

src/internal/vendor/__tests__/d3-scale-third-party-licences.test.ts

-15
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
import path from 'path';
4+
import fs from 'fs';
5+
6+
const licensesDir = path.resolve(__dirname, '../../../../vendor/');
7+
8+
describe('Vendor licenses attribution', () => {
9+
test('for d3-scale', () => {
10+
const content = fs.readFileSync(path.join(licensesDir, 'generated-third-party-licenses-d3-scale.txt'), 'utf8');
11+
expect(content).toMatchSnapshot();
12+
});
13+
test('for react-virtual', () => {
14+
const content = fs.readFileSync(path.join(licensesDir, 'generated-third-party-licenses-react-virtual.txt'), 'utf8');
15+
expect(content).toMatchSnapshot();
16+
});
17+
});
File renamed without changes.

src/internal/vendor/d3-scale.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// This file is only for the compiler. The artifacts will contain the generated bundle instead.
5+
// `d3-scale` and its transitive dependencies are using ESM format which causes
6+
// issues during unit tests at clients using jest and do not have the associated
7+
// jest-preset package installed.
8+
// eslint-disable-next-line no-restricted-imports
9+
export { scaleLinear, scaleLog, scaleTime, scaleBand } from 'd3-scale';
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// eslint-disable-next-line no-restricted-imports
5+
export { useVirtual, VirtualItem } from 'react-virtual';

src/internal/vendor/react-virtual.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
// eslint-disable-next-line no-restricted-imports
5+
export { useVirtual } from 'react-virtual';

src/select/utils/render-options.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33
import React from 'react';
4-
import { VirtualItem } from 'react-virtual';
4+
import { VirtualItem } from '../../internal/vendor/react-virtual';
55
import Item from '../parts/item';
66
import MutliselectItem from '../parts/multiselect-item';
77
import { DropdownOption } from '../../internal/components/option/interfaces';

tsconfig.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"src/test-utils/**",
2121
"**/__integ__/**",
2222
"**/__a11y__/**",
23-
"**/__motion__/**",
24-
"src/internal/vendor/**"
23+
"**/__motion__/**"
2524
]
2625
}

vendor/rollup.config.mjs

+11-28
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,42 @@ import * as path from 'path';
66
import { fileURLToPath } from 'url';
77
import commenting from 'commenting';
88
import { readFileSync } from 'fs';
9-
import { sync as rimrafSync } from 'rimraf';
109

1110
const dirName = path.dirname(fileURLToPath(import.meta.url));
12-
13-
const vendorFileName = 'd3-scale.js';
1411
const vendorFolder = path.join(dirName, '../lib/components/internal/vendor');
15-
const vendorFile = path.join(vendorFolder, vendorFileName);
16-
const d3LicencesFile = path.join(dirName, 'generated-third-party-licenses.txt');
12+
const licensesFile = path.join(dirName, 'generated-third-party-licenses.txt');
1713

18-
export default {
19-
input: vendorFile,
14+
export default ['d3-scale', 'react-virtual'].map(entry => ({
15+
input: `./src/internal/vendor/${entry}.js`,
2016
output: {
21-
file: vendorFile,
17+
dir: vendorFolder,
2218
format: 'es',
2319
},
20+
external: ['react', 'react-dom'],
2421
plugins: [
2522
resolve({
2623
extensions: ['.js'],
2724
}),
2825
license({
2926
thirdParty: {
3027
output: {
31-
file: d3LicencesFile,
28+
file: path.join(dirName, `generated-third-party-licenses-${entry}.txt`),
3229
encoding: 'utf-8',
3330
},
3431
},
3532
}),
36-
attach3rdPartyLicenses(),
37-
removeVendorFolder(),
33+
attach3rdPartyLicenses(entry),
3834
],
39-
};
40-
41-
function removeVendorFolder() {
42-
return {
43-
name: 'remove-vendor-folder',
44-
generateBundle: {
45-
sequential: true,
46-
order: 'pre',
47-
handler() {
48-
rimrafSync(vendorFolder);
49-
},
50-
},
51-
};
52-
}
35+
}));
5336

5437
// Rollup plugin which prepends the generated 3rd party licences content to the bundled code before writing the file.
55-
function attach3rdPartyLicenses() {
38+
function attach3rdPartyLicenses(entry) {
5639
return {
5740
name: 'attach-3rd-party-licences',
5841
generateBundle(_options, bundle) {
59-
const content = readFileSync(d3LicencesFile, 'utf8');
42+
const content = readFileSync(path.join(dirName, `generated-third-party-licenses-${entry}.txt`), 'utf8');
6043
const comment = commenting(content, { extension: '.js' });
61-
bundle[vendorFileName].code = `${comment}${bundle[vendorFileName].code}`;
44+
bundle[`${entry}.js`].code = `${comment}${bundle[`${entry}.js`].code}`;
6245
},
6346
};
6447
}

0 commit comments

Comments
 (0)