Browse Source

feat: added process.electron to get the electron version in forked process (#16450)

SamvelRaja 6 years ago
parent
commit
8af532ba98
2 changed files with 18 additions and 0 deletions
  1. 6 0
      atom/app/node_main.cc
  2. 12 0
      spec/node-spec.js

+ 6 - 0
atom/app/node_main.cc

@@ -11,6 +11,7 @@
 #include "atom/browser/javascript_environment.h"
 #include "atom/browser/node_debugger.h"
 #include "atom/common/api/atom_bindings.h"
+#include "atom/common/atom_version.h"
 #include "atom/common/crash_reporter/crash_reporter.h"
 #include "atom/common/native_mate_converters/string16_converter.h"
 #include "atom/common/node_bindings.h"
@@ -79,6 +80,11 @@ int NodeMain(int argc, char* argv[]) {
     reporter.SetMethod("start", &crash_reporter::CrashReporter::StartInstance);
     process.Set("crashReporter", reporter);
 
+    mate::Dictionary versions;
+    if (process.Get("versions", &versions)) {
+      versions.SetReadOnly(ATOM_PROJECT_NAME, ATOM_VERSION_STRING);
+    }
+
     node::LoadEnvironment(env);
 
     bool more;

+ 12 - 0
spec/node-spec.js

@@ -111,6 +111,18 @@ describe('node feature', () => {
         })
         forked.send('hello')
       })
+
+      it('has the electron version in process.versions', (done) => {
+        const source = 'process.send(process.versions)'
+        const forked = ChildProcess.fork('--eval', [source])
+        forked.on('message', (message) => {
+          expect(message)
+            .to.have.own.property('electron')
+            .that.is.a('string')
+            .and.matches(/^\d+\.\d+\.\d+(\S*)?$/)
+          done()
+        })
+      })
     })
 
     describe('child_process.spawn', () => {