Skip to content

Commit

Permalink
fix(material-luxon-adapter): error when added through ng add
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
crisbeto committed Dec 6, 2023
1 parent 2da9f6b commit 91b6467
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/material-luxon-adapter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)
1 change: 1 addition & 0 deletions src/material-luxon-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"@angular/material-luxon-adapter"
]
},
"schematics": "./schematics/collection.json",
"sideEffects": false
}
34 changes: 34 additions & 0 deletions src/material-luxon-adapter/schematics/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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",
],
)
10 changes: 10 additions & 0 deletions src/material-luxon-adapter/schematics/collection.json
Original file line number Diff line number Diff line change
@@ -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-luxon-adapter/schematics/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -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-luxon-adapter/schematics/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}

0 comments on commit 91b6467

Please sign in to comment.