Skip to content

build: include importAs in metadata #7448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions tools/package-tools/build-release.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function composeRelease(buildPackage: BuildPackage) {
const {name, sourceDir} = buildPackage;
const packageOut = buildPackage.outputDir;
const releasePath = join(outputDir, 'releases', name);
const importAsName = `@angular/${name}`;

inlinePackageMetadataFiles(packageOut);

Expand All @@ -48,7 +49,7 @@ export function composeRelease(buildPackage: BuildPackage) {

replaceVersionPlaceholders(releasePath);
createTypingsReexportFile(releasePath, './typings/index', name);
createMetadataReexportFile(releasePath, './typings/index', name);
createMetadataReexportFile(releasePath, './typings/index', name, importAsName);

if (buildPackage.secondaryEntryPoints.length) {
createFilesForSecondaryEntryPoint(buildPackage, releasePath);
Expand All @@ -70,7 +71,8 @@ export function composeRelease(buildPackage: BuildPackage) {
createMetadataReexportFile(
releasePath,
buildPackage.secondaryEntryPoints.concat(['typings/index']).map(p => `./${p}`),
name);
name,
importAsName);
}
}

Expand All @@ -85,6 +87,7 @@ function createFilesForSecondaryEntryPoint(buildPackage: BuildPackage, releasePa
// * An index.d.ts file that re-exports the index.d.ts from the typings/ directory
// * A metadata.json re-export for this entry-point's metadata.
const entryPointDir = join(releasePath, entryPointName);
const importAsName = `@angular/${name}/${entryPointName}`;

mkdirpSync(entryPointDir);
createEntryPointPackageJson(entryPointDir, name, entryPointName);
Expand All @@ -98,12 +101,13 @@ function createFilesForSecondaryEntryPoint(buildPackage: BuildPackage, releasePa
// Create a typings and a metadata re-export within the entry-point to point to the
// typings we just copied.
createTypingsReexportFile(entryPointDir, `./typings/index`, 'index');
createMetadataReexportFile(entryPointDir, `./typings/index`, 'index');
createMetadataReexportFile(entryPointDir, `./typings/index`, 'index', importAsName);

// Finally, create both a d.ts and metadata file for this entry-point in the root of
// the package that re-exports from the entry-point's directory.
createTypingsReexportFile(releasePath, `./${entryPointName}/index`, entryPointName);
createMetadataReexportFile(releasePath, `./${entryPointName}/index`, entryPointName);
createMetadataReexportFile(releasePath, `./${entryPointName}/index`, entryPointName,
importAsName);
});
}

Expand Down
8 changes: 5 additions & 3 deletions tools/package-tools/metadata-reexport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import {writeFileSync} from 'fs';
import {join} from 'path';

/** Creates a metadata file that re-exports the metadata bundle inside of the typings. */
export function createMetadataReexportFile(destDir: string, from: string|string[], name: string) {
export function createMetadataReexportFile(destDir: string, from: string|string[],
entryPointName: string, importAsName: string) {
from = Array.isArray(from) ? from : [from];

const metadataJsonContent = JSON.stringify({
__symbolic: 'module',
version: 3,
metadata: {},
exports: from.map(f => ({from: f})),
flatModuleIndexRedirect: true
flatModuleIndexRedirect: true,
importAs: importAsName
}, null, 2);

writeFileSync(join(destDir, `${name}.metadata.json`), metadataJsonContent, 'utf-8');
writeFileSync(join(destDir, `${entryPointName}.metadata.json`), metadataJsonContent, 'utf-8');
}