Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 44 additions & 5 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,18 +133,37 @@ jobs:
const p = JSON.parse(fs.readFileSync('package.json', 'utf8'));
const v = p.version;
p.optionalDependencies = {
'rush-fs-win32-x64-msvc': v,
'rush-fs-darwin-x64': v,
'rush-fs-linux-x64-gnu': v,
'rush-fs-darwin-arm64': v
'@rush-fs/rush-fs-win32-x64-msvc': v,
'@rush-fs/rush-fs-darwin-x64': v,
'@rush-fs/rush-fs-linux-x64-gnu': v,
'@rush-fs/rush-fs-darwin-arm64': v
};
fs.writeFileSync('package.json', JSON.stringify(p, null, 2));
"
- name: Update platform package names to use scope (@rush-fs/xxx)
run: |
for dir in npm/*/; do
if [ -f "$dir/package.json" ]; then
PKG_PATH="$dir/package.json"
export PKG_PATH
node -e "
const fs = require('fs');
const pkgPath = process.env.PKG_PATH;
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
console.log('Updating package name from', pkg.name, 'to @rush-fs/' + pkg.name);
if (!pkg.name.startsWith('@rush-fs/')) {
pkg.name = '@rush-fs/' + pkg.name;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
}
"
fi
done
Comment on lines +143 to +160
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Misleading log fires unconditionally before the guard.

Line 153 (console.log('Updating package name from', ...)) runs before the if (!pkg.name.startsWith('@rush-fs/')) check. On the second pass — or if a name was already scoped — it prints an incorrect "to @rush-fs/@rush-fs/rush-fs-..." string.

🛠️ Proposed fix — move the log inside the branch
-              console.log('Updating package name from', pkg.name, 'to `@rush-fs/`' + pkg.name);
               if (!pkg.name.startsWith('@rush-fs/')) {
+                console.log('Updating package name from', pkg.name, 'to `@rush-fs/`' + pkg.name);
                 pkg.name = '@rush-fs/' + pkg.name;
                 fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
               }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/Release.yml around lines 143 - 160, The console.log inside
the node -e script logs the "Updating package name from ... to `@rush-fs/`..."
message unconditionally, which can produce incorrect output when pkg.name is
already scoped; move the console.log so it only runs inside the if guard that
checks !pkg.name.startsWith('@rush-fs/'), ensuring the log and the writeFileSync
only execute when pkg.name is actually being changed (refer to the inline
script's pkg, pkgPath, pkg.name, the if (!pkg.name.startsWith('@rush-fs/'))
block, and the console.log statement).

- name: Publish to npm
run: |
npm config set provenance true
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
# 读取 package.json 版本号,检查对应的 tag 是否已存在
# 先 fetch tags,然后检查对应的 tag 是否已存在
git fetch --tags --force
VERSION=$(node -p "require('./package.json').version")
TAG="v$VERSION"
if git rev-parse "$TAG" >/dev/null 2>&1; then
Expand All @@ -154,6 +173,26 @@ jobs:
echo "Tag $TAG does not exist, will create GitHub Release"
pnpm prepublishOnly
fi
# prepublish 之后再次更新包名(因为 prepublish 可能会更新 package.json)
for dir in npm/*/; do
if [ -f "$dir/package.json" ]; then
PKG_PATH="$dir/package.json"
export PKG_PATH
node -e "
const fs = require('fs');
const pkgPath = process.env.PKG_PATH;
const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
if (!pkg.name.startsWith('@rush-fs/')) {
console.log('Fixing package name:', pkg.name, '-> @rush-fs/' + pkg.name);
pkg.name = '@rush-fs/' + pkg.name;
fs.writeFileSync(pkgPath, JSON.stringify(pkg, null, 2));
}
"
fi
done
# 主包 index.js 里 require 的是 rush-fs-xxx,改为 @rush-fs/rush-fs-xxx 才能找到已发布的平台包
sed -i "s/require('rush-fs-/require('@rush-fs\/rush-fs-/g" index.js
sed -i 's/require(\"rush-fs-/require(\"@rush-fs\/rush-fs-/g' index.js
npm publish --access public
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "rush-fs",
"version": "0.0.3",
"version": "0.0.4",
"description": "High-performance drop-in replacement for Node.js fs module, powered by Rust",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/rush-fs/rush-fs.git"
"url": "git+https://github.com/CoderSerio/rush-fs.git"
},
"license": "MIT",
"browser": "browser.js",
Expand Down