From 91b646717d9836215ff839fafcf148ded677006e Mon Sep 17 00:00:00 2001 From: Kristiyan Kostadinov Date: Wed, 6 Dec 2023 10:42:54 +0100 Subject: [PATCH] fix(material-luxon-adapter): error when added through ng add Currently adding the `@angular/material-luxon-adapter` module through `ng add` results in an error because it doesn't have an `ng add` schematic. These changes add a blank one so users don't get an error now and so that we can easily add more functionality in the future. --- src/material-luxon-adapter/BUILD.bazel | 1 + src/material-luxon-adapter/package.json | 1 + .../schematics/BUILD.bazel | 34 +++++++++++++++++++ .../schematics/collection.json | 10 ++++++ .../schematics/ng-add/index.ts | 15 ++++++++ .../schematics/package.json | 3 ++ 6 files changed, 64 insertions(+) create mode 100644 src/material-luxon-adapter/schematics/BUILD.bazel create mode 100644 src/material-luxon-adapter/schematics/collection.json create mode 100644 src/material-luxon-adapter/schematics/ng-add/index.ts create mode 100644 src/material-luxon-adapter/schematics/package.json diff --git a/src/material-luxon-adapter/BUILD.bazel b/src/material-luxon-adapter/BUILD.bazel index a96f68fd8f5e..65e855aa2c1e 100644 --- a/src/material-luxon-adapter/BUILD.bazel +++ b/src/material-luxon-adapter/BUILD.bazel @@ -41,6 +41,7 @@ ng_web_test_suite( ng_package( name = "npm_package", srcs = ["package.json"], + nested_packages = ["//src/material-luxon-adapter/schematics:npm_package"], tags = ["release-package"], deps = [":material-luxon-adapter"], ) diff --git a/src/material-luxon-adapter/package.json b/src/material-luxon-adapter/package.json index 51a9654322d7..1985174a2e3b 100644 --- a/src/material-luxon-adapter/package.json +++ b/src/material-luxon-adapter/package.json @@ -26,5 +26,6 @@ "@angular/material-luxon-adapter" ] }, + "schematics": "./schematics/collection.json", "sideEffects": false } diff --git a/src/material-luxon-adapter/schematics/BUILD.bazel b/src/material-luxon-adapter/schematics/BUILD.bazel new file mode 100644 index 000000000000..aaa2c12aa7dc --- /dev/null +++ b/src/material-luxon-adapter/schematics/BUILD.bazel @@ -0,0 +1,34 @@ +load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") +load("//tools:defaults.bzl", "pkg_npm", "ts_library") + +package(default_visibility = ["//visibility:public"]) + +copy_to_bin( + name = "schematics_assets", + srcs = glob(["**/*.json"]), +) + +ts_library( + name = "schematics", + srcs = glob( + ["**/*.ts"], + exclude = ["**/*.spec.ts"], + ), + # Schematics can not yet run in ESM module. For now we continue to use CommonJS. + # TODO(ESM): remove this once the Angular CLI supports ESM schematics. + devmode_module = "commonjs", + prodmode_module = "commonjs", + deps = [ + "@npm//@angular-devkit/schematics", + "@npm//@types/node", + ], +) + +# This package is intended to be combined into the main @angular/material-luxon-adapter package as a dep. +pkg_npm( + name = "npm_package", + deps = [ + ":schematics", + ":schematics_assets", + ], +) diff --git a/src/material-luxon-adapter/schematics/collection.json b/src/material-luxon-adapter/schematics/collection.json new file mode 100644 index 000000000000..b016bd5442b1 --- /dev/null +++ b/src/material-luxon-adapter/schematics/collection.json @@ -0,0 +1,10 @@ +{ + "$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json", + "schematics": { + "ng-add": { + "description": "Installs the Angular YouTube Player", + "factory": "./ng-add/index", + "hidden": true + } + } +} diff --git a/src/material-luxon-adapter/schematics/ng-add/index.ts b/src/material-luxon-adapter/schematics/ng-add/index.ts new file mode 100644 index 000000000000..b07c842d3231 --- /dev/null +++ b/src/material-luxon-adapter/schematics/ng-add/index.ts @@ -0,0 +1,15 @@ +/** + * @license + * Copyright Google LLC 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 + */ + +import {Rule} from '@angular-devkit/schematics'; + +export default function (): Rule { + // Noop schematic so the CLI doesn't throw if users try to `ng add` this package. + // Also allows us to add more functionality in the future. + return () => {}; +} diff --git a/src/material-luxon-adapter/schematics/package.json b/src/material-luxon-adapter/schematics/package.json new file mode 100644 index 000000000000..5bbefffbabee --- /dev/null +++ b/src/material-luxon-adapter/schematics/package.json @@ -0,0 +1,3 @@ +{ + "type": "commonjs" +}