Skip to content

Commit eca5016

Browse files
committed
fix(material-moment-adapter): error when added through ng add
Currently adding the `@angular/material-moment-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.
1 parent 91b6467 commit eca5016

File tree

6 files changed

+64
-0
lines changed

6 files changed

+64
-0
lines changed

src/material-moment-adapter/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ ng_web_test_suite(
4040
ng_package(
4141
name = "npm_package",
4242
srcs = ["package.json"],
43+
nested_packages = ["//src/material-moment-adapter/schematics:npm_package"],
4344
tags = ["release-package"],
4445
deps = [":material-moment-adapter"],
4546
)

src/material-moment-adapter/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,6 @@
2626
"@angular/material-moment-adapter"
2727
]
2828
},
29+
"schematics": "./schematics/collection.json",
2930
"sideEffects": false
3031
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin")
2+
load("//tools:defaults.bzl", "pkg_npm", "ts_library")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
copy_to_bin(
7+
name = "schematics_assets",
8+
srcs = glob(["**/*.json"]),
9+
)
10+
11+
ts_library(
12+
name = "schematics",
13+
srcs = glob(
14+
["**/*.ts"],
15+
exclude = ["**/*.spec.ts"],
16+
),
17+
# Schematics can not yet run in ESM module. For now we continue to use CommonJS.
18+
# TODO(ESM): remove this once the Angular CLI supports ESM schematics.
19+
devmode_module = "commonjs",
20+
prodmode_module = "commonjs",
21+
deps = [
22+
"@npm//@angular-devkit/schematics",
23+
"@npm//@types/node",
24+
],
25+
)
26+
27+
# This package is intended to be combined into the main @angular/material-moment-adapter package as a dep.
28+
pkg_npm(
29+
name = "npm_package",
30+
deps = [
31+
":schematics",
32+
":schematics_assets",
33+
],
34+
)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "../node_modules/@angular-devkit/schematics/collection-schema.json",
3+
"schematics": {
4+
"ng-add": {
5+
"description": "Installs the Angular YouTube Player",
6+
"factory": "./ng-add/index",
7+
"hidden": true
8+
}
9+
}
10+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Rule} from '@angular-devkit/schematics';
10+
11+
export default function (): Rule {
12+
// Noop schematic so the CLI doesn't throw if users try to `ng add` this package.
13+
// Also allows us to add more functionality in the future.
14+
return () => {};
15+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"type": "commonjs"
3+
}

0 commit comments

Comments
 (0)