Paul Gschwendtner 34367874da build: migrate @schematics/angular tests to rules_js
Migrates the @schematics/angular tests to `rules_js`.
2025-01-21 18:19:11 +01:00

159 lines
4.3 KiB
Python

# Copyright Google Inc. All Rights Reserved.
#
# Use of this source code is governed by an MIT-style license that can be
# found in the LICENSE file at https://angular.dev/license
load("@npm2//:defs.bzl", "npm_link_all_packages")
load("//tools:defaults2.bzl", "jasmine_test", "npm_package", "ts_project")
load("//tools:ts_json_schema.bzl", "ts_json_schema")
licenses(["notice"])
package(default_visibility = ["//visibility:public"])
npm_link_all_packages()
# Create a list of Tuple("path/file.json", "path_file") to be used as rules
ALL_SCHEMA_TARGETS = [
(
x,
x.replace("/", "_").replace("-", "_").replace(".json", ""),
)
for x in glob(
include = ["*/schema.json"],
exclude = [
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
"node_modules/**",
],
)
]
# Create all the targets.
[
ts_json_schema(
name = name,
src = src,
)
for (src, name) in ALL_SCHEMA_TARGETS
]
RUNTIME_ASSETS = [
"collection.json",
"migrations/migration-collection.json",
"package.json",
"utility/latest-versions/package.json",
] + glob(
include = [
"*/schema.json",
"*/files/**/*",
"*/other-files/**/*",
"*/implements-files/**/*",
"*/type-files/**/*",
"*/functional-files/**/*",
"*/class-files/**/*",
],
exclude = [
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
"node_modules/**",
],
)
ts_project(
name = "angular",
srcs = glob(
include = ["**/*.ts"],
exclude = [
"**/*_spec.ts",
# Also exclude templated files.
"*/files/**/*.ts",
"*/other-files/**/*.ts",
"*/implements-files/**/*",
"*/type-files/**/*",
"*/functional-files/**/*",
"*/class-files/**/*",
# Exclude test helpers.
"utility/test/**/*.ts",
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
"node_modules/**",
],
) + [
"//packages/schematics/angular:" + src.replace(".json", ".ts")
for (src, _) in ALL_SCHEMA_TARGETS
],
data = RUNTIME_ASSETS,
module_name = "@schematics/angular",
deps = [
":node_modules/@angular-devkit/core",
":node_modules/@angular-devkit/schematics",
"//:node_modules/@inquirer/prompts",
"//:node_modules/@types/node",
"//:node_modules/browserslist",
"//:node_modules/jsonc-parser",
"//packages/schematics/angular/third_party/github.com/Microsoft/TypeScript:TypeScript_rjs",
],
)
jasmine_test(
name = "no_typescript_runtime_dep_test",
data = [
"no_typescript_runtime_dep_spec.js",
":angular_rjs",
"//:node_modules/@types/jasmine",
],
)
ts_project(
name = "angular_test_lib",
testonly = True,
srcs = glob(
include = [
"**/*_spec.ts",
"utility/test/**/*.ts",
],
exclude = [
# NB: we need to exclude the nested node_modules that is laid out by yarn workspaces
"node_modules/**",
],
),
deps = [
":angular_rjs",
":node_modules/@angular-devkit/core",
":node_modules/@angular-devkit/schematics",
"//:node_modules/@types/jasmine",
"//:node_modules/jsonc-parser",
"//packages/schematics/angular/third_party/github.com/Microsoft/TypeScript:TypeScript_rjs",
],
)
jasmine_test(
name = "angular_test",
data = [":angular_test_lib_rjs"],
)
genrule(
name = "license",
srcs = ["//:LICENSE"],
outs = ["LICENSE"],
cmd = "cp $(execpath //:LICENSE) $@",
)
npm_package(
name = "pkg",
pkg_deps = [
"//packages/angular_devkit/schematics:package.json",
"//packages/angular_devkit/core:package.json",
],
stamp_files = [
"utility/latest-versions.js",
],
tags = ["release-package"],
deps = RUNTIME_ASSETS + [
":README.md",
":angular_rjs",
":license",
"//packages/schematics/angular/third_party/github.com/Microsoft/TypeScript:LICENSE",
# Force typescript library to be included.
"//packages/schematics/angular/third_party/github.com/Microsoft/TypeScript:lib/typescript.js",
],
)