From e2c58d164dc44515a067b156302a391e6c13e8a6 Mon Sep 17 00:00:00 2001 From: David Sanders Date: Mon, 27 Jun 2022 01:29:18 -0700 Subject: [PATCH] chore: replace Object.assign with object spread syntax (#34739) --- script/gn-check.js | 7 ++++--- script/lint.js | 11 ++++++----- script/nan-spec-runner.js | 5 +++-- script/release/publish-to-npm.js | 2 +- script/spec-runner.js | 5 +++-- spec-main/api-browser-window-spec.ts | 2 +- spec-main/node-spec.ts | 14 ++++++++------ spec/api-shell-spec.js | 2 +- 8 files changed, 27 insertions(+), 21 deletions(-) diff --git a/script/gn-check.js b/script/gn-check.js index 497e6ec5f3cd..12dca3651e72 100644 --- a/script/gn-check.js +++ b/script/gn-check.js @@ -18,10 +18,11 @@ if (!OUT_DIR) { throw new Error('No viable out dir: one of Debug, Testing, or Release must exist.'); } -const env = Object.assign({ +const env = { CHROMIUM_BUILDTOOLS_PATH: path.resolve(SOURCE_ROOT, '..', 'buildtools'), - DEPOT_TOOLS_WIN_TOOLCHAIN: '0' -}, process.env); + DEPOT_TOOLS_WIN_TOOLCHAIN: '0', + ...process.env +}; // Users may not have depot_tools in PATH. env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`; diff --git a/script/lint.js b/script/lint.js index 839215ee35e8..8ee4f9b75613 100755 --- a/script/lint.js +++ b/script/lint.js @@ -27,7 +27,7 @@ const IGNORELIST = new Set([ const IS_WINDOWS = process.platform === 'win32'; function spawnAndCheckExitCode (cmd, args, opts) { - opts = Object.assign({ stdio: 'inherit' }, opts); + opts = { stdio: 'inherit', ...opts }; const { error, status, signal } = childProcess.spawnSync(cmd, args, opts); if (error) { // the subsprocess failed or timed out @@ -103,7 +103,7 @@ const LINTERS = [{ run: (opts, filenames) => { const rcfile = path.join(DEPOT_TOOLS, 'pylintrc'); const args = ['--rcfile=' + rcfile, ...filenames]; - const env = Object.assign({ PYTHONPATH: path.join(ELECTRON_ROOT, 'script') }, process.env); + const env = { PYTHONPATH: path.join(ELECTRON_ROOT, 'script'), ...process.env }; spawnAndCheckExitCode('pylint-2.7', args, { env }); } }, { @@ -143,10 +143,11 @@ const LINTERS = [{ test: filename => filename.endsWith('.gn') || filename.endsWith('.gni'), run: (opts, filenames) => { const allOk = filenames.map(filename => { - const env = Object.assign({ + const env = { CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools'), - DEPOT_TOOLS_WIN_TOOLCHAIN: '0' - }, process.env); + DEPOT_TOOLS_WIN_TOOLCHAIN: '0', + ...process.env + }; // Users may not have depot_tools in PATH. env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`; const args = ['format', filename]; diff --git a/script/nan-spec-runner.js b/script/nan-spec-runner.js index f022f3da25fa..c03f3f36ca98 100644 --- a/script/nan-spec-runner.js +++ b/script/nan-spec-runner.js @@ -20,12 +20,13 @@ const args = require('minimist')(process.argv.slice(2), { async function main () { const outDir = utils.getOutDir({ shouldLog: true }); const nodeDir = path.resolve(BASE, 'out', outDir, 'gen', 'node_headers'); - const env = Object.assign({}, process.env, { + const env = { + ...process.env, npm_config_nodedir: nodeDir, npm_config_msvs_version: '2019', npm_config_arch: process.env.NPM_CONFIG_ARCH, npm_config_yes: 'true' - }); + }; const clangDir = path.resolve(BASE, 'third_party', 'llvm-build', 'Release+Asserts', 'bin'); const cc = path.resolve(clangDir, 'clang'); diff --git a/script/release/publish-to-npm.js b/script/release/publish-to-npm.js index 55799665a57a..081274d83eda 100644 --- a/script/release/publish-to-npm.js +++ b/script/release/publish-to-npm.js @@ -167,7 +167,7 @@ new Promise((resolve, reject) => { const tarballPath = path.join(tempDir, `${rootPackageJson.name}-${rootPackageJson.version}.tgz`); return new Promise((resolve, reject) => { const result = childProcess.spawnSync('npm', ['install', tarballPath, '--force', '--silent'], { - env: Object.assign({}, process.env, { electron_config_cache: tempDir }), + env: { ...process.env, electron_config_cache: tempDir }, cwd: tempDir, stdio: 'inherit' }); diff --git a/script/spec-runner.js b/script/spec-runner.js index eb4160c8ce8b..590966f064b8 100755 --- a/script/spec-runner.js +++ b/script/spec-runner.js @@ -235,12 +235,13 @@ async function installSpecModules (dir) { const CXXFLAGS = ['-std=c++17', process.env.CXXFLAGS].filter(x => !!x).join(' '); const nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`); - const env = Object.assign({}, process.env, { + const env = { + ...process.env, CXXFLAGS, npm_config_nodedir: nodeDir, npm_config_msvs_version: '2019', npm_config_yes: 'true' - }); + }; if (fs.existsSync(path.resolve(dir, 'node_modules'))) { await fs.remove(path.resolve(dir, 'node_modules')); } diff --git a/spec-main/api-browser-window-spec.ts b/spec-main/api-browser-window-spec.ts index a7b3cc87dd9a..67539005316a 100644 --- a/spec-main/api-browser-window-spec.ts +++ b/spec-main/api-browser-window-spec.ts @@ -1040,7 +1040,7 @@ describe('BrowserWindow module', () => { const boundsUpdate = { width: 200 }; w.setBounds(boundsUpdate as any); - const expectedBounds = Object.assign(fullBounds, boundsUpdate); + const expectedBounds = { ...fullBounds, ...boundsUpdate }; expectBoundsEqual(w.getBounds(), expectedBounds); }); diff --git a/spec-main/node-spec.ts b/spec-main/node-spec.ts index af6c11360f20..40eb0276029e 100644 --- a/spec-main/node-spec.ts +++ b/spec-main/node-spec.ts @@ -78,7 +78,7 @@ describe('node feature', () => { child.kill(); }); - const env = Object.assign({}, process.env, { NODE_OPTIONS: '--v8-options' }); + const env = { ...process.env, NODE_OPTIONS: '--v8-options' }; child = childProcess.spawn(process.execPath, { env }); exitPromise = emittedOnce(child, 'exit'); @@ -113,7 +113,7 @@ describe('node feature', () => { child.kill(); }); - const env = Object.assign({}, process.env, { NODE_OPTIONS: '--use-openssl-ca' }); + const env = { ...process.env, NODE_OPTIONS: '--use-openssl-ca' }; child = childProcess.spawn(process.execPath, ['--enable-logging'], { env }); let output = ''; @@ -136,9 +136,10 @@ describe('node feature', () => { it('does allow --require in non-packaged apps', async () => { const appPath = path.join(fixtures, 'module', 'noop.js'); - const env = Object.assign({}, process.env, { + const env = { + ...process.env, NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}` - }); + }; // App should exit with code 1. const child = childProcess.spawn(process.execPath, [appPath], { env }); const [code] = await emittedOnce(child, 'exit'); @@ -147,10 +148,11 @@ describe('node feature', () => { it('does not allow --require in packaged apps', async () => { const appPath = path.join(fixtures, 'module', 'noop.js'); - const env = Object.assign({}, process.env, { + const env = { + ...process.env, ELECTRON_FORCE_IS_PACKAGED: 'true', NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}` - }); + }; // App should exit with code 0. const child = childProcess.spawn(process.execPath, [appPath], { env }); const [code] = await emittedOnce(child, 'exit'); diff --git a/spec/api-shell-spec.js b/spec/api-shell-spec.js index 284dd62864d8..6eacf5136399 100644 --- a/spec/api-shell-spec.js +++ b/spec/api-shell-spec.js @@ -63,7 +63,7 @@ describe('shell module', () => { expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions); const change = { target: 'D:\\' }; expect(shell.writeShortcutLink(tmpShortcut, 'update', change)).to.be.true(); - expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(Object.assign(shortcutOptions, change)); + expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal({ ...shortcutOptions, ...change }); }); it('replaces the shortcut', () => {