Fix empty constants in published package - #378
Merged
Merged
Conversation
The release workflow passes the substitution commands as the
`prepare-script` input of a reusable workflow. Workflow-level `env` is not
propagated to called workflows, so `${CDN_URL}` and friends were unset in
that runner and `sed` replaced every `<@Placeholder@>` with an empty string.
That shipped 0.24.0 with empty constants: `PREVIEW_WIDGET_URL` became a
relative URL, so the preview widget iframe framed the host page instead of
the CDN, and the empty `PREVIEW_WIDGET_ORIGIN` broke the postMessage origin
check. The empty `CDN_URL` also disabled the app ID auto-detection, since
`script[src^='']` never matches.
Move the whole prepare step into `prepare-release.mjs`, so the values live
in the repository rather than in workflow environment variables, and fail
the release when a placeholder or an empty constant survives. The bundle and
widget jobs read the same values from `release-config.mjs` to keep a single
source of truth.
Also replace the substitutions in the preview workflow, which targeted
placeholders that do not exist in this package, and fix the preview widget
job caching the root `node_modules` under the same key as the bundle job,
which could skip installing the widget dependencies.
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
@croct/plug@0.24.0is published with every constant empty (unpkg):Reported by a user on
@croct/plug-next@0.11.0. SincePREVIEW_WIDGET_URLis empty, the iframesrcbuilt insrc/plugins/preview/index.ts:102becomes a relative URL, so the page frames itself instead of the CDN and gets blocked by the host's ownframe-ancestors. The widget never renders. The emptyPREVIEW_WIDGET_ORIGINindependently breaks thepostMessageorigin check insrc/plugins/preview/index.ts:128, so fixing only the URL would not be enough.The empty
CDN_URLalso silently disables app ID auto-detection:detectAppId()insrc/plug.ts:106queriesscript[src^=''], which never matches.Cause
#373moved the publish to a reusable workflow and passed the substitution commands as theprepare-scriptinput. A caller's workflow-levelenvblock is not propagated to a called reusable workflow, andpublish-public-npm-package.ymldefines noenvof its own, so${CDN_URL}and the rest were unset in that runner. Actions runsbash -eo pipefailwithout-u, so the unset variables expanded to empty strings andsedhappily replaced each<@placeholder@>with nothing. The publish succeeded.That also explains why only the npm package is affected:
$GITHUB_REF_NAMEis a runner default variable, so the version was set correctly.cdnandpreview-widgetjobs are ordinary jobs in this workflow, so their variables did resolve —widget-0.24.0.htmlis on the CDN and returns 200.Note that
${{ env.X }}is not a workaround either: theenvcontext is unavailable injobs.<job_id>.with.<input>.Fix
Move the prepare step into
prepare-release.mjs, so the values live in the repository instead of in workflow environment variables, and fail the release if any placeholder or empty constant survives — the check that would have caught this before publishing.release-config.mjsholds the values, and the bundle and widget jobs derive their variables from it, so there is a single source of truth rather than a second copy that can drift.Also in this PR:
deploy-preview.yamlsubstituted<@version@>,<@baseEndpointUrl@>and<@maxQueryLength@>, none of which exist in this package — they were copy-pasted from the SDK. PR previews have therefore always shipped literal<@cdnUrl@>placeholders, since well before#373. The preview now pins constants to the latest release tag, soPREVIEW_WIDGET_URLpoints at a widget that exists.preview-widgetjob cachedpath: node_moduleskeyed on the root lockfile while runningnpm ciinpreview/, using the same cache key as thecdnjob. A cache hit fromcdnwould make it skip installing the widget dependencies and fail the build. Now matches the pattern already used invalidate-preview.yaml.Verification
Each path was run locally:
widget-0.23.0.html(latest tag at the time of testing).plug.min.js.1.Out of scope
@croct/sdk@0.22.0shipsMAX_QUERY_LENGTH = parseInt("<@maxQueryLength@>", 10)→NaN(BASE_ENDPOINT_URLandVERSIONare substituted, only that one is missed). Same bug class insdk-js, and it leaks into the CDNplug.min.js, which bundles the SDK. The placeholder check here is deliberately scoped to the build output and not the bundle, so releases are not blocked on a dependency's defect.Follow-up
npm does not allow republishing
0.24.0, so this needs a0.24.1tag to reach users.