Skip to content

Commit fed8fae

Browse files
devversionamysorto
authored andcommitted
build: switch to http server rule from dev-infra
Switches the dev-app and e2e-app to the http server rule exposed by the shared dev-infra code.
1 parent 52b3e9c commit fed8fae

File tree

8 files changed

+34
-19
lines changed

8 files changed

+34
-19
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,3 @@ testem.log
5050
*.log
5151
.ng-dev.user*
5252
.husky/_
53-
54-
# Variables that are inlined into the dev app index.html
55-
/src/dev-app/variables.json

DEV_ENVIRONMENT.md

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,18 @@ export HUSKY=0
7878
```
7979

8080
### Injecting variables into the dev app
81-
Variables can be injected into the dev app by creating the `src/dev-app/variables.json` file.
82-
They'll be made available under the `window.DEV_APP_VARIABLES` object. The file isn't checked into
83-
Git and it can be used to pass private configuration like API keys. Variables currently being used:
81+
82+
A set of environment variables is made available within the dev-app. Such variables
83+
will be injected into the dev-app, so that e.g. API keys can be used for development
84+
without requiring secrets to be committed.
85+
86+
The following variables are currently used in the dev-app:
8487

8588
* `GOOGLE_MAPS_KEY` - Optional key for the Google Maps API.
89+
90+
For example, you can store a personal development Google Maps API key for the
91+
dev-app within your `.bashrc` or `.zshrc` file.
92+
93+
```bash
94+
export GOOGLE_MAPS_KEY=<api-key>
95+
```

src/cdk/testing/tests/webdriver-test.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def webdriver_test(name, deps, tags = [], **kwargs):
2626

2727
server_test(
2828
name = "%s_chromium" % name,
29-
server = "//src/e2e-app:devserver",
29+
server = "//src/e2e-app:server",
3030
test = ":%s_chromium_web_test" % name,
3131
tags = tags + ["e2e"],
3232
)

src/dev-app/BUILD.bazel

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_web")
2-
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "ng_module", "sass_binary")
3-
load("//tools/dev-server:index.bzl", "dev_server")
2+
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary")
43
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
54
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
65

@@ -165,7 +164,7 @@ filegroup(
165164
],
166165
)
167166

168-
dev_server(
167+
http_server(
169168
name = "devserver",
170169
srcs = [":dev_app_static_files"],
171170
additional_root_paths = [
@@ -174,6 +173,13 @@ dev_server(
174173
# artifact output as workspace root.
175174
"angular_material",
176175
],
176+
enable_dev_ui = True,
177+
# List of environment variables that will be made available as `window.<NAME>` in the
178+
# served `index.html` throuhg an injected script. Useful for allowing developers to
179+
# configure API keys without requiring secrets to be committed.
180+
environment_variables = [
181+
"GOOGLE_MAPS_KEY",
182+
],
177183
tags = ["manual"],
178184
deps = [
179185
":bundles",

src/dev-app/index.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@
2323
<script src="https://www.youtube.com/iframe_api"></script>
2424
<script src="https://unpkg.com/@googlemaps/markerclustererplus/dist/index.min.js"></script>
2525
<script>
26-
(function loadGoogleMaps(variables) {
27-
var key = variables ? variables.GOOGLE_MAPS_KEY : null;
28-
var script = document.createElement('script');
26+
(function loadGoogleMaps() {
27+
// Key can be set through the `GOOGLE_MAPS_KEY` environment variable.
28+
const key = window.GOOGLE_MAPS_KEY;
29+
const script = document.createElement('script');
2930
script.src = 'https://maps.googleapis.com/maps/api/js?libraries=visualization' +
3031
(key ? '&key=' + key : '');
3132
document.body.appendChild(script);
32-
})(window.DEV_APP_VARIABLES);
33+
})();
3334
</script>
3435
<script src="bundles/dev-app/main.js" type="module"></script>
3536
</body>

src/e2e-app/BUILD.bazel

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
load("//tools/dev-server:index.bzl", "dev_server")
2-
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "ng_module", "sass_binary")
1+
load("//tools:defaults.bzl", "devmode_esbuild", "esbuild_config", "http_server", "ng_module", "sass_binary")
32
load("//src/components-examples:config.bzl", "ALL_EXAMPLES")
43
load("//tools/angular:index.bzl", "LINKER_PROCESSED_FW_PACKAGES")
54

@@ -119,8 +118,8 @@ devmode_esbuild(
119118
],
120119
)
121120

122-
dev_server(
123-
name = "devserver",
121+
http_server(
122+
name = "server",
124123
testonly = True,
125124
srcs = devserverIndexHtmlDependencies,
126125
additional_root_paths = [

src/e2e-app/test_suite.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def e2e_test_suite(name, data = [], tags = ["e2e"], deps = []):
99
"@npm//@axe-core/webdriverjs",
1010
] + data,
1111
on_prepare = "//src/e2e-app:start-devserver.js",
12-
server = "//src/e2e-app:devserver",
12+
server = "//src/e2e-app:server",
1313
tags = tags,
1414
deps = deps,
1515
)

tools/defaults.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ load("@npm//@angular/bazel:index.bzl", _ng_module = "ng_module", _ng_package = "
77
load("@npm//@angular/dev-infra-private/bazel/integration:index.bzl", _integration_test = "integration_test")
88
load("@npm//@angular/dev-infra-private/bazel/esbuild:index.bzl", _esbuild = "esbuild", _esbuild_config = "esbuild_config")
99
load("@npm//@angular/dev-infra-private/bazel/spec-bundling:index.bzl", _spec_bundle = "spec_bundle")
10+
load("@npm//@angular/dev-infra-private/bazel/http-server:index.bzl", _http_server = "http_server")
1011
load("@npm//@angular/dev-infra-private/bazel:extract_js_module_output.bzl", "extract_js_module_output")
1112
load("@npm//@bazel/jasmine:index.bzl", _jasmine_node_test = "jasmine_node_test")
1213
load("@npm//@bazel/concatjs:index.bzl", _karma_web_test = "karma_web_test", _karma_web_test_suite = "karma_web_test_suite")
@@ -31,6 +32,7 @@ markdown_to_html = _markdown_to_html
3132
integration_test = _integration_test
3233
esbuild = _esbuild
3334
esbuild_config = _esbuild_config
35+
http_server = _http_server
3436

3537
def _make_tsec_test(target):
3638
package_name = native.package_name()

0 commit comments

Comments
 (0)