@@ -50,6 +50,21 @@ if [ ! -d "$BIN_DIR" ]; then
5050 exit 1
5151fi
5252
53+ # Always copy resources to pick up script/config/patch changes.
54+ # This keeps prep resilient when invoked from different working directories
55+ # while still expecting files under $BIN_DIR/mac_vscode_resources.
56+ log " -- Copying resources to $BIN_DIR /mac_vscode_resources"
57+ SRC_RES_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
58+ DST_RES_DIR=" $BIN_DIR /mac_vscode_resources"
59+ mkdir -p " $DST_RES_DIR "
60+ check_status " resource directory creation"
61+ if [ " $SRC_RES_DIR " = " $DST_RES_DIR " ]; then
62+ log " ✓ Resource copy skipped (already running from $DST_RES_DIR )"
63+ else
64+ cp -r " $SRC_RES_DIR " /* " $DST_RES_DIR /"
65+ check_status " resource copy"
66+ fi
67+
5368cd $BIN_DIR || { log " ERROR - Failed to change to $BIN_DIR " ; exit 1; }
5469
5570# 1. Ensure Xcode command-line tools are installed
@@ -160,29 +175,83 @@ check_status "VS Code checkout v1.106.2"
160175
161176# 7. Install npm dependencies
162177log " -- Installing npm dependencies (this may take 10-20 minutes)..."
163- # First attempt - this will fail on @vscode/spdlog due to Apple Clang consteval issue on Darwin 25.4+
164- npm install --loglevel=error 2> /dev/null
165-
166- # Patch bundled fmt in @vscode/spdlog to work around Apple Clang consteval issue
167- SPDLOG_FMT_DIR=" node_modules/@vscode/spdlog/deps/spdlog/include/spdlog/fmt/bundled"
168- if [ -d " $SPDLOG_FMT_DIR " ]; then
169- log " -- Patching spdlog fmt headers (consteval -> constexpr)"
170- sed -i ' ' ' s/consteval/constexpr/g' " $SPDLOG_FMT_DIR /format.h"
171- sed -i ' ' ' s/consteval/constexpr/g' " $SPDLOG_FMT_DIR /core.h"
172- check_status " spdlog fmt patch"
173-
174- # Rebuild just spdlog with the patched source (npm uses its bundled node-gyp)
175- log " -- Rebuilding @vscode/spdlog..."
176- npm rebuild @vscode/spdlog
177- check_status " spdlog rebuild"
178+ # Install deps without lifecycle scripts first so @vscode/spdlog headers are
179+ # guaranteed to exist for patching before node-gyp build kicks in.
180+ NPM_FIRST_LOG=" $LOG_DIR /mac_vscode_npm_install_first.log"
181+ log " phase-1 npm install (--ignore-scripts) output -> $NPM_FIRST_LOG "
182+ npm install --ignore-scripts --loglevel=error >> " $NPM_FIRST_LOG " 2>&1
183+ NPM_FIRST_RC=$?
184+ if [ $NPM_FIRST_RC -ne 0 ]; then
185+ log " ERROR - First npm install phase failed (rc=$NPM_FIRST_RC )."
186+ log " ERROR - See $NPM_FIRST_LOG for the underlying error."
187+ exit 1
188+ fi
189+ log " ✓ phase-1 npm install completed"
190+
191+ # Apply a checked-in patch (durable and auditable) instead of ad-hoc string
192+ # replacement in the script. This keeps the workaround deterministic for the
193+ # pinned VS Code tag.
194+ # TODO: Revisit/remove this patch when we move off VS Code 1.106.2 or when
195+ # upstream @vscode/spdlog/fmt builds cleanly on Darwin 25+ with Node 22.
196+ PATCH_FILE=" $BIN_DIR /mac_vscode_resources/spdlog_fmt_darwin25.patch"
197+ if [ ! -f " $PATCH_FILE " ]; then
198+ log " ERROR - Required patch file not found: $PATCH_FILE "
199+ exit 1
200+ fi
201+
202+ CORE_H=" node_modules/@vscode/spdlog/deps/spdlog/include/spdlog/fmt/bundled/core.h"
203+ if [ ! -f " $CORE_H " ]; then
204+ log " ERROR - Expected spdlog header not found: $CORE_H "
205+ exit 1
206+ fi
207+
208+ # Fast-path: if this package build already carries the Apple-compatible
209+ # constexpr form, skip patching entirely.
210+ if grep -Eq ' ^#[[:space:]]*define[[:space:]]+FMT_CONSTEVAL[[:space:]]+constexpr$' " $CORE_H " ; then
211+ log " ✓ spdlog/fmt already in compatible state (FMT_CONSTEVAL constexpr)"
178212else
179- log " -- No spdlog fmt patch needed"
213+ log " -- Applying spdlog/fmt compatibility patch: $PATCH_FILE "
214+ if git apply --check " $PATCH_FILE " > /dev/null 2>&1 ; then
215+ git apply " $PATCH_FILE "
216+ check_status " spdlog/fmt patch apply"
217+ elif git apply --reverse --check " $PATCH_FILE " > /dev/null 2>&1 ; then
218+ log " ✓ spdlog/fmt patch already applied"
219+ else
220+ # Fallback for minor upstream drift where patch hunk context changed
221+ # but the required token replacement is still well-defined.
222+ if grep -Eq ' ^#[[:space:]]*define[[:space:]]+FMT_CONSTEVAL[[:space:]]+consteval$' " $CORE_H " ; then
223+ log " -- Patch did not apply cleanly; applying tolerant fallback edit in $CORE_H "
224+ sed -E -i ' ' ' s@^#[[:space:]]*define[[:space:]]+FMT_CONSTEVAL[[:space:]]+consteval$@# define FMT_CONSTEVAL constexpr@' " $CORE_H "
225+ check_status " spdlog/fmt fallback edit"
226+ if grep -Eq ' ^#[[:space:]]*define[[:space:]]+FMT_CONSTEVAL[[:space:]]+constexpr$' " $CORE_H " ; then
227+ log " ✓ spdlog/fmt fallback edit applied"
228+ else
229+ log " ERROR - spdlog/fmt fallback edit failed to verify"
230+ exit 1
231+ fi
232+ else
233+ log " ERROR - spdlog/fmt patch does not apply cleanly and FMT_CONSTEVAL token was not found in core.h"
234+ exit 1
235+ fi
236+ fi
180237fi
181238
239+ # Rebuild just spdlog with the patched source (npm uses its bundled node-gyp)
240+ log " -- Rebuilding @vscode/spdlog..."
241+ npm rebuild @vscode/spdlog
242+ check_status " spdlog rebuild"
243+
182244# Re-run npm install to complete any remaining steps (postinstall, etc.)
183245log " -- Completing npm install..."
184- npm install --loglevel=error
185- check_status " npm install"
246+ NPM_FINAL_LOG=" $LOG_DIR /mac_vscode_npm_install_final.log"
247+ log " phase-2 npm install output -> $NPM_FINAL_LOG "
248+ npm install --loglevel=error >> " $NPM_FINAL_LOG " 2>&1
249+ if [ $? -ne 0 ]; then
250+ log " ERROR - Final npm install failed."
251+ log " ERROR - See $NPM_FINAL_LOG for details."
252+ exit 1
253+ fi
254+ log " ✓ npm install successful"
186255
187256log " "
188257log " ✓ All checks passed"
0 commit comments