vite 6.0.0-beta.1 → 6.0.0-beta.3
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/LICENSE.md +17 -215
- package/README.md +4 -4
- package/bin/vite.js +4 -0
- package/dist/client/client.mjs +8 -10
- package/dist/node/chunks/dep-CBTZ9M2V.js +7220 -0
- package/dist/node/chunks/{dep-BZ_CwQkz.js → dep-ChZnDG_O.js} +22174 -27804
- package/dist/node/chunks/dep-DHwgfHPT.js +1103 -0
- package/dist/node/chunks/dep-wWOLM6NS.js +593 -0
- package/dist/node/cli.js +10 -12
- package/dist/node/constants.js +7 -2
- package/dist/node/index.d.ts +118 -92
- package/dist/node/index.js +8 -118
- package/dist/node/module-runner.d.ts +75 -53
- package/dist/node/module-runner.js +151 -159
- package/dist/node-cjs/publicUtils.cjs +2869 -2636
- package/index.cjs +1 -1
- package/index.d.cts +1 -1
- package/package.json +17 -17
- package/dist/node/chunks/dep-BZeeNeMJ.js +0 -6843
- package/dist/node/chunks/dep-DiM5uMHt.js +0 -993
- package/dist/node/chunks/dep-IQS-Za7F.js +0 -561
@@ -0,0 +1,1103 @@
|
|
1
|
+
import { L as getDefaultExportFromCjs } from './dep-ChZnDG_O.js';
|
2
|
+
import require$$0 from 'path';
|
3
|
+
import require$$0__default from 'fs';
|
4
|
+
import { r as requireLib } from './dep-wWOLM6NS.js';
|
5
|
+
|
6
|
+
import { fileURLToPath as __cjs_fileURLToPath } from 'node:url';
|
7
|
+
import { dirname as __cjs_dirname } from 'node:path';
|
8
|
+
import { createRequire as __cjs_createRequire } from 'node:module';
|
9
|
+
|
10
|
+
const __filename = __cjs_fileURLToPath(import.meta.url);
|
11
|
+
const __dirname = __cjs_dirname(__filename);
|
12
|
+
const require = __cjs_createRequire(import.meta.url);
|
13
|
+
const __require = require;
|
14
|
+
function _mergeNamespaces(n, m) {
|
15
|
+
for (var i = 0; i < m.length; i++) {
|
16
|
+
var e = m[i];
|
17
|
+
if (typeof e !== 'string' && !Array.isArray(e)) { for (var k in e) {
|
18
|
+
if (k !== 'default' && !(k in n)) {
|
19
|
+
n[k] = e[k];
|
20
|
+
}
|
21
|
+
} }
|
22
|
+
}
|
23
|
+
return n;
|
24
|
+
}
|
25
|
+
|
26
|
+
var formatImportPrelude;
|
27
|
+
var hasRequiredFormatImportPrelude;
|
28
|
+
|
29
|
+
function requireFormatImportPrelude () {
|
30
|
+
if (hasRequiredFormatImportPrelude) return formatImportPrelude;
|
31
|
+
hasRequiredFormatImportPrelude = 1;
|
32
|
+
|
33
|
+
formatImportPrelude = function formatImportPrelude(layer, media, supports) {
|
34
|
+
const parts = [];
|
35
|
+
|
36
|
+
if (typeof layer !== "undefined") {
|
37
|
+
let layerParams = "layer";
|
38
|
+
if (layer) {
|
39
|
+
layerParams = `layer(${layer})`;
|
40
|
+
}
|
41
|
+
|
42
|
+
parts.push(layerParams);
|
43
|
+
}
|
44
|
+
|
45
|
+
if (typeof supports !== "undefined") {
|
46
|
+
parts.push(`supports(${supports})`);
|
47
|
+
}
|
48
|
+
|
49
|
+
if (typeof media !== "undefined") {
|
50
|
+
parts.push(media);
|
51
|
+
}
|
52
|
+
|
53
|
+
return parts.join(" ")
|
54
|
+
};
|
55
|
+
return formatImportPrelude;
|
56
|
+
}
|
57
|
+
|
58
|
+
var base64EncodedImport;
|
59
|
+
var hasRequiredBase64EncodedImport;
|
60
|
+
|
61
|
+
function requireBase64EncodedImport () {
|
62
|
+
if (hasRequiredBase64EncodedImport) return base64EncodedImport;
|
63
|
+
hasRequiredBase64EncodedImport = 1;
|
64
|
+
|
65
|
+
const formatImportPrelude = requireFormatImportPrelude();
|
66
|
+
|
67
|
+
// Base64 encode an import with conditions
|
68
|
+
// The order of conditions is important and is interleaved with cascade layer declarations
|
69
|
+
// Each group of conditions and cascade layers needs to be interpreted in order
|
70
|
+
// To achieve this we create a list of base64 encoded imports, where each import contains a stylesheet with another import.
|
71
|
+
// Each import can define a single group of conditions and a single cascade layer.
|
72
|
+
base64EncodedImport = function base64EncodedConditionalImport(prelude, conditions) {
|
73
|
+
conditions.reverse();
|
74
|
+
const first = conditions.pop();
|
75
|
+
let params = `${prelude} ${formatImportPrelude(
|
76
|
+
first.layer,
|
77
|
+
first.media,
|
78
|
+
first.supports,
|
79
|
+
)}`;
|
80
|
+
|
81
|
+
for (const condition of conditions) {
|
82
|
+
params = `'data:text/css;base64,${Buffer.from(`@import ${params}`).toString(
|
83
|
+
"base64",
|
84
|
+
)}' ${formatImportPrelude(
|
85
|
+
condition.layer,
|
86
|
+
condition.media,
|
87
|
+
condition.supports,
|
88
|
+
)}`;
|
89
|
+
}
|
90
|
+
|
91
|
+
return params
|
92
|
+
};
|
93
|
+
return base64EncodedImport;
|
94
|
+
}
|
95
|
+
|
96
|
+
var applyConditions;
|
97
|
+
var hasRequiredApplyConditions;
|
98
|
+
|
99
|
+
function requireApplyConditions () {
|
100
|
+
if (hasRequiredApplyConditions) return applyConditions;
|
101
|
+
hasRequiredApplyConditions = 1;
|
102
|
+
|
103
|
+
const base64EncodedConditionalImport = requireBase64EncodedImport();
|
104
|
+
|
105
|
+
applyConditions = function applyConditions(bundle, atRule) {
|
106
|
+
bundle.forEach(stmt => {
|
107
|
+
if (
|
108
|
+
stmt.type === "charset" ||
|
109
|
+
stmt.type === "warning" ||
|
110
|
+
!stmt.conditions?.length
|
111
|
+
) {
|
112
|
+
return
|
113
|
+
}
|
114
|
+
|
115
|
+
if (stmt.type === "import") {
|
116
|
+
stmt.node.params = base64EncodedConditionalImport(
|
117
|
+
stmt.fullUri,
|
118
|
+
stmt.conditions,
|
119
|
+
);
|
120
|
+
return
|
121
|
+
}
|
122
|
+
|
123
|
+
const { nodes } = stmt;
|
124
|
+
const { parent } = nodes[0];
|
125
|
+
|
126
|
+
const atRules = [];
|
127
|
+
|
128
|
+
// Convert conditions to at-rules
|
129
|
+
for (const condition of stmt.conditions) {
|
130
|
+
if (typeof condition.media !== "undefined") {
|
131
|
+
const mediaNode = atRule({
|
132
|
+
name: "media",
|
133
|
+
params: condition.media,
|
134
|
+
source: parent.source,
|
135
|
+
});
|
136
|
+
|
137
|
+
atRules.push(mediaNode);
|
138
|
+
}
|
139
|
+
|
140
|
+
if (typeof condition.supports !== "undefined") {
|
141
|
+
const supportsNode = atRule({
|
142
|
+
name: "supports",
|
143
|
+
params: `(${condition.supports})`,
|
144
|
+
source: parent.source,
|
145
|
+
});
|
146
|
+
|
147
|
+
atRules.push(supportsNode);
|
148
|
+
}
|
149
|
+
|
150
|
+
if (typeof condition.layer !== "undefined") {
|
151
|
+
const layerNode = atRule({
|
152
|
+
name: "layer",
|
153
|
+
params: condition.layer,
|
154
|
+
source: parent.source,
|
155
|
+
});
|
156
|
+
|
157
|
+
atRules.push(layerNode);
|
158
|
+
}
|
159
|
+
}
|
160
|
+
|
161
|
+
// Add nodes to AST
|
162
|
+
const outerAtRule = atRules.shift();
|
163
|
+
const innerAtRule = atRules.reduce((previous, next) => {
|
164
|
+
previous.append(next);
|
165
|
+
return next
|
166
|
+
}, outerAtRule);
|
167
|
+
|
168
|
+
parent.insertBefore(nodes[0], outerAtRule);
|
169
|
+
|
170
|
+
// remove nodes
|
171
|
+
nodes.forEach(node => {
|
172
|
+
node.parent = undefined;
|
173
|
+
});
|
174
|
+
|
175
|
+
// better output
|
176
|
+
nodes[0].raws.before = nodes[0].raws.before || "\n";
|
177
|
+
|
178
|
+
// wrap new rules with media query and/or layer at rule
|
179
|
+
innerAtRule.append(nodes);
|
180
|
+
|
181
|
+
stmt.type = "nodes";
|
182
|
+
stmt.nodes = [outerAtRule];
|
183
|
+
delete stmt.node;
|
184
|
+
});
|
185
|
+
};
|
186
|
+
return applyConditions;
|
187
|
+
}
|
188
|
+
|
189
|
+
var applyRaws;
|
190
|
+
var hasRequiredApplyRaws;
|
191
|
+
|
192
|
+
function requireApplyRaws () {
|
193
|
+
if (hasRequiredApplyRaws) return applyRaws;
|
194
|
+
hasRequiredApplyRaws = 1;
|
195
|
+
|
196
|
+
applyRaws = function applyRaws(bundle) {
|
197
|
+
bundle.forEach((stmt, index) => {
|
198
|
+
if (index === 0) return
|
199
|
+
|
200
|
+
if (stmt.parent) {
|
201
|
+
const { before } = stmt.parent.node.raws;
|
202
|
+
if (stmt.type === "nodes") stmt.nodes[0].raws.before = before;
|
203
|
+
else stmt.node.raws.before = before;
|
204
|
+
} else if (stmt.type === "nodes") {
|
205
|
+
stmt.nodes[0].raws.before = stmt.nodes[0].raws.before || "\n";
|
206
|
+
}
|
207
|
+
});
|
208
|
+
};
|
209
|
+
return applyRaws;
|
210
|
+
}
|
211
|
+
|
212
|
+
var applyStyles;
|
213
|
+
var hasRequiredApplyStyles;
|
214
|
+
|
215
|
+
function requireApplyStyles () {
|
216
|
+
if (hasRequiredApplyStyles) return applyStyles;
|
217
|
+
hasRequiredApplyStyles = 1;
|
218
|
+
|
219
|
+
applyStyles = function applyStyles(bundle, styles) {
|
220
|
+
styles.nodes = [];
|
221
|
+
|
222
|
+
// Strip additional statements.
|
223
|
+
bundle.forEach(stmt => {
|
224
|
+
if (["charset", "import"].includes(stmt.type)) {
|
225
|
+
stmt.node.parent = undefined;
|
226
|
+
styles.append(stmt.node);
|
227
|
+
} else if (stmt.type === "nodes") {
|
228
|
+
stmt.nodes.forEach(node => {
|
229
|
+
node.parent = undefined;
|
230
|
+
styles.append(node);
|
231
|
+
});
|
232
|
+
}
|
233
|
+
});
|
234
|
+
};
|
235
|
+
return applyStyles;
|
236
|
+
}
|
237
|
+
|
238
|
+
var readCache = {exports: {}};
|
239
|
+
|
240
|
+
var pify = {exports: {}};
|
241
|
+
|
242
|
+
var hasRequiredPify;
|
243
|
+
|
244
|
+
function requirePify () {
|
245
|
+
if (hasRequiredPify) return pify.exports;
|
246
|
+
hasRequiredPify = 1;
|
247
|
+
|
248
|
+
var processFn = function (fn, P, opts) {
|
249
|
+
return function () {
|
250
|
+
var that = this;
|
251
|
+
var args = new Array(arguments.length);
|
252
|
+
|
253
|
+
for (var i = 0; i < arguments.length; i++) {
|
254
|
+
args[i] = arguments[i];
|
255
|
+
}
|
256
|
+
|
257
|
+
return new P(function (resolve, reject) {
|
258
|
+
args.push(function (err, result) {
|
259
|
+
if (err) {
|
260
|
+
reject(err);
|
261
|
+
} else if (opts.multiArgs) {
|
262
|
+
var results = new Array(arguments.length - 1);
|
263
|
+
|
264
|
+
for (var i = 1; i < arguments.length; i++) {
|
265
|
+
results[i - 1] = arguments[i];
|
266
|
+
}
|
267
|
+
|
268
|
+
resolve(results);
|
269
|
+
} else {
|
270
|
+
resolve(result);
|
271
|
+
}
|
272
|
+
});
|
273
|
+
|
274
|
+
fn.apply(that, args);
|
275
|
+
});
|
276
|
+
};
|
277
|
+
};
|
278
|
+
|
279
|
+
var pify$1 = pify.exports = function (obj, P, opts) {
|
280
|
+
if (typeof P !== 'function') {
|
281
|
+
opts = P;
|
282
|
+
P = Promise;
|
283
|
+
}
|
284
|
+
|
285
|
+
opts = opts || {};
|
286
|
+
opts.exclude = opts.exclude || [/.+Sync$/];
|
287
|
+
|
288
|
+
var filter = function (key) {
|
289
|
+
var match = function (pattern) {
|
290
|
+
return typeof pattern === 'string' ? key === pattern : pattern.test(key);
|
291
|
+
};
|
292
|
+
|
293
|
+
return opts.include ? opts.include.some(match) : !opts.exclude.some(match);
|
294
|
+
};
|
295
|
+
|
296
|
+
var ret = typeof obj === 'function' ? function () {
|
297
|
+
if (opts.excludeMain) {
|
298
|
+
return obj.apply(this, arguments);
|
299
|
+
}
|
300
|
+
|
301
|
+
return processFn(obj, P, opts).apply(this, arguments);
|
302
|
+
} : {};
|
303
|
+
|
304
|
+
return Object.keys(obj).reduce(function (ret, key) {
|
305
|
+
var x = obj[key];
|
306
|
+
|
307
|
+
ret[key] = typeof x === 'function' && filter(key) ? processFn(x, P, opts) : x;
|
308
|
+
|
309
|
+
return ret;
|
310
|
+
}, ret);
|
311
|
+
};
|
312
|
+
|
313
|
+
pify$1.all = pify$1;
|
314
|
+
return pify.exports;
|
315
|
+
}
|
316
|
+
|
317
|
+
var hasRequiredReadCache;
|
318
|
+
|
319
|
+
function requireReadCache () {
|
320
|
+
if (hasRequiredReadCache) return readCache.exports;
|
321
|
+
hasRequiredReadCache = 1;
|
322
|
+
var fs = require$$0__default;
|
323
|
+
var path = require$$0;
|
324
|
+
var pify = requirePify();
|
325
|
+
|
326
|
+
var stat = pify(fs.stat);
|
327
|
+
var readFile = pify(fs.readFile);
|
328
|
+
var resolve = path.resolve;
|
329
|
+
|
330
|
+
var cache = Object.create(null);
|
331
|
+
|
332
|
+
function convert(content, encoding) {
|
333
|
+
if (Buffer.isEncoding(encoding)) {
|
334
|
+
return content.toString(encoding);
|
335
|
+
}
|
336
|
+
return content;
|
337
|
+
}
|
338
|
+
|
339
|
+
readCache.exports = function (path, encoding) {
|
340
|
+
path = resolve(path);
|
341
|
+
|
342
|
+
return stat(path).then(function (stats) {
|
343
|
+
var item = cache[path];
|
344
|
+
|
345
|
+
if (item && item.mtime.getTime() === stats.mtime.getTime()) {
|
346
|
+
return convert(item.content, encoding);
|
347
|
+
}
|
348
|
+
|
349
|
+
return readFile(path).then(function (data) {
|
350
|
+
cache[path] = {
|
351
|
+
mtime: stats.mtime,
|
352
|
+
content: data
|
353
|
+
};
|
354
|
+
|
355
|
+
return convert(data, encoding);
|
356
|
+
});
|
357
|
+
}).catch(function (err) {
|
358
|
+
cache[path] = null;
|
359
|
+
return Promise.reject(err);
|
360
|
+
});
|
361
|
+
};
|
362
|
+
|
363
|
+
readCache.exports.sync = function (path, encoding) {
|
364
|
+
path = resolve(path);
|
365
|
+
|
366
|
+
try {
|
367
|
+
var stats = fs.statSync(path);
|
368
|
+
var item = cache[path];
|
369
|
+
|
370
|
+
if (item && item.mtime.getTime() === stats.mtime.getTime()) {
|
371
|
+
return convert(item.content, encoding);
|
372
|
+
}
|
373
|
+
|
374
|
+
var data = fs.readFileSync(path);
|
375
|
+
|
376
|
+
cache[path] = {
|
377
|
+
mtime: stats.mtime,
|
378
|
+
content: data
|
379
|
+
};
|
380
|
+
|
381
|
+
return convert(data, encoding);
|
382
|
+
} catch (err) {
|
383
|
+
cache[path] = null;
|
384
|
+
throw err;
|
385
|
+
}
|
386
|
+
|
387
|
+
};
|
388
|
+
|
389
|
+
readCache.exports.get = function (path, encoding) {
|
390
|
+
path = resolve(path);
|
391
|
+
if (cache[path]) {
|
392
|
+
return convert(cache[path].content, encoding);
|
393
|
+
}
|
394
|
+
return null;
|
395
|
+
};
|
396
|
+
|
397
|
+
readCache.exports.clear = function () {
|
398
|
+
cache = Object.create(null);
|
399
|
+
};
|
400
|
+
return readCache.exports;
|
401
|
+
}
|
402
|
+
|
403
|
+
var dataUrl;
|
404
|
+
var hasRequiredDataUrl;
|
405
|
+
|
406
|
+
function requireDataUrl () {
|
407
|
+
if (hasRequiredDataUrl) return dataUrl;
|
408
|
+
hasRequiredDataUrl = 1;
|
409
|
+
|
410
|
+
const anyDataURLRegexp = /^data:text\/css(?:;(base64|plain))?,/i;
|
411
|
+
const base64DataURLRegexp = /^data:text\/css;base64,/i;
|
412
|
+
const plainDataURLRegexp = /^data:text\/css;plain,/i;
|
413
|
+
|
414
|
+
function isValid(url) {
|
415
|
+
return anyDataURLRegexp.test(url)
|
416
|
+
}
|
417
|
+
|
418
|
+
function contents(url) {
|
419
|
+
if (base64DataURLRegexp.test(url)) {
|
420
|
+
// "data:text/css;base64,".length === 21
|
421
|
+
return Buffer.from(url.slice(21), "base64").toString()
|
422
|
+
}
|
423
|
+
|
424
|
+
if (plainDataURLRegexp.test(url)) {
|
425
|
+
// "data:text/css;plain,".length === 20
|
426
|
+
return decodeURIComponent(url.slice(20))
|
427
|
+
}
|
428
|
+
|
429
|
+
// "data:text/css,".length === 14
|
430
|
+
return decodeURIComponent(url.slice(14))
|
431
|
+
}
|
432
|
+
|
433
|
+
dataUrl = {
|
434
|
+
isValid,
|
435
|
+
contents,
|
436
|
+
};
|
437
|
+
return dataUrl;
|
438
|
+
}
|
439
|
+
|
440
|
+
var loadContent;
|
441
|
+
var hasRequiredLoadContent;
|
442
|
+
|
443
|
+
function requireLoadContent () {
|
444
|
+
if (hasRequiredLoadContent) return loadContent;
|
445
|
+
hasRequiredLoadContent = 1;
|
446
|
+
|
447
|
+
const readCache = requireReadCache();
|
448
|
+
const dataURL = requireDataUrl();
|
449
|
+
|
450
|
+
loadContent = function loadContent(filename) {
|
451
|
+
if (dataURL.isValid(filename)) {
|
452
|
+
return dataURL.contents(filename)
|
453
|
+
}
|
454
|
+
|
455
|
+
return readCache(filename, "utf-8")
|
456
|
+
};
|
457
|
+
return loadContent;
|
458
|
+
}
|
459
|
+
|
460
|
+
var parseStatements;
|
461
|
+
var hasRequiredParseStatements;
|
462
|
+
|
463
|
+
function requireParseStatements () {
|
464
|
+
if (hasRequiredParseStatements) return parseStatements;
|
465
|
+
hasRequiredParseStatements = 1;
|
466
|
+
|
467
|
+
// external tooling
|
468
|
+
const valueParser = requireLib();
|
469
|
+
|
470
|
+
// extended tooling
|
471
|
+
const { stringify } = valueParser;
|
472
|
+
|
473
|
+
parseStatements = function parseStatements(result, styles, conditions, from) {
|
474
|
+
const statements = [];
|
475
|
+
let nodes = [];
|
476
|
+
|
477
|
+
styles.each(node => {
|
478
|
+
let stmt;
|
479
|
+
if (node.type === "atrule") {
|
480
|
+
if (node.name === "import")
|
481
|
+
stmt = parseImport(result, node, conditions, from);
|
482
|
+
else if (node.name === "charset")
|
483
|
+
stmt = parseCharset(result, node, conditions, from);
|
484
|
+
}
|
485
|
+
|
486
|
+
if (stmt) {
|
487
|
+
if (nodes.length) {
|
488
|
+
statements.push({
|
489
|
+
type: "nodes",
|
490
|
+
nodes,
|
491
|
+
conditions: [...conditions],
|
492
|
+
from,
|
493
|
+
});
|
494
|
+
nodes = [];
|
495
|
+
}
|
496
|
+
statements.push(stmt);
|
497
|
+
} else nodes.push(node);
|
498
|
+
});
|
499
|
+
|
500
|
+
if (nodes.length) {
|
501
|
+
statements.push({
|
502
|
+
type: "nodes",
|
503
|
+
nodes,
|
504
|
+
conditions: [...conditions],
|
505
|
+
from,
|
506
|
+
});
|
507
|
+
}
|
508
|
+
|
509
|
+
return statements
|
510
|
+
};
|
511
|
+
|
512
|
+
function parseCharset(result, atRule, conditions, from) {
|
513
|
+
if (atRule.prev()) {
|
514
|
+
return result.warn("@charset must precede all other statements", {
|
515
|
+
node: atRule,
|
516
|
+
})
|
517
|
+
}
|
518
|
+
return {
|
519
|
+
type: "charset",
|
520
|
+
node: atRule,
|
521
|
+
conditions: [...conditions],
|
522
|
+
from,
|
523
|
+
}
|
524
|
+
}
|
525
|
+
|
526
|
+
function parseImport(result, atRule, conditions, from) {
|
527
|
+
let prev = atRule.prev();
|
528
|
+
|
529
|
+
// `@import` statements may follow other `@import` statements.
|
530
|
+
if (prev) {
|
531
|
+
do {
|
532
|
+
if (
|
533
|
+
prev.type === "comment" ||
|
534
|
+
(prev.type === "atrule" && prev.name === "import")
|
535
|
+
) {
|
536
|
+
prev = prev.prev();
|
537
|
+
continue
|
538
|
+
}
|
539
|
+
|
540
|
+
break
|
541
|
+
} while (prev)
|
542
|
+
}
|
543
|
+
|
544
|
+
// All `@import` statements may be preceded by `@charset` or `@layer` statements.
|
545
|
+
// But the `@import` statements must be consecutive.
|
546
|
+
if (prev) {
|
547
|
+
do {
|
548
|
+
if (
|
549
|
+
prev.type === "comment" ||
|
550
|
+
(prev.type === "atrule" &&
|
551
|
+
(prev.name === "charset" || (prev.name === "layer" && !prev.nodes)))
|
552
|
+
) {
|
553
|
+
prev = prev.prev();
|
554
|
+
continue
|
555
|
+
}
|
556
|
+
|
557
|
+
return result.warn(
|
558
|
+
"@import must precede all other statements (besides @charset or empty @layer)",
|
559
|
+
{ node: atRule },
|
560
|
+
)
|
561
|
+
} while (prev)
|
562
|
+
}
|
563
|
+
|
564
|
+
if (atRule.nodes) {
|
565
|
+
return result.warn(
|
566
|
+
"It looks like you didn't end your @import statement correctly. " +
|
567
|
+
"Child nodes are attached to it.",
|
568
|
+
{ node: atRule },
|
569
|
+
)
|
570
|
+
}
|
571
|
+
|
572
|
+
const params = valueParser(atRule.params).nodes;
|
573
|
+
const stmt = {
|
574
|
+
type: "import",
|
575
|
+
uri: "",
|
576
|
+
fullUri: "",
|
577
|
+
node: atRule,
|
578
|
+
conditions: [...conditions],
|
579
|
+
from,
|
580
|
+
};
|
581
|
+
|
582
|
+
let layer;
|
583
|
+
let media;
|
584
|
+
let supports;
|
585
|
+
|
586
|
+
for (let i = 0; i < params.length; i++) {
|
587
|
+
const node = params[i];
|
588
|
+
|
589
|
+
if (node.type === "space" || node.type === "comment") continue
|
590
|
+
|
591
|
+
if (node.type === "string") {
|
592
|
+
if (stmt.uri) {
|
593
|
+
return result.warn(`Multiple url's in '${atRule.toString()}'`, {
|
594
|
+
node: atRule,
|
595
|
+
})
|
596
|
+
}
|
597
|
+
|
598
|
+
if (!node.value) {
|
599
|
+
return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
|
600
|
+
node: atRule,
|
601
|
+
})
|
602
|
+
}
|
603
|
+
|
604
|
+
stmt.uri = node.value;
|
605
|
+
stmt.fullUri = stringify(node);
|
606
|
+
continue
|
607
|
+
}
|
608
|
+
|
609
|
+
if (node.type === "function" && /^url$/i.test(node.value)) {
|
610
|
+
if (stmt.uri) {
|
611
|
+
return result.warn(`Multiple url's in '${atRule.toString()}'`, {
|
612
|
+
node: atRule,
|
613
|
+
})
|
614
|
+
}
|
615
|
+
|
616
|
+
if (!node.nodes?.[0]?.value) {
|
617
|
+
return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
|
618
|
+
node: atRule,
|
619
|
+
})
|
620
|
+
}
|
621
|
+
|
622
|
+
stmt.uri = node.nodes[0].value;
|
623
|
+
stmt.fullUri = stringify(node);
|
624
|
+
continue
|
625
|
+
}
|
626
|
+
|
627
|
+
if (!stmt.uri) {
|
628
|
+
return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
|
629
|
+
node: atRule,
|
630
|
+
})
|
631
|
+
}
|
632
|
+
|
633
|
+
if (
|
634
|
+
(node.type === "word" || node.type === "function") &&
|
635
|
+
/^layer$/i.test(node.value)
|
636
|
+
) {
|
637
|
+
if (typeof layer !== "undefined") {
|
638
|
+
return result.warn(`Multiple layers in '${atRule.toString()}'`, {
|
639
|
+
node: atRule,
|
640
|
+
})
|
641
|
+
}
|
642
|
+
|
643
|
+
if (typeof supports !== "undefined") {
|
644
|
+
return result.warn(
|
645
|
+
`layers must be defined before support conditions in '${atRule.toString()}'`,
|
646
|
+
{
|
647
|
+
node: atRule,
|
648
|
+
},
|
649
|
+
)
|
650
|
+
}
|
651
|
+
|
652
|
+
if (node.nodes) {
|
653
|
+
layer = stringify(node.nodes);
|
654
|
+
} else {
|
655
|
+
layer = "";
|
656
|
+
}
|
657
|
+
|
658
|
+
continue
|
659
|
+
}
|
660
|
+
|
661
|
+
if (node.type === "function" && /^supports$/i.test(node.value)) {
|
662
|
+
if (typeof supports !== "undefined") {
|
663
|
+
return result.warn(
|
664
|
+
`Multiple support conditions in '${atRule.toString()}'`,
|
665
|
+
{
|
666
|
+
node: atRule,
|
667
|
+
},
|
668
|
+
)
|
669
|
+
}
|
670
|
+
|
671
|
+
supports = stringify(node.nodes);
|
672
|
+
|
673
|
+
continue
|
674
|
+
}
|
675
|
+
|
676
|
+
media = stringify(params.slice(i));
|
677
|
+
break
|
678
|
+
}
|
679
|
+
|
680
|
+
if (!stmt.uri) {
|
681
|
+
return result.warn(`Unable to find uri in '${atRule.toString()}'`, {
|
682
|
+
node: atRule,
|
683
|
+
})
|
684
|
+
}
|
685
|
+
|
686
|
+
if (
|
687
|
+
typeof media !== "undefined" ||
|
688
|
+
typeof layer !== "undefined" ||
|
689
|
+
typeof supports !== "undefined"
|
690
|
+
) {
|
691
|
+
stmt.conditions.push({
|
692
|
+
layer,
|
693
|
+
media,
|
694
|
+
supports,
|
695
|
+
});
|
696
|
+
}
|
697
|
+
|
698
|
+
return stmt
|
699
|
+
}
|
700
|
+
return parseStatements;
|
701
|
+
}
|
702
|
+
|
703
|
+
var processContent;
|
704
|
+
var hasRequiredProcessContent;
|
705
|
+
|
706
|
+
function requireProcessContent () {
|
707
|
+
if (hasRequiredProcessContent) return processContent;
|
708
|
+
hasRequiredProcessContent = 1;
|
709
|
+
|
710
|
+
// builtin tooling
|
711
|
+
const path = require$$0;
|
712
|
+
|
713
|
+
// placeholder tooling
|
714
|
+
let sugarss;
|
715
|
+
|
716
|
+
processContent = function processContent(
|
717
|
+
result,
|
718
|
+
content,
|
719
|
+
filename,
|
720
|
+
options,
|
721
|
+
postcss,
|
722
|
+
) {
|
723
|
+
const { plugins } = options;
|
724
|
+
const ext = path.extname(filename);
|
725
|
+
|
726
|
+
const parserList = [];
|
727
|
+
|
728
|
+
// SugarSS support:
|
729
|
+
if (ext === ".sss") {
|
730
|
+
if (!sugarss) {
|
731
|
+
/* c8 ignore next 3 */
|
732
|
+
try {
|
733
|
+
sugarss = __require('sugarss');
|
734
|
+
} catch {} // Ignore
|
735
|
+
}
|
736
|
+
if (sugarss)
|
737
|
+
return runPostcss(postcss, content, filename, plugins, [sugarss])
|
738
|
+
}
|
739
|
+
|
740
|
+
// Syntax support:
|
741
|
+
if (result.opts.syntax?.parse) {
|
742
|
+
parserList.push(result.opts.syntax.parse);
|
743
|
+
}
|
744
|
+
|
745
|
+
// Parser support:
|
746
|
+
if (result.opts.parser) parserList.push(result.opts.parser);
|
747
|
+
// Try the default as a last resort:
|
748
|
+
parserList.push(null);
|
749
|
+
|
750
|
+
return runPostcss(postcss, content, filename, plugins, parserList)
|
751
|
+
};
|
752
|
+
|
753
|
+
function runPostcss(postcss, content, filename, plugins, parsers, index) {
|
754
|
+
if (!index) index = 0;
|
755
|
+
return postcss(plugins)
|
756
|
+
.process(content, {
|
757
|
+
from: filename,
|
758
|
+
parser: parsers[index],
|
759
|
+
})
|
760
|
+
.catch(err => {
|
761
|
+
// If there's an error, try the next parser
|
762
|
+
index++;
|
763
|
+
// If there are no parsers left, throw it
|
764
|
+
if (index === parsers.length) throw err
|
765
|
+
return runPostcss(postcss, content, filename, plugins, parsers, index)
|
766
|
+
})
|
767
|
+
}
|
768
|
+
return processContent;
|
769
|
+
}
|
770
|
+
|
771
|
+
var parseStyles_1;
|
772
|
+
var hasRequiredParseStyles;
|
773
|
+
|
774
|
+
function requireParseStyles () {
|
775
|
+
if (hasRequiredParseStyles) return parseStyles_1;
|
776
|
+
hasRequiredParseStyles = 1;
|
777
|
+
|
778
|
+
const path = require$$0;
|
779
|
+
|
780
|
+
const dataURL = requireDataUrl();
|
781
|
+
const parseStatements = requireParseStatements();
|
782
|
+
const processContent = requireProcessContent();
|
783
|
+
const resolveId = (id) => id;
|
784
|
+
const formatImportPrelude = requireFormatImportPrelude();
|
785
|
+
|
786
|
+
async function parseStyles(
|
787
|
+
result,
|
788
|
+
styles,
|
789
|
+
options,
|
790
|
+
state,
|
791
|
+
conditions,
|
792
|
+
from,
|
793
|
+
postcss,
|
794
|
+
) {
|
795
|
+
const statements = parseStatements(result, styles, conditions, from);
|
796
|
+
|
797
|
+
for (const stmt of statements) {
|
798
|
+
if (stmt.type !== "import" || !isProcessableURL(stmt.uri)) {
|
799
|
+
continue
|
800
|
+
}
|
801
|
+
|
802
|
+
if (options.filter && !options.filter(stmt.uri)) {
|
803
|
+
// rejected by filter
|
804
|
+
continue
|
805
|
+
}
|
806
|
+
|
807
|
+
await resolveImportId(result, stmt, options, state, postcss);
|
808
|
+
}
|
809
|
+
|
810
|
+
let charset;
|
811
|
+
const imports = [];
|
812
|
+
const bundle = [];
|
813
|
+
|
814
|
+
function handleCharset(stmt) {
|
815
|
+
if (!charset) charset = stmt;
|
816
|
+
// charsets aren't case-sensitive, so convert to lower case to compare
|
817
|
+
else if (
|
818
|
+
stmt.node.params.toLowerCase() !== charset.node.params.toLowerCase()
|
819
|
+
) {
|
820
|
+
throw stmt.node.error(
|
821
|
+
`Incompatible @charset statements:
|
822
|
+
${stmt.node.params} specified in ${stmt.node.source.input.file}
|
823
|
+
${charset.node.params} specified in ${charset.node.source.input.file}`,
|
824
|
+
)
|
825
|
+
}
|
826
|
+
}
|
827
|
+
|
828
|
+
// squash statements and their children
|
829
|
+
statements.forEach(stmt => {
|
830
|
+
if (stmt.type === "charset") handleCharset(stmt);
|
831
|
+
else if (stmt.type === "import") {
|
832
|
+
if (stmt.children) {
|
833
|
+
stmt.children.forEach((child, index) => {
|
834
|
+
if (child.type === "import") imports.push(child);
|
835
|
+
else if (child.type === "charset") handleCharset(child);
|
836
|
+
else bundle.push(child);
|
837
|
+
// For better output
|
838
|
+
if (index === 0) child.parent = stmt;
|
839
|
+
});
|
840
|
+
} else imports.push(stmt);
|
841
|
+
} else if (stmt.type === "nodes") {
|
842
|
+
bundle.push(stmt);
|
843
|
+
}
|
844
|
+
});
|
845
|
+
|
846
|
+
return charset ? [charset, ...imports.concat(bundle)] : imports.concat(bundle)
|
847
|
+
}
|
848
|
+
|
849
|
+
async function resolveImportId(result, stmt, options, state, postcss) {
|
850
|
+
if (dataURL.isValid(stmt.uri)) {
|
851
|
+
// eslint-disable-next-line require-atomic-updates
|
852
|
+
stmt.children = await loadImportContent(
|
853
|
+
result,
|
854
|
+
stmt,
|
855
|
+
stmt.uri,
|
856
|
+
options,
|
857
|
+
state,
|
858
|
+
postcss,
|
859
|
+
);
|
860
|
+
|
861
|
+
return
|
862
|
+
} else if (dataURL.isValid(stmt.from.slice(-1))) {
|
863
|
+
// Data urls can't be used as a base url to resolve imports.
|
864
|
+
throw stmt.node.error(
|
865
|
+
`Unable to import '${stmt.uri}' from a stylesheet that is embedded in a data url`,
|
866
|
+
)
|
867
|
+
}
|
868
|
+
|
869
|
+
const atRule = stmt.node;
|
870
|
+
let sourceFile;
|
871
|
+
if (atRule.source?.input?.file) {
|
872
|
+
sourceFile = atRule.source.input.file;
|
873
|
+
}
|
874
|
+
const base = sourceFile
|
875
|
+
? path.dirname(atRule.source.input.file)
|
876
|
+
: options.root;
|
877
|
+
|
878
|
+
const paths = [await options.resolve(stmt.uri, base, options, atRule)].flat();
|
879
|
+
|
880
|
+
// Ensure that each path is absolute:
|
881
|
+
const resolved = await Promise.all(
|
882
|
+
paths.map(file => {
|
883
|
+
return !path.isAbsolute(file)
|
884
|
+
? resolveId(file)
|
885
|
+
: file
|
886
|
+
}),
|
887
|
+
);
|
888
|
+
|
889
|
+
// Add dependency messages:
|
890
|
+
resolved.forEach(file => {
|
891
|
+
result.messages.push({
|
892
|
+
type: "dependency",
|
893
|
+
plugin: "postcss-import",
|
894
|
+
file,
|
895
|
+
parent: sourceFile,
|
896
|
+
});
|
897
|
+
});
|
898
|
+
|
899
|
+
const importedContent = await Promise.all(
|
900
|
+
resolved.map(file => {
|
901
|
+
return loadImportContent(result, stmt, file, options, state, postcss)
|
902
|
+
}),
|
903
|
+
);
|
904
|
+
|
905
|
+
// Merge loaded statements
|
906
|
+
// eslint-disable-next-line require-atomic-updates
|
907
|
+
stmt.children = importedContent.flat().filter(x => !!x);
|
908
|
+
}
|
909
|
+
|
910
|
+
async function loadImportContent(
|
911
|
+
result,
|
912
|
+
stmt,
|
913
|
+
filename,
|
914
|
+
options,
|
915
|
+
state,
|
916
|
+
postcss,
|
917
|
+
) {
|
918
|
+
const atRule = stmt.node;
|
919
|
+
const { conditions, from } = stmt;
|
920
|
+
const stmtDuplicateCheckKey = conditions
|
921
|
+
.map(condition =>
|
922
|
+
formatImportPrelude(condition.layer, condition.media, condition.supports),
|
923
|
+
)
|
924
|
+
.join(":");
|
925
|
+
|
926
|
+
if (options.skipDuplicates) {
|
927
|
+
// skip files already imported at the same scope
|
928
|
+
if (state.importedFiles[filename]?.[stmtDuplicateCheckKey]) {
|
929
|
+
return
|
930
|
+
}
|
931
|
+
|
932
|
+
// save imported files to skip them next time
|
933
|
+
if (!state.importedFiles[filename]) {
|
934
|
+
state.importedFiles[filename] = {};
|
935
|
+
}
|
936
|
+
state.importedFiles[filename][stmtDuplicateCheckKey] = true;
|
937
|
+
}
|
938
|
+
|
939
|
+
if (from.includes(filename)) {
|
940
|
+
return
|
941
|
+
}
|
942
|
+
|
943
|
+
const content = await options.load(filename, options);
|
944
|
+
|
945
|
+
if (content.trim() === "" && options.warnOnEmpty) {
|
946
|
+
result.warn(`${filename} is empty`, { node: atRule });
|
947
|
+
return
|
948
|
+
}
|
949
|
+
|
950
|
+
// skip previous imported files not containing @import rules
|
951
|
+
if (
|
952
|
+
options.skipDuplicates &&
|
953
|
+
state.hashFiles[content]?.[stmtDuplicateCheckKey]
|
954
|
+
) {
|
955
|
+
return
|
956
|
+
}
|
957
|
+
|
958
|
+
const importedResult = await processContent(
|
959
|
+
result,
|
960
|
+
content,
|
961
|
+
filename,
|
962
|
+
options,
|
963
|
+
postcss,
|
964
|
+
);
|
965
|
+
|
966
|
+
const styles = importedResult.root;
|
967
|
+
result.messages = result.messages.concat(importedResult.messages);
|
968
|
+
|
969
|
+
if (options.skipDuplicates) {
|
970
|
+
const hasImport = styles.some(child => {
|
971
|
+
return child.type === "atrule" && child.name === "import"
|
972
|
+
});
|
973
|
+
if (!hasImport) {
|
974
|
+
// save hash files to skip them next time
|
975
|
+
if (!state.hashFiles[content]) {
|
976
|
+
state.hashFiles[content] = {};
|
977
|
+
}
|
978
|
+
|
979
|
+
state.hashFiles[content][stmtDuplicateCheckKey] = true;
|
980
|
+
}
|
981
|
+
}
|
982
|
+
|
983
|
+
// recursion: import @import from imported file
|
984
|
+
return parseStyles(
|
985
|
+
result,
|
986
|
+
styles,
|
987
|
+
options,
|
988
|
+
state,
|
989
|
+
conditions,
|
990
|
+
[...from, filename],
|
991
|
+
postcss,
|
992
|
+
)
|
993
|
+
}
|
994
|
+
|
995
|
+
function isProcessableURL(uri) {
|
996
|
+
// skip protocol base uri (protocol://url) or protocol-relative
|
997
|
+
if (/^(?:[a-z]+:)?\/\//i.test(uri)) {
|
998
|
+
return false
|
999
|
+
}
|
1000
|
+
|
1001
|
+
// check for fragment or query
|
1002
|
+
try {
|
1003
|
+
// needs a base to parse properly
|
1004
|
+
const url = new URL(uri, "https://example.com");
|
1005
|
+
if (url.search) {
|
1006
|
+
return false
|
1007
|
+
}
|
1008
|
+
} catch {} // Ignore
|
1009
|
+
|
1010
|
+
return true
|
1011
|
+
}
|
1012
|
+
|
1013
|
+
parseStyles_1 = parseStyles;
|
1014
|
+
return parseStyles_1;
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
var postcssImport;
|
1018
|
+
var hasRequiredPostcssImport;
|
1019
|
+
|
1020
|
+
function requirePostcssImport () {
|
1021
|
+
if (hasRequiredPostcssImport) return postcssImport;
|
1022
|
+
hasRequiredPostcssImport = 1;
|
1023
|
+
// builtin tooling
|
1024
|
+
const path = require$$0;
|
1025
|
+
|
1026
|
+
// internal tooling
|
1027
|
+
const applyConditions = requireApplyConditions();
|
1028
|
+
const applyRaws = requireApplyRaws();
|
1029
|
+
const applyStyles = requireApplyStyles();
|
1030
|
+
const loadContent = requireLoadContent();
|
1031
|
+
const parseStyles = requireParseStyles();
|
1032
|
+
const resolveId = (id) => id;
|
1033
|
+
|
1034
|
+
function AtImport(options) {
|
1035
|
+
options = {
|
1036
|
+
root: process.cwd(),
|
1037
|
+
path: [],
|
1038
|
+
skipDuplicates: true,
|
1039
|
+
resolve: resolveId,
|
1040
|
+
load: loadContent,
|
1041
|
+
plugins: [],
|
1042
|
+
addModulesDirectories: [],
|
1043
|
+
warnOnEmpty: true,
|
1044
|
+
...options,
|
1045
|
+
};
|
1046
|
+
|
1047
|
+
options.root = path.resolve(options.root);
|
1048
|
+
|
1049
|
+
// convert string to an array of a single element
|
1050
|
+
if (typeof options.path === "string") options.path = [options.path];
|
1051
|
+
|
1052
|
+
if (!Array.isArray(options.path)) options.path = [];
|
1053
|
+
|
1054
|
+
options.path = options.path.map(p => path.resolve(options.root, p));
|
1055
|
+
|
1056
|
+
return {
|
1057
|
+
postcssPlugin: "postcss-import",
|
1058
|
+
async Once(styles, { result, atRule, postcss }) {
|
1059
|
+
const state = {
|
1060
|
+
importedFiles: {},
|
1061
|
+
hashFiles: {},
|
1062
|
+
};
|
1063
|
+
|
1064
|
+
if (styles.source?.input?.file) {
|
1065
|
+
state.importedFiles[styles.source.input.file] = {};
|
1066
|
+
}
|
1067
|
+
|
1068
|
+
if (options.plugins && !Array.isArray(options.plugins)) {
|
1069
|
+
throw new Error("plugins option must be an array")
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
const bundle = await parseStyles(
|
1073
|
+
result,
|
1074
|
+
styles,
|
1075
|
+
options,
|
1076
|
+
state,
|
1077
|
+
[],
|
1078
|
+
[],
|
1079
|
+
postcss,
|
1080
|
+
);
|
1081
|
+
|
1082
|
+
applyRaws(bundle);
|
1083
|
+
applyConditions(bundle, atRule);
|
1084
|
+
applyStyles(bundle, styles);
|
1085
|
+
},
|
1086
|
+
}
|
1087
|
+
}
|
1088
|
+
|
1089
|
+
AtImport.postcss = true;
|
1090
|
+
|
1091
|
+
postcssImport = AtImport;
|
1092
|
+
return postcssImport;
|
1093
|
+
}
|
1094
|
+
|
1095
|
+
var postcssImportExports = requirePostcssImport();
|
1096
|
+
var index = /*@__PURE__*/getDefaultExportFromCjs(postcssImportExports);
|
1097
|
+
|
1098
|
+
var index$1 = /*#__PURE__*/_mergeNamespaces({
|
1099
|
+
__proto__: null,
|
1100
|
+
default: index
|
1101
|
+
}, [postcssImportExports]);
|
1102
|
+
|
1103
|
+
export { index$1 as i };
|