Skip to content

Commit

Permalink
refactor: remove old code (Angular <13) for ng-packagr
Browse files Browse the repository at this point in the history
  • Loading branch information
ocombe committed Dec 4, 2023
1 parent 955f91f commit be8304b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 30 deletions.
1 change: 0 additions & 1 deletion angular/devkit/common/env-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export type AngularEnvOptions = {
jestConfigPath: string;
jestModulePath: string;
ngPackagrModulePath: string;
readDefaultTsConfig: string;
angularElementsModulePath?: string;
webpackConfigFactory?: WebpackConfigFactory;
webpackDevServerModulePath?: string;
Expand Down
41 changes: 17 additions & 24 deletions angular/devkit/compiler/ng-packagr/ng-packagr.compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,28 +127,21 @@ export class NgPackagrCompiler implements Compiler {
this.ngPackagr = require(ngPackagrPath).ngPackagr();

// eslint-disable-next-line global-require,import/no-dynamic-require
const module = require(ngEnvOptions.readDefaultTsConfig);
if (typeof module.readDefaultTsConfig !== 'undefined') {
// Angular v8 to v12
this.readDefaultTsConfig = module.readDefaultTsConfig;
} else {
// Angular v13+
this.readDefaultTsConfig = async() => {
const { initializeTsConfig } = module;
const entryPoints: any = [{
data: {
entryPoint: {
moduleId: '@bitdev/angular.dev-services.compiler.ng-packagr',
entryFilePath: '',
flatModuleFile: ''
},
tsConfig: null
}
}];
await initializeTsConfig(undefined, entryPoints);
return entryPoints[0].data.tsConfig;
};
}
this.readDefaultTsConfig = async() => {
const { initializeTsConfig } = require('ng-packagr/lib/ts/tsconfig');
const entryPoints: any = [{
data: {
entryPoint: {
moduleId: '@bitdev/angular.dev-services.compiler.ng-packagr',
entryFilePath: '',
flatModuleFile: ''
},
tsConfig: null
}
}];
await initializeTsConfig(undefined, entryPoints);
return entryPoints[0].data.tsConfig;
};
}

updatePaths(packageJson: Record<string, any>) {
Expand Down Expand Up @@ -182,7 +175,7 @@ export class NgPackagrCompiler implements Compiler {
diagnosticsReporter: DiagnosticsReporter,
// component ids of other angular components in the workspace
componentIds: string[],
isBuild = true,
isBuild = true
): Promise<void> {
// check for dependencies other than tslib and move them to peer dependencies
// see https://github.com/ng-packagr/ng-packagr/blob/master/docs/dependencies.md#general-recommendation-use-peerdependencies-whenever-possible
Expand Down Expand Up @@ -248,7 +241,7 @@ export class NgPackagrCompiler implements Compiler {
await removeFilesAndEmptyDirsRecursively([resolve(join(pathToOutputFolder, this.distDir, PACKAGE_JSON))]);
await removeFilesAndEmptyDirsRecursively([resolve(join(pathToOutputFolder, NG_PACKAGE_JSON))]);
// eslint-disable-next-line consistent-return
}, async (err: Error) => {
}, async(err: Error) => {
if (err.message === ViewEngineTemplateError && !tsCompilerOptions.fullTemplateTypeCheck) {
// eslint-disable-next-line no-console
console.warn(chalk.yellow(`\nError "${ err.message }" triggered by the Angular compiler, retrying compilation without "fullTemplateTypeCheck" (you should probably create a custom environment using "bit create ng-env my-custom-angular-env" to set this option by default and avoid this error message)\n`));
Expand Down
1 change: 0 additions & 1 deletion angular/envs/angular-v13-env/angular-v13-env.bit-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class AngularV13Env extends AngularBaseEnv {
jestConfigPath: require.resolve('./jest/jest.config'),
jestModulePath: require.resolve('jest'),
ngPackagrModulePath: require.resolve('ng-packagr'),
readDefaultTsConfig: require.resolve('ng-packagr/lib/ts/tsconfig'),
webpackConfigFactory,
webpackDevServerModulePath: require.resolve('webpack-dev-server'),
// resolving to the webpack used by angular devkit to avoid multiple instances of webpack
Expand Down
1 change: 0 additions & 1 deletion angular/envs/angular-v14-env/angular-v14-env.bit-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class AngularV14Env extends AngularBaseEnv {
jestConfigPath: require.resolve('./jest/jest.config'),
jestModulePath: require.resolve('jest'),
ngPackagrModulePath: require.resolve('ng-packagr'),
readDefaultTsConfig: require.resolve('ng-packagr/lib/ts/tsconfig'),
webpackConfigFactory,
webpackDevServerModulePath: require.resolve('webpack-dev-server'),
// resolving to the webpack used by angular devkit to avoid multiple instances of webpack
Expand Down
1 change: 0 additions & 1 deletion angular/envs/angular-v15-env/angular-v15-env.bit-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class AngularV15Env extends AngularBaseEnv {
jestConfigPath: require.resolve('./jest/jest.config'),
jestModulePath: require.resolve('jest'),
ngPackagrModulePath: require.resolve('ng-packagr'),
readDefaultTsConfig: require.resolve('ng-packagr/lib/ts/tsconfig'),
webpackConfigFactory,
webpackDevServerModulePath: require.resolve('webpack-dev-server'),
// resolving to the webpack used by angular devkit to avoid multiple instances of webpack
Expand Down
1 change: 0 additions & 1 deletion angular/envs/angular-v16-env/angular-v16-env.bit-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class AngularV16Env extends AngularBaseEnv {
jestConfigPath: require.resolve('./jest/jest.config'),
jestModulePath: require.resolve('jest'),
ngPackagrModulePath: require.resolve('ng-packagr'),
readDefaultTsConfig: require.resolve('ng-packagr/lib/ts/tsconfig'),
webpackConfigFactory,
webpackDevServerModulePath: require.resolve('webpack-dev-server'),
// resolving to the webpack used by angular devkit to avoid multiple instances of webpack
Expand Down
1 change: 0 additions & 1 deletion angular/envs/angular-v17-env/angular-v17-env.bit-env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class AngularV17Env extends AngularBaseEnv {
jestConfigPath: require.resolve('./jest/jest.config'),
jestModulePath: require.resolve('jest'),
ngPackagrModulePath: require.resolve('ng-packagr'),
readDefaultTsConfig: require.resolve('ng-packagr/lib/ts/tsconfig'),
webpackConfigFactory,
webpackDevServerModulePath: require.resolve('webpack-dev-server'),
// resolving to the webpack used by angular devkit to avoid multiple instances of webpack
Expand Down

0 comments on commit be8304b

Please sign in to comment.