Skip to content

Commit 637b068

Browse files
authored
build: bazel bundles, release artifacts and lsp & e2e tests (#1738)
1 parent c50ff13 commit 637b068

File tree

21 files changed

+320
-17
lines changed

21 files changed

+320
-17
lines changed

.bazelignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
node_modules/
2+
dist/
23
integration/pre_apf_project/node_modules/
4+
integration/project/node_modules/
5+
integration/project/dist/
36
integration/workspace/node_modules/

.bazelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ build --nobuild_runfile_links
2727

2828
build --enable_runfiles
2929

30+
# Keep tests tagged "exclusive" in the sandbox
31+
test --incompatible_exclusive_test_sandboxed
32+
3033
###############################
3134
# Output #
3235
###############################

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
- checkout
3535
- node/install-packages:
3636
pkg-manager: yarn
37-
- run: yarn test:bazel
37+
- run: yarn bazel test //...
3838
workflows:
3939
build-and-test:
4040
jobs:

BUILD.bazel

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
load("@aspect_rules_js//js:defs.bzl", "js_library")
2+
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
23
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
34
load("@npm//:defs.bzl", "npm_link_all_packages")
5+
load("@npm//:vsce/package_json.bzl", vsce_bin = "bin")
46

57
npm_link_all_packages(name = "node_modules")
68

@@ -15,3 +17,62 @@ ts_config(
1517
src = "tsconfig.json",
1618
visibility = ["//visibility:public"]
1719
)
20+
21+
npm_package(
22+
name = "npm",
23+
srcs = [
24+
"package.json",
25+
"angular.png",
26+
"CHANGELOG.md",
27+
"README.md",
28+
"//client:index.js",
29+
"//server:npm_files",
30+
"//syntaxes:npm_files",
31+
"//v12_language_service:npm_files",
32+
# Transitive closure of npm deps needed for vsce; this set was determined manually by
33+
# running `bazel build //:vsix` and burning down missing packages. We do this so that we
34+
# don't have to run an additional `npm install` action to create a node_modules within the
35+
# //:npm npm_package where the vsce build takes place.
36+
":node_modules/@angular/language-service",
37+
":node_modules/balanced-match",
38+
":node_modules/brace-expansion",
39+
":node_modules/concat-map",
40+
":node_modules/lru-cache",
41+
":node_modules/minimatch",
42+
":node_modules/semver",
43+
":node_modules/typescript",
44+
":node_modules/vscode-jsonrpc",
45+
":node_modules/vscode-languageclient",
46+
":node_modules/vscode-languageserver-protocol",
47+
":node_modules/vscode-languageserver-types",
48+
":node_modules/vscode-languageserver",
49+
":node_modules/vscode-uri",
50+
":node_modules/yallist",
51+
],
52+
include_srcs_packages = [
53+
"**",
54+
],
55+
exclude_srcs_patterns = [
56+
"*.map",
57+
"**/*.map",
58+
],
59+
replace_prefixes = {
60+
"client/": "",
61+
"syntaxes/src/": "syntaxes/",
62+
},
63+
visibility = ["//integration:__subpackages__"],
64+
)
65+
66+
vsce_bin.vsce(
67+
name = "vsix",
68+
srcs = [
69+
":npm",
70+
],
71+
outs = ["ng-template.vsix"],
72+
chdir = "npm",
73+
args = [
74+
"package",
75+
"-o",
76+
"../ng-template.vsix"
77+
],
78+
)

WORKSPACE

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,31 @@ load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependenc
3333

3434
rules_jasmine_dependencies()
3535

36+
http_archive(
37+
name = "aspect_rules_esbuild",
38+
sha256 = "6446a784e72b04c33bc48debd84c5a54db4727f0a4a61a0da9faa64bededd7c2",
39+
strip_prefix = "rules_esbuild-0909898c1344569f59fa83f70a1db7548563c274",
40+
url = "https://github.com/aspect-build/rules_esbuild/archive/0909898c1344569f59fa83f70a1db7548563c274.tar.gz",
41+
)
42+
43+
load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")
44+
45+
rules_esbuild_dependencies()
46+
3647
load("@aspect_rules_jasmine//jasmine:repositories.bzl", "rules_jasmine_repositories", JASMINE_LATEST_VERSION = "LATEST_VERSION")
3748

3849
rules_jasmine_repositories(
3950
name = "jasmine",
4051
jasmine_version = JASMINE_LATEST_VERSION,
4152
)
4253

54+
load("@aspect_rules_esbuild//esbuild:repositories.bzl", "esbuild_register_toolchains", ESBUILD_LATEST_VERSION = "LATEST_VERSION")
55+
56+
esbuild_register_toolchains(
57+
name = "esbuild",
58+
esbuild_version = ESBUILD_LATEST_VERSION,
59+
)
60+
4361
load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")
4462

4563
nodejs_register_toolchains(
@@ -54,6 +72,20 @@ npm_translate_lock(
5472
yarn_lock = "//:yarn.lock",
5573
package_json = "//:package.json",
5674
verify_node_modules_ignored = "//:.bazelignore",
75+
public_hoist_packages = {
76+
# Hoist transitive closure of npm deps needed for vsce; this set was determined manually by
77+
# running `bazel build //:vsix` and burning down missing packages. We do this so that we
78+
# don't have to run an additional `npm install` action to create a node_modules within the
79+
# //:npm npm_package where the vsce build takes place.
80+
81+
82+
83+
84+
85+
86+
87+
88+
},
5789
)
5890

5991
load("@npm//:repositories.bzl", "npm_repositories")
@@ -81,3 +113,14 @@ npm_translate_lock(
81113
load("@npm_integration_pre_apf_project//:repositories.bzl", npm_integration_pre_apf_project_repositories = "npm_repositories")
82114

83115
npm_integration_pre_apf_project_repositories()
116+
117+
npm_translate_lock(
118+
name = "npm_integration_project",
119+
yarn_lock = "//integration/project:yarn.lock",
120+
package_json = "//integration/project:package.json",
121+
verify_node_modules_ignored = "//:.bazelignore",
122+
)
123+
124+
load("@npm_integration_project//:repositories.bzl", npm_integration_project_repositories = "npm_repositories")
125+
126+
npm_integration_project_repositories()

client/BUILD.bazel

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
2+
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")
23

34
ts_config(
45
name = "tsconfig",
@@ -9,3 +10,27 @@ ts_config(
910
],
1011
visibility = ["//client:__subpackages__"]
1112
)
13+
14+
esbuild(
15+
name = "index",
16+
entry_point = "//client/src:extension.js",
17+
data = ["//client/src"],
18+
platform = "node",
19+
format = "cjs",
20+
sourcemap = "external",
21+
config = {
22+
# Workaround for https://github.com/aspect-build/rules_esbuild/issues/58
23+
"resolveExtensions": [".js"],
24+
},
25+
external = [
26+
"fs",
27+
"path",
28+
"vscode",
29+
"vscode-languageclient/node",
30+
"vscode-languageserver-protocol",
31+
"vscode-jsonrpc",
32+
],
33+
# Do not enable minification. It seems to break the extension on Windows (with WSL). See #1198.
34+
minify = False,
35+
visibility = ["//:__pkg__"],
36+
)

client/src/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
22

3-
43
ts_project(
54
name = "src",
65
srcs = glob(["*.ts"]),

integration/BUILD.bazel

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ ts_config(
1212

1313
ts_project(
1414
name = "integration",
15+
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
16+
# they cannot be broken up into separate ts_project targets
1517
srcs = glob([
1618
"*.ts",
17-
# NB: there is an import cycle between lsp/*.ts and test_constants.ts so they cannot be
18-
# broken up into separate ts_project targets
19-
"lsp/*.ts",
20-
]),
19+
]) + ["//integration/lsp:srcs"],
2120
declaration = True,
2221
source_map = True,
2322
tsconfig = ":tsconfig",
@@ -32,4 +31,4 @@ ts_project(
3231
visibility = [
3332
"//integration:__subpackages__",
3433
],
35-
)
34+
)

integration/e2e/BUILD.bazel

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
load("@aspect_rules_js//js:defs.bzl", "js_test")
12
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")
23

34
ts_project(
@@ -16,4 +17,24 @@ ts_project(
1617
visibility = [
1718
"//integration:__subpackages__",
1819
],
19-
)
20+
)
21+
22+
js_test(
23+
name = "test",
24+
data = [
25+
":e2e",
26+
"//:npm",
27+
"//integration",
28+
"//integration/project",
29+
"//server:index",
30+
# Depend on //:node_modules/jasmine as a temporary work-around for jasmine escaping its
31+
# runfiles likely due to esm import issue in rules_js https://github.com/aspect-build/rules_js/issues/362
32+
"//:node_modules/jasmine",
33+
],
34+
entry_point = ":index.js",
35+
# This test downloads vscode & installs it which is not allowed in the sandbox
36+
# due to file system protection. It is tagged local so it runs outside of
37+
# the sandbox. It would need some redesign to allow for sandbox execution.
38+
# Tagged manual so that `bazel test //...` doesn't run it automatically.
39+
tags = ["e2e", "local", "manual"],
40+
)

integration/e2e/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import {join} from 'path';
22
import {runTests} from 'vscode-test';
33

4-
import {PACKAGE_ROOT, PROJECT_PATH} from '../test_constants';
4+
import {IS_BAZEL, PACKAGE_ROOT, PROJECT_PATH} from '../test_constants';
55

66
async function main() {
7-
const EXT_DEVELOPMENT_PATH = join(PACKAGE_ROOT, 'dist', 'npm');
8-
const EXT_TESTS_PATH = join(PACKAGE_ROOT, 'dist', 'integration', 'e2e', 'jasmine');
7+
const EXT_DEVELOPMENT_PATH =
8+
IS_BAZEL ? join(PACKAGE_ROOT, 'npm') : join(PACKAGE_ROOT, 'dist', 'npm');
9+
const EXT_TESTS_PATH = IS_BAZEL ? join(PACKAGE_ROOT, 'integration', 'e2e', 'jasmine') :
10+
join(PACKAGE_ROOT, 'dist', 'integration', 'e2e', 'jasmine');
911

1012
try {
1113
await runTests({

integration/lsp/BUILD.bazel

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
2+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
3+
4+
jasmine_test(
5+
name = "test",
6+
data = [
7+
"//integration",
8+
"//integration/project",
9+
"//server:index",
10+
],
11+
args = ["*_spec.js"],
12+
chdir = package_name(),
13+
tags = ["e2e"],
14+
)
15+
16+
copy_to_bin(
17+
name = "srcs",
18+
srcs = glob(["*.ts"]),
19+
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
20+
# they cannot be broken up into separate ts_project targets
21+
visibility = ["//integration:__subpackages__"]
22+
)

integration/lsp/ivy_spec.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {URI} from 'vscode-uri';
1414

1515
import {NgccProgressEnd, ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
1616
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
17-
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, PROJECT_PATH, TSCONFIG} from '../test_constants';
17+
import {APP_COMPONENT, APP_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, IS_BAZEL, PROJECT_PATH, TSCONFIG} from '../test_constants';
1818

1919
import {convertPathToFileUrl, createConnection, createTracer, initializeServer, openTextDocument} from './test_utils';
2020

@@ -403,6 +403,13 @@ describe('Angular Ivy language server', () => {
403403

404404
describe('compiler options', () => {
405405
const originalConfig = fs.readFileSync(TSCONFIG, 'utf-8');
406+
if (IS_BAZEL) {
407+
// Under Bazel, the tsconfig.json file in the output tree is write protected.
408+
// We change the file permissions here so that the fs.writeFileSync(TSCONFIG, ...)
409+
// calls below don't fail under Bazel. This should be fixed in the future by
410+
// use an in-memory FS harness for the server.
411+
fs.chmodSync(TSCONFIG, 0o644);
412+
}
406413

407414
afterEach(() => {
408415
// TODO(kyliau): Use an in-memory FS harness for the server

integration/pre_apf_project/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ npm_link_all_packages(name = "node_modules")
66
copy_to_bin(
77
name = "pre_apf_project",
88
srcs = glob(["**"]),
9-
visibility = ["//server/src/tests:__pkg__"],
9+
visibility = [
10+
"//server/src/tests:__pkg__",
11+
],
1012
)

integration/project/BUILD.bazel

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
2+
load("@npm_integration_project//:defs.bzl", "npm_link_all_packages")
3+
load("@npm_integration_project//integration/project:ng-packagr/package_json.bzl", ng_packagr_bin = "bin")
4+
5+
npm_link_all_packages(name = "node_modules")
6+
7+
copy_to_bin(
8+
name = "project_srcs",
9+
srcs = glob(["**"]),
10+
)
11+
12+
ng_packagr_bin.ng_packagr(
13+
name = "dist",
14+
srcs = [":project_srcs", ":node_modules"],
15+
out_dirs = ["dist"],
16+
chdir = package_name(),
17+
args = [
18+
"-p",
19+
"libs/post/ng-package.json",
20+
"-c",
21+
"libs/post/tsconfig.json",
22+
],
23+
)
24+
25+
filegroup(
26+
name = "project",
27+
srcs = [":project_srcs", ":dist"],
28+
visibility = ["//integration:__subpackages__"],
29+
)

integration/test_constants.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import {join, resolve} from 'path';
22

33
import {convertPathToFileUrl} from './lsp/test_utils';
44

5-
export const PACKAGE_ROOT = resolve(__dirname, '../..');
6-
export const SERVER_PATH = join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
5+
export const IS_BAZEL = !!process.env['TEST_TARGET'];
6+
export const PACKAGE_ROOT = IS_BAZEL ? resolve(__dirname, '..') : resolve(__dirname, '../..');
7+
export const SERVER_PATH = IS_BAZEL ? join(PACKAGE_ROOT, 'server', 'index.js') :
8+
join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
79
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
810
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
911
export const APP_COMPONENT_URI = convertPathToFileUrl(APP_COMPONENT);

integration/workspace/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ npm_link_all_packages(name = "node_modules")
66
copy_to_bin(
77
name = "workspace",
88
srcs = glob(["**"]),
9-
visibility = ["//server/src/tests:__pkg__"],
9+
visibility = [
10+
"//server/src/tests:__pkg__",
11+
],
1012
)

0 commit comments

Comments
 (0)