# 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.io/license

load("@npm//@bazel/jasmine:index.bzl", "jasmine_node_test")
load("//tools:defaults.bzl", "ts_library")

# @external_begin
load("@bazel_tools//tools/build_defs/pkg:pkg.bzl", "pkg_tar")
load("@build_bazel_rules_nodejs//:index.bzl", "pkg_npm")
# @external_end

licenses(["notice"])  # MIT

package(default_visibility = ["//visibility:public"])

ts_library(
    name = "build_optimizer",
    srcs = glob(
        include = ["src/**/*.ts"],
        exclude = [
            # TODO(@filipesilva): shouldn't need to exclude the cli files but can't exclude them
            # from jasmine_node_test.
            "src/**/cli.ts",
            "src/**/*_spec.ts",
            "src/**/*_benchmark.ts",
        ],
    ),
    data = [
        "package.json",
        "webpack-loader/package.json",
    ],
    module_name = "@angular-devkit/build-optimizer",
    module_root = "src/index.d.ts",
    deps = [
        "@npm//@types/node",
        "@npm//@types/webpack",
        "@npm//@types/webpack-sources",
        "@npm//source-map",
        "@npm//tslib",
        "@npm//typescript",
    ],
)

ts_library(
    name = "build_optimizer_test_lib",
    testonly = True,
    srcs = glob(["src/**/*_spec.ts"]),
    # @external_begin
    deps = [
        ":build_optimizer",
        "//packages/angular_devkit/core",
        "@npm//source-map",
        "@npm//typescript",
    ],
    # @external_end
)

jasmine_node_test(
    name = "build_optimizer_test",
    srcs = [":build_optimizer_test_lib"],
    deps = [
        "@npm//jasmine",
        "@npm//source-map",
    ],
)

# @external_begin
pkg_npm(
    name = "npm_package",
    deps = [
        ":build_optimizer",
    ],
)

pkg_tar(
    name = "npm_package_archive",
    srcs = [":npm_package"],
    extension = "tar.gz",
    strip_prefix = "./npm_package",
    tags = ["manual"],
)
# @external_end
