@parcel/transformer-less 2.16.4 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/LessTransformer.js +104 -179
- package/package.json +13 -8
- package/LICENSE +0 -21
- package/lib/loadConfig.js +0 -37
- package/src/LessTransformer.js +0 -175
- package/src/loadConfig.js +0 -38
package/lib/LessTransformer.js
CHANGED
|
@@ -1,188 +1,113 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _plugin() {
|
|
15
|
-
const data = require("@parcel/plugin");
|
|
16
|
-
_plugin = function () {
|
|
17
|
-
return data;
|
|
18
|
-
};
|
|
19
|
-
return data;
|
|
20
|
-
}
|
|
21
|
-
function _sourceMap() {
|
|
22
|
-
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
23
|
-
_sourceMap = function () {
|
|
24
|
-
return data;
|
|
25
|
-
};
|
|
26
|
-
return data;
|
|
27
|
-
}
|
|
28
|
-
function _less() {
|
|
29
|
-
const data = _interopRequireDefault(require("less"));
|
|
30
|
-
_less = function () {
|
|
31
|
-
return data;
|
|
32
|
-
};
|
|
33
|
-
return data;
|
|
34
|
-
}
|
|
35
|
-
var _loadConfig = require("./loadConfig");
|
|
36
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { Transformer } from '@parcel/plugin';
|
|
3
|
+
import less from 'less';
|
|
4
|
+
import fs from 'fs';
|
|
37
5
|
// E.g: ~library/file.less
|
|
38
6
|
const WEBPACK_ALIAS_RE = /^~[^/]/;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
resolve
|
|
70
|
-
})];
|
|
71
|
-
result = await _less().default.render(code, lessConfig);
|
|
72
|
-
} catch (err) {
|
|
73
|
-
// For the error reporter
|
|
74
|
-
err.fileName = err.filename;
|
|
75
|
-
err.loc = {
|
|
76
|
-
line: err.line,
|
|
77
|
-
column: err.column
|
|
78
|
-
};
|
|
79
|
-
throw err;
|
|
80
|
-
}
|
|
81
|
-
if (result.map != null) {
|
|
82
|
-
let map = new (_sourceMap().default)(options.projectRoot);
|
|
83
|
-
let rawMap = JSON.parse(result.map);
|
|
84
|
-
map.addVLQMap({
|
|
85
|
-
...rawMap,
|
|
86
|
-
sources: rawMap.sources.map(s => _path().default.relative(options.projectRoot, s))
|
|
87
|
-
});
|
|
88
|
-
asset.setMap(map);
|
|
89
|
-
}
|
|
90
|
-
asset.setCode(result.css);
|
|
91
|
-
return [asset];
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
function urlPlugin({
|
|
95
|
-
asset
|
|
96
|
-
}) {
|
|
97
|
-
return {
|
|
98
|
-
install(less, pluginManager) {
|
|
99
|
-
// This is a hack; no such interface exists, even conceptually, in Less.
|
|
100
|
-
|
|
101
|
-
const visitor = new less.visitors.Visitor({
|
|
102
|
-
visitUrl(node) {
|
|
103
|
-
const valueNode = node.value;
|
|
104
|
-
const stringValue = valueNode.value;
|
|
105
|
-
if (!stringValue.startsWith('#') // IE's `behavior: url(#default#VML)`)
|
|
106
|
-
) {
|
|
107
|
-
valueNode.value = asset.addURLDependency(stringValue, {});
|
|
108
|
-
}
|
|
109
|
-
return node;
|
|
7
|
+
export default new Transformer({
|
|
8
|
+
async transform ({ asset, options, config, resolve }) {
|
|
9
|
+
asset.type = 'css';
|
|
10
|
+
let code = asset.getCode();
|
|
11
|
+
let result;
|
|
12
|
+
try {
|
|
13
|
+
let lessConfig = {};
|
|
14
|
+
if (config?.paths) {
|
|
15
|
+
lessConfig.paths = config.paths.map((p)=>path.join(options.projectRoot, p));
|
|
16
|
+
}
|
|
17
|
+
if (asset.target.sourceMap) {
|
|
18
|
+
lessConfig.sourceMap = {};
|
|
19
|
+
}
|
|
20
|
+
lessConfig.filename = asset.filePath;
|
|
21
|
+
lessConfig.relativeUrls = true;
|
|
22
|
+
lessConfig.plugins = [
|
|
23
|
+
resolvePathPlugin({
|
|
24
|
+
asset,
|
|
25
|
+
resolve
|
|
26
|
+
})
|
|
27
|
+
];
|
|
28
|
+
result = await less.render(code, lessConfig);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
// For the error reporter
|
|
31
|
+
err.fileName = err.filename;
|
|
32
|
+
err.loc = {
|
|
33
|
+
line: err.line,
|
|
34
|
+
column: err.column
|
|
35
|
+
};
|
|
36
|
+
throw err;
|
|
110
37
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// $FlowFixMe[method-unbinding]
|
|
114
|
-
visitor.run = visitor.visit;
|
|
115
|
-
pluginManager.addVisitor(visitor);
|
|
38
|
+
asset.setCode(result.css, result.map ?? null);
|
|
116
39
|
}
|
|
117
|
-
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
install(less, pluginManager) {
|
|
125
|
-
class LessFileManager extends less.FileManager {
|
|
126
|
-
supports() {
|
|
127
|
-
return true;
|
|
128
|
-
}
|
|
129
|
-
supportsSync() {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
async loadFile(rawFilename, currentDirectory, options) {
|
|
133
|
-
let filename = rawFilename;
|
|
134
|
-
if (WEBPACK_ALIAS_RE.test(filename)) {
|
|
135
|
-
let correctPath = filename.replace(/^~/, '');
|
|
136
|
-
throw new Error(`The @import path "${filename}" is using webpack specific syntax, which isn't supported by Parcel.\n\nTo @import files from node_modules, use "${correctPath}"`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
// Based on https://github.com/less/less.js/blob/master/packages/less/src/less-node/file-manager.js
|
|
140
|
-
let isAbsoluteFilename = this.isPathAbsolute(filename);
|
|
141
|
-
let paths = isAbsoluteFilename ? [''] : [currentDirectory];
|
|
142
|
-
if (options.paths) {
|
|
143
|
-
paths.push(...options.paths);
|
|
144
|
-
}
|
|
145
|
-
let prefixes = options.prefixes || [''];
|
|
146
|
-
let fileParts = this.extractUrlParts(filename);
|
|
147
|
-
let filePath;
|
|
148
|
-
let contents;
|
|
149
|
-
if (filename[0] !== '~') {
|
|
150
|
-
outer: for (let p of paths) {
|
|
151
|
-
for (let prefix of prefixes) {
|
|
152
|
-
filePath = fileParts.rawPath + prefix + fileParts.filename;
|
|
153
|
-
if (p) {
|
|
154
|
-
filePath = _path().default.join(p, filePath);
|
|
40
|
+
});
|
|
41
|
+
function resolvePathPlugin({ asset, resolve }) {
|
|
42
|
+
return {
|
|
43
|
+
install (less, pluginManager) {
|
|
44
|
+
class LessFileManager extends less.FileManager {
|
|
45
|
+
supports() {
|
|
46
|
+
return true;
|
|
155
47
|
}
|
|
156
|
-
|
|
157
|
-
|
|
48
|
+
supportsSync() {
|
|
49
|
+
return false;
|
|
158
50
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
51
|
+
async loadFile(rawFilename, currentDirectory, options) {
|
|
52
|
+
let filename = rawFilename;
|
|
53
|
+
if (WEBPACK_ALIAS_RE.test(filename)) {
|
|
54
|
+
let correctPath = filename.replace(/^~/, '');
|
|
55
|
+
throw new Error(`The @import path "${filename}" is using webpack specific syntax, which isn't supported by Parcel.\n\nTo @import files from node_modules, use "${correctPath}"`);
|
|
56
|
+
}
|
|
57
|
+
// Based on https://github.com/less/less.js/blob/master/packages/less/src/less-node/file-manager.js
|
|
58
|
+
let isAbsoluteFilename = this.isPathAbsolute(filename);
|
|
59
|
+
let paths = isAbsoluteFilename ? [
|
|
60
|
+
''
|
|
61
|
+
] : [
|
|
62
|
+
currentDirectory
|
|
63
|
+
];
|
|
64
|
+
if (options.paths) {
|
|
65
|
+
paths.push(...options.paths);
|
|
66
|
+
}
|
|
67
|
+
let prefixes = options.prefixes || [
|
|
68
|
+
''
|
|
69
|
+
];
|
|
70
|
+
let fileParts = this.extractUrlParts(filename);
|
|
71
|
+
let filePath = filename;
|
|
72
|
+
let contents;
|
|
73
|
+
if (filename[0] !== '~') {
|
|
74
|
+
outer: for (let p of paths){
|
|
75
|
+
for (let prefix of prefixes){
|
|
76
|
+
filePath = fileParts.rawPath + prefix + fileParts.filename;
|
|
77
|
+
if (p) {
|
|
78
|
+
filePath = path.join(p, filePath);
|
|
79
|
+
}
|
|
80
|
+
if (options.ext) {
|
|
81
|
+
filePath = this.tryAppendExtension(filePath, options.ext);
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
contents = fs.readFileSync(filePath, 'utf8');
|
|
85
|
+
break outer;
|
|
86
|
+
} catch {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!contents) {
|
|
91
|
+
let resolved = await resolve(asset.filePath, filename, {
|
|
92
|
+
importType: 'stylesheet',
|
|
93
|
+
packageConditions: [
|
|
94
|
+
'less',
|
|
95
|
+
'style'
|
|
96
|
+
]
|
|
97
|
+
});
|
|
98
|
+
if (resolved?.filePath == null) {
|
|
99
|
+
throw new Error(`Could not resolve '${filename}' to a file`);
|
|
100
|
+
}
|
|
101
|
+
filePath = resolved.filePath;
|
|
102
|
+
contents = fs.readFileSync(filePath, 'utf8');
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
contents,
|
|
106
|
+
filename: filePath
|
|
107
|
+
};
|
|
166
108
|
}
|
|
167
|
-
}
|
|
168
109
|
}
|
|
169
|
-
|
|
170
|
-
if (!contents) {
|
|
171
|
-
filePath = await resolve(asset.filePath, filename, {
|
|
172
|
-
packageConditions: ['less', 'style']
|
|
173
|
-
});
|
|
174
|
-
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
175
|
-
}
|
|
176
|
-
if (filePath) {
|
|
177
|
-
asset.invalidateOnFileChange(filePath);
|
|
178
|
-
}
|
|
179
|
-
return {
|
|
180
|
-
contents,
|
|
181
|
-
filename: filePath
|
|
182
|
-
};
|
|
110
|
+
pluginManager.addFileManager(new LessFileManager());
|
|
183
111
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
}
|
|
112
|
+
};
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-less",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0-alpha.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -13,16 +13,21 @@
|
|
|
13
13
|
"type": "git",
|
|
14
14
|
"url": "https://github.com/parcel-bundler/parcel.git"
|
|
15
15
|
},
|
|
16
|
+
"type": "module",
|
|
16
17
|
"main": "lib/LessTransformer.js",
|
|
17
|
-
"
|
|
18
|
+
"files": [
|
|
19
|
+
"lib"
|
|
20
|
+
],
|
|
21
|
+
"source": "src/LessTransformer.ts",
|
|
18
22
|
"engines": {
|
|
19
23
|
"node": ">= 16.0.0",
|
|
20
|
-
"parcel": "^
|
|
24
|
+
"parcel": "^3.0.0-0"
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "
|
|
24
|
-
"
|
|
25
|
-
"less": "^4.3.0"
|
|
27
|
+
"@parcel/plugin": "^3.0.0-alpha.1",
|
|
28
|
+
"less": "^4.9.0"
|
|
26
29
|
},
|
|
27
|
-
"
|
|
28
|
-
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@types/less": "^3.0.8"
|
|
32
|
+
}
|
|
33
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017-present Devon Govett
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
package/lib/loadConfig.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.load = load;
|
|
7
|
-
function _path() {
|
|
8
|
-
const data = _interopRequireDefault(require("path"));
|
|
9
|
-
_path = function () {
|
|
10
|
-
return data;
|
|
11
|
-
};
|
|
12
|
-
return data;
|
|
13
|
-
}
|
|
14
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
15
|
-
async function load({
|
|
16
|
-
config
|
|
17
|
-
}) {
|
|
18
|
-
let configFile = await config.getConfig(['.lessrc', '.lessrc.js', '.lessrc.cjs', '.lessrc.mjs'], {
|
|
19
|
-
packageKey: 'less'
|
|
20
|
-
});
|
|
21
|
-
let configContents = {};
|
|
22
|
-
if (configFile != null) {
|
|
23
|
-
configContents = configFile.contents;
|
|
24
|
-
|
|
25
|
-
// Resolve relative paths from config file
|
|
26
|
-
if (configContents.paths) {
|
|
27
|
-
configContents.paths = configContents.paths.map(p => _path().default.resolve(_path().default.dirname(configFile.filePath), p));
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Rewrites urls to be relative to the provided filename
|
|
32
|
-
configContents.rewriteUrls = 'all';
|
|
33
|
-
configContents.plugins = configContents.plugins || [];
|
|
34
|
-
return {
|
|
35
|
-
config: configContents
|
|
36
|
-
};
|
|
37
|
-
}
|
package/src/LessTransformer.js
DELETED
|
@@ -1,175 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import {typeof default as Less} from 'less';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
import {Transformer} from '@parcel/plugin';
|
|
5
|
-
import SourceMap from '@parcel/source-map';
|
|
6
|
-
import less from 'less';
|
|
7
|
-
|
|
8
|
-
import {load} from './loadConfig';
|
|
9
|
-
|
|
10
|
-
// E.g: ~library/file.less
|
|
11
|
-
const WEBPACK_ALIAS_RE = /^~[^/]/;
|
|
12
|
-
|
|
13
|
-
type LessConfig = {
|
|
14
|
-
sourceMap: any,
|
|
15
|
-
filename: string,
|
|
16
|
-
plugins: Array<any>,
|
|
17
|
-
...
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export default (new Transformer({
|
|
21
|
-
loadConfig({config}) {
|
|
22
|
-
return load({config});
|
|
23
|
-
},
|
|
24
|
-
|
|
25
|
-
async transform({asset, options, config, resolve}) {
|
|
26
|
-
asset.type = 'css';
|
|
27
|
-
asset.meta.hasDependencies = false;
|
|
28
|
-
|
|
29
|
-
let code = await asset.getCode();
|
|
30
|
-
let result;
|
|
31
|
-
try {
|
|
32
|
-
let lessConfig: LessConfig = config ? {...config.config} : {};
|
|
33
|
-
|
|
34
|
-
if (asset.env.sourceMap) {
|
|
35
|
-
lessConfig.sourceMap = {};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
lessConfig.filename = asset.filePath;
|
|
39
|
-
lessConfig.plugins = [
|
|
40
|
-
...(lessConfig.plugins || []),
|
|
41
|
-
urlPlugin({asset}),
|
|
42
|
-
resolvePathPlugin({asset, resolve}),
|
|
43
|
-
];
|
|
44
|
-
|
|
45
|
-
result = await less.render(code, lessConfig);
|
|
46
|
-
} catch (err) {
|
|
47
|
-
// For the error reporter
|
|
48
|
-
err.fileName = err.filename;
|
|
49
|
-
err.loc = {
|
|
50
|
-
line: err.line,
|
|
51
|
-
column: err.column,
|
|
52
|
-
};
|
|
53
|
-
throw err;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (result.map != null) {
|
|
57
|
-
let map = new SourceMap(options.projectRoot);
|
|
58
|
-
let rawMap = JSON.parse(result.map);
|
|
59
|
-
map.addVLQMap({
|
|
60
|
-
...rawMap,
|
|
61
|
-
sources: rawMap.sources.map(s => path.relative(options.projectRoot, s)),
|
|
62
|
-
});
|
|
63
|
-
asset.setMap(map);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
asset.setCode(result.css);
|
|
67
|
-
|
|
68
|
-
return [asset];
|
|
69
|
-
},
|
|
70
|
-
}): Transformer);
|
|
71
|
-
|
|
72
|
-
function urlPlugin({asset}) {
|
|
73
|
-
return {
|
|
74
|
-
install(less: Less, pluginManager) {
|
|
75
|
-
// This is a hack; no such interface exists, even conceptually, in Less.
|
|
76
|
-
type LessNodeWithValue = less.tree.Node & {value: any, ...};
|
|
77
|
-
|
|
78
|
-
const visitor = new less.visitors.Visitor({
|
|
79
|
-
visitUrl(node) {
|
|
80
|
-
const valueNode = ((node.value: any): LessNodeWithValue);
|
|
81
|
-
const stringValue = (valueNode.value: string);
|
|
82
|
-
if (
|
|
83
|
-
!stringValue.startsWith('#') // IE's `behavior: url(#default#VML)`)
|
|
84
|
-
) {
|
|
85
|
-
valueNode.value = asset.addURLDependency(stringValue, {});
|
|
86
|
-
}
|
|
87
|
-
return node;
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
|
|
91
|
-
// $FlowFixMe[method-unbinding]
|
|
92
|
-
visitor.run = visitor.visit;
|
|
93
|
-
pluginManager.addVisitor(visitor);
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function resolvePathPlugin({asset, resolve}) {
|
|
99
|
-
return {
|
|
100
|
-
install(less, pluginManager) {
|
|
101
|
-
class LessFileManager extends less.FileManager {
|
|
102
|
-
supports() {
|
|
103
|
-
return true;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
supportsSync() {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async loadFile(rawFilename, currentDirectory, options) {
|
|
111
|
-
let filename = rawFilename;
|
|
112
|
-
|
|
113
|
-
if (WEBPACK_ALIAS_RE.test(filename)) {
|
|
114
|
-
let correctPath = filename.replace(/^~/, '');
|
|
115
|
-
throw new Error(
|
|
116
|
-
`The @import path "${filename}" is using webpack specific syntax, which isn't supported by Parcel.\n\nTo @import files from node_modules, use "${correctPath}"`,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// Based on https://github.com/less/less.js/blob/master/packages/less/src/less-node/file-manager.js
|
|
121
|
-
let isAbsoluteFilename = this.isPathAbsolute(filename);
|
|
122
|
-
let paths = isAbsoluteFilename ? [''] : [currentDirectory];
|
|
123
|
-
if (options.paths) {
|
|
124
|
-
paths.push(...options.paths);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
let prefixes = options.prefixes || [''];
|
|
128
|
-
let fileParts = this.extractUrlParts(filename);
|
|
129
|
-
let filePath;
|
|
130
|
-
let contents;
|
|
131
|
-
|
|
132
|
-
if (filename[0] !== '~') {
|
|
133
|
-
outer: for (let p of paths) {
|
|
134
|
-
for (let prefix of prefixes) {
|
|
135
|
-
filePath = fileParts.rawPath + prefix + fileParts.filename;
|
|
136
|
-
if (p) {
|
|
137
|
-
filePath = path.join(p, filePath);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (options.ext) {
|
|
141
|
-
filePath = this.tryAppendExtension(filePath, options.ext);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
try {
|
|
145
|
-
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
146
|
-
break outer;
|
|
147
|
-
} catch (err) {
|
|
148
|
-
asset.invalidateOnFileCreate({filePath});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
if (!contents) {
|
|
155
|
-
filePath = await resolve(asset.filePath, filename, {
|
|
156
|
-
packageConditions: ['less', 'style'],
|
|
157
|
-
});
|
|
158
|
-
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (filePath) {
|
|
162
|
-
asset.invalidateOnFileChange(filePath);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return {
|
|
166
|
-
contents,
|
|
167
|
-
filename: filePath,
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
pluginManager.addFileManager(new LessFileManager());
|
|
173
|
-
},
|
|
174
|
-
};
|
|
175
|
-
}
|
package/src/loadConfig.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
import type {Config} from '@parcel/types';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
type ConfigResult = {|
|
|
6
|
-
config: any,
|
|
7
|
-
|};
|
|
8
|
-
|
|
9
|
-
export async function load({
|
|
10
|
-
config,
|
|
11
|
-
}: {|
|
|
12
|
-
config: Config,
|
|
13
|
-
|}): Promise<ConfigResult> {
|
|
14
|
-
let configFile = await config.getConfig(
|
|
15
|
-
['.lessrc', '.lessrc.js', '.lessrc.cjs', '.lessrc.mjs'],
|
|
16
|
-
{
|
|
17
|
-
packageKey: 'less',
|
|
18
|
-
},
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
let configContents = {};
|
|
22
|
-
if (configFile != null) {
|
|
23
|
-
configContents = configFile.contents;
|
|
24
|
-
|
|
25
|
-
// Resolve relative paths from config file
|
|
26
|
-
if (configContents.paths) {
|
|
27
|
-
configContents.paths = configContents.paths.map(p =>
|
|
28
|
-
path.resolve(path.dirname(configFile.filePath), p),
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Rewrites urls to be relative to the provided filename
|
|
34
|
-
configContents.rewriteUrls = 'all';
|
|
35
|
-
configContents.plugins = configContents.plugins || [];
|
|
36
|
-
|
|
37
|
-
return {config: configContents};
|
|
38
|
-
}
|