Skip to content

Commit

Permalink
fix(material-date-fns-adapter): error when added through ng add
Browse files Browse the repository at this point in the history
Currently adding the `@angular/material-date-fns-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.
  • Loading branch information
crisbeto committed Dec 6, 2023
1 parent 338aa18 commit 2da9f6b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/material-date-fns-adapter/BUILD.bazel
Expand Up @@ -39,6 +39,7 @@ ng_web_test_suite(
ng_package(
name = "npm_package",
srcs = ["package.json"],
nested_packages = ["//src/material-date-fns-adapter/schematics:npm_package"],
tags = ["release-package"],
deps = [":material-date-fns-adapter"],
)
1 change: 1 addition & 0 deletions src/material-date-fns-adapter/package.json
Expand Up @@ -26,5 +26,6 @@
"@angular/material-date-fns-adapter"
]
},
"schematics": "./schematics/collection.json",
"sideEffects": false
}
34 changes: 34 additions & 0 deletions src/material-date-fns-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-date-fns-adapter package as a dep.
pkg_npm(
name = "npm_package",
deps = [
":schematics",
":schematics_assets",
],
)
10 changes: 10 additions & 0 deletions src/material-date-fns-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
}
}
}
15 changes: 15 additions & 0 deletions src/material-date-fns-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 () => {};
}
3 changes: 3 additions & 0 deletions src/material-date-fns-adapter/schematics/package.json
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

0 comments on commit 2da9f6b

Please sign in to comment.