From f9e2ec43d0688a95610796e01501f5f882eb3bb7 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Tue, 26 Jun 2018 23:47:01 -0700 Subject: [PATCH] fix: deprecate properties in app.getAppMetrics() (#13446) * fix: deprecate properties in app.getAppMetrics() * address feedback from review * fix deprecated property location * simplify test --- docs/api/breaking-changes.md | 19 +++++++++++++++++-- lib/browser/api/app.js | 7 +++++++ lib/common/api/deprecate.js | 10 ++++++++-- spec/api-deprecations-spec.js | 17 +++++++++++++++-- 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/docs/api/breaking-changes.md b/docs/api/breaking-changes.md index e1e5923d21..1e38f4a882 100644 --- a/docs/api/breaking-changes.md +++ b/docs/api/breaking-changes.md @@ -35,9 +35,9 @@ app.releaseSingleInstanceLock() ``` -# Planned Breaking API Changes (3.0) +# Breaking API Changes (3.0) -The following list includes the breaking API changes planned for Electron 3.0. +The following list includes the breaking API changes in Electron 3.0. ## `app` @@ -46,6 +46,12 @@ The following list includes the breaking API changes planned for Electron 3.0. app.getAppMemoryInfo() // Replace with app.getAppMetrics() + +// Deprecated +const metrics = app.getAppMetrics() +const {memory} = metrics[0] +memory.privateBytes // Deprecated property +memory.sharedBytes // Deprecated property ``` ## `BrowserWindow` @@ -124,6 +130,15 @@ nativeImage.createFromBuffer(buffer, { }) ``` +## `process` + +```js +// Deprecated +const info = process.getProcessMemoryInfo() +const privateBytes = info.privateBytes // deprecated property +const sharedBytes = info.sharedBytes // deprecated property +``` + ## `screen` ```js diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 0db77baecb..a6d94a20a4 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -58,6 +58,13 @@ Object.assign(app, { } }) +const nativeFn = app.getAppMetrics +app.getAppMetrics = () => { + deprecate.removeProperty(nativeFn, 'privateBytes') + deprecate.removeProperty(nativeFn, 'sharedBytes') + return nativeFn.call(app) +} + app.isPackaged = (() => { const execFile = path.basename(process.execPath).toLowerCase() if (process.platform === 'win32') { diff --git a/lib/common/api/deprecate.js b/lib/common/api/deprecate.js index b95bf76a8f..4a42b2a693 100644 --- a/lib/common/api/deprecate.js +++ b/lib/common/api/deprecate.js @@ -88,8 +88,14 @@ deprecate.getHandler = () => deprecationHandler // } // } -// Deprecate the old name of a property -deprecate.property = (object, deprecatedName, newName) => { +deprecate.removeProperty = (object, deprecatedName) => { + if (!process.noDeprecation) { + deprecate.log(`The '${deprecatedName}' property has been deprecated.`) + } +} + +// Replace the old name of a property +deprecate.renameProperty = (object, deprecatedName, newName) => { let warned = false let warn = () => { if (!(warned || process.noDeprecation)) { diff --git a/spec/api-deprecations-spec.js b/spec/api-deprecations-spec.js index 8bb0711b72..6a18f77040 100644 --- a/spec/api-deprecations-spec.js +++ b/spec/api-deprecations-spec.js @@ -65,7 +65,7 @@ describe('deprecations', () => { expect(o).to.not.have.a.property(oldPropertyName) expect(o).to.have.a.property(newPropertyName).that.is.a('number') - deprecate.property(o, oldPropertyName, newPropertyName) + deprecate.renameProperty(o, oldPropertyName, newPropertyName) o[oldPropertyName] = ++value expect(msg).to.be.a('string') @@ -76,6 +76,19 @@ describe('deprecations', () => { expect(o).to.have.a.property(oldPropertyName).that.is.equal(value) }) + it('deprecates a property of an object', () => { + let msg + deprecations.setHandler(m => { msg = m }) + + const propertyName = 'itMustGo' + const o = { [propertyName]: 0 } + + deprecate.removeProperty(o, propertyName) + + expect(msg).to.be.a('string') + expect(msg).to.include(propertyName) + }) + it('warns if deprecated property is already set', () => { let msg deprecations.setHandler((m) => { msg = m }) @@ -85,7 +98,7 @@ describe('deprecations', () => { const value = 0 let o = { [oldPropertyName]: value } - deprecate.property(o, oldPropertyName, newPropertyName) + deprecate.renameProperty(o, oldPropertyName, newPropertyName) expect(msg).to.be.a('string') expect(msg).to.include(oldPropertyName)