Skip to content

build: bazel bundles, release artifacts and lsp & e2e tests #1738

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules/
dist/
integration/pre_apf_project/node_modules/
integration/project/node_modules/
integration/project/dist/
integration/workspace/node_modules/
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ build --nobuild_runfile_links

build --enable_runfiles

# Keep tests tagged "exclusive" in the sandbox
test --incompatible_exclusive_test_sandboxed

###############################
# Output #
###############################
Expand Down
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- checkout
- node/install-packages:
pkg-manager: yarn
- run: yarn test:bazel
- run: yarn bazel test //...
workflows:
build-and-test:
jobs:
Expand Down
61 changes: 61 additions & 0 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
load("@aspect_rules_js//js:defs.bzl", "js_library")
load("@aspect_rules_js//npm:defs.bzl", "npm_package")
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@npm//:defs.bzl", "npm_link_all_packages")
load("@npm//:vsce/package_json.bzl", vsce_bin = "bin")

npm_link_all_packages(name = "node_modules")

Expand All @@ -15,3 +17,62 @@ ts_config(
src = "tsconfig.json",
visibility = ["//visibility:public"]
)

npm_package(
name = "npm",
srcs = [
"package.json",
"angular.png",
"CHANGELOG.md",
"README.md",
"//client:index.js",
"//server:npm_files",
"//syntaxes:npm_files",
"//v12_language_service:npm_files",
# Transitive closure of npm deps needed for vsce; this set was determined manually by
# running `bazel build //:vsix` and burning down missing packages. We do this so that we
# don't have to run an additional `npm install` action to create a node_modules within the
# //:npm npm_package where the vsce build takes place.
":node_modules/@angular/language-service",
":node_modules/balanced-match",
":node_modules/brace-expansion",
":node_modules/concat-map",
":node_modules/lru-cache",
":node_modules/minimatch",
":node_modules/semver",
":node_modules/typescript",
":node_modules/vscode-jsonrpc",
":node_modules/vscode-languageclient",
":node_modules/vscode-languageserver-protocol",
":node_modules/vscode-languageserver-types",
":node_modules/vscode-languageserver",
":node_modules/vscode-uri",
":node_modules/yallist",
],
include_srcs_packages = [
"**",
],
exclude_srcs_patterns = [
"*.map",
"**/*.map",
],
replace_prefixes = {
"client/": "",
"syntaxes/src/": "syntaxes/",
},
visibility = ["//integration:__subpackages__"],
)

