@parcel/transformer-css 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.
- package/lib/CSSTransformer.js +25 -74
- package/package.json +6 -6
- package/src/CSSTransformer.js +20 -4
package/lib/CSSTransformer.js
CHANGED
|
@@ -4,93 +4,65 @@ 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 _sourceMap() {
|
|
19
15
|
const data = _interopRequireDefault(require("@parcel/source-map"));
|
|
20
|
-
|
|
21
16
|
_sourceMap = function () {
|
|
22
17
|
return data;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
return data;
|
|
26
20
|
}
|
|
27
|
-
|
|
28
21
|
function _plugin() {
|
|
29
22
|
const data = require("@parcel/plugin");
|
|
30
|
-
|
|
31
23
|
_plugin = function () {
|
|
32
24
|
return data;
|
|
33
25
|
};
|
|
34
|
-
|
|
35
26
|
return data;
|
|
36
27
|
}
|
|
37
|
-
|
|
38
28
|
function _lightningcss() {
|
|
39
29
|
const data = require("lightningcss");
|
|
40
|
-
|
|
41
30
|
_lightningcss = function () {
|
|
42
31
|
return data;
|
|
43
32
|
};
|
|
44
|
-
|
|
45
33
|
return data;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
35
|
function _utils() {
|
|
49
36
|
const data = require("@parcel/utils");
|
|
50
|
-
|
|
51
37
|
_utils = function () {
|
|
52
38
|
return data;
|
|
53
39
|
};
|
|
54
|
-
|
|
55
40
|
return data;
|
|
56
41
|
}
|
|
57
|
-
|
|
58
42
|
function _browserslist() {
|
|
59
43
|
const data = _interopRequireDefault(require("browserslist"));
|
|
60
|
-
|
|
61
44
|
_browserslist = function () {
|
|
62
45
|
return data;
|
|
63
46
|
};
|
|
64
|
-
|
|
65
47
|
return data;
|
|
66
48
|
}
|
|
67
|
-
|
|
68
49
|
function _nullthrows() {
|
|
69
50
|
const data = _interopRequireDefault(require("nullthrows"));
|
|
70
|
-
|
|
71
51
|
_nullthrows = function () {
|
|
72
52
|
return data;
|
|
73
53
|
};
|
|
74
|
-
|
|
75
54
|
return data;
|
|
76
55
|
}
|
|
77
|
-
|
|
78
56
|
function _diagnostic() {
|
|
79
57
|
const data = _interopRequireWildcard(require("@parcel/diagnostic"));
|
|
80
|
-
|
|
81
58
|
_diagnostic = function () {
|
|
82
59
|
return data;
|
|
83
60
|
};
|
|
84
|
-
|
|
85
61
|
return data;
|
|
86
62
|
}
|
|
87
|
-
|
|
88
63
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
89
|
-
|
|
90
64
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
91
|
-
|
|
92
65
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
93
|
-
|
|
94
66
|
var _default = new (_plugin().Transformer)({
|
|
95
67
|
async loadConfig({
|
|
96
68
|
config,
|
|
@@ -101,7 +73,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
101
73
|
});
|
|
102
74
|
return conf === null || conf === void 0 ? void 0 : conf.contents;
|
|
103
75
|
},
|
|
104
|
-
|
|
105
76
|
async transform({
|
|
106
77
|
asset,
|
|
107
78
|
config,
|
|
@@ -123,7 +94,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
123
94
|
let [code, originalMap] = await Promise.all([asset.getBuffer(), asset.getMap()]);
|
|
124
95
|
let targets = getTargets(asset.env.engines.browsers);
|
|
125
96
|
let res;
|
|
126
|
-
|
|
127
97
|
try {
|
|
128
98
|
if (asset.meta.type === 'attr') {
|
|
129
99
|
res = (0, _lightningcss().transformStyleAttribute)({
|
|
@@ -134,19 +104,15 @@ var _default = new (_plugin().Transformer)({
|
|
|
134
104
|
});
|
|
135
105
|
} else {
|
|
136
106
|
let cssModules = false;
|
|
137
|
-
|
|
138
107
|
if (asset.meta.type !== 'tag' && asset.meta.cssModulesCompiled == null) {
|
|
139
108
|
let cssModulesConfig = config === null || config === void 0 ? void 0 : config.cssModules;
|
|
140
|
-
|
|
141
109
|
if (asset.isSource && (typeof cssModulesConfig === 'boolean' || cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.global) || /\.module\./.test(asset.filePath)) {
|
|
142
110
|
if (cssModulesConfig !== null && cssModulesConfig !== void 0 && cssModulesConfig.dashedIdents && !asset.isSource) {
|
|
143
111
|
cssModulesConfig.dashedIdents = false;
|
|
144
112
|
}
|
|
145
|
-
|
|
146
113
|
cssModules = cssModulesConfig !== null && cssModulesConfig !== void 0 ? cssModulesConfig : true;
|
|
147
114
|
}
|
|
148
115
|
}
|
|
149
|
-
|
|
150
116
|
res = (0, _lightningcss().transform)({
|
|
151
117
|
filename: _path().default.relative(options.projectRoot, asset.filePath),
|
|
152
118
|
code,
|
|
@@ -161,23 +127,19 @@ var _default = new (_plugin().Transformer)({
|
|
|
161
127
|
}
|
|
162
128
|
} catch (err) {
|
|
163
129
|
var _err$data;
|
|
164
|
-
|
|
165
130
|
err.filePath = asset.filePath;
|
|
166
131
|
let diagnostic = (0, _diagnostic().errorToDiagnostic)(err, {
|
|
167
132
|
origin: '@parcel/transformer-css'
|
|
168
133
|
});
|
|
169
|
-
|
|
170
134
|
if (((_err$data = err.data) === null || _err$data === void 0 ? void 0 : _err$data.type) === 'AmbiguousUrlInCustomProperty' && err.data.url) {
|
|
171
135
|
let p = '/' + (0, _utils().relativePath)(options.projectRoot, _path().default.resolve(_path().default.dirname(asset.filePath), err.data.url), false);
|
|
172
136
|
diagnostic[0].hints = [`Replace with: url(${p})`];
|
|
173
137
|
diagnostic[0].documentationURL = 'https://parceljs.org/languages/css/#url()';
|
|
174
138
|
}
|
|
175
|
-
|
|
176
139
|
throw new (_diagnostic().default)({
|
|
177
140
|
diagnostic
|
|
178
141
|
});
|
|
179
142
|
}
|
|
180
|
-
|
|
181
143
|
if (res.warnings) {
|
|
182
144
|
for (let warning of res.warnings) {
|
|
183
145
|
logger.warn({
|
|
@@ -187,45 +149,39 @@ var _default = new (_plugin().Transformer)({
|
|
|
187
149
|
codeHighlights: [{
|
|
188
150
|
start: {
|
|
189
151
|
line: warning.loc.line,
|
|
190
|
-
column: warning.loc.column
|
|
152
|
+
column: warning.loc.column + 1
|
|
191
153
|
},
|
|
192
154
|
end: {
|
|
193
155
|
line: warning.loc.line,
|
|
194
|
-
column: warning.loc.column
|
|
156
|
+
column: warning.loc.column + 1
|
|
195
157
|
}
|
|
196
158
|
}]
|
|
197
159
|
}]
|
|
198
160
|
});
|
|
199
161
|
}
|
|
200
162
|
}
|
|
201
|
-
|
|
202
163
|
asset.setBuffer(res.code);
|
|
203
|
-
|
|
204
164
|
if (res.map != null) {
|
|
205
165
|
let vlqMap = JSON.parse(res.map.toString());
|
|
206
166
|
let map = new (_sourceMap().default)(options.projectRoot);
|
|
207
167
|
map.addVLQMap(vlqMap);
|
|
208
|
-
|
|
209
168
|
if (originalMap) {
|
|
210
169
|
map.extends(originalMap);
|
|
211
170
|
}
|
|
212
|
-
|
|
213
171
|
asset.setMap(map);
|
|
214
172
|
}
|
|
215
|
-
|
|
216
173
|
if (res.dependencies) {
|
|
217
174
|
for (let dep of res.dependencies) {
|
|
218
|
-
let loc = dep.loc;
|
|
219
|
-
|
|
175
|
+
let loc = convertLoc(dep.loc);
|
|
220
176
|
if (originalMap) {
|
|
221
177
|
loc = (0, _utils().remapSourceLocation)(loc, originalMap);
|
|
222
178
|
}
|
|
223
|
-
|
|
224
179
|
if (dep.type === 'import' && !res.exports) {
|
|
225
180
|
asset.addDependency({
|
|
226
181
|
specifier: dep.url,
|
|
227
182
|
specifierType: 'url',
|
|
228
183
|
loc,
|
|
184
|
+
packageConditions: ['style'],
|
|
229
185
|
meta: {
|
|
230
186
|
// For the glob resolver to distinguish between `@import` and other URL dependencies.
|
|
231
187
|
isCSSImport: true,
|
|
@@ -242,9 +198,7 @@ var _default = new (_plugin().Transformer)({
|
|
|
242
198
|
}
|
|
243
199
|
}
|
|
244
200
|
}
|
|
245
|
-
|
|
246
201
|
let assets = [asset];
|
|
247
|
-
|
|
248
202
|
if (res.exports != null) {
|
|
249
203
|
let exports = res.exports;
|
|
250
204
|
asset.symbols.ensure();
|
|
@@ -254,25 +208,19 @@ var _default = new (_plugin().Transformer)({
|
|
|
254
208
|
let c = 0;
|
|
255
209
|
let depjs = '';
|
|
256
210
|
let js = '';
|
|
257
|
-
|
|
258
211
|
for (let key in exports) {
|
|
259
212
|
locals.set(exports[key].name, key);
|
|
260
213
|
}
|
|
261
|
-
|
|
262
214
|
let seen = new Set();
|
|
263
|
-
|
|
264
215
|
let add = key => {
|
|
265
216
|
if (seen.has(key)) {
|
|
266
217
|
return;
|
|
267
218
|
}
|
|
268
|
-
|
|
269
219
|
seen.add(key);
|
|
270
220
|
let e = exports[key];
|
|
271
221
|
let s = `module.exports[${JSON.stringify(key)}] = \`${e.name}`;
|
|
272
|
-
|
|
273
222
|
for (let ref of e.composes) {
|
|
274
223
|
s += ' ';
|
|
275
|
-
|
|
276
224
|
if (ref.type === 'local') {
|
|
277
225
|
add((0, _nullthrows().default)(locals.get(ref.name)));
|
|
278
226
|
s += '${' + `module.exports[${JSON.stringify((0, _nullthrows().default)(locals.get(ref.name)))}]` + '}';
|
|
@@ -280,36 +228,35 @@ var _default = new (_plugin().Transformer)({
|
|
|
280
228
|
s += ref.name;
|
|
281
229
|
} else if (ref.type === 'dependency') {
|
|
282
230
|
let d = dependencies.get(ref.specifier);
|
|
283
|
-
|
|
284
231
|
if (d == null) {
|
|
285
232
|
d = `dep_${c++}`;
|
|
286
233
|
depjs += `import * as ${d} from ${JSON.stringify(ref.specifier)};\n`;
|
|
287
234
|
dependencies.set(ref.specifier, d);
|
|
288
235
|
asset.addDependency({
|
|
289
236
|
specifier: ref.specifier,
|
|
290
|
-
specifierType: 'esm'
|
|
237
|
+
specifierType: 'esm',
|
|
238
|
+
packageConditions: ['style']
|
|
291
239
|
});
|
|
292
240
|
}
|
|
293
|
-
|
|
294
241
|
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
|
|
295
242
|
}
|
|
296
243
|
}
|
|
244
|
+
s += '`;\n';
|
|
297
245
|
|
|
298
|
-
|
|
246
|
+
// If the export is referenced internally (e.g. used @keyframes), add a self-reference
|
|
299
247
|
// to the JS so the symbol is retained during tree-shaking.
|
|
300
|
-
|
|
301
248
|
if (e.isReferenced) {
|
|
302
249
|
s += `module.exports[${JSON.stringify(key)}];\n`;
|
|
303
250
|
}
|
|
304
|
-
|
|
305
251
|
js += s;
|
|
306
252
|
};
|
|
307
253
|
|
|
308
|
-
|
|
254
|
+
// It's possible that the exports can be ordered differently between builds.
|
|
255
|
+
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
256
|
+
for (let key of Object.keys(exports).sort()) {
|
|
309
257
|
asset.symbols.set(key, exports[key].name);
|
|
310
258
|
add(key);
|
|
311
259
|
}
|
|
312
|
-
|
|
313
260
|
if (res.dependencies) {
|
|
314
261
|
for (let dep of res.dependencies) {
|
|
315
262
|
if (dep.type === 'import') {
|
|
@@ -321,15 +268,14 @@ var _default = new (_plugin().Transformer)({
|
|
|
321
268
|
}
|
|
322
269
|
}
|
|
323
270
|
}
|
|
324
|
-
|
|
325
271
|
if (res.references != null) {
|
|
326
272
|
let references = res.references;
|
|
327
|
-
|
|
328
273
|
for (let symbol in references) {
|
|
329
274
|
let reference = references[symbol];
|
|
330
275
|
asset.addDependency({
|
|
331
276
|
specifier: reference.specifier,
|
|
332
277
|
specifierType: 'esm',
|
|
278
|
+
packageConditions: ['style'],
|
|
333
279
|
symbols: new Map([[reference.name, {
|
|
334
280
|
local: symbol,
|
|
335
281
|
isWeak: false,
|
|
@@ -339,7 +285,6 @@ var _default = new (_plugin().Transformer)({
|
|
|
339
285
|
asset.meta.hasReferences = true;
|
|
340
286
|
}
|
|
341
287
|
}
|
|
342
|
-
|
|
343
288
|
assets.push({
|
|
344
289
|
type: 'js',
|
|
345
290
|
content: depjs + js,
|
|
@@ -347,27 +292,33 @@ var _default = new (_plugin().Transformer)({
|
|
|
347
292
|
env
|
|
348
293
|
});
|
|
349
294
|
}
|
|
350
|
-
|
|
351
295
|
return assets;
|
|
352
296
|
}
|
|
353
|
-
|
|
354
297
|
});
|
|
355
|
-
|
|
356
298
|
exports.default = _default;
|
|
357
299
|
let cache = new Map();
|
|
358
|
-
|
|
359
300
|
function getTargets(browsers) {
|
|
360
301
|
if (browsers == null) {
|
|
361
302
|
return undefined;
|
|
362
303
|
}
|
|
363
|
-
|
|
364
304
|
let cached = cache.get(browsers);
|
|
365
|
-
|
|
366
305
|
if (cached != null) {
|
|
367
306
|
return cached;
|
|
368
307
|
}
|
|
369
|
-
|
|
370
308
|
let targets = (0, _lightningcss().browserslistToTargets)((0, _browserslist().default)(browsers));
|
|
371
309
|
cache.set(browsers, targets);
|
|
372
310
|
return targets;
|
|
311
|
+
}
|
|
312
|
+
function convertLoc(loc) {
|
|
313
|
+
return {
|
|
314
|
+
filePath: loc.filePath,
|
|
315
|
+
start: {
|
|
316
|
+
line: loc.start.line,
|
|
317
|
+
column: loc.start.column
|
|
318
|
+
},
|
|
319
|
+
end: {
|
|
320
|
+
line: loc.end.line,
|
|
321
|
+
column: loc.end.column + 1
|
|
322
|
+
}
|
|
323
|
+
};
|
|
373
324
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parcel/transformer-css",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.9.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -17,16 +17,16 @@
|
|
|
17
17
|
"source": "src/CSSTransformer.js",
|
|
18
18
|
"engines": {
|
|
19
19
|
"node": ">= 12.0.0",
|
|
20
|
-
"parcel": "^2.
|
|
20
|
+
"parcel": "^2.9.0"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@parcel/diagnostic": "2.
|
|
24
|
-
"@parcel/plugin": "2.
|
|
23
|
+
"@parcel/diagnostic": "2.9.0",
|
|
24
|
+
"@parcel/plugin": "2.9.0",
|
|
25
25
|
"@parcel/source-map": "^2.1.1",
|
|
26
|
-
"@parcel/utils": "2.
|
|
26
|
+
"@parcel/utils": "2.9.0",
|
|
27
27
|
"browserslist": "^4.6.6",
|
|
28
28
|
"lightningcss": "^1.16.1",
|
|
29
29
|
"nullthrows": "^1.1.1"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "dd9435be8afed35c5ffc161cf4b586fd6c78fc1f"
|
|
32
32
|
}
|
package/src/CSSTransformer.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// @flow strict-local
|
|
2
2
|
|
|
3
|
+
import type {SourceLocation} from '@parcel/types';
|
|
4
|
+
|
|
3
5
|
import path from 'path';
|
|
4
6
|
import SourceMap from '@parcel/source-map';
|
|
5
7
|
import {Transformer} from '@parcel/plugin';
|
|
@@ -7,6 +9,7 @@ import {
|
|
|
7
9
|
transform,
|
|
8
10
|
transformStyleAttribute,
|
|
9
11
|
browserslistToTargets,
|
|
12
|
+
type SourceLocation as LightningSourceLocation,
|
|
10
13
|
} from 'lightningcss';
|
|
11
14
|
import {remapSourceLocation, relativePath} from '@parcel/utils';
|
|
12
15
|
import browserslist from 'browserslist';
|
|
@@ -116,11 +119,11 @@ export default (new Transformer({
|
|
|
116
119
|
{
|
|
117
120
|
start: {
|
|
118
121
|
line: warning.loc.line,
|
|
119
|
-
column: warning.loc.column,
|
|
122
|
+
column: warning.loc.column + 1,
|
|
120
123
|
},
|
|
121
124
|
end: {
|
|
122
125
|
line: warning.loc.line,
|
|
123
|
-
column: warning.loc.column,
|
|
126
|
+
column: warning.loc.column + 1,
|
|
124
127
|
},
|
|
125
128
|
},
|
|
126
129
|
],
|
|
@@ -146,7 +149,7 @@ export default (new Transformer({
|
|
|
146
149
|
|
|
147
150
|
if (res.dependencies) {
|
|
148
151
|
for (let dep of res.dependencies) {
|
|
149
|
-
let loc = dep.loc;
|
|
152
|
+
let loc = convertLoc(dep.loc);
|
|
150
153
|
if (originalMap) {
|
|
151
154
|
loc = remapSourceLocation(loc, originalMap);
|
|
152
155
|
}
|
|
@@ -156,6 +159,7 @@ export default (new Transformer({
|
|
|
156
159
|
specifier: dep.url,
|
|
157
160
|
specifierType: 'url',
|
|
158
161
|
loc,
|
|
162
|
+
packageConditions: ['style'],
|
|
159
163
|
meta: {
|
|
160
164
|
// For the glob resolver to distinguish between `@import` and other URL dependencies.
|
|
161
165
|
isCSSImport: true,
|
|
@@ -225,6 +229,7 @@ export default (new Transformer({
|
|
|
225
229
|
asset.addDependency({
|
|
226
230
|
specifier: ref.specifier,
|
|
227
231
|
specifierType: 'esm',
|
|
232
|
+
packageConditions: ['style'],
|
|
228
233
|
});
|
|
229
234
|
}
|
|
230
235
|
s += '${' + `${d}[${JSON.stringify(ref.name)}]` + '}';
|
|
@@ -242,7 +247,9 @@ export default (new Transformer({
|
|
|
242
247
|
js += s;
|
|
243
248
|
};
|
|
244
249
|
|
|
245
|
-
|
|
250
|
+
// It's possible that the exports can be ordered differently between builds.
|
|
251
|
+
// Sorting by key is safe as the order is irrelevant but needs to be deterministic.
|
|
252
|
+
for (let key of Object.keys(exports).sort()) {
|
|
246
253
|
asset.symbols.set(key, exports[key].name);
|
|
247
254
|
add(key);
|
|
248
255
|
}
|
|
@@ -266,6 +273,7 @@ export default (new Transformer({
|
|
|
266
273
|
asset.addDependency({
|
|
267
274
|
specifier: reference.specifier,
|
|
268
275
|
specifierType: 'esm',
|
|
276
|
+
packageConditions: ['style'],
|
|
269
277
|
symbols: new Map([
|
|
270
278
|
[reference.name, {local: symbol, isWeak: false, loc: null}],
|
|
271
279
|
]),
|
|
@@ -304,3 +312,11 @@ function getTargets(browsers) {
|
|
|
304
312
|
cache.set(browsers, targets);
|
|
305
313
|
return targets;
|
|
306
314
|
}
|
|
315
|
+
|
|
316
|
+
function convertLoc(loc: LightningSourceLocation): SourceLocation {
|
|
317
|
+
return {
|
|
318
|
+
filePath: loc.filePath,
|
|
319
|
+
start: {line: loc.start.line, column: loc.start.column},
|
|
320
|
+
end: {line: loc.end.line, column: loc.end.column + 1},
|
|
321
|
+
};
|
|
322
|
+
}
|