fix(packages): use ES modules for primary build (#11120)
This commit is contained in:
committed by
Victor Berchet
parent
8cb1046ce9
commit
979657989b
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
/**
|
||||
* @module
|
||||
* @description
|
||||
* The http module provides services to perform http requests. To get started, see the {@link Http}
|
||||
* class.
|
||||
*/
|
||||
import {NgModule} from '@angular/core';
|
||||
|
||||
import {BrowserJsonp} from './backends/browser_jsonp';
|
||||
import {BrowserXhr} from './backends/browser_xhr';
|
||||
import {JSONPBackend, JSONPBackend_} from './backends/jsonp_backend';
|
||||
import {CookieXSRFStrategy, XHRBackend} from './backends/xhr_backend';
|
||||
import {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
import {BaseResponseOptions, ResponseOptions} from './base_response_options';
|
||||
import {Http, Jsonp} from './http';
|
||||
import {XSRFStrategy} from './interfaces';
|
||||
|
||||
|
||||
export function _createDefaultCookieXSRFStrategy() {
|
||||
return new CookieXSRFStrategy();
|
||||
}
|
||||
|
||||
export function httpFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions): Http {
|
||||
return new Http(xhrBackend, requestOptions);
|
||||
}
|
||||
|
||||
export function jsonpFactory(jsonpBackend: JSONPBackend, requestOptions: RequestOptions): Jsonp {
|
||||
return new Jsonp(jsonpBackend, requestOptions);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The module that includes http's providers
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
@NgModule({
|
||||
providers: [
|
||||
// TODO(pascal): use factory type annotations once supported in DI
|
||||
// issue: https://github.com/angular/angular/issues/3183
|
||||
{provide: Http, useFactory: httpFactory, deps: [XHRBackend, RequestOptions]},
|
||||
BrowserXhr,
|
||||
{provide: RequestOptions, useClass: BaseRequestOptions},
|
||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||
XHRBackend,
|
||||
{provide: XSRFStrategy, useFactory: _createDefaultCookieXSRFStrategy},
|
||||
],
|
||||
})
|
||||
export class HttpModule {
|
||||
}
|
||||
|
||||
/**
|
||||
* The module that includes jsonp's providers
|
||||
*
|
||||
* @experimental
|
||||
*/
|
||||
@NgModule({
|
||||
providers: [
|
||||
// TODO(pascal): use factory type annotations once supported in DI
|
||||
// issue: https://github.com/angular/angular/issues/3183
|
||||
{provide: Jsonp, useFactory: jsonpFactory, deps: [JSONPBackend, RequestOptions]},
|
||||
BrowserJsonp,
|
||||
{provide: RequestOptions, useClass: BaseRequestOptions},
|
||||
{provide: ResponseOptions, useClass: BaseResponseOptions},
|
||||
{provide: JSONPBackend, useClass: JSONPBackend_},
|
||||
],
|
||||
})
|
||||
export class JsonpModule {
|
||||
}
|
||||
@@ -17,7 +17,7 @@ export function normalizeMethodName(method: string | RequestMethod): RequestMeth
|
||||
.replace(
|
||||
/(\w)(\w*)/g,
|
||||
(g0: string, g1: string, g2: string) => g1.toUpperCase() + g2.toLowerCase());
|
||||
method = <number>(<{[key: string]: any}>RequestMethod)[method];
|
||||
method = <RequestMethod>(<{[key: string]: any}>RequestMethod)[method];
|
||||
if (typeof method !== 'number')
|
||||
throw new Error(`Invalid request method. The method "${originalMethod}" is not supported.`);
|
||||
}
|
||||
|
||||
@@ -6,16 +6,16 @@
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
// Index to be used if Http is ever configured as a standalone npm package.
|
||||
// require('reflect-metadata');
|
||||
// require('core-js');
|
||||
// import {HTTP_PROVIDERS, JSONP_PROVIDERS, Http, Jsonp} from './http';
|
||||
// import {Injector} from '@angular/core';
|
||||
// export * from './http';
|
||||
|
||||
// /**
|
||||
// * TODO(jeffbcross): export each as their own top-level file, to require as:
|
||||
// * require('@angular/http'); require('http/jsonp');
|
||||
// */
|
||||
// export var http = Injector.resolveAndCreate([HTTP_PROVIDERS]).get(Http);
|
||||
// export var jsonp = Injector.resolveAndCreate([JSONP_PROVIDERS]).get(Jsonp);
|
||||
export {BrowserXhr} from './backends/browser_xhr';
|
||||
export {JSONPBackend, JSONPConnection} from './backends/jsonp_backend';
|
||||
export {CookieXSRFStrategy, XHRBackend, XHRConnection} from './backends/xhr_backend';
|
||||
export {BaseRequestOptions, RequestOptions} from './base_request_options';
|
||||
export {BaseResponseOptions, ResponseOptions} from './base_response_options';
|
||||
export {ReadyState, RequestMethod, ResponseContentType, ResponseType} from './enums';
|
||||
export {Headers} from './headers';
|
||||
export {Http, Jsonp} from './http';
|
||||
export {HttpModule, JsonpModule} from './http_module';
|
||||
export {Connection, ConnectionBackend, RequestOptionsArgs, ResponseOptionsArgs, XSRFStrategy} from './interfaces';
|
||||
export {Request} from './static_request';
|
||||
export {Response} from './static_response';
|
||||
export {QueryEncoder, URLSearchParams} from './url_search_params';
|
||||
|
||||
@@ -71,4 +71,4 @@ export type ResponseOptionsArgs = {
|
||||
headers?: Headers;
|
||||
type?: ResponseType;
|
||||
url?: string;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user