Skip to content

Commit

Permalink
fix: handle js_library 1p deps correctly in js_run_devserver
Browse files Browse the repository at this point in the history
  • Loading branch information
gregmagolan committed Jul 27, 2024
1 parent c949bd3 commit cf18bb4
Show file tree
Hide file tree
Showing 24 changed files with 234 additions and 62 deletions.
1 change: 1 addition & 0 deletions e2e/webpack_devserver/.bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
mylib/node_modules
mypkg/node_modules
10 changes: 8 additions & 2 deletions e2e/webpack_devserver/mylib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_package(
npm_link_all_packages(name = "node_modules")

js_library(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
visibility = ["//visibility:public"],
deps = [
":node_modules",
],
)
2 changes: 1 addition & 1 deletion e2e/webpack_devserver/mylib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const packageJson = require('./package.json')
const chalk = require('chalk')
module.exports = {
name: () => chalk.blue(packageJson.name),
name: () => chalk.green(packageJson.name),
}
10 changes: 10 additions & 0 deletions e2e/webpack_devserver/mypkg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
visibility = ["//visibility:public"],
)
5 changes: 5 additions & 0 deletions e2e/webpack_devserver/mypkg/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const packageJson = require('./package.json')
const chalk = require('chalk')
module.exports = {
name: () => chalk.blue(packageJson.name),
}
6 changes: 6 additions & 0 deletions e2e/webpack_devserver/mypkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@mycorp/mypkg",
"dependencies": {
"chalk": "^4"
}
}
3 changes: 2 additions & 1 deletion e2e/webpack_devserver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"lodash": "4.17.21",
"@mycorp/mylib": "workspace:*"
"@mycorp/mylib": "workspace:*",
"@mycorp/mypkg": "workspace:*"
}
}
9 changes: 9 additions & 0 deletions e2e/webpack_devserver/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/webpack_devserver/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- '.'
- 'mylib'
- 'mypkg'
61 changes: 46 additions & 15 deletions e2e/webpack_devserver/serve_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ ibazel_pid="$!"
function _exit {
kill "$ibazel_pid"
git checkout src/index.html >/dev/null 2>&1
git checkout mylib/index.js >/dev/null 2>&1
git checkout mypkg/index.js >/dev/null 2>&1
rm -f "$ibazel_logs"
}
trap _exit EXIT
Expand All @@ -48,11 +48,18 @@ if ! curl http://localhost:8080/index.html --fail 2>/dev/null | grep "Getting St
exit 1
fi

# from @mycorp/mypkg
if ! curl http://localhost:8080/main.js --fail 2>/dev/null | grep "chalk.blue(packageJson.name)"; then
echo "ERROR: Expected http://localhost:8080/main.js to contain 'chalk.blue(packageJson.name)'"
exit 1
fi

# from @mycorp/mylib
if ! curl http://localhost:8080/main.js --fail 2>/dev/null | grep "chalk.green(packageJson.name)"; then
echo "ERROR: Expected http://localhost:8080/main.js to contain 'chalk.green(packageJson.name)'"
exit 1
fi

_sedi 's#Getting Started#Goodbye#' src/index.html

echo "Waiting 5 seconds for ibazel rebuild after change to src/index.html..."
Expand All @@ -63,45 +70,69 @@ if ! curl http://localhost:8080/index.html --fail 2>/dev/null | grep "Goodbye";
exit 1
fi

_sedi 's#blue#red#' mylib/index.js
_sedi 's#blue#red#' mypkg/index.js

echo "Waiting 5 seconds for ibazel rebuild after change to mylib/index.js..."
echo "Waiting 5 seconds for ibazel rebuild after change to mypkg/index.js..."
sleep 5

# from @mycorp/mypkg
if ! curl http://localhost:8080/main.js --fail 2>/dev/null | grep "chalk.red(packageJson.name)"; then
echo "ERROR: Expected http://localhost:8080/main.js to contain 'chalk.red(packageJson.name)'"
exit 1
fi

_sedi 's#green#cyan#' mylib/index.js

echo "Waiting 5 seconds for ibazel rebuild after change to mylib/index.js..."
sleep 5

# from @mycorp/mylib
if ! curl http://localhost:8080/main.js --fail 2>/dev/null | grep "chalk.cyan(packageJson.name)"; then
echo "ERROR: Expected http://localhost:8080/main.js to contain 'chalk.cyan(packageJson.name)'"
exit 1
fi

echo "Checking log file $ibazel_logs"

count=$(grep -c "Syncing file node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib/index.js" "$ibazel_logs" || true)
count=$(grep -c "Syncing symlink node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib (1p)" "$ibazel_logs" || true)
if [[ "$count" -ne 1 ]]; then
echo "ERROR: expected to have synced @mycorp/mylib symlink 1 time but found ${count}"
exit 1
fi

count=$(grep -c "Syncing file node_modules/.aspect_rules_js/@mycorp+mypkg@0.0.0/node_modules/@mycorp/mypkg/index.js" "$ibazel_logs" || true)
if [[ "$count" -ne 2 ]]; then
echo "ERROR: expected to have synced @mycorp/mylib/index.js 2 times but found ${count}"
echo "ERROR: expected to have synced @mycorp/mypkg/index.js 2 times but found ${count}"
exit 1
fi

