Skip to content

Commit 830ac81

Browse files
committed
upgrade to webpack5 to work with node18
1 parent 076cf79 commit 830ac81

10 files changed

+49138
-18200
lines changed

babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module.exports = {
2-
presets: [['@babel/preset-env', { targets: { node: 'current' } }], '@babel/preset-typescript', '@babel/preset-react'],
2+
presets: ['@babel/preset-env', '@babel/preset-typescript', '@babel/preset-react'],
33
}

dist/react-csv-reader.js

Lines changed: 184 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/react-csv-reader.js.LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
object-assign
3+
(c) Sindre Sorhus
4+
@license MIT
5+
*/
6+
7+
/* @license
8+
Papa Parse
9+
v5.3.2
10+
https://github.com/mholt/PapaParse
11+
License: MIT
12+
*/
13+
14+
/** @license React v16.14.0
15+
* react.production.min.js
16+
*
17+
* Copyright (c) Facebook, Inc. and its affiliates.
18+
*
19+
* This source code is licensed under the MIT license found in the
20+
* LICENSE file in the root directory of this source tree.
21+
*/

dist/react-csv-reader.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 31144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"license": "MIT",
1111
"types": "./dist/index.d.ts",
1212
"scripts": {
13-
"build": "webpack -p",
14-
"prerelease": "webpack -p",
13+
"build": "webpack --mode=development",
14+
"prerelease": "webpack --define-process-env-node-env production",
1515
"release": "release-it",
1616
"test": "jest --rootDir src",
1717
"watch": "webpack --watch --progress",
@@ -55,8 +55,8 @@
5555
"source-map-loader": "^0.2.4",
5656
"ts-loader": "^6.2.1",
5757
"typescript": "^3.8.3",
58-
"webpack": "^4.42.0",
59-
"webpack-cli": "^3.3.11"
58+
"webpack": "^5.75.0",
59+
"webpack-cli": "^5.0.1"
6060
},
6161
"peerDependencies": {
6262
"prop-types": "^15.7.2",

src/index.jsx

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import * as React from 'react';
2+
import * as PropTypes from 'prop-types';
3+
import * as PapaParse from 'papaparse';
4+
5+
const CSVReader = React.forwardRef(({ accept = '.csv, text/csv', cssClass = 'csv-reader-input', cssInputClass = 'csv-input', cssLabelClass = 'csv-label', fileEncoding = 'UTF-8', inputId = 'react-csv-reader-input', inputName = 'react-csv-reader-input', inputStyle = {}, label, onError = () => { }, onFileLoaded, parserOptions = {}, disabled = false, strict = false, }, inputRef) => {
6+
const handleChangeFile = (e) => {
7+
let reader = new FileReader();
8+
const files = e.target.files;
9+
if (files.length > 0) {
10+
const fileInfo = {
11+
name: files[0].name,
12+
size: files[0].size,
13+
type: files[0].type,
14+
};
15+
if (strict && accept.indexOf(fileInfo.type) <= 0) {
16+
onError(new Error(`[strict mode] Accept type not respected: got '${fileInfo.type}' but not in '${accept}'`));
17+
return;
18+
}
19+
reader.onload = (_event) => {
20+
var _a;
21+
const csvData = PapaParse.parse(reader.result, Object.assign(parserOptions, {
22+
error: onError,
23+
encoding: fileEncoding,
24+
}));
25+
onFileLoaded((_a = csvData === null || csvData === void 0 ? void 0 : csvData.data) !== null && _a !== void 0 ? _a : [], fileInfo, files[0]);
26+
};
27+
reader.readAsText(files[0], fileEncoding);
28+
}
29+
};
30+
return (React.createElement("div", { className: cssClass },
31+
label && (React.createElement("label", { className: cssLabelClass, htmlFor: inputId }, label)),
32+
React.createElement("input", { className: cssInputClass, type: "file", id: inputId, name: inputName, style: inputStyle, accept: accept, onChange: handleChangeFile, disabled: disabled, ref: inputRef })));
33+
});
34+
35+
CSVReader.propTypes = {
36+
accept: PropTypes.string,
37+
cssClass: PropTypes.string,
38+
cssInputClass: PropTypes.string,
39+
cssLabelClass: PropTypes.string,
40+
fileEncoding: PropTypes.string,
41+
inputId: PropTypes.string,
42+
inputName: PropTypes.string,
43+
inputStyle: PropTypes.object,
44+
label: PropTypes.oneOfType([PropTypes.string, PropTypes.element]),
45+
onError: PropTypes.func,
46+
onFileLoaded: PropTypes.func.isRequired,
47+
parserOptions: PropTypes.object,
48+
disabled: PropTypes.bool,
49+
strict: PropTypes.bool,
50+
};
51+
52+
export default CSVReader;

src/index.tsx

Lines changed: 0 additions & 119 deletions
This file was deleted.

webpack.config.js

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ var path = require('path')
22

33
module.exports = {
44
devtool: 'source-map',
5-
entry: './src/index.tsx',
6-
resolve: {
7-
extensions: ['.ts', '.tsx'],
8-
},
5+
entry: './src/index.jsx',
96
output: {
107
filename: 'react-csv-reader.js',
11-
path: path.resolve(__dirname, 'dist'),
12-
library: 'CSVReader',
13-
libraryTarget: 'commonjs2',
8+
library: {
9+
name: 'CSVReader',
10+
type: 'commonjs2',
11+
},
1412
},
1513
module: {
1614
rules: [
@@ -25,15 +23,6 @@ module.exports = {
2523
},
2624
},
2725
},
28-
{
29-
test: /\.ts(x?)$/,
30-
exclude: /node_modules/,
31-
use: [
32-
{
33-
loader: 'ts-loader',
34-
},
35-
],
36-
},
3726
{
3827
enforce: 'pre',
3928
test: /\.js$/,

0 commit comments

Comments
 (0)