Skip to content

Commit 2bbae42

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

3 files changed

Lines changed: 35 additions & 22 deletions

File tree

.github/workflows/npm-publish.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
fetch-depth: 0
6363

6464
- name: Hyperlight setup
65-
uses: hyperlight-dev/ci-setup-workflow@v1.8.0
65+
uses: hyperlight-dev/ci-setup-workflow@v1.9.0
6666
with:
6767
rust-toolchain: "1.89"
6868

@@ -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: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
# Validate npm packages by packing to /tmp and installing into a clean project.
33
# Simulates what a consumer would experience after `npm install @hyperlight/js-host-api`.
44
#
5-
# Prerequisites: run `npm run build` first to produce the .node binary.
5+
# Prerequisites:
6+
# - Native .node binary must exist (via `npm run build`)
7+
# - Generated bindings (index.js, index.d.ts) must be present
8+
# (via `npx napi prepublish -t npm` or the CI workflow)
69

710
set -euo pipefail
811

@@ -22,30 +25,32 @@ if [ ! -f "package.json" ]; then
2225
exit 1
2326
fi
2427

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

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 ───────────────────────────────────
41+
# ── Step 1: Pack platform package ───────────────────────────────────
3742
echo "📦 Packing platform package (linux-x64-gnu)..."
3843
PLATFORM_TGZ=$(npm pack ./npm/linux-x64-gnu --pack-destination "${PACK_DIR}" 2>/dev/null)
3944
PLATFORM_TGZ_PATH="${PACK_DIR}/${PLATFORM_TGZ}"
4045
echo "${PLATFORM_TGZ_PATH}"
4146

42-
# ── Step 3: Pack main package ───────────────────────────────────────
47+
# ── Step 2: Pack main package ───────────────────────────────────────
4348
echo "📦 Packing main package..."
4449
MAIN_TGZ=$(npm pack --pack-destination "${PACK_DIR}" 2>/dev/null)
4550
MAIN_TGZ_PATH="${PACK_DIR}/${MAIN_TGZ}"
4651
echo "${MAIN_TGZ_PATH}"
4752

48-
# ── Step 4: Inspect tarball contents ────────────────────────────────
53+
# ── Step 3: Inspect tarball contents ────────────────────────────────
4954
echo ""
5055
echo "🔍 Platform package contents:"
5156
tar tzf "${PLATFORM_TGZ_PATH}" | sed 's/^/ /'
@@ -54,7 +59,7 @@ echo ""
5459
echo "🔍 Main package contents:"
5560
tar tzf "${MAIN_TGZ_PATH}" | sed 's/^/ /'
5661

57-
# ── Step 5: Validate main package contents ──────────────────────────
62+
# ── Step 4: Validate main package contents ──────────────────────────
5863
echo ""
5964
echo "✅ Validating main package contents..."
6065
MAIN_FILES=$(tar tzf "${MAIN_TGZ_PATH}")
@@ -79,7 +84,14 @@ for p in "${BANNED_PATTERNS[@]}"; do
7984
fi
8085
done
8186

82-
# ── Step 6: Validate platform package contents ──────────────────────
87+
if echo "${MAIN_FILES}" | grep -q '\.node$'; then
88+
echo " ❌ LEAKED: .node binary in main package (should only be in platform packages)" >&2
89+
exit 1
90+
else
91+
echo " ✅ No leak: *.node"
92+
fi
93+
94+
# ── Step 5: Validate platform package contents ──────────────────────
8395
echo ""
8496
echo "✅ Validating platform package contents..."
8597
PLATFORM_FILES=$(tar tzf "${PLATFORM_TGZ_PATH}")
@@ -91,7 +103,7 @@ else
91103
exit 1
92104
fi
93105

94-
# ── Step 7: Install from tarballs into a clean directory ────────────
106+
# ── Step 6: Install from tarballs into a clean directory ────────────
95107
echo ""
96108
echo "📥 Installing from tarballs into ${INSTALL_DIR}..."
97109
cd "${INSTALL_DIR}"
@@ -101,7 +113,7 @@ npm init -y --silent >/dev/null 2>&1
101113
npm install "${PLATFORM_TGZ_PATH}" --no-save 2>&1 | sed 's/^/ /'
102114
npm install "${MAIN_TGZ_PATH}" --no-save 2>&1 | sed 's/^/ /'
103115

104-
# ── Step 8: Smoke test — require and check exports ──────────────────
116+
# ── Step 7: Smoke test — require and check exports ──────────────────
105117
echo ""
106118
echo "🧪 Smoke test: require('@hyperlight/js-host-api')..."
107119
EXPORTS=$(node -e "
@@ -115,7 +127,7 @@ EXPORTS=$(node -e "
115127
")
116128
echo " ${EXPORTS}"
117129

118-
# ── Step 9: Hello World — end-to-end sandbox test ───────────────────
130+
# ── Step 8: Hello World — end-to-end sandbox test ───────────────────
119131
echo ""
120132
echo "🧪 Hello World: create sandbox, load handler, call it..."
121133
node -e "
@@ -144,9 +156,6 @@ node -e "
144156
main().catch(err => { console.error(' ❌', err.message); process.exit(1); });
145157
"
146158

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

0 commit comments

Comments
 (0)