/
dummy-resolver.ts
38 lines (33 loc) · 1.48 KB
/
dummy-resolver.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import path from 'node:path';
import type { ImportResolution, YaniceImportBoundariesImportResolver } from '@yanice/import-boundaries';
function absolutePath(relativePathToYaniceJson: string): string {
const pathToRepoRoot: string = require.resolve('yanice').replace('/dist/index.js', '');
const pathToIntegrationTestDirectory: string = 'integration-tests/test-project';
return path.join(pathToRepoRoot, pathToIntegrationTestDirectory, relativePathToYaniceJson);
}
const dummyResolver: YaniceImportBoundariesImportResolver = {
name: 'dummy-resolver',
getFileImportMap: async (absoluteFilePath: string, _fileContent: string): Promise<ImportResolution | null> => {
const absolutePathToProjectA: string = absolutePath('project-A/empty.txt');
if (absoluteFilePath !== absolutePathToProjectA) {
return Promise.resolve(null);
}
const result: ImportResolution = {
unknownImports: [],
resolvedImports: [
{
resolvedAbsoluteFilePath: absolutePath('project-B/empty.txt'),
parsedImportStatement: {
type: 'relative',
raw: 'import stuff from "somewhere"',
fromClause: 'somewhere'
}
}
],
resolvedPackageImports: [],
createdBy: 'dummy-resolver'
};
return Promise.resolve(result);
}
};
module.exports = dummyResolver;