Skip to content

Commit cd9e484

Browse files
authored
fix: browsersync works in ES module environment (#68)
Co-authored-by: tyler36 <[email protected]>
1 parent da01151 commit cd9e484

File tree

5 files changed

+28
-2
lines changed

5 files changed

+28
-2
lines changed
File renamed without changes.

commands/web/browsersync

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
## ExecRaw: true
88

99
echo "Proxying browsersync on ${DDEV_PRIMARY_URL}:3000"
10-
browser-sync start -c /var/www/html/.ddev/browser-sync.js | grep -v "Access URLs\|--------------------\|Local: http\|External: http"
10+
browser-sync start -c /var/www/html/.ddev/browser-sync.cjs | grep -v "Access URLs\|--------------------\|Local: http\|External: http"

install.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pre_install_actions:
1111
project_files:
1212
- config.browsersync.yaml
1313
- web-build/Dockerfile.ddev-browsersync
14-
- browser-sync.js
14+
- browser-sync.cjs
1515
- commands/web/browsersync
1616
- scripts/wp-config-ddev-browsersync.php
1717
- scripts/remove-wordpress-settings.sh
@@ -24,6 +24,10 @@ post_install_actions:
2424
if ( test -f "$HOME/.ddev/commands/web/browsersync" ) ; then
2525
echo "Note: '~/.ddev/commands/web/browsersync' is no longer required and can be safely removed." && exit 0
2626
fi
27+
#ddev-description:Check for 'browser-sync.js'
28+
if ( test -f "$DDEV_APPROOT/commands/web/browsersync.js" ) ; then
29+
echo "Note: '$DDEV_APPROOT/commands/web/browsersync.js' is no longer required and can be safely removed." && exit 0
30+
fi
2731
#ddev-nodisplay
2832
#ddev-description:Remove old 'docker-compose.browsersync.yaml'
2933
if grep "#ddev-generated" $DDEV_APPROOT/.ddev/docker-compose.browsersync.yaml 2>/dev/null; then rm -f "$DDEV_APPROOT/.ddev/docker-compose.browsersync.yaml"; fi

tests/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "test-browsersync",
3+
"type": "module"
4+
}

tests/test.bats

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,21 @@ healthcheck() {
6060
# Check service works
6161
healthcheck
6262
}
63+
64+
@test "ES module environment" {
65+
set -eu -o pipefail
66+
cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )
67+
68+
# Setup NPM environment
69+
cp "${DIR}/tests/package.json" "${TESTDIR}"
70+
71+
echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3
72+
ddev addon get ${DIR}
73+
74+
ddev restart
75+
./run-ddev-browsersync &
76+
sleep 5
77+
78+
# Check service works
79+
healthcheck
80+
}

0 commit comments

Comments
 (0)