count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib/index.js since its timestamp has not changed" "$ibazel_logs" || true)
if [[ "$count" -ne 1 ]]; then
echo "ERROR: expected to have skipped @mycorp/mylib/index.js due to timestamp 1 time but found ${count}"
count=$(grep -c "Syncing file mylib/index.js" "$ibazel_logs" || true)
if [[ "$count" -ne 2 ]]; then
echo "ERROR: expected to have synced mylib/index.js 2 times but found ${count}"
exit 1
fi

count=$(grep -c "Syncing file node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib/package.json" "$ibazel_logs" || true)
if [[ "$count" -ne 1 ]]; then
echo "ERROR: expected to have synced @mycorp/mylib/package.json 1 time but found ${count}"
count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mypkg@0.0.0/node_modules/@mycorp/mypkg/index.js since its timestamp has not changed" "$ibazel_logs" || true)
if [[ "$count" -ne 2 ]]; then
echo "ERROR: expected to have skipped @mycorp/mypkg/index.js due to timestamp 2 times but found ${count}"
exit 1
fi

count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib/package.json since its timestamp has not changed" "$ibazel_logs" || true)
count=$(grep -c "Syncing file node_modules/.aspect_rules_js/@mycorp+mypkg@0.0.0/node_modules/@mycorp/mypkg/package.json" "$ibazel_logs" || true)
if [[ "$count" -ne 1 ]]; then
echo "ERROR: expected to have skipped @mycorp/mylib/package.json due to timestamp 1 time but found ${count}"
echo "ERROR: expected to have synced @mycorp/mypkg/package.json 1 time but found ${count}"
exit 1
fi

count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mypkg@0.0.0/node_modules/@mycorp/mypkg/package.json since its timestamp has not changed" "$ibazel_logs" || true)
if [[ "$count" -ne 2 ]]; then
echo "ERROR: expected to have skipped @mycorp/mypkg/package.json due to timestamp 2 times but found ${count}"
exit 1
fi

count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mylib@0.0.0/node_modules/@mycorp/mylib/package.json since contents have not changed" "$ibazel_logs" || true)
count=$(grep -c "Skipping file node_modules/.aspect_rules_js/@mycorp+mypkg@0.0.0/node_modules/@mycorp/mypkg/package.json since contents have not changed" "$ibazel_logs" || true)
if [[ "$count" -ne 1 ]]; then
echo "ERROR: expected to have skipped @mycorp/mylib/package.json due to contents 1 time but found ${count}"
echo "ERROR: expected to have skipped @mycorp/mypkg/package.json due to contents 1 times but found ${count}"
exit 1
fi

Expand Down
8 changes: 6 additions & 2 deletions e2e/webpack_devserver/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import _ from 'lodash'
import { name } from '@mycorp/mylib'
import { name as mylibname } from '@mycorp/mylib'
import { name as mypkgname } from '@mycorp/mypkg'

function component() {
const element = document.createElement('div')

// Lodash, currently included via a script, is required for this line to work
element.innerHTML = _.join(['Hello', 'webpack', name()], ' ')
element.innerHTML = _.join(
['Hello', 'webpack', mylibname(), mypkgname()],
' '
)

return element
}
Expand Down
1 change: 1 addition & 0 deletions e2e/webpack_devserver_esm/.bazelignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
mylib/node_modules
mypkg/node_modules
10 changes: 8 additions & 2 deletions e2e/webpack_devserver_esm/mylib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@npm//:defs.bzl", "npm_link_all_packages")

npm_package(
npm_link_all_packages(name = "node_modules")

js_library(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
visibility = ["//visibility:public"],
deps = [
":node_modules",
],
)
2 changes: 1 addition & 1 deletion e2e/webpack_devserver_esm/mylib/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import packageJson from './package.json'
import chalk from 'chalk'
export function name() {
return chalk.blue(packageJson.name)
return chalk.green(packageJson.name)
}
10 changes: 10 additions & 0 deletions e2e/webpack_devserver_esm/mypkg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
load("@aspect_rules_js//npm:defs.bzl", "npm_package")

npm_package(
name = "pkg",
srcs = [
"index.js",
"package.json",
],
visibility = ["//visibility:public"],
)
5 changes: 5 additions & 0 deletions e2e/webpack_devserver_esm/mypkg/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import packageJson from './package.json'
import chalk from 'chalk'
export function name() {
return chalk.blue(packageJson.name)
}
6 changes: 6 additions & 0 deletions e2e/webpack_devserver_esm/mypkg/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@mycorp/mypkg",
"dependencies": {
"chalk": "^4"
}
}
3 changes: 2 additions & 1 deletion e2e/webpack_devserver_esm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"lodash": "4.17.21",
"@mycorp/mylib": "workspace:*"
"@mycorp/mylib": "workspace:*",
"@mycorp/mypkg": "workspace:*"
}
}
9 changes: 9 additions & 0 deletions e2e/webpack_devserver_esm/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions e2e/webpack_devserver_esm/pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages:
- '.'
- 'mylib'
- 'mypkg'
Loading

0 comments on commit cf18bb4

Please sign in to comment.