Skip to content

Commit e18ab54

Browse files
authored
Chore: update dependencies (#290)
1 parent 8e058d9 commit e18ab54

28 files changed

+5672
-6186
lines changed

.config/.cprc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version": "4.13.0"
3+
}

.config/.eslintrc

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,25 @@
11
/*
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
4-
* In order to extend the configuration follow the steps in .config/README.md
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config
56
*/
6-
{
7+
{
78
"extends": ["@grafana/eslint-config"],
89
"root": true,
910
"rules": {
1011
"react/prop-types": "off"
11-
}
12+
},
13+
"overrides": [
14+
{
15+
"plugins": ["deprecation"],
16+
"files": ["src/**/*.{ts,tsx}"],
17+
"rules": {
18+
"deprecation/deprecation": "warn"
19+
},
20+
"parserOptions": {
21+
"project": "./tsconfig.json"
22+
}
23+
}
24+
]
1225
}

.config/.prettierrc.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
*/
66

77
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-
};
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/Dockerfile

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
ARG grafana_version=latest
2+
ARG grafana_image=grafana-enterprise
23

3-
FROM grafana/grafana:${grafana_version}
4+
FROM grafana/${grafana_image}:${grafana_version}
5+
6+
ARG development=false
7+
8+
ARG GO_VERSION=1.21.6
9+
ARG GO_ARCH=amd64
10+
11+
ENV DEV "${development}"
412

513
# Make it as simple as possible to access the grafana instance for development purposes
614
# Do NOT enable these settings in a public facing / production grafana instance
@@ -10,6 +18,58 @@ ENV GF_AUTH_BASIC_ENABLED "false"
1018
# Set development mode so plugins can be loaded without the need to sign
1119
ENV GF_DEFAULT_APP_MODE "development"
1220

