From e700452b2460f54c140918bf049be60511dcea7a Mon Sep 17 00:00:00 2001 From: Corinne PAULVE Date: Tue, 17 Dec 2024 12:40:41 +0100 Subject: [PATCH] fix: the tsconfig spec generated for library contains several issues --- .../workspace/schematics/library/index.ts | 25 ++++++++++++++++- .../templates/ng/tsconfig.spec.json.template | 17 ------------ .../new-version/packaged-action/LICENSE.txt | 27 +++++++++++++++++++ 3 files changed, 51 insertions(+), 18 deletions(-) delete mode 100644 packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.spec.json.template diff --git a/packages/@o3r/workspace/schematics/library/index.ts b/packages/@o3r/workspace/schematics/library/index.ts index 1d8935c9f0..074f5dc1ae 100644 --- a/packages/@o3r/workspace/schematics/library/index.ts +++ b/packages/@o3r/workspace/schematics/library/index.ts @@ -4,7 +4,9 @@ import { chain, noop, Rule, + SchematicContext, strings, + Tree, } from '@angular-devkit/schematics'; import { RunSchematicTask, @@ -14,6 +16,7 @@ import { createSchematicWithMetricsIfInstalled, type DependencyToAdd, getPackagesBaseRootFolder, + getTestFramework, getWorkspaceConfig, isNxContext, O3rCliError, @@ -35,6 +38,25 @@ import { NgGenerateModuleSchema, } from './schema'; +const updatePackageJsonForJest = (options: NgGenerateModuleSchema) => + (tree: Tree, context: SchematicContext) => { + if ((options.testingFramework || getTestFramework(getWorkspaceConfig(tree), context)) !== 'jest') { + return; + } + + const workspaceConfig = getWorkspaceConfig(tree); + const workspaceProject = (options.projectName && workspaceConfig?.projects?.[options.projectName]) || undefined; + if (!workspaceProject?.root) { + context.logger.error(`Failed to find a package json for ${options.name}`); + return; + } + const packageJsonPath = path.resolve(workspaceProject.root, 'package.json'); + const packageJsonContent = tree.readJson(packageJsonPath) as PackageJson; + packageJsonContent.script ||= {}; + packageJsonContent.scripts!.test ||= 'jest'; + tree.overwrite(packageJsonPath, JSON.stringify(packageJsonContent, null, 2)); + return tree; + }; /** * Add an Otter compatible module to a monorepo * @param options Schematic options @@ -79,7 +101,8 @@ function generateModuleFn(options: NgGenerateModuleSchema): Rule { context.addTask(new RunSchematicTask('@o3r/core', 'ng-add-create', { name: extendedOptions.name, projectName: extendedOptions.name, path: targetPath }), ids); } }), - options.skipLinter ? noop() : applyEsLintFix() + options.skipLinter ? noop() : applyEsLintFix(), + updatePackageJsonForJest(options) ])(tree, context); }; } diff --git a/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.spec.json.template b/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.spec.json.template deleted file mode 100644 index 4dba869bbf..0000000000 --- a/packages/@o3r/workspace/schematics/library/templates/ng/tsconfig.spec.json.template +++ /dev/null @@ -1,17 +0,0 @@ -{ - "extends": "<%= tsconfigSpecPath %>", - "compilerOptions": { - "composite": true, - "outDir": "test", - "rootDir": ".", - }, - "include": [ - "./src/**/*.spec.ts" - ], - "exclude": [], - "references": [ - { - "path": "./tsconfig.build.composite.json" - } - ] -} diff --git a/tools/github-actions/new-version/packaged-action/LICENSE.txt b/tools/github-actions/new-version/packaged-action/LICENSE.txt index 7ee631dd7c..4ec329636a 100644 --- a/tools/github-actions/new-version/packaged-action/LICENSE.txt +++ b/tools/github-actions/new-version/packaged-action/LICENSE.txt @@ -94,6 +94,33 @@ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. @o3r/new-version +Copyright Amadeus SAS + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this +list of conditions and the following disclaimer. + +2. Redistributions in binary form must reproduce the above copyright notice, +this list of conditions and the following disclaimer in the documentation and/or +other materials provided with the distribution. + +3. Neither the name of the copyright holder nor the names of its contributors +may be used to endorse or promote products derived from this software without +specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + @octokit/auth-token MIT