-
Notifications
You must be signed in to change notification settings - Fork 26.2k
Tree-Shakeable Tokens #22005
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Tree-Shakeable Tokens #22005
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
dd8835c
fix(platform-browser): add @Injectable where it was missing
alxhub b5b2029
build: update some ts_library rules to ng_module
alxhub 3d883b1
feat(compiler): mark @NgModules in provider lists for identification …
alxhub 7700d3c
feat: change @Injectable() to support tree-shakeable tokens
alxhub File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "angular-integration", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@angular/animations": "file:../../dist/packages-dist/animations", | ||
"@angular/common": "file:../../dist/packages-dist/common", | ||
"@angular/compiler": "file:../../dist/packages-dist/compiler", | ||
"@angular/compiler-cli": "file:../../dist/packages-dist/compiler-cli", | ||
"@angular/core": "file:../../dist/packages-dist/core", | ||
"@angular/http": "file:../../dist/packages-dist/http", | ||
"@angular/platform-browser": "file:../../dist/packages-dist/platform-browser", | ||
"@angular/platform-browser-dynamic": "file:../../dist/packages-dist/platform-browser-dynamic", | ||
"@angular/platform-server": "file:../../dist/packages-dist/platform-server", | ||
"@types/node": "^9.4.0", | ||
"rxjs": "file:../../node_modules/rxjs", | ||
"typescript": "file:../../node_modules/typescript", | ||
"zone.js": "file:../../node_modules/zone.js" | ||
}, | ||
"devDependencies": { | ||
"@types/jasmine": "2.5.41", | ||
"concurrently": "3.4.0", | ||
"lite-server": "2.2.2", | ||
"protractor": "file:../../node_modules/protractor" | ||
}, | ||
"scripts": { | ||
"test": "./test.sh" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import {Component, NgModule} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {ServerModule} from '@angular/platform-server'; | ||
import {Lib2Module} from 'lib2_built'; | ||
|
||
@Component({ | ||
selector: 'test-app', | ||
template: '<test-cmp></test-cmp>', | ||
}) | ||
export class TestApp {} | ||
|
||
@NgModule({ | ||
declarations: [TestApp], | ||
bootstrap: [TestApp], | ||
imports: [ | ||
Lib2Module, | ||
BrowserModule.withServerTransition({appId: 'appId'}), | ||
ServerModule, | ||
], | ||
}) | ||
export class AppModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {Injectable, NgModule} from '@angular/core'; | ||
|
||
@NgModule({}) | ||
export class Lib1Module {} | ||
|
||
@Injectable({scope: Lib1Module}) | ||
export class Service { | ||
static instance = 0; | ||
readonly instance = Service.instance++; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {Component, Injector, NgModule} from '@angular/core'; | ||
import {Lib1Module, Service} from 'lib1_built'; | ||
|
||
@Component({ | ||
selector: 'test-cmp', | ||
template: '{{instance1}}:{{instance2}}', | ||
}) | ||
export class TestCmp { | ||
instance1: number; | ||
instance2: number; | ||
|
||
constructor(service: Service, injector: Injector) { | ||
this.instance1 = service.instance; | ||
this.instance2 = injector.get(Service).instance; | ||
} | ||
} | ||
|
||
@NgModule({ | ||
declarations: [TestCmp], | ||
exports: [TestCmp], | ||
imports: [Lib1Module], | ||
}) | ||
export class Lib2Module {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import 'zone.js/dist/zone-node'; | ||
|
||
import {enableProdMode} from '@angular/core'; | ||
import {renderModuleFactory} from '@angular/platform-server'; | ||
import {AppModuleNgFactory} from './app.ngfactory'; | ||
|
||
enableProdMode(); | ||
renderModuleFactory(AppModuleNgFactory, { | ||
document: '<test-app></test-app>', | ||
url: '/', | ||
}).then(html => { | ||
if (/>0:0</.test(html)) { | ||
process.exit(0); | ||
} else { | ||
console.error('html was', html); | ||
process.exit(1); | ||
} | ||
}).catch(err => { | ||
console.error(err); | ||
process.exit(2); | ||
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "lib1_built", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "lib2_built", | ||
"version": "0.0.0", | ||
"license": "MIT", | ||
"main": "./src/index.js", | ||
"typings": "./src/index.d.ts" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash | ||
set -e -x | ||
|
||
NPM_BIN=$(npm bin) | ||
PATH="$PATH:${NPM_BIN}" | ||
|
||
rm -rf node_modules/lib1_built node_modules/lib2_built dist/ | ||
|
||
ngc -p tsconfig-lib1.json | ||
cp src/package-lib1.json node_modules/lib1_built/package.json | ||
|
||
ngc -p tsconfig-lib2.json | ||
cp src/package-lib2.json node_modules/lib2_built/package.json | ||
|
||
ngc -p tsconfig-app.json | ||
|
||
node ./dist/src/main.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"lib": ["es2015", "dom"], | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"outDir": "dist", | ||
"types": ["node"], | ||
"rootDir": "." | ||
}, | ||
"files": [ | ||
"src/app.ts", | ||
"src/main.ts" | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"moduleResolution": "node", | ||
"lib": ["es2015", "dom"], | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"outDir": "node_modules/lib1_built", | ||
"types": [], | ||
"rootDir": "." | ||
}, | ||
"files": [ | ||
"src/lib1.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"flatModuleOutFile": "index.js", | ||
"flatModuleId": "lib1_built" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"module": "commonjs", | ||
"declaration": true, | ||
"moduleResolution": "node", | ||
"lib": ["es2015", "dom"], | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"outDir": "node_modules/lib2_built", | ||
"types": [], | ||
"rootDir": "." | ||
}, | ||
"files": [ | ||
"src/lib2.ts" | ||
], | ||
"angularCompilerOptions": { | ||
"skipTemplateCodegen": true, | ||
"flatModuleId": "lib2_built", | ||
"flatModuleOutFile": "index.js" | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
packages/compiler-cli/integrationtest/bazel/injectable_def/app/BUILD.bazel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package(default_visibility = ["//visibility:public"]) | ||
|
||
load("//tools:defaults.bzl", "ng_module", "ts_library") | ||
load("@build_bazel_rules_nodejs//:defs.bzl", "jasmine_node_test") | ||
|
||
ng_module( | ||
name = "app", | ||
srcs = glob( | ||
[ | ||
"src/**/*.ts", | ||
], | ||
), | ||
module_name = "app_built", | ||
deps = [ | ||
"//packages/compiler-cli/integrationtest/bazel/injectable_def/lib2", | ||
"//packages/core", | ||
"//packages/platform-browser", | ||
"//packages/platform-server", | ||
"@rxjs", | ||
], | ||
) |
31 changes: 31 additions & 0 deletions
31
packages/compiler-cli/integrationtest/bazel/injectable_def/app/src/basic.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {Component, NgModule} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {ServerModule} from '@angular/platform-server'; | ||
import {Lib2Module} from 'lib2_built/module'; | ||
|
||
@Component({ | ||
selector: 'id-app', | ||
template: '<lib2-cmp></lib2-cmp>', | ||
}) | ||
export class AppComponent { | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
Lib2Module, | ||
BrowserModule.withServerTransition({appId: 'id-app'}), | ||
ServerModule, | ||
], | ||
declarations: [AppComponent], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class BasicAppModule { | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/compiler-cli/integrationtest/bazel/injectable_def/app/src/hierarchy.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 {Component, Injectable, NgModule, Optional, Self} from '@angular/core'; | ||
import {BrowserModule} from '@angular/platform-browser'; | ||
import {ServerModule} from '@angular/platform-server'; | ||
|
||
@Injectable() | ||
export class Service { | ||
} | ||
|
||
@Component({ | ||
selector: 'hierarchy-app', | ||
template: '<child-cmp></child-cmp>', | ||
providers: [Service], | ||
}) | ||
export class AppComponent { | ||
} | ||
|
||
@Component({ | ||
selector: 'child-cmp', | ||
template: '{{found}}', | ||
}) | ||
export class ChildComponent { | ||
found: boolean; | ||
|
||
constructor(@Optional() @Self() service: Service|null) { this.found = !!service; } | ||
} | ||
|
||
@NgModule({ | ||
imports: [ | ||
BrowserModule.withServerTransition({appId: 'hierarchy-app'}), | ||
ServerModule, | ||
], | ||
declarations: [AppComponent, ChildComponent], | ||
bootstrap: [AppComponent], | ||
}) | ||
export class HierarchyAppModule { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this change (while awesome!) increased cli hello world by 5.8kb and closure hello world by 4kb. Do we understand why? Is this size increase justified? @alxhub can you please comment?