13-
# Inject livereload script into grafana index.html
21+
22+
LABEL maintainer="Grafana Labs <[email protected]>"
23+
24+
ENV GF_PATHS_HOME="/usr/share/grafana"
25+
WORKDIR $GF_PATHS_HOME
26+
1427
USER root
15-
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html
28+
29+
# Installing supervisor and inotify-tools
30+
RUN if [ "${development}" = "true" ]; then \
31+
if grep -i -q alpine /etc/issue; then \
32+
apk add supervisor inotify-tools git; \
33+
elif grep -i -q ubuntu /etc/issue; then \
34+
DEBIAN_FRONTEND=noninteractive && \
35+
apt-get update && \
36+
apt-get install -y supervisor inotify-tools git && \
37+
rm -rf /var/lib/apt/lists/*; \
38+
else \
39+
echo 'ERROR: Unsupported base image' && /bin/false; \
40+
fi \
41+
fi
42+
43+
COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
44+
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
45+
46+
47+
# Installing Go
48+
RUN if [ "${development}" = "true" ]; then \
49+
curl -O -L https://golang.org/dl/go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
50+
rm -rf /usr/local/go && \
51+
tar -C /usr/local -xzf go${GO_VERSION}.linux-${GO_ARCH}.tar.gz && \
52+
echo "export PATH=$PATH:/usr/local/go/bin:~/go/bin" >> ~/.bashrc && \
53+
rm -f go${GO_VERSION}.linux-${GO_ARCH}.tar.gz; \
54+
fi
55+
56+
# Installing delve for debugging
57+
RUN if [ "${development}" = "true" ]; then \
58+
/usr/local/go/bin/go install github.com/go-delve/delve/cmd/dlv@latest; \
59+
fi
60+
61+
# Installing mage for plugin (re)building
62+
RUN if [ "${development}" = "true" ]; then \
63+
git clone https://github.com/magefile/mage; \
64+
cd mage; \
65+
export PATH=$PATH:/usr/local/go/bin; \
66+
go run bootstrap.go; \
67+
fi
68+
69+
# Inject livereload script into grafana index.html
70+
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html
71+
72+
73+
COPY entrypoint.sh /entrypoint.sh
74+
RUN chmod +x /entrypoint.sh
75+
ENTRYPOINT ["/entrypoint.sh"]

.config/README.md

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ to issues around working with the project.
1616
Edit the `.eslintrc` file in the project root in order to extend the ESLint configuration.
1717

1818
**Example:**
19+
1920
```json
2021
{
2122
"extends": "./.config/.eslintrc",
2223
"rules": {
23-
"react/prop-types": "off"
24+
"react/prop-types": "off"
2425
}
2526
}
2627
```
@@ -32,10 +33,11 @@ Edit the `.eslintrc` file in the project root in order to extend the ESLint conf
3233
Edit the `.prettierrc.js` file in the project root in order to extend the Prettier configuration.
3334

3435
**Example:**
36+
3537
```javascript
3638
module.exports = {
3739
// Prettier configuration provided by Grafana scaffolding
38-
...require("./.config/.prettierrc.js"),
40+
...require('./.config/.prettierrc.js'),
3941

4042
semi: false,
4143
};
@@ -50,7 +52,23 @@ There are two configuration in the project root that belong to Jest: `jest-setup
5052
**`jest-setup.js`:** A file that is run before each test file in the suite is executed. We are using it to
5153
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))
5254

53-
**`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))
55+
**`jest.config.js`:** The main Jest configuration file that extends the Grafana recommended setup. ([link to Jest docs](https://jestjs.io/docs/configuration))
56+
57+
#### ESM errors with Jest
58+
59+
A common issue with the current jest config involves importing an npm package that only offers an ESM build. These packages cause jest to error with `SyntaxError: Cannot use import statement outside a module`. To work around this, we provide a list of known packages to pass to the `[transformIgnorePatterns](https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)` jest configuration property. If need be, this can be extended in the following way:
60+
61+
```javascript
62+
process.env.TZ = 'UTC';
63+
const { grafanaESModules, nodeModulesToTransform } = require('./config/jest/utils');
64+
65+
module.exports = {
66+
// Jest configuration provided by Grafana
67+
...require('./.config/jest.config'),
68+
// Inform jest to only transform specific node_module packages.
69+
transformIgnorePatterns: [nodeModulesToTransform([...grafanaESModules, 'packageName'])],
70+
};
71+
```
5472

5573
---
5674

@@ -59,6 +77,7 @@ set up the Jest DOM for the testing library and to apply some polyfills. ([link
5977
Edit the `tsconfig.json` file in the project root in order to extend the TypeScript configuration.
6078

6179
**Example:**
80+
6281
```json
6382
{
6483
"extends": "./.config/tsconfig.json",
@@ -80,6 +99,7 @@ Create a new config file that is going to extend the basic one provided by Grafa
8099
It can live in the project root, e.g. `webpack.config.ts`.
81100

82101
#### 2. Merge the basic config provided by Grafana and your custom setup
102+
83103
We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge) for this.
84104

85105
```typescript
@@ -100,21 +120,45 @@ const config = async (env): Promise<Configuration> => {
100120
};
101121

102122
export default config;
103-
104123
```
105124

106125
#### 3. Update the `package.json` to use the new Webpack config
107126

108127
We need to update the `scripts` in the `package.json` to use the extended Webpack configuration.
109128

110129
**Update for `build`:**
130+
111131
```diff
112132
-"build": "webpack -c ./.config/webpack/webpack.config.ts --env production",
113133
+"build": "webpack -c ./webpack.config.ts --env production",
114134
```
115135

116136
**Update for `dev`:**
137+
117138
```diff
118139
-"dev": "webpack -w -c ./.config/webpack/webpack.config.ts --env development",
119140
+"dev": "webpack -w -c ./webpack.config.ts --env development",
120141
```
142+
143+
### Configure grafana image to use when running docker
144+
145+
By default, `grafana-enterprise` will be used as the docker image for all docker related commands. If you want to override this behavior, simply alter the `docker-compose.yaml` by adding the following build arg `grafana_image`.
146+
147+
**Example:**
148+
149+
```yaml
150+
version: '3.7'
151+
152+
services:
153+
grafana:
154+
container_name: 'myorg-basic-app'
155+
build:
156+
context: ./.config
157+
args:
158+
grafana_version: ${GRAFANA_VERSION:-9.1.2}
159+
grafana_image: ${GRAFANA_IMAGE:-grafana}
160+
```
161+
162+
In this example, we assign the environment variable `GRAFANA_IMAGE` to the build arg `grafana_image` with a default value of `grafana`. This will allow you to set the value while running the docker-compose commands, which might be convenient in some scenarios.
163+
164+
---

.config/entrypoint.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/bin/sh
2+
3+
if [ "${DEV}" = "false" ]; then
4+
echo "Starting test mode"
5+
exec /run.sh
6+
fi
7+
8+
echo "Starting development mode"
9+
10+
if grep -i -q alpine /etc/issue; then
11+
exec /usr/bin/supervisord -c /etc/supervisord.conf
12+
elif grep -i -q ubuntu /etc/issue; then
13+
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
14+
else
15+
echo 'ERROR: Unsupported base image'
16+
exit 1
17+
fi
18+

.config/jest-setup.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
/*
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
4-
* In order to extend the configuration follow the steps in .config/README.md
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
56
*/
67

