Skip to content

Commit 1563f4b

Browse files
committed
Make it more concurrent-friendly.
1 parent 41bbdb3 commit 1563f4b

File tree

1 file changed

+29
-11
lines changed
  • scripts/lib/bashy-node/node-project/lint-src/main-linter/bin

1 file changed

+29
-11
lines changed

scripts/lib/bashy-node/node-project/lint-src/main-linter/bin/eslint

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,31 @@ configFile=''
2020
# Helper functions
2121
#
2222

23+
# Copies a config file to a directory, giving it a unique name, and prints out
24+
# the full path.
25+
function copy-config-file {
26+
local srcPath="$1"
27+
local destDir="$2"
28+
29+
local baseName="$(basename "${srcPath}")"
30+
local prefix="$(date +%s)"
31+
(( prefix = (prefix + $$) % 10000 ))
32+
33+
local destPath
34+
while true; do
35+
destPath="${destDir}/${prefix}-${baseName}"
36+
if [[ ! -x "${destPath}" ]]; then
37+
break
38+
fi
39+
(( prefix++ ))
40+
done
41+
42+
cp "${srcPath}" "${destPath}" \
43+
|| return "$?"
44+
45+
echo "${destPath}"
46+
}
47+
2348
# Finds the argument which specifies the config file, stashes it in a global
2449
# as an absolute path, and drops it from the arguments.
2550
function find-config-arg {
@@ -73,19 +98,12 @@ if [[ ${configFile} =~ (^|/)eslint[.]config[.] ]]; then
7398
srcDir="$(dirname "${configFile}")"
7499
cd "${srcDir}"
75100

76-
# TEMP: Should do this in a concurrent-safe way.
77-
newConfigFile="${baseDir}/lib/$(basename "${configFile}")"
78-
cp "${configFile}" "${newConfigFile}"
101+
newConfigFile="$(copy-config-file "${configFile}" "${baseDir}/lib")" \
102+
|| exit "$?"
103+
trap "rm -rf \"${newConfigFile}\"" EXIT
79104

80-
echo \
81105
ESLINT_USE_FLAT_CONFIG=true \
82-
exec "${baseDir}/lib/node_modules/.bin/eslint" \
83-
--cache --cache-location "${baseDir}/cache" \
84-
--config "${newConfigFile}" \
85-
"${args[@]}"
86-
87-
ESLINT_USE_FLAT_CONFIG=true \
88-
exec "${baseDir}/lib/node_modules/.bin/eslint" \
106+
"${baseDir}/lib/node_modules/.bin/eslint" \
89107
--cache --cache-location "${baseDir}/cache" \
90108
--config "${newConfigFile}" \
91109
"${args[@]}"

0 commit comments

Comments
 (0)