@plumeria/turbopack-loader 13.2.1 → 13.2.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/dist/index.js +7 -25
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -40,31 +40,12 @@ const path = __importStar(require("path"));
|
|
|
40
40
|
const zss_engine_1 = require("zss-engine");
|
|
41
41
|
const utils_1 = require("@plumeria/utils");
|
|
42
42
|
let lastValidCss = '';
|
|
43
|
-
function cleanStaleThemeRules(currentCss, optInCss) {
|
|
44
|
-
const hashRegex = /--([a-z0-9]{8})-[a-zA-Z0-9-]+:/g;
|
|
45
|
-
const hashes = new Set();
|
|
46
|
-
let match;
|
|
47
|
-
while ((match = hashRegex.exec(optInCss)) !== null) {
|
|
48
|
-
hashes.add(match[1]);
|
|
49
|
-
}
|
|
50
|
-
let cleanedCss = currentCss;
|
|
51
|
-
for (const hash of hashes) {
|
|
52
|
-
const propRegex = new RegExp(`--${hash}-[a-zA-Z0-9-]+:[^}]*?(?:;|(?=\\}))`, 'g');
|
|
53
|
-
cleanedCss = cleanedCss.replace(propRegex, '');
|
|
54
|
-
}
|
|
55
|
-
const emptyBlockRegex = /(?<=^|[}{])[^{}]*\{\s*\}/g;
|
|
56
|
-
let prevCss;
|
|
57
|
-
do {
|
|
58
|
-
prevCss = cleanedCss;
|
|
59
|
-
cleanedCss = cleanedCss.replace(emptyBlockRegex, '');
|
|
60
|
-
} while (cleanedCss !== prevCss);
|
|
61
|
-
return cleanedCss.trim();
|
|
62
|
-
}
|
|
63
43
|
async function loader(source) {
|
|
64
44
|
const callback = this.async();
|
|
65
45
|
const resourcePath = this.resourcePath;
|
|
66
46
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
67
47
|
const VIRTUAL_FILE_PATH = path.resolve(__dirname, '..', 'zero-virtual.css');
|
|
48
|
+
let isThemeCSS = false;
|
|
68
49
|
if (!lastValidCss && !isProduction) {
|
|
69
50
|
try {
|
|
70
51
|
lastValidCss = fs.readFileSync(VIRTUAL_FILE_PATH, 'utf-8');
|
|
@@ -419,6 +400,7 @@ async function loader(source) {
|
|
|
419
400
|
else if (propName === 'createTheme' &&
|
|
420
401
|
init.arguments.length >= 2 &&
|
|
421
402
|
utils_1.t.isObjectExpression(init.arguments[1].expression)) {
|
|
403
|
+
isThemeCSS = true;
|
|
422
404
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
423
405
|
idSpans.add(node.id.span.start);
|
|
424
406
|
}
|
|
@@ -431,7 +413,7 @@ async function loader(source) {
|
|
|
431
413
|
throw new Error(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`);
|
|
432
414
|
}
|
|
433
415
|
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
434
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
416
|
+
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
435
417
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
436
418
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
437
419
|
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
@@ -602,6 +584,7 @@ async function loader(source) {
|
|
|
602
584
|
else if (propName === 'createTheme' &&
|
|
603
585
|
args.length >= 2 &&
|
|
604
586
|
utils_1.t.isObjectExpression(args[1].expression)) {
|
|
587
|
+
isThemeCSS = true;
|
|
605
588
|
let selector = '';
|
|
606
589
|
const selectorExpr = args[0].expression;
|
|
607
590
|
if (utils_1.t.isStringLiteral(selectorExpr)) {
|
|
@@ -611,7 +594,7 @@ async function loader(source) {
|
|
|
611
594
|
throw new Error(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`);
|
|
612
595
|
}
|
|
613
596
|
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
614
|
-
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
597
|
+
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
615
598
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
616
599
|
if (scannedTables.createThemeSelectorTable) {
|
|
617
600
|
scannedTables.createThemeSelectorTable[hash] = selector;
|
|
@@ -1501,9 +1484,8 @@ async function loader(source) {
|
|
|
1501
1484
|
}
|
|
1502
1485
|
catch (e) {
|
|
1503
1486
|
}
|
|
1504
|
-
if (!currentCss.includes(optInCSS)) {
|
|
1505
|
-
const
|
|
1506
|
-
const nextCss = cleanedCss ? cleanedCss + '\n' + newCss : newCss;
|
|
1487
|
+
if (!currentCss.includes(optInCSS) || isThemeCSS) {
|
|
1488
|
+
const nextCss = currentCss + '\n' + newCss;
|
|
1507
1489
|
fs.writeFileSync(VIRTUAL_FILE_PATH, nextCss, 'utf-8');
|
|
1508
1490
|
lastValidCss = nextCss;
|
|
1509
1491
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "13.2.
|
|
3
|
+
"version": "13.2.3",
|
|
4
4
|
"description": "Plumeria Turbopack-loader",
|
|
5
5
|
"author": "Refirst 11",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
"zero-virtual.css"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^13.2.
|
|
25
|
+
"@plumeria/utils": "^13.2.3"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@swc/core": "1.15.
|
|
28
|
+
"@swc/core": "1.15.41",
|
|
29
29
|
"zss-engine": "2.3.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|