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,23 +45,20 @@ 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
|
||||
if (nameParts[0].startsWith('@')) nameParts = nameParts.splice(1);
|
||||
let rel = Array(nameParts.length - 1).fill('..').join('/');
|
||||
if (!rel) {
|
||||
rel = '.';
|
||||
}
|
||||
const indexFile = nameParts[nameParts.length - 1];
|
||||
parsedPackage['main'] = `${rel}/bundles/${nameParts.join('-')}.umd.js`;
|
||||
parsedPackage['module'] = `${rel}/esm5/${indexFile}.js`;
|
||||
parsedPackage['es2015'] = `${rel}/esm2015/${indexFile}.js`;
|
||||
parsedPackage['typings'] = `./${indexFile}.d.ts`;
|
||||
return JSON.stringify(parsedPackage, null, 2);
|
||||
const parsedPackage = JSON.parse(content);
|
||||
let nameParts = parsedPackage['name'].split('/');
|
||||
// for scoped packages, we don't care about the scope segment of the path
|
||||
if (nameParts[0].startsWith('@')) nameParts = nameParts.splice(1);
|
||||
let rel = Array(nameParts.length - 1).fill('..').join('/');
|
||||
if (!rel) {
|
||||
rel = '.';
|
||||
}
|
||||
return content;
|
||||
const indexFile = nameParts[nameParts.length - 1];
|
||||
parsedPackage['main'] = `${rel}/bundles/${nameParts.join('-')}.umd.js`;
|
||||
parsedPackage['module'] = `${rel}/esm5/${indexFile}.js`;
|
||||
parsedPackage['es2015'] = `${rel}/esm2015/${indexFile}.js`;
|
||||
parsedPackage['typings'] = `./${indexFile}.d.ts`;
|
||||
return JSON.stringify(parsedPackage, null, 2);
|
||||
}
|
||||
|
||||
function writeFesm(file: string, baseDir: string) {
|
||||
|
@ -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);
|
||||
content = amendPackageJson(src, content);
|
||||
fs.writeFileSync(path.join(out, path.relative(srcDir, src)), content);
|
||||
if (path.basename(src) === 'package.json') {
|
||||
content = amendPackageJson(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