feat: refs #8698 enhance module detection in Cypress tests and resolve import paths using jsconfig
gitea/salix-front/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Alex Moreno 2025-04-07 10:37:45 +02:00
parent c89fd0580f
commit c7f25d6909
2 changed files with 25 additions and 8 deletions

View File

@ -1,6 +1,9 @@
import { execSync } from 'child_process';
import { findImports } from './find-imports.js';
import { getModules } from './get-modules.js';
const E2E_PATH = 'test/cypress/integration';
const FINDED_PATHS = ['src', E2E_PATH];
function getGitDiff(options) {
const TARGET_BRANCH = options[2] || 'dev';
const diff = execSync(`git diff --name-only origin/${TARGET_BRANCH}`, {
@ -10,21 +13,22 @@ function getGitDiff(options) {
}
async function getChangedModules() {
const FINDED_PATHS = ['src', 'test/cypress/integration'];
let changedModules = new Set();
const changes = getGitDiff(process.argv);
for (const change of changes) {
if (!FINDED_PATHS.some((prefix) => change.startsWith(prefix))) return '';
changedModules = new Set([
const changedArray = [
...changedModules,
...new Set(getModules(await findImports(change))),
]);
];
if (change.startsWith(E2E_PATH)) changedArray.push(change);
changedModules = new Set(changedArray);
}
return [...changedModules].join(' ');
}
getChangedModules()
.then((modules) => console.log(modules)) // return
.then((modules) => console.log(modules)) // is return
.catch((e) => {
console.error(e);
process.exit(1);

View File

@ -1,20 +1,33 @@
import path from 'path';
const rootDir = process.cwd();
import config from '../../../../jsconfig.json' with { type: 'json' };
const { paths, baseUrl } = config.compilerOptions;
function resolveImportPath(importPath, fileBase) {
const fileDir = path.dirname(fileBase);
if (!importPath) return null;
importPath = jsConfigPaths(importPath);
const fileDir = path.dirname(fileBase);
if (importPath.startsWith('.') || importPath.startsWith('/')) {
return path.relative(rootDir, path.resolve(fileDir, importPath));
}
return importPath;
}
function toRelative(file) {
return path.relative(rootDir, file);
}
function jsConfigPaths(importPath) {
for (const [aliasPattern, [target]] of Object.entries(paths)) {
const alias = aliasPattern.replace('/*', '');
const targetBase = target.replace('/*', '');
if (importPath.startsWith(alias)) {
const rest = importPath.slice(alias.length);
return path.resolve(baseUrl, targetBase + rest);
}
}
return importPath;
}
export { resolveImportPath, toRelative };