Skip to content

Commit fa010ba

Browse files
committed
fix: strip lifecycle scripts from artifacts instead of failing
1 parent c65f89b commit fa010ba

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

.github/workflows/publish-preview.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ jobs:
188188
# execute during `yarn npm publish` with the NPM token in the environment
189189
# (enableScripts: false does NOT prevent pack/publish lifecycle scripts).
190190
# It could also override publishConfig.registry to exfiltrate the token.
191-
- name: Validate artifact manifests
191+
# We strip dangerous lifecycle scripts (they already ran during build)
192+
# and block unexpected registries outright.
193+
- name: Sanitize and validate artifact manifests
192194
run: |
193195
bad=0
194196
if [[ "${{ inputs.is-monorepo }}" == "true" ]]; then
@@ -201,10 +203,13 @@ jobs:
201203
exit 1
202204
fi
203205
for f in "${manifests[@]}"; do
206+
# Strip lifecycle scripts that run during pack/publish
204207
if jq -e '.scripts // {} | keys[] | select(test("^(pre|post)(pack|publish)"))' "$f" > /dev/null 2>&1; then
205-
echo "::error::Forbidden lifecycle script in $f"
206-
bad=1
208+
echo "Stripping pack/publish lifecycle scripts from $f"
209+
jq 'if .scripts then .scripts |= with_entries(select(.key | test("^(pre|post)(pack|publish)") | not)) else . end' "$f" > "${f}.tmp"
210+
mv "${f}.tmp" "$f"
207211
fi
212+
# Block unexpected registries
208213
reg=$(jq -r '.publishConfig.registry // ""' "$f")
209214
if [[ -n "$reg" && "$reg" != "https://registry.npmjs.org/" ]]; then
210215
echo "::error::Unexpected registry in $f: $reg"

0 commit comments

Comments
 (0)