Skip to content

Commit 1f94fd2

Browse files
committed
feat: consolidate tsconfig files and allow override for custom envs
1 parent 0664886 commit 1f94fd2

38 files changed

+687
-241
lines changed

angular/devkit/common/utils.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,13 @@ const timestamp = Date.now();
140140
* Add the list of files to include in the typescript compilation as absolute paths
141141
*/
142142
export function generateTsConfig(
143-
appPath: string,
143+
pAppPath: string,
144+
tsConfigPath: string,
144145
includePaths: string[],
145146
excludePaths: string[] = [],
146-
tsPaths: { [key: string]: string[] }
147+
tsPaths: { [key: string]: string[] },
147148
): string {
148-
const tsconfigPath = join(appPath, 'tsconfig.app.json');
149-
const tsconfigJSON = readConfigFile(tsconfigPath, sys.readFile).config;
150-
const pAppPath = normalizePath(appPath);
149+
const tsconfigJSON = readConfigFile(tsConfigPath, sys.readFile).config;
151150

152151
// tsconfigJSON.config.angularCompilerOptions.enableIvy = this.enableIvy;
153152
tsconfigJSON.files = tsconfigJSON.files?.map((file: string) => posix.join(pAppPath, file)) || [];
@@ -174,6 +173,7 @@ export function writeTsconfig(
174173
application: ApplicationMain,
175174
pkg: PkgMain,
176175
devFilesMain: DevFilesMain,
176+
tsConfigPath?: string,
177177
workspace?: Workspace
178178
): string {
179179
const tsPaths: { [key: string]: string[] } = {};
@@ -215,7 +215,9 @@ export function writeTsconfig(
215215
});
216216
});
217217

218-
const content = generateTsConfig(rootPath, Array.from(includePaths), Array.from(excludePaths), tsPaths);
218+
const pAppPath = normalizePath(rootPath);
219+
tsConfigPath = tsConfigPath ?? join(rootPath, 'tsconfig.app.json');
220+
const content = generateTsConfig(pAppPath, tsConfigPath, Array.from(includePaths), Array.from(excludePaths), tsPaths);
219221
const hash = objectHash(content);
220222
const targetPath = join(dirPath, `tsconfig/tsconfig-${ timestamp }.json`);
221223

