mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Plugins: Angular: Update hardcoded Angular detection patterns (#70053)
* Plugins: Angular: add ConfigCtrl to Angular patterns * Update angular detection patterns * Add tests
This commit is contained in:
parent
7b9e047ffd
commit
5622f2f43a
@ -22,6 +22,8 @@ func TestAngularDetector_Inspect(t *testing.T) {
|
||||
[]byte(`define(["app/plugins/sdk"],(function(n){return function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof`),
|
||||
[]byte(`define(["app/plugins/sdk"],(function(n){return function(n){var t={};function e(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return n[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}return e.m=n,e.c=t,e.d=function(n,t,r){e.o(n,t)||Object.defineProperty(n,t,{enumerable:!0,get:r})},e.r=function(n){"undefined"!=typeof Symbol&&Symbol.toSt`),
|
||||
[]byte(`define(["react","lodash","@grafana/data","@grafana/ui","@emotion/css","@grafana/runtime","moment","app/core/utils/datemath","jquery","app/plugins/sdk","app/core/core_module","app/core/core","app/core/table_model","app/core/utils/kbn","app/core/config","angular"],(function(e,t,r,n,i,a,o,s,u,l,c,p,f,h,d,m){return function(e){var t={};function r(n){if(t[n])return t[n].exports;var i=t[n]={i:n,l:!1,exports:{}};retur`),
|
||||
[]byte(`exports_1("QueryCtrl", query_ctrl_1.PluginQueryCtrl);`),
|
||||
[]byte(`exports_1('QueryCtrl', query_ctrl_1.PluginQueryCtrl);`),
|
||||
} {
|
||||
tcs = append(tcs, tc{
|
||||
name: "angular " + strconv.Itoa(i),
|
||||
@ -34,16 +36,22 @@ func TestAngularDetector_Inspect(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
// Not angular
|
||||
tcs = append(tcs, tc{
|
||||
name: "not angular",
|
||||
plugin: &plugins.Plugin{
|
||||
FS: plugins.NewInMemoryFS(map[string][]byte{
|
||||
"module.js": []byte(`import { PanelPlugin } from '@grafana/data'`),
|
||||
}),
|
||||
},
|
||||
exp: false,
|
||||
})
|
||||
// Not angular (test against possible false detections)
|
||||
for i, content := range [][]byte{
|
||||
[]byte(`import { PanelPlugin } from '@grafana/data'`),
|
||||
// React ML app
|
||||
[]byte(`==(null===(t=e.components)||void 0===t?void 0:t.QueryCtrl)};function`),
|
||||
} {
|
||||
tcs = append(tcs, tc{
|
||||
name: "not angular " + strconv.Itoa(i),
|
||||
plugin: &plugins.Plugin{
|
||||
FS: plugins.NewInMemoryFS(map[string][]byte{
|
||||
"module.js": content,
|
||||
}),
|
||||
},
|
||||
exp: false,
|
||||
})
|
||||
}
|
||||
inspector := NewDefaultPatternsListInspector()
|
||||
for _, tc := range tcs {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
@ -12,16 +12,14 @@ import (
|
||||
// They are executed in the specified order.
|
||||
var defaultDetectors = []detector{
|
||||
&containsBytesDetector{pattern: []byte("PanelCtrl")},
|
||||
&containsBytesDetector{pattern: []byte("QueryCtrl")},
|
||||
&containsBytesDetector{pattern: []byte("ConfigCtrl")},
|
||||
&containsBytesDetector{pattern: []byte("app/plugins/sdk")},
|
||||
&containsBytesDetector{pattern: []byte("angular.isNumber(")},
|
||||
&containsBytesDetector{pattern: []byte("editor.html")},
|
||||
&containsBytesDetector{pattern: []byte("ctrl.annotation")},
|
||||
&containsBytesDetector{pattern: []byte("getLegacyAngularInjector")},
|
||||
|
||||
®exDetector{regex: regexp.MustCompile(`['"](app/core/utils/promiseToDigest)|(app/plugins/.*?)|(app/core/core_module)['"]`)},
|
||||
®exDetector{regex: regexp.MustCompile(`from\s+['"]grafana\/app\/`)},
|
||||
®exDetector{regex: regexp.MustCompile(`System\.register\(`)},
|
||||
®exDetector{regex: regexp.MustCompile(`["']QueryCtrl["']`)},
|
||||
}
|
||||
|
||||
// PatternsListInspector matches module.js against all the specified patterns, in sequence.
|
||||
|
Loading…
Reference in New Issue
Block a user