Skip to content

Commit effa60d

Browse files
Lightning00BladeDevtools-frontend LUCI CQ
authored and
Devtools-frontend LUCI CQ
committed
[eslint][vscode] Fixes issue with EsLint plugin not working
Bug: none Change-Id: I1be301aeac1ba08708bd03869fa0bf5b2ff6272f Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/6190538 Reviewed-by: Simon Zünd <[email protected]> Commit-Queue: Nikolay Vitkov <[email protected]>
1 parent b1b834b commit effa60d

File tree

6 files changed

+160
-95
lines changed

6 files changed

+160
-95
lines changed
+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
2-
"eslint.runtime": "third_party/node/node.py",
2+
"eslint.runtime": "$PATHED by scripts/deps/sync-vscode-settings.mjs",
33
"typescript.tsdk": "node_modules/typescript/lib",
44
"debug.javascript.terminalOptions": {
5-
"skipFiles": [
6-
"node_modules/typescript/**"
7-
]
5+
"skipFiles": ["node_modules/typescript/**"]
86
}
97
}

DEPS

+1-1
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ hooks = [
309309
'name': 'VS Code settings',
310310
'pattern': '.',
311311
'condition': 'build_with_chromium == False',
312-
'action': ['vpython3', 'third_party/node/node.py', '--output', 'scripts/deps/sync-vscode-settings.js']
312+
'action': ['vpython3', 'third_party/node/node.py', '--output', 'scripts/deps/sync-vscode-settings.mjs']
313313
},
314314
]
315315

scripts/deps/sync-vscode-settings.js

-60
This file was deleted.

scripts/deps/sync-vscode-settings.mjs

+112
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2021 The Chromium Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
import path from 'path';
6+
import fs from 'fs';
7+
import childProcess from 'child_process';
8+
9+
// JSON files under .vscode/ synced by this script
10+
const VSCODE_SETTINGS_TO_MERGE = [
11+
{ settingsFile: 'settings.json' },
12+
{ settingsFile: 'tasks.json', mergeField: 'tasks', byField: 'label' },
13+
{
14+
settingsFile: 'launch.json',
15+
mergeField: 'configurations',
16+
byField: 'name',
17+
},
18+
];
19+
20+
// If the user has opted out of updates, return and do nothing.
21+
if (Boolean(process.env['SKIP_VSCODE_SETTINGS_SYNC'])) {
22+
process.exit(0);
23+
}
24+
25+
for (const { settingsFile, mergeField, byField } of VSCODE_SETTINGS_TO_MERGE) {
26+
const vscodeSettingsLocation = path.join(
27+
process.cwd(),
28+
'.vscode',
29+
settingsFile,
30+
);
31+
const devtoolsSettingsLocation = path.join(
32+
process.cwd(),
33+
'.vscode',
34+
'devtools-workspace-' + settingsFile,
35+
);
36+
37+
// If there are no settings to copy and paste, skip.
38+
if (!fs.existsSync(devtoolsSettingsLocation)) {
39+
continue;
40+
}
41+
42+
try {
43+
const devtoolsSettings = (
44+
await import(devtoolsSettingsLocation, {
45+
with: { type: 'json' },
46+
})
47+
).default;
48+
let preExistingSettings = {};
49+
if (fs.existsSync(vscodeSettingsLocation)) {
50+
preExistingSettings = (
51+
await import(vscodeSettingsLocation, {
52+
with: { type: 'json' },
53+
})
54+
).default;
55+
}
56+
57+
const updatedSettings = {
58+
...devtoolsSettings,
59+
// Any setting specified by the engineer will always take precedence over the defaults
60+
...preExistingSettings,
61+
};
62+
63+
// TODO: We found that this never work so patch it now
64+
// so gclient sync updates it.
65+
// Later we should remove and allow user to keep their
66+
// preference.
67+
if (updatedSettings['eslint.runtime']) {
68+
const nodePath = childProcess
69+
.execSync(
70+
path.join(
71+
import.meta.dirname,
72+
'..',
73+
'..',
74+
'third_party',
75+
'node',
76+
'node_path.py',
77+
),
78+
)
79+
.toString('utf-8')
80+
.trim();
81+
82+
updatedSettings['eslint.runtime'] = nodePath;
83+
}
84+
85+
if (
86+
mergeField &&
87+
byField &&
88+
preExistingSettings[mergeField] &&
89+
devtoolsSettings[mergeField]
90+
) {
91+
// We need to merge two lists in a field. The list items have a unique
92+
// id specified by byField. If an entry is found in devtoolsSettings we
93+
// assume it should be updated when the devtools settings file is updated,
94+
// otherwise we keep the preexisting setting.
95+
const mergedList = [...devtoolsSettings[mergeField]];
96+
const doNotDuplicate = new Set(mergedList.map(item => item[byField]));
97+
for (const item of preExistingSettings[mergeField]) {
98+
if (!doNotDuplicate.has(item[byField])) {
99+
mergedList.push(item);
100+
}
101+
}
102+
updatedSettings[mergeField] = mergedList;
103+
}
104+
fs.writeFileSync(
105+
vscodeSettingsLocation,
106+
JSON.stringify(updatedSettings, null, 2),
107+
);
108+
} catch (err) {
109+
console.warn('Unable to update VSCode settings - skipping');
110+
console.warn(err.stack);
111+
}
112+
}

