@grafana/create-plugin 6.8.0-canary.2356.20816081919.0 → 6.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +101 -0
  2. package/dist/codemods/additions/additions.js +3 -3
  3. package/dist/codemods/utils.js +2 -2
  4. package/package.json +3 -3
  5. package/src/codemods/additions/additions.ts +3 -3
  6. package/templates/backend/go.mod +30 -29
  7. package/templates/backend/go.sum +62 -62
  8. package/templates/backend-app/go.mod +30 -29
  9. package/templates/backend-app/go.sum +62 -62
  10. package/templates/common/.config/bundler/copyFiles.ts +23 -0
  11. package/templates/common/.config/docker-compose-base.yaml +1 -1
  12. package/templates/common/.config/rspack/BuildModeRspackPlugin.ts +4 -4
  13. package/templates/common/.config/rspack/{liveReloadPlugin.js → liveReloadPlugin.ts} +34 -11
  14. package/templates/common/.config/rspack/rspack.config.ts +8 -22
  15. package/templates/common/.config/webpack/BuildModeWebpackPlugin.ts +1 -1
  16. package/templates/common/.config/webpack/webpack.config.ts +4 -17
  17. package/templates/common/_package.json +46 -44
  18. package/templates/github/workflows/bundle-stats.yml +1 -1
  19. package/templates/github/workflows/ci.yml +17 -10
  20. package/templates/github/workflows/is-compatible.yml +2 -2
  21. package/templates/github/workflows/release.yml +1 -1
  22. package/dist/codemods/additions/scripts/bundle-grafana-ui/index.js +0 -174
  23. package/dist/codemods/utils.bundler-config.js +0 -19
  24. package/dist/codemods/utils.externals.js +0 -116
  25. package/src/codemods/additions/scripts/bundle-grafana-ui/README.md +0 -68
  26. package/src/codemods/additions/scripts/bundle-grafana-ui/index.test.ts +0 -511
  27. package/src/codemods/additions/scripts/bundle-grafana-ui/index.ts +0 -259
  28. package/src/codemods/utils.bundler-config.ts +0 -203
  29. package/src/codemods/utils.externals.test.ts +0 -87
  30. package/src/codemods/utils.externals.ts +0 -181
  31. package/templates/common/.config/rspack/utils.ts +0 -63
  32. package/templates/common/.config/webpack/constants.ts +0 -2
  33. /package/templates/common/.config/{rspack → bundler}/constants.ts +0 -0
  34. /package/templates/common/.config/{webpack → bundler}/utils.ts +0 -0
