@@ -23,6 +23,8 @@ PUBLISH_REGISTRY_HOST="${PUBLISH_REGISTRY_URL#https://}"
2323PUBLISH_REGISTRY_HOST=" ${PUBLISH_REGISTRY_HOST# http:// } "
2424PUBLISH_REGISTRY_HOST=" ${PUBLISH_REGISTRY_HOST%/ } "
2525BUILD_REGISTRY_URL=" ${BUILD_REGISTRY_URL:- https:// registry.npmjs.org} "
26+ PUBLISH_DEPENDENCY_WAIT_ATTEMPTS=" ${PUBLISH_DEPENDENCY_WAIT_ATTEMPTS:- 15} "
27+ PUBLISH_DEPENDENCY_WAIT_SECONDS=" ${PUBLISH_DEPENDENCY_WAIT_SECONDS:- 4} "
2628REGISTRY_FLAG=" --registry $PUBLISH_REGISTRY_URL "
2729ACCESS_FLAG=" "
2830if [[ -n " $PUBLISH_ACCESS " ]]; then
@@ -134,12 +136,7 @@ PACKAGE_PAGE_URL=""
134136if [[ " $PUBLISH_REGISTRY_URL " == " https://registry.npmjs.org" ]]; then
135137 PACKAGE_PAGE_URL=" https://www.npmjs.com/package/${PACKAGE_NAME} "
136138fi
137- CLIENT_PACKAGE_NAME=" $( node -p " Object.keys(JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8')).peerDependencies ?? {}).find((name) => name.endsWith('/client')) || ''" " $PUBLISH_PACKAGE_JSON " ) "
138- if [[ -z " $CLIENT_PACKAGE_NAME " ]]; then
139- echo " ❌ Could not determine the required app-facing client package from peerDependencies."
140- exit 1
141- fi
142- CLIENT_REGISTRY_URL=" ${PUBLISH_REGISTRY_URL} /${CLIENT_PACKAGE_NAME} "
139+ INTERNAL_PEER_DEPENDENCIES=" $( node -p " const pkg=JSON.parse(require('fs').readFileSync(process.argv[1], 'utf8')); const packageName=process.argv[2]; const scope = packageName.startsWith('@') ? packageName.split('/')[0] : ''; console.log(Object.keys(pkg.peerDependencies ?? {}).filter((name) => scope && name.startsWith(scope + '/') && name !== packageName).join('\n'))" " $PUBLISH_PACKAGE_JSON " " $PACKAGE_NAME " ) "
143140
144141echo " "
145142echo " ══════════════════════════════════════════════════════"
@@ -153,6 +150,37 @@ echo ""
153150
154151cd " $PUBLISH_DIR "
155152
153+ ensure_registry_auth_configured () {
154+ if [[ -n " ${NODE_AUTH_TOKEN:- } " ]]; then
155+ LOCAL_NPMRC=" $PUBLISH_DIR /.npmrc"
156+ npm config set " //${PUBLISH_REGISTRY_HOST} /:_authToken" " ${NODE_AUTH_TOKEN} " --location=project
157+ fi
158+ }
159+
160+ wait_for_dependency_version () {
161+ local dependency_name=" $1 "
162+ local dependency_registry_url=" ${PUBLISH_REGISTRY_URL} /${dependency_name} "
163+ local attempt
164+
165+ for (( attempt= 1 ; attempt<= PUBLISH_DEPENDENCY_WAIT_ATTEMPTS; attempt++ )) ; do
166+ if npm view " $dependency_name @$VERSION " version --silent $REGISTRY_FLAG > /dev/null 2>&1 ; then
167+ echo " ✅ Internal dependency ${dependency_name} @$VERSION is available on $PUBLISH_REGISTRY_NAME ."
168+ return 0
169+ fi
170+
171+ if [[ " $attempt " -lt " $PUBLISH_DEPENDENCY_WAIT_ATTEMPTS " ]]; then
172+ echo " ⏳ Waiting for ${dependency_name} @$VERSION to appear on $PUBLISH_REGISTRY_NAME (${attempt} /${PUBLISH_DEPENDENCY_WAIT_ATTEMPTS} )..."
173+ sleep " $PUBLISH_DEPENDENCY_WAIT_SECONDS "
174+ fi
175+ done
176+
177+ echo " ❌ ${dependency_name} @$VERSION is not published yet on $PUBLISH_REGISTRY_NAME . Publish it first."
178+ echo " registry API: $dependency_registry_url "
179+ exit 1
180+ }
181+
182+ ensure_registry_auth_configured
183+
156184NPM_TAG_FLAG=" --tag latest"
157185PRERELEASE_TAG=" "
158186if [[ " $VERSION " == * " -" * ]]; then
@@ -162,10 +190,11 @@ if [[ "$VERSION" == *"-"* ]]; then
162190 echo " 🏷️ Pre-release version detected — publishing to latest and adding dist-tag: $PRERELEASE_TAG "
163191fi
164192
165- if ! npm view " $CLIENT_PACKAGE_NAME @$VERSION " version --silent $REGISTRY_FLAG > /dev/null 2>&1 ; then
166- echo " ❌ ${CLIENT_PACKAGE_NAME} @$VERSION is not published yet on $PUBLISH_REGISTRY_NAME . Publish the main package first."
167- echo " registry API: $CLIENT_REGISTRY_URL "
168- exit 1
193+ if [[ -n " $INTERNAL_PEER_DEPENDENCIES " ]]; then
194+ while IFS= read -r dependency_name; do
195+ [[ -z " $dependency_name " ]] && continue
196+ wait_for_dependency_version " $dependency_name "
197+ done <<< " $INTERNAL_PEER_DEPENDENCIES"
169198fi
170199
171200if [[ " $DRY_RUN " == " true" ]]; then
@@ -188,8 +217,7 @@ if [[ -z "${NODE_AUTH_TOKEN:-}" ]]; then
188217 exit 1
189218fi
190219
191- LOCAL_NPMRC=" $PUBLISH_DIR /.npmrc"
192- npm config set " //${PUBLISH_REGISTRY_HOST} /:_authToken" " ${NODE_AUTH_TOKEN} " --location=project
220+ ensure_registry_auth_configured
193221
194222echo " "
195223echo " 🚀 Publishing $PACKAGE_NAME @$VERSION to $PUBLISH_REGISTRY_NAME ..."
0 commit comments