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
This commit is contained in:
Brandon Roberts 2019-04-25 09:36:49 -05:00 committed by Andrew Kushnir
parent 61365a94ed
commit 6de4cbdd41
11 changed files with 49 additions and 14 deletions

View File

@ -10,6 +10,7 @@
"@angular/platform-browser": "packages-dist:platform-browser", "@angular/platform-browser": "packages-dist:platform-browser",
"@angular/platform-browser-dynamic": "packages-dist:platform-browser-dynamic", "@angular/platform-browser-dynamic": "packages-dist:platform-browser-dynamic",
"@angular/router": "packages-dist:router", "@angular/router": "packages-dist:router",
"@angular/upgrade": "packages-dist:upgrade",
"reflect-metadata": "0.1.12", "reflect-metadata": "0.1.12",
"rxjs": "6.4.0", "rxjs": "6.4.0",
"tslib": "1.9.3", "tslib": "1.9.3",

View File

@ -48,6 +48,10 @@ describe('@angular/common ng_package', () => {
'common-testing.umd.js.map', 'common-testing.umd.js.map',
'common-testing.umd.min.js', 'common-testing.umd.min.js',
'common-testing.umd.min.js.map', 'common-testing.umd.min.js.map',
'common-upgrade.umd.js',
'common-upgrade.umd.js.map',
'common-upgrade.umd.min.js',
'common-upgrade.umd.min.js.map',
'common.umd.js', 'common.umd.js',
'common.umd.js.map', 'common.umd.js.map',
'common.umd.min.js', 'common.umd.min.js',
@ -69,6 +73,8 @@ describe('@angular/common ng_package', () => {
'http/testing.js.map', 'http/testing.js.map',
'testing.js', 'testing.js',
'testing.js.map', 'testing.js.map',
'upgrade.js',
'upgrade.js.map',
]; ];
expect(shx.ls('-R', 'fesm5').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected); expect(shx.ls('-R', 'fesm5').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
expect(shx.ls('-R', 'fesm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected); expect(shx.ls('-R', 'fesm2015').stdout.split('\n').filter(n => !!n).sort()).toEqual(expected);
@ -91,6 +97,10 @@ describe('@angular/common ng_package', () => {
.toMatch('//# sourceMappingURL=testing.js.map'); .toMatch('//# sourceMappingURL=testing.js.map');
expect(shx.grep('sourceMappingURL', 'fesm2015/testing.js')) expect(shx.grep('sourceMappingURL', 'fesm2015/testing.js'))
.toMatch('//# sourceMappingURL=testing.js.map'); .toMatch('//# sourceMappingURL=testing.js.map');
expect(shx.grep('sourceMappingURL', 'fesm5/upgrade.js'))
.toMatch('//# sourceMappingURL=upgrade.js.map');
expect(shx.grep('sourceMappingURL', 'fesm2015/upgrade.js'))
.toMatch('//# sourceMappingURL=upgrade.js.map');
}); });
describe('secondary entry-point', () => { describe('secondary entry-point', () => {
@ -129,5 +139,13 @@ describe('@angular/common ng_package', () => {
expect(actual['module']).toEqual('../../fesm5/http/testing.js'); expect(actual['module']).toEqual('../../fesm5/http/testing.js');
expect(actual['typings']).toEqual('./testing.d.ts'); expect(actual['typings']).toEqual('./testing.d.ts');
}); });
// https://github.com/angular/common-builds/blob/master/upgrade/package.json
it('/upgrade', () => {
const actual = JSON.parse(fs.readFileSync('upgrade/package.json', {encoding: 'utf-8'}));
expect(actual['main']).toEqual('../bundles/common-upgrade.umd.js');
expect(actual['es2015']).toEqual('../fesm2015/upgrade.js');
expect(actual['module']).toEqual('../fesm5/upgrade.js');
expect(actual['typings']).toEqual('./upgrade.d.ts');
});
}); });
}); });