@@ -1,181 +0,0 @@
1
- import * as recast from 'recast';
2
- import * as typeScriptParser from 'recast/parsers/typescript.js';
3
-
4
- import type { Context } from './context.js';
5
- import { additionsDebug } from './utils.js';
6
-
7
- /**
8
- * Utility for updating externals arrays in plugin bundler configurations.
9
- *
10
- * This utility is needed because the location of externals configuration has changed over time:
11
- * - **New plugins** (created with recent versions of @grafana/create-plugin): Externals are defined
12
- * in a separate file at `.config/bundler/externals.ts`
13
- * - **Older plugins** (created with earlier versions): Externals are defined inline within
14
- * `.config/webpack/webpack.config.ts` as part of the webpack Configuration object
15
- *
16
- * This utility handles both cases automatically, preferring the modern structure when both exist,
17
- * to ensure additions and migrations work correctly regardless of when the plugin was created.
18
- */
19
-
20
- /**
21
- * Type for a function that modifies an externals array
22
- * @param externalsArray - The AST node representing the externals array
23
- * @returns true if changes were made, false otherwise
24
- */
25
- export type ExternalsArrayModifier = (externalsArray: recast.types.namedTypes.ArrayExpression) => boolean;
26
-
27
- const EXTERNALS_PATH = '.config/bundler/externals.ts';
28
- const WEBPACK_CONFIG_PATH = '.config/webpack/webpack.config.ts';
29
-
30
- /**
31
- * Updates the externals array in either .config/bundler/externals.ts (preferred) or
32
- * .config/webpack/webpack.config.ts (legacy fallback).
33
- *
34
- * @param context - The codemod context
35
- * @param modifier - A function that modifies the externals array and returns true if changes were made
36
- * @returns true if changes were made to any file, false otherwise
37
- */
38
- export function updateExternalsArray(context: Context, modifier: ExternalsArrayModifier): boolean {
39
- // Try new structure first: .config/bundler/externals.ts
40
- if (context.doesFileExist(EXTERNALS_PATH)) {
41
- additionsDebug(`Found ${EXTERNALS_PATH}, updating externals array...`);
42
- const externalsContent = context.getFile(EXTERNALS_PATH);
43
- if (externalsContent) {
44
- try {
45
- const ast = recast.parse(externalsContent, {
46
- parser: typeScriptParser,
47
- });
48
-
49
- let hasChanges = false;
50
-
51
- recast.visit(ast, {
52
- visitVariableDeclarator(path) {
53
- const { node } = path;
54
-
55
- if (
56
- node.id.type === 'Identifier' &&
57
- node.id.name === 'externals' &&
58
- node.init &&
59
- node.init.type === 'ArrayExpression'
60
- ) {
61
- additionsDebug('Found externals array in externals.ts');
62
- if (modifier(node.init)) {
63
- hasChanges = true;
64
- }
65
- }
66
-
67
- return this.traverse(path);
68
- },
69
- });
70
-
71
- if (hasChanges) {
72
- const output = recast.print(ast, {
73
- tabWidth: 2,
74
- trailingComma: true,
75
- lineTerminator: '\n',
76
- });
77
- context.updateFile(EXTERNALS_PATH, output.code);
78
- additionsDebug(`Updated ${EXTERNALS_PATH}`);
79
- return true;
80
- }
81
- return false;
82
- } catch (error) {
83
- additionsDebug(`Error updating ${EXTERNALS_PATH}:`, error);
84
- return false;
85
- }
86
- }
87
- }
88
-
89
- // Fall back to legacy structure: .config/webpack/webpack.config.ts with inline externals
90
- additionsDebug(`Checking for ${WEBPACK_CONFIG_PATH}...`);
91
- if (context.doesFileExist(WEBPACK_CONFIG_PATH)) {
92
- additionsDebug(`Found ${WEBPACK_CONFIG_PATH}, checking for inline externals...`);
93
- const webpackContent = context.getFile(WEBPACK_CONFIG_PATH);
94
- if (webpackContent) {
95
- try {
96
- const ast = recast.parse(webpackContent, {
97
- parser: typeScriptParser,
98
- });
99
-
100
- let hasChanges = false;
101
- let foundExternals = false;
102
-
103
- recast.visit(ast, {
104
- visitObjectExpression(path) {
105
- const { node } = path;
106
- const properties = node.properties;
107
-
108
- if (properties) {
109
- for (const prop of properties) {
110
- if (prop && (prop.type === 'Property' || prop.type === 'ObjectProperty')) {
111
- const key = 'key' in prop ? prop.key : null;
112
- const value = 'value' in prop ? prop.value : null;
113
-
114
- if (
115
- key &&
116
- key.type === 'Identifier' &&
117
- key.name === 'externals' &&
118
- value &&
119
- value.type === 'ArrayExpression'
120
- ) {
121
- foundExternals = true;
122
- additionsDebug('Found externals property in webpack.config.ts');
123
- if (modifier(value)) {
124
- hasChanges = true;
125
- }
126
- }
127
- }
128
- }
129
- }
130
-
131
- return this.traverse(path);
132
- },
133
- visitProperty(path) {
134
- const { node } = path;
135
-
136
- // Also check properties directly (fallback)
137
- if (
138
- node.key &&
139
- node.key.type === 'Identifier' &&
140
- node.key.name === 'externals' &&
141
- node.value &&
142
- node.value.type === 'ArrayExpression'
143
- ) {
144
- if (!foundExternals) {
145
- foundExternals = true;
146
- additionsDebug('Found externals property in webpack.config.ts (via visitProperty)');
147
- }
148
- if (modifier(node.value)) {
149
- hasChanges = true;
150
- }
151
- }
152
-
153
- return this.traverse(path);
154
- },
155
- });
156
-
157
- if (!foundExternals) {
158
- additionsDebug('No externals property found in webpack.config.ts');
159
- }
160
-
161
- if (hasChanges) {
162
- const output = recast.print(ast, {
163
- tabWidth: 2,
164
- trailingComma: true,
165
- lineTerminator: '\n',
166
- });
167
- context.updateFile(WEBPACK_CONFIG_PATH, output.code);
168
- additionsDebug(`Updated ${WEBPACK_CONFIG_PATH}`);
169
- return true;
170
- }
171
- return false;
172
- } catch (error) {
173
- additionsDebug(`Error updating ${WEBPACK_CONFIG_PATH}:`, error);
174
- return false;
175
- }
176
- }
177
- }
178
-
179
- additionsDebug('No externals configuration found');
180
- return false;
181
- }
@@ -1,63 +0,0 @@
1
- import fs from 'fs';
2
- import process from 'process';
3
- import os from 'os';
4
- import path from 'path';
5
- import { glob } from 'glob';
6
- import { SOURCE_DIR } from './constants';
7
-
8
- export function isWSL() {
9
- if (process.platform !== 'linux') {
10
- return false;
11
- }
12
-
13
- if (os.release().toLowerCase().includes('microsoft')) {
14
- return true;
15
- }
16
-
17
- try {
18
- return fs.readFileSync('/proc/version', 'utf8').toLowerCase().includes('microsoft');
19
- } catch {
20
- return false;
21
- }
22
- }
23
-
24
- export function getPackageJson() {
25
- return require(path.resolve(process.cwd(), 'package.json'));
26
- }
27
-
28
- export function getPluginJson() {
29
- return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`));
30
- }
31
-
32
- export function getCPConfigVersion() {
33
- const cprcJson = path.resolve(__dirname, '../', '.cprc.json');
34
- return fs.existsSync(cprcJson) ? require(cprcJson).version : { version: 'unknown' };
35
- }
36
-
37
- export function hasReadme() {
38
- return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md'));
39
- }
40
-
41
- // Support bundling nested plugins by finding all plugin.json files in src directory
42
- // then checking for a sibling module.[jt]sx? file.
43
- export async function getEntries(): Promise<Record<string, string>> {
44
- const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true });
45
-
46
- const plugins = await Promise.all(
47
- pluginsJson.map((pluginJson) => {
48
- const folder = path.dirname(pluginJson);
49
- return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true });
50
- })
51
- );
52
-
53
- return plugins.reduce((result, modules) => {
54
- return modules.reduce((result, module) => {
55
- const pluginPath = path.dirname(module);
56
- const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, '');
57
- const entryName = pluginName === '' ? 'module' : `${pluginName}/module`;
58
-
59
- result[entryName] = module;
60
- return result;
61
- }, result);
62
- }, {});
63
- }
@@ -1,2 +0,0 @@
1
- export const SOURCE_DIR = 'src';
2
- export const DIST_DIR = 'dist';