refactor: move angular source to /packages rather than modules/@angular

This commit is contained in:
Jason Aden
2017-03-02 10:48:42 -08:00
parent 5ad5301a3e
commit 3e51a19983
1051 changed files with 18 additions and 18 deletions

View File

@ -0,0 +1,15 @@
{
"presets": ["es2015"],
"plugins": [["transform-es2015-modules-umd", {
"globals": {
"@angular/core": "ng.core",
"@angular/common": "ng.common",
"@angular/compiler": "ng.compiler",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/platform-browser-dynamic": "ng.platformBrowserDynamic"
},
"exactGlobals": true
}]],
"moduleId": "@angular/platform-browser-dynamic"
}

View File

@ -0,0 +1,19 @@
{
"presets": ["es2015"],
"plugins": [["transform-es2015-modules-umd", {
"globals": {
"@angular/core": "ng.core",
"@angular/core/testing": "ng.core.testing",
"@angular/common": "ng.common",
"@angular/compiler": "ng.compiler",
"@angular/compiler/testing": "ng.compiler.testing",
"@angular/platform-browser": "ng.platformBrowser",
"@angular/platform-browser/testing": "ng.platformBrowser.testing",
"@angular/platform-browser-dynamic": "ng.platformBrowserDynamic",
"@angular/platform-browser-dynamic/testing": "ng.platformBrowserDynamic.testing"
},
"exactGlobals": true
}]],
"moduleId": "@angular/platform-browser-dynamic/testing"
}

View File

@ -0,0 +1,16 @@
/**
* @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
* Entry point for all public APIs of the platform-browser-dynamic package.
*/
export * from './src/platform-browser-dynamic';
// This file only reexports content of the `src` folder. Keep it that way.

View File

@ -0,0 +1,21 @@
{
"name": "@angular/platform-browser-dynamic",
"version": "0.0.0-PLACEHOLDER",
"description": "Angular - library for using Angular in a web browser with JIT compilation",
"main": "./bundles/platform-browser-dynamic.umd.js",
"module": "./@angular/platform-browser-dynamic.es5.js",
"es2015": "./@angular/platform-browser-dynamic.js",
"typings": "./typings/platform-browser-dynamic.d.ts",
"author": "angular",
"license": "MIT",
"peerDependencies": {
"@angular/core": "0.0.0-PLACEHOLDER",
"@angular/common": "0.0.0-PLACEHOLDER",
"@angular/compiler": "0.0.0-PLACEHOLDER",
"@angular/platform-browser": "0.0.0-PLACEHOLDER"
},
"repository": {
"type": "git",
"url": "https://github.com/angular/angular.git"
}
}

View File

