Skip to content

Commit 4bce9dd

Browse files
authored
Create Plugin: Support Node 24 (#1772)
1 parent f0fc915 commit 4bce9dd

File tree

4 files changed

+110
-12
lines changed

4 files changed

+110
-12
lines changed

.github/workflows/ci.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,98 @@ jobs:
5656
path: ./packed-artifacts
5757
retention-days: 1
5858

59+
test-node-versions:
60+
runs-on: ubuntu-latest
61+
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"
62+
name: Test node versions
63+
needs: [test]
64+
strategy:
65+
fail-fast: false
66+
matrix:
67+
node-version:
68+
- 20
69+
- 22
70+
- 24
71+
env:
72+
WORKING_DIR: 'myorg-nobackend-panel'
73+
steps:
74+
- name: Setup .npmrc file for NPM registry
75+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
76+
with:
77+
node-version: ${{ matrix.node-version }}
78+
registry-url: 'https://registry.npmjs.org'
79+
80+
- name: Download packed artifacts
81+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
82+
with:
83+
name: packed-artifacts
84+
path: ./packed-artifacts
85+
86+
- name: Install npm packages globally
87+
run: for file in *.tgz; do npm install -g "$file"; done
88+
working-directory: ./packed-artifacts
89+
90+
- name: Generate plugin
91+
run: npx create-plugin --plugin-name='no-backend' --org-name='myorg' --plugin-type='panel'
92+
93+
- name: Install generated plugin dependencies
94+
run: npm install --no-audit
95+
working-directory: ./${{ env.WORKING_DIR }}
96+
97+
- name: Lint plugin frontend
98+
run: npm run lint
99+
working-directory: ./${{ env.WORKING_DIR }}
100+
101+
- name: Typecheck plugin frontend
102+
run: npm run typecheck
103+
working-directory: ./${{ env.WORKING_DIR }}
104+
105+
- name: Build plugin frontend
106+
run: npm run build
107+
working-directory: ./${{ env.WORKING_DIR }}
108+
109+
- name: Test plugin frontend
110+
run: npm run test:ci
111+
working-directory: ./${{ env.WORKING_DIR }}
112+
113+
- name: Install playwright dependencies
114+
run: npm exec playwright install --with-deps chromium
115+
working-directory: ./${{ env.WORKING_DIR }}
116+
117+
- name: Start grafana server for e2e tests (10.4.0)
118+
run: |
119+
ANONYMOUS_AUTH_ENABLED=false docker compose build --no-cache
120+
docker compose up -d
121+
env:
122+
GRAFANA_VERSION: '10.4.0'
123+
working-directory: ./${{ env.WORKING_DIR }}
124+
125+
- name: Wait for grafana server (10.4.0)
126+
uses: grafana/plugin-actions/wait-for-grafana@7954f7aa08f1450c1ca49e20be401e4c3f8865f8
127+
with:
128+
url: http://localhost:3000/login
129+
130+
- name: Run e2e tests (10.4.0)
131+
id: run-e2e-tests-min-version
132+
run: npm run e2e
133+
working-directory: ./${{ env.WORKING_DIR }}
134+
135+
- name: Stop grafana docker (10.4.0)
136+
run: docker compose down
137+
working-directory: ./${{ env.WORKING_DIR }}
138+
139+
- name: '@grafana/sign-plugin - use GRAFANA_ACCESS_POLICY_TOKEN to sign generate-panel plugin'
140+
env:
141+
GRAFANA_ACCESS_POLICY_TOKEN: ${{ secrets.GRAFANA_ACCESS_POLICY_TOKEN }}
142+
run: sign-plugin --rootUrls http://www.example.com --signatureType private
143+
working-directory: ./${{ env.WORKING_DIR }}
144+
145+
- name: '@grafana/sign-plugin - use GRAFANA_API_KEY to sign generate-panel plugin'
146+
env:
147+
GRAFANA_API_KEY: ${{ secrets.GRAFANA_API_KEY }}
148+
run: sign-plugin --rootUrls http://www.example.com --signatureType private
149+
working-directory: ./${{ env.WORKING_DIR }}
150+
59151
generate-plugins:
60152
name: Test plugin scaffolding
61153
if: "!contains(github.event.head_commit.message, 'ci skip') && !contains(github.event.head_commit.message, 'skip ci')"

packages/create-plugin/templates/common/.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

packages/create-plugin/templates/common/.config/webpack/utils.ts

Lines changed: 10 additions & 5 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() {

packages/create-plugin/templates/common/.config/webpack/webpack.config.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import path from 'path';
1212
import ReplaceInFileWebpackPlugin from 'replace-in-file-webpack-plugin';
1313
import TerserPlugin from 'terser-webpack-plugin';
1414
import { SubresourceIntegrityPlugin } from "webpack-subresource-integrity";
15-
import { type Configuration, BannerPlugin } from 'webpack';
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();
@@ -43,7 +43,8 @@ const config = async (env: Env): Promise<Configuration> => {
4343
cache: {
4444
type: 'filesystem',
4545
buildDependencies: {
46-
config: [__filename],
46+
// __filename doesnt work in Node 24
47+
config: [path.resolve(process.cwd(), '.config', 'webpack', 'webpack.config.ts')],
4748
},
4849
},
4950

@@ -196,7 +197,7 @@ const config = async (env: Env): Promise<Configuration> => {
196197
new BuildModeWebpackPlugin(),
197198
virtualPublicPath,
198199
// Insert create plugin version information into the bundle
199-
new BannerPlugin({
200+
new webpack.BannerPlugin({
200201
banner: "/* [create-plugin] version: " + cpVersion + " */",
201202
raw: true,
202203
entryOnly: true,

0 commit comments

Comments
 (0)