@@ -133,18 +133,37 @@ jobs:
133133 const p = JSON.parse(fs.readFileSync('package.json', 'utf8'));
134134 const v = p.version;
135135 p.optionalDependencies = {
136- 'rush-fs-win32-x64-msvc': v,
137- 'rush-fs-darwin-x64': v,
138- 'rush-fs-linux-x64-gnu': v,
139- 'rush-fs-darwin-arm64': v
136+ '@rush-fs/ rush-fs-win32-x64-msvc': v,
137+ '@rush-fs/ rush-fs-darwin-x64': v,
138+ '@rush-fs/ rush-fs-linux-x64-gnu': v,
139+ '@rush-fs/ rush-fs-darwin-arm64': v
140140 };
141141 fs.writeFileSync('package.json', JSON.stringify(p, null, 2));
142142 "
143+ - name : Update platform package names to use scope (@rush-fs/xxx)
144+ run : |
145+ for dir in npm/*/; do
146+ if [ -f "$dir/package.json" ]; then
147+ PKG_PATH="$dir/package.json"
148+ export PKG_PATH
149+ node -e "
150+ const fs = require('fs');
151+ const pkgPath = process.env.PKG_PATH;
152+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
153+ console.log('Updating package name from', pkg.name, 'to @rush-fs/' + pkg.name);
154+ if (!pkg.name.startsWith('@rush-fs/')) {
155+ pkg.name = '@rush-fs/' + pkg.name;
156+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
157+ }
158+ "
159+ fi
160+ done
143161 - name : Publish to npm
144162 run : |
145163 npm config set provenance true
146164 echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
147- # 读取 package.json 版本号,检查对应的 tag 是否已存在
165+ # 先 fetch tags,然后检查对应的 tag 是否已存在
166+ git fetch --tags --force
148167 VERSION=$(node -p "require('./package.json').version")
149168 TAG="v$VERSION"
150169 if git rev-parse "$TAG" >/dev/null 2>&1; then
@@ -154,6 +173,26 @@ jobs:
154173 echo "Tag $TAG does not exist, will create GitHub Release"
155174 pnpm prepublishOnly
156175 fi
176+ # prepublish 之后再次更新包名(因为 prepublish 可能会更新 package.json)
177+ for dir in npm/*/; do
178+ if [ -f "$dir/package.json" ]; then
179+ PKG_PATH="$dir/package.json"
180+ export PKG_PATH
181+ node -e "
182+ const fs = require('fs');
183+ const pkgPath = process.env.PKG_PATH;
184+ const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
185+ if (!pkg.name.startsWith('@rush-fs/')) {
186+ console.log('Fixing package name:', pkg.name, '-> @rush-fs/' + pkg.name);
187+ pkg.name = '@rush-fs/' + pkg.name;
188+ fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
189+ }
190+ "
191+ fi
192+ done
193+ # 主包 index.js 里 require 的是 rush-fs-xxx,改为 @rush-fs/rush-fs-xxx 才能找到已发布的平台包
194+ sed -i "s/require('rush-fs-/require('@rush-fs\/rush-fs-/g" index.js
195+ sed -i 's/require(\"rush-fs-/require(\"@rush-fs\/rush-fs-/g' index.js
157196 npm publish --access public
158197 env :
159198 GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments