Skip to content

Commit b57765f

Browse files
authored
Merge pull request #75 from plesk/task-dmodin-update-dependencies-EXTPLESK-9730
Update dependencies
2 parents cbaa9a5 + 8d81128 commit b57765f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+5605
-6305
lines changed

.eslintrc

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

docs/01-getting-started.md

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Create `package.json` file in the root of your project or use yarn init command:
9999

100100
Since UI Library is based on React and browsers don't support jsx and ES6 syntax natively, first we need to transpile our code to native JS. We will use [Babel](http://babeljs.io/) for it. We will also use ES6 imports for importing functions and components from UI Library. We'll have to use [Webpack](https://webpack.js.org/) for handling ES6 imports because browsers don't support them natively. All these tools and some configs for integrating them are available in the package `@plesk/plesk-ext-sdk`. We will also need an HTTP client for retrieving data from the server, so let's install, for example, [axios](https://github.com/axios/axios) as a dependency.
101101
```bash
102-
yarn add @plesk/plesk-ext-sdk@0.5.5 axios
102+
yarn add @plesk/plesk-ext-sdk axios
103103
```
104104
Once Yarn has added these packages to `package.json`, install it and generate `yarn.lock`. The lock file should be added to Git – you can read more about this in the Yarn [documentation](https://yarnpkg.com/lang/en/docs/yarn-lock/).
105105

@@ -139,37 +139,31 @@ Now we can write our first React component.
139139
`src/frontend/index.js`
140140

141141
```js
142-
import { createElement, Component, Alert, PropTypes } from '@plesk/plesk-ext-sdk';
142+
import { createElement, useState, useEffect } from 'react';
143+
import PropTypes from 'prop-types';
144+
import { Alert } from '@plesk/plesk-ext-sdk';
143145
import axios from 'axios';
144146

145-
export default class extends Component {
146-
static propTypes = {
147-
baseUrl: PropTypes.string.isRequired,
148-
};
147+
export default function MainPage({baseUrl}) {
148+
const [date, setDate] = useState(null);
149149

150-
state = {
151-
date: null,
152-
};
153-
154-
componentDidMount() {
155-
const { baseUrl } = this.props;
156-
axios.get(`${baseUrl}/api/date`).then(({ data }) => this.setState({ date: data }));
157-
}
158-
159-
render() {
160-
const { date } = this.state;
161-
162-
if (!date) {
163-
return null;
164-
}
165-
166-
return (
167-
<Alert intent="info">
168-
{`Server time: ${date}`}
169-
</Alert>
170-
)
150+
useEffect(() => {
151+
axios.get(`${baseUrl}/api/date`).then(({ data }) => setDate(data));
152+
}, []);
153+
154+
if (!date) {
155+
return null;
171156
}
157+
return (
158+
<Alert intent="info">
159+
{`Server time: ${date}`}
160+
</Alert>
161+
);
172162
}
163+
164+
MainPage.propTypes = {
165+
baseUrl: PropTypes.string.isRequired,
166+
};
173167
```
174168

175169
Let's build the app to create the production code with `yarn build` command.

docs/03-code-quality-tools.md

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,27 @@ How to enable ESLint:
1111
```json
1212
{
1313
"scripts": {
14-
"lint": "eslint frontend"
15-
}
16-
}
17-
```
18-
2. Add `.eslintrc` file
19-
`.eslintrc`
20-
```
21-
{
22-
"extends": "@plesk/eslint-config",
23-
"settings": {
24-
"react": {
25-
"pragma": "createElement"
26-
}
14+
"lint": "eslint src/rontend"
2715
}
2816
}
2917
```
3018

19+
2. Add `eslint.config.mjs` file
20+
```js
21+
const pleskConfig = require('@plesk/eslint-config');
22+
23+
module.exports = [
24+
pleskConfig,
25+
];
26+
```
27+
28+
3. Due to dependency bug in enzyme, add version override in your `package.json`
29+
```
30+
"resolutions": {
31+
"cheerio": "1.0.0-rc.12"
32+
}
33+
```
34+
3135
Now you can check your code with the following command:
3236

3337
```
@@ -38,9 +42,8 @@ Alternatively, you can run `yarn lint --fix` command to automatically fix all er
3842

3943
You can also enable ESLint in your PhpStorm: Settings > Languages & Frameworks > JavaScript > Code Quality Tools > ESLint > Enable
4044

41-
## StyleLint
45+
To know more about ESLint and it's configuration please check [ESLint documentation](https://eslint.org/docs/latest/use/getting-started)
4246

43-
This section is under construction.
4447

4548
## Unit Testing
4649

@@ -49,7 +52,7 @@ All your code should be covered by unit tests. We recommend using [Jest](https:/
4952
### Installing Dependencies
5053

5154
```bash
52-
yarn add enzyme enzyme-adapter-react-16 --dev
55+
yarn add @cfaester/enzyme-adapter-react-18 --dev
5356
```
5457

5558
### Adding Helper Scripts
@@ -71,10 +74,12 @@ yarn add enzyme enzyme-adapter-react-16 --dev
7174

7275
```js
7376
import Enzyme from 'enzyme';
74-
import Adapter from 'enzyme-adapter-react-16';
77+
import Adapter from '@cfaester/enzyme-adapter-react-18';
78+
import { TextEncoder } from 'util';
79+
global.TextEncoder = TextEncoder;
80+
7581

7682
Enzyme.configure({ adapter: new Adapter() });
77-
Enzyme.configure({ disableLifecycleMethods: true });
7883
```
7984

8085
### Writing Tests
@@ -107,17 +112,6 @@ describe('Overview', () => {
107112
});
108113
```
109114

110-
Add to `.eslintrc` section `env`:
111-
112-
113-
```
114-
{
115-
"env": {
116-
"jest": true
117-
}
118-
}
119-
```
120-
121115
### Running Tests
122116

123117
Now you can check your code via `yarn test` command.

eslint.config.cjs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
2+
3+
const pleskConfig = require('@plesk/eslint-config');
4+
5+
module.exports = [
6+
pleskConfig,
7+
{
8+
settings: {
9+
react: {
10+
pragma: "createElement",
11+
},
12+
},
13+
rules: {
14+
'jest/no-test-return-statement': 'off',
15+
'react/require-default-props': 'off',
16+
}
17+
},
18+
];

lib/babel/createConfig.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

33
module.exports = () => ({
44
babelrc: false,

lib/commands/build.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

33
const createConfig = require('../webpack/createConfig');
44
const build = require('../webpack/build');

lib/commands/dev.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

33
const createConfig = require('../webpack/createConfig');
44
const build = require('../webpack/build');

lib/commands/test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

3-
// eslint-disable-next-line jest/no-jest-import
43
const jest = require('jest');
54
const createConfig = require('../jest/createConfig');
65

lib/jest/babelTransform.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

33
const babelJest = require('babel-jest');
44
const createConfig = require('../babel/createConfig');

lib/jest/createConfig.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 1999-2018. Plesk International GmbH. All rights reserved.
1+
// Copyright 1999-2025. WebPros International GmbH. All rights reserved.
22

33
const path = require('path');
44
const fs = require('fs-extra');
@@ -10,7 +10,8 @@ module.exports = () => {
1010
: undefined;
1111

1212
return {
13-
setupTestFrameworkScriptFile: setupTestsFile,
13+
testEnvironment: 'jsdom',
14+
setupFilesAfterEnv: [setupTestsFile].filter(Boolean),
1415
testMatch: [
1516
'**/*.test.js?(x)',
1617
],
@@ -23,5 +24,9 @@ module.exports = () => {
2324
snapshotSerializers: [
2425
'enzyme-to-json/serializer',
2526
],
27+
moduleNameMapper: {
28+
'\\.(css|less|scss)$': path.resolve(__dirname, './styleMock.js'),
29+
'\\.(png|jpg|gif|svg|woff|woff2|webp)$': path.resolve(__dirname, './fileMock.js'),
30+
},
2631
};
2732
};

0 commit comments

Comments
 (0)