From 7bd4be8ca6f54cb395d16eaa4ef88a9ef096b4fe Mon Sep 17 00:00:00 2001 From: Ayushman Chhabra <14110965+ayushmanchhabra@users.noreply.github.com> Date: Sat, 13 Apr 2024 00:31:05 +0530 Subject: [PATCH] chore: refactor platform parsing logic --- lib/index.cjs | 28 +++++++++++++--------------- test/demo.cjs | 1 - 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/lib/index.cjs b/lib/index.cjs index 0bfa841b6..4835e413f 100644 --- a/lib/index.cjs +++ b/lib/index.cjs @@ -28,15 +28,13 @@ const { class NwBuilder { constructor(options) { this.init(options).then(() => { - this._platforms = { ...Platforms }; - - // clear all unused platforms - for (const name in this._platforms) { - if ( - this.options.platforms && - this.options.platforms.indexOf(name) === -1 - ) - delete this._platforms[name]; + /* Make a shallow copy of the Platforms object */ + this.platforms = Object.assign({}, Platforms); + /* Clear all unused platforms */ + for (const platform of Object.keys(this.platforms)) { + if (!options.platforms.includes(platform)) { + delete this.platforms[platform]; + } } }).catch((error) => { console.error(error); @@ -467,7 +465,7 @@ class NwBuilder { self._files, self, JSON.stringify( - self._platforms[platformName].platformSpecificManifest, + self.platforms[platformName].platformSpecificManifest, ), zipOptions, ).then(function (file) { @@ -595,8 +593,8 @@ class NwBuilder { var executableName = self.getExecutableName(name); await fs.promises.rename( - resolve(platform.releasePath, "nwjs.app"), - resolve(platform.releasePath, executableName), + path.resolve(platform.releasePath, "nwjs.app"), + path.resolve(platform.releasePath, executableName), ); // Let's first handle the mac icon @@ -691,8 +689,8 @@ class NwBuilder { var executablePath = path.resolve(platform.releasePath, executableName); await fs.promises.rename( - resolve(platform.releasePath, "nw.exe"), - resolve(platform.releasePath, executableName), + path.resolve(platform.releasePath, "nw.exe"), + path.resolve(platform.releasePath, executableName), ); var rcConf = {}; @@ -782,7 +780,7 @@ class NwBuilder { } _forEachPlatform(fn) { - _.forEach(this._platforms, function (platform, name) { + _.forEach(this.platforms, function (platform, name) { return fn(name, platform); }); } diff --git a/test/demo.cjs b/test/demo.cjs index d7b21d29f..2a3a9935c 100644 --- a/test/demo.cjs +++ b/test/demo.cjs @@ -1,5 +1,4 @@ const NwBuilder = require('nw-builder'); -const { version } = require('yargs'); const nw = new NwBuilder({ version: '0.86.0',