Skip to content

Commit dd6e469

Browse files
committed
fix(@schematics/angular): remove setting files tsconfig field with SSR/Server generation
The `files` field within the `tsconfig.app.json` file is no longer used with the "solution" style tsconfig generated with applications. The SSR and server schematics no longer need to modify this field since all TS files within `src` are included by default.
1 parent 1987b2f commit dd6e469

File tree

6 files changed

+37
-9
lines changed

6 files changed

+37
-9
lines changed

packages/schematics/angular/application/index_spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ describe('Application Schematic', () => {
110110
expect(_extends).toBe('../../tsconfig.json');
111111
});
112112

113+
it('should add project references in the root tsconfig.json', async () => {
114+
const tree = await schematicRunner.runSchematic('application', defaultOptions, workspaceTree);
115+
116+
const { references } = readJsonFile(tree, '/tsconfig.json');
117+
expect(references).toContain(
118+
jasmine.objectContaining({ path: 'projects/foo/tsconfig.app.json' }),
119+
);
120+
expect(references).toContain(
121+
jasmine.objectContaining({ path: 'projects/foo/tsconfig.spec.json' }),
122+
);
123+
});
124+
113125
it('should install npm dependencies when `skipInstall` is false', async () => {
114126
await schematicRunner.runSchematic(
115127
'application',

packages/schematics/angular/server/index.ts

-4
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,6 @@ function updateConfigFileApplicationBuilder(options: ServerOptions): Rule {
119119
function updateTsConfigFile(tsConfigPath: string): Rule {
120120
return (host: Tree) => {
121121
const json = new JSONFile(host, tsConfigPath);
122-
const filesPath = ['files'];
123-
const files = new Set((json.get(filesPath) as string[] | undefined) ?? []);
124-
files.add('src/' + serverMainEntryName);
125-
json.modify(filesPath, [...files]);
126122

127123
const typePath = ['compilerOptions', 'types'];
128124
const types = new Set((json.get(typePath) as string[] | undefined) ?? []);

packages/schematics/angular/server/index_spec.ts

-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ describe('Server Schematic', () => {
167167
const filePath = '/projects/bar/tsconfig.app.json';
168168
const contents = parseJson(tree.readContent(filePath).toString());
169169
expect(contents.compilerOptions.types).toEqual(['node']);
170-
expect(contents.files).toEqual(['src/main.ts', 'src/main.server.ts']);
171170
});
172171

173172
it(`should add 'provideClientHydration' to the providers list`, async () => {

packages/schematics/angular/ssr/index.ts

+7
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ function updateApplicationBuilderTsConfigRule(options: SSROptions): Rule {
154154
}
155155

156156
const json = new JSONFile(host, tsConfigPath);
157+
158+
// Skip adding the files entry if the server entry would already be included
159+
const include = json.get(['include']);
160+
if (Array.isArray(include) && include.includes('src/**/*.ts')) {
161+
return;
162+
}
163+
157164
const filesPath = ['files'];
158165
const files = new Set((json.get(filesPath) as string[] | undefined) ?? []);
159166
files.add('src/server.ts');

packages/schematics/angular/ssr/index_spec.ts

+17-2
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,28 @@ describe('SSR Schematic', () => {
7070
expect((schematicRunner.tasks[0].options as { command: string }).command).toBe('install');
7171
});
7272

73-
it(`should update 'tsconfig.app.json' files with Express main file`, async () => {
73+
it(`should not update 'tsconfig.app.json' files with Express main file already included`, async () => {
7474
const tree = await schematicRunner.runSchematic('ssr', defaultOptions, appTree);
7575
const { files } = tree.readJson('/projects/test-app/tsconfig.app.json') as {
7676
files: string[];
7777
};
7878

79-
expect(files).toEqual(['src/main.ts', 'src/main.server.ts', 'src/server.ts']);
79+
expect(files).toBeUndefined();
80+
});
81+
82+
it(`should update 'tsconfig.app.json' files with Express main file if not included`, async () => {
83+
const appTsConfigContent = appTree.readJson('/projects/test-app/tsconfig.app.json') as {
84+
include?: string[];
85+
};
86+
appTsConfigContent.include = [];
87+
appTree.overwrite('/projects/test-app/tsconfig.app.json', JSON.stringify(appTsConfigContent));
88+
89+
const tree = await schematicRunner.runSchematic('ssr', defaultOptions, appTree);
90+
const { files } = tree.readJson('/projects/test-app/tsconfig.app.json') as {
91+
files: string[];
92+
};
93+
94+
expect(files).toContain('src/server.ts');
8095
});
8196
});
8297

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
/* To learn more about Angular compiler options: https://angular.dev/reference/configs/angular-compiler-options. */
33
{
44
"compileOnSave": false,
5-
"compilerOptions": {
6-
"outDir": "./dist/out-tsc",<% if (strict) { %>
5+
"compilerOptions": {<% if (strict) { %>
76
"strict": true,
87
"noImplicitOverride": true,
98
"noPropertyAccessFromIndexSignature": true,

0 commit comments

Comments
 (0)