diff --git a/packages/@o3r/workspace/project.json b/packages/@o3r/workspace/project.json index df5f2706cd..03e24252d9 100644 --- a/packages/@o3r/workspace/project.json +++ b/packages/@o3r/workspace/project.json @@ -43,7 +43,11 @@ "executor": "@nx/jest:jest", "options": { "jestConfig": "packages/@o3r/workspace/jest.config.js" - } + }, + "dependsOn": [ + "build", + "^build" + ] }, "test-int": { "executor": "@nx/jest:jest", diff --git a/packages/@o3r/workspace/schematics/application/index.spec.ts b/packages/@o3r/workspace/schematics/application/index.spec.ts index f67ad422eb..a56944e091 100644 --- a/packages/@o3r/workspace/schematics/application/index.spec.ts +++ b/packages/@o3r/workspace/schematics/application/index.spec.ts @@ -29,19 +29,19 @@ const collectionPath = path.join(__dirname, '../../collection.json'); let runner: SchematicTestRunner; describe('generateApplication', () => { - let initalTree: UnitTestTree; + let initialTree: UnitTestTree; beforeEach(() => { - initalTree = new UnitTestTree(Tree.empty()); - initalTree.create('angular.json', fs.readFileSync(path.resolve(__dirname, '..', '..', 'testing', 'mocks', 'angular.mocks.json'))); - initalTree.create('package.json', fs.readFileSync(path.resolve(__dirname, '..', '..', 'testing', 'mocks', 'package.mocks.json'))); + initialTree = new UnitTestTree(Tree.empty()); + initialTree.create('angular.json', fs.readFileSync(path.resolve(__dirname, '..', '..', 'testing', 'mocks', 'angular.mocks.json'))); + initialTree.create('package.json', fs.readFileSync(path.resolve(__dirname, '..', '..', 'testing', 'mocks', 'package.mocks.json'))); runner = new SchematicTestRunner('schematics', collectionPath); const angularPackageJson = require.resolve('@schematics/angular/package.json'); runner.registerCollection('@schematics/angular', path.resolve(path.dirname(angularPackageJson), require(angularPackageJson).schematics)); }); it('should generate an application', async () => { - const tree = await runner.runSchematic('application', { name: 'test', routing: true }, initalTree); + const tree = await runner.runSchematic('application', { name: 'test', routing: true }, initialTree); const mockExternalSchematic = require('@angular-devkit/schematics').externalSchematic as jest.Mock; expect(mockExternalSchematic).toHaveBeenCalledWith('@schematics/angular', 'application', expect.objectContaining({ name: 'test', @@ -55,7 +55,7 @@ describe('generateApplication', () => { }); it('should generate an application with provided path', async () => { - const tree = await runner.runSchematic('application', { name: 'test', path: '/apps' }, initalTree); + const tree = await runner.runSchematic('application', { name: 'test', path: '/apps' }, initialTree); const mockExternalSchematic = require('@angular-devkit/schematics').externalSchematic as jest.Mock; expect(mockExternalSchematic).toHaveBeenCalledWith('@schematics/angular', 'application', expect.objectContaining({ name: 'test', @@ -69,13 +69,13 @@ describe('generateApplication', () => { it('should throw error if NX context is detected', async () => { require('@o3r/schematics').isNxContext.mockReturnValueOnce(true); - await expect(runner.runSchematic('application', { name: 'test' }, initalTree)).rejects.toThrow( + await expect(runner.runSchematic('application', { name: 'test' }, initialTree)).rejects.toThrow( 'NX is not currently supported. Feature tracked via https://github.com/AmadeusITGroup/otter/issues/720'); }); it('should throw error if no workspace configuration is found', async () => { require('@o3r/schematics').getWorkspaceConfig.mockReturnValueOnce(null); - await expect(runner.runSchematic('application', { name: 'test' }, initalTree)).rejects.toThrow( + await expect(runner.runSchematic('application', { name: 'test' }, initialTree)).rejects.toThrow( 'The `path` option is not provided and no workspace configuration file found to define it.'); }); }); diff --git a/packages/@o3r/workspace/schematics/application/index.ts b/packages/@o3r/workspace/schematics/application/index.ts index daa643b217..57cedb54a0 100644 --- a/packages/@o3r/workspace/schematics/application/index.ts +++ b/packages/@o3r/workspace/schematics/application/index.ts @@ -18,6 +18,7 @@ import { createSchematicWithMetricsIfInstalled, type DependencyToAdd, enforceTildeRange, + findConfigFileRelativePath, getPackagesBaseRootFolder, getWorkspaceConfig, isNxContext, @@ -51,10 +52,11 @@ function generateApplicationFn(options: NgGenerateApplicationSchema): Rule { const packageJsonName = strings.dasherize(options.name); const cleanName = packageJsonName.replace(/^@/, '').replaceAll(/\//g, '-'); - const addProjectSpecificFiles = (targetPath: string, rootDependencies: Record) => { + const addProjectSpecificFiles = (targetPath: string, rootDependencies: Record, tsconfigBasePath: string) => { return mergeWith(apply(url('./templates'), [ template({ ...options, + tsconfigBasePath, enforceTildeRange, name: packageJsonName, rootDependencies @@ -109,13 +111,15 @@ function generateApplicationFn(options: NgGenerateApplicationSchema): Rule { } } as const satisfies Record; + const tsconfigBasePath = findConfigFileRelativePath(tree, ['tsconfig.base.json', 'tsconfig.json'], targetPath); + return chain([ externalSchematic>('@schematics/angular', 'application', { ...Object.entries(extendedOptions).reduce((acc, [key, value]) => (angularOptions.includes(key) ? { ...acc, [key]: value } : acc), {}), name: cleanName, projectRoot, style: Style.Scss }), - addProjectSpecificFiles(targetPath, rootDependencies), + addProjectSpecificFiles(targetPath, rootDependencies, tsconfigBasePath), updateProjectTsConfig(targetPath, 'tsconfig.app.json', { updateInputFiles: true }), setupDependencies({ dependencies, diff --git a/packages/@o3r/workspace/schematics/application/templates/tsconfig.json.template b/packages/@o3r/workspace/schematics/application/templates/tsconfig.json.template new file mode 100644 index 0000000000..536763d0e6 --- /dev/null +++ b/packages/@o3r/workspace/schematics/application/templates/tsconfig.json.template @@ -0,0 +1,8 @@ +/* For IDE usage only */ +{ +"extends": "<%= tsconfigBasePath %>", + "references": [ + {"path": "./tsconfig.app.json"}, + {"path": "./tsconfig.spec.json"} + ] +}