vsce_bin.vsce(
name = "vsix",
srcs = [
":npm",
],
outs = ["ng-template.vsix"],
chdir = "npm",
args = [
"package",
"-o",
"../ng-template.vsix"
],
)
43 changes: 43 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,31 @@ load("@aspect_rules_jasmine//jasmine:dependencies.bzl", "rules_jasmine_dependenc

rules_jasmine_dependencies()

http_archive(
name = "aspect_rules_esbuild",
sha256 = "6446a784e72b04c33bc48debd84c5a54db4727f0a4a61a0da9faa64bededd7c2",
strip_prefix = "rules_esbuild-0909898c1344569f59fa83f70a1db7548563c274",
url = "https://github.com/aspect-build/rules_esbuild/archive/0909898c1344569f59fa83f70a1db7548563c274.tar.gz",
)

load("@aspect_rules_esbuild//esbuild:dependencies.bzl", "rules_esbuild_dependencies")

rules_esbuild_dependencies()

load("@aspect_rules_jasmine//jasmine:repositories.bzl", "rules_jasmine_repositories", JASMINE_LATEST_VERSION = "LATEST_VERSION")

rules_jasmine_repositories(
name = "jasmine",
jasmine_version = JASMINE_LATEST_VERSION,
)

load("@aspect_rules_esbuild//esbuild:repositories.bzl", "esbuild_register_toolchains", ESBUILD_LATEST_VERSION = "LATEST_VERSION")

esbuild_register_toolchains(
name = "esbuild",
esbuild_version = ESBUILD_LATEST_VERSION,
)

load("@rules_nodejs//nodejs:repositories.bzl", "DEFAULT_NODE_VERSION", "nodejs_register_toolchains")

nodejs_register_toolchains(
Expand All @@ -54,6 +72,20 @@ npm_translate_lock(
yarn_lock = "//:yarn.lock",
package_json = "//:package.json",
verify_node_modules_ignored = "//:.bazelignore",
public_hoist_packages = {
# Hoist transitive closure of npm deps needed for vsce; this set was determined manually by
# running `bazel build //:vsix` and burning down missing packages. We do this so that we
# don't have to run an additional `npm install` action to create a node_modules within the
# //:npm npm_package where the vsce build takes place.
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
"[email protected]": [""],
},
)

load("@npm//:repositories.bzl", "npm_repositories")
Expand Down Expand Up @@ -81,3 +113,14 @@ npm_translate_lock(
load("@npm_integration_pre_apf_project//:repositories.bzl", npm_integration_pre_apf_project_repositories = "npm_repositories")

npm_integration_pre_apf_project_repositories()

npm_translate_lock(
name = "npm_integration_project",
yarn_lock = "//integration/project:yarn.lock",
package_json = "//integration/project:package.json",
verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm_integration_project//:repositories.bzl", npm_integration_project_repositories = "npm_repositories")

npm_integration_project_repositories()
25 changes: 25 additions & 0 deletions client/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
load("@aspect_rules_esbuild//esbuild:defs.bzl", "esbuild")

ts_config(
name = "tsconfig",
Expand All @@ -9,3 +10,27 @@ ts_config(
],
visibility = ["//client:__subpackages__"]
)

esbuild(
name = "index",
entry_point = "//client/src:extension.js",
data = ["//client/src"],
platform = "node",
format = "cjs",
sourcemap = "external",
config = {
# Workaround for https://github.com/aspect-build/rules_esbuild/issues/58
"resolveExtensions": [".js"],
},
external = [
"fs",
"path",
"vscode",
"vscode-languageclient/node",
"vscode-languageserver-protocol",
"vscode-jsonrpc",
],
# Do not enable minification. It seems to break the extension on Windows (with WSL). See #1198.
minify = False,
visibility = ["//:__pkg__"],
)
1 change: 0 additions & 1 deletion client/src/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")


ts_project(
name = "src",
srcs = glob(["*.ts"]),
Expand Down
9 changes: 4 additions & 5 deletions integration/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ ts_config(

ts_project(
name = "integration",
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
# they cannot be broken up into separate ts_project targets
srcs = glob([
"*.ts",
# NB: there is an import cycle between lsp/*.ts and test_constants.ts so they cannot be
# broken up into separate ts_project targets
"lsp/*.ts",
]),
]) + ["//integration/lsp:srcs"],
declaration = True,
source_map = True,
tsconfig = ":tsconfig",
Expand All @@ -32,4 +31,4 @@ ts_project(
visibility = [
"//integration:__subpackages__",
],
)
)
23 changes: 22 additions & 1 deletion integration/e2e/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@aspect_rules_js//js:defs.bzl", "js_test")
load("@aspect_rules_ts//ts:defs.bzl", "ts_project")

ts_project(
Expand All @@ -16,4 +17,24 @@ ts_project(
visibility = [
"//integration:__subpackages__",
],
)
)

js_test(
name = "test",
data = [
":e2e",
"//:npm",
"//integration",
"//integration/project",
"//server:index",
# Depend on //:node_modules/jasmine as a temporary work-around for jasmine escaping its
# runfiles likely due to esm import issue in rules_js https://github.com/aspect-build/rules_js/issues/362
"//:node_modules/jasmine",
],
entry_point = ":index.js",
# This test downloads vscode & installs it which is not allowed in the sandbox
# due to file system protection. It is tagged local so it runs outside of
# the sandbox. It would need some redesign to allow for sandbox execution.
# Tagged manual so that `bazel test //...` doesn't run it automatically.
tags = ["e2e", "local", "manual"],
)
8 changes: 5 additions & 3 deletions integration/e2e/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import {join} from 'path';
import {runTests} from 'vscode-test';

import {PACKAGE_ROOT, PROJECT_PATH} from '../test_constants';
import {IS_BAZEL, PACKAGE_ROOT, PROJECT_PATH} from '../test_constants';

async function main() {
const EXT_DEVELOPMENT_PATH = join(PACKAGE_ROOT, 'dist', 'npm');
const EXT_TESTS_PATH = join(PACKAGE_ROOT, 'dist', 'integration', 'e2e', 'jasmine');
const EXT_DEVELOPMENT_PATH =
IS_BAZEL ? join(PACKAGE_ROOT, 'npm') : join(PACKAGE_ROOT, 'dist', 'npm');
const EXT_TESTS_PATH = IS_BAZEL ? join(PACKAGE_ROOT, 'integration', 'e2e', 'jasmine') :
join(PACKAGE_ROOT, 'dist', 'integration', 'e2e', 'jasmine');

try {
await runTests({
Expand Down
22 changes: 22 additions & 0 deletions integration/lsp/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
load("@aspect_rules_jasmine//jasmine:defs.bzl", "jasmine_test")
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")

jasmine_test(
name = "test",
data = [
"//integration",
"//integration/project",
"//server:index",
],
args = ["*_spec.js"],
chdir = package_name(),
tags = ["e2e"],
)

copy_to_bin(
name = "srcs",
srcs = glob(["*.ts"]),
# NB: there is an import cycle between integration/lsp/*.ts and integration/test_constants.ts so
# they cannot be broken up into separate ts_project targets
visibility = ["//integration:__subpackages__"]
)
9 changes: 8 additions & 1 deletion integration/lsp/ivy_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {URI} from 'vscode-uri';

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

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

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

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

afterEach(() => {
// TODO(kyliau): Use an in-memory FS harness for the server
Expand Down
4 changes: 3 additions & 1 deletion integration/pre_apf_project/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ npm_link_all_packages(name = "node_modules")
copy_to_bin(
name = "pre_apf_project",
srcs = glob(["**"]),
visibility = ["//server/src/tests:__pkg__"],
visibility = [
"//server/src/tests:__pkg__",
],
)
29 changes: 29 additions & 0 deletions integration/project/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
load("@npm_integration_project//:defs.bzl", "npm_link_all_packages")
load("@npm_integration_project//integration/project:ng-packagr/package_json.bzl", ng_packagr_bin = "bin")

npm_link_all_packages(name = "node_modules")

copy_to_bin(
name = "project_srcs",
srcs = glob(["**"]),
)

ng_packagr_bin.ng_packagr(
name = "dist",
srcs = [":project_srcs", ":node_modules"],
out_dirs = ["dist"],
chdir = package_name(),
args = [
"-p",
"libs/post/ng-package.json",
"-c",
"libs/post/tsconfig.json",
],
)

filegroup(
name = "project",
srcs = [":project_srcs", ":dist"],
visibility = ["//integration:__subpackages__"],
)
6 changes: 4 additions & 2 deletions integration/test_constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import {join, resolve} from 'path';

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

export const PACKAGE_ROOT = resolve(__dirname, '../..');
export const SERVER_PATH = join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
export const IS_BAZEL = !!process.env['TEST_TARGET'];
export const PACKAGE_ROOT = IS_BAZEL ? resolve(__dirname, '..') : resolve(__dirname, '../..');
export const SERVER_PATH = IS_BAZEL ? join(PACKAGE_ROOT, 'server', 'index.js') :
join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
export const APP_COMPONENT_URI = convertPathToFileUrl(APP_COMPONENT);
Expand Down
4 changes: 3 additions & 1 deletion integration/workspace/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ npm_link_all_packages(name = "node_modules")
copy_to_bin(
name = "workspace",
srcs = glob(["**"]),
visibility = ["//server/src/tests:__pkg__"],
visibility = [
"//server/src/tests:__pkg__",
],
)
Loading