@parcel/transformer-less 2.8.3 → 2.9.0

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