Skip to content
This repository was archived by the owner on Jan 6, 2025. It is now read-only.

Commit 006cb81

Browse files
devversionCaerusKaru
authored andcommitted
build: UMD module references incorrect flex-layout globals (#978)
Fixes #977
1 parent 2411ac2 commit 006cb81

File tree

5 files changed

+47
-16
lines changed

5 files changed

+47
-16
lines changed

tools/gulp/packages.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,8 @@ export const flexLayoutPackage = new BuildPackage('flex-layout', []);
55

66
// To avoid refactoring of the project the Flex-Layout package will map to the source path `lib/`.
77
flexLayoutPackage.sourceDir = join(buildConfig.packagesDir, 'lib');
8+
9+
// Re-export secondary entry-points at the root. We don't want to require users to add
10+
// UMD bundles for each secondary entry-points.
11+
flexLayoutPackage.exportsSecondaryEntryPointsAtRoot = true;
12+
flexLayoutPackage.exportsSecondaryEntryPointsAtRootExcludes = ['server'];

tools/package-tools/build-bundles.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,13 @@ const bundlesDir = join(buildConfig.outputDir, 'bundles');
1717

1818
/** Utility for creating bundles from raw ngc output. */
1919
export class PackageBundler {
20-
constructor(private buildPackage: BuildPackage) {}
20+
21+
/** Name of the AMD module for the primary entry point of the build package. */
22+
private readonly primaryAmdModuleName: string;
23+
24+
constructor(private buildPackage: BuildPackage) {
25+
this.primaryAmdModuleName = this.getAmdModuleName(buildPackage.name);
26+
}
2127

2228
/** Creates all bundles for the package and all associated entry points (UMD, ES5, ES2015). */
2329
async createBundles() {
@@ -36,7 +42,7 @@ export class PackageBundler {
3642
entryFile: this.buildPackage.entryFilePath,
3743
esm5EntryFile: join(this.buildPackage.esm5OutputDir, 'index.js'),
3844
importName: `@angular/${this.buildPackage.name}`,
39-
moduleName: `ng.${this.buildPackage.name}`,
45+
moduleName: this.primaryAmdModuleName,
4046
esm2015Dest: join(bundlesDir, `${packageName}.js`),
4147
esm5Dest: join(bundlesDir, `${packageName}.es5.js`),
4248
umdDest: join(bundlesDir, `${packageName}.umd.js`),
@@ -45,21 +51,20 @@ export class PackageBundler {
4551
}
4652

4753
/** Bundles a single secondary entry-point w/ given entry file, e.g. @angular/cdk/a11y */
48-
private async bundleSecondaryEntryPoint(entryPoint: string) {
54+
private async bundleSecondaryEntryPoint(entryPointName: string) {
4955
const packageName = this.buildPackage.name;
50-
const entryFile = join(this.buildPackage.outputDir, entryPoint, 'index.js');
51-
const esm5EntryFile = join(this.buildPackage.esm5OutputDir, entryPoint, 'index.js');
52-
const dashedEntryName = dashCaseToCamelCase(entryPoint);
56+
const entryFile = join(this.buildPackage.outputDir, entryPointName, 'index.js');
57+
const esm5EntryFile = join(this.buildPackage.esm5OutputDir, entryPointName, 'index.js');
5358

5459
return this.bundleEntryPoint({
5560
entryFile,
5661
esm5EntryFile,
57-
importName: `@angular/${this.buildPackage.name}/${dashedEntryName}`,
58-
moduleName: `ng.${packageName}.${dashedEntryName}`,
59-
esm2015Dest: join(bundlesDir, `${packageName}`, `${entryPoint}.js`),
60-
esm5Dest: join(bundlesDir, `${packageName}`, `${entryPoint}.es5.js`),
61-
umdDest: join(bundlesDir, `${packageName}-${entryPoint}.umd.js`),
62-
umdMinDest: join(bundlesDir, `${packageName}-${entryPoint}.umd.min.js`),
62+
importName: `@angular/${this.buildPackage.name}/${entryPointName}`,
63+
moduleName: this.getAmdModuleName(packageName, entryPointName),
64+
esm2015Dest: join(bundlesDir, `${packageName}`, `${entryPointName}.js`),
65+
esm5Dest: join(bundlesDir, `${packageName}`, `${entryPointName}.es5.js`),
66+
umdDest: join(bundlesDir, `${packageName}-${entryPointName}.umd.js`),
67+
umdMinDest: join(bundlesDir, `${packageName}-${entryPointName}.umd.min.js`),
6368
});
6469
}
6570

@@ -150,7 +155,7 @@ export class PackageBundler {
150155
// secondary entry-points from the rollup globals because we want the UMD for this package
151156
// to include *all* of the sources for those entry-points.
152157
if (this.buildPackage.exportsSecondaryEntryPointsAtRoot &&
153-
config.moduleName === `ng.${this.buildPackage.name}`) {
158+
config.moduleName === this.primaryAmdModuleName) {
154159

155160
const importRegex = new RegExp(`@angular/${this.buildPackage.name}/.+`);
156161
external = external.filter(e => !importRegex.test(e));
@@ -181,8 +186,18 @@ export class PackageBundler {
181186
return map;
182187
}, {} as {[key: string]: string});
183188
}
184-
}
185189

190+
/** Gets the AMD module name for a package and an optional entry point. */
191+
private getAmdModuleName(packageName: string, entryPointName?: string) {
192+
let amdModuleName = `ng.${dashCaseToCamelCase(packageName)}`;
193+
194+
if (entryPointName) {
195+
amdModuleName += `.${dashCaseToCamelCase(entryPointName)}`;
196+
}
197+
198+
return amdModuleName;
199+
}
200+
}
186201

187202
/** Configuration for creating library bundles. */
188203
interface BundlesConfig {

tools/package-tools/build-package.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ export class BuildPackage {
2929
/** Whether this package will re-export its secondary-entry points at the root module. */
3030
exportsSecondaryEntryPointsAtRoot = false;
3131

32+
/** List of secondary entry points that should not be re-exported in the primary entry point. */
33+
exportsSecondaryEntryPointsAtRootExcludes: string[] = [];
34+
3235
/** Whether the secondary entry-point styles should be copied to the release output. */
3336
copySecondaryEntryPointStylesToRoot = false;
3437

@@ -52,6 +55,12 @@ export class BuildPackage {
5255
}
5356
private _secondaryEntryPoints?: string[];
5457

58+
/** Secondary entry points that should be re-exported in the primary entry point. */
59+
get reexportedSecondaryEntryPoints(): string[] {
60+
return this.secondaryEntryPoints
61+
.filter(p => !this.exportsSecondaryEntryPointsAtRootExcludes.includes(p));
62+
}
63+
5564
constructor(readonly name: string, readonly dependencies: BuildPackage[] = []) {
5665
this.sourceDir = join(packagesDir, name);
5766
this.outputDir = join(outputDir, 'packages', name);

tools/package-tools/build-release.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ export function composeRelease(buildPackage: BuildPackage) {
6262
if (buildPackage.exportsSecondaryEntryPointsAtRoot) {
6363
// Add re-exports to the root d.ts file to prevent errors of the form
6464
// "@angular/material/material has no exported member 'MATERIAL_SANITY_CHECKS."
65-
const es2015Exports = buildPackage.secondaryEntryPoints
65+
const es2015Exports = buildPackage.reexportedSecondaryEntryPoints
6666
.map(p => `export * from './${p}';`).join('\n');
6767
appendFileSync(join(releasePath, `${name}.d.ts`), es2015Exports, 'utf-8');
6868

6969
// When re-exporting secondary entry-points, we need to manually create a metadata file that
7070
// re-exports everything.
7171
createMetadataReexportFile(
7272
releasePath,
73-
buildPackage.secondaryEntryPoints.concat(['typings/index']).map(p => `./${p}`),
73+
buildPackage.reexportedSecondaryEntryPoints.concat(['typings/index']).map(p => `./${p}`),
7474
name,
7575
importAsName);
7676
}

tools/package-tools/rollup-globals.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const flexLayoutSecondaryEntryPoints = getSubdirectoryNames(join(buildConfig.pac
1212
/** Object with all flex layout entry points in the format of Rollup globals. */
1313
const rollupFlexLayoutEntryPoints = flexLayoutSecondaryEntryPoints
1414
.reduce((globals: any, entryPoint: string) => {
15+
// Note that this needs to be in sync with the UMD module name format in "build-bundles.ts".
1516
globals[`@angular/flex-layout/${entryPoint}`] =
1617
`ng.flexLayout.${dashCaseToCamelCase(entryPoint)}`;
1718
return globals;
@@ -42,6 +43,7 @@ export const rollupGlobals = {
4243
'@angular/cdk/platform': 'ng.cdk.platform',
4344

4445
// Some packages are not really needed for the UMD bundles, but for the missingRollupGlobals rule.
46+
// Note that this needs to be in sync with the UMD module name format in "build-bundles.ts".
4547
'@angular/flex-layout': 'ng.flexLayout',
4648

4749
// Include secondary entry-points of the cdk and material packages

0 commit comments

Comments
 (0)