2020 with :
2121 node-version : 20
2222 cache : " npm"
23- registry-url : " https://registry.npmjs.org"
2423
2524 - name : Install dependencies
2625 run : npm install
@@ -55,24 +54,78 @@ jobs:
5554 # Create a backup of original package.json
5655 cp package.json package.json.bak
5756
58- # Update name and version for preview
59- npm pkg set name="${{ steps.preview_info.outputs.package_name }}"
60- npm pkg set version="${{ steps.preview_info.outputs.version }}"
57+ # Get the official package name for safety checks
58+ OFFICIAL_PACKAGE=$(node -p "require('./package.json').name")
59+ PREVIEW_PACKAGE="${{ steps.preview_info.outputs.package_name }}"
60+
61+ echo "Official package: $OFFICIAL_PACKAGE"
62+ echo "Preview package: $PREVIEW_PACKAGE"
63+
64+ # Safety check: Ensure we're not accidentally using the official package name
65+ if [ "$PREVIEW_PACKAGE" = "$OFFICIAL_PACKAGE" ]; then
66+ echo "❌ ERROR: Preview package name matches official package name!"
67+ echo "This would overwrite the official package. Aborting."
68+ exit 1
69+ fi
70+
71+ # Update name with error handling
72+ if ! npm pkg set name="$PREVIEW_PACKAGE"; then
73+ echo "❌ ERROR: Failed to set package name to $PREVIEW_PACKAGE"
74+ exit 1
75+ fi
76+
77+ # Update version with error handling
78+ if ! npm pkg set version="${{ steps.preview_info.outputs.version }}"; then
79+ echo "❌ ERROR: Failed to set package version to ${{ steps.preview_info.outputs.version }}"
80+ exit 1
81+ fi
82+
83+ echo "✅ Package.json updated successfully"
84+
85+ - name: Final safety check before publish
86+ run: |
87+ # Double-check package name one more time before publishing
88+ CURRENT_PACKAGE_NAME=$(node -p "require('./package.json').name")
89+ OFFICIAL_PACKAGE="@base44/sdk"
90+
91+ echo "About to publish: $CURRENT_PACKAGE_NAME"
92+
93+ if [ "$CURRENT_PACKAGE_NAME" = "$OFFICIAL_PACKAGE" ]; then
94+ echo "❌ CRITICAL ERROR: About to publish to official package name!"
95+ echo "This is not allowed. Check the workflow configuration."
96+ exit 1
97+ fi
98+
99+ echo "✅ Safety check passed. Package name is safe to publish."
61100
62101 - name : Publish preview package
63- run : npm publish
102+ run : |
103+ if npm publish; then
104+ echo "✅ Package published successfully"
105+ else
106+ echo "❌ Package publish failed"
107+ exit 1
108+ fi
64109 env :
65110 NODE_AUTH_TOKEN : ${{ secrets.NPM_TOKEN }}
66111
67112 - name : Restore original package.json
68- run : mv package.json.bak package.json
113+ run : |
114+ if [ -f package.json.bak ]; then
115+ mv package.json.bak package.json
116+ echo "✅ Original package.json restored"
117+ else
118+ echo "❌ WARNING: Backup file package.json.bak not found"
119+ echo "This could indicate an earlier step failed"
120+ fi
69121
70122 - name : Comment PR with install instructions
71123 uses : actions/github-script@v6
72124 with :
73125 script : |
74126 const fullPackage = '${{ steps.preview_info.outputs.full_package }}';
75127 const installCmd = `npm i ${fullPackage}`;
128+ const aliasInstallCmd = `npm i "@base44/sdk@npm:${fullPackage}"`;
76129 const body = `### 🚀 Package Preview Available!
77130
78131 ---
@@ -83,6 +136,22 @@ jobs:
83136 ${installCmd}
84137 \`\`\`
85138
139+ **Prefer not to change any import paths? Install using npm alias so your code still imports \\`@base44/sdk\\`:**
140+
141+ \`\`\`sh
142+ ${aliasInstallCmd}
143+ \`\`\`
144+
145+ Or add it to your \`package.json\` dependencies:
146+
147+ \`\`\`json
148+ {
149+ "dependencies": {
150+ "@base44/sdk": "npm:${fullPackage}"
151+ }
152+ }
153+ \`\`\`
154+
86155 - 📦 **Preview Package**: \`${fullPackage}\`
87156 - 🔗 [View this commit on GitHub](https://github.com/${{ github.repository }}/commit/${{ github.sha }})
88157
0 commit comments