78
import '@testing-library/jest-dom';
9+
import { TextEncoder, TextDecoder } from 'util';
10+
11+
Object.assign(global, { TextDecoder, TextEncoder });
812

913
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
1014
Object.defineProperty(global, 'matchMedia', {

.config/jest.config.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
/*
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
4-
* In order to extend the configuration follow the steps in .config/README.md
4+
* In order to extend the configuration follow the steps in
5+
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
56
*/
67

78
const path = require('path');
9+
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils');
810

911
module.exports = {
1012
moduleNameMapper: {
11-
"\\.(css|scss|sass)$": "identity-obj-proxy",
12-
"react-inlinesvg": path.resolve(__dirname, "mocks", "react-inlinesvg.tsx"),
13+
'\\.(css|scss|sass)$': 'identity-obj-proxy',
14+
'react-inlinesvg': path.resolve(__dirname, 'jest', 'mocks', 'react-inlinesvg.tsx'),
1315
},
1416
modulePaths: ['<rootDir>/src'],
1517
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'],
@@ -23,7 +25,7 @@ module.exports = {
2325
'^.+\\.(t|j)sx?$': [
2426
'@swc/jest',
2527
{
26-
sourceMaps: true,
28+
sourceMaps: 'inline',
2729
jsc: {
2830
parser: {
2931
syntax: 'typescript',
@@ -35,5 +37,7 @@ module.exports = {
3537
},
3638
],
3739
},
38-
transformIgnorePatterns: [],
40+
// Jest will throw `Cannot use import statement outside module` if it tries to load an
41+
// ES module without it being transformed first. ./config/README.md#esm-errors-with-jest
42+
transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)],
3943
};
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/jest/utils.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
/*
8+
* This utility function is useful in combination with jest `transformIgnorePatterns` config
9+
* to transform specific packages (e.g.ES modules) in a projects node_modules folder.
10+
*/
11+
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNames.join('|')})\/.*)`;
12+
13+
// Array of known nested grafana package dependencies that only bundle an ESM version
14+
const grafanaESModules = [
15+
'.pnpm', // Support using pnpm symlinked packages
16+
'@grafana/schema',
17+
'd3',
18+
'd3-color',
19+
'd3-force',
20+
'd3-interpolate',
21+
'd3-scale-chromatic',
22+
'ol',
23+
'react-colorful',
24+
'rxjs',
25+
'uuid',
26+
];
27+
28+
module.exports = {
29+
nodeModulesToTransform,
30+
grafanaESModules,
31+
};

0 commit comments

Comments
 (0)