Skip to content

Commit 3e458ee

Browse files
devversionkara
authored andcommitted
build: include importAs in metadata (#7448)
1 parent cef1eba commit 3e458ee

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

tools/package-tools/build-release.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function composeRelease(buildPackage: BuildPackage) {
2424
const {name, sourceDir} = buildPackage;
2525
const packageOut = buildPackage.outputDir;
2626
const releasePath = join(outputDir, 'releases', name);
27+
const importAsName = `@angular/${name}`;
2728

2829
inlinePackageMetadataFiles(packageOut);
2930

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

4950
replaceVersionPlaceholders(releasePath);
5051
createTypingsReexportFile(releasePath, './typings/index', name);
51-
createMetadataReexportFile(releasePath, './typings/index', name);
52+
createMetadataReexportFile(releasePath, './typings/index', name, importAsName);
5253

5354
if (buildPackage.secondaryEntryPoints.length) {
5455
createFilesForSecondaryEntryPoint(buildPackage, releasePath);
@@ -70,7 +71,8 @@ export function composeRelease(buildPackage: BuildPackage) {
7071
createMetadataReexportFile(
7172
releasePath,
7273
buildPackage.secondaryEntryPoints.concat(['typings/index']).map(p => `./${p}`),
73-
name);
74+
name,
75+
importAsName);
7476
}
7577
}
7678

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

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

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

tools/package-tools/metadata-reexport.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ import {writeFileSync} from 'fs';
22
import {join} from 'path';
33

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

89
const metadataJsonContent = JSON.stringify({
910
__symbolic: 'module',
1011
version: 3,
1112
metadata: {},
1213
exports: from.map(f => ({from: f})),
13-
flatModuleIndexRedirect: true
14+
flatModuleIndexRedirect: true,
15+
importAs: importAsName
1416
}, null, 2);
1517

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

0 commit comments

Comments
 (0)