@@ -47,19 +47,30 @@ yarn_args=("--ignore-engines")
4747
4848if [ -n " $dd_trace_override " ]; then
4949 echo " Node ${TARGET_NODE_MAJOR} is not supported by dd-trace v6, pinning dd-trace to ${dd_trace_override} "
50- # Rewrite the manifest against temporary backups and restore both tracked
51- # files on exit, however the install ends. node_modules keeps the resolved
52- # v5 line (which is what update_dist_version.sh reads), but leaving
53- # package.json/yarn.lock modified would make the next v6 build on this
54- # tree silently install the wrong tracer line against a dirty lockfile .
50+ # Rewrite the manifest against a temporary backup and preserve the lockfile
51+ # when the input tree contains one. Restore that initial state on exit,
52+ # however the install ends. node_modules keeps the resolved v5 line (which
53+ # is what update_dist_version.sh reads), but leaving package.json or a
54+ # generated v5 lockfile behind could affect the next build from this tree .
5555 package_backup=$( mktemp)
56- lock_backup=$( mktemp )
56+ lock_backup=" "
5757 cp package.json " $package_backup "
58- cp yarn.lock " $lock_backup "
58+ if [ -f yarn.lock ]; then
59+ lock_backup=$( mktemp)
60+ cp yarn.lock " $lock_backup "
61+ fi
5962 restore_manifests () {
6063 cp " $package_backup " package.json
61- cp " $lock_backup " yarn.lock
62- rm -f " $package_backup " " $lock_backup "
64+ if [ -n " $lock_backup " ]; then
65+ cp " $lock_backup " yarn.lock
66+ rm -f " $lock_backup "
67+ else
68+ # Reduced build contexts may omit the repository lockfile. Remove
69+ # the v5 lockfile generated by Yarn so the temporary pin still
70+ # leaves the input tree unchanged.
71+ rm -f yarn.lock
72+ fi
73+ rm -f " $package_backup "
6374 }
6475 trap restore_manifests EXIT
6576 node ./scripts/set_ddtrace_version.js " $( cat package.json) " " $dd_trace_override " > package-new.json
0 commit comments