Files
react-native-devtools-frontend/scripts/deps/sync-vscode-settings.js
T
Paul Lewis 2afe8be656 Skip VSCode settings update on error
I had a rogue comma in my settings.json file. This prevented the require
from running correctly, which in turn stopped gclient sync from running.
This CL adds a try-catch around the code so that on any error, the
update is skipped.

This CL also adds a bypass option, so that people can opt out of syncing
their VSCode settings entirely.

R=jacktfranklin@chromium.org

Bug: None
Change-Id: I3d90dc0546fcc145c881cb1aa49964e79db3f24f
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2914873
Reviewed-by: Jack Franklin <jacktfranklin@chromium.org>
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Paul Lewis <aerotwist@chromium.org>
2021-05-24 09:12:16 +00:00

35 lines
1.2 KiB
JavaScript

// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
const path = require('path');
const fs = require('fs');
const DEVTOOLS_SETTINGS_LOCATION = path.join(process.cwd(), '.vscode', 'devtools-workspace-settings.json');
const VSCODE_SETTINGS_LOCATION = path.join(process.cwd(), '.vscode', 'settings.json');
// If there are no settings to copy and paste, or the user has opted out of updates,
// return and do nothing.
if (!fs.existsSync(DEVTOOLS_SETTINGS_LOCATION) || Boolean(process.env['SKIP_VSCODE_SETTINGS_SYNC'])) {
return;
}
try {
const devtoolsSettings = require(DEVTOOLS_SETTINGS_LOCATION);
let preExistingSettings = {};
if (fs.existsSync(VSCODE_SETTINGS_LOCATION)) {
preExistingSettings = require(VSCODE_SETTINGS_LOCATION);
}
const updatedSettings = {
...devtoolsSettings,
// Any setting specified by the engineer will always take precedence over the defaults
...preExistingSettings,
};
fs.writeFileSync(VSCODE_SETTINGS_LOCATION, JSON.stringify(updatedSettings, null, 2));
} catch (err) {
console.warn('Unable to update VSCode settings - skipping');
console.warn(err.stack);
}