Skip to content

Commit

Permalink
fix(workspace): the tsconfig links to generate libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
kpanot committed Dec 23, 2024
1 parent c8834dc commit d9c04af
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 12 deletions.
43 changes: 31 additions & 12 deletions packages/@o3r/workspace/schematics/library/rules/rules.ng.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,44 @@ export function ngGenerateModule(options: NgGenerateModuleSchema & { targetPath:
const updateTsConfigFiles: Rule = (tree, context) => {
const tsconfigBase = findConfigFileRelativePath(tree, ['tsconfig.base.json', 'tsconfig.json'], '/');
const tsconfigBuild = findConfigFileRelativePath(tree, ['tsconfig.build.json'], '/');

// create tsconfig.build.json if it does not exist
if (tsconfigBase && (!tsconfigBuild || !tree.exists(tsconfigBuild))) {
const content = {
extends: tsconfigBase.replace(/^\/?/, './'),
compilerOptions: {
declarationMap: false
},
angularCompilerOptions: {
compilationMode: 'partial'
}
};
tree.create('/tsconfig.build.json', JSON.stringify(content, null, 2));
}

[tsconfigBase, tsconfigBuild].forEach((tsconfigPath) => {
if (tsconfigPath) {
const configFile = tree.readJson(tsconfigPath) as TsConfigJson;
if (configFile?.compilerOptions?.paths) {
configFile.compilerOptions.baseUrl = '.';
configFile.compilerOptions.paths = Object.fromEntries(
Object.entries(configFile.compilerOptions.paths).filter(([pathName, _]) => pathName !== options.name));
configFile.compilerOptions.paths[options.packageJsonName] = [
path.posix.join(relativeTargetPath, 'dist'),
path.posix.join(relativeTargetPath, 'src', 'public-api')
];
tree.overwrite(tsconfigPath, JSON.stringify(configFile, null, 2));
} else {
context.logger.warn(`${tsconfigPath} does not contain path mapping, the edition will be skipped`);
}
configFile.compilerOptions ||= {};
configFile.compilerOptions.paths ||= {};
configFile.compilerOptions.baseUrl ||= '.';
configFile.compilerOptions.paths = Object.fromEntries(
Object.entries(configFile.compilerOptions.paths).filter(([pathName, _]) => pathName !== options.name));
configFile.compilerOptions.paths[options.packageJsonName] = [
path.posix.join(relativeTargetPath, 'src', 'public-api')
];
tree.overwrite(tsconfigPath, JSON.stringify(configFile, null, 2));
} else {
context.logger.warn(`No TsConfig file found at ${tsconfigPath}`);
}
});

if (tsconfigBuild && tree.exists(tsconfigBuild)) {
const configFile = tree.readJson(tsconfigBuild) as TsConfigJson;
configFile.compilerOptions!.paths![options.packageJsonName].unshift();
path.posix.join(relativeTargetPath, 'dist');
tree.overwrite(tsconfigBuild, JSON.stringify(configFile, null, 2));
}
};

const ngCliUpdate: Rule = (tree, context) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/* For IDE usage only */
{
"extends": "<%= tsconfigBuildPath %>"
}

0 comments on commit d9c04af

Please sign in to comment.