Skip to content

Commit

Permalink
chore: warn when people attempt to use the Electron module to do Elec…
Browse files Browse the repository at this point in the history
…tron things but from node (#15916)

* chore: warn when people attempt to use the Electron module to do Electron things but from node

* update node env console warning
  • Loading branch information
MarshallOfSound authored and codebytere committed Dec 7, 2018
1 parent 177091c commit eb8fcf8
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,20 @@ function getElectronPath () {
}
}

module.exports = getElectronPath()
// A list of the main modules the people will attempt to use from the Electron API, this is not a complete list but should cover most
// use cases.
var electronModuleNames = ['app', 'autoUpdater', 'BrowserWindow', 'ipcMain', 'Menu', 'net', 'Notification', 'systemPreferences', 'Tray']
var electronPath = new String(getElectronPath())

electronModuleNames.forEach(function warnOnElectronAPIAccess (apiKey) {
Object.defineProperty(electronPath, apiKey, {
enumerable: false,
configurable: false,
get: function getElectronAPI () {
console.warn('WARNING: You are attempting to access an Electron API from a node environment.\n\n' +
'You need to use the "electron" command to run your app. E.g. "npx electron ./myapp.js"')
}
})
})

module.exports = electronPath

0 comments on commit eb8fcf8

Please sign in to comment.