Skip to content

Commit 152d99e

Browse files
jasonadenbenlesh
authored andcommitted
feat(common): add @angular/common/upgrade package for $location-related APIs (#30055)
AngularJS's `$location` service doesn't have a direct counterpart in Angular. This is largely because the `Location` service in Angular was pulled out of the `Router`, but was not purpose-built to stand on its own. This commit adds a new `@angular/common/upgrade` package with the beginnings of a new `LocationUpgradeService`. This service will more closely match the API of AngularJS and provide a way to replace the `$location` service from AngularJS. PR Close #30055
1 parent b635fe8 commit 152d99e

File tree

15 files changed

+229
-0
lines changed

15 files changed

+229
-0
lines changed

packages/common/src/location/platform_location.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export abstract class PlatformLocation {
3535
abstract onPopState(fn: LocationChangeListener): void;
3636
abstract onHashChange(fn: LocationChangeListener): void;
3737

38+
abstract get href(): string;
3839
abstract get protocol(): string;
3940
abstract get hostname(): string;
4041
abstract get port(): string;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files(["package.json"])
4+
5+
load("//tools:defaults.bzl", "ng_module")
6+
7+
ng_module(
8+
name = "upgrade",
9+
srcs = glob(
10+
[
11+
"*.ts",
12+
"src/**/*.ts",
13+
],
14+
),
15+
deps = [
16+
"//packages/common",
17+
"//packages/core",
18+
"//packages/upgrade/static",
19+
],
20+
)

packages/common/upgrade/index.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
// This file is not used to build this module. It is only used during editing
10+
// by the TypeScript language service and during build for verification. `ngc`
11+
// replaces this file with production index.ts when it rewrites private symbol
12+
// names.
13+
14+
export * from './public_api';
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@angular/common/upgrade",
3+
"typings": "./upgrade.d.ts",
4+
"main": "../bundles/common-upgrade.umd.js",
5+
"module": "../fesm5/upgrade.js",
6+
"es2015": "../fesm2015/upgrade.js",
7+
"esm5": "../esm5/upgrade/upgrade.js",
8+
"esm2015": "../esm2015/upgrade/upgrade.js",
9+
"fesm5": "../fesm5/upgrade.js",
10+
"fesm2015": "../fesm2015/upgrade.js",
11+
"sideEffects": false
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
/**
10+
* @module
11+
* @description
12+
* Entry point for all public APIs of this package.
13+
*/
14+
export * from './src/index';
15+
16+
// This file only reexports content of the `src` folder. Keep it that way.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
const resolve = require('rollup-plugin-node-resolve');
10+
const sourcemaps = require('rollup-plugin-sourcemaps');
11+
12+
const globals = {
13+
'@angular/core': 'ng.core',
14+
'@angular/common': 'ng.common',
15+
'@angular/upgrade/static': 'ng.upgrade.static'
16+
};
17+
18+
19+
module.exports = {
20+
entry: '../../../dist/packages-dist/common/fesm5/upgrade.js',
21+
dest: '../../../dist/packages-dist/common/bundles/common-upgrade.umd.js',
22+
format: 'umd',
23+
exports: 'named',
24+
amd: {id: '@angular/common/upgrade'},
25+
moduleName: 'ng.common.upgrade',
26+
plugins: [resolve(), sourcemaps()],
27+
external: Object.keys(globals),
28+
globals: globals
29+
};
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
export * from './location';
10+
export * from './location_module';
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {Injectable} from '@angular/core';
10+
11+
/**
12+
* A Location service that provides properties and methods to match AngularJS's `$location`
13+
* service. It is recommended that this LocationUpgradeService be used in place of
14+
* `$location` in any hybrid Angular/AngularJS applications.
15+
*/
16+
@Injectable()
17+
export class LocationUpgradeService {
18+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
9+
import {NgModule} from '@angular/core';
10+
import {LocationUpgradeService} from './location';
11+
12+
/**
13+
* Module used for configuring Angular's LocationUpgradeService.
14+
*/
15+
@NgModule({providers: [LocationUpgradeService]})
16+
export class LocationUpgradeModule {
17+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
load("//tools:defaults.bzl", "jasmine_node_test", "ts_library", "ts_web_test_suite")
2+
3+
ts_library(
4+
name = "test_lib",
5+
testonly = True,
6+
srcs = glob(["**/*.ts"]),
7+
deps = [
8+
"//packages/common",
9+
"//packages/common/upgrade",
10+
"//packages/common/testing",
11+
"//packages/core/testing",
12+
"//packages/upgrade/static",
13+
],
14+
)
15+
16+
jasmine_node_test(
17+
name = "test",
18+
bootstrap = ["angular/tools/testing/init_node_spec.js"],
19+
deps = [
20+
":test_lib",
21+
"//tools/testing:node",
22+
],
23+
)

0 commit comments

Comments
 (0)