@grafana/create-plugin 6.8.0-canary.2356.20813982803.0 → 6.8.0-canary.2356.20814126191.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.
|
@@ -2,20 +2,19 @@ import * as v from 'valibot';
|
|
|
2
2
|
import * as recast from 'recast';
|
|
3
3
|
import { coerce, gte } from 'semver';
|
|
4
4
|
import { additionsDebug } from '../../../utils.js';
|
|
5
|
+
import { getBundlerConfig } from '../../../utils.bundler-config.js';
|
|
5
6
|
import { updateExternalsArray } from '../../../utils.externals.js';
|
|
6
7
|
|
|
7
8
|
const { builders } = recast.types;
|
|
8
9
|
const PLUGIN_JSON_PATH = "src/plugin.json";
|
|
9
10
|
const MIN_GRAFANA_VERSION = "10.2.0";
|
|
10
|
-
const WEBPACK_CONFIG_PATH = ".config/webpack/webpack.config.ts";
|
|
11
|
-
const RSPACK_CONFIG_PATH = ".config/rspack/rspack.config.ts";
|
|
12
11
|
const schema = v.object({});
|
|
13
12
|
function bundleGrafanaUI(context, _options) {
|
|
14
13
|
additionsDebug("Running bundle-grafana-ui addition...");
|
|
15
14
|
ensureMinGrafanaVersion(context);
|
|
16
15
|
updateExternalsArray(context, createBundleGrafanaUIModifier());
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
updateResolveExtensions(context);
|
|
17
|
+
updateModuleRules(context);
|
|
19
18
|
return context;
|
|
20
19
|
}
|
|
21
20
|
function isGrafanaRegex(element, pattern) {
|
|
@@ -78,15 +77,12 @@ function createBundleGrafanaUIModifier() {
|
|
|
78
77
|
return removeGrafanaUiAndAddReactInlineSvg(externalsArray);
|
|
79
78
|
};
|
|
80
79
|
}
|
|
81
|
-
function
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const content = context.getFile(configPath);
|
|
87
|
-
if (!content) {
|
|
80
|
+
function updateResolveExtensions(context) {
|
|
81
|
+
const config = getBundlerConfig(context);
|
|
82
|
+
if (!config) {
|
|
88
83
|
return;
|
|
89
84
|
}
|
|
85
|
+
const { path: configPath, content } = config;
|
|
90
86
|
if (content.includes("'.mjs'") || content.includes('".mjs"')) {
|
|
91
87
|
return;
|
|
92
88
|
}
|
|
@@ -101,15 +97,12 @@ function updateResolveExtensionsSimple(context) {
|
|
|
101
97
|
additionsDebug("Added '.mjs' to resolve.extensions");
|
|
102
98
|
}
|
|
103
99
|
}
|
|
104
|
-
function
|
|
105
|
-
const
|
|
106
|
-
if (!
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
const content = context.getFile(configPath);
|
|
110
|
-
if (!content) {
|
|
100
|
+
function updateModuleRules(context) {
|
|
101
|
+
const config = getBundlerConfig(context);
|
|
102
|
+
if (!config) {
|
|
111
103
|
return;
|
|
112
104
|
}
|
|
105
|
+
const { path: configPath, content } = config;
|
|
113
106
|
if (content.includes("test: /\\.mjs$") || content.includes("test: /\\\\.mjs$")) {
|
|
114
107
|
return;
|
|
115
108
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import 'recast';
|
|
2
|
+
import 'recast/parsers/typescript.js';
|
|
3
|
+
import './utils.js';
|
|
4
|
+
|
|
5
|
+
const WEBPACK_CONFIG_PATH = ".config/webpack/webpack.config.ts";
|
|
6
|
+
const RSPACK_CONFIG_PATH = ".config/rspack/rspack.config.ts";
|
|
7
|
+
function getBundlerConfig(context) {
|
|
8
|
+
const configPath = context.doesFileExist(RSPACK_CONFIG_PATH) ? RSPACK_CONFIG_PATH : context.doesFileExist(WEBPACK_CONFIG_PATH) ? WEBPACK_CONFIG_PATH : null;
|
|
9
|
+
if (!configPath) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
const content = context.getFile(configPath);
|
|
13
|
+
if (!content) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
return { path: configPath, content };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { getBundlerConfig };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/create-plugin",
|
|
3
|
-
"version": "6.8.0-canary.2356.
|
|
3
|
+
"version": "6.8.0-canary.2356.20814126191.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"directory": "packages/create-plugin",
|
|
6
6
|
"url": "https://github.com/grafana/plugin-tools"
|
|
@@ -55,5 +55,5 @@
|
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">=20"
|
|
57
57
|
},
|
|
58
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "cbc5b5a6579bc798c0db9c3caee8443e0c9bf8c7"
|
|
59
59
|
}
|
|
@@ -4,14 +4,13 @@ import { coerce, gte } from 'semver';
|
|
|
4
4
|
|
|
5
5
|
import type { Context } from '../../../context.js';
|
|
6
6
|
import { additionsDebug } from '../../../utils.js';
|
|
7
|
+
import { getBundlerConfig } from '../../../utils.bundler-config.js';
|
|
7
8
|
import { updateExternalsArray, type ExternalsArrayModifier } from '../../../utils.externals.js';
|
|
8
9
|
|
|
9
10
|
const { builders } = recast.types;
|
|
10
11
|
|
|
11
12
|
const PLUGIN_JSON_PATH = 'src/plugin.json';
|
|
12
13
|
const MIN_GRAFANA_VERSION = '10.2.0';
|
|
13
|
-
const WEBPACK_CONFIG_PATH = '.config/webpack/webpack.config.ts';
|
|
14
|
-
const RSPACK_CONFIG_PATH = '.config/rspack/rspack.config.ts';
|
|
15
14
|
|
|
16
15
|
export const schema = v.object({});
|
|
17
16
|
type BundleGrafanaUIOptions = v.InferOutput<typeof schema>;
|
|
@@ -26,10 +25,10 @@ export default function bundleGrafanaUI(context: Context, _options: BundleGrafan
|
|
|
26
25
|
updateExternalsArray(context, createBundleGrafanaUIModifier());
|
|
27
26
|
|
|
28
27
|
// Update bundler resolve configuration to handle ESM imports
|
|
29
|
-
|
|
28
|
+
updateResolveExtensions(context);
|
|
30
29
|
|
|
31
30
|
// Update module rules directly with simple string manipulation
|
|
32
|
-
|
|
31
|
+
updateModuleRules(context);
|
|
33
32
|
|
|
34
33
|
return context;
|
|
35
34
|
}
|
|
@@ -132,24 +131,15 @@ function createBundleGrafanaUIModifier(): ExternalsArrayModifier {
|
|
|
132
131
|
}
|
|
133
132
|
|
|
134
133
|
/**
|
|
135
|
-
* Updates resolve extensions to add .mjs using
|
|
136
|
-
* This is a simplified approach that may not handle all edge cases, but is much simpler
|
|
134
|
+
* Updates resolve extensions to add .mjs using string manipulation
|
|
137
135
|
*/
|
|
138
|
-
function
|
|
139
|
-
const
|
|
140
|
-
|
|
141
|
-
: context.doesFileExist(WEBPACK_CONFIG_PATH)
|
|
142
|
-
? WEBPACK_CONFIG_PATH
|
|
143
|
-
: null;
|
|
144
|
-
|
|
145
|
-
if (!configPath) {
|
|
136
|
+
function updateResolveExtensions(context: Context): void {
|
|
137
|
+
const config = getBundlerConfig(context);
|
|
138
|
+
if (!config) {
|
|
146
139
|
return;
|
|
147
140
|
}
|
|
148
141
|
|
|
149
|
-
const content =
|
|
150
|
-
if (!content) {
|
|
151
|
-
return;
|
|
152
|
-
}
|
|
142
|
+
const { path: configPath, content } = config;
|
|
153
143
|
|
|
154
144
|
// Check if .mjs already exists
|
|
155
145
|
if (content.includes("'.mjs'") || content.includes('".mjs"')) {
|
|
@@ -171,24 +161,15 @@ function updateResolveExtensionsSimple(context: Context): void {
|
|
|
171
161
|
}
|
|
172
162
|
|
|
173
163
|
/**
|
|
174
|
-
* Updates module rules to add .mjs rule using
|
|
175
|
-
* This is a simplified approach that may not handle all edge cases, but is much simpler
|
|
164
|
+
* Updates module rules to add .mjs rule using string manipulation
|
|
176
165
|
*/
|
|
177
|
-
function
|
|
178
|
-
const
|
|
179
|
-
|
|
180
|
-
: context.doesFileExist(WEBPACK_CONFIG_PATH)
|
|
181
|
-
? WEBPACK_CONFIG_PATH
|
|
182
|
-
: null;
|
|
183
|
-
|
|
184
|
-
if (!configPath) {
|
|
166
|
+
function updateModuleRules(context: Context): void {
|
|
167
|
+
const config = getBundlerConfig(context);
|
|
168
|
+
if (!config) {
|
|
185
169
|
return;
|
|
186
170
|
}
|
|
187
171
|
|
|
188
|
-
const content =
|
|
189
|
-
if (!content) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
172
|
+
const { path: configPath, content } = config;
|
|
192
173
|
|
|
193
174
|
// Check if rule already exists
|
|
194
175
|
if (content.includes('test: /\\.mjs$') || content.includes('test: /\\\\.mjs$')) {
|
|
@@ -7,6 +7,29 @@ import { additionsDebug } from './utils.js';
|
|
|
7
7
|
const WEBPACK_CONFIG_PATH = '.config/webpack/webpack.config.ts';
|
|
8
8
|
const RSPACK_CONFIG_PATH = '.config/rspack/rspack.config.ts';
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Gets the bundler config file path and content, preferring rspack over webpack
|
|
12
|
+
* @returns Object with path and content, or null if no config file exists
|
|
13
|
+
*/
|
|
14
|
+
export function getBundlerConfig(context: Context): { path: string; content: string } | null {
|
|
15
|
+
const configPath = context.doesFileExist(RSPACK_CONFIG_PATH)
|
|
16
|
+
? RSPACK_CONFIG_PATH
|
|
17
|
+
: context.doesFileExist(WEBPACK_CONFIG_PATH)
|
|
18
|
+
? WEBPACK_CONFIG_PATH
|
|
19
|
+
: null;
|
|
20
|
+
|
|
21
|
+
if (!configPath) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const content = context.getFile(configPath);
|
|
26
|
+
if (!content) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return { path: configPath, content };
|
|
31
|
+
}
|
|
32
|
+
|
|
10
33
|
/**
|
|
11
34
|
* Type for a function that modifies a resolve object expression
|
|
12
35
|
* @param resolveObject - The AST node representing the resolve configuration
|