Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd6f594f

Browse files
committed
feat(@schematics/angular): generate applications using TypeScript project references
When generating a project (either via `ng new` or `ng generate application`), thecreated TypeScript configuration files (`tsconfig.app.json`/`tsconfig.spec.json`)will be setup as composite projects and added as project references to in the root`tsconfig.json`. This transforms the root `tsconfig.json` into a "solution" styleconfiguration. This allows IDEs to more accurately discover and provide type informationfor the varying types of files (test, application, etc.) within each project.The Angular build process is otherwise unaffected by these changes.
1 parent11d1f2e commitd6f594f

File tree

5 files changed

+36
-9
lines changed

5 files changed

+36
-9
lines changed

‎packages/schematics/angular/application/files/common-files/tsconfig.app.json.template‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
{
44
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
55
"compilerOptions": {
6+
"composite": true,
67
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/app",
78
"types": []
89
},
9-
"files": [
10-
"src/main.ts"
11-
],
1210
"include": [
13-
"src/**/*.d.ts"
11+
"src/**/*.ts"
12+
],
13+
"exclude": [
14+
"src/**/*.spec.ts"
1415
]
1516
}

‎packages/schematics/angular/application/files/common-files/tsconfig.spec.json.template‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
{
44
"extends": "<%= relativePathToWorkspaceRoot %>/tsconfig.json",
55
"compilerOptions": {
6+
"composite": true,
67
"outDir": "<%= relativePathToWorkspaceRoot %>/out-tsc/spec",
78
"types": [
89
"jasmine"
910
]
1011
},
1112
"include": [
12-
"src/**/*.spec.ts",
13-
"src/**/*.d.ts"
13+
"src/**/*.ts"
1414
]
1515
}

‎packages/schematics/angular/application/index.ts‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,39 @@ import {
2626
import{NodePackageInstallTask}from'@angular-devkit/schematics/tasks';
2727
import{SchemaasComponentOptions}from'../component/schema';
2828
import{NodeDependencyType,addPackageJsonDependency}from'../utility/dependencies';
29+
import{JSONFile}from'../utility/json-file';
2930
import{latestVersions}from'../utility/latest-versions';
3031
import{relativePathToWorkspaceRoot}from'../utility/paths';
3132
import{getWorkspace,updateWorkspace}from'../utility/workspace';
3233
import{Builders,ProjectType}from'../utility/workspace-models';
3334
import{SchemaasApplicationOptions,Style}from'./schema';
3435

36+
functionupdateTsConfig(...paths:string[]){
37+
return(host:Tree)=>{
38+
if(!host.exists('tsconfig.json')){
39+
returnhost;
40+
}
41+
42+
constnewReferences=paths.map((path)=>({ path}));
43+
44+
constfile=newJSONFile(host,'tsconfig.json');
45+
constjsonPath=['references'];
46+
constvalue=file.get(jsonPath);
47+
file.modify(jsonPath,Array.isArray(value) ?[...value, ...newReferences] :newReferences);
48+
};
49+
}
50+
3551
exportdefaultfunction(options:ApplicationOptions):Rule{
3652
returnasync(host:Tree,context:SchematicContext)=>{
3753
const{ appDir, appRootSelector, componentOptions, folderName, sourceDir}=
3854
awaitgetAppOptions(host,options);
3955

4056
returnchain([
4157
addAppToWorkspaceFile(options,appDir,folderName),
58+
updateTsConfig(
59+
join(normalize(appDir),'tsconfig.app.json'),
60+
join(normalize(appDir),'tsconfig.spec.json'),
61+
),
4262
options.standalone
4363
?noop()
4464
:schematic('module',{

‎packages/schematics/angular/application/index_spec.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,13 @@ describe('Application Schematic', () => {
9393
it('should set the right paths in the tsconfig.app.json',async()=>{
9494
consttree=awaitschematicRunner.runSchematic('application',defaultOptions,workspaceTree);
9595

96-
const{ files,extends:_extends}=readJsonFile(tree,'/projects/foo/tsconfig.app.json');
97-
expect(files).toEqual(['src/main.ts']);
96+
const{
97+
include,
98+
exclude,
99+
extends:_extends,
100+
}=readJsonFile(tree,'/projects/foo/tsconfig.app.json');
101+
expect(include).toEqual(['src/**/*.ts']);
102+
expect(exclude).toEqual(['src/**/*.spec.ts']);
98103
expect(_extends).toBe('../../tsconfig.json');
99104
});
100105

‎packages/schematics/angular/workspace/files/tsconfig.json.template‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@
2222
"strictInputAccessModifiers": true,
2323
"typeCheckHostBindings": true,
2424
"strictTemplates": true<% } %>
25-
}
25+
},
26+
"files": []
2627
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp