fix(bazel): ng_package includes transitive .d.ts and flatModuleMetadata (#22499)
Fixes #22419 PR Close #22499
This commit is contained in:
parent
b6c941053e
commit
aabe16c08c
|
@ -312,8 +312,11 @@ def ng_module_impl(ctx, ts_compile_actions):
|
|||
# and only under Bazel
|
||||
if hasattr(ctx.executable, "_index_bundler"):
|
||||
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
|
||||
|
||||
|
|
|
@ -172,7 +172,9 @@ def _ng_package_impl(ctx):
|
|||
progress_message = "Angular Packaging: building npm package for %s" % ctx.label.name,
|
||||
mnemonic = "AngularPackage",
|
||||
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 +
|
||||
other_inputs,
|
||||
outputs = [npm_package_directory],
|
||||
|
|
|
@ -45,7 +45,6 @@ function main(args: string[]): number {
|
|||
* @param content current file content
|
||||
*/
|
||||
function amendPackageJson(filePath: string, content: string) {
|
||||
if (path.basename(filePath) === 'package.json') {
|
||||
const parsedPackage = JSON.parse(content);
|
||||
let nameParts = parsedPackage['name'].split('/');
|
||||
// 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`;
|
||||
return JSON.stringify(parsedPackage, null, 2);
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
function writeFesm(file: string, baseDir: string) {
|
||||
const parts = path.basename(file).split('__');
|
||||
|
@ -132,8 +129,12 @@ function main(args: string[]): number {
|
|||
for (const src of srcs) {
|
||||
let content = fs.readFileSync(src, {encoding: 'utf-8'});
|
||||
content = replaceVersionPlaceholders(src, content);
|
||||
if (path.basename(src) === 'package.json') {
|
||||
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) => {
|
||||
|
|
|
@ -17,9 +17,5 @@ ng_package(
|
|||
],
|
||||
entry_point = "packages/bazel/test/ng_package/example/index.js",
|
||||
secondary_entry_points = ["secondary"],
|
||||
deps = [
|
||||
":example",
|
||||
# FIXME(#22419)
|
||||
"//packages/bazel/test/ng_package/example/secondary",
|
||||
],
|
||||
deps = [":example"],
|
||||
)
|
||||
|
|
|
@ -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';
|
|
@ -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 {a} from './secondary/secondarymodule';
|
||||
|
||||
@NgModule({})
|
||||
export class MyModule {
|
||||
|
|
|
@ -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';
|
||||
|
|
|
@ -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';
|
||||
|
||||
@NgModule({})
|
||||
export class SecondaryModule {
|
||||
}
|
||||
|
||||
export const a = 1;
|
||||
|
|
|
@ -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', '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', () => {
|
||||
const packageJson = JSON.parse(fs.readFileSync('package.json', UTF8));
|
||||
expect(packageJson['main']).toBe('./bundles/example.umd.js');
|
||||
|
|
Loading…
Reference in New Issue