@ -0,0 +1,27 @@
/**
* @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
*/
import {ResourceLoader, platformCoreDynamic} from '@angular/compiler';
import {PlatformRef, Provider, createPlatformFactory} from '@angular/core';
import {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './platform_providers';
import {CachedResourceLoader} from './resource_loader/resource_loader_cache';
export * from './private_export';
export {VERSION} from './version';
/**
* @experimental
*/
export const RESOURCE_CACHE_PROVIDER: Provider[] =
[{provide: ResourceLoader, useClass: CachedResourceLoader}];
/**
* @stable
*/
export const platformBrowserDynamic = createPlatformFactory(
platformCoreDynamic, 'browserDynamic', INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);

View File

@ -0,0 +1,25 @@
/**
* @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
*/
import {ɵPLATFORM_BROWSER_ID as PLATFORM_BROWSER_ID} from '@angular/common';
import {ResourceLoader} from '@angular/compiler';
import {COMPILER_OPTIONS, PLATFORM_ID, Provider} from '@angular/core';
import {ɵINTERNAL_BROWSER_PLATFORM_PROVIDERS as INTERNAL_BROWSER_PLATFORM_PROVIDERS} from '@angular/platform-browser';
import {ResourceLoaderImpl} from './resource_loader/resource_loader_impl';
export const INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS: Provider[] = [
INTERNAL_BROWSER_PLATFORM_PROVIDERS,
{
provide: COMPILER_OPTIONS,
useValue: {providers: [{provide: ResourceLoader, useClass: ResourceLoaderImpl}]},
multi: true
},
{provide: PLATFORM_ID, useValue: PLATFORM_BROWSER_ID},
];

View File

@ -0,0 +1,10 @@
/**
* @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
*/
export {INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from './platform_providers';
export {ResourceLoaderImpl as ɵResourceLoaderImpl} from './resource_loader/resource_loader_impl';

View File

@ -0,0 +1,38 @@
/**
* @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
*/
import {ResourceLoader} from '@angular/compiler';
import {ɵglobal as global} from '@angular/core';
/**
* An implementation of ResourceLoader that uses a template cache to avoid doing an actual
* ResourceLoader.
*
* The template cache needs to be built and loaded into window.$templateCache
* via a separate mechanism.
*/
export class CachedResourceLoader extends ResourceLoader {
private _cache: {[url: string]: string};
constructor() {
super();
this._cache = (<any>global).$templateCache;
if (this._cache == null) {
throw new Error('CachedResourceLoader: Template cache was not found in $templateCache.');
}
}
get(url: string): Promise<string> {
if (this._cache.hasOwnProperty(url)) {
return Promise.resolve(this._cache[url]);
} else {
return <Promise<any>>Promise.reject(
'CachedResourceLoader: Did not find cached template for ' + url);
}
}
}

View File

@ -0,0 +1,53 @@
/**
* @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
*/
import {ResourceLoader} from '@angular/compiler';
import {Injectable} from '@angular/core';
@Injectable()
export class ResourceLoaderImpl extends ResourceLoader {
get(url: string): Promise<string> {
let resolve: (result: any) => void;
let reject: (error: any) => void;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
const xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.responseType = 'text';
xhr.onload = function() {
// responseText is the old-school way of retrieving response (supported by IE8 & 9)
// response/responseType properties were introduced in ResourceLoader Level2 spec (supported
// by IE10)
const response = xhr.response || xhr.responseText;
// normalize IE9 bug (http://bugs.jquery.com/ticket/1450)
let status = xhr.status === 1223 ? 204 : xhr.status;
// fix status code when it is 0 (0 status is undocumented).
// Occurs when accessing file resources or on Android 4.1 stock browser
// while retrieving files from application cache.
if (status === 0) {
status = response ? 200 : 0;
}
if (200 <= status && status <= 300) {
resolve(response);
} else {
reject(`Failed to load ${url}`);
}
};
xhr.onerror = function() { reject(`Failed to load ${url}`); };
xhr.send();
return promise;
}
}

View File

@ -0,0 +1,19 @@
/**
* @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
* Entry point for all public APIs of the common package.
*/
import {Version} from '@angular/core';
/**
* @stable
*/
export const VERSION = new Version('0.0.0-PLACEHOLDER');

View File

@ -0,0 +1,11 @@
/**
* @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
*/
export function setTemplateCache(cache: any /** TODO #9100 */): void {
(<any>window).$templateCache = cache;
}

View File

@ -0,0 +1,84 @@
/**
* @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
*/
import {ResourceLoader, UrlResolver} from '@angular/compiler';
import {Component} from '@angular/core';
import {TestBed, async, fakeAsync, tick} from '@angular/core/testing';
import {expect} from '@angular/platform-browser/testing/matchers';
import {CachedResourceLoader} from '../../src/resource_loader/resource_loader_cache';
import {setTemplateCache} from './resource_loader_cache_setter';
export function main() {
describe('CachedResourceLoader', () => {
let resourceLoader: CachedResourceLoader;
function createCachedResourceLoader(): CachedResourceLoader {
setTemplateCache({'test.html': '<div>Hello</div>'});
return new CachedResourceLoader();
}
beforeEach(fakeAsync(() => {
TestBed.configureCompiler({
providers: [
{provide: UrlResolver, useClass: TestUrlResolver},
{provide: ResourceLoader, useFactory: createCachedResourceLoader}
]
});
TestBed.configureTestingModule({declarations: [TestComponent]});
TestBed.compileComponents();
}));
it('should throw exception if $templateCache is not found', () => {
setTemplateCache(null);
expect(() => {
resourceLoader = new CachedResourceLoader();
}).toThrowError('CachedResourceLoader: Template cache was not found in $templateCache.');
});
it('should resolve the Promise with the cached file content on success', async(() => {
setTemplateCache({'test.html': '<div>Hello</div>'});
resourceLoader = new CachedResourceLoader();
resourceLoader.get('test.html').then((text) => { expect(text).toBe('<div>Hello</div>'); });
}));
it('should reject the Promise on failure', async(() => {
resourceLoader = new CachedResourceLoader();
resourceLoader.get('unknown.html')
.then((text) => { throw new Error('Not expected to succeed.'); })
.catch((error) => {/** success */});
}));
it('should allow fakeAsync Tests to load components with templateUrl synchronously',
fakeAsync(() => {
TestBed.configureTestingModule({declarations: [TestComponent]});
TestBed.compileComponents();
tick();
const fixture = TestBed.createComponent(TestComponent);
// This should initialize the fixture.
tick();
expect(fixture.debugElement.children[0].nativeElement).toHaveText('Hello');
}));
});
}
@Component({selector: 'test-cmp', templateUrl: 'test.html'})
class TestComponent {
}
class TestUrlResolver extends UrlResolver {
resolve(baseUrl: string, url: string): string {
// Don't use baseUrl to get the same URL as templateUrl.
// This is to remove any difference between Dart and TS tests.
return url;
}
}

View File

@ -0,0 +1,44 @@
/**
* @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
*/
import {AsyncTestCompleter, beforeEach, describe, expect, inject, it} from '@angular/core/testing/testing_internal';
import {ResourceLoaderImpl} from '../../src/resource_loader/resource_loader_impl';
export function main() {
describe('ResourceLoaderImpl', () => {
let resourceLoader: ResourceLoaderImpl;
// TODO(juliemr): This file currently won't work with dart unit tests run using
// exclusive it or describe (iit or ddescribe). This is because when
// pub run test is executed against this specific file the relative paths
// will be relative to here, so url200 should look like
// static_assets/200.html.
// We currently have no way of detecting this.
const url200 = '/base/modules/@angular/platform-browser/test/browser/static_assets/200.html';
const url404 = '/bad/path/404.html';
beforeEach(() => { resourceLoader = new ResourceLoaderImpl(); });
it('should resolve the Promise with the file content on success',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
resourceLoader.get(url200).then((text) => {
expect(text.trim()).toEqual('<p>hey</p>');
async.done();
});
}), 10000);
it('should reject the Promise on failure',
inject([AsyncTestCompleter], (async: AsyncTestCompleter) => {
resourceLoader.get(url404).catch((e) => {
expect(e).toEqual(`Failed to load ${url404}`);
async.done();
return null;
});
}), 10000);
});
}

