2015-04-13 19:39:47 -04:00
|
|
|
'use strict';
|
|
|
|
|
2015-05-04 11:19:25 -04:00
|
|
|
import destCopy from '../broccoli-dest-copy';
|
2016-05-26 13:45:37 -04:00
|
|
|
import compileWithTypescript, {INTERNAL_TYPINGS_PATH} from '../broccoli-typescript';
|
2015-04-13 19:39:47 -04:00
|
|
|
var Funnel = require('broccoli-funnel');
|
2015-05-21 12:07:52 -04:00
|
|
|
import mergeTrees from '../broccoli-merge-trees';
|
2015-04-13 19:39:47 -04:00
|
|
|
var path = require('path');
|
2015-06-09 13:35:58 -04:00
|
|
|
import renderLodashTemplate from '../broccoli-lodash';
|
2015-06-08 14:05:32 -04:00
|
|
|
import replace from '../broccoli-replace';
|
2016-01-06 17:13:44 -05:00
|
|
|
import generateForTest from '../broccoli-generate-for-test';
|
2015-04-13 19:39:47 -04:00
|
|
|
var stew = require('broccoli-stew');
|
2016-02-11 00:25:12 -05:00
|
|
|
var writeFile = require('broccoli-file-creator');
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-04-26 04:04:28 -04:00
|
|
|
var projectRootDir = path.normalize(path.join(__dirname, '..', '..', '..', '..'));
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2016-01-22 13:51:16 -05:00
|
|
|
module.exports = function makeNodeTree(projects: string[], destinationPath: string) {
|
2015-04-13 19:39:47 -04:00
|
|
|
// list of npm packages that this build will create
|
2015-09-09 22:00:22 -04:00
|
|
|
var outputPackages = ['angular2', 'benchpress'];
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2015-12-22 19:24:35 -05:00
|
|
|
let srcTree = new Funnel('modules', {
|
|
|
|
include: ['angular2/**'],
|
|
|
|
exclude: [
|
2016-04-12 12:40:37 -04:00
|
|
|
'**/e2e_test/**',
|
|
|
|
'angular2/test/**',
|
|
|
|
'angular2/examples/**',
|
2015-12-22 19:24:35 -05:00
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/src/testing/**',
|
|
|
|
'angular2/testing.ts',
|
|
|
|
'angular2/testing_internal.ts',
|
|
|
|
'angular2/src/upgrade/**',
|
|
|
|
'angular2/upgrade.ts',
|
|
|
|
'angular2/platform/testing/**',
|
|
|
|
'angular2/manual_typings/**',
|
2016-05-26 13:45:37 -04:00
|
|
|
'angular2/typings/**',
|
2015-12-22 19:24:35 -05:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2016-04-06 19:10:45 -04:00
|
|
|
let externalTypings = [
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/typings/hammerjs/hammerjs.d.ts',
|
|
|
|
'angular2/typings/node/node.d.ts',
|
|
|
|
'angular2/manual_typings/globals.d.ts',
|
|
|
|
'angular2/typings/es6-collections/es6-collections.d.ts',
|
2016-05-26 13:45:37 -04:00
|
|
|
'angular2/typings/es6-promise/es6-promise.d.ts',
|
2016-02-01 13:29:42 -05:00
|
|
|
];
|
|
|
|
|
2016-04-06 19:10:45 -04:00
|
|
|
let externalTypingsTree = new Funnel('modules', {files: externalTypings});
|
|
|
|
|
|
|
|
let packageTypings =
|
|
|
|
new Funnel('node_modules', {include: ['rxjs/**/*.d.ts', 'zone.js/**/*.d.ts']});
|
|
|
|
|
|
|
|
let compileSrcContext = mergeTrees([srcTree, externalTypingsTree, packageTypings]);
|
|
|
|
|
2015-12-22 19:24:35 -05:00
|
|
|
// Compile the sources and generate the @internal .d.ts
|
2016-04-06 19:10:45 -04:00
|
|
|
let compiledSrcTreeWithInternals = compileTree(compileSrcContext, true, []);
|
2015-12-22 19:24:35 -05:00
|
|
|
|
|
|
|
var testTree = new Funnel('modules', {
|
|
|
|
include: [
|
|
|
|
'angular2/manual_typings/**',
|
|
|
|
'angular2/typings/**',
|
|
|
|
|
|
|
|
'angular2/test/**',
|
|
|
|
'benchpress/**',
|
|
|
|
'**/e2e_test/**',
|
|
|
|
'angular2/examples/**/*_spec.ts',
|
|
|
|
|
|
|
|
'angular2/src/testing/**',
|
|
|
|
'angular2/testing.ts',
|
|
|
|
'angular2/testing_internal.ts',
|
|
|
|
'angular2/src/upgrade/**',
|
|
|
|
'angular2/upgrade.ts',
|
|
|
|
'angular2/platform/testing/**',
|
|
|
|
],
|
2015-04-14 02:56:07 -04:00
|
|
|
exclude: [
|
2015-04-26 21:04:45 -04:00
|
|
|
// the following code and tests are not compatible with CJS/node environment
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/test/animate/**',
|
|
|
|
'angular2/test/core/zone/**',
|
|
|
|
'angular2/test/testing/fake_async_spec.ts',
|
feat(tests): manage asynchronous tests using zones
Instead of using injectAsync and returning a promise, use the `async` function
to wrap tests. This will run the test inside a zone which does not complete
the test until all asynchronous tasks have been completed.
`async` may be used with the `inject` function, or separately.
BREAKING CHANGE:
`injectAsync` is now deprecated. Instead, use the `async` function
to wrap any asynchronous tests.
Before:
```
it('should wait for returned promises', injectAsync([FancyService], (service) => {
return service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
}));
it('should wait for returned promises', injectAsync([], () => {
return somePromise.then(() => { expect(true).toEqual(true); });
}));
```
After:
```
it('should wait for returned promises', async(inject([FancyService], (service) => {
service.getAsyncValue().then((value) => { expect(value).toEqual('async value'); });
})));
// Note that if there is no injection, we no longer need `inject` OR `injectAsync`.
it('should wait for returned promises', async(() => {
somePromise.then() => { expect(true).toEqual(true); });
}));
```
Closes #7735
2016-03-23 13:59:38 -04:00
|
|
|
'angular2/test/testing/testing_public_browser_spec.ts',
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/test/platform/xhr_impl_spec.ts',
|
|
|
|
'angular2/test/platform/browser/**/*.ts',
|
|
|
|
'angular2/test/common/forms/**',
|
|
|
|
'angular2/manual_typings/**',
|
|
|
|
'angular2/typings/**',
|
2015-11-23 13:18:04 -05:00
|
|
|
|
|
|
|
// we call browser's bootstrap
|
2016-02-09 14:12:41 -05:00
|
|
|
'angular2/test/router/route_config/route_config_spec.ts',
|
refactor(router): improve recognition and generation pipeline
This is a big change. @matsko also deserves much of the credit for the implementation.
Previously, `ComponentInstruction`s held all the state for async components.
Now, we introduce several subclasses for `Instruction` to describe each type of navigation.
BREAKING CHANGE:
Redirects now use the Link DSL syntax. Before:
```
@RouteConfig([
{ path: '/foo', redirectTo: '/bar' },
{ path: '/bar', component: BarCmp }
])
```
After:
```
@RouteConfig([
{ path: '/foo', redirectTo: ['Bar'] },
{ path: '/bar', component: BarCmp, name: 'Bar' }
])
```
BREAKING CHANGE:
This also introduces `useAsDefault` in the RouteConfig, which makes cases like lazy-loading
and encapsulating large routes with sub-routes easier.
Previously, you could use `redirectTo` like this to expand a URL like `/tab` to `/tab/posts`:
@RouteConfig([
{ path: '/tab', redirectTo: '/tab/users' }
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
Now the recommended way to handle this is case is to use `useAsDefault` like so:
```
@RouteConfig([
{ path: '/tab', component: TabsCmp, name: 'Tab' }
])
AppCmp { ... }
@RouteConfig([
{ path: '/posts', component: PostsCmp, useAsDefault: true, name: 'Posts' },
{ path: '/users', component: UsersCmp, name: 'Users' }
])
TabsCmp { ... }
```
In the above example, you can write just `['/Tab']` and the route `Users` is automatically selected as a child route.
Closes #4728
Closes #4228
Closes #4170
Closes #4490
Closes #4694
Closes #5200
Closes #5475
2015-11-23 21:07:37 -05:00
|
|
|
'angular2/test/router/integration/bootstrap_spec.ts',
|
2015-11-23 13:18:04 -05:00
|
|
|
|
|
|
|
// we check the public api by importing angular2/angular2
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/test/symbol_inspector/**/*.ts',
|
|
|
|
'angular2/test/public_api_spec.ts',
|
2015-11-23 13:18:04 -05:00
|
|
|
|
2015-12-15 19:38:27 -05:00
|
|
|
'angular2/test/web_workers/worker/renderer_integration_spec.ts',
|
|
|
|
|
2016-04-12 12:40:37 -04:00
|
|
|
'angular2/test/upgrade/**/*.ts',
|
|
|
|
'angular1_router/**',
|
2016-05-26 13:45:37 -04:00
|
|
|
'payload_tests/**',
|
2015-04-14 02:56:07 -04:00
|
|
|
]
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
2015-12-22 19:24:35 -05:00
|
|
|
// Compile the tests against the src @internal .d.ts
|
|
|
|
let srcPrivateDeclarations =
|
|
|
|
new Funnel(compiledSrcTreeWithInternals, {srcDir: INTERNAL_TYPINGS_PATH});
|
|
|
|
|
2016-04-06 19:10:45 -04:00
|
|
|
let testAmbients = [
|
2015-12-22 19:24:35 -05:00
|
|
|
'angular2/typings/jasmine/jasmine.d.ts',
|
|
|
|
'angular2/typings/angular-protractor/angular-protractor.d.ts',
|
2016-04-06 19:10:45 -04:00
|
|
|
'angular2/typings/selenium-webdriver/selenium-webdriver.d.ts'
|
|
|
|
];
|
|
|
|
let testAmbientsTree = new Funnel('modules', {files: testAmbients});
|
|
|
|
|
|
|
|
testTree = mergeTrees(
|
|
|
|
[testTree, srcPrivateDeclarations, testAmbientsTree, externalTypingsTree, packageTypings]);
|
|
|
|
|
|
|
|
let compiledTestTree = compileTree(testTree, false, []);
|
2015-12-22 19:24:35 -05:00
|
|
|
|
|
|
|
// Merge the compiled sources and tests
|
|
|
|
let compiledSrcTree =
|
|
|
|
new Funnel(compiledSrcTreeWithInternals, {exclude: [`${INTERNAL_TYPINGS_PATH}/**`]});
|
|
|
|
|
|
|
|
let compiledTree = mergeTrees([compiledSrcTree, compiledTestTree]);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2016-01-06 17:13:44 -05:00
|
|
|
// Generate test files
|
|
|
|
let generatedJsTestFiles =
|
|
|
|
generateForTest(compiledTree, {files: ['*/test/**/*_codegen_untyped.js']});
|
|
|
|
let generatedTsTestFiles = stew.rename(
|
|
|
|
generateForTest(compiledTree, {files: ['*/test/**/*_codegen_typed.js']}), /.js$/, '.ts');
|
|
|
|
|
|
|
|
// Compile generated test files against the src @internal .d.ts and the test files
|
|
|
|
compiledTree = mergeTrees(
|
|
|
|
[
|
2016-05-26 13:45:37 -04:00
|
|
|
compiledTree, generatedJsTestFiles,
|
2016-01-06 17:13:44 -05:00
|
|
|
compileTree(
|
|
|
|
new Funnel(
|
|
|
|
mergeTrees([
|
|
|
|
packageTypings,
|
2016-05-26 13:45:37 -04:00
|
|
|
new Funnel(
|
|
|
|
'modules', {include: ['angular2/manual_typings/**', 'angular2/typings/**']}),
|
|
|
|
generatedTsTestFiles, srcPrivateDeclarations, compiledTestTree
|
2016-01-06 17:13:44 -05:00
|
|
|
]),
|
|
|
|
{include: ['angular2/**', 'rxjs/**', 'zone.js/**']}),
|
|
|
|
false, [])
|
|
|
|
],
|
|
|
|
{overwrite: true});
|
|
|
|
|
2016-04-10 16:51:11 -04:00
|
|
|
// Down-level .d.ts files to be TS 1.8 compatible
|
|
|
|
// TODO(alexeagle): this can be removed once we drop support for using Angular 2 with TS 1.8
|
|
|
|
compiledTree = replace(compiledTree, {
|
|
|
|
files: ['**/*.d.ts'],
|
|
|
|
patterns: [
|
2016-04-29 13:08:56 -04:00
|
|
|
// all readonly keywords
|
2016-05-26 13:45:37 -04:00
|
|
|
{match: /^(\s*(static\s+|private\s+)*)readonly\s+/mg, replacement: '$1'},
|
2016-04-29 13:08:56 -04:00
|
|
|
// abstract properties (but not methods or classes)
|
2016-05-26 13:45:37 -04:00
|
|
|
{match: /^(\s+)abstract\s+([^\(\n]*$)/mg, replacement: '$1$2'},
|
2016-04-10 16:51:11 -04:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2015-04-13 19:39:47 -04:00
|
|
|
// Now we add the LICENSE file into all the folders that will become npm packages
|
|
|
|
outputPackages.forEach(function(destDir) {
|
|
|
|
var license = new Funnel('.', {files: ['LICENSE'], destDir: destDir});
|
2015-12-22 19:24:35 -05:00
|
|
|
// merge the test tree
|
|
|
|
compiledTree = mergeTrees([compiledTree, license]);
|
2015-04-13 19:39:47 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
// Get all docs and related assets and prepare them for js build
|
2015-12-22 19:24:35 -05:00
|
|
|
var srcDocs = extractDocs(srcTree);
|
|
|
|
var testDocs = extractDocs(testTree);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
|
|
|
var BASE_PACKAGE_JSON = require(path.join(projectRootDir, 'package.json'));
|
2015-12-22 19:24:35 -05:00
|
|
|
var srcPkgJsons = extractPkgJsons(srcTree, BASE_PACKAGE_JSON);
|
|
|
|
var testPkgJsons = extractPkgJsons(testTree, BASE_PACKAGE_JSON);
|
2015-04-13 19:39:47 -04:00
|
|
|
|
2016-02-11 00:25:12 -05:00
|
|
|
// Copy es6 typings so quickstart doesn't require typings install
|
|
|
|
let typingsTree = mergeTrees([
|
2016-05-26 13:45:37 -04:00
|
|
|
new Funnel('modules', {
|
|
|
|
include: [
|
|
|
|
'angular2/typings/es6-collections/es6-collections.d.ts',
|
|
|
|
'angular2/typings/es6-promise/es6-promise.d.ts',
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
writeFile(
|
|
|
|
'angular2/typings/browser.d.ts', '// Typings needed for compilation with --target=es5\n' +
|
|
|
|
'///<reference path="./es6-collections/es6-collections.d.ts"/>\n' +
|
|
|
|
'///<reference path="./es6-promise/es6-promise.d.ts"/>\n')
|
2016-02-11 00:25:12 -05:00
|
|
|
]);
|
|
|
|
|
|
|
|
var nodeTree =
|
|
|
|
mergeTrees([compiledTree, srcDocs, testDocs, srcPkgJsons, testPkgJsons, typingsTree]);
|
2015-05-19 20:39:57 -04:00
|
|
|
|
2015-05-22 15:50:58 -04:00
|
|
|
// Transform all tests to make them runnable in node
|
|
|
|
nodeTree = replace(nodeTree, {
|
|
|
|
files: ['**/test/**/*_spec.js'],
|
2015-06-03 16:42:57 -04:00
|
|
|
patterns: [
|
|
|
|
{
|
2015-08-20 17:28:25 -04:00
|
|
|
match: /^/,
|
2015-10-26 20:23:01 -04:00
|
|
|
replacement:
|
2015-11-17 18:24:36 -05:00
|
|
|
() =>
|
|
|
|
`var parse5Adapter = require('angular2/src/platform/server/parse5_adapter');\r\n` +
|
2016-05-26 13:45:37 -04:00
|
|
|
`parse5Adapter.Parse5DomAdapter.makeCurrent();`
|
2015-08-20 17:28:25 -04:00
|
|
|
},
|
2016-05-26 13:45:37 -04:00
|
|
|
{match: /$/, replacement: (_: any, relativePath: string) => '\r\n main(); \r\n'}
|
2015-06-03 16:42:57 -04:00
|
|
|
]
|
2015-05-22 15:50:58 -04:00
|
|
|
});
|
|
|
|
|
2015-06-19 18:02:35 -04:00
|
|
|
// Prepend 'use strict' directive to all JS files.
|
|
|
|
// See https://github.com/Microsoft/TypeScript/issues/3576
|
2015-10-26 20:23:01 -04:00
|
|
|
nodeTree = replace(
|
|
|
|
nodeTree, {files: ['**/*.js'], patterns: [{match: /^/, replacement: () => `'use strict';`}]});
|
2015-06-19 18:02:35 -04:00
|
|
|
|
2015-05-19 20:39:57 -04:00
|
|
|
return destCopy(nodeTree, destinationPath);
|
|
|
|
};
|
2015-12-22 19:24:35 -05:00
|
|
|
|
2016-05-26 13:45:37 -04:00
|
|
|
function compileTree(
|
|
|
|
tree: BroccoliTree, genInternalTypings: boolean, rootFilePaths: string[] = []) {
|
2015-12-22 19:24:35 -05:00
|
|
|
return compileWithTypescript(tree, {
|
|
|
|
// build pipeline options
|
2016-05-26 13:45:37 -04:00
|
|
|
'rootFilePaths': rootFilePaths,
|
|
|
|
'internalTypings': genInternalTypings,
|
2015-12-22 19:24:35 -05:00
|
|
|
// tsc options
|
2016-05-26 13:45:37 -04:00
|
|
|
'emitDecoratorMetadata': true,
|
|
|
|
'experimentalDecorators': true,
|
|
|
|
'declaration': true,
|
|
|
|
'stripInternal': true,
|
|
|
|
'module': 'commonjs',
|
|
|
|
'moduleResolution': 'classic',
|
|
|
|
'noEmitOnError': true,
|
|
|
|
'rootDir': '.',
|
|
|
|
'inlineSourceMap': true,
|
|
|
|
'inlineSources': true,
|
|
|
|
'target': 'es5'
|
2015-12-22 19:24:35 -05:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-01-22 13:51:16 -05:00
|
|
|
function extractDocs(tree: BroccoliTree) {
|
2015-12-22 19:24:35 -05:00
|
|
|
var docs = new Funnel(tree, {include: ['**/*.md', '**/*.png'], exclude: ['**/*.dart.md']});
|
|
|
|
return stew.rename(docs, 'README.js.md', 'README.md');
|
|
|
|
}
|
|
|
|
|
2016-01-22 13:51:16 -05:00
|
|
|
function extractPkgJsons(tree: BroccoliTree, BASE_PACKAGE_JSON: any) {
|
2015-12-22 19:24:35 -05:00
|
|
|
// Generate shared package.json info
|
|
|
|
var COMMON_PACKAGE_JSON = {
|
|
|
|
version: BASE_PACKAGE_JSON.version,
|
|
|
|
homepage: BASE_PACKAGE_JSON.homepage,
|
|
|
|
bugs: BASE_PACKAGE_JSON.bugs,
|
|
|
|
license: BASE_PACKAGE_JSON.license,
|
|
|
|
repository: BASE_PACKAGE_JSON.repository,
|
|
|
|
contributors: BASE_PACKAGE_JSON.contributors,
|
|
|
|
dependencies: BASE_PACKAGE_JSON.dependencies,
|
|
|
|
devDependencies: BASE_PACKAGE_JSON.devDependencies,
|
|
|
|
defaultDevDependencies: {}
|
|
|
|
};
|
|
|
|
|
|
|
|
var packageJsons = new Funnel(tree, {include: ['**/package.json']});
|
|
|
|
return renderLodashTemplate(packageJsons, {context: {'packageJson': COMMON_PACKAGE_JSON}});
|
|
|
|
}
|