diff --git a/packages/@o3r/workspace/schematics/library/rules/rules.ng.ts b/packages/@o3r/workspace/schematics/library/rules/rules.ng.ts index 6384dd4447..44e4c549d1 100644 --- a/packages/@o3r/workspace/schematics/library/rules/rules.ng.ts +++ b/packages/@o3r/workspace/schematics/library/rules/rules.ng.ts @@ -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) => { diff --git a/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.lib.prod.json.template b/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.lib.prod.json.template new file mode 100644 index 0000000000..e311f097a8 --- /dev/null +++ b/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.lib.prod.json.template @@ -0,0 +1,4 @@ +/* For IDE usage only */ +{ + "extends": "<%= tsconfigBuildPath %>" +}