View File

@ -0,0 +1,135 @@
/**
* @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
*/
import {ResourceLoader} from '@angular/compiler';
import {Component} from '@angular/core';
import {TestBed, async, fakeAsync, inject, tick} from '@angular/core/testing';
import {ResourceLoaderImpl} from '../src/resource_loader/resource_loader_impl';
// Components for the tests.
class FancyService {
value: string = 'real value';
getAsyncValue() { return Promise.resolve('async value'); }
getTimeoutValue() {
return new Promise(
(resolve, reject) => { setTimeout(() => { resolve('timeout value'); }, 10); });
}
}
@Component({
selector: 'external-template-comp',
templateUrl: '/base/modules/@angular/platform-browser/test/static_assets/test.html'
})
class ExternalTemplateComp {
}
@Component({selector: 'bad-template-comp', templateUrl: 'non-existant.html'})
class BadTemplateUrl {
}
// Tests for angular2/testing bundle specific to the browser environment.
// For general tests, see test/testing/testing_public_spec.ts.
export function main() {
describe('test APIs for the browser', () => {
describe('using the async helper', () => {
let actuallyDone: boolean;
beforeEach(() => { actuallyDone = false; });
afterEach(() => { expect(actuallyDone).toEqual(true); });
it('should run async tests with ResourceLoaders', async(() => {
const resourceLoader = new ResourceLoaderImpl();
resourceLoader
.get('/base/modules/@angular/platform-browser/test/static_assets/test.html')
.then(() => { actuallyDone = true; });
}),
10000); // Long timeout here because this test makes an actual ResourceLoader.
});
describe('using the test injector with the inject helper', () => {
describe('setting up Providers', () => {
beforeEach(() => {
TestBed.configureTestingModule(
{providers: [{provide: FancyService, useValue: new FancyService()}]});
});
it('provides a real ResourceLoader instance',
inject([ResourceLoader], (resourceLoader: ResourceLoader) => {
expect(resourceLoader instanceof ResourceLoaderImpl).toBeTruthy();
}));
it('should allow the use of fakeAsync',
fakeAsync(inject([FancyService], (service: any /** TODO #9100 */) => {
let value: any /** TODO #9100 */;
service.getAsyncValue().then(function(val: any /** TODO #9100 */) { value = val; });
tick();
expect(value).toEqual('async value');
})));
});
});
describe('errors', () => {
let originalJasmineIt: any;
const patchJasmineIt = () => {
let resolve: (result: any) => void;
let reject: (error: any) => void;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
originalJasmineIt = jasmine.getEnv().it;
jasmine.getEnv().it = (description: string, fn: any /** TODO #9100 */) => {
const done = () => { resolve(null); };
(<any>done).fail = (err: any /** TODO #9100 */) => { reject(err); };
fn(done);
return null;
};
return promise;
};
const restoreJasmineIt = () => { jasmine.getEnv().it = originalJasmineIt; };
it('should fail when an ResourceLoader fails', (done: any /** TODO #9100 */) => {
const itPromise = patchJasmineIt();
it('should fail with an error from a promise', async(() => {
TestBed.configureTestingModule({declarations: [BadTemplateUrl]});
TestBed.compileComponents();
}));
itPromise.then(
() => { done.fail('Expected test to fail, but it did not'); },
(err: any) => {
expect(err.message)
.toEqual('Uncaught (in promise): Failed to load non-existant.html');
done();
});
restoreJasmineIt();
}, 10000);
});
describe('TestBed createComponent', function() {
it('should allow an external templateUrl', async(() => {
TestBed.configureTestingModule({declarations: [ExternalTemplateComp]});
TestBed.compileComponents().then(() => {
const componentFixture = TestBed.createComponent(ExternalTemplateComp);
componentFixture.detectChanges();
expect(componentFixture.nativeElement.textContent).toEqual('from external template\n');
});
}),
10000); // Long timeout here because this test makes an actual ResourceLoader request, and
// is slow
// on Edge.
});
});
}

