Skip to content

build: do not ship load-example code to npm package [patch port] #18554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/components-examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ load("//tools:defaults.bzl", "ng_module", "ng_package")
load("//tools/highlight-files:index.bzl", "highlight_files")
load("//tools/package-docs-content:index.bzl", "package_docs_content")

EXAMPLE_PACKAGES = [
ALL_EXAMPLES = [
# TODO(devversion): try to have for each entry-point a bazel package so that
# we can automate this using the "package.bzl" variables. Currently generated
# with "bazel query 'kind("ng_module", //src/components-examples/...:*)' --output="label"
Expand Down Expand Up @@ -61,12 +61,12 @@ ng_module(
name = "components-examples",
srcs = glob(["*.ts"]) + [":example-module.ts"],
module_name = "@angular/components-examples",
deps = EXAMPLE_PACKAGES,
deps = ALL_EXAMPLES,
)

filegroup(
name = "example-source-files",
srcs = ["%s:source-files" % pkg for pkg in EXAMPLE_PACKAGES],
srcs = ["%s:source-files" % pkg for pkg in ALL_EXAMPLES],
)

highlight_files(
Expand Down Expand Up @@ -106,7 +106,7 @@ ng_package(
data = [":docs-content"],
entry_point = ":public-api.ts",
tags = ["docs-package"],
deps = [":components-examples"] + EXAMPLE_PACKAGES,
deps = [":components-examples"] + ALL_EXAMPLES,
)

genrule(
Expand Down
13 changes: 13 additions & 0 deletions src/components-examples/private/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package(default_visibility = ["//visibility:public"])

load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "private",
srcs = glob(["*.ts"]),
module_name = "@angular/components-examples/private",
deps = [
"//src/components-examples",
"@npm//@angular/core",
],
)
1 change: 1 addition & 0 deletions src/components-examples/private/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './load-example';
Original file line number Diff line number Diff line change
@@ -1,22 +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 {ComponentFactory, Injector, NgModuleFactory, Type} from '@angular/core';
import {EXAMPLE_COMPONENTS} from './example-module';
import {EXAMPLE_COMPONENTS} from '../example-module';

/** Asynchronously loads the specified example and returns its component factory. */
export async function loadExampleFactory(name: string, injector: Injector)
: Promise<ComponentFactory<any>> {
const {componentName, module} = EXAMPLE_COMPONENTS[name];
const importSpecifier = `@angular/components-examples/${module.importSpecifier}`;
// TODO(devversion): remove the NgFactory import when the `--config=view-engine` switch is gone.
const [moduleFactoryExports, moduleExports] = await Promise.all([
import(module.importSpecifier + '/index.ngfactory'),
import(module.importSpecifier)
import(importSpecifier + '/index.ngfactory'),
import(importSpecifier)
]);
const moduleFactory: NgModuleFactory<any> = moduleFactoryExports[`${module.name}NgFactory`];
const componentType: Type<any> = moduleExports[componentName];
Expand Down
1 change: 0 additions & 1 deletion src/components-examples/public-api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './example-data';
export * from './load-example';

// The example-module file will be auto-generated. As soon as the
// examples are being compiled, the module file will be generated.
Expand Down
1 change: 1 addition & 0 deletions src/dev-app/example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ng_module(
deps = [
"//src/cdk/coercion",
"//src/components-examples",
"//src/components-examples/private",
"//src/material/expansion",
"@npm//@angular/elements",
],
Expand Down
3 changes: 2 additions & 1 deletion src/dev-app/example/example.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

import {BooleanInput, coerceBooleanProperty} from '@angular/cdk/coercion';
import {EXAMPLE_COMPONENTS, loadExampleFactory} from '@angular/components-examples';
import {EXAMPLE_COMPONENTS} from '@angular/components-examples';
import {loadExampleFactory} from '@angular/components-examples/private';
import {Component, Injector, Input, OnInit, ViewContainerRef} from '@angular/core';

@Component({
Expand Down
7 changes: 5 additions & 2 deletions src/dev-app/system-config-tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ configureEntryPoint('components-examples');
configureEntryPoint('material');
configureEntryPoint('material-experimental');
configureEntryPoint('material-moment-adapter');
configureEntryPoint('google-maps');
configureEntryPoint('youtube-player');

// Configure all secondary entry-points.
CDK_PACKAGES.forEach(function(pkgName) {
Expand All @@ -48,8 +50,9 @@ MATERIAL_EXPERIMENTAL_PACKAGES.forEach(function(pkgName) {
MATERIAL_PACKAGES.forEach(function(pkgName) {
configureEntryPoint('material', pkgName);
});
configureEntryPoint('google-maps');
configureEntryPoint('youtube-player');

// Private secondary entry-points.
configureEntryPoint('components-examples', 'private');

/** Configures the specified package, its entry-point and its examples. */
function configureEntryPoint(pkgName, entryPoint) {
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ ng_module(
"//src/cdk/overlay",
"//src/cdk/scrolling",
"//src/cdk/testing/tests:test_components",
"//src/components-examples",
"//src/components-examples/private",
"//src/material-experimental/mdc-button",
"//src/material-experimental/mdc-card",
"//src/material-experimental/mdc-checkbox",
Expand Down
2 changes: 1 addition & 1 deletion src/e2e-app/example-viewer/example-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {loadExampleFactory} from '@angular/components-examples';
import {loadExampleFactory} from '@angular/components-examples/private';
import {Component, Injector, Input, OnInit, ViewContainerRef} from '@angular/core';

/** Loads an example component from `@angular/components-examples` */
Expand Down
3 changes: 2 additions & 1 deletion src/e2e-app/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"@angular/cdk-experimental/*": ["../cdk-experimental/*"],
"@angular/cdk-experimental": ["../cdk-experimental/"],
"@angular/material-moment-adapter": ["../material-moment-adapter/"],
"@angular/components-examples": ["../components-examples/"]
"@angular/components-examples": ["../components-examples/"],
"@angular/components-examples/*": ["../components-examples/*"]
}
},
"include": ["./**/*.ts"]
Expand Down
6 changes: 5 additions & 1 deletion tools/example-module/example-module.template
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export interface LiveExample {
export interface NgModuleInfo {
/** Name of the NgModule. */
name: string;
/** Import specifier that resolves to this NgModule. */
/**
* Import specifier that resolves to this module. The specifier is not scoped to
* `@angular/components-examples` because it's up to the consumer how the module is
* imported. For example, in the docs app, modules are lazily imported from `fesm2015/`.
*/
importSpecifier: string;
}

Expand Down
2 changes: 1 addition & 1 deletion tools/example-module/generate-example-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function inlineExampleModuleTemplate(parsedData: AnalyzedExamples): string {
additionalComponents: data.additionalComponents,
module: {
name: data.module.name,
importSpecifier: `@angular/components-examples/${data.module.packagePath}`,
importSpecifier: data.module.packagePath,
},
};

Expand Down