-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to Plugin Tools 1.5.0 (#171)
- Loading branch information
1 parent
12707c3
commit e7a1400
Showing
21 changed files
with
2,078 additions
and
3,139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in | ||
* https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-eslint-config | ||
*/ | ||
{ | ||
"extends": ["@grafana/eslint-config"], | ||
"root": true, | ||
"rules": { | ||
"react/prop-types": "off" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in .config/README.md | ||
*/ | ||
|
||
module.exports = { | ||
"endOfLine": "auto", | ||
"printWidth": 120, | ||
"trailingComma": "es5", | ||
"semi": true, | ||
"jsxSingleQuote": false, | ||
"singleQuote": true, | ||
"useTabs": false, | ||
"tabWidth": 2 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in | ||
* https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-jest-config | ||
*/ | ||
|
||
import '@testing-library/jest-dom'; | ||
|
||
// https://jestjs.io/docs/manual-mocks#mocking-methods-which-are-not-implemented-in-jsdom | ||
Object.defineProperty(global, 'matchMedia', { | ||
writable: true, | ||
value: jest.fn().mockImplementation((query) => ({ | ||
matches: false, | ||
media: query, | ||
onchange: null, | ||
addListener: jest.fn(), // deprecated | ||
removeListener: jest.fn(), // deprecated | ||
addEventListener: jest.fn(), | ||
removeEventListener: jest.fn(), | ||
dispatchEvent: jest.fn(), | ||
})), | ||
}); | ||
|
||
HTMLCanvasElement.prototype.getContext = () => {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in | ||
* https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-jest-config | ||
*/ | ||
|
||
const path = require('path'); | ||
const { grafanaESModules, nodeModulesToTransform } = require('./jest/utils'); | ||
|
||
module.exports = { | ||
moduleNameMapper: { | ||
'\\.(css|scss|sass)$': 'identity-obj-proxy', | ||
'react-inlinesvg': path.resolve(__dirname, 'jest', 'mocks', 'react-inlinesvg.tsx'), | ||
}, | ||
modulePaths: ['<rootDir>/src'], | ||
setupFilesAfterEnv: ['<rootDir>/jest-setup.js'], | ||
testEnvironment: 'jest-environment-jsdom', | ||
testMatch: [ | ||
'<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', | ||
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}', | ||
'<rootDir>/src/**/*.{spec,test,jest}.{js,jsx,ts,tsx}', | ||
], | ||
transform: { | ||
'^.+\\.(t|j)sx?$': [ | ||
'@swc/jest', | ||
{ | ||
sourceMaps: true, | ||
jsc: { | ||
parser: { | ||
syntax: 'typescript', | ||
tsx: true, | ||
decorators: false, | ||
dynamicImport: true, | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
// Jest will throw `Cannot use import statement outside module` if it tries to load an | ||
// ES module without it being transformed first. ./config/README.md#esm-errors-with-jest | ||
transformIgnorePatterns: [nodeModulesToTransform(grafanaESModules)], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Due to the grafana/ui Icon component making fetch requests to | ||
// `/public/img/icon/<icon_name>.svg` we need to mock react-inlinesvg to prevent | ||
// the failed fetch requests from displaying errors in console. | ||
|
||
import React from 'react'; | ||
|
||
type Callback = (...args: any[]) => void; | ||
|
||
export interface StorageItem { | ||
content: string; | ||
queue: Callback[]; | ||
status: string; | ||
} | ||
|
||
export const cacheStore: { [key: string]: StorageItem } = Object.create(null); | ||
|
||
const SVG_FILE_NAME_REGEX = /(.+)\/(.+)\.svg$/; | ||
|
||
const InlineSVG = ({ src }: { src: string }) => { | ||
// testId will be the file name without extension (e.g. `public/img/icons/angle-double-down.svg` -> `angle-double-down`) | ||
const testId = src.replace(SVG_FILE_NAME_REGEX, '$2'); | ||
return <svg xmlns="http://www.w3.org/2000/svg" data-testid={testId} viewBox="0 0 24 24" />; | ||
}; | ||
|
||
export default InlineSVG; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in .config/README.md | ||
*/ | ||
|
||
/* | ||
* This utility function is useful in combination with jest `transformIgnorePatterns` config | ||
* to transform specific packages (e.g.ES modules) in a projects node_modules folder. | ||
*/ | ||
const nodeModulesToTransform = (moduleNames) => `node_modules\/(?!(${moduleNames.join('|')})\/)`; | ||
|
||
// Array of known nested grafana package dependencies that only bundle an ESM version | ||
const grafanaESModules = [ | ||
'.pnpm', // Support using pnpm symlinked packages | ||
'd3', | ||
'd3-color', | ||
'd3-force', | ||
'd3-interpolate', | ||
'd3-scale-chromatic', | ||
'ol', | ||
'react-colorful', | ||
'uuid', | ||
]; | ||
|
||
module.exports = { | ||
nodeModulesToTransform, | ||
grafanaESModules | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* ⚠️⚠️⚠️ THIS FILE WAS SCAFFOLDED BY `@grafana/create-plugin`. DO NOT EDIT THIS FILE DIRECTLY. ⚠️⚠️⚠️ | ||
* | ||
* In order to extend the configuration follow the steps in | ||
* https://grafana.github.io/plugin-tools/docs/advanced-configuration#extending-the-typescript-config | ||
*/ | ||
{ | ||
"compilerOptions": { | ||
"alwaysStrict": true, | ||
"declaration": false, | ||
"rootDir": "../src", | ||
"baseUrl": "../src", | ||
"typeRoots": ["../node_modules/@types"], | ||
"resolveJsonModule": true | ||
}, | ||
"ts-node": { | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"esModuleInterop": true | ||
}, | ||
"transpileOnly": true | ||
}, | ||
"include": ["../src", "./types"], | ||
"extends": "@grafana/tsconfig" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Image declarations | ||
declare module '*.gif' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.jpeg' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.png' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.webp' { | ||
const src: string; | ||
export default src; | ||
} | ||
|
||
declare module '*.svg' { | ||
const content: string; | ||
export default content; | ||
} | ||
|
||
// Font declarations | ||
declare module '*.woff'; | ||
declare module '*.woff2'; | ||
declare module '*.eot'; | ||
declare module '*.ttf'; | ||
declare module '*.otf'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const SOURCE_DIR = 'src'; | ||
export const DIST_DIR = 'dist'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import util from 'util'; | ||
import { glob } from 'glob'; | ||
import { SOURCE_DIR } from './constants'; | ||
|
||
export function getPackageJson() { | ||
return require(path.resolve(process.cwd(), 'package.json')); | ||
} | ||
|
||
export function getPluginJson() { | ||
return require(path.resolve(process.cwd(), `${SOURCE_DIR}/plugin.json`)); | ||
} | ||
|
||
export function hasReadme() { | ||
return fs.existsSync(path.resolve(process.cwd(), SOURCE_DIR, 'README.md')); | ||
} | ||
|
||
// Support bundling nested plugins by finding all plugin.json files in src directory | ||
// then checking for a sibling module.[jt]sx? file. | ||
export async function getEntries(): Promise<Record<string, string>> { | ||
const pluginsJson = await glob('**/src/**/plugin.json', { absolute: true }); | ||
|
||
const plugins = await Promise.all(pluginsJson.map((pluginJson) => { | ||
const folder = path.dirname(pluginJson); | ||
return glob(`${folder}/module.{ts,tsx,js,jsx}`, { absolute: true }); | ||
}) | ||
); | ||
|
||
return plugins.reduce((result, modules) => { | ||
return modules.reduce((result, module) => { | ||
const pluginPath = path.dirname(module); | ||
const pluginName = path.relative(process.cwd(), pluginPath).replace(/src\/?/i, ''); | ||
const entryName = pluginName === '' ? 'module' : `${pluginName}/module`; | ||
|
||
result[entryName] = module; | ||
return result; | ||
}, result); | ||
}, {}); | ||
} |
Oops, something went wrong.