Skip to content

Commit d54c671

Browse files
authored
Chore: Bump create plugin (#339)
This PR bumps the create plugin version to 5.22.0 also bumps backend dependencies and migrates to use yarn 4.
1 parent 69975e1 commit d54c671

24 files changed

+16228
-10900
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": "5.12.4"
2+
"version": "5.22.0"
33
}

.config/.eslintrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
{
2525
"files": ["./tests/**/*"],
2626
"rules": {
27-
"react-hooks/rules-of-hooks": "off",
28-
},
27+
"react-hooks/rules-of-hooks": "off"
28+
}
2929
}
3030
]
3131
}

.config/README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ We are going to use [`webpack-merge`](https://github.com/survivejs/webpack-merge
106106
// webpack.config.ts
107107
import type { Configuration } from 'webpack';
108108
import { merge } from 'webpack-merge';
109-
import grafanaConfig from './.config/webpack/webpack.config';
109+
import grafanaConfig, { type Env } from './.config/webpack/webpack.config';
110110

111-
const config = async (env): Promise<Configuration> => {
111+
const config = async (env: Env): Promise<Configuration> => {
112112
const baseConfig = await grafanaConfig(env);
113113

114114
return merge(baseConfig, {
@@ -151,9 +151,10 @@ version: '3.7'
151151

152152
services:
153153
grafana:
154-
container_name: 'myorg-basic-app'
154+
extends:
155+
file: .config/docker-compose-base.yaml
156+
service: grafana
155157
build:
156-
context: ./.config
157158
args:
158159
grafana_version: ${GRAFANA_VERSION:-9.1.2}
159160
grafana_image: ${GRAFANA_IMAGE:-grafana}

.config/docker-compose-base.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
services:
2+
grafana:
3+
user: root
4+
container_name: 'grafana-bigquery-datasource'
5+
6+
build:
7+
context: .
8+
args:
9+
grafana_image: ${GRAFANA_IMAGE:-grafana-enterprise}
10+
grafana_version: ${GRAFANA_VERSION:-11.5.3}
11+
development: ${DEVELOPMENT:-false}
12+
anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
13+
ports:
14+
- 3000:3000/tcp
15+
- 2345:2345/tcp # delve
16+
security_opt:
17+
- 'apparmor:unconfined'
18+
- 'seccomp:unconfined'
19+
cap_add:
20+
- SYS_PTRACE
21+
volumes:
22+
- ../dist:/var/lib/grafana/plugins/grafana-bigquery-datasource
23+
- ../provisioning:/etc/grafana/provisioning
24+
- ..:/root/grafana-bigquery-datasource
25+
26+
environment:
27+
NODE_ENV: development
28+
GF_LOG_FILTERS: plugin.grafana-bigquery-datasource:debug
29+
GF_LOG_LEVEL: debug
30+
GF_DATAPROXY_LOGGING: 1
31+
GF_PLUGINS_ALLOW_LOADING_UNSIGNED_PLUGINS: grafana-bigquery-datasource

.config/types/bundler-rules.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 src: string;
29+
export default src;
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';

.config/types/webpack-plugins.d.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
declare module 'replace-in-file-webpack-plugin' {
2+
import { Compiler, Plugin } from 'webpack';
3+
4+
interface ReplaceRule {
5+
search: string | RegExp;
6+
replace: string | ((match: string) => string);
7+
}
8+
9+
interface ReplaceOption {
10+
dir?: string;
11+
files?: string[];
12+
test?: RegExp | RegExp[];
13+
rules: ReplaceRule[];
14+
}
15+
16+
class ReplaceInFilePlugin extends Plugin {
17+
constructor(options?: ReplaceOption[]);
18+
options: ReplaceOption[];
19+
apply(compiler: Compiler): void;
20+
}
21+
22+
export = ReplaceInFilePlugin;
23+
}
24+
25+
declare module 'webpack-livereload-plugin' {
26+
import { ServerOptions } from 'https';
27+
import { Compiler, Plugin, Stats, Compilation } from 'webpack';
28+
29+
interface Options extends Pick<ServerOptions, 'cert' | 'key' | 'pfx'> {
30+
/**
31+
* protocol for livereload `<script>` src attribute value
32+
* @default protocol of the page, either `http` or `https`
33+
*/
34+
protocol?: string | undefined;
35+
/**
36+
* The desired port for the livereload server.
37+
* If you define port 0, an available port will be searched for, starting from 35729.
38+
* @default 35729
39+
*/
40+
port?: number | undefined;
41+
/**
42+
* he desired hostname for the appended `<script>` (if present) to point to
43+
* @default hostname of the page, like `localhost` or 10.0.2.2
44+
*/
45+
hostname?: string | undefined;
46+
/**
47+
* livereload `<script>` automatically to `<head>`.
48+
* @default false
49+
*/
50+
appendScriptTag?: boolean | undefined;
51+
/**
52+
* RegExp of files to ignore. Null value means ignore nothing.
53+
* It is also possible to define an array and use multiple anymatch patterns
54+
*/
55+
ignore?: RegExp | RegExp[] | null | undefined;
56+
/**
57+
* amount of milliseconds by which to delay the live reload (in case build takes longer)
58+
* @default 0
59+
*/
60+
delay?: number | undefined;
61+
/**
62+
* create hash for each file source and only notify livereload if hash has changed
63+
* @default false
64+
*/
65+
useSourceHash?: boolean | undefined;
66+
}
67+
68+
class LiveReloadPlugin extends Plugin {
69+
readonly isRunning: boolean;
70+
constructor(options?: Options);
71+
72+
apply(compiler: Compiler): void;
73+
74+
start(watching: any, cb: () => void): void;
75+
done(stats: Stats): void;
76+
failed(): void;
77+
autoloadJs(): string;
78+
scriptTag(source: string): string;
79+
applyCompilation(compilation: Compilation): void;
80+
}
81+
82+
export = LiveReloadPlugin;
83+
}

.config/webpack/BuildModeWebpackPlugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as webpack from 'webpack';
1+
import webpack, { type Compiler } from 'webpack';
22

33
const PLUGIN_NAME = 'BuildModeWebpack';
44

.config/webpack/utils.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import process from 'process';
33
import os from 'os';
44
import path from 'path';
55
import { glob } from 'glob';
6-
import { SOURCE_DIR } from './constants';
6+
import { SOURCE_DIR } from './constants.ts';
77

88
export function isWSL() {
99
if (process.platform !== 'linux') {
@@ -21,17 +21,22 @@ export function isWSL() {
2121
}
2222
}
2323

24+
function loadJson(path: string) {
25+
const rawJson = fs.readFileSync(path, 'utf8');
26+
return JSON.parse(rawJson);
27+
}
28+
2429
export function getPackageJson() {
25-
return require(path.resolve(process.cwd(), 'package.json'));
30+
return loadJson(path.resolve(process.cwd(), 'package.json'));
2631
}
2732

2833
export function getPluginJson() {
29-
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
34+
return loadJson(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
3035
}
3136

3237
export function getCPConfigVersion() {
33-
const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34-
return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
38+
const cprcJson = path.resolve(process.cwd(), './.config', '.cprc.json');
39+
return fs.existsSync(cprcJson) ? loadJson(cprcJson).version : { version: 'unknown' };
3540
}
3641

3742
export function hasReadme() {
@@ -40,7 +45,7 @@ export function hasReadme() {
4045

4146
// Support bundling nested plugins by finding all plugin.json files in src directory
4247
// then checking for a sibling module.[jt]sx? file.
43-
export async function getEntries(): Promise<Record<string, string>> {
48+
export async function getEntries() {
4449
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });
4550

4651
const plugins = await Promise.all(
@@ -50,14 +55,14 @@ export async function getEntries(): Promise<Record<string, string>> {
5055
})
5156
);
5257

53-
return plugins.reduce((result, modules) => {
54-
return modules.reduce((result, module) => {
58+
return plugins.reduce<Record<string, string>>((result, modules) => {
59+
return modules.reduce((innerResult, module) => {
5560
const pluginPath = path.dirname(module);
5661
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '');
5762
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`;
5863

59-
result[entryName] = module;
60-
return result;
64+
innerResult[entryName] = module;
65+
return innerResult;
6166
}, result);
6267
}, {});
6368
}

.config/webpack/webpack.config.ts

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@ import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
1111
import path from 'path';
1212
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
1313
import TerserPlugin from 'terser-webpack-plugin';
14-
import { SubresourceIntegrityPlugin } from "webpack-subresource-integrity";
15-
import { type Configuration, BannerPlugin } from 'webpack';
14+
import { SubresourceIntegrityPlugin } from 'webpack-subresource-integrity';
15+
import webpack, { type Configuration } from 'webpack';
1616
import LiveReloadPlugin from 'webpack-livereload-plugin';
1717
import VirtualModulesPlugin from 'webpack-virtual-modules';
1818

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

2323
const pluginJson = getPluginJson();
2424
const cpVersion = getCPConfigVersion();
@@ -34,12 +34,17 @@ __webpack_public_path__ =
3434
`,
3535
});
3636

37-
const config = async (env): Promise<Configuration> => {
37+
export type Env = {
38+
[key: string]: true | string | Env;
39+
};
40+
41+
const config = async (env: Env): Promise<Configuration> => {
3842
const baseConfig: Configuration = {
3943
cache: {
4044
type: 'filesystem',
4145
buildDependencies: {
42-
config: [__filename],
46+
// __filename doesnt work in Node 24
47+
config: [path.resolve(process.cwd(), '.config', 'webpack', 'webpack.config.ts')],
4348
},
4449
},
4550

@@ -68,20 +73,19 @@ const config = async (env): Promise<Configuration> => {
6873
'redux',
6974
'rxjs',
7075
'react-router',
71-
'react-router-dom',
7276
'd3',
7377
'angular',
74-
'@grafana/ui',
75-
'@grafana/runtime',
76-
'@grafana/data',
78+
/^@grafana\/ui/i,
79+
/^@grafana\/runtime/i,
80+
/^@grafana\/data/i,
7781

7882
// Mark legacy SDK imports as external if their name starts with the "grafana/" prefix
7983
({ request }, callback) => {
8084
const prefix = 'grafana/';
81-
const hasPrefix = (request) => request.indexOf(prefix) === 0;
82-
const stripPrefix = (request) => request.substr(prefix.length);
85+
const hasPrefix = (request: string) => request.indexOf(prefix) === 0;
86+
const stripPrefix = (request: string) => request.substr(prefix.length);
8387

84-
if (hasPrefix(request)) {
88+
if (request && hasPrefix(request)) {
8589
return callback(undefined, stripPrefix(request));
8690
}
8791

@@ -164,8 +168,8 @@ const config = async (env): Promise<Configuration> => {
164168
comments: (_, { type, value }) => type === 'comment2' && value.trim().startsWith('[create-plugin]'),
165169
},
166170
compress: {
167-
drop_console: ['log', 'info']
168-
}
171+
drop_console: ['log', 'info'],
172+
},
169173
},
170174
}),
171175
],
@@ -190,8 +194,8 @@ const config = async (env): Promise<Configuration> => {
190194
new BuildModeWebpackPlugin(),
191195
virtualPublicPath,
192196
// Insert create plugin version information into the bundle
193-
new BannerPlugin({
194-
banner: "/* [create-plugin] version: " + cpVersion + " */",
197+
new webpack.BannerPlugin({
198+
banner: '/* [create-plugin] version: ' + cpVersion + ' */',
195199
raw: true,
196200
entryOnly: true,
197201
}),
@@ -235,22 +239,24 @@ const config = async (env): Promise<Configuration> => {
235239
},
236240
]),
237241
new SubresourceIntegrityPlugin({
238-
hashFuncNames: ["sha256"],
242+
hashFuncNames: ['sha256'],
239243
}),
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-
] : []),
244+
...(env.development
245+
? [
246+
new LiveReloadPlugin(),
247+
new ForkTsCheckerWebpackPlugin({
248+
async: Boolean(env.development),
249+
issue: {
250+
include: [{ file: '**/*.{ts,tsx}' }],
251+
},
252+
typescript: { configFile: path.join(process.cwd(), 'tsconfig.json') },
253+
}),
254+
new ESLintPlugin({
255+
extensions: ['.ts', '.tsx'],
256+
lintDirtyModulesOnly: Boolean(env.development), // don't lint on start, only lint changed files
257+
}),
258+
]
259+
: []),
254260
],
255261

256262
resolve: {

0 commit comments

Comments
 (0)