@plumeria/turbopack-loader 6.3.0 → 6.3.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/dist/index.js +87 -41
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -5,13 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = loader;
|
|
7
7
|
const core_1 = require("@swc/core");
|
|
8
|
-
const fs_1 =
|
|
8
|
+
const fs_1 = require("fs");
|
|
9
9
|
const path_1 = __importDefault(require("path"));
|
|
10
10
|
const zss_engine_1 = require("zss-engine");
|
|
11
11
|
const utils_1 = require("@plumeria/utils");
|
|
12
12
|
const VIRTUAL_FILE_PATH = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
|
|
13
13
|
if (process.env.NODE_ENV === 'production') {
|
|
14
|
-
fs_1.
|
|
14
|
+
(0, fs_1.writeFileSync)(VIRTUAL_FILE_PATH, '/** Placeholder file */\n', 'utf-8');
|
|
15
15
|
}
|
|
16
16
|
async function loader(source) {
|
|
17
17
|
const callback = this.async();
|
|
@@ -221,7 +221,7 @@ async function loader(source) {
|
|
|
221
221
|
if (obj) {
|
|
222
222
|
const hashMap = {};
|
|
223
223
|
Object.entries(obj).forEach(([key, style]) => {
|
|
224
|
-
const records = (0, utils_1.getStyleRecords)(key, style
|
|
224
|
+
const records = (0, utils_1.getStyleRecords)(key, style);
|
|
225
225
|
if (!isProduction) {
|
|
226
226
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
227
227
|
records.forEach((r) => {
|
|
@@ -371,6 +371,9 @@ async function loader(source) {
|
|
|
371
371
|
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
372
372
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
373
373
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
374
|
+
if (!isProduction) {
|
|
375
|
+
(0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
376
|
+
}
|
|
374
377
|
replacements.push({
|
|
375
378
|
start: node.span.start - ast.span.start,
|
|
376
379
|
end: node.span.end - ast.span.start,
|
|
@@ -418,7 +421,7 @@ async function loader(source) {
|
|
|
418
421
|
scannedTables.createObjectTable[hash] = obj;
|
|
419
422
|
Object.entries(obj).forEach(([key, style]) => {
|
|
420
423
|
if (typeof style === 'object' && style !== null) {
|
|
421
|
-
const records = (0, utils_1.getStyleRecords)(key, style
|
|
424
|
+
const records = (0, utils_1.getStyleRecords)(key, style);
|
|
422
425
|
if (!isProduction) {
|
|
423
426
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
424
427
|
records.forEach((r) => addSheet(r.sheet));
|
|
@@ -769,7 +772,7 @@ async function loader(source) {
|
|
|
769
772
|
(0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
|
|
770
773
|
}
|
|
771
774
|
const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
|
|
772
|
-
const records = (0, utils_1.getStyleRecords)(hash, baseStyle
|
|
775
|
+
const records = (0, utils_1.getStyleRecords)(hash, baseStyle);
|
|
773
776
|
if (!isProduction) {
|
|
774
777
|
records.forEach((r) => addSheet(r.sheet));
|
|
775
778
|
}
|
|
@@ -782,35 +785,49 @@ async function loader(source) {
|
|
|
782
785
|
}
|
|
783
786
|
else {
|
|
784
787
|
const table = {};
|
|
785
|
-
const
|
|
786
|
-
|
|
788
|
+
const groups = {};
|
|
789
|
+
let strayIdCounter = groupIdCounter + 1;
|
|
790
|
+
conditionals.forEach((c) => {
|
|
791
|
+
const gid = c.groupId !== undefined ? c.groupId : strayIdCounter++;
|
|
792
|
+
if (!groups[gid]) {
|
|
793
|
+
groups[gid] = [];
|
|
794
|
+
}
|
|
795
|
+
groups[gid].push(c);
|
|
796
|
+
});
|
|
797
|
+
const sortedGroupIds = Object.keys(groups)
|
|
798
|
+
.map(Number)
|
|
799
|
+
.sort((a, b) => a - b);
|
|
800
|
+
let totalCombinations = 1;
|
|
801
|
+
const groupMeta = sortedGroupIds.map((gid) => {
|
|
802
|
+
const options = groups[gid];
|
|
803
|
+
const isVariantGroup = options[0].groupId !== undefined;
|
|
804
|
+
const size = isVariantGroup ? options.length : 2;
|
|
805
|
+
const stride = totalCombinations;
|
|
806
|
+
totalCombinations *= size;
|
|
807
|
+
return { gid, options, size, stride, isVariantGroup };
|
|
808
|
+
});
|
|
809
|
+
for (let i = 0; i < totalCombinations; i++) {
|
|
787
810
|
let currentStyle = { ...baseStyle };
|
|
788
|
-
const
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
if (conditionals[j].groupId !== undefined) {
|
|
793
|
-
if (seenGroups.has(conditionals[j].groupId)) {
|
|
794
|
-
impossible = true;
|
|
795
|
-
break;
|
|
796
|
-
}
|
|
797
|
-
seenGroups.add(conditionals[j].groupId);
|
|
798
|
-
}
|
|
799
|
-
currentStyle = (0, utils_1.deepMerge)(currentStyle, conditionals[j].truthy);
|
|
811
|
+
for (const meta of groupMeta) {
|
|
812
|
+
const localIndex = Math.floor(i / meta.stride) % meta.size;
|
|
813
|
+
if (meta.isVariantGroup) {
|
|
814
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, meta.options[localIndex].truthy);
|
|
800
815
|
}
|
|
801
816
|
else {
|
|
802
|
-
|
|
817
|
+
const cond = meta.options[0];
|
|
818
|
+
if (localIndex === 1) {
|
|
819
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.truthy);
|
|
820
|
+
}
|
|
821
|
+
else {
|
|
822
|
+
currentStyle = (0, utils_1.deepMerge)(currentStyle, cond.falsy);
|
|
823
|
+
}
|
|
803
824
|
}
|
|
804
825
|
}
|
|
805
|
-
if (impossible) {
|
|
806
|
-
table[i] = '';
|
|
807
|
-
continue;
|
|
808
|
-
}
|
|
809
826
|
if (process.env.NODE_ENV !== 'production') {
|
|
810
827
|
(0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
|
|
811
828
|
}
|
|
812
829
|
const hash = (0, zss_engine_1.genBase36Hash)(currentStyle, 1, 8);
|
|
813
|
-
const records = (0, utils_1.getStyleRecords)(hash, currentStyle
|
|
830
|
+
const records = (0, utils_1.getStyleRecords)(hash, currentStyle);
|
|
814
831
|
if (process.env.NODE_ENV !== 'production') {
|
|
815
832
|
records.forEach((r) => extractedSheets.push(r.sheet));
|
|
816
833
|
}
|
|
@@ -819,22 +836,50 @@ async function loader(source) {
|
|
|
819
836
|
.join(' ');
|
|
820
837
|
table[i] = className;
|
|
821
838
|
}
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
839
|
+
const indexParts = [];
|
|
840
|
+
for (const meta of groupMeta) {
|
|
841
|
+
if (meta.isVariantGroup) {
|
|
842
|
+
const exprs = meta.options
|
|
843
|
+
.map((opt, idx) => {
|
|
844
|
+
if (idx === 0)
|
|
845
|
+
return null;
|
|
846
|
+
let testStr = opt.testString;
|
|
847
|
+
if (!testStr && opt.test) {
|
|
848
|
+
const start = opt.test.span.start - ast.span.start;
|
|
849
|
+
const end = opt.test.span.end - ast.span.start;
|
|
850
|
+
testStr = source.substring(start, end);
|
|
851
|
+
}
|
|
852
|
+
return `(!!(${testStr}) * ${idx})`;
|
|
853
|
+
})
|
|
854
|
+
.filter(Boolean);
|
|
855
|
+
if (exprs.length > 0) {
|
|
856
|
+
const groupSum = `(${exprs.join(' + ')})`;
|
|
857
|
+
if (meta.stride > 1) {
|
|
858
|
+
indexParts.push(`(${groupSum} * ${meta.stride})`);
|
|
859
|
+
}
|
|
860
|
+
else {
|
|
861
|
+
indexParts.push(groupSum);
|
|
862
|
+
}
|
|
830
863
|
}
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
const
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
864
|
+
}
|
|
865
|
+
else {
|
|
866
|
+
const cond = meta.options[0];
|
|
867
|
+
let testStr = cond.testString;
|
|
868
|
+
if (!testStr && cond.test) {
|
|
869
|
+
const start = cond.test.span.start - ast.span.start;
|
|
870
|
+
const end = cond.test.span.end - ast.span.start;
|
|
871
|
+
testStr = source.substring(start, end);
|
|
872
|
+
}
|
|
873
|
+
const expr = `(!!(${testStr}))`;
|
|
874
|
+
if (meta.stride > 1) {
|
|
875
|
+
indexParts.push(`(${expr} * ${meta.stride})`);
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
indexParts.push(`(${expr} * 1)`);
|
|
879
|
+
}
|
|
880
|
+
}
|
|
837
881
|
}
|
|
882
|
+
const indexExpr = indexParts.join(' + ') || '0';
|
|
838
883
|
const tableStr = JSON.stringify(table);
|
|
839
884
|
const replacement = `${tableStr}[${indexExpr}]`;
|
|
840
885
|
replacements.push({
|
|
@@ -848,7 +893,7 @@ async function loader(source) {
|
|
|
848
893
|
},
|
|
849
894
|
});
|
|
850
895
|
Object.values(localCreateStyles).forEach((info) => {
|
|
851
|
-
if (info.type === 'constant'
|
|
896
|
+
if (info.type === 'constant') {
|
|
852
897
|
return;
|
|
853
898
|
}
|
|
854
899
|
if (info.isExported) {
|
|
@@ -866,6 +911,7 @@ async function loader(source) {
|
|
|
866
911
|
});
|
|
867
912
|
}
|
|
868
913
|
});
|
|
914
|
+
const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
|
|
869
915
|
const buffer = Buffer.from(source);
|
|
870
916
|
let offset = 0;
|
|
871
917
|
const parts = [];
|
|
@@ -899,7 +945,7 @@ async function loader(source) {
|
|
|
899
945
|
if (process.env.NODE_ENV === 'production')
|
|
900
946
|
return callback(null, transformedSource);
|
|
901
947
|
if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
|
|
902
|
-
fs_1.
|
|
948
|
+
(0, fs_1.appendFileSync)(VIRTUAL_FILE_PATH, optInCSS, 'utf-8');
|
|
903
949
|
}
|
|
904
950
|
return callback(null, transformedSource + postfix);
|
|
905
951
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "6.3.
|
|
3
|
+
"version": "6.3.2",
|
|
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": "^6.3.
|
|
25
|
+
"@plumeria/utils": "^6.3.2"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|