@grafana/create-plugin 3.1.1 → 3.1.2-canary.694.f97a4af.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.
@@ -133,9 +133,16 @@ async function generateFiles({ actions }) {
133
133
  });
134
134
  }
135
135
  catch (error) {
136
+ let message;
137
+ if (error instanceof Error) {
138
+ message = error.message;
139
+ }
140
+ else {
141
+ message = String(error);
142
+ }
136
143
  failures.push({
137
144
  path: action.path,
138
- error: error.message || error.toString(),
145
+ error: message,
139
146
  });
140
147
  }
141
148
  }
@@ -28,6 +28,13 @@ export const provisioning = async () => {
28
28
  }
29
29
  }
30
30
  catch (error) {
31
- printError(error);
31
+ let message;
32
+ if (error instanceof Error) {
33
+ message = error.message;
34
+ }
35
+ else {
36
+ message = String(error);
37
+ }
38
+ printError(message);
32
39
  }
33
40
  };
@@ -3,7 +3,7 @@ import { GRAFANA_FE_PACKAGES } from '../constants.js';
3
3
  import { getPackageJson, writePackageJson, getLatestPackageJson } from './utils.packagejson.js';
4
4
  export function getNpmDependencyUpdatesAsText(dependencyUpdates) {
5
5
  return Object.entries(dependencyUpdates)
6
- .filter(([packageName, { prev, next }]) => prev !== next)
6
+ .filter(([_, { prev, next }]) => prev !== next)
7
7
  .map(([packageName, { prev, next }]) => {
8
8
  if (!prev) {
9
9
  return `\`${packageName}\` - \`${next}\` (new)`;
@@ -39,7 +39,7 @@ export function updatePackageJson(options = {}) {
39
39
  export function updateNpmDependencies(dependencies, updateSummary) {
40
40
  const updatedDependencies = { ...dependencies };
41
41
  for (const [packageName, summary] of Object.entries(updateSummary)) {
42
- updatedDependencies[packageName] = summary.next;
42
+ updatedDependencies[packageName] = summary.next ?? '';
43
43
  }
44
44
  return updatedDependencies;
45
45
  }
@@ -72,12 +72,14 @@ function getPackageManagerFromLockFile() {
72
72
  }
73
73
  catch (error) {
74
74
  console.error('Failed to find package manager from lock file. Have you installed dependencies?');
75
- throw Error(error);
75
+ if (error instanceof Error) {
76
+ throw error;
77
+ }
76
78
  }
77
79
  }
78
80
  function getPackageManagerFromPackageJson() {
79
81
  const packageJson = getPackageJson();
80
- if (packageJson.hasOwnProperty('packageManager')) {
82
+ if (packageJson?.packageManager) {
81
83
  const [packageManagerName, packageManagerVersion] = packageJson.packageManager.split('@');
82
84
  return { packageManagerName, packageManagerVersion };
83
85
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/create-plugin",
3
- "version": "3.1.1",
3
+ "version": "3.1.2-canary.694.f97a4af.0",
4
4
  "repository": {
5
5
  "directory": "packages/create-plugin",
6
6
  "url": "https://github.com/grafana/plugin-tools"
@@ -36,7 +36,7 @@
36
36
  "generate-datasource-backend": "tsc && npm run clean-generated && CREATE_PLUGIN_DEV=true node ./dist/bin/run.js --pluginName='Sample datasource' --orgName='sample-org' --pluginDescription='This is a sample datasource.' --pluginType='datasource' --hasBackend --hasGithubWorkflows --hasGithubLevitateWorkflow",
37
37
  "lint": "eslint --cache --ext .js,.jsx,.ts,.tsx ./src",
38
38
  "lint:fix": "npm run lint -- --fix",
39
- "test": "vitest run",
39
+ "test": "vitest",
40
40
  "typecheck": "tsc --noEmit"
41
41
  },
42
42
  "dependencies": {
@@ -62,8 +62,7 @@
62
62
  "devDependencies": {
63
63
  "@types/glob": "^7.0.0",
64
64
  "eslint-plugin-react": "^7.26.1",
65
- "eslint-plugin-react-hooks": "^4.2.0",
66
- "vitest": "^1.1.3"
65
+ "eslint-plugin-react-hooks": "^4.2.0"
67
66
  },
68
67
  "overrides": {
69
68
  "@types/marked-terminal": {
@@ -86,5 +85,5 @@
86
85
  "engines": {
87
86
  "node": ">=20"
88
87
  },
89
- "gitHead": "44847f05e9bb2b747ed171852a8052514c25725e"
88
+ "gitHead": "f97a4af609f8d9b4fd498d88f6811f26725e4ca8"
90
89
  }
@@ -32,7 +32,7 @@ type Prompt = {
32
32
  validate?: (value: string) => boolean | string | Promise<boolean | string>;
33
33
  initial?: any;
34
34
  choices?: Array<string | Choice>;
35
- shouldPrompt?: ((state: object) => boolean | Promise<boolean>) | boolean;
35
+ shouldPrompt?: (answers: Partial<CliArgs>) => boolean;
36
36
  };
37
37
 
38
38
  type Choice = {
@@ -85,7 +85,7 @@ const prompts: Prompt[] = [
85
85
  type: 'confirm',
86
86
  message: 'Do you want a backend part of your plugin?',
87
87
  initial: false,
88
- shouldPrompt: (answers: CliArgs) => answers.pluginType !== PLUGIN_TYPES.panel,
88
+ shouldPrompt: (answers) => answers.pluginType !== PLUGIN_TYPES.panel,
89
89
  },
90
90
  {
91
91
  name: 'hasGithubWorkflows',
@@ -74,6 +74,12 @@ function getTemplateData(answers: CliArgs) {
74
74
  return templateData;
75
75
  }
76
76
 
77
+ type TemplateAction = {
78
+ templateFile: string;
79
+ path: string;
80
+ data: TemplateData;
81
+ };
82
+
77
83
  function getTemplateActions({ exportPath, templateData }: { exportPath: string; templateData: any }) {
78
84
  const commonActions = getActionsForTemplateFolder({
79
85
  folderPath: TEMPLATE_PATHS.common,
@@ -97,15 +103,18 @@ function getTemplateActions({ exportPath, templateData }: { exportPath: string;
97
103
  // Common, pluginType and backend actions can contain different templates for the same destination.
98
104
  // This filtering removes the duplicate file additions to make sure the correct template is scaffolded.
99
105
  // Note that the order is reversed so backend > pluginType > common
100
- const pluginActions = [...backendActions, ...pluginTypeSpecificActions, ...commonActions].reduce((acc, file) => {
101
- const actionExists = acc.find((f) => f.path === file.path);
102
- // return early to prevent duplicate file additions
103
- if (actionExists) {
106
+ const pluginActions = [...backendActions, ...pluginTypeSpecificActions, ...commonActions].reduce<TemplateAction[]>(
107
+ (acc, file) => {
108
+ const actionExists = acc.find((f) => f.path === file.path);
109
+ // return early to prevent duplicate file additions
110
+ if (actionExists) {
111
+ return acc;
112
+ }
113
+ acc.push(file);
104
114
  return acc;
105
- }
106
- acc.push(file);
107
- return acc;
108
- }, []);
115
+ },
116
+ []
117
+ );
109
118
 
110
119
  // Copy over Github workflow files (if selected)
111
120
  const ciWorkflowActions = templateData.hasGithubWorkflows
@@ -147,7 +156,7 @@ function getActionsForTemplateFolder({
147
156
  return path.relative(folderPath, path.dirname(f));
148
157
  }
149
158
 
150
- return files.filter(isFile).map((f) => ({
159
+ return files.filter(isFile).map<TemplateAction>((f) => ({
151
160
  templateFile: f,
152
161
  // The target path where the compiled template is saved to
153
162
  path: path.join(exportPath, getFileExportPath(f), getExportFileName(f)),
@@ -175,9 +184,15 @@ async function generateFiles({ actions }: { actions: any[] }) {
175
184
  path: action.path,
176
185
  });
177
186
  } catch (error) {
187
+ let message;
188
+ if (error instanceof Error) {
189
+ message = error.message;
190
+ } else {
191
+ message = String(error);
192
+ }
178
193
  failures.push({
179
194
  path: action.path,
180
- error: error.message || error.toString(),
195
+ error: message,
181
196
  });
182
197
  }
183
198
  }
@@ -27,6 +27,12 @@ export const provisioning = async () => {
27
27
  process.exit(1);
28
28
  }
29
29
  } catch (error) {
30
- printError(error);
30
+ let message;
31
+ if (error instanceof Error) {
32
+ message = error.message;
33
+ } else {
34
+ message = String(error);
35
+ }
36
+ printError(message);
31
37
  }
32
38
  };
@@ -23,10 +23,10 @@ export function getConfig(): CreatePluginConfig {
23
23
  return {
24
24
  ...rootConfig,
25
25
  ...userConfig,
26
- version: rootConfig.version,
26
+ version: rootConfig!.version,
27
27
  features: createFeatureFlags({
28
- ...rootConfig.features,
29
- ...userConfig.features,
28
+ ...rootConfig!.features,
29
+ ...userConfig!.features,
30
30
  }),
31
31
  };
32
32
  } catch (error) {
@@ -45,7 +45,7 @@ function getUserConfig(): UserConfig | undefined {
45
45
  return {
46
46
  ...userConfig,
47
47
  features: createFeatureFlags({
48
- ...userConfig.features,
48
+ ...userConfig!.features,
49
49
  }),
50
50
  };
51
51
  } catch (error) {
@@ -13,7 +13,7 @@ type UpdateOptions = {
13
13
 
14
14
  export function getNpmDependencyUpdatesAsText(dependencyUpdates: UpdateSummary) {
15
15
  return Object.entries(dependencyUpdates)
16
- .filter(([packageName, { prev, next }]) => prev !== next)
16
+ .filter(([_, { prev, next }]) => prev !== next)
17
17
  .map(([packageName, { prev, next }]) => {
18
18
  // New package
19
19
  if (!prev) {
@@ -59,14 +59,11 @@ export function updatePackageJson(options: UpdateOptions = {}) {
59
59
  writePackageJson(packageJson);
60
60
  }
61
61
 
62
- export function updateNpmDependencies(
63
- dependencies: Record<string, string>,
64
- updateSummary: UpdateSummary
65
- ): Record<string, string> {
66
- const updatedDependencies: Record<string, string> = { ...dependencies };
62
+ export function updateNpmDependencies(dependencies: Record<string, string>, updateSummary: UpdateSummary) {
63
+ const updatedDependencies = { ...dependencies };
67
64
 
68
65
  for (const [packageName, summary] of Object.entries(updateSummary)) {
69
- updatedDependencies[packageName] = summary.next;
66
+ updatedDependencies[packageName] = summary.next ?? '';
70
67
  }
71
68
 
72
69
  return updatedDependencies;
@@ -94,13 +94,15 @@ function getPackageManagerFromLockFile(): PackageManager | undefined {
94
94
  return undefined;
95
95
  } catch (error) {
96
96
  console.error('Failed to find package manager from lock file. Have you installed dependencies?');
97
- throw Error(error);
97
+ if (error instanceof Error) {
98
+ throw error;
99
+ }
98
100
  }
99
101
  }
100
102
 
101
103
  function getPackageManagerFromPackageJson(): PackageManager | undefined {
102
104
  const packageJson = getPackageJson();
103
- if (packageJson.hasOwnProperty('packageManager')) {
105
+ if (packageJson?.packageManager) {
104
106
  const [packageManagerName, packageManagerVersion] = packageJson.packageManager.split('@');
105
107
  return { packageManagerName, packageManagerVersion };
106
108
  }
package/tsconfig.json CHANGED
@@ -1,10 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/tsconfig",
3
3
  "compilerOptions": {
4
- "lib": ["es2023", "dom"],
5
- "module": "node16",
6
- "target": "es2022",
7
- "moduleResolution": "node16",
8
4
  "outDir": "./dist"
9
5
  },
10
6
  "exclude": ["node_modules", "templates"],
package/vitest.config.ts CHANGED
@@ -1,10 +1,12 @@
1
- import { resolve } from 'path';
2
- import { defineConfig } from 'vitest/config';
1
+ import { resolve } from 'node:path';
2
+ import { defineProject, mergeConfig } from 'vitest/config';
3
+ import configShared from '../../vitest.config.base.js';
3
4
 
4
- export default defineConfig({
5
- test: {
6
- root: resolve(__dirname),
7
- globals: true,
8
- include: ['**/*.test.ts'],
9
- },
10
- });
5
+ export default mergeConfig(
6
+ configShared,
7
+ defineProject({
8
+ test: {
9
+ root: resolve(__dirname),
10
+ },
11
+ })
12
+ );
package/jest.config.js DELETED
@@ -1,8 +0,0 @@
1
- const sharedConfig = require('../../jest.config.base');
2
- const esModules = ['change-case', 'title-case'].join('|');
3
-
4
- module.exports = {
5
- ...sharedConfig,
6
- modulePathIgnorePatterns: ['<rootDir>/templates/'],
7
- transformIgnorePatterns: [`/node_modules/(?!${esModules})`],
8
- };