View File

@ -0,0 +1,31 @@
/**
* @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
*/
import {Inject, Injectable} from '@angular/core';
import {TestComponentRenderer} from '@angular/core/testing';
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/platform-browser';
/**
* A DOM based implementation of the TestComponentRenderer.
*/
@Injectable()
export class DOMTestComponentRenderer extends TestComponentRenderer {
constructor(@Inject(DOCUMENT) private _doc: any /** TODO #9100 */) { super(); }
insertRootElement(rootElId: string) {
const rootEl = <HTMLElement>getDOM().firstChild(
getDOM().content(getDOM().createTemplate(`<div id="${rootElId}"></div>`)));
// TODO(juliemr): can/should this be optional?
const oldRoots = getDOM().querySelectorAll(this._doc, '[id^=root]');
for (let i = 0; i < oldRoots.length; i++) {
getDOM().remove(oldRoots[i]);
}
getDOM().appendChild(this._doc.body, rootEl);
}
}

View File

@ -0,0 +1,38 @@
/**
* @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
*/
import {platformCoreDynamicTesting} from '@angular/compiler/testing';
import {NgModule, PlatformRef, Provider, createPlatformFactory} from '@angular/core';
import {TestComponentRenderer} from '@angular/core/testing';
import {ɵINTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS as INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS} from '@angular/platform-browser-dynamic';
import {BrowserTestingModule} from '@angular/platform-browser/testing';
import {DOMTestComponentRenderer} from './dom_test_component_renderer';
export * from './private_export_testing'
/**
* @stable
*/
export const platformBrowserDynamicTesting = createPlatformFactory(
platformCoreDynamicTesting, 'browserDynamicTesting',
INTERNAL_BROWSER_DYNAMIC_PLATFORM_PROVIDERS);
/**
* NgModule for testing.
*
* @stable
*/
@NgModule({
exports: [BrowserTestingModule],
providers: [
{provide: TestComponentRenderer, useClass: DOMTestComponentRenderer},
]
})
export class BrowserDynamicTestingModule {
}