angular/devkit/webpack/ng-webpack-bundler.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from '@teambit/webpack';
2929
import { generateTransformers, runTransformers } from '@teambit/webpack.webpack-bundler';
3030
import assert from 'assert';
31-
import { join } from 'path';
31+
import { join, posix } from 'path';
3232
import type { Configuration, WebpackPluginInstance } from 'webpack';
3333
import { WebpackConfigFactoryOpts } from './utils';
3434
import { StatsLoggerPlugin } from './webpack-plugins/stats-logger';
@@ -93,11 +93,11 @@ export class NgWebpackBundler {
9393
let plugins: WebpackPluginInstance[] = [];
9494
if (isAppBuildContext(bundlerContext)) { // When you use `bit build` for an actual angular app
9595
appRootPath = bundlerContext.capsule.path;
96-
tsconfigPath = join(appRootPath, 'tsconfig.app.json');
96+
tsconfigPath = options?.angularOptions?.tsConfig ?? posix.join(appRootPath, 'tsconfig.app.json');
9797
plugins = [new StatsLoggerPlugin()];
9898
} else { // When you use `bit build` for the preview app
9999
appRootPath = getPreviewRootPath();
100-
tsconfigPath = writeTsconfig(bundlerContext, appRootPath, tempFolder, application, pkg, devFilesMain, workspace);
100+
tsconfigPath = writeTsconfig(bundlerContext, appRootPath, tempFolder, application, pkg, devFilesMain, options?.angularOptions?.tsConfig, workspace);
101101
}
102102

103103
const transformers = options.transformers || [];

angular/devkit/webpack/ng-webpack-dev-server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export class NgWebpackDevServer {
103103
isApp = true;
104104
} else { // When you use `bit start`
105105
appRootPath = getPreviewRootPath();
106-
tsconfigPath = writeTsconfig(devServerContext, appRootPath, tempFolder, application, pkg, devFilesMain, workspace);
106+
tsconfigPath = writeTsconfig(devServerContext, appRootPath, tempFolder, application, pkg, devFilesMain, options?.angularOptions?.tsConfig, workspace);
107107

108108
// add the assets paths for each component to the angular compiler options
109109
const assetsPaths: string[] = [];
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,5 @@
11
/* To learn more about this file see: https://angular.io/config/tsconfig. */
22
{
3-
"compileOnSave": false,
4-
"compilerOptions": {
5-
"baseUrl": "./",
6-
"outDir": "./dist/out-tsc/spec",
7-
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true,
11-
"sourceMap": true,
12-
"declaration": false,
13-
"downlevelIteration": true,
14-
"experimentalDecorators": true,
15-
"moduleResolution": "node",
16-
"allowSyntheticDefaultImports": true,
17-
"importHelpers": true,
18-
"allowJs": true,
19-
"target": "es2020",
20-
"module": "esnext",
21-
"lib": [
22-
"es2018",
23-
"dom"
24-
],
25-
"types": ["jest", "node"]
26-
},
27-
"angularCompilerOptions": {
28-
"enableI18nLegacyMessageIdFormat": false,
29-
"strictInjectionParameters": true,
30-
"strictInputAccessModifiers": true,
31-
"strictTemplates": true,
32-
"enableIvy": true
33-
},
3+
"extends": "@bitdev/angular.envs.base-env/config/tsconfig.json",
344
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
355
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
/* To learn more about this file see: https://angular.io/config/tsconfig. */
22
{
3-
"compileOnSave": false,
4-
"compilerOptions": {
5-
"baseUrl": "./",
6-
"outDir": "./dist/out-tsc/spec",
7-
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true,
11-
"sourceMap": true,
12-
"declaration": false,
13-
"downlevelIteration": true,
14-
"experimentalDecorators": true,
15-
"esModuleInterop": true,
16-
"moduleResolution": "node",
17-
"allowSyntheticDefaultImports": true,
18-
"importHelpers": true,
19-
"allowJs": true,
20-
"target": "es2020",
21-
"module": "esnext",
22-
"lib": [
23-
"es2018",
24-
"dom"
25-
],
26-
"types": ["jest", "node"]
27-
},
28-
"angularCompilerOptions": {
29-
"enableI18nLegacyMessageIdFormat": false,
30-
"strictInjectionParameters": true,
31-
"strictInputAccessModifiers": true,
32-
"strictTemplates": true,
33-
"enableIvy": true
34-
},
3+
"extends": "@bitdev/angular.envs.base-env/config/tsconfig.json",
354
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
365
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
/* To learn more about this file see: https://angular.io/config/tsconfig. */
22
{
3-
"compileOnSave": false,
4-
"compilerOptions": {
5-
"baseUrl": "./",
6-
"outDir": "./dist/out-tsc/spec",
7-
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true,
11-
"sourceMap": true,
12-
"declaration": false,
13-
"downlevelIteration": true,
14-
"experimentalDecorators": true,
15-
"esModuleInterop": true,
16-
"moduleResolution": "node",
17-
"allowSyntheticDefaultImports": true,
18-
"importHelpers": true,
19-
"allowJs": true,
20-
"target": "es2020",
21-
"module": "esnext",
22-
"lib": [
23-
"es2018",
24-
"dom"
25-
],
26-
"types": ["jest", "node"]
27-
},
28-
"angularCompilerOptions": {
29-
"enableI18nLegacyMessageIdFormat": false,
30-
"strictInjectionParameters": true,
31-
"strictInputAccessModifiers": true,
32-
"strictTemplates": true,
33-
"enableIvy": true
34-
},
3+
"extends": "@bitdev/angular.envs.base-env/config/tsconfig.json",
354
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
365
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
/* To learn more about this file see: https://angular.io/config/tsconfig. */
22
{
3-
"compileOnSave": false,
4-
"compilerOptions": {
5-
"baseUrl": "./",
6-
"outDir": "./dist/out-tsc/spec",
7-
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true,
11-
"sourceMap": true,
12-
"declaration": false,
13-
"downlevelIteration": true,
14-
"experimentalDecorators": true,
15-
"esModuleInterop": true,
16-
"moduleResolution": "node",
17-
"allowSyntheticDefaultImports": true,
18-
"importHelpers": true,
19-
"allowJs": true,
20-
"target": "es2020",
21-
"module": "esnext",
22-
"lib": [
23-
"es2018",
24-
"dom"
25-
],
26-
"types": ["jest", "node"]
27-
},
28-
"angularCompilerOptions": {
29-
"enableI18nLegacyMessageIdFormat": false,
30-
"strictInjectionParameters": true,
31-
"strictInputAccessModifiers": true,
32-
"strictTemplates": true,
33-
"enableIvy": true
34-
},
3+
"extends": "@bitdev/angular.envs.base-env/config/tsconfig.json",
354
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
365
}
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,5 @@
11
/* To learn more about this file see: https://angular.io/config/tsconfig. */
22
{
3-
"compileOnSave": false,
4-
"compilerOptions": {
5-
"baseUrl": "./",
6-
"outDir": "./dist/out-tsc/spec",
7-
"forceConsistentCasingInFileNames": true,
8-
"strict": true,
9-
"noImplicitReturns": true,
10-
"noFallthroughCasesInSwitch": true,
11-
"sourceMap": true,
12-
"declaration": false,
13-
"downlevelIteration": true,
14-
"experimentalDecorators": true,
15-
"esModuleInterop": true,
16-
"moduleResolution": "node",
17-
"allowSyntheticDefaultImports": true,
18-
"importHelpers": true,
19-
"allowJs": true,
20-
"target": "es2020",
21-
"module": "esnext",
22-
"lib": [
23-
"es2018",
24-
"dom"
25-
],
26-
"types": ["jest", "node"]
27-
},
28-
"angularCompilerOptions": {
29-
"enableI18nLegacyMessageIdFormat": false,
30-
"strictInjectionParameters": true,
31-
"strictInputAccessModifiers": true,
32-
"strictTemplates": true,
33-
"enableIvy": true
34-
},
3+
"extends": "@bitdev/angular.envs.base-env/config/tsconfig.json",
354
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
365
}

angular/envs/base-env/angular-base-env.bit-env.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export abstract class AngularBaseEnv implements AngularEnvInterface {
116116

117117
getLinterConfig(): any {
118118
return {
119-
tsconfig: require.resolve('@bitdev/angular.dev-services.linter.eslint/config/tsconfig.json'),
119+
tsconfig: require.resolve('./config/tsconfig.json'),
120120
eslint: ESLintLib,
121121
configPath: require.resolve('./config/eslintrc'),
122122
// resolve all plugins from the angular environment.
@@ -190,7 +190,13 @@ export abstract class AngularBaseEnv implements AngularEnvInterface {
190190
webpackOptions: any = {},
191191
sourceRoot?: string
192192
) => this.getDevServer(devServerContext, ngEnvOptions, transformers, angularOptions, webpackOptions, sourceRoot);
193-
const bundlerProvider: BundlerProvider = (bundlerContext: BundlerContext) => this.getBundler(bundlerContext, ngEnvOptions);
193+
const bundlerProvider: BundlerProvider = (
194+
bundlerContext: BundlerContext,
195+
transformers: WebpackConfigTransformer[] = [],
196+
angularOptions: Partial<(BrowserOptions | ApplicationOptions) & DevServerOptions> = {},
197+
webpackOptions: any = {},
198+
sourceRoot?: string
199+
) => this.getBundler(bundlerContext, ngEnvOptions, transformers, angularOptions, webpackOptions, sourceRoot);
194200
return AngularPreview.from({
195201
devServerProvider,
196202
bundlerProvider,

angular/envs/base-env/config/tsconfig.json

+16-9
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22
"extends": "@teambit/react/typescript/tsconfig.json",
33
"compilerOptions": {
44
/* Visit https://aka.ms/tsconfig.json to read more about this file */
5-
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
6-
"lib": ["ESNext", "dom"], /* Specify library files to be included in the compilation. */
75
"allowJs": true, /* Allow javascript files to be compiled. */
8-
"strict": true, /* Enable all strict type-checking options. */
9-
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
6+
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
107
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
11-
"preserveSymlinks": false, /* Do not resolve the real path of symlinks. */
128
"experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
13-
"emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
9+
"forceConsistentCasingInFileNames": true, /* Disallow inconsistently cased references to the same file. */
10+
"jsx": "react-jsx", /* Specify JSX code generation: 'preserve', 'react-native', 'react-jsx' or 'react'. */
11+
"lib": ["ESNext", "dom"], /* Specify library files to be included in the compilation. */
12+
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
13+
"preserveSymlinks": false, /* Do not resolve the real path of symlinks. */
1414
"skipLibCheck": true, /* Skip type checking of declaration files. */
15-
"forceConsistentCasingInFileNames": true,
16-
"jsx": "react-jsx"
15+
"strict": true, /* Enable all strict type-checking options. */
16+
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */
1717
},
1818
"exclude": ["artifacts", "public", "dist", "node_modules", "package.json", "**/*.cjs"],
19-
"include": ["**/*", "**/*.json"]
19+
"include": ["**/*", "**/*.json"],
20+
"angularCompilerOptions": {
21+
"enableI18nLegacyMessageIdFormat": false,
22+
"strictInjectionParameters": true,
23+
"strictInputAccessModifiers": true,
24+
"strictTemplates": true,
25+
"enableIvy": true
26+
}
2027
}

angular/examples/my-angular-env/config/jest.config.ts

+19
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,26 @@
22
* @see https://bit.dev/reference/jest/jest-config
33
*/
44
import { jestConfig } from '@bitdev/angular.angular-env';
5+
import { generateNodeModulesPattern } from '@teambit/dependencies.modules.packages-excluder';
6+
const { defaultTransformerOptions } = require('jest-preset-angular/presets');
57

8+
const packagesToExclude: string[] = ['@angular', '@ngrx', 'apollo-angular'];
69
export default {
710
...jestConfig,
11+
transform: {
12+
'^.+\\.(ts|js|mjs|html|svg)$': [
13+
'jest-preset-angular',
14+
{
15+
...defaultTransformerOptions,
16+
tsconfig: require.resolve('./tsconfig.spec.json')
17+
}
18+
]
19+
},
20+
transformIgnorePatterns: [
21+
'^.+.module.(css|sass|scss)$',
22+
generateNodeModulesPattern({
23+
packages: packagesToExclude,
24+
excludeComponents: true
25+
})
26+
]
827
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
/* This config is used for bit start and bit build to generate the preview */
3+
{
4+
"extends": "./tsconfig.json",
5+
"files": [
6+
"./src/main.ts",
7+
"./src/polyfills.ts"
8+
],
9+
"include": [
10+
"./src/app/**/*.ts",
11+
],
12+
"exclude": [
13+
"./src/app/**/*.spec.ts"
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
/* This config is used for bit test */
3+
{
4+
"extends": "./tsconfig.json",
5+
"include": ["**/*.spec.+(js|ts)", "**/*.test.+(js|ts)", "**/*.d.ts"]
6+
}

angular/examples/my-angular-v13-env/config/jest.config.ts

+15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,22 @@
22
* @see https://bit.dev/reference/jest/jest-config
33
*/
44
import { jestConfig } from '@bitdev/angular.envs.angular-v13-env';
5+
import { generateNodeModulesPattern } from '@teambit/dependencies.modules.packages-excluder';
6+
7+
const packagesToExclude: string[] = ['@angular', '@ngrx', 'apollo-angular'];
58

69
export default {
710
...jestConfig,
11+
globals: {
12+
'ts-jest': {
13+
tsconfig: require.resolve('./tsconfig.spec.json'),
14+
},
15+
},
16+
transformIgnorePatterns: [
17+
'^.+.module.(css|sass|scss)$',
18+
generateNodeModulesPattern({
19+
packages: packagesToExclude,
20+
excludeComponents: true
21+
})
22+
]
823
};

0 commit comments

Comments
 (0)