load("//tools/npm_integration_test:npm_integration_test.bzl", "npm_integration_test")

filegroup(
    name = "angular_cli_sources",
    srcs = glob(
        include = ["**/*"],
        exclude = [
            "node_modules/**",
            ".yarn_local_cache/**",
        ],
    ),
)

npm_integration_test(
    name = "angular_cli_test",
    check_npm_packages = [
        "@angular/cli",
        "@angular-devkit/architect",
        "@angular-devkit/build-angular",
        "@angular-devkit/build-webpack",
        "@angular-devkit/build-optimizer",
        "@angular-devkit/core",
        "@angular-devkit/schematics",
        "@schematics/angular",
        "@schematics/update",
    ],
    commands = [
        # Workaround https://github.com/yarnpkg/yarn/issues/2165
        # Yarn will cache file://dist URIs and not update
        "rm -rf ./.yarn_local_cache",
        "mkdir .yarn_local_cache",
        "patch-package-json",
        "$(rootpath @nodejs//:yarn_bin) install --cache-folder ./.yarn_local_cache",
        "$(rootpath @nodejs//:yarn_bin) --cache-folder ./.yarn_local_cache ng version",
        "rm -rf ./.yarn_local_cache",
    ],
    data = [
        "@nodejs//:yarn_bin",
        "@nodejs//:yarn_files",
    ],
    npm_packages = {
        "//packages/angular/cli:npm_package_archive": "@angular/cli",
        "//packages/angular_devkit/architect:npm_package_archive": "@angular-devkit/architect",
        "//packages/angular_devkit/build_angular:npm_package_archive": "@angular-devkit/build-angular",
        "//packages/angular_devkit/core:npm_package_archive": "@angular-devkit/core",
        "//packages/angular_devkit/schematics:npm_package_archive": "@angular-devkit/schematics",
        "//packages/angular_devkit/build_optimizer:npm_package_archive": "@angular-devkit/build-optimizer",
        "//packages/angular_devkit/build_webpack:npm_package_archive": "@angular-devkit/build-webpack",
        "//packages/ngtools/webpack:npm_package_archive": "@ngtools/webpack",
        "//packages/schematics/angular:npm_package_archive": "@schematics/angular",
        "//packages/schematics/update:npm_package_archive": "@schematics/update",
    },
    test_files = ":angular_cli_sources",
)
