fix(bazel): ng_package should include private exports in fesms (#23054)
PR Close #23054
This commit is contained in:
@ -9,8 +9,8 @@ def _extract_flat_module_index(ctx):
|
||||
files = []
|
||||
for dep in ctx.attr.deps:
|
||||
if hasattr(dep, "angular"):
|
||||
for metadata in dep.angular.flat_module_metadata:
|
||||
files.extend([metadata.metadata_file, metadata.typings_file])
|
||||
metadata = dep.angular.flat_module_metadata
|
||||
files.extend([metadata.metadata_file, metadata.typings_file])
|
||||
return [DefaultInfo(files = depset(files))]
|
||||
|
||||
extract_flat_module_index = rule(
|
||||
|
@ -37,7 +37,11 @@ function createSyntheticIndexHost<H extends ts.CompilerHost>(
|
||||
newHost.getSourceFile =
|
||||
(fileName: string, languageVersion: ts.ScriptTarget, onError?: (message: string) => void) => {
|
||||
if (path.normalize(fileName) == normalSyntheticIndexName) {
|
||||
return ts.createSourceFile(fileName, indexContent, languageVersion, true);
|
||||
const sf = ts.createSourceFile(fileName, indexContent, languageVersion, true);
|
||||
if ((delegate as any).fileNameToModuleName) {
|
||||
sf.moduleName = (delegate as any).fileNameToModuleName(fileName);
|
||||
}
|
||||
return sf;
|
||||
}
|
||||
return delegate.getSourceFile(fileName, languageVersion, onError);
|
||||
};
|
||||
@ -48,10 +52,10 @@ function createSyntheticIndexHost<H extends ts.CompilerHost>(
|
||||
sourceFiles: Readonly<ts.SourceFile>[]) => {
|
||||
delegate.writeFile(fileName, data, writeByteOrderMark, onError, sourceFiles);
|
||||
if (fileName.match(DTS) && sourceFiles && sourceFiles.length == 1 &&
|
||||
path.normalize(sourceFiles[0].fileName) == normalSyntheticIndexName) {
|
||||
path.normalize(sourceFiles[0].fileName) === normalSyntheticIndexName) {
|
||||
// If we are writing the synthetic index, write the metadata along side.
|
||||
const metadataName = fileName.replace(DTS, '.metadata.json');
|
||||
fs.writeFileSync(metadataName, indexMetadata, {encoding: 'utf8'});
|
||||
delegate.writeFile(metadataName, indexMetadata, writeByteOrderMark, onError, []);
|
||||
}
|
||||
};
|
||||
return newHost;
|
||||
@ -61,7 +65,20 @@ export function createBundleIndexHost<H extends ts.CompilerHost>(
|
||||
ngOptions: CompilerOptions, rootFiles: ReadonlyArray<string>,
|
||||
host: H): {host: H, indexName?: string, errors?: ts.Diagnostic[]} {
|
||||
const files = rootFiles.filter(f => !DTS.test(f));
|
||||
if (files.length != 1) {
|
||||
let indexFile: string|undefined;
|
||||
if (files.length === 1) {
|
||||
indexFile = files[0];
|
||||
} else {
|
||||
for (const f of files) {
|
||||
// Assume the shortest file path called index.ts is the entry point
|
||||
if (f.endsWith(path.sep + 'index.ts')) {
|
||||
if (!indexFile || indexFile.length > f.length) {
|
||||
indexFile = f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!indexFile) {
|
||||
return {
|
||||
host,
|
||||
errors: [{
|
||||
@ -75,8 +92,8 @@ export function createBundleIndexHost<H extends ts.CompilerHost>(
|
||||
}]
|
||||
};
|
||||
}
|
||||
const file = files[0];
|
||||
const indexModule = file.replace(/\.ts$/, '');
|
||||
|
||||
const indexModule = indexFile.replace(/\.ts$/, '');
|
||||
const bundler = new MetadataBundler(
|
||||
indexModule, ngOptions.flatModuleId, new CompilerHostAdapter(host),
|
||||
ngOptions.flatModulePrivateSymbolPrefix);
|
||||
|
@ -1,43 +0,0 @@
|
||||
#!/usr/bin/env node
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
|
||||
// Must be imported first, because Angular decorators throw on load.
|
||||
import 'reflect-metadata';
|
||||
|
||||
import * as ts from 'typescript';
|
||||
import * as path from 'path';
|
||||
import {readCommandLineAndConfiguration} from '../main';
|
||||
import {createBundleIndexHost} from './bundle_index_host';
|
||||
import * as ng from '../transformers/entry_points';
|
||||
|
||||
export function main(args: string[], consoleError: (s: string) => void = console.error): number {
|
||||
const {options, rootNames} = readCommandLineAndConfiguration(args);
|
||||
const host = ng.createCompilerHost({options});
|
||||
const {host: bundleHost, indexName, errors} = createBundleIndexHost(options, rootNames, host);
|
||||
if (!indexName) {
|
||||
console.error('Did not find an index.ts in the top-level of the package.');
|
||||
return 1;
|
||||
}
|
||||
// The index file is synthetic, so we have to add it to the program after parsing the tsconfig
|
||||
rootNames.push(indexName);
|
||||
const program = ts.createProgram(rootNames, options, bundleHost);
|
||||
const indexSourceFile = program.getSourceFile(indexName);
|
||||
if (!indexSourceFile) {
|
||||
console.error(`${indexSourceFile} is not in the program. Please file a bug.`);
|
||||
return 1;
|
||||
}
|
||||
program.emit(indexSourceFile);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// CLI entry point
|
||||
if (require.main === module) {
|
||||
const args = process.argv.slice(2);
|
||||
process.exitCode = main(args);
|
||||
}
|
@ -27,7 +27,6 @@
|
||||
"index.ts",
|
||||
"ngtools2.ts",
|
||||
"src/main.ts",
|
||||
"src/metadata/bundle_index_main.ts",
|
||||
"src/extract_i18n.ts",
|
||||
"src/language_services.ts",
|
||||
"../../node_modules/@types/node/index.d.ts",
|
||||
|
Reference in New Issue
Block a user