Skip to content

Commit 2fb087b

Browse files
Bump supported grafana version to 10.4.8 and release 2.0.0 (#406)
Co-authored-by: Sriram <[email protected]>
1 parent fa9f66e commit 2fb087b

19 files changed

+1179
-396
lines changed

.config/.cprc.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"version": "4.10.3"
2+
"version": "5.12.4"
33
}

.config/.eslintrc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* 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
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-eslint-config
66
*/
77
{
88
"extends": ["@grafana/eslint-config"],
@@ -20,6 +20,12 @@
2020
"parserOptions": {
2121
"project": "./tsconfig.json"
2222
}
23+
},
24+
{
25+
"files": ["./tests/**/*"],
26+
"rules": {
27+
"react-hooks/rules-of-hooks": "off",
28+
},
2329
}
2430
]
2531
}

.config/Dockerfile

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@ ARG grafana_image=grafana-enterprise
33

44
FROM grafana/${grafana_image}:${grafana_version}
55

6-
ARG development=true
6+
ARG anonymous_auth_enabled=true
7+
ARG development=false
8+
ARG TARGETARCH
79

810
ARG GO_VERSION=1.21.6
9-
ARG GO_ARCH=amd64
11+
ARG GO_ARCH=${TARGETARCH:-amd64}
1012

1113
ENV DEV "${development}"
1214

1315
# Make it as simple as possible to access the grafana instance for development purposes
1416
# Do NOT enable these settings in a public facing / production grafana instance
1517
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
16-
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
18+
ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}"
1719
ENV GF_AUTH_BASIC_ENABLED "false"
1820
# Set development mode so plugins can be loaded without the need to sign
1921
ENV GF_DEFAULT_APP_MODE "development"
@@ -29,14 +31,14 @@ USER root
2931
# Installing supervisor and inotify-tools
3032
RUN if [ "${development}" = "true" ]; then \
3133
if grep -i -q alpine /etc/issue; then \
32-
apk add supervisor inotify-tools git; \
34+
apk add supervisor inotify-tools git; \
3335
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/*; \
36+
DEBIAN_FRONTEND=noninteractive && \
37+
apt-get update && \
38+
apt-get install -y supervisor inotify-tools git && \
39+
rm -rf /var/lib/apt/lists/*; \
3840
else \
39-
echo 'ERROR: Unsupported base image' && /bin/false; \
41+
echo 'ERROR: Unsupported base image' && /bin/false; \
4042
fi \
4143
fi
4244

.config/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,6 @@ services:
159159
grafana_image: ${GRAFANA_IMAGE:-grafana}
160160
```
161161
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.
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.
163163

164164
---

.config/jest-setup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* 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
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
66
*/
77