third_party/node/node.py

+1-30
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,12 @@
33
# Use of this source code is governed by a BSD-style license that can be
44
# found in the LICENSE file.
55

6-
from os import path as os_path
7-
import platform
86
import subprocess
97
import sys
108
import os
119

10+
from node_path import GetBinaryPath
1211

13-
def get_mac_architecture():
14-
if platform.machine() == "x86_64":
15-
is_translated = subprocess.run(
16-
["sysctl", "-n", "sysctl.proc_translated"],
17-
capture_output=True,
18-
text=True).stdout.strip() == "1"
19-
return "arm64" if is_translated else "x86_64"
20-
return platform.machine()
21-
22-
23-
def GetBinaryPath():
24-
if platform.machine() == 'arm64':
25-
darwin_path = 'mac_arm64'
26-
darwin_name = 'node-darwin-arm64'
27-
else:
28-
darwin_path = 'mac'
29-
darwin_name = 'node-darwin-x64'
30-
relative = {
31-
'Darwin': (darwin_path, darwin_name, 'bin', 'node'),
32-
'Linux': ('linux', 'node-linux-x64', 'bin', 'node'),
33-
'Windows': ('win', 'node.exe'),
34-
}[platform.system()]
35-
devtools_checkout_path = os.path.join(os.path.dirname(__file__), *relative)
36-
if os_path.exists(devtools_checkout_path):
37-
return devtools_checkout_path
38-
# Assume we are in a chromium checkout.
39-
return os_path.join(os.path.dirname(__file__), '..', '..', '..', '..',
40-
'node', *relative)
4112

4213
def RunNode(cmd_parts, output=subprocess.PIPE):
4314
cmd = [GetBinaryPath()] + cmd_parts

third_party/node/node_path.py

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env vpython3
2+
# Copyright 2025 The Chromium Authors. All rights reserved.
3+
# Use of this source code is governed by a BSD-style license that can be
4+
# found in the LICENSE file.
5+
6+
from os import path as os_path
7+
import platform
8+
import subprocess
9+
import os
10+
11+
12+
def get_mac_architecture():
13+
if platform.machine() == "x86_64":
14+
is_translated = subprocess.run(
15+
["sysctl", "-n", "sysctl.proc_translated"],
16+
capture_output=True,
17+
text=True).stdout.strip() == "1"
18+
return "arm64" if is_translated else "x86_64"
19+
return platform.machine()
20+
21+
22+
def GetBinaryPath():
23+
if platform.machine() == 'arm64':
24+
darwin_path = 'mac_arm64'
25+
darwin_name = 'node-darwin-arm64'
26+
else:
27+
darwin_path = 'mac'
28+
darwin_name = 'node-darwin-x64'
29+
relative = {
30+
'Darwin': (darwin_path, darwin_name, 'bin', 'node'),
31+
'Linux': ('linux', 'node-linux-x64', 'bin', 'node'),
32+
'Windows': ('win', 'node.exe'),
33+
}[platform.system()]
34+
devtools_checkout_path = os.path.join(os.path.dirname(__file__), *relative)
35+
if os_path.exists(devtools_checkout_path):
36+
return devtools_checkout_path
37+
# Assume we are in a chromium checkout.
38+
return os_path.join(os.path.dirname(__file__), '..', '..', '..', '..',
39+
'node', *relative)
40+
41+
42+
if __name__ == '__main__':
43+
node_path = GetBinaryPath()
44+
print(node_path)

0 commit comments

Comments
 (0)