Skip to content

Commit db35faa

Browse files
authored
Show plugin (name and version) loaded (vercel#1826)
* Print plugin name and version in devtools * Add plugins informations in About dialog
1 parent 5ec7050 commit db35faa

File tree

6 files changed

+61
-18
lines changed

6 files changed

+61
-18
lines changed

app/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,8 +405,9 @@ app.on('ready', () => installDevExtensions(isDev).then(() => {
405405
const menu = plugins.decorateMenu(
406406
AppMenu(createWindow, () => {
407407
plugins.updatePlugins({force: true});
408-
})
409-
);
408+
},
409+
plugins.getLoadedPluginVersions
410+
));
410411

411412
// If we're on Mac make a Dock Menu
412413
if (process.platform === 'darwin') {

app/menus/menu.js

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
const {app, dialog} = require('electron');
2+
13
const {getKeymaps} = require('../config');
4+
const {icon} = require('../config/paths');
25

36
// menus
47
const viewMenu = require('./menus/view');
@@ -9,16 +12,32 @@ const windowMenu = require('./menus/window');
912
const helpMenu = require('./menus/help');
1013
const darwinMenu = require('./menus/darwin');
1114

12-
module.exports = (createWindow, updatePlugins) => {
15+
const appName = app.getName();
16+
const appVersion = app.getVersion();
17+
18+
module.exports = (createWindow, updatePlugins, getLoadedPluginVersions) => {
1319
const commands = getKeymaps().commands;
20+
const showAbout = () => {
21+
const loadedPlugins = getLoadedPluginVersions();
22+
const pluginList = loadedPlugins.length === 0 ?
23+
'none' :
24+
loadedPlugins.map(plugin => `\n ${plugin.name} (${plugin.version})`);
25+
dialog.showMessageBox({
26+
title: `About ${appName}`,
27+
message: `${appName} ${appVersion}`,
28+
detail: `Plugins: ${pluginList}\n\nCreated by Guillermo Rauch\nCopyright © 2017 Zeit, Inc.`,
29+
buttons: [],
30+
icon
31+
});
32+
};
1433
const menu = [
15-
...(process.platform === 'darwin' ? [darwinMenu(commands)] : []),
34+
...(process.platform === 'darwin' ? [darwinMenu(commands, showAbout)] : []),
1635
shellMenu(commands, createWindow),
1736
editMenu(commands),
1837
viewMenu(commands),
1938
pluginsMenu(commands, updatePlugins),
2039
windowMenu(commands),
21-
helpMenu(commands)
40+
helpMenu(commands, showAbout)
2241
];
2342

2443
return menu;

app/menus/menus/darwin.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
const {app} = require('electron');
44
const {openConfig} = require('../../config');
55

6-
module.exports = function (commands) {
6+
module.exports = function (commands, showAbout) {
77
return {
88
label: `${app.getName()}`,
99
submenu: [
1010
{
11-
role: 'about'
11+
label: 'About Hyper',
12+
click() {
13+
showAbout();
14+
}
1215
},
1316
{
1417
type: 'separator'

app/menus/menus/help.js

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
const os = require('os');
2-
const {app, shell, dialog} = require('electron');
3-
const {icon} = require('../../config/paths');
2+
const {app, shell} = require('electron');
43

5-
module.exports = function () {
4+
module.exports = function (commands, showAbout) {
65
const submenu = [
76
{
87
label: `${app.getName()} Website`,
@@ -31,13 +30,7 @@ module.exports = function () {
3130
{
3231
role: 'about',
3332
click() {
34-
dialog.showMessageBox({
35-
title: `About ${app.getName()}`,
36-
message: `${app.getName()} ${app.getVersion()}`,
37-
detail: 'Created by Guillermo Rauch',
38-
icon,
39-
buttons: []
40-
});
33+
showAbout();
4134
}
4235
}
4336
);

app/plugins.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ function clearCache() {
161161

162162
exports.updatePlugins = updatePlugins;
163163

164+
exports.getLoadedPluginVersions = function () {
165+
return modules.map(mod => ({name: mod._name, version: mod._version}));
166+
};
167+
164168
// we schedule the initial plugins update
165169
// a bit after the user launches the terminal
166170
// to prevent slowness
@@ -309,6 +313,13 @@ function requirePlugins() {
309313

310314
// populate the name for internal errors here
311315
mod._name = basename(path);
316+
try {
317+
// eslint-disable-next-line import/no-dynamic-require
318+
mod._version = require(resolve(path, 'package.json')).version;
319+
} catch (err) {
320+
console.warn(`No package.json found in ${path}`);
321+
}
322+
console.log(`Plugin ${mod._name} (${mod._version}) loaded.`);
312323

313324
return mod;
314325
} catch (err) {

lib/utils/plugins.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,19 @@ const clearModulesCache = () => {
7373
}
7474
};
7575

76-
const getPluginName = path => window.require('path').basename(path);
76+
const pathModule = window.require('path');
77+
78+
const getPluginName = path => pathModule.basename(path);
79+
80+
const getPluginVersion = path => {
81+
let version = null;
82+
try {
83+
version = window.require(pathModule.resolve(path, 'package.json')).version;
84+
} catch (err) {
85+
console.warn(`No package.json found in ${path}`);
86+
}
87+
return version;
88+
};
7789

7890
const loadModules = () => {
7991
console.log('(re)loading renderer plugins');
@@ -112,6 +124,7 @@ const loadModules = () => {
112124
.map(path => {
113125
let mod;
114126
const pluginName = getPluginName(path);
127+
const pluginVersion = getPluginVersion(path);
115128

116129
// window.require allows us to ensure this doesn't get
117130
// in the way of our build
@@ -126,6 +139,7 @@ const loadModules = () => {
126139
for (const i in mod) {
127140
if ({}.hasOwnProperty.call(mod, i)) {
128141
mod[i]._pluginName = pluginName;
142+
mod[i]._pluginVersion = pluginVersion;
129143
}
130144
}
131145

@@ -209,6 +223,8 @@ const loadModules = () => {
209223
mod.onRendererWindow(window);
210224
}
211225

226+
console.log(`Plugin ${pluginName} (${pluginVersion}) loaded.`);
227+
212228
return mod;
213229
})
214230
.filter(mod => Boolean(mod));

0 commit comments

Comments
 (0)