cssmodules-language-server
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -6,2 +6,7 @@ import { Position } from 'vscode-languageserver-protocol'; | ||
export declare function genImportRegExp(importName: string): RegExp; | ||
/** | ||
* Returns absolute file path to a file where css modules is from or an empty string | ||
* | ||
* @example "/users/foo/path/to/project/styles/foo.css" | ||
*/ | ||
export declare function findImportPath(fileContent: string, importName: string, directoryPath: string): string; | ||
@@ -8,0 +13,0 @@ export declare type StringTransformer = (str: string) => string; |
@@ -22,2 +22,3 @@ "use strict"; | ||
const postcss_1 = __importDefault(require("postcss")); | ||
const resolveAliasedImport_1 = require("./utils/resolveAliasedImport"); | ||
function getCurrentDirFromUri(uri) { | ||
@@ -35,11 +36,26 @@ return path_1.default.dirname(uri).replace(/^file:\/\//, ''); | ||
exports.genImportRegExp = genImportRegExp; | ||
function isRelativeFilePath(str) { | ||
return str.startsWith('../') || str.startsWith('./'); | ||
} | ||
/** | ||
* Returns absolute file path to a file where css modules is from or an empty string | ||
* | ||
* @example "/users/foo/path/to/project/styles/foo.css" | ||
*/ | ||
function findImportPath(fileContent, importName, directoryPath) { | ||
var _a; | ||
const re = genImportRegExp(importName); | ||
const results = re.exec(fileContent); | ||
if (!!results && results.length > 0) { | ||
if (results == null) { | ||
return ''; | ||
} | ||
const rawImportedFrom = results[1]; | ||
// "./style.modules.css" or "../../style.modules.css" | ||
if (isRelativeFilePath(rawImportedFrom)) { | ||
return path_1.default.resolve(directoryPath, results[1]); | ||
} | ||
else { | ||
return ''; | ||
} | ||
return ((_a = (0, resolveAliasedImport_1.resolveAliasedImport)({ | ||
importFilepath: rawImportedFrom, | ||
location: directoryPath, | ||
})) !== null && _a !== void 0 ? _a : ''); | ||
} | ||
@@ -110,3 +126,3 @@ exports.findImportPath = findImportPath; | ||
.join('\n\t'); | ||
fs_1.default.writeFileSync('/tmp/log-cssmodules', `\n[${timestamp}] ${msg}`); | ||
fs_1.default.appendFileSync('/tmp/log-cssmodules', `\n[${timestamp}] ${msg}\n`); | ||
}; | ||
@@ -113,0 +129,0 @@ exports.log = log; |
{ | ||
"name": "cssmodules-language-server", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "language server for cssmodules", | ||
@@ -46,2 +46,3 @@ "bin": { | ||
"dependencies": { | ||
"lilconfig": "^2.0.4", | ||
"lodash.camelcase": "^4.3.0", | ||
@@ -48,0 +49,0 @@ "postcss": "^8.1.10", |
37421
726
10
+ Addedlilconfig@^2.0.4
+ Addedlilconfig@2.1.0(transitive)