Skip to content

Commit 0cdd781

Browse files
authored
Update configs (#8)
* Update configs * use .config dir for base configuration
1 parent c63de31 commit 0cdd781

File tree

15 files changed

+1989
-8050
lines changed

15 files changed

+1989
-8050
lines changed

.config/.eslintrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
{
7+
"extends": ["@grafana/eslint-config"],
8+
"root": true,
9+
"rules": {
10+
"react/prop-types": "off"
11+
}
12+
}

.config/.prettierrc.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
module.exports = {
8+
"endOfLine": "auto",
9+
"printWidth": 120,
10+
"trailingComma": "es5",
11+
"semi": true,
12+
"jsxSingleQuote": false,
13+
"singleQuote": true,
14+
"useTabs": false,
15+
"tabWidth": 2
16+
};

.config/README.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Default build configuration by Grafana
2+
3+
**This is an auto-generated directory and is not intended to be changed! ⚠️**
4+
5+
The `.config/` directory holds basic configuration for the different tools
6+
that are used to develop, test and build the project. In order to make it updates easier we ask you to
7+
not edit files in this folder to extend configuration.
8+
9+
## How to extend the basic configs?
10+
11+
Bear in mind that you are doing it at your own risk, and that extending any of the basic configuration can lead
12+
to issues around working with the project.
13+
14+
### Extending the ESLint config
15+
16+
Edit the `.eslintrc` file in the project root in order to extend the ESLint configuration.
17+
18+
**Example:**
19+
20+
```json
21+
{
22+
"extends": "./.config/.eslintrc",
23+
"rules": {
24+
"react/prop-types": "off"
25+
}
26+
}
27+
```
28+
29+
---
30+
31+
### Extending the Prettier config
32+
33+
Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration.
34+
35+
**Example:**
36+
37+
```javascript
38+
module.exports = {
39+
// Prettier configuration provided by Grafana scaffolding
40+
...require('./.config/.prettierrc.js'),
41+
42+
semi: false,
43+
};
44+
```
45+
46+
---
47+
48+
### Extending the Jest config
49+
50+
There are two configuration in the project root that belong to Jest: `jest-setup.js` and `jest.config.js`.
51+
52+
**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to
53+
set up the Jest DOM for the testing library and to apply some polyfills. ([link to Jest docs](https://jestjs.io/docs/configuration#setupfilesafterenv-array))
54+
55+
**`jest.config.js`:** The main Jest configuration file that is extending our basic Grafana-tailored setup. ([link to Jest docs](https://jestjs.io/docs/configuration))
56+
57+
---
58+
59+
### Extending the TypeScript config
60+
61+
Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration.
62+
63+
**Example:**
64+
65+
```json
66+
{
67+
"extends": "./.config/tsconfig.json",
68+
"compilerOptions": {
69+
"preserveConstEnums": true
70+
}
71+
}
72+
```

.config/jest-setup.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
import '@testing-library/jest-dom';
8+
9+
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
10+
Object.defineProperty(global, 'matchMedia', {
11+
writable: true,
12+
value: jest.fn().mockImplementation((query) => ({
13+
matches: false,
14+
media: query,
15+
onchange: null,
16+
addListener: jest.fn(), // deprecated
17+
removeListener: jest.fn(), // deprecated
18+
addEventListener: jest.fn(),
19+
removeEventListener: jest.fn(),
20+
dispatchEvent: jest.fn(),
21+
})),
22+
});
23+
24+
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
7+
const path = require('path');
8+
9+
module.exports = {
10+
moduleNameMapper: {
11+
"\\.(css|scss|sass)$": "identity-obj-proxy",
12+
"react-inlinesvg": path.resolve(__dirname, "mocks", "react-inlinesvg.tsx"),
13+
},
14+
modulePaths: ['<rootDir>/src'],
15+
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
16+
testEnvironment: 'jest-environment-jsdom',
17+
testMatch: [
18+
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}',
19+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
20+
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}',
21+
],
22+
transform: {
23+
'^.+\\.(t|j)sx?$': [
24+
'@swc/jest',
25+
{
26+
sourceMaps: true,
27+
jsc: {
28+
parser: {
29+
syntax: 'typescript',
30+
tsx: true,
31+
decorators: false,
32+
dynamicImport: true,
33+
},
34+
},
35+
},
36+
],
37+
},
38+
transformIgnorePatterns: [],
39+
};

.config/mocks/react-inlinesvg.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Due to the grafana/ui Icon component making fetch requests to
2+
// `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent
3+
// the failed fetch requests from displaying errors in console.
4+
5+
import React from 'react';
6+
7+
type Callback = (...args: any[]) => void;
8+
9+
export interface StorageItem {
10+
content: string;
11+
queue: Callback[];
12+
status: string;
13+
}
14+
15+
export const cacheStore: { [key: string]: StorageItem } = Object.create(null);
16+
17+
const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/;
18+
19+
const InlineSVG = ({ src }: { src: string }) => {
20+
// testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`)
21+
const testId = src.replace(SVG_FILE_NAME_REGEX, '$2');
22+
return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />;
23+
};
24+
25+
export default InlineSVG;

.config/tsconfig.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3+
*
4+
* In order to extend the configuration follow the steps in .config/README.md
5+
*/
6+
{
7+
"compilerOptions": {
8+
"alwaysStrict": true,
9+
"declaration": false,
10+
"rootDir": "../src",
11+
"baseUrl": "../src",
12+
"typeRoots": ["../node_modules/@types"],
13+
"resolveJsonModule": true
14+
},
15+
"ts-node": {
16+
"compilerOptions": {
17+
"module": "commonjs",
18+
"target": "es5",
19+
"esModuleInterop": true
20+
},
21+
"transpileOnly": true
22+
},
23+
"include": ["../src", "./types"],
24+
"extends": "@grafana/tsconfig"
25+
}

.config/types/custom.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Image declarations
2+
declare module '*.gif' {
3+
const src: string;
4+
export default src;
5+
}
6+
7+
declare module '*.jpg' {
8+
const src: string;
9+
export default src;
10+
}
11+
12+
declare module '*.jpeg' {
13+
const src: string;
14+
export default src;
15+
}
16+
17+
declare module '*.png' {
18+
const src: string;
19+
export default src;
20+
}
21+
22+
declare module '*.webp' {
23+
const src: string;
24+
export default src;
25+
}
26+
27+
declare module '*.svg' {
28+
const content: string;
29+
export default content;
30+
}
31+
32+
// Font declarations
33+
declare module '*.woff';
34+
declare module '*.woff2';
35+
declare module '*.eot';
36+
declare module '*.ttf';
37+
declare module '*.otf';

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"extends": ["@grafana/eslint-config"]
2+
"extends": "./.config/.eslintrc"
33
}

.prettierrc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
module.exports = {
2-
...require('@grafana/toolkit/src/config/prettier.plugin.config.json'),
2+
// Prettier configuration provided by Grafana scaffolding
3+
...require('./.config/.prettierrc.js'),
34
};

0 commit comments

Comments
 (0)