Skip to content

Commit 7fca09b

Browse files
authored
fix: restore index.js deleted by napi artifacts during publish (#355)
napi artifacts treats index.js as a stale managed root entry (listed in snappy.wasi.cjs metadata) because package.json main points to the hand-written main.js, so the published tarball silently missed index.js and require('snappy') failed with MODULE_NOT_FOUND. Restore it from git after moving artifacts, and fail the publish if any declared file is missing instead of letting npm pack skip it silently.
1 parent 2559ee3 commit 7fca09b

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

.github/workflows/CI.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,9 +426,25 @@ jobs:
426426
path: artifacts
427427
- name: Move artifacts
428428
run: yarn artifacts
429+
# `napi artifacts` deletes the committed index.js: the wasi loader metadata in
430+
# snappy.wasi.cjs lists it as a managed root entry, and since package.json's
431+
# main is main.js, artifacts treats index.js as stale. Restore it from git.
432+
- name: Restore index.js
433+
run: git checkout -- index.js
429434
- name: List packages
430435
run: ls -R ./npm
431436
shell: bash
437+
# npm pack silently skips missing entries of the `files` array; fail loudly instead
438+
- name: Verify package files exist
439+
run: |
440+
node -e "
441+
const fs = require('fs')
442+
const missing = require('./package.json').files.filter((f) => !fs.existsSync(f))
443+
if (missing.length) {
444+
console.error('Files declared in package.json but missing on disk: ' + missing.join(', '))
445+
process.exit(1)
446+
}
447+
"
432448
- name: Publish
433449
run: |
434450
if git log -1 --pretty=%B | grep "^[0-9]\+\.[0-9]\+\.[0-9]\+$";

0 commit comments

Comments
 (0)