@grafana/create-plugin 4.15.0-canary.984.dbba404.0 → 4.15.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ # v4.15.0 (Thu Jul 04 2024)
2
+
3
+ #### 🚀 Enhancement
4
+
5
+ - Create Plugin: Dynamic webpack publicPath [#966](https://github.com/grafana/plugin-tools/pull/966) ([@jackw](https://github.com/jackw))
6
+
7
+ #### Authors: 1
8
+
9
+ - Jack Westbrook ([@jackw](https://github.com/jackw))
10
+
11
+ ---
12
+
13
+ # v4.14.1 (Thu Jul 04 2024)
14
+
15
+ #### 🐛 Bug Fix
16
+
17
+ - Create Plugin: Fix backend dev env for arm64 hosts [#990](https://github.com/grafana/plugin-tools/pull/990) ([@jackw](https://github.com/jackw))
18
+
19
+ #### Authors: 1
20
+
21
+ - Jack Westbrook ([@jackw](https://github.com/jackw))
22
+
23
+ ---
24
+
1
25
  # v4.14.0 (Mon Jul 01 2024)
2
26
 
3
27
  #### 🚀 Enhancement
@@ -11,7 +11,7 @@ export function printGenerateSuccessMessage(answers) {
11
11
  `- \`${packageManagerName} run dev\` to build (and watch) the plugin frontend code.`,
12
12
  ...(answers.hasBackend
13
13
  ? [
14
- '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
14
+ '- `mage -v build:backend` to build the plugin backend code. Rerun this command every time you edit your backend files.',
15
15
  ]
16
16
  : []),
17
17
  '- `docker-compose up` to start a grafana development server.',
@@ -8,7 +8,6 @@ import { DEFAULT_FEATURE_FLAGS } from '../../constants.js';
8
8
  const mocks = vi.hoisted(() => {
9
9
  return {
10
10
  commandName: 'generate',
11
- argv: {},
12
11
  };
13
12
  });
14
13
  vi.mock('../utils.cli.js', async () => mocks);
@@ -21,7 +20,6 @@ describe('getConfig', () => {
21
20
  describe('Command: Generate', () => {
22
21
  beforeEach(() => {
23
22
  mocks.commandName = 'generate';
24
- mocks.argv = {};
25
23
  });
26
24
  it('should give back a default config', async () => {
27
25
  const config = getConfig(tmpDir);
@@ -30,17 +28,6 @@ describe('getConfig', () => {
30
28
  features: DEFAULT_FEATURE_FLAGS,
31
29
  });
32
30
  });
33
- it('should override default feature flags via cli args', async () => {
34
- mocks.argv = {
35
- useReactRouterV6: false,
36
- bundleGrafanaUI: true,
37
- };
38
- const config = getConfig(tmpDir);
39
- expect(config).toEqual({
40
- version: getVersion(),
41
- features: { ...DEFAULT_FEATURE_FLAGS, ...mocks.argv },
42
- });
43
- });
44
31
  });
45
32
  describe('Command: Update', () => {
46
33
  beforeEach(() => {
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { getVersion } from './utils.version.js';
4
- import { argv, commandName } from './utils.cli.js';
4
+ import { commandName } from './utils.cli.js';
5
5
  import { DEFAULT_FEATURE_FLAGS } from '../constants.js';
6
6
  export function getConfig(workDir = process.cwd()) {
7
7
  const rootConfig = getRootConfig(workDir);
@@ -59,15 +59,7 @@ function readRCFileSync(path) {
59
59
  }
60
60
  function createFeatureFlags(flags) {
61
61
  if (commandName === 'generate') {
62
- const flags = Object.entries(DEFAULT_FEATURE_FLAGS).reduce((acc, [flag, value]) => {
63
- if (argv.hasOwnProperty(flag)) {
64
- return { ...acc, [flag]: argv[flag] };
65
- }
66
- else {
67
- return { ...acc, [flag]: value };
68
- }
69
- }, {});
70
- return flags;
62
+ return DEFAULT_FEATURE_FLAGS;
71
63
  }
72
64
  return flags ?? {};
73
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "4.15.0-canary.984.dbba404.0",
3
+ "version": "4.15.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -87,5 +87,5 @@
87
87
  "engines": {
88
88
  "node": ">=20"
89
89
  },
90
- "gitHead": "dbba404bbb705c8daf675fa82e19a3e197728bd6"
90
+ "gitHead": "10a4a8648f2f2794df271011c3bd062d47e323d6"
91
91
  }
@@ -13,7 +13,7 @@ export function printGenerateSuccessMessage(answers: TemplateData) {
13
13
  `- \`${packageManagerName} run dev\` to build (and watch) the plugin frontend code.`,
14
14
  ...(answers.hasBackend
15
15
  ? [
16
- '- `mage -v build:linux` to build the plugin backend code. Rerun this command every time you edit your backend files.',
16
+ '- `mage -v build:backend` to build the plugin backend code. Rerun this command every time you edit your backend files.',
17
17
  ]
18
18
  : []),
19
19
  '- `docker-compose up` to start a grafana development server.',
@@ -9,7 +9,6 @@ import { DEFAULT_FEATURE_FLAGS } from '../../constants.js';
9
9
  const mocks = vi.hoisted(() => {
10
10
  return {
11
11
  commandName: 'generate',
12
- argv: {},
13
12
  };
14
13
  });
15
14
 
@@ -26,7 +25,6 @@ describe('getConfig', () => {
26
25
  describe('Command: Generate', () => {
27
26
  beforeEach(() => {
28
27
  mocks.commandName = 'generate';
29
- mocks.argv = {};
30
28
  });
31
29
 
32
30
  it('should give back a default config', async () => {
@@ -37,19 +35,6 @@ describe('getConfig', () => {
37
35
  features: DEFAULT_FEATURE_FLAGS,
38
36
  });
39
37
  });
40
-
41
- it('should override default feature flags via cli args', async () => {
42
- mocks.argv = {
43
- useReactRouterV6: false,
44
- bundleGrafanaUI: true,
45
- };
46
- const config = getConfig(tmpDir);
47
-
48
- expect(config).toEqual({
49
- version: getVersion(),
50
- features: { ...DEFAULT_FEATURE_FLAGS, ...mocks.argv },
51
- });
52
- });
53
38
  });
54
39
 
55
40
  describe('Command: Update', () => {
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs';
2
2
  import path from 'node:path';
3
3
  import { getVersion } from './utils.version.js';
4
- import { argv, commandName } from './utils.cli.js';
4
+ import { commandName } from './utils.cli.js';
5
5
  import { DEFAULT_FEATURE_FLAGS } from '../constants.js';
6
6
 
7
7
  export type FeatureFlags = {
@@ -84,17 +84,9 @@ function readRCFileSync(path: string): CreatePluginConfig | undefined {
84
84
  }
85
85
 
86
86
  function createFeatureFlags(flags?: FeatureFlags): FeatureFlags {
87
- // For new scaffolds override any defaults with args passed in the CLI.
87
+ // Default values for new scaffoldings
88
88
  if (commandName === 'generate') {
89
- const flags = Object.entries(DEFAULT_FEATURE_FLAGS).reduce((acc, [flag, value]) => {
90
- if (argv.hasOwnProperty(flag)) {
91
- return { ...acc, [flag]: argv[flag] };
92
- } else {
93
- return { ...acc, [flag]: value };
94
- }
95
- }, {} as FeatureFlags);
96
-
97
- return flags;
89
+ return DEFAULT_FEATURE_FLAGS;
98
90
  }
99
91
 
100
92
  return flags ?? {};
@@ -4,10 +4,11 @@ ARG grafana_image=grafana-enterprise
4
4
  FROM grafana/${grafana_image}:${grafana_version}
5
5
 
6
6
  ARG development=false
7
+ ARG TARGETARCH
7
8
 
8
9
  {{#if hasBackend}}
9
10
  ARG GO_VERSION=1.21.6
10
- ARG GO_ARCH=amd64
11
+ ARG GO_ARCH=${TARGETARCH:-amd64}
11
12
  {{/if}}
12
13
 
13
14
  ENV DEV "${development}"
@@ -0,0 +1,17 @@
1
+ /*
2
+ * ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️
3
+ *
4
+ * This file dynamically sets the public path at runtime based on the location of the plugin's AMD module.
5
+ * It relies on the magic `module` which is defined by the AMD loader.
6
+ * https://github.com/requirejs/requirejs/wiki/Differences-between-the-simplified-CommonJS-wrapper-and-standard-AMD-define#module
7
+ *
8
+ * We fallback to the plugin root so that older versions of Grafana will continue to load the plugin correctly.
9
+ */
10
+
11
+ // @ts-nocheck
12
+ import amdMetaModule from 'amd-module';
13
+
14
+ __webpack_public_path__ =
15
+ amdMetaModule && amdMetaModule.uri
16
+ ? amdMetaModule.uri.slice(0, amdMetaModule.uri.lastIndexOf('/') + 1)
17
+ : 'public/plugins/{{ pluginId }}/';
@@ -36,6 +36,8 @@ const config = async (env): Promise<Configuration> => {
36
36
  entry: await getEntries(),
37
37
 
38
38
  externals: [
39
+ // Required for dynamic publicPath resolution
40
+ { 'amd-module': 'module' },
39
41
  'lodash',
40
42
  'jquery',
41
43
  'moment',
@@ -104,6 +106,17 @@ const config = async (env): Promise<Configuration> => {
104
106
  },
105
107
  },
106
108
  },
109
+ {
110
+ test: /src\/(?:.*\/)?module\.tsx?$/,
111
+ use: [
112
+ {
113
+ loader: 'imports-loader',
114
+ options: {
115
+ imports: `side-effects ${path.join(__dirname, 'publicPath.ts')}`,
116
+ },
117
+ },
118
+ ],
119
+ },
107
120
  {
108
121
  test: /\.css$/,
109
122
  use: ['style-loader', 'css-loader'],
@@ -116,9 +129,6 @@ const config = async (env): Promise<Configuration> => {
116
129
  test: /\.(png|jpe?g|gif|svg)$/,
117
130
  type: 'asset/resource',
118
131
  generator: {
119
- // Keep publicPath relative for host.com/grafana/ deployments
120
- publicPath: `public/plugins/${pluginJson.id}/img/`,
121
- outputPath: 'img/',
122
132
  filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
123
133
  },
124
134
  },
@@ -126,10 +136,7 @@ const config = async (env): Promise<Configuration> => {
126
136
  test: /\.(woff|woff2|eot|ttf|otf)(\?v=\d+\.\d+\.\d+)?$/,
127
137
  type: 'asset/resource',
128
138
  generator: {
129
- // Keep publicPath relative for host.com/grafana/ deployments
130
- publicPath: `public/plugins/${pluginJson.id}/fonts/`,
131
- outputPath: 'fonts/',
132
- filename: Boolean(env.production) ? '[hash][ext]' : '[name][ext]',
139
+ filename: Boolean(env.production) ? '[hash][ext]' : '[file]',
133
140
  },
134
141
  },
135
142
  ],
@@ -43,6 +43,7 @@
43
43
  "fork-ts-checker-webpack-plugin": "^8.0.0",
44
44
  "glob": "^10.2.7",
45
45
  "identity-obj-proxy": "3.0.0",
46
+ "imports-loader": "^5.0.0",
46
47
  "jest": "^29.5.0",
47
48
  "jest-environment-jsdom": "^29.5.0",
48
49
  "prettier": "^2.8.7",
@@ -3,7 +3,6 @@ services:
3
3
  user: root
4
4
  container_name: '{{ pluginId }}'
5
5
 
6
- platform: 'linux/amd64'
7
6
  build:
8
7
  context: ./.config
9
8
  args: