Skip to content

Commit fd6fbd5

Browse files
committed
Fixes from copilot review
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
1 parent 23a947e commit fd6fbd5

3 files changed

Lines changed: 30 additions & 20 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ jobs:
7979

8080
- name: Set package version
8181
working-directory: ${{ env.WORKING_DIR }}
82-
run: npm version ${{ inputs.version }} --no-git-tag-version --allow-same-version
82+
run: npm version "$VERSION" --no-git-tag-version --allow-same-version
83+
env:
84+
VERSION: ${{ inputs.version }}
8385

8486
- name: Install musl tools
8587
if: contains(matrix.target, 'musl')

src/js-host-api/.npmignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ node_modules/
88
target/
99
Cargo.lock
1010
*.tgz
11+
*.node
1112
npm-debug.log*
1213
yarn-debug.log*
1314
yarn-error.log*
@@ -27,6 +28,7 @@ build.rs
2728
src/
2829
Cargo.toml
2930
test-examples.sh
31+
test-pack.sh
3032

3133
# Exclude artifacts directory (only used during CI)
3234
artifacts/

src/js-host-api/test-pack.sh

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@ if [ ! -f "package.json" ]; then
2222
exit 1
2323
fi
2424

25-
if ! ls ./*.node 1>/dev/null 2>&1; then
26-
echo "❌ Error: No .node binary found. Run 'npm run build' first." >&2
25+
# In CI the .node binary is already in npm/linux-x64-gnu/; locally it's in the project root.
26+
if ls npm/linux-x64-gnu/*.node 1>/dev/null 2>&1; then
27+
echo "📦 Platform binary already present in npm/linux-x64-gnu/"
28+
elif ls ./*.node 1>/dev/null 2>&1; then
29+
NATIVE_BINARY=$(ls ./*.node | head -1)
30+
BINARY_NAME=$(basename "${NATIVE_BINARY}")
31+
echo "📦 Copying ${BINARY_NAME} into platform package..."
32+
cp "${NATIVE_BINARY}" npm/linux-x64-gnu/"${BINARY_NAME}"
33+
else
34+
echo "❌ Error: No .node binary found. Run 'npm run build' first, or ensure CI artifacts are staged." >&2
2735
exit 1
2836
fi
2937

30-
# ── Step 1: Copy the .node binary into the platform package ─────────
31-
echo "📦 Preparing platform package..."
32-
NATIVE_BINARY=$(ls ./*.node | head -1)
33-
BINARY_NAME=$(basename "${NATIVE_BINARY}")
34-
cp "${NATIVE_BINARY}" npm/linux-x64-gnu/"${BINARY_NAME}"
35-
36-
# ── Step 2: Pack platform package ───────────────────────────────────
38+
# ── Step 1: Pack platform package ───────────────────────────────────
3739
echo "📦 Packing platform package (linux-x64-gnu)..."
3840
PLATFORM_TGZ=$(npm pack ./npm/linux-x64-gnu --pack-destination "${PACK_DIR}" 2>/dev/null)
3941
PLATFORM_TGZ_PATH="${PACK_DIR}/${PLATFORM_TGZ}"
4042
echo "${PLATFORM_TGZ_PATH}"
4143

42-
# ── Step 3: Pack main package ───────────────────────────────────────
44+
# ── Step 2: Pack main package ───────────────────────────────────────
4345
echo "📦 Packing main package..."
4446
MAIN_TGZ=$(npm pack --pack-destination "${PACK_DIR}" 2>/dev/null)
4547
MAIN_TGZ_PATH="${PACK_DIR}/${MAIN_TGZ}"
4648
echo "${MAIN_TGZ_PATH}"
4749

48-
# ── Step 4: Inspect tarball contents ────────────────────────────────
50+
# ── Step 3: Inspect tarball contents ────────────────────────────────
4951
echo ""
5052
echo "🔍 Platform package contents:"
5153
tar tzf "${PLATFORM_TGZ_PATH}" | sed 's/^/ /'
@@ -54,7 +56,7 @@ echo ""
5456
echo "🔍 Main package contents:"
5557
tar tzf "${MAIN_TGZ_PATH}" | sed 's/^/ /'
5658

57-
# ── Step 5: Validate main package contents ──────────────────────────
59+
# ── Step 4: Validate main package contents ──────────────────────────
5860
echo ""
5961
echo "✅ Validating main package contents..."
6062
MAIN_FILES=$(tar tzf "${MAIN_TGZ_PATH}")
@@ -79,7 +81,14 @@ for p in "${BANNED_PATTERNS[@]}"; do
7981
fi
8082
done
8183

82-
# ── Step 6: Validate platform package contents ──────────────────────
84+
if echo "${MAIN_FILES}" | grep -q '\.node$'; then
85+
echo " ❌ LEAKED: .node binary in main package (should only be in platform packages)" >&2
86+
exit 1
87+
else
88+
echo " ✅ No leak: *.node"
89+
fi
90+
91+
# ── Step 5: Validate platform package contents ──────────────────────
8392
echo ""
8493
echo "✅ Validating platform package contents..."
8594
PLATFORM_FILES=$(tar tzf "${PLATFORM_TGZ_PATH}")
@@ -91,7 +100,7 @@ else
91100
exit 1
92101
fi
93102

94-
# ── Step 7: Install from tarballs into a clean directory ────────────
103+
# ── Step 6: Install from tarballs into a clean directory ────────────
95104
echo ""
96105
echo "📥 Installing from tarballs into ${INSTALL_DIR}..."
97106
cd "${INSTALL_DIR}"
@@ -101,7 +110,7 @@ npm init -y --silent >/dev/null 2>&1
101110
npm install "${PLATFORM_TGZ_PATH}" --no-save 2>&1 | sed 's/^/ /'
102111
npm install "${MAIN_TGZ_PATH}" --no-save 2>&1 | sed 's/^/ /'
103112

104-
# ── Step 8: Smoke test — require and check exports ──────────────────
113+
# ── Step 7: Smoke test — require and check exports ──────────────────
105114
echo ""
106115
echo "🧪 Smoke test: require('@hyperlight/js-host-api')..."
107116
EXPORTS=$(node -e "
@@ -115,7 +124,7 @@ EXPORTS=$(node -e "
115124
")
116125
echo " ${EXPORTS}"
117126

118-
# ── Step 9: Hello World — end-to-end sandbox test ───────────────────
127+
# ── Step 8: Hello World — end-to-end sandbox test ───────────────────
119128
echo ""
120129
echo "🧪 Hello World: create sandbox, load handler, call it..."
121130
node -e "
@@ -144,9 +153,6 @@ node -e "
144153
main().catch(err => { console.error(' ❌', err.message); process.exit(1); });
145154
"
146155

147-
# ── Cleanup temp .node from platform dir ────────────────────────────
148-
rm -f "${SCRIPT_DIR}/npm/linux-x64-gnu/${BINARY_NAME}"
149-
150156
# ── Done ────────────────────────────────────────────────────────────
151157
echo ""
152158
echo "🎉 All checks passed! Package is ready to ship."

0 commit comments

Comments
 (0)