Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# https://editorconfig.org

root = true

[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
insert_final_newline = false
trim_trailing_whitespace = false
38 changes: 38 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# 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
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:

runs-on: ${{ matrix.os }}

strategy:
matrix:
os: [macos-latest, ubuntu-latest]
node-version: [14.x, 16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm i
- run: npm run build --if-present
- run: npm run coverage
- if: ${{ matrix.node-version == '14.x' && matrix.os == 'ubuntu-latest' }}
name: Upload coverage to Codecov
uses: codecov/codecov-action@v2
with:
token: ${{ secrets.CODECOV_TOKEN }}
directory: ./coverage
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ dist

# TernJS port file
.tern-port

# pnpm lockfile
pnpm-lock.yaml

# output
libs
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,13 @@
# less-plugin-module-resolver
# less-plugin-module-resolver


## Usage

```js
const less = require('less');
const ModuleResolverPlugin = require('less-plugin-module-resolver');

less.render('input', {
plugins: [new ModuleResolverPlugin()],
});
```
Empty file added lib/index.d.ts
Empty file.
10 changes: 10 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = class LessPluginModuleResolver {
options;
constructor(options) {
this.options = options;
}
install(less, pluginManager) {
// noop yet
}
minVersion = [2, 1, 1];
};
31 changes: 31 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "less-plugin-module-resolver",
"version": "0.0.1",
"description": "",
"main": "index.js",
"scripts": {
"compile": "tsc",
"test": "vitest",
"coverage": "vitest run --coverage"
},
"repository": {
"type": "git",
"url": "git+https://github.com/vagusX/less-plugin-module-resolver.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"bugs": {
"url": "https://github.com/vagusX/less-plugin-module-resolver/issues"
},
"homepage": "https://github.com/vagusX/less-plugin-module-resolver#readme",
"devDependencies": {
"@less/test-data": "^4.1.0",
"@types/less": "^3.0.3",
"@types/node": "^17.0.31",
"c8": "^7.11.2",
"less": "^4.1.2",
"typescript": "^4.6.4",
"vitest": "^0.10.2"
}
}
26 changes: 26 additions & 0 deletions src/alias-file-manager.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function getAliasFileManager(less: LessStatic) {

return class AliasFileManager extends less.FileManager implements Less.FileManager {
constructor(private readonly options: any) {
super();
}

supports(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): boolean {
}

supportsSync(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): boolean {
}

loadFile(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): Promise<Less.FileLoadResult> {

}

loadFileSync(filename: string, currentDirectory: string, options: Less.LoadFileOptions, environment: Less.Environment): Less.FileLoadResult | Less.FileLoadError {

}

private resolve(filename: string, currentDirectory: string) {

}
}
}
15 changes: 15 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { getAliasFileManager } from "./alias-file-manager";

export interface LessPluginModuleResolverOptions {}

export class LessPluginModuleResolver implements Less.Plugin {
constructor(private readonly options: LessPluginModuleResolverOptions) {}

public install(less: LessStatic, pluginManager: Less.PluginManager): void {
// noop yet
const AliasFileManager = getAliasFileManager(less);
pluginManager.addFileManager(new AliasFileManager(this.options));
}

public minVersion: [number, number, number] = [2, 1, 1];
}
15 changes: 15 additions & 0 deletions test/css/module-resolver/test.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.test_file {
color: black;
}
.test_file_css {
color: black;
}
.test_deeper_file {
color: black;
}
.test_index {
color: black;
}
.test_deeper_index {
color: black;
}
19 changes: 19 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { vi, expect, describe, it } from 'vitest';
import less from 'less';

import { LessPluginModuleResolver, LessPluginModuleResolverOptions } from '../src';

function lessc(lessContent: string, pluginOptions: LessPluginModuleResolverOptions = {}) {
return less.render(lessContent, {
plugins: [new LessPluginModuleResolver(pluginOptions)],
});
}

describe('test cases', () => {
it('basic', async () => {
const { css } = await lessc(`
@white: #fff;
`);
expect(css).toBe('');
});
});
5 changes: 5 additions & 0 deletions test/less/module-resolver/test.less
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@import "npm://npm-import-plugin-test/file";
@import (less) "npm://npm-import-plugin-test/file.css";
@import "npm://npm-import-plugin-test/deeper/file";
@import "npm://npm-import-plugin-test";
@import "npm://npm-import-plugin-test/deeper/";
67 changes: 67 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"compilerOptions": {
/* Basic Options */
"target": "esnext", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
/* Specify library files to be included in the compilation. */
"lib": [
"ESNext"
],
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
"declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": false, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "lib", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
"resolveJsonModule": true,
/* Strict Type-Checking Options */
"strict": false, /* Enable all strict type-checking options. */
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
"skipLibCheck": true,
/* Additional Checks */
"noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
"moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
"allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
/* Advanced Options */
// "declarationDir": "lib" /* Output directory for generated declaration files. */
},
"include": [
"src"
],
"exclude": [
"node_modules*"
]
}