Skip to content

Commit

Permalink
fix(angular): fix Coveo headless error on application run (#193)
Browse files Browse the repository at this point in the history
  • Loading branch information
y-lakhdar authored May 3, 2021
1 parent dd72c42 commit f633459
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/angular/src/ng-add-setup-project/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../common-rules/dependencies';
import {updateNgModule} from './rules/ng-module';
import {addMaterialAngular, addToPackageJson} from './rules/dependencies';
import {updateTsConfig} from './rules/tsconfig';

export default function (options: CoveoSchema): Rule {
return async (tree: Tree) => {
Expand All @@ -20,6 +21,7 @@ export default function (options: CoveoSchema): Rule {
addMaterialAngular(options),
createFiles(options),
updateNgModule(options, project),
updateTsConfig(options),
]);
};
}
Expand Down
32 changes: 32 additions & 0 deletions packages/angular/src/ng-add-setup-project/rules/tsconfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {Rule, SchematicContext, Tree} from '@angular-devkit/schematics';
import {normalize} from '@angular-devkit/core';
import {CoveoSchema} from '../../schema';
import {EOL} from 'os';

export function updateTsConfig(_options: CoveoSchema): Rule {
return (tree: Tree, _context: SchematicContext) => {
const tsconfigBuffer = tree.read(normalize('./tsconfig.json'));
if (tsconfigBuffer === null) {
return;
}
try {
const fileArray = tsconfigBuffer.toString().split(EOL);
const tsconfigcomment = fileArray[0];
const tsConfig = JSON.parse(fileArray.slice(1).join(EOL));

tsConfig.compilerOptions.skipLibCheck = true;

tree.overwrite(
normalize('./tsconfig.json'),
`${tsconfigcomment}
${JSON.stringify(tsConfig, null, 4)}`
);
} catch (error) {
console.error(
`Unable to update the Angular tsconfig.json file by adding the "allowSyntheticDefaultImports" flag.
Make sure to add this flag to your tsconfig.json. Otherwise, you might experience errors when running the app`,
error
);
}
};
}

0 comments on commit f633459

Please sign in to comment.