Skip to content

Commit fff1a4f

Browse files
vagusXvagusX
andauthored
feat: add vitest (#1)
Co-authored-by: vagusX <vagusx@vagusxdeMacBook-Pro.local>
1 parent 1020917 commit fff1a4f

File tree

13 files changed

+260
-1
lines changed

13 files changed

+260
-1
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://editorconfig.org
2+
3+
root = true
4+
5+
[*]
6+
charset = utf-8
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
13+
[*.md]
14+
insert_final_newline = false
15+
trim_trailing_whitespace = false

.github/workflows/node.js.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
2+
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3+
4+
name: Node.js CI
5+
6+
on:
7+
push:
8+
branches: [ main ]
9+
pull_request:
10+
branches: [ main ]
11+
12+
jobs:
13+
test:
14+
15+
runs-on: ${{ matrix.os }}
16+
17+
strategy:
18+
matrix:
19+
os: [macos-latest, ubuntu-latest]
20+
node-version: [14.x, 16.x]
21+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
22+
23+
steps:
24+
- uses: actions/checkout@v3
25+
- name: Use Node.js ${{ matrix.node-version }}
26+
uses: actions/setup-node@v1
27+
with:
28+
node-version: ${{ matrix.node-version }}
29+
cache: 'npm'
30+
- run: npm i
31+
- run: npm run build --if-present
32+
- run: npm run coverage
33+
- if: ${{ matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest' }}
34+
name: Upload coverage to Codecov
35+
uses: codecov/codecov-action@v2
36+
with:
37+
token: ${{ secrets.CODECOV_TOKEN }}
38+
directory: ./coverage

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,3 +102,9 @@ dist
102102

103103
# TernJS port file
104104
.tern-port
105+
106+
# pnpm lockfile
107+
pnpm-lock.yaml
108+
109+
# output
110+
libs

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,13 @@
1-
# less-plugin-module-resolver
1+
# less-plugin-module-resolver
2+
3+
4+
## Usage
5+
6+
```js
7+
const less = require('less');
8+
const ModuleResolverPlugin = require('less-plugin-module-resolver');
9+
10+
less.render('input', {
11+
plugins: [new ModuleResolverPlugin()],
12+
});
13+
```

lib/index.d.ts

Whitespace-only changes.

lib/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module.exports = class LessPluginModuleResolver {
2+
options;
3+
constructor(options) {
4+
this.options = options;
5+
}
6+
install(less, pluginManager) {
7+
// noop yet
8+
}
9+
minVersion = [2, 1, 1];
10+
};

package.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "less-plugin-module-resolver",
3+
"version": "0.0.1",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"compile": "tsc",
8+
"test": "vitest",
9+
"coverage": "vitest run --coverage"
10+
},
11+
"repository": {
12+
"type": "git",
13+
"url": "git+https://github.com/vagusX/less-plugin-module-resolver.git"
14+
},
15+
"keywords": [],
16+
"author": "",
17+
"license": "ISC",
18+
"bugs": {
19+
"url": "https://github.com/vagusX/less-plugin-module-resolver/issues"
20+
},
21+
"homepage": "https://github.com/vagusX/less-plugin-module-resolver#readme",
22+
"devDependencies": {
23+
"@less/test-data": "^4.1.0",
24+
"@types/less": "^3.0.3",
25+
"@types/node": "^17.0.31",
26+
"c8": "^7.11.2",
27+
"less": "^4.1.2",
28+
"typescript": "^4.6.4",
29+
"vitest": "^0.10.2"
30+
}
31+
}

src/alias-file-manager.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export function getAliasFileManager(less: LessStatic) {
2+
3+
return class AliasFileManager extends less.FileManager implements Less.FileManager {
4+
constructor(private readonly options: any) {
5+
super();
6+
}
7+
8+
supports(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): boolean {
9+
}
10+
11+
supportsSync(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): boolean {
12+
}
13+
14+
loadFile(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): Promise<Less.FileLoadResult> {
15+
16+
}
17+
18+
loadFileSync(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): Less.FileLoadResult | Less.FileLoadError {
19+
20+
}
21+
22+
private resolve(filename: string, currentDirectory: string) {
23+
24+
}
25+
}
26+
}

src/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { getAliasFileManager } from "./alias-file-manager";
2+
3+
export interface LessPluginModuleResolverOptions {}
4+
5+
export class LessPluginModuleResolver implements Less.Plugin {
6+
constructor(private readonly options: LessPluginModuleResolverOptions) {}
7+
8+
public install(less: LessStatic, pluginManager: Less.PluginManager): void {
9+
// noop yet
10+
const AliasFileManager = getAliasFileManager(less);
11+
pluginManager.addFileManager(new AliasFileManager(this.options));
12+
}
13+
14+
public minVersion: [number, number, number] = [2, 1, 1];
15+
}

test/css/module-resolver/test.css

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
.test_file {
2+
color: black;
3+
}
4+
.test_file_css {
5+
color: black;
6+
}
7+
.test_deeper_file {
8+
color: black;
9+
}
10+
.test_index {
11+
color: black;
12+
}
13+
.test_deeper_index {
14+
color: black;
15+
}

0 commit comments

Comments
 (0)