fix(bazel): ng_package includes transitive .d.ts and flatModuleMetadata (#22499)

Fixes #22419

PR Close #22499
This commit is contained in:
Alex Eagle 2018-02-28 09:12:39 -08:00
parent b6c941053e
commit aabe16c08c
9 changed files with 73 additions and 26 deletions

View File

@ -312,8 +312,11 @@ def ng_module_impl(ctx, ts_compile_actions):
# and only under Bazel # and only under Bazel
if hasattr(ctx.executable, "_index_bundler"): if hasattr(ctx.executable, "_index_bundler"):
bundle_index_metadata = _write_bundle_index(ctx) bundle_index_metadata = _write_bundle_index(ctx)
# note, not recursive providers["angular"]["flat_module_metadata"] = depset(bundle_index_metadata,
providers["angular"]["flat_module_metadata"] = depset(bundle_index_metadata) transitive = [
d.angular.flat_module_metadata
for d in ctx.attr.deps
if hasattr(d, "angular")])
return providers return providers

View File

@ -172,7 +172,9 @@ def _ng_package_impl(ctx):
progress_message = "Angular Packaging: building npm package for %s" % ctx.label.name, progress_message = "Angular Packaging: building npm package for %s" % ctx.label.name,
mnemonic = "AngularPackage", mnemonic = "AngularPackage",
inputs = esm5_sources.to_list() + inputs = esm5_sources.to_list() +
ctx.files.deps + depset(transitive = [d.typescript.transitive_declarations
for d in ctx.attr.deps
if hasattr(d, "typescript")]).to_list() +
ctx.files.srcs + ctx.files.srcs +
other_inputs, other_inputs,
outputs = [npm_package_directory], outputs = [npm_package_directory],

View File

@ -45,7 +45,6 @@ function main(args: string[]): number {
* @param content current file content * @param content current file content
*/ */
function amendPackageJson(filePath: string, content: string) { function amendPackageJson(filePath: string, content: string) {
if (path.basename(filePath) === 'package.json') {
const parsedPackage = JSON.parse(content); const parsedPackage = JSON.parse(content);
let nameParts = parsedPackage['name'].split('/'); let nameParts = parsedPackage['name'].split('/');
// for scoped packages, we don't care about the scope segment of the path // for scoped packages, we don't care about the scope segment of the path
@ -61,8 +60,6 @@ function main(args: string[]): number {
parsedPackage['typings'] = `./${indexFile}.d.ts`; parsedPackage['typings'] = `./${indexFile}.d.ts`;
return JSON.stringify(parsedPackage, null, 2); return JSON.stringify(parsedPackage, null, 2);
} }
return content;
}
function writeFesm(file: string, baseDir: string) { function writeFesm(file: string, baseDir: string) {
const parts = path.basename(file).split('__'); const parts = path.basename(file).split('__');
@ -132,8 +129,12 @@ function main(args: string[]): number {
for (const src of srcs) { for (const src of srcs) {
let content = fs.readFileSync(src, {encoding: 'utf-8'}); let content = fs.readFileSync(src, {encoding: 'utf-8'});
content = replaceVersionPlaceholders(src, content); content = replaceVersionPlaceholders(src, content);
if (path.basename(src) === 'package.json') {
content = amendPackageJson(src, content); content = amendPackageJson(src, content);
fs.writeFileSync(path.join(out, path.relative(srcDir, src)), content); }
const outputPath = path.join(out, path.relative(srcDir, src));
shx.mkdir('-p', path.dirname(outputPath));
fs.writeFileSync(outputPath, content);
} }
allsrcs.filter(filter('.bundle_index.metadata.json')).forEach((f: string) => { allsrcs.filter(filter('.bundle_index.metadata.json')).forEach((f: string) => {

View File

@ -17,9 +17,5 @@ ng_package(
], ],
entry_point = "packages/bazel/test/ng_package/example/index.js", entry_point = "packages/bazel/test/ng_package/example/index.js",
secondary_entry_points = ["secondary"], secondary_entry_points = ["secondary"],
deps = [ deps = [":example"],
":example",
# FIXME(#22419)
"//packages/bazel/test/ng_package/example/secondary",
],
) )

View File

@ -1 +1,9 @@
/**
* @license
* Copyright Google Inc. 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
*/
export * from './mymodule'; export * from './mymodule';

View File

@ -1,4 +1,13 @@
/**
* @license
* Copyright Google Inc. 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 {NgModule} from '@angular/core'; import {NgModule} from '@angular/core';
import {a} from './secondary/secondarymodule';
@NgModule({}) @NgModule({})
export class MyModule { export class MyModule {

View File

@ -1 +1,9 @@
/**
* @license
* Copyright Google Inc. 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
*/
export * from './secondarymodule'; export * from './secondarymodule';

View File

@ -1,5 +1,15 @@
/**
* @license
* Copyright Google Inc. 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 {NgModule} from '@angular/core'; import {NgModule} from '@angular/core';
@NgModule({}) @NgModule({})
export class SecondaryModule { export class SecondaryModule {
} }
export const a = 1;

View File

@ -41,6 +41,16 @@ describe('ng_package', () => {
expect(shx.ls('-R', 'esm5').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected); expect(shx.ls('-R', 'esm5').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
expect(shx.ls('-R', 'esm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected); expect(shx.ls('-R', 'esm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
}); });
it('should have right secondary sources', () => {
const expected = [
'index.d.ts',
'package.json',
'secondary.d.ts',
'secondary.metadata.json',
'secondarymodule.d.ts',
];
expect(shx.ls('-R', 'secondary').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
});
it('should have main entry point package.json properties set', () => { it('should have main entry point package.json properties set', () => {
const packageJson = JSON.parse(fs.readFileSync('package.json', UTF8)); const packageJson = JSON.parse(fs.readFileSync('package.json', UTF8));
expect(packageJson['main']).toBe('./bundles/example.umd.js'); expect(packageJson['main']).toBe('./bundles/example.umd.js');