vite 3.0.9 → 3.1.0-beta.2
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 +46 -116
- package/dist/client/client.mjs +8 -25
- package/dist/client/client.mjs.map +1 -1
- package/dist/node/chunks/dep-4069c338.js +8079 -0
- package/dist/node/chunks/{dep-94c1417a.js → dep-42c2c4e4.js} +67 -13
- package/dist/node/chunks/{dep-25be4b3b.js → dep-6d69fd4f.js} +142 -154
- package/dist/node/chunks/{dep-0fc8e132.js → dep-d66eb979.js} +24026 -23684
- package/dist/node/cli.js +7 -6
- package/dist/node/constants.js +1 -1
- package/dist/node/index.d.ts +31 -23
- package/dist/node/index.js +3 -2
- package/dist/node-cjs/publicUtils.cjs +7 -2
- package/package.json +12 -13
- package/src/client/client.ts +30 -40
- package/types/chokidar.d.ts +1 -1
- package/types/hmrPayload.d.ts +4 -0
- package/types/shims.d.ts +1 -0
- package/dist/node/chunks/dep-9d3f225a.js +0 -8816
|
@@ -272,7 +272,7 @@ var processContent$1 = function processContent(
|
|
|
272
272
|
}
|
|
273
273
|
|
|
274
274
|
// Syntax support:
|
|
275
|
-
if (result.opts.syntax
|
|
275
|
+
if (result.opts.syntax?.parse) {
|
|
276
276
|
parserList.push(result.opts.syntax.parse);
|
|
277
277
|
}
|
|
278
278
|
|
|
@@ -491,6 +491,7 @@ function AtImport(options) {
|
|
|
491
491
|
load: loadContent,
|
|
492
492
|
plugins: [],
|
|
493
493
|
addModulesDirectories: [],
|
|
494
|
+
nameLayer: null,
|
|
494
495
|
...options,
|
|
495
496
|
};
|
|
496
497
|
|
|
@@ -509,9 +510,12 @@ function AtImport(options) {
|
|
|
509
510
|
const state = {
|
|
510
511
|
importedFiles: {},
|
|
511
512
|
hashFiles: {},
|
|
513
|
+
rootFilename: null,
|
|
514
|
+
anonymousLayerCounter: 0,
|
|
512
515
|
};
|
|
513
516
|
|
|
514
|
-
if (styles.source
|
|
517
|
+
if (styles.source?.input?.file) {
|
|
518
|
+
state.rootFilename = styles.source.input.file;
|
|
515
519
|
state.importedFiles[styles.source.input.file] = {};
|
|
516
520
|
}
|
|
517
521
|
|
|
@@ -519,6 +523,10 @@ function AtImport(options) {
|
|
|
519
523
|
throw new Error("plugins option must be an array")
|
|
520
524
|
}
|
|
521
525
|
|
|
526
|
+
if (options.nameLayer && typeof options.nameLayer !== "function") {
|
|
527
|
+
throw new Error("nameLayer option must be a function")
|
|
528
|
+
}
|
|
529
|
+
|
|
522
530
|
return parseStyles(result, styles, options, state, [], []).then(
|
|
523
531
|
bundle => {
|
|
524
532
|
applyRaws(bundle);
|
|
@@ -553,7 +561,30 @@ function AtImport(options) {
|
|
|
553
561
|
if (stmt.type === "import") {
|
|
554
562
|
stmt.node.params = `${stmt.fullUri} ${stmt.media.join(", ")}`;
|
|
555
563
|
} else if (stmt.type === "media") {
|
|
556
|
-
|
|
564
|
+
if (stmt.layer.length) {
|
|
565
|
+
const layerNode = atRule({
|
|
566
|
+
name: "layer",
|
|
567
|
+
params: stmt.layer.filter(layer => layer !== "").join("."),
|
|
568
|
+
source: stmt.node.source,
|
|
569
|
+
});
|
|
570
|
+
|
|
571
|
+
if (stmt.parentMedia?.length) {
|
|
572
|
+
const mediaNode = atRule({
|
|
573
|
+
name: "media",
|
|
574
|
+
params: stmt.parentMedia.join(", "),
|
|
575
|
+
source: stmt.node.source,
|
|
576
|
+
});
|
|
577
|
+
|
|
578
|
+
mediaNode.append(layerNode);
|
|
579
|
+
layerNode.append(stmt.node);
|
|
580
|
+
stmt.node = mediaNode;
|
|
581
|
+
} else {
|
|
582
|
+
layerNode.append(stmt.node);
|
|
583
|
+
stmt.node = layerNode;
|
|
584
|
+
}
|
|
585
|
+
} else {
|
|
586
|
+
stmt.node.params = stmt.media.join(", ");
|
|
587
|
+
}
|
|
557
588
|
} else {
|
|
558
589
|
const { nodes } = stmt;
|
|
559
590
|
const { parent } = nodes[0];
|
|
@@ -642,6 +673,7 @@ function AtImport(options) {
|
|
|
642
673
|
return stmts.reduce((promise, stmt) => {
|
|
643
674
|
return promise.then(() => {
|
|
644
675
|
stmt.media = joinMedia(media, stmt.media || []);
|
|
676
|
+
stmt.parentMedia = media;
|
|
645
677
|
stmt.layer = joinLayer(layer, stmt.layer || []);
|
|
646
678
|
|
|
647
679
|
// skip protocol base uri (protocol://url) or protocol-relative
|
|
@@ -708,7 +740,7 @@ function AtImport(options) {
|
|
|
708
740
|
function resolveImportId(result, stmt, options, state) {
|
|
709
741
|
const atRule = stmt.node;
|
|
710
742
|
let sourceFile;
|
|
711
|
-
if (atRule.source
|
|
743
|
+
if (atRule.source?.input?.file) {
|
|
712
744
|
sourceFile = atRule.source.input.file;
|
|
713
745
|
}
|
|
714
746
|
const base = sourceFile
|
|
@@ -755,18 +787,34 @@ function AtImport(options) {
|
|
|
755
787
|
function loadImportContent(result, stmt, filename, options, state) {
|
|
756
788
|
const atRule = stmt.node;
|
|
757
789
|
const { media, layer } = stmt;
|
|
790
|
+
layer.forEach((layerPart, i) => {
|
|
791
|
+
if (layerPart === "") {
|
|
792
|
+
if (options.nameLayer) {
|
|
793
|
+
layer[i] = options
|
|
794
|
+
.nameLayer(state.anonymousLayerCounter++, state.rootFilename)
|
|
795
|
+
.toString();
|
|
796
|
+
} else {
|
|
797
|
+
throw atRule.error(
|
|
798
|
+
`When using anonymous layers in @import you must also set the "nameLayer" plugin option`
|
|
799
|
+
)
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
});
|
|
803
|
+
|
|
758
804
|
if (options.skipDuplicates) {
|
|
759
805
|
// skip files already imported at the same scope
|
|
760
|
-
if (
|
|
761
|
-
state.importedFiles[filename] &&
|
|
762
|
-
state.importedFiles[filename][media]
|
|
763
|
-
) {
|
|
806
|
+
if (state.importedFiles[filename]?.[media]?.[layer]) {
|
|
764
807
|
return
|
|
765
808
|
}
|
|
766
809
|
|
|
767
810
|
// save imported files to skip them next time
|
|
768
|
-
if (!state.importedFiles[filename])
|
|
769
|
-
|
|
811
|
+
if (!state.importedFiles[filename]) {
|
|
812
|
+
state.importedFiles[filename] = {};
|
|
813
|
+
}
|
|
814
|
+
if (!state.importedFiles[filename][media]) {
|
|
815
|
+
state.importedFiles[filename][media] = {};
|
|
816
|
+
}
|
|
817
|
+
state.importedFiles[filename][media][layer] = true;
|
|
770
818
|
}
|
|
771
819
|
|
|
772
820
|
return Promise.resolve(options.load(filename, options)).then(
|
|
@@ -777,8 +825,9 @@ function AtImport(options) {
|
|
|
777
825
|
}
|
|
778
826
|
|
|
779
827
|
// skip previous imported files not containing @import rules
|
|
780
|
-
if (state.hashFiles[content]
|
|
828
|
+
if (state.hashFiles[content]?.[media]?.[layer]) {
|
|
781
829
|
return
|
|
830
|
+
}
|
|
782
831
|
|
|
783
832
|
return processContent(
|
|
784
833
|
result,
|
|
@@ -796,8 +845,13 @@ function AtImport(options) {
|
|
|
796
845
|
});
|
|
797
846
|
if (!hasImport) {
|
|
798
847
|
// save hash files to skip them next time
|
|
799
|
-
if (!state.hashFiles[content])
|
|
800
|
-
|
|
848
|
+
if (!state.hashFiles[content]) {
|
|
849
|
+
state.hashFiles[content] = {};
|
|
850
|
+
}
|
|
851
|
+
if (!state.hashFiles[content][media]) {
|
|
852
|
+
state.hashFiles[content][media] = {};
|
|
853
|
+
}
|
|
854
|
+
state.hashFiles[content][media][layer] = true;
|
|
801
855
|
}
|
|
802
856
|
}
|
|
803
857
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import require$$0$1 from 'postcss';
|
|
2
|
-
import { z as commonjsGlobal } from './dep-
|
|
2
|
+
import { z as commonjsGlobal } from './dep-d66eb979.js';
|
|
3
3
|
import require$$0 from 'path';
|
|
4
4
|
import require$$5 from 'crypto';
|
|
5
5
|
import require$$0__default from 'fs';
|
|
@@ -1388,19 +1388,21 @@ Object.defineProperty(unquote$1, "__esModule", {
|
|
|
1388
1388
|
});
|
|
1389
1389
|
unquote$1.default = unquote;
|
|
1390
1390
|
// copied from https://github.com/lakenen/node-unquote
|
|
1391
|
-
|
|
1392
1391
|
var reg = /['"]/;
|
|
1393
1392
|
|
|
1394
1393
|
function unquote(str) {
|
|
1395
1394
|
if (!str) {
|
|
1396
1395
|
return "";
|
|
1397
1396
|
}
|
|
1397
|
+
|
|
1398
1398
|
if (reg.test(str.charAt(0))) {
|
|
1399
1399
|
str = str.substr(1);
|
|
1400
1400
|
}
|
|
1401
|
+
|
|
1401
1402
|
if (reg.test(str.charAt(str.length - 1))) {
|
|
1402
1403
|
str = str.substr(0, str.length - 1);
|
|
1403
1404
|
}
|
|
1405
|
+
|
|
1404
1406
|
return str;
|
|
1405
1407
|
}
|
|
1406
1408
|
|
|
@@ -1438,16 +1440,15 @@ lib.default = function (css, translations) {
|
|
|
1438
1440
|
Object.defineProperty(parser$1, "__esModule", {
|
|
1439
1441
|
value: true
|
|
1440
1442
|
});
|
|
1443
|
+
parser$1.default = void 0;
|
|
1441
1444
|
|
|
1442
|
-
var _icssReplaceSymbols = lib;
|
|
1443
|
-
|
|
1444
|
-
var _icssReplaceSymbols2 = _interopRequireDefault$6(_icssReplaceSymbols);
|
|
1445
|
+
var _icssReplaceSymbols = _interopRequireDefault$6(lib);
|
|
1445
1446
|
|
|
1446
1447
|
function _interopRequireDefault$6(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1447
1448
|
|
|
1448
1449
|
// Copied from https://github.com/css-modules/css-modules-loader-core
|
|
1449
|
-
|
|
1450
1450
|
const importRegexp = /^:import\((.+)\)$/;
|
|
1451
|
+
|
|
1451
1452
|
class Parser {
|
|
1452
1453
|
constructor(pathFetcher, trace) {
|
|
1453
1454
|
this.pathFetcher = pathFetcher;
|
|
@@ -1461,9 +1462,11 @@ class Parser {
|
|
|
1461
1462
|
const parser = this;
|
|
1462
1463
|
return {
|
|
1463
1464
|
postcssPlugin: "css-modules-parser",
|
|
1465
|
+
|
|
1464
1466
|
OnceExit(css) {
|
|
1465
1467
|
return Promise.all(parser.fetchAllImports(css)).then(() => parser.linkImportedSymbols(css)).then(() => parser.extractExports(css));
|
|
1466
1468
|
}
|
|
1469
|
+
|
|
1467
1470
|
};
|
|
1468
1471
|
}
|
|
1469
1472
|
|
|
@@ -1478,7 +1481,7 @@ class Parser {
|
|
|
1478
1481
|
}
|
|
1479
1482
|
|
|
1480
1483
|
linkImportedSymbols(css) {
|
|
1481
|
-
(0,
|
|
1484
|
+
(0, _icssReplaceSymbols.default)(css, this.translations);
|
|
1482
1485
|
}
|
|
1483
1486
|
|
|
1484
1487
|
extractExports(css) {
|
|
@@ -1511,7 +1514,9 @@ class Parser {
|
|
|
1511
1514
|
importNode.remove();
|
|
1512
1515
|
}, err => console.log(err));
|
|
1513
1516
|
}
|
|
1517
|
+
|
|
1514
1518
|
}
|
|
1519
|
+
|
|
1515
1520
|
parser$1.default = Parser;
|
|
1516
1521
|
|
|
1517
1522
|
var loader = {};
|
|
@@ -1519,51 +1524,45 @@ var loader = {};
|
|
|
1519
1524
|
Object.defineProperty(loader, "__esModule", {
|
|
1520
1525
|
value: true
|
|
1521
1526
|
});
|
|
1527
|
+
loader.default = void 0;
|
|
1522
1528
|
|
|
1523
|
-
var _postcss$1 = require$$0$1;
|
|
1524
|
-
|
|
1525
|
-
var _postcss2$1 = _interopRequireDefault$5(_postcss$1);
|
|
1526
|
-
|
|
1527
|
-
var _fs$1 = require$$0__default;
|
|
1528
|
-
|
|
1529
|
-
var _fs2 = _interopRequireDefault$5(_fs$1);
|
|
1530
|
-
|
|
1531
|
-
var _path = require$$0;
|
|
1529
|
+
var _postcss$1 = _interopRequireDefault$5(require$$0$1);
|
|
1532
1530
|
|
|
1533
|
-
var
|
|
1531
|
+
var _fs$1 = _interopRequireDefault$5(require$$0__default);
|
|
1534
1532
|
|
|
1535
|
-
var
|
|
1533
|
+
var _path = _interopRequireDefault$5(require$$0);
|
|
1536
1534
|
|
|
1537
|
-
var
|
|
1535
|
+
var _parser$1 = _interopRequireDefault$5(parser$1);
|
|
1538
1536
|
|
|
1539
1537
|
function _interopRequireDefault$5(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1540
1538
|
|
|
1541
1539
|
// Copied from https://github.com/css-modules/css-modules-loader-core
|
|
1542
|
-
|
|
1543
1540
|
class Core {
|
|
1544
1541
|
constructor(plugins) {
|
|
1545
1542
|
this.plugins = plugins || Core.defaultPlugins;
|
|
1546
1543
|
}
|
|
1547
1544
|
|
|
1548
1545
|
load(sourceString, sourcePath, trace, pathFetcher) {
|
|
1549
|
-
let parser = new
|
|
1550
|
-
|
|
1551
|
-
|
|
1546
|
+
let parser = new _parser$1.default(pathFetcher, trace);
|
|
1547
|
+
return (0, _postcss$1.default)(this.plugins.concat([parser.plugin()])).process(sourceString, {
|
|
1548
|
+
from: sourcePath
|
|
1549
|
+
}).then(result => {
|
|
1552
1550
|
return {
|
|
1553
1551
|
injectableSource: result.css,
|
|
1554
1552
|
exportTokens: parser.exportTokens
|
|
1555
1553
|
};
|
|
1556
1554
|
});
|
|
1557
1555
|
}
|
|
1558
|
-
}
|
|
1559
1556
|
|
|
1560
|
-
// Sorts dependencies in the following way:
|
|
1557
|
+
} // Sorts dependencies in the following way:
|
|
1561
1558
|
// AAA comes before AA and A
|
|
1562
1559
|
// AB comes after AA and before A
|
|
1563
1560
|
// All Bs come after all As
|
|
1564
1561
|
// This ensures that the files are always returned in the following order:
|
|
1565
1562
|
// - In the order they were required, except
|
|
1566
1563
|
// - After all their dependencies
|
|
1564
|
+
|
|
1565
|
+
|
|
1567
1566
|
const traceKeySorter = (a, b) => {
|
|
1568
1567
|
if (a.length < b.length) {
|
|
1569
1568
|
return a < b.substring(0, a.length) ? -1 : 1;
|
|
@@ -1576,6 +1575,16 @@ const traceKeySorter = (a, b) => {
|
|
|
1576
1575
|
|
|
1577
1576
|
class FileSystemLoader {
|
|
1578
1577
|
constructor(root, plugins) {
|
|
1578
|
+
if (root === '/' && process.platform === "win32") {
|
|
1579
|
+
const cwdDrive = process.cwd().slice(0, 3);
|
|
1580
|
+
|
|
1581
|
+
if (!/^[A-Z]:\\$/.test(cwdDrive)) {
|
|
1582
|
+
throw new Error(`Failed to obtain root from "${process.cwd()}".`);
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
root = cwdDrive;
|
|
1586
|
+
}
|
|
1587
|
+
|
|
1579
1588
|
this.root = root;
|
|
1580
1589
|
this.sources = {};
|
|
1581
1590
|
this.traces = {};
|
|
@@ -1587,28 +1596,32 @@ class FileSystemLoader {
|
|
|
1587
1596
|
fetch(_newPath, relativeTo, _trace) {
|
|
1588
1597
|
let newPath = _newPath.replace(/^["']|["']$/g, ""),
|
|
1589
1598
|
trace = _trace || String.fromCharCode(this.importNr++);
|
|
1599
|
+
|
|
1590
1600
|
return new Promise((resolve, reject) => {
|
|
1591
|
-
let relativeDir =
|
|
1592
|
-
rootRelativePath =
|
|
1593
|
-
fileRelativePath =
|
|
1601
|
+
let relativeDir = _path.default.dirname(relativeTo),
|
|
1602
|
+
rootRelativePath = _path.default.resolve(relativeDir, newPath),
|
|
1603
|
+
fileRelativePath = _path.default.resolve(_path.default.resolve(this.root, relativeDir), newPath); // if the path is not relative or absolute, try to resolve it in node_modules
|
|
1604
|
+
|
|
1594
1605
|
|
|
1595
|
-
|
|
1596
|
-
if (newPath[0] !== "." && newPath[0] !== "/") {
|
|
1606
|
+
if (newPath[0] !== "." && !_path.default.isAbsolute(newPath)) {
|
|
1597
1607
|
try {
|
|
1598
1608
|
fileRelativePath = require.resolve(newPath);
|
|
1599
|
-
} catch (e) {
|
|
1600
|
-
// noop
|
|
1609
|
+
} catch (e) {// noop
|
|
1601
1610
|
}
|
|
1602
1611
|
}
|
|
1603
1612
|
|
|
1604
1613
|
const tokens = this.tokensByFile[fileRelativePath];
|
|
1614
|
+
|
|
1605
1615
|
if (tokens) {
|
|
1606
1616
|
return resolve(tokens);
|
|
1607
1617
|
}
|
|
1608
1618
|
|
|
1609
|
-
|
|
1619
|
+
_fs$1.default.readFile(fileRelativePath, "utf-8", (err, source) => {
|
|
1610
1620
|
if (err) reject(err);
|
|
1611
|
-
this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({
|
|
1621
|
+
this.core.load(source, rootRelativePath, trace, this.fetch.bind(this)).then(({
|
|
1622
|
+
injectableSource,
|
|
1623
|
+
exportTokens
|
|
1624
|
+
}) => {
|
|
1612
1625
|
this.sources[fileRelativePath] = injectableSource;
|
|
1613
1626
|
this.traces[trace] = fileRelativePath;
|
|
1614
1627
|
this.tokensByFile[fileRelativePath] = exportTokens;
|
|
@@ -1622,18 +1635,20 @@ class FileSystemLoader {
|
|
|
1622
1635
|
const traces = this.traces;
|
|
1623
1636
|
const sources = this.sources;
|
|
1624
1637
|
let written = new Set();
|
|
1625
|
-
|
|
1626
1638
|
return Object.keys(traces).sort(traceKeySorter).map(key => {
|
|
1627
1639
|
const filename = traces[key];
|
|
1640
|
+
|
|
1628
1641
|
if (written.has(filename)) {
|
|
1629
1642
|
return null;
|
|
1630
1643
|
}
|
|
1631
|
-
written.add(filename);
|
|
1632
1644
|
|
|
1645
|
+
written.add(filename);
|
|
1633
1646
|
return sources[filename];
|
|
1634
1647
|
}).join("");
|
|
1635
1648
|
}
|
|
1649
|
+
|
|
1636
1650
|
}
|
|
1651
|
+
|
|
1637
1652
|
loader.default = FileSystemLoader;
|
|
1638
1653
|
|
|
1639
1654
|
var generateScopedName$1 = {};
|
|
@@ -1659,17 +1674,14 @@ Object.defineProperty(generateScopedName$1, "__esModule", {
|
|
|
1659
1674
|
});
|
|
1660
1675
|
generateScopedName$1.default = generateScopedName;
|
|
1661
1676
|
|
|
1662
|
-
var _stringHash = stringHash;
|
|
1663
|
-
|
|
1664
|
-
var _stringHash2 = _interopRequireDefault$4(_stringHash);
|
|
1677
|
+
var _stringHash = _interopRequireDefault$4(stringHash);
|
|
1665
1678
|
|
|
1666
1679
|
function _interopRequireDefault$4(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
1667
1680
|
|
|
1668
1681
|
function generateScopedName(name, filename, css) {
|
|
1669
1682
|
const i = css.indexOf(`.${name}`);
|
|
1670
1683
|
const lineNumber = css.substr(0, i).split(/[\r\n]/).length;
|
|
1671
|
-
const hash = (0,
|
|
1672
|
-
|
|
1684
|
+
const hash = (0, _stringHash.default)(css).toString(36).substr(0, 5);
|
|
1673
1685
|
return `_${name}_${hash}_${lineNumber}`;
|
|
1674
1686
|
}
|
|
1675
1687
|
|
|
@@ -7309,45 +7321,43 @@ src.exports.postcss = true;
|
|
|
7309
7321
|
Object.defineProperty(behaviours$1, "__esModule", {
|
|
7310
7322
|
value: true
|
|
7311
7323
|
});
|
|
7312
|
-
behaviours$1.behaviours =
|
|
7324
|
+
behaviours$1.behaviours = void 0;
|
|
7313
7325
|
behaviours$1.getDefaultPlugins = getDefaultPlugins;
|
|
7314
7326
|
behaviours$1.isValidBehaviour = isValidBehaviour;
|
|
7315
7327
|
|
|
7316
|
-
var _postcssModulesLocalByDefault = src$4.exports;
|
|
7317
|
-
|
|
7318
|
-
var _postcssModulesLocalByDefault2 = _interopRequireDefault$1(_postcssModulesLocalByDefault);
|
|
7319
|
-
|
|
7320
|
-
var _postcssModulesExtractImports = src$2.exports;
|
|
7321
|
-
|
|
7322
|
-
var _postcssModulesExtractImports2 = _interopRequireDefault$1(_postcssModulesExtractImports);
|
|
7323
|
-
|
|
7324
|
-
var _postcssModulesScope = src$1;
|
|
7328
|
+
var _postcssModulesLocalByDefault = _interopRequireDefault$1(src$4.exports);
|
|
7325
7329
|
|
|
7326
|
-
var
|
|
7330
|
+
var _postcssModulesExtractImports = _interopRequireDefault$1(src$2.exports);
|
|
7327
7331
|
|
|
7328
|
-
var
|
|
7332
|
+
var _postcssModulesScope = _interopRequireDefault$1(src$1);
|
|
7329
7333
|
|
|
7330
|
-
var
|
|
7334
|
+
var _postcssModulesValues = _interopRequireDefault$1(src.exports);
|
|
7331
7335
|
|
|
7332
7336
|
function _interopRequireDefault$1(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7333
7337
|
|
|
7334
|
-
const behaviours =
|
|
7338
|
+
const behaviours = {
|
|
7335
7339
|
LOCAL: "local",
|
|
7336
7340
|
GLOBAL: "global"
|
|
7337
7341
|
};
|
|
7342
|
+
behaviours$1.behaviours = behaviours;
|
|
7338
7343
|
|
|
7339
7344
|
function getDefaultPlugins({
|
|
7340
7345
|
behaviour,
|
|
7341
7346
|
generateScopedName,
|
|
7342
7347
|
exportGlobals
|
|
7343
7348
|
}) {
|
|
7344
|
-
const scope = (0,
|
|
7345
|
-
|
|
7349
|
+
const scope = (0, _postcssModulesScope.default)({
|
|
7350
|
+
generateScopedName,
|
|
7351
|
+
exportGlobals
|
|
7352
|
+
});
|
|
7346
7353
|
const plugins = {
|
|
7347
|
-
[behaviours.LOCAL]: [
|
|
7348
|
-
|
|
7354
|
+
[behaviours.LOCAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
|
7355
|
+
mode: 'local'
|
|
7356
|
+
}), _postcssModulesExtractImports.default, scope],
|
|
7357
|
+
[behaviours.GLOBAL]: [_postcssModulesValues.default, (0, _postcssModulesLocalByDefault.default)({
|
|
7358
|
+
mode: 'global'
|
|
7359
|
+
}), _postcssModulesExtractImports.default, scope]
|
|
7349
7360
|
};
|
|
7350
|
-
|
|
7351
7361
|
return plugins[behaviour];
|
|
7352
7362
|
}
|
|
7353
7363
|
|
|
@@ -7355,44 +7365,26 @@ function isValidBehaviour(behaviour) {
|
|
|
7355
7365
|
return Object.keys(behaviours).map(key => behaviours[key]).indexOf(behaviour) > -1;
|
|
7356
7366
|
}
|
|
7357
7367
|
|
|
7358
|
-
var _postcss = require$$0$1;
|
|
7359
|
-
|
|
7360
|
-
var _postcss2 = _interopRequireDefault(_postcss);
|
|
7361
|
-
|
|
7362
|
-
var _lodash = lodash_camelcase;
|
|
7363
|
-
|
|
7364
|
-
var _lodash2 = _interopRequireDefault(_lodash);
|
|
7365
|
-
|
|
7366
|
-
var _genericNames = genericNames;
|
|
7367
|
-
|
|
7368
|
-
var _genericNames2 = _interopRequireDefault(_genericNames);
|
|
7368
|
+
var _postcss = _interopRequireDefault(require$$0$1);
|
|
7369
7369
|
|
|
7370
|
-
var
|
|
7370
|
+
var _lodash = _interopRequireDefault(lodash_camelcase);
|
|
7371
7371
|
|
|
7372
|
-
var
|
|
7372
|
+
var _genericNames = _interopRequireDefault(genericNames);
|
|
7373
7373
|
|
|
7374
|
-
var
|
|
7374
|
+
var _unquote = _interopRequireDefault(unquote$1);
|
|
7375
7375
|
|
|
7376
|
-
var
|
|
7376
|
+
var _parser = _interopRequireDefault(parser$1);
|
|
7377
7377
|
|
|
7378
|
-
var _loader = loader;
|
|
7378
|
+
var _loader = _interopRequireDefault(loader);
|
|
7379
7379
|
|
|
7380
|
-
var
|
|
7380
|
+
var _generateScopedName = _interopRequireDefault(generateScopedName$1);
|
|
7381
7381
|
|
|
7382
|
-
var
|
|
7383
|
-
|
|
7384
|
-
var _generateScopedName2 = _interopRequireDefault(_generateScopedName);
|
|
7385
|
-
|
|
7386
|
-
var _saveJSON = saveJSON$1;
|
|
7387
|
-
|
|
7388
|
-
var _saveJSON2 = _interopRequireDefault(_saveJSON);
|
|
7382
|
+
var _saveJSON = _interopRequireDefault(saveJSON$1);
|
|
7389
7383
|
|
|
7390
7384
|
var _behaviours = behaviours$1;
|
|
7391
7385
|
|
|
7392
7386
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
7393
7387
|
|
|
7394
|
-
function _asyncToGenerator(fn) { return function () { var gen = fn.apply(this, arguments); return new Promise(function (resolve, reject) { function step(key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { return Promise.resolve(value).then(function (value) { step("next", value); }, function (err) { step("throw", err); }); } } return step("next"); }); }; }
|
|
7395
|
-
|
|
7396
7388
|
const PLUGIN_NAME = "postcss-modules";
|
|
7397
7389
|
|
|
7398
7390
|
function getDefaultScopeBehaviour(opts) {
|
|
@@ -7404,10 +7396,9 @@ function getDefaultScopeBehaviour(opts) {
|
|
|
7404
7396
|
}
|
|
7405
7397
|
|
|
7406
7398
|
function getScopedNameGenerator(opts) {
|
|
7407
|
-
const scopedNameGenerator = opts.generateScopedName ||
|
|
7408
|
-
|
|
7399
|
+
const scopedNameGenerator = opts.generateScopedName || _generateScopedName.default;
|
|
7409
7400
|
if (typeof scopedNameGenerator === "function") return scopedNameGenerator;
|
|
7410
|
-
return (0,
|
|
7401
|
+
return (0, _genericNames.default)(scopedNameGenerator, {
|
|
7411
7402
|
context: process.cwd(),
|
|
7412
7403
|
hashPrefix: opts.hashPrefix
|
|
7413
7404
|
});
|
|
@@ -7415,7 +7406,7 @@ function getScopedNameGenerator(opts) {
|
|
|
7415
7406
|
|
|
7416
7407
|
function getLoader(opts, plugins) {
|
|
7417
7408
|
const root = typeof opts.root === "undefined" ? "/" : opts.root;
|
|
7418
|
-
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins) : new
|
|
7409
|
+
return typeof opts.Loader === "function" ? new opts.Loader(root, plugins) : new _loader.default(root, plugins);
|
|
7419
7410
|
}
|
|
7420
7411
|
|
|
7421
7412
|
function isGlobalModule(globalModules, inputFile) {
|
|
@@ -7454,83 +7445,80 @@ function dashesCamelCase(string) {
|
|
|
7454
7445
|
build.exports = (opts = {}) => {
|
|
7455
7446
|
return {
|
|
7456
7447
|
postcssPlugin: PLUGIN_NAME,
|
|
7457
|
-
OnceExit(css, { result }) {
|
|
7458
|
-
return _asyncToGenerator(function* () {
|
|
7459
|
-
const getJSON = opts.getJSON || _saveJSON2.default;
|
|
7460
|
-
const inputFile = css.source.input.file;
|
|
7461
|
-
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
7462
|
-
const resultPluginIndex = result.processor.plugins.findIndex(function (plugin) {
|
|
7463
|
-
return isOurPlugin(plugin);
|
|
7464
|
-
});
|
|
7465
|
-
if (resultPluginIndex === -1) {
|
|
7466
|
-
throw new Error('Plugin missing from options.');
|
|
7467
|
-
}
|
|
7468
|
-
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
7469
|
-
const loaderPlugins = [...earlierPlugins, ...pluginList];
|
|
7470
|
-
const loader = getLoader(opts, loaderPlugins);
|
|
7471
|
-
const fetcher = function fetcher(file, relativeTo, depTrace) {
|
|
7472
|
-
const unquoteFile = (0, _unquote2.default)(file);
|
|
7473
|
-
const resolvedResult = typeof opts.resolve === 'function' && opts.resolve(unquoteFile);
|
|
7474
|
-
const resolvedFile = resolvedResult instanceof Promise ? resolvedResult : Promise.resolve(resolvedResult);
|
|
7475
|
-
|
|
7476
|
-
return resolvedFile.then(function (f) {
|
|
7477
|
-
return loader.fetch.call(loader, `"${f || unquoteFile}"`, relativeTo, depTrace);
|
|
7478
|
-
});
|
|
7479
|
-
};
|
|
7480
|
-
const parser = new _parser2.default(fetcher);
|
|
7481
|
-
|
|
7482
|
-
yield (0, _postcss2.default)([...pluginList, parser.plugin()]).process(css, {
|
|
7483
|
-
from: inputFile
|
|
7484
|
-
});
|
|
7485
7448
|
|
|
7486
|
-
|
|
7487
|
-
|
|
7449
|
+
async OnceExit(css, {
|
|
7450
|
+
result
|
|
7451
|
+
}) {
|
|
7452
|
+
const getJSON = opts.getJSON || _saveJSON.default;
|
|
7453
|
+
const inputFile = css.source.input.file;
|
|
7454
|
+
const pluginList = getDefaultPluginsList(opts, inputFile);
|
|
7455
|
+
const resultPluginIndex = result.processor.plugins.findIndex(plugin => isOurPlugin(plugin));
|
|
7488
7456
|
|
|
7489
|
-
|
|
7490
|
-
|
|
7457
|
+
if (resultPluginIndex === -1) {
|
|
7458
|
+
throw new Error('Plugin missing from options.');
|
|
7459
|
+
}
|
|
7491
7460
|
|
|
7492
|
-
|
|
7493
|
-
|
|
7494
|
-
|
|
7461
|
+
const earlierPlugins = result.processor.plugins.slice(0, resultPluginIndex);
|
|
7462
|
+
const loaderPlugins = [...earlierPlugins, ...pluginList];
|
|
7463
|
+
const loader = getLoader(opts, loaderPlugins);
|
|
7495
7464
|
|
|
7496
|
-
|
|
7497
|
-
|
|
7465
|
+
const fetcher = (file, relativeTo, depTrace) => {
|
|
7466
|
+
const unquoteFile = (0, _unquote.default)(file);
|
|
7467
|
+
const resolvedResult = typeof opts.resolve === 'function' && opts.resolve(unquoteFile);
|
|
7468
|
+
const resolvedFile = resolvedResult instanceof Promise ? resolvedResult : Promise.resolve(resolvedResult);
|
|
7469
|
+
return resolvedFile.then(f => {
|
|
7470
|
+
return loader.fetch.call(loader, `"${f || unquoteFile}"`, relativeTo, depTrace);
|
|
7471
|
+
});
|
|
7472
|
+
};
|
|
7498
7473
|
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7474
|
+
const parser = new _parser.default(fetcher);
|
|
7475
|
+
await (0, _postcss.default)([...pluginList, parser.plugin()]).process(css, {
|
|
7476
|
+
from: inputFile
|
|
7477
|
+
});
|
|
7478
|
+
const out = loader.finalSource;
|
|
7479
|
+
if (out) css.prepend(out);
|
|
7480
|
+
|
|
7481
|
+
if (opts.localsConvention) {
|
|
7482
|
+
const isFunc = typeof opts.localsConvention === "function";
|
|
7483
|
+
parser.exportTokens = Object.entries(parser.exportTokens).reduce((tokens, [className, value]) => {
|
|
7484
|
+
if (isFunc) {
|
|
7485
|
+
tokens[opts.localsConvention(className, value, inputFile)] = value;
|
|
7486
|
+
return tokens;
|
|
7487
|
+
}
|
|
7503
7488
|
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7489
|
+
switch (opts.localsConvention) {
|
|
7490
|
+
case "camelCase":
|
|
7491
|
+
tokens[className] = value;
|
|
7492
|
+
tokens[(0, _lodash.default)(className)] = value;
|
|
7493
|
+
break;
|
|
7507
7494
|
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
tokens[dashesCamelCase(className)] = value;
|
|
7495
|
+
case "camelCaseOnly":
|
|
7496
|
+
tokens[(0, _lodash.default)(className)] = value;
|
|
7497
|
+
break;
|
|
7512
7498
|
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7499
|
+
case "dashes":
|
|
7500
|
+
tokens[className] = value;
|
|
7501
|
+
tokens[dashesCamelCase(className)] = value;
|
|
7502
|
+
break;
|
|
7516
7503
|
|
|
7517
|
-
|
|
7518
|
-
|
|
7504
|
+
case "dashesOnly":
|
|
7505
|
+
tokens[dashesCamelCase(className)] = value;
|
|
7506
|
+
break;
|
|
7507
|
+
}
|
|
7519
7508
|
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7509
|
+
return tokens;
|
|
7510
|
+
}, {});
|
|
7511
|
+
}
|
|
7523
7512
|
|
|
7524
|
-
|
|
7525
|
-
|
|
7526
|
-
|
|
7527
|
-
|
|
7528
|
-
|
|
7513
|
+
result.messages.push({
|
|
7514
|
+
type: "export",
|
|
7515
|
+
plugin: "postcss-modules",
|
|
7516
|
+
exportTokens: parser.exportTokens
|
|
7517
|
+
}); // getJSON may return a promise
|
|
7529
7518
|
|
|
7530
|
-
|
|
7531
|
-
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
7532
|
-
})();
|
|
7519
|
+
return getJSON(css.source.input.file, parser.exportTokens, result.opts.to);
|
|
7533
7520
|
}
|
|
7521
|
+
|
|
7534
7522
|
};
|
|
7535
7523
|
};
|
|
7536
7524
|
|