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.
|
// the property as processed even if its underlying format has been built already.
|
||||||
if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) {
|
if (!compiledFormats.has(formatPath) && (compileAllFormats || isFirstFormat)) {
|
||||||
const bundle = makeEntryPointBundle(
|
const bundle = makeEntryPointBundle(
|
||||||
fileSystem, entryPoint.path, formatPath, entryPoint.typings, isCore, property, format,
|
fileSystem, entryPoint, formatPath, isCore, property, format, processDts, pathMappings);
|
||||||
processDts, pathMappings);
|
|
||||||
if (bundle) {
|
if (bundle) {
|
||||||
logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`);
|
logger.info(`Compiling ${entryPoint.name} : ${property} as ${format}`);
|
||||||
const transformedFiles = transformer.transform(bundle);
|
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 {NgtscCompilerHost} from '../../../src/ngtsc/file_system/src/compiler_host';
|
||||||
import {PathMappings} from '../utils';
|
import {PathMappings} from '../utils';
|
||||||
import {BundleProgram, makeBundleProgram} from './bundle_program';
|
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';
|
import {NgccSourcesCompilerHost} from './ngcc_compiler_host';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A bundle of files and paths (and TS programs) that correspond to a particular
|
* A bundle of files and paths (and TS programs) that correspond to a particular
|
||||||
* format of a package entry-point.
|
* format of a package entry-point.
|
||||||
@ -38,26 +37,26 @@ export interface EntryPointBundle {
|
|||||||
* @param transformDts Whether to transform the typings along with this bundle.
|
* @param transformDts Whether to transform the typings along with this bundle.
|
||||||
*/
|
*/
|
||||||
export function makeEntryPointBundle(
|
export function makeEntryPointBundle(
|
||||||
fs: FileSystem, entryPointPath: string, formatPath: string, typingsPath: string,
|
fs: FileSystem, entryPoint: EntryPoint, formatPath: string, isCore: boolean,
|
||||||
isCore: boolean, formatProperty: EntryPointJsonProperty, format: EntryPointFormat,
|
formatProperty: EntryPointJsonProperty, format: EntryPointFormat, transformDts: boolean,
|
||||||
transformDts: boolean, pathMappings?: PathMappings): EntryPointBundle|null {
|
pathMappings?: PathMappings): EntryPointBundle|null {
|
||||||
// Create the TS program and necessary helpers.
|
// Create the TS program and necessary helpers.
|
||||||
const options: ts.CompilerOptions = {
|
const options: ts.CompilerOptions = {
|
||||||
allowJs: true,
|
allowJs: true,
|
||||||
maxNodeModuleJsDepth: Infinity,
|
maxNodeModuleJsDepth: Infinity,
|
||||||
noLib: true,
|
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 dtsHost = new NgtscCompilerHost(fs, options);
|
||||||
const rootDirs = [absoluteFrom(entryPointPath)];
|
const rootDirs = [absoluteFrom(entryPoint.path)];
|
||||||
|
|
||||||
// Create the bundle programs, as necessary.
|
// Create the bundle programs, as necessary.
|
||||||
const src = makeBundleProgram(
|
const src = makeBundleProgram(
|
||||||
fs, isCore, resolve(entryPointPath, formatPath), 'r3_symbols.js', options, srcHost);
|
fs, isCore, resolve(entryPoint.path, formatPath), 'r3_symbols.js', options, srcHost);
|
||||||
const dts = transformDts ?
|
const dts = transformDts ? makeBundleProgram(
|
||||||
makeBundleProgram(
|
fs, isCore, resolve(entryPoint.path, entryPoint.typings),
|
||||||
fs, isCore, resolve(entryPointPath, typingsPath), 'r3_symbols.d.ts', options, dtsHost) :
|
'r3_symbols.d.ts', options, dtsHost) :
|
||||||
null;
|
null;
|
||||||
const isFlatCore = isCore && src.r3SymbolsFile === null;
|
const isFlatCore = isCore && src.r3SymbolsFile === null;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
import {absoluteFrom, getFileSystem} from '../../../src/ngtsc/file_system';
|
||||||
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
import {runInEachFileSystem} from '../../../src/ngtsc/file_system/testing';
|
||||||
import {loadTestFiles} from '../../../test/helpers';
|
import {loadTestFiles} from '../../../test/helpers';
|
||||||
|
import {EntryPoint} from '../../src/packages/entry_point';
|
||||||
import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
import {makeEntryPointBundle} from '../../src/packages/entry_point_bundle';
|
||||||
|
|
||||||
runInEachFileSystem(() => {
|
runInEachFileSystem(() => {
|
||||||
@ -128,8 +129,16 @@ runInEachFileSystem(() => {
|
|||||||
() => {
|
() => {
|
||||||
setupMockFileSystem();
|
setupMockFileSystem();
|
||||||
const fs = getFileSystem();
|
const fs = getFileSystem();
|
||||||
const esm5bundle = makeEntryPointBundle(
|
const entryPoint: EntryPoint = {
|
||||||
fs, '/node_modules/test', './index.js', './index.d.ts', false, 'esm5', 'esm5', true) !;
|
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))
|
expect(esm5bundle.src.program.getSourceFiles().map(sf => sf.fileName))
|
||||||
.toEqual(jasmine.arrayWithExactContents([
|
.toEqual(jasmine.arrayWithExactContents([
|
||||||
|
@ -356,7 +356,7 @@ runInEachFileSystem(() => {
|
|||||||
fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty,
|
fs: FileSystem, entryPoint: EntryPoint, formatProperty: EntryPointJsonProperty,
|
||||||
format: EntryPointFormat): EntryPointBundle {
|
format: EntryPointFormat): EntryPointBundle {
|
||||||
return makeEntryPointBundle(
|
return makeEntryPointBundle(
|
||||||
fs, entryPoint.path, entryPoint.packageJson[formatProperty] !, entryPoint.typings, false,
|
fs, entryPoint, entryPoint.packageJson[formatProperty] !, false, formatProperty, format,
|
||||||
formatProperty, format, true) !;
|
true) !;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user