@plumeria/turbopack-loader 14.0.0 → 14.1.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/dist/index.js +13 -3
- package/dist/split-css-rules.d.ts +1 -0
- package/dist/split-css-rules.js +71 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -39,6 +39,7 @@ const fs = __importStar(require("fs"));
|
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const zss_engine_1 = require("zss-engine");
|
|
41
41
|
const utils_1 = require("@plumeria/utils");
|
|
42
|
+
const split_css_rules_1 = require("./split-css-rules");
|
|
42
43
|
let lastValidCss = '';
|
|
43
44
|
async function loader(source) {
|
|
44
45
|
const callback = this.async();
|
|
@@ -1540,15 +1541,24 @@ async function loader(source) {
|
|
|
1540
1541
|
return callback(null, transformedSource);
|
|
1541
1542
|
}
|
|
1542
1543
|
if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
|
|
1543
|
-
const newCss = optInCSS + '\n';
|
|
1544
1544
|
let currentCss = '';
|
|
1545
1545
|
try {
|
|
1546
1546
|
currentCss = fs.readFileSync(VIRTUAL_FILE_PATH, 'utf-8');
|
|
1547
1547
|
}
|
|
1548
1548
|
catch (e) {
|
|
1549
1549
|
}
|
|
1550
|
-
|
|
1551
|
-
|
|
1550
|
+
const currentRules = (0, split_css_rules_1.splitCssRules)(currentCss);
|
|
1551
|
+
const newRules = (0, split_css_rules_1.splitCssRules)(optInCSS);
|
|
1552
|
+
const ruleSet = new Set(currentRules);
|
|
1553
|
+
let hasNewRule = false;
|
|
1554
|
+
for (const rule of newRules) {
|
|
1555
|
+
if (!ruleSet.has(rule)) {
|
|
1556
|
+
ruleSet.add(rule);
|
|
1557
|
+
hasNewRule = true;
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
if (hasNewRule || isThemeCSS) {
|
|
1561
|
+
const nextCss = Array.from(ruleSet).join('\n\n') + '\n';
|
|
1552
1562
|
fs.writeFileSync(VIRTUAL_FILE_PATH, nextCss, 'utf-8');
|
|
1553
1563
|
lastValidCss = nextCss;
|
|
1554
1564
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function splitCssRules(css: string): string[];
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.splitCssRules = splitCssRules;
|
|
4
|
+
function splitCssRules(css) {
|
|
5
|
+
const rules = [];
|
|
6
|
+
let currentRule = '';
|
|
7
|
+
let depth = 0;
|
|
8
|
+
let inComment = false;
|
|
9
|
+
let inString = null;
|
|
10
|
+
for (let i = 0; i < css.length; i++) {
|
|
11
|
+
const char = css[i];
|
|
12
|
+
const nextChar = css[i + 1];
|
|
13
|
+
if (inComment) {
|
|
14
|
+
currentRule += char;
|
|
15
|
+
if (char === '*' && nextChar === '/') {
|
|
16
|
+
currentRule += '/';
|
|
17
|
+
i++;
|
|
18
|
+
inComment = false;
|
|
19
|
+
}
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
if (char === '/' && nextChar === '*') {
|
|
23
|
+
currentRule += '/*';
|
|
24
|
+
i++;
|
|
25
|
+
inComment = true;
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
if (inString) {
|
|
29
|
+
currentRule += char;
|
|
30
|
+
if (char === '\\') {
|
|
31
|
+
if (nextChar) {
|
|
32
|
+
currentRule += nextChar;
|
|
33
|
+
i++;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else if (char === inString) {
|
|
37
|
+
inString = null;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (char === '"' || char === "'") {
|
|
42
|
+
currentRule += char;
|
|
43
|
+
inString = char;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
currentRule += char;
|
|
47
|
+
if (char === '{') {
|
|
48
|
+
depth++;
|
|
49
|
+
}
|
|
50
|
+
else if (char === '}') {
|
|
51
|
+
depth--;
|
|
52
|
+
if (depth === 0) {
|
|
53
|
+
const trimmed = currentRule.trim();
|
|
54
|
+
if (trimmed)
|
|
55
|
+
rules.push(trimmed);
|
|
56
|
+
currentRule = '';
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (char === ';' && depth === 0) {
|
|
60
|
+
const trimmed = currentRule.trim();
|
|
61
|
+
if (trimmed)
|
|
62
|
+
rules.push(trimmed);
|
|
63
|
+
currentRule = '';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
const trimmed = currentRule.trim();
|
|
67
|
+
if (trimmed && depth === 0) {
|
|
68
|
+
rules.push(trimmed);
|
|
69
|
+
}
|
|
70
|
+
return rules;
|
|
71
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "14.
|
|
3
|
+
"version": "14.1.0",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^14.
|
|
25
|
+
"@plumeria/utils": "^14.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.41",
|