View File

@ -23,6 +23,7 @@ ng_package(
"//packages/common/http:package.json", "//packages/common/http:package.json",
"//packages/common/http/testing:package.json", "//packages/common/http/testing:package.json",
"//packages/common/testing:package.json", "//packages/common/testing:package.json",
"//packages/common/upgrade:package.json",
], ],
entry_point = "packages/common/index.js", entry_point = "packages/common/index.js",
packages = ["//packages/common/locales:package"], packages = ["//packages/common/locales:package"],
@ -46,5 +47,6 @@ ng_package(
"//packages/common/http", "//packages/common/http",
"//packages/common/http/testing", "//packages/common/http/testing",
"//packages/common/testing", "//packages/common/testing",
"//packages/common/upgrade",
], ],
) )

View File

@ -7,7 +7,7 @@
*/ */
import {LocationChangeEvent, LocationChangeListener, PlatformLocation} from '@angular/common'; import {LocationChangeEvent, LocationChangeListener, PlatformLocation} from '@angular/common';
import {Injectable, InjectionToken, Optional} from '@angular/core'; import {Inject, Injectable, InjectionToken, Optional} from '@angular/core';
import {Subject} from 'rxjs'; import {Subject} from 'rxjs';
/** /**
@ -78,11 +78,21 @@ function parseUrl(urlStr: string, baseHref: string) {
}; };
} }
/**
* Mock platform location config
*
* @publicApi
*/
export interface MockPlatformLocationConfig { export interface MockPlatformLocationConfig {
startUrl?: string; startUrl?: string;
appBaseHref?: string; appBaseHref?: string;
} }
/**
* Provider for mock platform location config
*
* @publicApi
*/
export const MOCK_PLATFORM_LOCATION_CONFIG = new InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG'); export const MOCK_PLATFORM_LOCATION_CONFIG = new InjectionToken('MOCK_PLATFORM_LOCATION_CONFIG');
/** /**
@ -104,7 +114,8 @@ export class MockPlatformLocation implements PlatformLocation {
state: unknown state: unknown
}[] = [{hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null}]; }[] = [{hostname: '', protocol: '', port: '', pathname: '/', search: '', hash: '', state: null}];
constructor(@Optional() config?: MockPlatformLocationConfig) { constructor(@Inject(MOCK_PLATFORM_LOCATION_CONFIG) @Optional() config?:
MockPlatformLocationConfig) {
if (config) { if (config) {
this.baseHref = config.appBaseHref || ''; this.baseHref = config.appBaseHref || '';

View File

@ -13,4 +13,4 @@
*/ */
export {SpyLocation} from './location_mock'; export {SpyLocation} from './location_mock';
export {MockLocationStrategy} from './mock_location_strategy'; export {MockLocationStrategy} from './mock_location_strategy';
export {MockPlatformLocation} from './mock_platform_location'; export {MOCK_PLATFORM_LOCATION_CONFIG, MockPlatformLocation, MockPlatformLocationConfig} from './mock_platform_location';

View File

@ -6,6 +6,6 @@
* found in the LICENSE file at https://angular.io/license * found in the LICENSE file at https://angular.io/license
*/ */
export * from './location_upgrade_module'; export {$locationShim, $locationShimProvider} from './location_shim';
export * from './$location_shim'; export {LOCATION_UPGRADE_CONFIGURATION, LocationUpgradeConfig, LocationUpgradeModule} from './location_upgrade_module';
export * from './params'; export {AngularJSUrlCodec, UrlCodec} from './params';

View File