88
import '@testing-library/jest-dom';
@@ -13,7 +13,7 @@ Object.assign(global, { TextDecoder, TextEncoder });
1313
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
1414
Object.defineProperty(global, 'matchMedia', {
1515
writable: true,
16-
value: jest.fn().mockImplementation((query) => ({
16+
value: (query) => ({
1717
matches: false,
1818
media: query,
1919
onchange: null,
@@ -22,7 +22,7 @@ Object.defineProperty(global, 'matchMedia', {
2222
addEventListener: jest.fn(),
2323
removeEventListener: jest.fn(),
2424
dispatchEvent: jest.fn(),
25-
})),
25+
}),
2626
});
2727

2828
HTMLCanvasElement.prototype.getContext = () => {};

.config/jest.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* 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
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-jest-config
66
*/
77

88
const path = require('path');

.config/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* 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-typescript-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-typescript-config
66
*/
77
{
88
"compilerOptions": {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import * as webpack from 'webpack';
2+
3+
const PLUGIN_NAME = 'BuildModeWebpack';
4+
5+
export class BuildModeWebpackPlugin {
6+
apply(compiler: webpack.Compiler) {
7+
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
8+
compilation.hooks.processAssets.tap(
9+
{
10+
name: PLUGIN_NAME,
11+
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
12+
},
13+
async () => {
14+
const assets = compilation.getAssets();
15+
for (const asset of assets) {
16+
if (asset.name.endsWith('plugin.json')) {
17+
const pluginJsonString = asset.source.source().toString();
18+
const pluginJsonWithBuildMode = JSON.stringify(
19+
{
20+
...JSON.parse(pluginJsonString),
21+
buildMode: compilation.options.mode,
22+
},
23+
null,
24+
4
25+
);
26+
compilation.updateAsset(asset.name, new webpack.sources.RawSource(pluginJsonWithBuildMode));
27+
}
28+
}
29+
}
30+
);
31+
});
32+
}
33+
}

.config/webpack/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ export function getPluginJson() {
2929
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
3030
}
3131

32+
export function getCPConfigVersion() {
33+
const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34+
return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
35+
}
36+
3237
export function hasReadme() {
3338
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
3439
}

.config/webpack/webpack.config.ts

Lines changed: 93 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,37 @@
22
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
33
*
44
* 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-webpack-config
5+
* https://grafana.com/developers/plugin-tools/get-started/set-up-development-environment#extend-the-webpack-config
66
*/
77

88
import CopyWebpackPlugin from 'copy-webpack-plugin';
99
import ESLintPlugin from 'eslint-webpack-plugin';
1010
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
11-
import LiveReloadPlugin from 'webpack-livereload-plugin';
1211
import path from 'path';
1312
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
14-
import { Configuration } from 'webpack';
15-
import { GrafanaPluginMetaExtractor } from '@grafana/plugin-meta-extractor';
13+
import TerserPlugin from 'terser-webpack-plugin';
14+
import { SubresourceIntegrityPlugin } from "webpack-subresource-integrity";
15+
import { type Configuration, BannerPlugin } from 'webpack';
16+
import LiveReloadPlugin from 'webpack-livereload-plugin';
17+
import VirtualModulesPlugin from 'webpack-virtual-modules';
1618

17-
import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL } from './utils';
18-
import { SOURCE_DIR, DIST_DIR } from './constants';
19+
import { BuildModeWebpackPlugin } from './BuildModeWebpackPlugin';
20+
import { DIST_DIR, SOURCE_DIR } from './constants';
21+
import { getCPConfigVersion, getEntries, getPackageJson, getPluginJson, hasReadme, isWSL } from './utils';
1922

2023
const pluginJson = getPluginJson();
24+
const cpVersion = getCPConfigVersion();
25+
26+
const virtualPublicPath = new VirtualModulesPlugin({
27+
'node_modules/grafana-public-path.js': `
28+
import amdMetaModule from 'amd-module';
29+
30+
__webpack_public_path__ =
31+
amdMetaModule && amdMetaModule.uri
32+
? amdMetaModule.uri.slice(0, amdMetaModule.uri.lastIndexOf('/') + 1)
33+
: 'public/plugins/${pluginJson.id}/';
34+
`,
35+
});
2136

2237
const config = async (env): Promise<Configuration> => {
2338
const baseConfig: Configuration = {
@@ -35,6 +50,8 @@ const config = async (env): Promise<Configuration> => {
3550
entry: await getEntries(),
3651

3752
externals: [
53+
// Required for dynamic publicPath resolution
54+
{ 'amd-module': 'module' },
3855
'lodash',
3956
'jquery',
4057
'moment',
@@ -72,18 +89,35 @@ const config = async (env): Promise<Configuration> => {
7289
},
7390
],
7491

92+
// Support WebAssembly according to latest spec - makes WebAssembly module async
93+
experiments: {
94+
asyncWebAssembly: true,
95+
},
96+
7597
mode: env.production ? 'production' : 'development',
7698

7799
module: {
78100
rules: [
101+
// This must come first in the rules array otherwise it breaks sourcemaps.
102+
{
103+
test: /src\/(?:.*\/)?module\.tsx?$/,
104+
use: [
105+
{
106+
loader: 'imports-loader',
107+
options: {
108+
imports: `side-effects grafana-public-path`,
109+
},
110+
},
111+
],
112+
},
79113
{
80114
exclude: /(node_modules)/,
81115
test: /\.[tj]sx?$/,
82116
use: {
83117
loader: 'swc-loader',
84118
options: {
85119
jsc: {
86-
baseUrl: path.resolve(__dirname, 'src'),
120+
baseUrl: path.resolve(process.cwd(), SOURCE_DIR),
87121
target: 'es2015',
88122
loose: false,
89123
parser: {
@@ -108,40 +142,59 @@ const config = async (env): Promise<Configuration> => {
108142
test: /\.(png|jpe?g|gif|svg)$/,
109143
type: 'asset/resource',
110144
generator: {
111-
// Keep publicPath relative for host.com/grafana/ deployments
112-
publicPath: `public/plugins/${pluginJson.id}/img/`,
113-
outputPath: 'img/',
114145
filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
115146
},
116147
},
117148
{
118149
test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
119150
type: 'asset/resource',
120151
generator: {
121-
// Keep publicPath relative for host.com/grafana/ deployments
122-
publicPath: `public/plugins/${pluginJson.id}/fonts/`,
123-
outputPath: 'fonts/',
124-
filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
152+
filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
125153
},
126154
},
127155
],
128156
},
129157

158+
optimization: {
159+
minimize: Boolean(env.production),
160+
minimizer: [
161+
new TerserPlugin({
162+
terserOptions: {
163+
format: {
164+
comments: (_, { type, value }) => type === 'comment2' && value.trim().startsWith('[create-plugin]'),
165+
},
166+
compress: {
167+
drop_console: ['log', 'info']
168+
}
169+
},
170+
}),
171+
],
172+
},
173+
130174
output: {
131175
clean: {
132176
keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
133177
},
134178
filename: '[name].js',
179+
chunkFilename: env.production ? '[name].js?_cache=[contenthash]' : '[name].js',
135180
library: {
136181
type: 'amd',
137182
},
138183
path: path.resolve(process.cwd(), DIST_DIR),
139184
publicPath: `public/plugins/${pluginJson.id}/`,
140185
uniqueName: pluginJson.id,
186+
crossOriginLoading: 'anonymous',
141187
},
142188

143189
plugins: [
144-
new GrafanaPluginMetaExtractor(),
190+
new BuildModeWebpackPlugin(),
191+
virtualPublicPath,
192+
// Insert create plugin version information into the bundle
193+
new BannerPlugin({
194+
banner: "/* [create-plugin] version: " + cpVersion + " */",
195+
raw: true,
196+
entryOnly: true,
197+
}),
145198
new CopyWebpackPlugin({
146199
patterns: [
147200
// If src/README.md exists use it; otherwise the root README
@@ -150,14 +203,14 @@ const config = async (env): Promise<Configuration> => {
150203
{ from: 'plugin.json', to: '.' },
151204
{ from: '../LICENSE', to: '.' },
152205
{ from: '../CHANGELOG.md', to: '.', force: true },
153-
{ from: '**/*.json', to: '.' }, // TODO<Add an error for checking the basic structure of the repo>
154-
{ from: '**/*.svg', to: '.', noErrorOnMissing: true }, // Optional
155-
{ from: '**/*.png', to: '.', noErrorOnMissing: true }, // Optional
156-
{ from: '**/*.html', to: '.', noErrorOnMissing: true }, // Optional
157-
{ from: 'img/**/*', to: '.', noErrorOnMissing: true }, // Optional
158-
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true }, // Optional
159-
{ from: 'static/**/*', to: '.', noErrorOnMissing: true }, // Optional
160-
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true }, // Optional
206+
{ from: '**/*.json', to: '.' },
207+
{ from: '**/*.svg', to: '.', noErrorOnMissing: true },
208+
{ from: '**/*.png', to: '.', noErrorOnMissing: true },
209+
{ from: '**/*.html', to: '.', noErrorOnMissing: true },
210+
{ from: 'img/**/*', to: '.', noErrorOnMissing: true },
211+
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true },
212+
{ from: 'static/**/*', to: '.', noErrorOnMissing: true },
213+
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true },
161214
],
162215
}),
163216
// Replace certain template-variables in the README and plugin.json
@@ -181,22 +234,23 @@ const config = async (env): Promise<Configuration> => {
181234
],
182235
},
183236
]),
184-
...(env.development
185-
? [
186-
new LiveReloadPlugin(),
187-
new ForkTsCheckerWebpackPlugin({
188-
async: Boolean(env.development),
189-
issue: {
190-
include: [{ file: '**/*.{ts,tsx}' }],
191-
},
192-
typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') },
193-
}),
194-
new ESLintPlugin({
195-
extensions: ['.ts', '.tsx'],
196-
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
197-
}),
198-
]
199-
: []),
237+
new SubresourceIntegrityPlugin({
238+
hashFuncNames: ["sha256"],
239+
}),
240+
...(env.development ? [
241+
new LiveReloadPlugin(),
242+
new ForkTsCheckerWebpackPlugin({
243+
async: Boolean(env.development),
244+
issue: {
245+
include: [{ file: '**/*.{ts,tsx}' }],
246+
},
247+
typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') },
248+
}),
249+
new ESLintPlugin({
250+
extensions: ['.ts', '.tsx'],
251+
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
252+
}),
253+
] : []),
200254
],
201255

202256
resolve: {

0 commit comments

Comments
 (0)