@grafana/create-plugin 7.17.0 → 7.18.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 (43) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/codemods/additions/additions.js +7 -0
  3. package/dist/codemods/additions/prompts/rspack.md +118 -0
  4. package/dist/codemods/additions/scripts/docs.js +2 -2
  5. package/dist/codemods/additions/scripts/rspack.js +322 -0
  6. package/dist/codemods/agentic/prompts.js +1 -1
  7. package/dist/codemods/migrations/migrations.js +6 -0
  8. package/dist/codemods/migrations/scripts/020-rename-rspack-feature-flag.js +8 -0
  9. package/dist/codemods/utils.rspack.js +38 -0
  10. package/dist/commands/generate.command.js +1 -9
  11. package/dist/constants.js +0 -1
  12. package/dist/utils/utils.templates.js +4 -4
  13. package/package.json +1 -1
  14. package/src/codemods/additions/additions.test.ts +9 -0
  15. package/src/codemods/additions/additions.ts +7 -0
  16. package/src/codemods/additions/prompts/rspack.md +118 -0
  17. package/src/codemods/additions/scripts/docs.test.ts +4 -4
  18. package/src/codemods/additions/scripts/docs.ts +2 -2
  19. package/src/codemods/additions/scripts/rspack.test.ts +768 -0
  20. package/src/codemods/additions/scripts/rspack.ts +428 -0
  21. package/src/codemods/agentic/prompts.test.ts +11 -2
  22. package/src/codemods/agentic/prompts.ts +1 -1
  23. package/src/codemods/migrations/migrations.ts +7 -0
  24. package/src/codemods/migrations/scripts/020-rename-rspack-feature-flag.test.ts +94 -0
  25. package/src/codemods/migrations/scripts/020-rename-rspack-feature-flag.ts +8 -0
  26. package/src/codemods/utils.rspack.ts +58 -0
  27. package/src/codemods/utils.test.ts +5 -2
  28. package/src/commands/generate.command.ts +2 -10
  29. package/src/constants.ts +0 -1
  30. package/src/types.ts +1 -1
  31. package/src/utils/tests/utils.config.test.ts +10 -0
  32. package/src/utils/utils.config.ts +2 -1
  33. package/src/utils/utils.templates.ts +4 -4
  34. package/templates/common/.config/AGENTS/instructions.md +2 -2
  35. package/templates/common/.config/README.md +56 -0
  36. package/templates/common/.config/bundler/externals.ts +2 -2
  37. package/templates/common/.config/rspack/DiagnosticsRspackPlugin.ts +29 -0
  38. package/templates/common/.config/rspack/LicenseRspackPlugin.ts +43 -0
  39. package/templates/common/.config/rspack/LiveReloadRspackPlugin.ts +95 -0
  40. package/templates/common/.config/rspack/rspack.config.ts +41 -32
  41. package/templates/common/.cprc.json +1 -2
  42. package/templates/common/_package.json +18 -18
  43. package/templates/common/.config/rspack/liveReloadPlugin.ts +0 -133
@@ -1,133 +0,0 @@
1
- import path from 'path';
2
- import { Compilation, type Compiler } from '@rspack/core';
3
- import { WebSocketServer } from 'ws';
4
- import { createServer } from 'http';
5
-
6
- interface RspackLiveReloadPluginOptions {
7
- port?: number;
8
- delay?: number;
9
- appendScriptTag?: boolean;
10
- protocol?: string;
11
- }
12
-
13
- class RspackLiveReloadPlugin {
14
- options: RspackLiveReloadPluginOptions;
15
- httpServer: ReturnType<typeof createServer> | null = null;
16
- server: WebSocketServer | null = null;
17
- constructor(options = {}) {
18
- this.options = Object.assign(
19
- {
20
- port: 35729,
21
- delay: 0,
22
- appendScriptTag: true,
23
- protocol: 'http',
24
- },
25
- options
26
- );
27
- }
28
-
29
- apply(compiler: Compiler) {
30
- const isRspack = compiler.rspack !== undefined;
31
- if (!isRspack) {
32
- throw new Error('This plugin is designed to work with Rspack.');
33
- }
34
-
35
- compiler.hooks.afterEmit.tap('RspackLiveReloadPlugin', (compilation) => {
36
- this._startServer();
37
- this._notifyClient();
38
- });
39
-
40
- compiler.hooks.done.tap('RspackLiveReloadPlugin', (stats) => {
41
- if (this.options.appendScriptTag) {
42
- this._injectLiveReloadScript(stats.compilation);
43
- }
44
- });
45
- }
46
-
47
- _startServer() {
48
- if (this.server) {
49
- return;
50
- }
51
-
52
- const port = this.options.port;
53
-
54
- this.httpServer = createServer((req, res) => {
55
- if (req.url === '/livereload.js') {
56
- res.writeHead(200, { 'Content-Type': 'application/javascript' });
57
- res.end(this._getLiveReloadScript());
58
- } else {
59
- res.writeHead(404);
60
- res.end('Not Found');
61
- }
62
- });
63
-
64
- this.server = new WebSocketServer({ server: this.httpServer });
65
- this.httpServer.listen(port, () => {
66
- console.log(`LiveReload server started on http://localhost:${port}`);
67
- });
68
- }
69
-
70
- _notifyClient() {
71
- if (!this.server) {
72
- return;
73
- }
74
-
75
- this.server.clients.forEach((client) => {
76
- if (client.readyState === WebSocket.OPEN) {
77
- client.send(JSON.stringify({ action: 'reload' }));
78
- }
79
- });
80
- }
81
-
82
- _injectLiveReloadScript(compilation: Compilation) {
83
- compilation.hooks.processAssets.tap(
84
- {
85
- name: 'RspackLiveReloadPlugin',
86
- stage: Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
87
- },
88
- (assets) => {
89
- Object.keys(assets).forEach((filename) => {
90
- if (path.extname(filename) === '.html') {
91
- const assetSource = compilation.getAsset(filename)?.source;
92
- if (!assetSource) {
93
- return;
94
- }
95
-
96
- const updatedSource = assetSource
97
- .source()
98
- .toString()
99
- .replace('</body>', `<script src="http://localhost:${this.options.port}/livereload.js"></script></body>`);
100
-
101
- compilation.updateAsset(filename, {
102
- source: () => updatedSource,
103
- buffer: () => Buffer.from(updatedSource),
104
- size: () => updatedSource.length,
105
- map: () => null,
106
- sourceAndMap: () => ({ source: updatedSource, map: null }),
107
- updateHash: (hash) => {
108
- hash.update(updatedSource);
109
- },
110
- });
111
- }
112
- });
113
- }
114
- );
115
- }
116
-
117
- _getLiveReloadScript() {
118
- return `
119
- (function() {
120
- if (typeof WebSocket === 'undefined') return;
121
- const ws = new WebSocket('${this.options.protocol}://localhost:${this.options.port}');
122
- ws.onmessage = function(event) {
123
- const data = JSON.parse(event.data);
124
- if (data.action === 'reload') {
125
- window.location.reload();
126
- }
127
- };
128
- })();
129
- `;
130
- }
131
- }
132
-
133
- export default RspackLiveReloadPlugin;