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
gitea/salix-front/pipeline/pr-dev There was a failure building this commit
Details
This commit is contained in:
parent
c89fd0580f
commit
c7f25d6909
|
@ -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);
|
||||
|
|
|
@ -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 };
|
||||
|
|
Loading…
Reference in New Issue