@ -10,7 +10,7 @@ import {APP_BASE_HREF, CommonModule, HashLocationStrategy, Location, LocationStr
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core'; import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
import {UpgradeModule} from '@angular/upgrade/static'; import {UpgradeModule} from '@angular/upgrade/static';
import {$locationShim, $locationShimProvider} from './$location_shim'; import {$locationShim, $locationShimProvider} from './location_shim';
import {AngularJSUrlCodec, UrlCodec} from './params'; import {AngularJSUrlCodec, UrlCodec} from './params';
@ -75,7 +75,6 @@ export class LocationUpgradeModule {
} }
} }
/** @internal */
export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?: string) { export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?: string) {
if (config && config.appBaseHref != null) { if (config && config.appBaseHref != null) {
return config.appBaseHref; return config.appBaseHref;
@ -85,20 +84,17 @@ export function provideAppBaseHref(config: LocationUpgradeConfig, appBaseHref?:
return ''; return '';
} }
/** @internal */
export function provideUrlCodec(config: LocationUpgradeConfig) { export function provideUrlCodec(config: LocationUpgradeConfig) {
const codec = config && config.urlCodec || AngularJSUrlCodec; const codec = config && config.urlCodec || AngularJSUrlCodec;
return new (codec as any)(); return new (codec as any)();
} }
/** @internal */
export function provideLocationStrategy( export function provideLocationStrategy(
platformLocation: PlatformLocation, baseHref: string, options: LocationUpgradeConfig = {}) { platformLocation: PlatformLocation, baseHref: string, options: LocationUpgradeConfig = {}) {
return options.useHash ? new HashLocationStrategy(platformLocation, baseHref) : return options.useHash ? new HashLocationStrategy(platformLocation, baseHref) :
new PathLocationStrategy(platformLocation, baseHref); new PathLocationStrategy(platformLocation, baseHref);
} }
/** @internal */
export function provide$location( export function provide$location(
ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation, ngUpgrade: UpgradeModule, location: Location, platformLocation: PlatformLocation,
urlCodec: UrlCodec, locationStrategy: LocationStrategy) { urlCodec: UrlCodec, locationStrategy: LocationStrategy) {

View File

@ -10,7 +10,7 @@ import {CommonModule, PathLocationStrategy} from '@angular/common';
import {TestBed, inject} from '@angular/core/testing'; import {TestBed, inject} from '@angular/core/testing';
import {UpgradeModule} from '@angular/upgrade/static'; import {UpgradeModule} from '@angular/upgrade/static';
import {$locationShim} from '../src/$location_shim'; import {$locationShim} from '../src/location_shim';
import {LocationUpgradeTestModule} from './upgrade_location_test_module'; import {LocationUpgradeTestModule} from './upgrade_location_test_module';

View File

@ -11,7 +11,7 @@ import {MockPlatformLocation} from '@angular/common/testing';
import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core'; import {Inject, InjectionToken, ModuleWithProviders, NgModule, Optional} from '@angular/core';
import {UpgradeModule} from '@angular/upgrade/static'; import {UpgradeModule} from '@angular/upgrade/static';
import {$locationShim, $locationShimProvider} from '../src/$location_shim'; import {$locationShim, $locationShimProvider} from '../src/location_shim';
import {LocationUpgradeModule} from '../src/location_upgrade_module'; import {LocationUpgradeModule} from '../src/location_upgrade_module';
import {UrlCodec} from '../src/params'; import {UrlCodec} from '../src/params';

View File

@ -1,3 +1,5 @@
export declare const MOCK_PLATFORM_LOCATION_CONFIG: InjectionToken<{}>;
export declare class MockLocationStrategy extends LocationStrategy { export declare class MockLocationStrategy extends LocationStrategy {
internalBaseHref: string; internalBaseHref: string;
internalPath: string; internalPath: string;
@ -37,6 +39,11 @@ export declare class MockPlatformLocation implements PlatformLocation {
replaceState(state: any, title: string, newUrl: string): void; replaceState(state: any, title: string, newUrl: string): void;
} }
export interface MockPlatformLocationConfig {
appBaseHref?: string;
startUrl?: string;
}
export declare class SpyLocation implements Location { export declare class SpyLocation implements Location {
urlChanges: string[]; urlChanges: string[];
back(): void; back(): void;