@grafana/create-plugin 5.17.0 → 5.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 (55) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/CONTRIBUTING.md +117 -1
  3. package/dist/commands/update.command.js +28 -68
  4. package/dist/commands/update.migrate.command.js +27 -0
  5. package/dist/commands/update.standard.command.js +51 -0
  6. package/dist/migrations/context.js +118 -0
  7. package/dist/migrations/context.test.js +122 -0
  8. package/dist/migrations/fixtures/foo/bar.js +2 -0
  9. package/dist/migrations/fixtures/foo/baz.js +1 -0
  10. package/dist/migrations/fixtures/migrations.js +19 -0
  11. package/dist/migrations/manager.js +50 -0
  12. package/dist/migrations/manager.test.js +177 -0
  13. package/dist/migrations/migrations.js +3 -0
  14. package/dist/migrations/migrations.test.js +10 -0
  15. package/dist/migrations/scripts/example-migration.js +23 -0
  16. package/dist/migrations/scripts/example-migration.test.js +24 -0
  17. package/dist/migrations/test-utils.js +9 -0
  18. package/dist/migrations/utils.js +46 -0
  19. package/dist/migrations/utils.test.js +65 -0
  20. package/dist/utils/utils.cli.js +3 -0
  21. package/dist/utils/utils.config.js +9 -1
  22. package/dist/utils/utils.console.js +6 -0
  23. package/dist/utils/utils.git.js +13 -0
  24. package/dist/utils/utils.goSdk.js +6 -6
  25. package/dist/utils/utils.templates.js +3 -3
  26. package/package.json +6 -4
  27. package/src/commands/update.command.ts +33 -75
  28. package/src/commands/update.migrate.command.ts +31 -0
  29. package/src/commands/update.standard.command.ts +55 -0
  30. package/src/migrations/context.test.ts +148 -0
  31. package/src/migrations/context.ts +155 -0
  32. package/src/migrations/fixtures/foo/bar.ts +1 -0
  33. package/src/migrations/fixtures/foo/baz.ts +0 -0
  34. package/src/migrations/fixtures/migrations.ts +19 -0
  35. package/src/migrations/manager.test.ts +217 -0
  36. package/src/migrations/manager.ts +70 -0
  37. package/src/migrations/migrations.test.ts +12 -0
  38. package/src/migrations/migrations.ts +20 -0
  39. package/src/migrations/scripts/example-migration.test.ts +40 -0
  40. package/src/migrations/scripts/example-migration.ts +34 -0
  41. package/src/migrations/test-utils.ts +12 -0
  42. package/src/migrations/utils.test.ts +81 -0
  43. package/src/migrations/utils.ts +50 -0
  44. package/src/utils/utils.cli.ts +5 -0
  45. package/src/utils/utils.config.ts +12 -1
  46. package/src/utils/utils.console.ts +7 -0
  47. package/src/utils/utils.git.ts +14 -0
  48. package/src/utils/utils.goSdk.ts +6 -6
  49. package/src/utils/utils.templates.ts +3 -3
  50. package/templates/common/.config/docker-compose-base.yaml +1 -1
  51. package/templates/common/_package.json +4 -4
  52. package/tsconfig.json +1 -1
  53. package/vitest.config.ts +1 -0
  54. package/vitest.d.ts +11 -0
  55. package/vitest.setup.ts +53 -0
@@ -2,10 +2,10 @@ import { lt as semverLt } from 'semver';
2
2
  import { glob } from 'glob';
3
3
  import path from 'node:path';
4
4
  import fs from 'node:fs';
5
- import createDebug from 'debug';
6
5
  import { filterOutCommonFiles, isFile, isFileStartingWith } from './utils.files.js';
7
6
  import { normalizeId, renderHandlebarsTemplate } from './utils.handlebars.js';
8
7
  import { getPluginJson } from './utils.plugin.js';
