MCPcopy Create free account
hub / github.com/antonk52/cssmodules-language-server / findImportPath

Function findImportPath

src/utils.ts:38–63  ·  view source on GitHub ↗
(
    fileContent: string,
    importName: string,
    directoryPath: string,
)

Source from the content-addressed store, hash-verified

36 * @example "/users/foo/path/to/project/styles/foo.css"
37 */
38export function findImportPath(
39 fileContent: string,
40 importName: string,
41 directoryPath: string,
42): string {
43 const re = genImportRegExp(importName);
44 const results = re.exec(fileContent);
45
46 if (results == null) {
47 return '';
48 }
49
50 const rawImportedFrom = results[1];
51
52 // "./style.modules.css" or "../../style.modules.css"
53 if (isRelativeFilePath(rawImportedFrom)) {
54 return path.resolve(directoryPath, results[1]);
55 }
56
57 return (
58 resolveAliasedImport({
59 importFilepath: rawImportedFrom,
60 location: directoryPath,
61 }) ?? ''
62 );
63}
64
65export type StringTransformer = (str: string) => string;
66export function getTransformer(

Callers 4

provideHoverMethod · 0.90
provideDefinitionMethod · 0.90
utils.spec.tsFile · 0.90

Calls 3

resolveAliasedImportFunction · 0.90
genImportRegExpFunction · 0.85
isRelativeFilePathFunction · 0.85

Tested by

no test coverage detected