anbot

root / test / core-imports.sh

1050 bytes

#!/bin/sh
set -eu
cd "$(git rev-parse --show-toplevel)"
fail=0
# core.mjs has no imports at all; the other platform-free modules may import
# only relative platform-free modules.
if grep -nE '^\s*import[[:space:]\(]' core.mjs; then fail=1; fi
for file in core.mjs store.mjs store-browser.mjs sync.mjs webui.mjs; do
  if grep -nE "node:|__dirname|__filename|require\(" "$file"; then fail=1; fi
  if grep -nwE 'Buffer|process|require' "$file"; then fail=1; fi
done
if grep -nE 'node:|__dirname|__filename|require\(' social.mjs ||
  grep -nwE 'Buffer|process|require' social.mjs; then fail=1; fi
if grep -E '^\s*import[[:space:]\(]' social.mjs | grep -v "from './core\.mjs'$"; then fail=1; fi
# sync.mjs may import only the platform-free core and social modules.
if grep -nE "from '[^']+'$" sync.mjs | grep -v "from './core\.mjs'$" |
  grep -v "from './social\.mjs'$"; then fail=1; fi
if [ "$fail" -ne 0 ]; then
  echo 'FAIL: core modules must stay platform-free.' >&2
  exit 1
fi
printf 'PASS: core modules have no platform-only imports or globals.\n'

Git ยท Social feed