File tree Expand file tree Collapse file tree 4 files changed +48
-0
lines changed
Expand file tree Collapse file tree 4 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -41,3 +41,4 @@ export * as openBrowser from './src/openBrowser';
4141export * as Env from './src/Env' ;
4242export * as validateSchema from './src/validateSchema' ;
4343export * as loadFile from './src/loadFile' ;
44+ export * as pluginResolution from './src/pluginResolution' ;
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ const internal = [
2424 'openBrowser' ,
2525 'Env' ,
2626 'validateSchema' ,
27+ 'pluginResolution' ,
2728] . reduce ( ( obj , key ) => {
2829 obj [ key ] = `./src/${ key } ` ;
2930 return obj ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const pluginRE = / ^ ( @ m i c r o - a p p \/ | m i c r o a p p - | @ [ \w - ] + ( \. ) ? [ \w - ] + \/ m i c r o a p p - ) p l u g i n - / ;
4+ const officialRE = / ^ @ m i c r o - a p p \/ / ;
5+
6+ exports . isPlugin = id => pluginRE . test ( id ) ;
7+
8+ exports . isOfficialPlugin = id => exports . isPlugin ( id ) && officialRE . test ( id ) ;
9+
10+ exports . getPluginLink = id => {
11+ let pkg = { } ;
12+ try {
13+ pkg = require ( `${ id } /package.json` ) ;
14+ } catch ( e ) { /* nothing */ }
15+ return (
16+ pkg . homepage ||
17+ ( pkg . repository && pkg . repository . url ) ||
18+ `https://www.npmjs.com/package/${ id . replace ( '/' , '%2F' ) } `
19+ ) ;
20+ } ;
Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ /* global expect */
4+
5+ const { pluginResolution } = require ( '../..' ) ;
6+
7+ describe ( 'pluginResolution' , ( ) => {
8+
9+ it ( 'isPlugin' , ( ) => {
10+ const pname = 'microapp-plugin-abc' ;
11+ expect ( pluginResolution . isPlugin ( pname ) ) . toBeTruthy ( ) ;
12+ expect ( pluginResolution . isOfficialPlugin ( pname ) ) . toBeFalsy ( ) ;
13+ } ) ;
14+
15+ it ( 'isOfficialPlugin' , ( ) => {
16+ const pname = '@micro-app/plugin-abc' ;
17+ expect ( pluginResolution . isPlugin ( pname ) ) . toBeTruthy ( ) ;
18+ expect ( pluginResolution . isOfficialPlugin ( pname ) ) . toBeTruthy ( ) ;
19+ } ) ;
20+
21+ it ( 'getPluginLink' , ( ) => {
22+ const pname = 'microapp-plugin-abc' ;
23+ expect ( pluginResolution . getPluginLink ( pname ) ) . toEqual ( `https://www.npmjs.com/package/${ pname . replace ( '/' , '%2F' ) } ` ) ;
24+ } ) ;
25+
26+ } ) ;
You can’t perform that action at this time.
0 commit comments