View File

@ -0,0 +1,9 @@
/**
* @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
*/
export {DOMTestComponentRenderer as ɵDOMTestComponentRenderer} from './dom_test_component_renderer';

View File

@ -0,0 +1,21 @@
{
"extends": "./tsconfig-build",
"compilerOptions": {
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],
"@angular/common": ["../../../dist/packages-dist/common"],
"@angular/common/testing": ["../../../dist/packages-dist/common/testing"],
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
"@angular/compiler/testing": ["../../../dist/packages-dist/compiler/testing"],
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
"@angular/platform-browser/testing": ["../../../dist/packages-dist/platform-browser/testing"],
"@angular/platform-browser-dynamic": ["../../../dist/packages-dist/platform-browser-dynamic"]
}
},
"files": [
"testing/index.ts",
"../../../node_modules/@types/jasmine/index.d.ts",
"../../../node_modules/zone.js/dist/zone.js.d.ts"
]
}

View File

@ -0,0 +1,34 @@
{
"compilerOptions": {
"baseUrl": ".",
"declaration": true,
"stripInternal": true,
"experimentalDecorators": true,
"module": "es2015",
"moduleResolution": "node",
"outDir": "../../../dist/packages-dist/platform-browser-dynamic",
"paths": {
"@angular/core": ["../../../dist/packages-dist/core"],
"@angular/core/testing": ["../../../dist/packages-dist/core/testing"],
"@angular/common": ["../../../dist/packages-dist/common"],
"@angular/common/testing": ["../../../dist/packages-dist/common/testing"],
"@angular/compiler": ["../../../dist/packages-dist/compiler"],
"@angular/compiler/testing": ["../../../dist/packages-dist/compiler/testing"],
"@angular/platform-browser": ["../../../dist/packages-dist/platform-browser"],
"@angular/platform-browser/testing": ["../../../dist/packages-dist/platform-browser/testing"]
},
"rootDir": ".",
"sourceMap": true,
"inlineSources": true,
"target": "es2015",
"skipLibCheck": true,
"lib": ["es2015", "dom"],
// don't auto-discover @types/node, it results in a ///<reference in the .d.ts output
"types": []
},
"files": [
"index.ts",
"../../../node_modules/@types/jasmine/index.d.ts",
"../../../node_modules/zone.js/dist/zone.js.d.ts"
]
}