abinfo "Disabling analytics ..."
dart --disable-analytics

abinfo "Fetching dependencies ..."
dart pub get

abinfo "Building dart-sass ..."
mkdir -pv "$SRCDIR"/build
mv -v "$SRCDIR/embedded-protocol" "$SRCDIR"/build/language
UPDATE_SASS_PROTOCOL=false dart run grinder protobuf
UPDATE_SASS_PROTOCOL=false dart run grinder pkg-npm-release

abinfo "Installing dart-sass-js ..."

# The following comments are from
# https://git.alpinelinux.org/aports/tree/community/dart-sass-js/APKBUILD
# Need to omit optional since it contains @parcel/watcher which has a C++ binary
npm install \
    --verbose \
    --install-links \
    --global \
    --prefix "$PKGDIR/usr" \
    "$SRCDIR/build/npm"

# TODO: --omit optional does not seem to work with the --global flag
# (https://github.com/npm/cli/issues/8284), so we have to remove
# @parcel/watcher manually
abinfo "Removing @parcel/watcher due to npm --omit=optional bug"
rm -rv "$PKGDIR"/usr/lib/node_modules/sass/node_modules/@parcel

abinfo "Setting correct ownership for npm-installed files"
chown -R root:root "$PKGDIR"