8
+ import { debug } from './utils.cli.js';
9
9
  import {
10
10
  TEMPLATE_PATHS,
11
11
  EXPORT_PATH_PREFIX,
@@ -23,7 +23,7 @@ import { getExportFileName } from '../utils/utils.files.js';
23
23
  import { getGrafanaRuntimeVersion, getVersion } from './utils.version.js';
24
24
  import { getConfig } from './utils.config.js';
25
25
 
26
- const debug = createDebug('create-plugin:templates');
26
+ const templatesDebugger = debug.extend('templates');
27
27
 
28
28
  /**
29
29
  *
@@ -161,7 +161,7 @@ export function getTemplateData(cliArgs?: GenerateCliArgs): TemplateData {
161
161
  };
162
162
  }
163
163
 
164
- debug('\nTemplate data:\n' + JSON.stringify(templateData, null, 2));
164
+ templatesDebugger('\nTemplate data:\n' + JSON.stringify(templateData, null, 2));
165
165
 
166
166
  return templateData;
167
167
  }
@@ -7,7 +7,7 @@ services:
7
7
  context: .
8
8
  args:
9
9
  grafana_image: ${GRAFANA_IMAGE:-{{~grafanaImage~}} }
10
- grafana_version: ${GRAFANA_VERSION:-11.5.1}
10
+ grafana_version: ${GRAFANA_VERSION:-11.5.2}
11
11
  development: ${DEVELOPMENT:-false}
12
12
  anonymous_auth_enabled: ${ANONYMOUS_AUTH_ENABLED:-true}
13
13
  ports:
@@ -72,10 +72,10 @@
72
72
  },
73
73
  "dependencies": {
74
74
  "@emotion/css": "11.10.6",
75
- "@grafana/data": "^11.5.1",
76
- "@grafana/runtime": "^11.5.1",
77
- "@grafana/ui": "^11.5.1",
78
- "@grafana/schema": "^11.5.1",{{#if_eq pluginType "scenesapp"}}
75
+ "@grafana/data": "^11.5.2",
76
+ "@grafana/runtime": "^11.5.2",
77
+ "@grafana/ui": "^11.5.2",
78
+ "@grafana/schema": "^11.5.2",{{#if_eq pluginType "scenesapp"}}
79
79
  "@grafana/scenes": "^5.41.3",{{/if_eq}}
80
80
  "react": "18.2.0",
81
81
  "react-dom": "18.2.0"{{#if isAppType}},
package/tsconfig.json CHANGED
@@ -5,5 +5,5 @@
5
5
  },
6
6
  "exclude": ["node_modules", "templates"],
7
7
  "extends": "../../tsconfig.base.json",
8
- "include": ["src"]
8
+ "include": ["src", "vitest.d.ts"]
9
9
  }
package/vitest.config.ts CHANGED
@@ -7,6 +7,7 @@ export default mergeConfig(
7
7
  defineProject({
8
8
  test: {
9
9
  root: resolve(__dirname),
10
+ setupFiles: ['./vitest.setup.ts'],
10
11
  },
11
12
  })
12
13
  );
package/vitest.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import 'vitest';
2
+ import { Context } from './src/migrations/context';
3
+
4
+ interface CustomMatchers<R = unknown> {
5
+ toBeIdempotent(context: Context): Promise<void>;
6
+ }
7
+
8
+ declare module 'vitest' {
9
+ interface Assertion<T = any> extends CustomMatchers<T> {}
10
+ interface AsymmetricMatchersContaining extends CustomMatchers {}
11
+ }
@@ -0,0 +1,53 @@
1
+ import { expect } from 'vitest';
2
+ import type { Context } from './src/migrations/context';
3
+ import { inspect } from 'node:util';
4
+
5
+ type ClonedContext = {
6
+ files: Record<string, { content: string; changeType: 'add' | 'update' | 'delete' }>;
7
+ };
8
+
9
+ async function compareContexts(firstRun: ClonedContext, secondRun: ClonedContext) {
10
+ for (const file of Object.keys(firstRun.files)) {
11
+ const firstRunContent = firstRun.files[file].content;
12
+ const secondRunContent = secondRun.files[file].content;
13
+ if (firstRunContent !== secondRunContent) {
14
+ return {
15
+ pass: false,
16
+ file,
17
+ firstRunContent,
18
+ secondRunContent,
19
+ };
20
+ }
21
+ }
22
+
23
+ return { pass: true };
24
+ }
25
+
26
+ const parseContent = (content?: string) => (content ? JSON.parse(content) : '');
27
+
28
+ expect.extend({
29
+ async toBeIdempotent(migrate: (context: Context) => Promise<Context>, context: Context) {
30
+ const firstRun = await migrate(context);
31
+ const firstRunDeepCopy = structuredClone(firstRun) as unknown as ClonedContext;
32
+
33
+ const secondRun = await migrate(firstRun);
34
+ const secondRunDeepCopy = structuredClone(secondRun) as unknown as ClonedContext;
35
+
36
+ const result = await compareContexts(firstRunDeepCopy, secondRunDeepCopy);
37
+
38
+ if (result.pass) {
39
+ return {
40
+ pass: true,
41
+ message: () => 'Expected migration not to be idempotent',
42
+ };
43
+ }
44
+
45
+ return {
46
+ pass: false,
47
+ message: () =>
48
+ `Migration is not idempotent. File ${result.file} changed on second run.\n` +
49
+ `First run content: ${inspect(parseContent(result.firstRunContent), { colors: true })}\n` +
50
+ `Second run content: ${inspect(parseContent(result.secondRunContent), { colors: true })}`,
51
+ };
52
+ },
53
+ });