refactor(ivy): ngcc - pass whole entry-point object to `makeEntryPointBundle()` (#30591)
This simplifies the interface somewhat but also allows us to make use of other properties of the EntryPoint object in the future. PR Close #30591
This commit is contained in:
parent
2dfd97d8f0
commit
a94bdc6793
|
@ -154,8 +154,7 @@ export function mainNgcc(
|
|||
// the property as processed even if its underlying format has been built already.
|
||||
if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) {
|
||||
const bundle = makeEntryPointBundle(
|
||||
fileSystem, entryPoint.path, formatPath, entryPoint.typings, isCore, property, format,
|
||||
processDts, pathMappings);
|
||||
fileSystem, entryPoint, formatPath, isCore, property, format, processDts, pathMappings);
|
||||
if (bundle) {
|
||||
logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`);
|
||||
const transformedFiles = transformer.transform(bundle);
|
||||
|
|
|
@ -10,10 +10,9 @@ import {AbsoluteFsPath, FileSystem, absoluteFrom, resolve} from '../../../src/ng
|
|||
import {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host';
|
||||
import {PathMappings} from '../utils';
|
||||
import {BundleProgram, makeBundleProgram} from './bundle_program';
|
||||
import {EntryPointFormat, EntryPointJsonProperty} from './entry_point';
|
||||
import {EntryPoint, EntryPointFormat, EntryPointJsonProperty} from './entry_point';
|
||||
import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
|
||||
|
||||
|
||||
/**
|
||||
* A bundle of files and paths (and TS programs) that correspond to a particular
|
||||
* format of a package entry-point.
|
||||
|
@ -38,26 +37,26 @@ export interface EntryPointBundle {
|
|||
* @param transformDts Whether to transform the typings along with this bundle.
|
||||
*/
|
||||
export function makeEntryPointBundle(
|
||||
fs: FileSystem, entryPointPath: string, formatPath: string, typingsPath: string,
|
||||
isCore: boolean, formatProperty: EntryPointJsonProperty, format: EntryPointFormat,
|
||||
transformDts: boolean, pathMappings?: PathMappings): EntryPointBundle|null {
|
||||
fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean,
|
||||
formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean,
|
||||
pathMappings?: PathMappings): EntryPointBundle|null {
|
||||
// Create the TS program and necessary helpers.
|
||||
const options: ts.CompilerOptions = {
|
||||
allowJs: true,
|
||||
maxNodeModuleJsDepth: Infinity,
|
||||
noLib: true,
|
||||
rootDir: entryPointPath, ...pathMappings
|
||||
rootDir: entryPoint.path, ...pathMappings
|
||||
};
|
||||
const srcHost = new NgccSourcesCompilerHost(fs, options, entryPointPath);
|
||||
const srcHost = new NgccSourcesCompilerHost(fs, options, entryPoint.path);
|
||||
const dtsHost = new NgtscCompilerHost(fs, options);
|
||||
const rootDirs = [absoluteFrom(entryPointPath)];
|
||||
const rootDirs = [absoluteFrom(entryPoint.path)];
|
||||
|
||||
// Create the bundle programs, as necessary.
|
||||
const src = makeBundleProgram(
|
||||
fs, isCore, resolve(entryPointPath, formatPath), 'r3_symbols.js', options, srcHost);
|
||||
const dts = transformDts ?
|
||||
makeBundleProgram(
|
||||
fs, isCore, resolve(entryPointPath, typingsPath), 'r3_symbols.d.ts', options, dtsHost) :
|
||||
fs, isCore, resolve(entryPoint.path, formatPath), 'r3_symbols.js', options, srcHost);
|
||||
const dts = transformDts ? makeBundleProgram(
|
||||
fs, isCore, resolve(entryPoint.path, entryPoint.typings),
|
||||
'r3_symbols.d.ts', options, dtsHost) :
|
||||
null;
|
||||
const isFlatCore = isCore && src.r3SymbolsFile === null;
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||
import {loadTestFiles} from '../../../test/helpers';
|
||||
import {EntryPoint} from '../../src/packages/entry_point';
|
||||
import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||
|
||||
runInEachFileSystem(() => {
|
||||
|
@ -128,8 +129,16 @@ runInEachFileSystem(() => {
|
|||
() => {
|
||||
setupMockFileSystem();
|
||||
const fs = getFileSystem();
|
||||
const esm5bundle = makeEntryPointBundle(
|
||||
fs, '/node_modules/test', './index.js', './index.d.ts', false, 'esm5', 'esm5', true) !;
|
||||
const entryPoint: EntryPoint = {
|
||||
name: 'test',
|
||||
packageJson: {name: 'test'},
|
||||
package: absoluteFrom('/node_modules/test'),
|
||||
path: absoluteFrom('/node_modules/test'),
|
||||
typings: absoluteFrom('/node_modules/test/index.d.ts'),
|
||||
compiledByAngular: true,
|
||||
};
|
||||
const esm5bundle =
|
||||
makeEntryPointBundle(fs, entryPoint, './index.js', false, 'esm5', 'esm5', true) !;
|
||||
|
||||
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
|
||||
.toEqual(jasmine.arrayWithExactContents([
|
||||
|
|
|
@ -356,7 +356,7 @@ runInEachFileSystem(() => {
|
|||
fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty,
|
||||
format: EntryPointFormat): EntryPointBundle {
|
||||
return makeEntryPointBundle(
|
||||
fs, entryPoint.path, entryPoint.packageJson[formatProperty] !, entryPoint.typings, false,
|
||||
formatProperty, format, true) !;
|
||||
fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, formatProperty, format,
|
||||
true) !;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue