From 3886b1d4778bdb7307bb3f538f348378b175141b Mon Sep 17 00:00:00 2001 From: Paul Schwind Date: Mon, 8 May 2023 21:22:05 +0200 Subject: [PATCH 1/2] fixes pathsep issue https://github.com/thymikee/jest-preset-angular/issues/2073 --- src/utils/ngcc-jest-processor.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/ngcc-jest-processor.ts b/src/utils/ngcc-jest-processor.ts index 31f3f20350..1a68534192 100644 --- a/src/utils/ngcc-jest-processor.ts +++ b/src/utils/ngcc-jest-processor.ts @@ -5,7 +5,7 @@ import { spawnSync } from 'child_process'; import path from 'path'; -const ANGULAR_COMPILER_CLI_PKG_NAME = `@angular${path.sep}compiler-cli`; +const ANGULAR_COMPILER_CLI_PKG_NAME = '@angular/compiler-cli'; let ngccPath = ''; try { @@ -20,12 +20,12 @@ try { } } function findNodeModulesDirectory(): string { - return ngccPath.substring(0, ngccPath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME)); + return ngccPath.substring(0, ngccPath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace("/", path.sep))); } function findAngularCompilerCliVersion(): string { const path = require.resolve(ANGULAR_COMPILER_CLI_PKG_NAME); - const substringLength = path.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME) + ANGULAR_COMPILER_CLI_PKG_NAME.length; + const substringLength = path.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace("/", path.sep)) + ANGULAR_COMPILER_CLI_PKG_NAME.length; const ngCompilerCliFolder = path.substring(0, substringLength); const ngCompilerCliPackageJson = `${ngCompilerCliFolder}/package.json`; // eslint-disable-next-line @typescript-eslint/no-var-requires From 8fa9241fd092436a67e36866938d8b8bdcfec964 Mon Sep 17 00:00:00 2001 From: Paul Schwind Date: Tue, 9 May 2023 01:01:04 +0200 Subject: [PATCH 2/2] fix: small path fixes --- src/utils/ngcc-jest-processor.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/utils/ngcc-jest-processor.ts b/src/utils/ngcc-jest-processor.ts index 1a68534192..c61a16d5ab 100644 --- a/src/utils/ngcc-jest-processor.ts +++ b/src/utils/ngcc-jest-processor.ts @@ -20,13 +20,14 @@ try { } } function findNodeModulesDirectory(): string { - return ngccPath.substring(0, ngccPath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace("/", path.sep))); + return ngccPath.substring(0, ngccPath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace('/', path.sep))); } function findAngularCompilerCliVersion(): string { - const path = require.resolve(ANGULAR_COMPILER_CLI_PKG_NAME); - const substringLength = path.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace("/", path.sep)) + ANGULAR_COMPILER_CLI_PKG_NAME.length; - const ngCompilerCliFolder = path.substring(0, substringLength); + const packagePath = require.resolve(ANGULAR_COMPILER_CLI_PKG_NAME); + const substringLength = + packagePath.indexOf(ANGULAR_COMPILER_CLI_PKG_NAME.replace('/', path.sep)) + ANGULAR_COMPILER_CLI_PKG_NAME.length; + const ngCompilerCliFolder = packagePath.substring(0, substringLength); const ngCompilerCliPackageJson = `${ngCompilerCliFolder}/package.json`; // eslint-disable-next-line @typescript-eslint/no-var-requires const { version } = require(ngCompilerCliPackageJson);