@parcel/transformer-less 2.0.0-beta.3.1 → 2.0.0-dev.1510
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 +18 -65
- package/lib/loadConfig.js +8 -21
- package/package.json +6 -6
- package/src/LessTransformer.js +5 -2
- package/src/loadConfig.js +16 -11
package/lib/LessTransformer.js
CHANGED
|
@@ -4,71 +4,46 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
_path = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _plugin() {
|
|
19
15
|
const data = require("@parcel/plugin");
|
|
20
|
-
|
|
21
16
|
_plugin = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _sourceMap() {
|
|
29
22
|
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
30
|
-
|
|
31
23
|
_sourceMap = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _less() {
|
|
39
29
|
const data = _interopRequireDefault(require("less"));
|
|
40
|
-
|
|
41
30
|
_less = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
|
-
function _loadConfig() {
|
|
49
|
-
const data = require("./loadConfig");
|
|
50
|
-
|
|
51
|
-
_loadConfig = function () {
|
|
52
|
-
return data;
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
return data;
|
|
56
|
-
}
|
|
57
|
-
|
|
35
|
+
var _loadConfig = require("./loadConfig");
|
|
58
36
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
59
|
-
|
|
60
37
|
// E.g: ~library/file.less
|
|
61
38
|
const WEBPACK_ALIAS_RE = /^~[^/]/;
|
|
62
|
-
|
|
63
|
-
var _default = new (_plugin().Transformer)({
|
|
39
|
+
var _default = exports.default = new (_plugin().Transformer)({
|
|
64
40
|
loadConfig({
|
|
65
41
|
config
|
|
66
42
|
}) {
|
|
67
|
-
return (0, _loadConfig
|
|
43
|
+
return (0, _loadConfig.load)({
|
|
68
44
|
config
|
|
69
45
|
});
|
|
70
46
|
},
|
|
71
|
-
|
|
72
47
|
async transform({
|
|
73
48
|
asset,
|
|
74
49
|
options,
|
|
@@ -79,15 +54,13 @@ var _default = new (_plugin().Transformer)({
|
|
|
79
54
|
asset.meta.hasDependencies = false;
|
|
80
55
|
let code = await asset.getCode();
|
|
81
56
|
let result;
|
|
82
|
-
|
|
83
57
|
try {
|
|
84
|
-
let lessConfig = config ? {
|
|
58
|
+
let lessConfig = config ? {
|
|
59
|
+
...config.config
|
|
85
60
|
} : {};
|
|
86
|
-
|
|
87
61
|
if (asset.env.sourceMap) {
|
|
88
62
|
lessConfig.sourceMap = {};
|
|
89
63
|
}
|
|
90
|
-
|
|
91
64
|
lessConfig.filename = asset.filePath;
|
|
92
65
|
lessConfig.plugins = [...(lessConfig.plugins || []), urlPlugin({
|
|
93
66
|
asset
|
|
@@ -105,51 +78,44 @@ var _default = new (_plugin().Transformer)({
|
|
|
105
78
|
};
|
|
106
79
|
throw err;
|
|
107
80
|
}
|
|
108
|
-
|
|
109
81
|
if (result.map != null) {
|
|
110
82
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
111
83
|
let rawMap = JSON.parse(result.map);
|
|
112
|
-
map.addVLQMap({
|
|
84
|
+
map.addVLQMap({
|
|
85
|
+
...rawMap,
|
|
113
86
|
sources: rawMap.sources.map(s => _path().default.relative(options.projectRoot, s))
|
|
114
87
|
});
|
|
115
88
|
asset.setMap(map);
|
|
116
89
|
}
|
|
117
|
-
|
|
118
90
|
asset.setCode(result.css);
|
|
119
91
|
return [asset];
|
|
120
92
|
}
|
|
121
|
-
|
|
122
93
|
});
|
|
123
|
-
|
|
124
|
-
exports.default = _default;
|
|
125
|
-
|
|
126
94
|
function urlPlugin({
|
|
127
95
|
asset
|
|
128
96
|
}) {
|
|
129
97
|
return {
|
|
130
98
|
install(less, pluginManager) {
|
|
131
99
|
// This is a hack; no such interface exists, even conceptually, in Less.
|
|
100
|
+
|
|
132
101
|
const visitor = new less.visitors.Visitor({
|
|
133
102
|
visitUrl(node) {
|
|
134
103
|
const valueNode = node.value;
|
|
135
104
|
const stringValue = valueNode.value;
|
|
136
|
-
|
|
137
105
|
if (!stringValue.startsWith('#') // IE's `behavior: url(#default#VML)`)
|
|
138
106
|
) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
107
|
+
valueNode.value = asset.addURLDependency(stringValue, {});
|
|
108
|
+
}
|
|
142
109
|
return node;
|
|
143
110
|
}
|
|
144
|
-
|
|
145
111
|
});
|
|
112
|
+
|
|
113
|
+
// $FlowFixMe[method-unbinding]
|
|
146
114
|
visitor.run = visitor.visit;
|
|
147
115
|
pluginManager.addVisitor(visitor);
|
|
148
116
|
}
|
|
149
|
-
|
|
150
117
|
};
|
|
151
118
|
}
|
|
152
|
-
|
|
153
119
|
function resolvePathPlugin({
|
|
154
120
|
asset,
|
|
155
121
|
resolve
|
|
@@ -160,45 +126,36 @@ function resolvePathPlugin({
|
|
|
160
126
|
supports() {
|
|
161
127
|
return true;
|
|
162
128
|
}
|
|
163
|
-
|
|
164
129
|
supportsSync() {
|
|
165
130
|
return false;
|
|
166
131
|
}
|
|
167
|
-
|
|
168
132
|
async loadFile(rawFilename, currentDirectory, options) {
|
|
169
133
|
let filename = rawFilename;
|
|
170
|
-
|
|
171
134
|
if (WEBPACK_ALIAS_RE.test(filename)) {
|
|
172
135
|
let correctPath = filename.replace(/^~/, '');
|
|
173
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}"`);
|
|
174
|
-
}
|
|
175
|
-
|
|
137
|
+
}
|
|
176
138
|
|
|
139
|
+
// Based on https://github.com/less/less.js/blob/master/packages/less/src/less-node/file-manager.js
|
|
177
140
|
let isAbsoluteFilename = this.isPathAbsolute(filename);
|
|
178
141
|
let paths = isAbsoluteFilename ? [''] : [currentDirectory];
|
|
179
|
-
|
|
180
142
|
if (options.paths) {
|
|
181
143
|
paths.push(...options.paths);
|
|
182
144
|
}
|
|
183
|
-
|
|
184
145
|
let prefixes = options.prefixes || [''];
|
|
185
146
|
let fileParts = this.extractUrlParts(filename);
|
|
186
147
|
let filePath;
|
|
187
148
|
let contents;
|
|
188
|
-
|
|
189
149
|
if (filename[0] !== '~') {
|
|
190
150
|
outer: for (let p of paths) {
|
|
191
151
|
for (let prefix of prefixes) {
|
|
192
152
|
filePath = fileParts.rawPath + prefix + fileParts.filename;
|
|
193
|
-
|
|
194
153
|
if (p) {
|
|
195
154
|
filePath = _path().default.join(p, filePath);
|
|
196
155
|
}
|
|
197
|
-
|
|
198
156
|
if (options.ext) {
|
|
199
157
|
filePath = this.tryAppendExtension(filePath, options.ext);
|
|
200
158
|
}
|
|
201
|
-
|
|
202
159
|
try {
|
|
203
160
|
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
204
161
|
break outer;
|
|
@@ -210,26 +167,22 @@ function resolvePathPlugin({
|
|
|
210
167
|
}
|
|
211
168
|
}
|
|
212
169
|
}
|
|
213
|
-
|
|
214
170
|
if (!contents) {
|
|
215
|
-
filePath = await resolve(asset.filePath, filename
|
|
171
|
+
filePath = await resolve(asset.filePath, filename, {
|
|
172
|
+
packageConditions: ['less', 'style']
|
|
173
|
+
});
|
|
216
174
|
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
217
175
|
}
|
|
218
|
-
|
|
219
176
|
if (filePath) {
|
|
220
|
-
asset.
|
|
177
|
+
asset.invalidateOnFileChange(filePath);
|
|
221
178
|
}
|
|
222
|
-
|
|
223
179
|
return {
|
|
224
180
|
contents,
|
|
225
181
|
filename: filePath
|
|
226
182
|
};
|
|
227
183
|
}
|
|
228
|
-
|
|
229
184
|
}
|
|
230
|
-
|
|
231
185
|
pluginManager.addFileManager(new LessFileManager());
|
|
232
186
|
}
|
|
233
|
-
|
|
234
187
|
};
|
|
235
188
|
}
|
package/lib/loadConfig.js
CHANGED
|
@@ -4,47 +4,34 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.load = load;
|
|
7
|
-
|
|
8
7
|
function _path() {
|
|
9
8
|
const data = _interopRequireDefault(require("path"));
|
|
10
|
-
|
|
11
9
|
_path = function () {
|
|
12
10
|
return data;
|
|
13
11
|
};
|
|
14
|
-
|
|
15
12
|
return data;
|
|
16
13
|
}
|
|
17
|
-
|
|
18
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
15
|
async function load({
|
|
21
16
|
config
|
|
22
17
|
}) {
|
|
23
|
-
let configFile = await config.getConfig(['.lessrc', '.lessrc.js'], {
|
|
18
|
+
let configFile = await config.getConfig(['.lessrc', '.lessrc.js', '.lessrc.cjs', '.lessrc.mjs'], {
|
|
24
19
|
packageKey: 'less'
|
|
25
20
|
});
|
|
26
21
|
let configContents = {};
|
|
27
|
-
|
|
28
22
|
if (configFile != null) {
|
|
29
|
-
configContents = configFile.contents;
|
|
23
|
+
configContents = configFile.contents;
|
|
30
24
|
|
|
25
|
+
// Resolve relative paths from config file
|
|
31
26
|
if (configContents.paths) {
|
|
32
27
|
configContents.paths = configContents.paths.map(p => _path().default.resolve(_path().default.dirname(configFile.filePath), p));
|
|
33
28
|
}
|
|
34
|
-
} // Rewrites urls to be relative to the provided filename
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
configContents.rewriteUrls = 'all';
|
|
38
|
-
configContents.plugins = configContents.plugins || []; // This should enforce the config to be reloaded on every run as it's JS
|
|
39
|
-
|
|
40
|
-
let isDynamic = configFile && _path().default.extname(configFile.filePath) === '.js';
|
|
41
|
-
|
|
42
|
-
if (isDynamic) {
|
|
43
|
-
config.shouldInvalidateOnStartup();
|
|
44
29
|
}
|
|
45
30
|
|
|
46
|
-
|
|
47
|
-
|
|
31
|
+
// Rewrites urls to be relative to the provided filename
|
|
32
|
+
configContents.rewriteUrls = 'all';
|
|
33
|
+
configContents.plugins = configContents.plugins || [];
|
|
34
|
+
return {
|
|
48
35
|
config: configContents
|
|
49
|
-
}
|
|
36
|
+
};
|
|
50
37
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-less",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-dev.1510+a9bb85adf",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
"source": "src/LessTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.0.0-
|
|
20
|
+
"parcel": "^2.0.0-dev.1508+a9bb85adf"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/plugin": "2.0.0-
|
|
24
|
-
"@parcel/source-map": "2.
|
|
25
|
-
"less": "^
|
|
23
|
+
"@parcel/plugin": "2.0.0-dev.1510+a9bb85adf",
|
|
24
|
+
"@parcel/source-map": "^2.1.1",
|
|
25
|
+
"less": "^4.1.1"
|
|
26
26
|
},
|
|
27
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a9bb85adf8f3b38631e178b3aacaa30c78696e36"
|
|
28
28
|
}
|
package/src/LessTransformer.js
CHANGED
|
@@ -88,6 +88,7 @@ function urlPlugin({asset}) {
|
|
|
88
88
|
},
|
|
89
89
|
});
|
|
90
90
|
|
|
91
|
+
// $FlowFixMe[method-unbinding]
|
|
91
92
|
visitor.run = visitor.visit;
|
|
92
93
|
pluginManager.addVisitor(visitor);
|
|
93
94
|
},
|
|
@@ -151,12 +152,14 @@ function resolvePathPlugin({asset, resolve}) {
|
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
if (!contents) {
|
|
154
|
-
filePath = await resolve(asset.filePath, filename
|
|
155
|
+
filePath = await resolve(asset.filePath, filename, {
|
|
156
|
+
packageConditions: ['less', 'style'],
|
|
157
|
+
});
|
|
155
158
|
contents = await asset.fs.readFile(filePath, 'utf8');
|
|
156
159
|
}
|
|
157
160
|
|
|
158
161
|
if (filePath) {
|
|
159
|
-
asset.
|
|
162
|
+
asset.invalidateOnFileChange(filePath);
|
|
160
163
|
}
|
|
161
164
|
|
|
162
165
|
return {
|
package/src/loadConfig.js
CHANGED
|
@@ -2,10 +2,21 @@
|
|
|
2
2
|
import type {Config} from '@parcel/types';
|
|
3
3
|
import path from 'path';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
+
);
|
|
9
20
|
|
|
10
21
|
let configContents = {};
|
|
11
22
|
if (configFile != null) {
|
|
@@ -23,11 +34,5 @@ export async function load({config}: {|config: Config|}): Promise<void> {
|
|
|
23
34
|
configContents.rewriteUrls = 'all';
|
|
24
35
|
configContents.plugins = configContents.plugins || [];
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
let isDynamic = configFile && path.extname(configFile.filePath) === '.js';
|
|
28
|
-
if (isDynamic) {
|
|
29
|
-
config.shouldInvalidateOnStartup();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return config.setResult({isStatic: !isDynamic, config: configContents});
|
|
37
|
+
return {config: configContents};
|
|
33
38
|
}
|