From b6b391155204120f31dc5538fee554c93b10d001 Mon Sep 17 00:00:00 2001 From: Paul Schwind Date: Tue, 9 May 2023 10:20:19 +0200 Subject: [PATCH] fix: file separator issue on Windows causing error in `ngcc-jest-processor` (#2079) --- src/utils/ngcc-jest-processor.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/utils/ngcc-jest-processor.ts b/src/utils/ngcc-jest-processor.ts index 31f3f20350..c61a16d5ab 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,13 +20,14 @@ 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 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);