chore: bump @grafana/create-plugin configuration to 5.26.4 (#2082)
Bumps [`@grafana/create-plugin`](https://github.com/grafana/plugin-tools/tree/main/packages/create-plugin) configuration from 4.2.1 to 5.26.4. **Notes for reviewer:** This is an auto-generated PR which ran `@grafana/create-plugin update`. Please consult the create-plugin [CHANGELOG.md](https://github.com/grafana/plugin-tools/blob/main/packages/create-plugin/CHANGELOG.md) to understand what may have changed. Please review the changes thoroughly before merging. --------- Co-authored-by: grafana-plugins-platform-bot[bot] <144369747+grafana-plugins-platform-bot[bot]@users.noreply.github.com> Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
This commit is contained in:
committed by
GitHub
parent
e76741b453
commit
b13d567eee
@@ -1,3 +1,3 @@
|
||||
{
|
||||
"version": "4.2.1"
|
||||
"version": "5.26.4"
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
|
||||
*
|
||||
* In order to extend the configuration follow the steps in
|
||||
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-eslint-config
|
||||
* https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-eslint-config
|
||||
*/
|
||||
{
|
||||
"extends": ["@grafana/eslint-config"],
|
||||
@@ -12,14 +12,19 @@
|
||||
},
|
||||
"overrides": [
|
||||
{
|
||||
"plugins": ["deprecation"],
|
||||
"files": ["src/**/*.{ts,tsx}"],
|
||||
"rules": {
|
||||
"deprecation/deprecation": "warn"
|
||||
"@typescript-eslint/no-deprecated": "warn"
|
||||
},
|
||||
"parserOptions": {
|
||||
"project": "./tsconfig.json"
|
||||
}
|
||||
},
|
||||
{
|
||||
"files": ["./tests/**/*"],
|
||||
"rules": {
|
||||
"react-hooks/rules-of-hooks": "off"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,14 +3,52 @@ ARG grafana_image=grafana-enterprise
|
||||
|
||||
FROM grafana/${grafana_image}:${grafana_version}
|
||||
|
||||
ARG anonymous_auth_enabled=true
|
||||
ARG development=false
|
||||
ARG TARGETARCH
|
||||
|
||||
|
||||
ENV DEV "${development}"
|
||||
|
||||
# Make it as simple as possible to access the grafana instance for development purposes
|
||||
# Do NOT enable these settings in a public facing / production grafana instance
|
||||
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
|
||||
ENV GF_AUTH_ANONYMOUS_ENABLED "true"
|
||||
ENV GF_AUTH_ANONYMOUS_ENABLED "${anonymous_auth_enabled}"
|
||||
ENV GF_AUTH_BASIC_ENABLED "false"
|
||||
# Set development mode so plugins can be loaded without the need to sign
|
||||
ENV GF_DEFAULT_APP_MODE "development"
|
||||
|
||||
# Inject livereload script into grafana index.html
|
||||
|
||||
LABEL maintainer="Grafana Labs <hello@grafana.com>"
|
||||
|
||||
ENV GF_PATHS_HOME="/usr/share/grafana"
|
||||
WORKDIR $GF_PATHS_HOME
|
||||
|
||||
USER root
|
||||
|
||||
# Installing supervisor and inotify-tools
|
||||
RUN if [ "${development}" = "true" ]; then \
|
||||
if grep -i -q alpine /etc/issue; then \
|
||||
apk add supervisor inotify-tools git; \
|
||||
elif grep -i -q ubuntu /etc/issue; then \
|
||||
DEBIAN_FRONTEND=noninteractive && \
|
||||
apt-get update && \
|
||||
apt-get install -y supervisor inotify-tools git && \
|
||||
rm -rf /var/lib/apt/lists/*; \
|
||||
else \
|
||||
echo 'ERROR: Unsupported base image' && /bin/false; \
|
||||
fi \
|
||||
fi
|
||||
|
||||
COPY supervisord/supervisord.conf /etc/supervisor.d/supervisord.ini
|
||||
COPY supervisord/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
||||
|
||||
|
||||
|
||||
# Inject livereload script into grafana index.html
|
||||
RUN sed -i 's|</body>|<script src="http://localhost:35729/livereload.js"></script></body>|g' /usr/share/grafana/public/views/index.html
|
||||
|
||||
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
||||
|
||||
@@ -106,9 +106,9 @@ We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge
|
||||
// webpack.config.ts
|
||||
import type { Configuration } from 'webpack';
|
||||
import { merge } from 'webpack-merge';
|
||||
import grafanaConfig from './.config/webpack/webpack.config';
|
||||
import grafanaConfig, { type Env } from './.config/webpack/webpack.config';
|
||||
|
||||
const config = async (env): Promise<Configuration> => {
|
||||
const config = async (env: Env): Promise<Configuration> => {
|
||||
const baseConfig = await grafanaConfig(env);
|
||||
|
||||
return merge(baseConfig, {
|
||||
@@ -151,14 +151,15 @@ version: '3.7'
|
||||
|
||||
services:
|
||||
grafana:
|
||||
container_name: 'myorg-basic-app'
|
||||
extends:
|
||||
file: .config/docker-compose-base.yaml
|
||||
service: grafana
|
||||
build:
|
||||
context: ./.config
|
||||
args:
|
||||
grafana_version: ${GRAFANA_VERSION:-9.1.2}
|
||||
grafana_image: ${GRAFANA_IMAGE:-grafana}
|
||||
```
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
25
.config/docker-compose-base.yaml
Normal file
25
.config/docker-compose-base.yaml
Normal file
@@ -0,0 +1,25 @@
|
||||
services:
|
||||
grafana:
|
||||
user: root
|
||||
container_name: 'alexanderzobnin-zabbix-app'
|
||||
|
||||
build:
|
||||
context: .
|
||||
args:
|
||||
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
|
||||
grafana_version: ${GRAFANA_VERSION:-12.1.1}
|
||||
development: ${DEVELOPMENT:-false}
|
||||
anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
|
||||
ports:
|
||||
- 3000:3000/tcp
|
||||
volumes:
|
||||
- ../dist:/var/lib/grafana/plugins/alexanderzobnin-zabbix-app
|
||||
- ../provisioning:/etc/grafana/provisioning
|
||||
- ..:/root/alexanderzobnin-zabbix-app
|
||||
|
||||
environment:
|
||||
NODE_ENV: development
|
||||
GF_LOG_FILTERS: plugin.alexanderzobnin-zabbix-app:debug
|
||||
GF_LOG_LEVEL: debug
|
||||
GF_DATAPROXY_LOGGING: 1
|
||||
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: alexanderzobnin-zabbix-app
|
||||
18
.config/entrypoint.sh
Normal file
18
.config/entrypoint.sh
Normal file
@@ -0,0 +1,18 @@
|
||||
#!/bin/sh
|
||||
|
||||
if [ "${DEV}" = "false" ]; then
|
||||
echo "Starting test mode"
|
||||
exec /run.sh
|
||||
fi
|
||||
|
||||
echo "Starting development mode"
|
||||
|
||||
if grep -i -q alpine /etc/issue; then
|
||||
exec /usr/bin/supervisord -c /etc/supervisord.conf
|
||||
elif grep -i -q ubuntu /etc/issue; then
|
||||
exec /usr/bin/supervisord -c /etc/supervisor/supervisord.conf
|
||||
else
|
||||
echo 'ERROR: Unsupported base image'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -2,15 +2,18 @@
|
||||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
|
||||
*
|
||||
* In order to extend the configuration follow the steps in
|
||||
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
|
||||
* https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-jest-config
|
||||
*/
|
||||
|
||||
import '@testing-library/jest-dom';
|
||||
import { TextEncoder, TextDecoder } from 'util';
|
||||
|
||||
Object.assign(global, { TextDecoder, TextEncoder });
|
||||
|
||||
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom
|
||||
Object.defineProperty(global, 'matchMedia', {
|
||||
writable: true,
|
||||
value: jest.fn().mockImplementation((query) => ({
|
||||
value: (query) => ({
|
||||
matches: false,
|
||||
media: query,
|
||||
onchange: null,
|
||||
@@ -19,7 +22,7 @@ Object.defineProperty(global, 'matchMedia', {
|
||||
addEventListener: jest.fn(),
|
||||
removeEventListener: jest.fn(),
|
||||
dispatchEvent: jest.fn(),
|
||||
})),
|
||||
}),
|
||||
});
|
||||
|
||||
HTMLCanvasElement.prototype.getContext = () => {};
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
|
||||
*
|
||||
* In order to extend the configuration follow the steps in
|
||||
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-jest-config
|
||||
* https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-jest-config
|
||||
*/
|
||||
|
||||
const path = require('path');
|
||||
@@ -40,4 +40,5 @@ module.exports = {
|
||||
// Jest will throw `Cannot use import statement outside module` if it tries to load an
|
||||
// ES module without it being transformed first. ./config/README.md#esm-errors-with-jest
|
||||
transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)],
|
||||
watchPathIgnorePatterns: ['<rootDir>/node_modules', '<rootDir>/dist'],
|
||||
};
|
||||
|
||||
@@ -14,12 +14,18 @@ const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!.*(${moduleNam
|
||||
const grafanaESModules = [
|
||||
'.pnpm', // Support using pnpm symlinked packages
|
||||
'@grafana/schema',
|
||||
'@wojtekmaj/date-utils',
|
||||
'd3',
|
||||
'd3-color',
|
||||
'd3-force',
|
||||
'd3-interpolate',
|
||||
'd3-scale-chromatic',
|
||||
'get-user-locale',
|
||||
'marked',
|
||||
'memoize',
|
||||
'mimic-function',
|
||||
'ol',
|
||||
'react-calendar',
|
||||
'react-colorful',
|
||||
'rxjs',
|
||||
'uuid',
|
||||
|
||||
15
.config/supervisord/supervisord.conf
Normal file
15
.config/supervisord/supervisord.conf
Normal file
@@ -0,0 +1,15 @@
|
||||
[supervisord]
|
||||
nodaemon=true
|
||||
user=root
|
||||
|
||||
[program:grafana]
|
||||
user=root
|
||||
directory=/var/lib/grafana
|
||||
command=/run.sh
|
||||
stdout_logfile=/dev/fd/1
|
||||
stdout_logfile_maxbytes=0
|
||||
redirect_stderr=true
|
||||
killasgroup=true
|
||||
stopasgroup=true
|
||||
autostart=true
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
|
||||
*
|
||||
* In order to extend the configuration follow the steps in
|
||||
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-typescript-config
|
||||
* https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-typescript-config
|
||||
*/
|
||||
{
|
||||
"compilerOptions": {
|
||||
|
||||
37
.config/types/bundler-rules.d.ts
vendored
Normal file
37
.config/types/bundler-rules.d.ts
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
// Image declarations
|
||||
declare module '*.gif' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.jpg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.jpeg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.png' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.webp' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
declare module '*.svg' {
|
||||
const src: string;
|
||||
export default src;
|
||||
}
|
||||
|
||||
// Font declarations
|
||||
declare module '*.woff';
|
||||
declare module '*.woff2';
|
||||
declare module '*.eot';
|
||||
declare module '*.ttf';
|
||||
declare module '*.otf';
|
||||
83
.config/types/webpack-plugins.d.ts
vendored
Normal file
83
.config/types/webpack-plugins.d.ts
vendored
Normal file
@@ -0,0 +1,83 @@
|
||||
declare module 'replace-in-file-webpack-plugin' {
|
||||
import { Compiler, Plugin } from 'webpack';
|
||||
|
||||
interface ReplaceRule {
|
||||
search: string | RegExp;
|
||||
replace: string | ((match: string) => string);
|
||||
}
|
||||
|
||||
interface ReplaceOption {
|
||||
dir?: string;
|
||||
files?: string[];
|
||||
test?: RegExp | RegExp[];
|
||||
rules: ReplaceRule[];
|
||||
}
|
||||
|
||||
class ReplaceInFilePlugin extends Plugin {
|
||||
constructor(options?: ReplaceOption[]);
|
||||
options: ReplaceOption[];
|
||||
apply(compiler: Compiler): void;
|
||||
}
|
||||
|
||||
export = ReplaceInFilePlugin;
|
||||
}
|
||||
|
||||
declare module 'webpack-livereload-plugin' {
|
||||
import { ServerOptions } from 'https';
|
||||
import { Compiler, Plugin, Stats, Compilation } from 'webpack';
|
||||
|
||||
interface Options extends Pick<ServerOptions, 'cert' | 'key' | 'pfx'> {
|
||||
/**
|
||||
* protocol for livereload `<script>` src attribute value
|
||||
* @default protocol of the page, either `http` or `https`
|
||||
*/
|
||||
protocol?: string | undefined;
|
||||
/**
|
||||
* The desired port for the livereload server.
|
||||
* If you define port 0, an available port will be searched for, starting from 35729.
|
||||
* @default 35729
|
||||
*/
|
||||
port?: number | undefined;
|
||||
/**
|
||||
* he desired hostname for the appended `<script>` (if present) to point to
|
||||
* @default hostname of the page, like `localhost` or 10.0.2.2
|
||||
*/
|
||||
hostname?: string | undefined;
|
||||
/**
|
||||
* livereload `<script>` automatically to `<head>`.
|
||||
* @default false
|
||||
*/
|
||||
appendScriptTag?: boolean | undefined;
|
||||
/**
|
||||
* RegExp of files to ignore. Null value means ignore nothing.
|
||||
* It is also possible to define an array and use multiple anymatch patterns
|
||||
*/
|
||||
ignore?: RegExp | RegExp[] | null | undefined;
|
||||
/**
|
||||
* amount of milliseconds by which to delay the live reload (in case build takes longer)
|
||||
* @default 0
|
||||
*/
|
||||
delay?: number | undefined;
|
||||
/**
|
||||
* create hash for each file source and only notify livereload if hash has changed
|
||||
* @default false
|
||||
*/
|
||||
useSourceHash?: boolean | undefined;
|
||||
}
|
||||
|
||||
class LiveReloadPlugin extends Plugin {
|
||||
readonly isRunning: boolean;
|
||||
constructor(options?: Options);
|
||||
|
||||
apply(compiler: Compiler): void;
|
||||
|
||||
start(watching: any, cb: () => void): void;
|
||||
done(stats: Stats): void;
|
||||
failed(): void;
|
||||
autoloadJs(): string;
|
||||
scriptTag(source: string): string;
|
||||
applyCompilation(compilation: Compilation): void;
|
||||
}
|
||||
|
||||
export = LiveReloadPlugin;
|
||||
}
|
||||
33
.config/webpack/BuildModeWebpackPlugin.ts
Normal file
33
.config/webpack/BuildModeWebpackPlugin.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import webpack, { type Compiler } from 'webpack';
|
||||
|
||||
const PLUGIN_NAME = 'BuildModeWebpack';
|
||||
|
||||
export class BuildModeWebpackPlugin {
|
||||
apply(compiler: webpack.Compiler) {
|
||||
compiler.hooks.compilation.tap(PLUGIN_NAME, (compilation) => {
|
||||
compilation.hooks.processAssets.tap(
|
||||
{
|
||||
name: PLUGIN_NAME,
|
||||
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS,
|
||||
},
|
||||
async () => {
|
||||
const assets = compilation.getAssets();
|
||||
for (const asset of assets) {
|
||||
if (asset.name.endsWith('plugin.json')) {
|
||||
const pluginJsonString = asset.source.source().toString();
|
||||
const pluginJsonWithBuildMode = JSON.stringify(
|
||||
{
|
||||
...JSON.parse(pluginJsonString),
|
||||
buildMode: compilation.options.mode,
|
||||
},
|
||||
null,
|
||||
4
|
||||
);
|
||||
compilation.updateAsset(asset.name, new webpack.sources.RawSource(pluginJsonWithBuildMode));
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import process from 'process';
|
||||
import os from 'os';
|
||||
import path from 'path';
|
||||
import { glob } from 'glob';
|
||||
import { SOURCE_DIR } from './constants';
|
||||
import { SOURCE_DIR } from './constants.ts';
|
||||
|
||||
export function isWSL() {
|
||||
if (process.platform !== 'linux') {
|
||||
@@ -21,12 +21,22 @@ export function isWSL() {
|
||||
}
|
||||
}
|
||||
|
||||
function loadJson(path: string) {
|
||||
const rawJson = fs.readFileSync(path, 'utf8');
|
||||
return JSON.parse(rawJson);
|
||||
}
|
||||
|
||||
export function getPackageJson() {
|
||||
return require(path.resolve(process.cwd(), 'package.json'));
|
||||
return loadJson(path.resolve(process.cwd(), 'package.json'));
|
||||
}
|
||||
|
||||
export function getPluginJson() {
|
||||
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
|
||||
return loadJson(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
|
||||
}
|
||||
|
||||
export function getCPConfigVersion() {
|
||||
const cprcJson = path.resolve(process.cwd(), './.config', '.cprc.json');
|
||||
return fs.existsSync(cprcJson) ? loadJson(cprcJson).version : { version: 'unknown' };
|
||||
}
|
||||
|
||||
export function hasReadme() {
|
||||
@@ -35,7 +45,7 @@ export function hasReadme() {
|
||||
|
||||
// Support bundling nested plugins by finding all plugin.json files in src directory
|
||||
// then checking for a sibling module.[jt]sx? file.
|
||||
export async function getEntries(): Promise<Record<string, string>> {
|
||||
export async function getEntries() {
|
||||
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });
|
||||
|
||||
const plugins = await Promise.all(
|
||||
@@ -45,14 +55,14 @@ export async function getEntries(): Promise<Record<string, string>> {
|
||||
})
|
||||
);
|
||||
|
||||
return plugins.reduce((result, modules) => {
|
||||
return modules.reduce((result, module) => {
|
||||
return plugins.reduce<Record<string, string>>((result, modules) => {
|
||||
return modules.reduce((innerResult, module) => {
|
||||
const pluginPath = path.dirname(module);
|
||||
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '');
|
||||
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`;
|
||||
|
||||
result[entryName] = module;
|
||||
return result;
|
||||
innerResult[entryName] = module;
|
||||
return innerResult;
|
||||
}, result);
|
||||
}, {});
|
||||
}
|
||||
|
||||
@@ -2,28 +2,50 @@
|
||||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
|
||||
*
|
||||
* In order to extend the configuration follow the steps in
|
||||
* https://grafana.com/developers/plugin-tools/create-a-plugin/extend-a-plugin/extend-configurations#extend-the-webpack-config
|
||||
* https://grafana.com/developers/plugin-tools/how-to-guides/extend-configurations#extend-the-webpack-config
|
||||
*/
|
||||
|
||||
import CopyWebpackPlugin from 'copy-webpack-plugin';
|
||||
import ESLintPlugin from 'eslint-webpack-plugin';
|
||||
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
|
||||
import LiveReloadPlugin from 'webpack-livereload-plugin';
|
||||
import path from 'path';
|
||||
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
|
||||
import { Configuration } from 'webpack';
|
||||
import TerserPlugin from 'terser-webpack-plugin';
|
||||
import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity';
|
||||
import webpack, { type Configuration } from 'webpack';
|
||||
import LiveReloadPlugin from 'webpack-livereload-plugin';
|
||||
import VirtualModulesPlugin from 'webpack-virtual-modules';
|
||||
|
||||
import { getPackageJson, getPluginJson, hasReadme, getEntries, isWSL } from './utils';
|
||||
import { SOURCE_DIR, DIST_DIR } from './constants';
|
||||
import { BuildModeWebpackPlugin } from './BuildModeWebpackPlugin.ts';
|
||||
import { DIST_DIR, SOURCE_DIR } from './constants.ts';
|
||||
import { getCPConfigVersion, getEntries, getPackageJson, getPluginJson, hasReadme, isWSL } from './utils.ts';
|
||||
|
||||
const pluginJson = getPluginJson();
|
||||
const cpVersion = getCPConfigVersion();
|
||||
const pluginVersion = getPackageJson().version;
|
||||
|
||||
const config = async (env): Promise<Configuration> => {
|
||||
const virtualPublicPath = new VirtualModulesPlugin({
|
||||
'node_modules/grafana-public-path.js': `
|
||||
import amdMetaModule from 'amd-module';
|
||||
|
||||
__webpack_public_path__ =
|
||||
amdMetaModule && amdMetaModule.uri
|
||||
? amdMetaModule.uri.slice(0, amdMetaModule.uri.lastIndexOf('/') + 1)
|
||||
: 'public/plugins/${pluginJson.id}/';
|
||||
`,
|
||||
});
|
||||
|
||||
export type Env = {
|
||||
[key: string]: true | string | Env;
|
||||
};
|
||||
|
||||
const config = async (env: Env): Promise<Configuration> => {
|
||||
const baseConfig: Configuration = {
|
||||
cache: {
|
||||
type: 'filesystem',
|
||||
buildDependencies: {
|
||||
config: [__filename],
|
||||
// __filename doesn't work in Node 24
|
||||
config: [path.resolve(process.cwd(), '.config', 'webpack', 'webpack.config.ts')],
|
||||
},
|
||||
},
|
||||
|
||||
@@ -34,6 +56,8 @@ const config = async (env): Promise<Configuration> => {
|
||||
entry: await getEntries(),
|
||||
|
||||
externals: [
|
||||
// Required for dynamic publicPath resolution
|
||||
{ 'amd-module': 'module' },
|
||||
'lodash',
|
||||
'jquery',
|
||||
'moment',
|
||||
@@ -49,21 +73,21 @@ const config = async (env): Promise<Configuration> => {
|
||||
'react-redux',
|
||||
'redux',
|
||||
'rxjs',
|
||||
'i18next',
|
||||
'react-router',
|
||||
'react-router-dom',
|
||||
'd3',
|
||||
'angular',
|
||||
'@grafana/ui',
|
||||
'@grafana/runtime',
|
||||
'@grafana/data',
|
||||
/^@grafana\/ui/i,
|
||||
/^@grafana\/runtime/i,
|
||||
/^@grafana\/data/i,
|
||||
|
||||
// Mark legacy SDK imports as external if their name starts with the "grafana/" prefix
|
||||
({ request }, callback) => {
|
||||
const prefix = 'grafana/';
|
||||
const hasPrefix = (request) => request.indexOf(prefix) === 0;
|
||||
const stripPrefix = (request) => request.substr(prefix.length);
|
||||
const hasPrefix = (request: string) => request.indexOf(prefix) === 0;
|
||||
const stripPrefix = (request: string) => request.substr(prefix.length);
|
||||
|
||||
if (hasPrefix(request)) {
|
||||
if (request && hasPrefix(request)) {
|
||||
return callback(undefined, stripPrefix(request));
|
||||
}
|
||||
|
||||
@@ -71,10 +95,27 @@ const config = async (env): Promise<Configuration> => {
|
||||
},
|
||||
],
|
||||
|
||||
// Support WebAssembly according to latest spec - makes WebAssembly module async
|
||||
experiments: {
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
|
||||
mode: env.production ? 'production' : 'development',
|
||||
|
||||
module: {
|
||||
rules: [
|
||||
// This must come first in the rules array otherwise it breaks sourcemaps.
|
||||
{
|
||||
test: /src\/(?:.*\/)?module\.tsx?$/,
|
||||
use: [
|
||||
{
|
||||
loader: 'imports-loader',
|
||||
options: {
|
||||
imports: `side-effects grafana-public-path`,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
exclude: /(node_modules)/,
|
||||
test: /\.[tj]sx?$/,
|
||||
@@ -82,7 +123,7 @@ const config = async (env): Promise<Configuration> => {
|
||||
loader: 'swc-loader',
|
||||
options: {
|
||||
jsc: {
|
||||
baseUrl: path.resolve(__dirname, 'src'),
|
||||
baseUrl: path.resolve(process.cwd(), SOURCE_DIR),
|
||||
target: 'es2015',
|
||||
loose: false,
|
||||
parser: {
|
||||
@@ -107,9 +148,6 @@ const config = async (env): Promise<Configuration> => {
|
||||
test: /\.(png|jpe?g|gif|svg)$/,
|
||||
type: 'asset/resource',
|
||||
generator: {
|
||||
// Keep publicPath relative for host.com/grafana/ deployments
|
||||
publicPath: `public/plugins/${pluginJson.id}/img/`,
|
||||
outputPath: 'img/',
|
||||
filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
|
||||
},
|
||||
},
|
||||
@@ -117,29 +155,53 @@ const config = async (env): Promise<Configuration> => {
|
||||
test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
|
||||
type: 'asset/resource',
|
||||
generator: {
|
||||
// Keep publicPath relative for host.com/grafana/ deployments
|
||||
publicPath: `public/plugins/${pluginJson.id}/fonts/`,
|
||||
outputPath: 'fonts/',
|
||||
filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
|
||||
filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
optimization: {
|
||||
minimize: Boolean(env.production),
|
||||
minimizer: [
|
||||
new TerserPlugin({
|
||||
terserOptions: {
|
||||
format: {
|
||||
comments: (_, { type, value }) => type === 'comment2' && value.trim().startsWith('[create-plugin]'),
|
||||
},
|
||||
compress: {
|
||||
drop_console: ['log', 'info'],
|
||||
},
|
||||
},
|
||||
}),
|
||||
],
|
||||
},
|
||||
|
||||
output: {
|
||||
clean: {
|
||||
keep: new RegExp(`(.*?_(amd64|arm(64)?)(.exe)?|go_plugin_build_manifest)`),
|
||||
},
|
||||
filename: '[name].js',
|
||||
chunkFilename: env.production ? '[name].js?_cache=[contenthash]' : '[name].js',
|
||||
library: {
|
||||
type: 'amd',
|
||||
},
|
||||
path: path.resolve(process.cwd(), DIST_DIR),
|
||||
publicPath: `public/plugins/${pluginJson.id}/`,
|
||||
uniqueName: pluginJson.id,
|
||||
crossOriginLoading: 'anonymous',
|
||||
},
|
||||
|
||||
plugins: [
|
||||
new BuildModeWebpackPlugin(),
|
||||
virtualPublicPath,
|
||||
// Insert create plugin version information into the bundle
|
||||
new webpack.BannerPlugin({
|
||||
banner: `/* [create-plugin] version: ${cpVersion} */
|
||||
/* [create-plugin] plugin: ${pluginJson.id}@${pluginVersion} */`,
|
||||
raw: true,
|
||||
entryOnly: true,
|
||||
}),
|
||||
new CopyWebpackPlugin({
|
||||
patterns: [
|
||||
// If src/README.md exists use it; otherwise the root README
|
||||
@@ -148,14 +210,14 @@ const config = async (env): Promise<Configuration> => {
|
||||
{ from: 'plugin.json', to: '.' },
|
||||
{ from: '../LICENSE', to: '.' },
|
||||
{ from: '../CHANGELOG.md', to: '.', force: true },
|
||||
{ from: '**/*.json', to: '.' }, // TODO<Add an error for checking the basic structure of the repo>
|
||||
{ from: '**/*.svg', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: '**/*.png', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: '**/*.html', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: 'img/**/*', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: 'static/**/*', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true }, // Optional
|
||||
{ from: '**/*.json', to: '.' },
|
||||
{ from: '**/*.svg', to: '.', noErrorOnMissing: true },
|
||||
{ from: '**/*.png', to: '.', noErrorOnMissing: true },
|
||||
{ from: '**/*.html', to: '.', noErrorOnMissing: true },
|
||||
{ from: 'img/**/*', to: '.', noErrorOnMissing: true },
|
||||
{ from: 'libs/**/*', to: '.', noErrorOnMissing: true },
|
||||
{ from: 'static/**/*', to: '.', noErrorOnMissing: true },
|
||||
{ from: '**/query_help.md', to: '.', noErrorOnMissing: true },
|
||||
],
|
||||
}),
|
||||
// Replace certain template-variables in the README and plugin.json
|
||||
@@ -166,7 +228,7 @@ const config = async (env): Promise<Configuration> => {
|
||||
rules: [
|
||||
{
|
||||
search: /\%VERSION\%/g,
|
||||
replace: getPackageJson().version,
|
||||
replace: pluginVersion,
|
||||
},
|
||||
{
|
||||
search: /\%TODAY\%/g,
|
||||
@@ -179,6 +241,9 @@ const config = async (env): Promise<Configuration> => {
|
||||
],
|
||||
},
|
||||
]),
|
||||
new SubresourceIntegrityPlugin({
|
||||
hashFuncNames: ['sha256'],
|
||||
}),
|
||||
...(env.development
|
||||
? [
|
||||
new LiveReloadPlugin(),
|
||||
@@ -192,6 +257,7 @@ const config = async (env): Promise<Configuration> => {
|
||||
new ESLintPlugin({
|
||||
extensions: ['.ts', '.tsx'],
|
||||
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
|
||||
failOnError: Boolean(env.production),
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
|
||||
Reference in New Issue
Block a user