chore: replace Object.assign with object spread syntax (#34739)

This commit is contained in:
David Sanders 2022-06-27 01:29:18 -07:00 committed by GitHub
parent ba4893c248
commit e2c58d164d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 21 deletions

View file

@ -18,10 +18,11 @@ if (!OUT_DIR) {
throw new Error('No viable out dir: one of Debug, Testing, or Release must exist.'); 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'), CHROMIUM_BUILDTOOLS_PATH: path.resolve(SOURCE_ROOT, '..', 'buildtools'),
DEPOT_TOOLS_WIN_TOOLCHAIN: '0' DEPOT_TOOLS_WIN_TOOLCHAIN: '0',
}, process.env); ...process.env
};
// Users may not have depot_tools in PATH. // Users may not have depot_tools in PATH.
env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`; env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`;

View file

@ -27,7 +27,7 @@ const IGNORELIST = new Set([
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
function spawnAndCheckExitCode (cmd, args, opts) { function spawnAndCheckExitCode (cmd, args, opts) {
opts = Object.assign({ stdio: 'inherit' }, opts); opts = { stdio: 'inherit', ...opts };
const { error, status, signal } = childProcess.spawnSync(cmd, args, opts); const { error, status, signal } = childProcess.spawnSync(cmd, args, opts);
if (error) { if (error) {
// the subsprocess failed or timed out // the subsprocess failed or timed out
@ -103,7 +103,7 @@ const LINTERS = [{
run: (opts, filenames) => { run: (opts, filenames) => {
const rcfile = path.join(DEPOT_TOOLS, 'pylintrc'); const rcfile = path.join(DEPOT_TOOLS, 'pylintrc');
const args = ['--rcfile=' + rcfile, ...filenames]; 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 }); spawnAndCheckExitCode('pylint-2.7', args, { env });
} }
}, { }, {
@ -143,10 +143,11 @@ const LINTERS = [{
test: filename => filename.endsWith('.gn') || filename.endsWith('.gni'), test: filename => filename.endsWith('.gn') || filename.endsWith('.gni'),
run: (opts, filenames) => { run: (opts, filenames) => {
const allOk = filenames.map(filename => { const allOk = filenames.map(filename => {
const env = Object.assign({ const env = {
CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools'), CHROMIUM_BUILDTOOLS_PATH: path.resolve(ELECTRON_ROOT, '..', 'buildtools'),
DEPOT_TOOLS_WIN_TOOLCHAIN: '0' DEPOT_TOOLS_WIN_TOOLCHAIN: '0',
}, process.env); ...process.env
};
// Users may not have depot_tools in PATH. // Users may not have depot_tools in PATH.
env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`; env.PATH = `${env.PATH}${path.delimiter}${DEPOT_TOOLS}`;
const args = ['format', filename]; const args = ['format', filename];

View file

@ -20,12 +20,13 @@ const args = require('minimist')(process.argv.slice(2), {
async function main () { async function main () {
const outDir = utils.getOutDir({ shouldLog: true }); const outDir = utils.getOutDir({ shouldLog: true });
const nodeDir = path.resolve(BASE, 'out', outDir, 'gen', 'node_headers'); 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_nodedir: nodeDir,
npm_config_msvs_version: '2019', npm_config_msvs_version: '2019',
npm_config_arch: process.env.NPM_CONFIG_ARCH, npm_config_arch: process.env.NPM_CONFIG_ARCH,
npm_config_yes: 'true' npm_config_yes: 'true'
}); };
const clangDir = path.resolve(BASE, 'third_party', 'llvm-build', 'Release+Asserts', 'bin'); const clangDir = path.resolve(BASE, 'third_party', 'llvm-build', 'Release+Asserts', 'bin');
const cc = path.resolve(clangDir, 'clang'); const cc = path.resolve(clangDir, 'clang');

View file

@ -167,7 +167,7 @@ new Promise((resolve, reject) => {
const tarballPath = path.join(tempDir, `${rootPackageJson.name}-${rootPackageJson.version}.tgz`); const tarballPath = path.join(tempDir, `${rootPackageJson.name}-${rootPackageJson.version}.tgz`);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const result = childProcess.spawnSync('npm', ['install', tarballPath, '--force', '--silent'], { 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, cwd: tempDir,
stdio: 'inherit' stdio: 'inherit'
}); });

View file

@ -235,12 +235,13 @@ async function installSpecModules (dir) {
const CXXFLAGS = ['-std=c++17', process.env.CXXFLAGS].filter(x => !!x).join(' '); 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 nodeDir = path.resolve(BASE, `out/${utils.getOutDir({ shouldLog: true })}/gen/node_headers`);
const env = Object.assign({}, process.env, { const env = {
...process.env,
CXXFLAGS, CXXFLAGS,
npm_config_nodedir: nodeDir, npm_config_nodedir: nodeDir,
npm_config_msvs_version: '2019', npm_config_msvs_version: '2019',
npm_config_yes: 'true' npm_config_yes: 'true'
}); };
if (fs.existsSync(path.resolve(dir, 'node_modules'))) { if (fs.existsSync(path.resolve(dir, 'node_modules'))) {
await fs.remove(path.resolve(dir, 'node_modules')); await fs.remove(path.resolve(dir, 'node_modules'));
} }

View file

@ -1040,7 +1040,7 @@ describe('BrowserWindow module', () => {
const boundsUpdate = { width: 200 }; const boundsUpdate = { width: 200 };
w.setBounds(boundsUpdate as any); w.setBounds(boundsUpdate as any);
const expectedBounds = Object.assign(fullBounds, boundsUpdate); const expectedBounds = { ...fullBounds, ...boundsUpdate };
expectBoundsEqual(w.getBounds(), expectedBounds); expectBoundsEqual(w.getBounds(), expectedBounds);
}); });

View file

@ -78,7 +78,7 @@ describe('node feature', () => {
child.kill(); 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 }); child = childProcess.spawn(process.execPath, { env });
exitPromise = emittedOnce(child, 'exit'); exitPromise = emittedOnce(child, 'exit');
@ -113,7 +113,7 @@ describe('node feature', () => {
child.kill(); 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 }); child = childProcess.spawn(process.execPath, ['--enable-logging'], { env });
let output = ''; let output = '';
@ -136,9 +136,10 @@ describe('node feature', () => {
it('does allow --require in non-packaged apps', async () => { it('does allow --require in non-packaged apps', async () => {
const appPath = path.join(fixtures, 'module', 'noop.js'); 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')}` NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
}); };
// App should exit with code 1. // App should exit with code 1.
const child = childProcess.spawn(process.execPath, [appPath], { env }); const child = childProcess.spawn(process.execPath, [appPath], { env });
const [code] = await emittedOnce(child, 'exit'); const [code] = await emittedOnce(child, 'exit');
@ -147,10 +148,11 @@ describe('node feature', () => {
it('does not allow --require in packaged apps', async () => { it('does not allow --require in packaged apps', async () => {
const appPath = path.join(fixtures, 'module', 'noop.js'); const appPath = path.join(fixtures, 'module', 'noop.js');
const env = Object.assign({}, process.env, { const env = {
...process.env,
ELECTRON_FORCE_IS_PACKAGED: 'true', ELECTRON_FORCE_IS_PACKAGED: 'true',
NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}` NODE_OPTIONS: `--require=${path.join(fixtures, 'module', 'fail.js')}`
}); };
// App should exit with code 0. // App should exit with code 0.
const child = childProcess.spawn(process.execPath, [appPath], { env }); const child = childProcess.spawn(process.execPath, [appPath], { env });
const [code] = await emittedOnce(child, 'exit'); const [code] = await emittedOnce(child, 'exit');

View file

@ -63,7 +63,7 @@ describe('shell module', () => {
expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions); expect(shell.readShortcutLink(tmpShortcut)).to.deep.equal(shortcutOptions);
const change = { target: 'D:\\' }; const change = { target: 'D:\\' };
expect(shell.writeShortcutLink(tmpShortcut, 'update', change)).to.be.true(); 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', () => { it('replaces the shortcut', () => {