Skip to content

Commit 59713b8

Browse files
thelgevolddherges
authored andcommitted
feat: add support for AMD module id in umd bundles (#675)
1 parent c364c7c commit 59713b8

File tree

8 files changed

+25
-2
lines changed

8 files changed

+25
-2
lines changed

integration/samples/comments-remove/specs/umd.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ describe(`@sample/sample-comments-remove`, () => {
1515
it(`should not contain all the comments by default`, () => {
1616
expect(BUNDLE).not.to.contain(`Copyright Example Software.`);
1717
});
18+
19+
it(`should use lib name as amd id`, () => {
20+
expect(BUNDLE).to.contain(`define('@sample/comments-remove', ['exports'`);
21+
});
1822
});
1923

2024
describe(`sample-comments-remove.umd.min.js`, () => {
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"$schema": "../../../src/ng-package.schema.json",
33
"lib": {
4-
"entryFile": "public_api.ts"
4+
"entryFile": "public_api.ts",
5+
"amdId": "@mylib/test"
56
}
67
}

integration/samples/comments/specs/umd.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ describe(`@sample/comments`, () => {
1212
it(`should contain all the comments by default`, () => {
1313
expect(BUNDLE).to.contain(`Copyright Example Software.`);
1414
});
15+
16+
it(`should give the umd an amd id`, () => {
17+
expect(BUNDLE).to.contain(`define('@mylib/test', ['exports'`);
18+
});
1519
});
1620

1721
describe(`sample-comments.umd.min.js`, () => {

src/lib/flatten/flatten.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface FlattenOpts {
1717
/** List of module ids that should be embedded to the bundle. */
1818
embedded?: string[];
1919

20+
amdId?: string;
21+
2022
/** Map of external UMD module ids that */
2123
umdModuleIds?: { [key: string]: string };
2224
}
@@ -79,6 +81,7 @@ export async function flattenToUmd(opts: FlattenOpts): Promise<string> {
7981
entry: opts.entryFile,
8082
format: 'umd',
8183
dest: destFile,
84+
amd: { id: opts.amdId },
8285
umdModuleIds: {
8386
...opts.umdModuleIds
8487
},

src/lib/flatten/rollup.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface RollupOptions {
2424
comments?: string;
2525
licensePath?: string;
2626
transform?: TransformHook;
27+
amd?: { id: string };
2728
}
2829

2930
/** Runs rollup over the given entry file, writes a bundle file. */
@@ -76,6 +77,7 @@ export async function rollupBundleFile(opts: RollupOptions): Promise<void> {
7677
name: `${opts.moduleName}`,
7778
file: opts.dest,
7879
format: opts.format,
80+
amd: opts.amd,
7981
banner: '',
8082
globals: moduleId => umdModuleIdStrategy(moduleId, opts.umdModuleIds || {}),
8183
sourcemap: true

src/lib/ng-package-format/entry-point.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ export class NgEntryPoint {
9191
return this.$get('lib.jsx');
9292
}
9393

94+
public get amdId(): string {
95+
return this.$get('lib.amdId') || this.moduleId;
96+
}
97+
9498
public get flatModuleFile(): string {
9599
return this.$get('lib.flatModuleFile') || this.flattenModuleId('-');
96100
}

src/lib/ng-v5/entry-point/write-bundles.transform.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export const writeBundlesTransform: Transform = pipe(
2323
umdModuleIds: ngEntryPoint.umdModuleIds,
2424
embedded: ngEntryPoint.embedded,
2525
comments: ngEntryPoint.comments,
26-
licensePath: ngEntryPoint.licensePath
26+
licensePath: ngEntryPoint.licensePath,
27+
amdId: ngEntryPoint.amdId
2728
};
2829

2930
return fromPromise(writeFlatBundleFiles(opts)).pipe(map(() => graph));

src/ng-package.schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@
9898
"type": "string"
9999
},
100100
"default": ["dom", "es2015"]
101+
},
102+
"amdId": {
103+
"description": "ID for AMD module",
104+
"type": "string"
101105
}
102106
}
103107
}

0 commit comments

Comments
 (0)