Skip to content

Commit 6de4cbd

Browse files
brandonrobertsAndrewKushnir
authored andcommittedApr 25, 2019
fix(common): add upgrade sub-package to ng_package rule for @angular/common (#30117)
Follow-up to #30055 to include @angular/common/upgrade in the npm package Closes #30116 PR Close #30117
1 parent 61365a9 commit 6de4cbd

File tree

11 files changed

+49
-14
lines changed

11 files changed

+49
-14
lines changed
 

‎integration/bazel/src/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"@angular/platform-browser": "packages-dist:platform-browser",
1111
"@angular/platform-browser-dynamic": "packages-dist:platform-browser-dynamic",
1212
"@angular/router": "packages-dist:router",
13+
"@angular/upgrade": "packages-dist:upgrade",
1314
"reflect-metadata": "0.1.12",
1415
"rxjs": "6.4.0",
1516
"tslib": "1.9.3",
@@ -30,4 +31,4 @@
3031
"postinstall": "ngc -p ./angular-metadata.tsconfig.json",
3132
"//": "TODO(gregmagolan): figure out how to keep dependencies here up to date with the root package.json"
3233
}
33-
}
34+
}

‎packages/bazel/test/ng_package/common_package.spec.ts

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ describe('@angular/common ng_package', () => {
4848
'common-testing.umd.js.map',
4949
'common-testing.umd.min.js',
5050
'common-testing.umd.min.js.map',
51+
'common-upgrade.umd.js',
52+
'common-upgrade.umd.js.map',
53+
'common-upgrade.umd.min.js',
54+
'common-upgrade.umd.min.js.map',
5155
'common.umd.js',
5256
'common.umd.js.map',
5357
'common.umd.min.js',
@@ -69,6 +73,8 @@ describe('@angular/common ng_package', () => {
6973
'http/testing.js.map',
7074
'testing.js',
7175
'testing.js.map',
76+
'upgrade.js',
77+
'upgrade.js.map',
7278
];
7379
expect(shx.ls('-R', 'fesm5').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
7480
expect(shx.ls('-R', 'fesm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
@@ -91,6 +97,10 @@ describe('@angular/common ng_package', () => {
9197
.toMatch('//# sourceMappingURL=testing.js.map');
9298
expect(shx.grep('sourceMappingURL', 'fesm2015/testing.js'))
9399
.toMatch('//# sourceMappingURL=testing.js.map');
100+
expect(shx.grep('sourceMappingURL', 'fesm5/upgrade.js'))
101+
.toMatch('//# sourceMappingURL=upgrade.js.map');
102+
expect(shx.grep('sourceMappingURL', 'fesm2015/upgrade.js'))
103+
.toMatch('//# sourceMappingURL=upgrade.js.map');
94104
});
95105

96106
describe('secondary entry-point', () => {
@@ -129,5 +139,13 @@ describe('@angular/common ng_package', () => {
129139
expect(actual['module']).toEqual('../../fesm5/http/testing.js');
130140
expect(actual['typings']).toEqual('./testing.d.ts');
131141
});
142+
// https://github.com/angular/common-builds/blob/master/upgrade/package.json
143+
it('/upgrade', () => {
144+
const actual = JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'}));
145+
expect(actual['main']).toEqual('../bundles/common-upgrade.umd.js');
146+
expect(actual['es2015']).toEqual('../fesm2015/upgrade.js');
147+
expect(actual['module']).toEqual('../fesm5/upgrade.js');
148+
expect(actual['typings']).toEqual('./upgrade.d.ts');
149+
});
132150
});
133151
});

‎packages/common/BUILD.bazel

+2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ng_package(
2323
"//packages/common/http:package.json",
2424
"//packages/common/http/testing:package.json",
2525
"//packages/common/testing:package.json",
26+
"//packages/common/upgrade:package.json",
2627
],
2728
entry_point = "packages/common/index.js",
2829
packages = ["//packages/common/locales:package"],
@@ -46,5 +47,6 @@ ng_package(
4647
"//packages/common/http",
4748
"//packages/common/http/testing",
4849
"//packages/common/testing",
50+
"//packages/common/upgrade",
4951
],
5052
)

‎packages/common/testing/src/mock_platform_location.ts

+13-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import {LocationChangeEvent, LocationChangeListener, PlatformLocation} from '@angular/common';
10-
import {Injectable, InjectionToken, Optional} from '@angular/core';
10+
import {Inject, Injectable, InjectionToken, Optional} from '@angular/core';
1111
import {Subject} from 'rxjs';
1212

1313
/**
@@ -78,11 +78,21 @@ function parseUrl(urlStr: string, baseHref: string) {
7878
};
7979
}
8080

81+
/**
82+
* Mock platform location config
83+
*
84+
* @publicApi
85+
*/
8186
export interface MockPlatformLocationConfig {
8287
startUrl?: string;
8388
appBaseHref?: string;
8489
}
8590

91+
/**
92+
* Provider for mock platform location config
93+
*
94+
* @publicApi
95+
*/
8696
export const MOCK_PLATFORM_LOCATION_CONFIG = new InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
8797

8898
/**
@@ -104,7 +114,8 @@ export class MockPlatformLocation implements PlatformLocation {
104114
state: unknown
105115
}[] = [{hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null}];
106116

107-
constructor(@Optional() config?: MockPlatformLocationConfig) {
117+
constructor(@Inject(MOCK_PLATFORM_LOCATION_CONFIG) @Optional() config?:
118+
MockPlatformLocationConfig) {
108119
if (config) {
109120
this.baseHref = config.appBaseHref || '';
110121

‎packages/common/testing/src/testing.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
*/
1414
export {SpyLocation} from './location_mock';
1515
export {MockLocationStrategy} from './mock_location_strategy';
16-
export {MockPlatformLocation} from './mock_platform_location';
16+
export {MOCK_PLATFORM_LOCATION_CONFIG, MockPlatformLocation, MockPlatformLocationConfig} from './mock_platform_location';

‎packages/common/upgrade/src/index.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
* found in the LICENSE file at https://angular.io/license
77
*/
88

9-
export * from './location_upgrade_module';
10-
export * from './$location_shim';
11-
export * from './params';
9+
export {$locationShim, $locationShimProvider} from './location_shim';
10+
export {LOCATION_UPGRADE_CONFIGURATION, LocationUpgradeConfig, LocationUpgradeModule} from './location_upgrade_module';
11+
export {AngularJSUrlCodec, UrlCodec} from './params';

‎packages/common/upgrade/src/location_upgrade_module.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {APP_BASE_HREF, CommonModule, HashLocationStrategy, Location, LocationStr
1010
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
1111
import {UpgradeModule} from '@angular/upgrade/static';
1212

13-
import {$locationShim, $locationShimProvider} from './$location_shim';
13+
import {$locationShim, $locationShimProvider} from './location_shim';
1414
import {AngularJSUrlCodec, UrlCodec} from './params';
1515

1616

@@ -75,7 +75,6 @@ export class LocationUpgradeModule {
7575
}
7676
}
7777

78-
/** @internal */
7978
export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?: string) {
8079
if (config && config.appBaseHref != null) {
8180
return config.appBaseHref;
@@ -85,20 +84,17 @@ export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?:
8584
return '';
8685
}
8786

88-
/** @internal */
8987
export function provideUrlCodec(config: LocationUpgradeConfig) {
9088
const codec = config && config.urlCodec || AngularJSUrlCodec;
9189
return new (codec as any)();
9290
}
9391

94-
/** @internal */
9592
export function provideLocationStrategy(
9693
platformLocation: PlatformLocation, baseHref: string, options: LocationUpgradeConfig = {}) {
9794
return options.useHash ? new HashLocationStrategy(platformLocation, baseHref) :
9895
new PathLocationStrategy(platformLocation, baseHref);
9996
}
10097

101-
/** @internal */
10298
export function provide$location(
10399
ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation,
104100
urlCodec: UrlCodec, locationStrategy: LocationStrategy) {

‎packages/common/upgrade/test/upgrade.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {CommonModule, PathLocationStrategy} from '@angular/common';
1010
import {TestBed, inject} from '@angular/core/testing';
1111
import {UpgradeModule} from '@angular/upgrade/static';
1212

13-
import {$locationShim} from '../src/$location_shim';
13+
import {$locationShim} from '../src/location_shim';
1414

1515
import {LocationUpgradeTestModule} from './upgrade_location_test_module';
1616

‎packages/common/upgrade/test/upgrade_location_test_module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {MockPlatformLocation} from '@angular/common/testing';
1111
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
1212
import {UpgradeModule} from '@angular/upgrade/static';
1313

14-
import {$locationShim, $locationShimProvider} from '../src/$location_shim';
14+
import {$locationShim, $locationShimProvider} from '../src/location_shim';
1515
import {LocationUpgradeModule} from '../src/location_upgrade_module';
1616
import {UrlCodec} from '../src/params';
1717

‎tools/public_api_guard/common/testing.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
export declare const MOCK_PLATFORM_LOCATION_CONFIG: InjectionToken<{}>;
2+
13
export declare class MockLocationStrategy extends LocationStrategy {
24
internalBaseHref: string;
35
internalPath: string;
@@ -37,6 +39,11 @@ export declare class MockPlatformLocation implements PlatformLocation {
3739
replaceState(state: any, title: string, newUrl: string): void;
3840
}
3941

42+
export interface MockPlatformLocationConfig {
43+
appBaseHref?: string;
44+
startUrl?: string;
45+
}
46+
4047
export declare class SpyLocation implements Location {
4148
urlChanges: string[];
4249
back(): void;

0 commit comments

Comments
 (0)
Please sign in to comment.