@plumeria/turbopack-loader 7.1.2 → 7.2.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 +19 -117
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -9,13 +9,13 @@ 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
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
12
13
|
const VIRTUAL_FILE_PATH = path_1.default.resolve(__dirname, '..', 'zero-virtual.css');
|
|
13
|
-
if (
|
|
14
|
+
if (isProduction) {
|
|
14
15
|
(0, fs_1.writeFileSync)(VIRTUAL_FILE_PATH, '/** Placeholder file */\n', 'utf-8');
|
|
15
16
|
}
|
|
16
17
|
async function loader(source) {
|
|
17
18
|
const callback = this.async();
|
|
18
|
-
const isProduction = process.env.NODE_ENV === 'production';
|
|
19
19
|
if (this.resourcePath.includes('node_modules') ||
|
|
20
20
|
!source.includes('@plumeria/core')) {
|
|
21
21
|
return callback(null, source);
|
|
@@ -36,13 +36,22 @@ async function loader(source) {
|
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
|
-
const scannedTables = (0, utils_1.scanAll)();
|
|
39
|
+
const scannedTables = (0, utils_1.scanAll)(!isProduction);
|
|
40
|
+
const extractedSheets = [];
|
|
41
|
+
const addSheet = (sheet) => {
|
|
42
|
+
if (!extractedSheets.includes(sheet)) {
|
|
43
|
+
extractedSheets.push(sheet);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
if (scannedTables.extractedSheet) {
|
|
47
|
+
addSheet(scannedTables.extractedSheet);
|
|
48
|
+
}
|
|
40
49
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
41
|
-
const resourcePath = this.resourcePath;
|
|
42
50
|
const importMap = {};
|
|
43
51
|
const createThemeImportMap = {};
|
|
44
52
|
const createStaticImportMap = {};
|
|
45
53
|
const plumeriaAliases = {};
|
|
54
|
+
const resourcePath = this.resourcePath;
|
|
46
55
|
(0, utils_1.traverse)(ast, {
|
|
47
56
|
ImportDeclaration({ node }) {
|
|
48
57
|
const sourcePath = node.source.value;
|
|
@@ -165,18 +174,9 @@ async function loader(source) {
|
|
|
165
174
|
}
|
|
166
175
|
const localCreateStyles = {};
|
|
167
176
|
const replacements = [];
|
|
168
|
-
const extractedSheets = [];
|
|
169
|
-
const addSheet = (sheet) => {
|
|
170
|
-
if (!extractedSheets.includes(sheet)) {
|
|
171
|
-
extractedSheets.push(sheet);
|
|
172
|
-
}
|
|
173
|
-
};
|
|
174
177
|
const processedDecls = new Set();
|
|
175
178
|
const idSpans = new Set();
|
|
176
179
|
const excludedSpans = new Set();
|
|
177
|
-
if (scannedTables.extractedSheet) {
|
|
178
|
-
addSheet(scannedTables.extractedSheet);
|
|
179
|
-
}
|
|
180
180
|
const checkVariantAssignment = (decl) => {
|
|
181
181
|
if (decl.init &&
|
|
182
182
|
utils_1.t.isCallExpression(decl.init) &&
|
|
@@ -269,10 +269,7 @@ async function loader(source) {
|
|
|
269
269
|
}
|
|
270
270
|
return undefined;
|
|
271
271
|
});
|
|
272
|
-
const { hashMap
|
|
273
|
-
if (!isProduction) {
|
|
274
|
-
sheets.forEach(addSheet);
|
|
275
|
-
}
|
|
272
|
+
const { hashMap } = (0, utils_1.processVariants)(obj);
|
|
276
273
|
localCreateStyles[node.id.value] = {
|
|
277
274
|
name: node.id.value,
|
|
278
275
|
type: 'variant',
|
|
@@ -375,9 +372,6 @@ async function loader(source) {
|
|
|
375
372
|
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
376
373
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
377
374
|
scannedTables.keyframesObjectTable[hash] = obj;
|
|
378
|
-
if (!isProduction) {
|
|
379
|
-
(0, utils_1.extractOndemandStyles)({ kf: `kf-${hash}` }, extractedSheets, scannedTables);
|
|
380
|
-
}
|
|
381
375
|
replacements.push({
|
|
382
376
|
start: node.span.start - ast.span.start,
|
|
383
377
|
end: node.span.end - ast.span.start,
|
|
@@ -390,9 +384,6 @@ async function loader(source) {
|
|
|
390
384
|
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
391
385
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
392
386
|
scannedTables.viewTransitionObjectTable[hash] = obj;
|
|
393
|
-
if (!isProduction) {
|
|
394
|
-
(0, utils_1.extractOndemandStyles)({ vt: `vt-${hash}` }, extractedSheets, scannedTables);
|
|
395
|
-
}
|
|
396
387
|
replacements.push({
|
|
397
388
|
start: node.span.start - ast.span.start,
|
|
398
389
|
end: node.span.end - ast.span.start,
|
|
@@ -423,15 +414,6 @@ async function loader(source) {
|
|
|
423
414
|
const obj = (0, utils_1.objectExpressionToObject)(args[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
424
415
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
425
416
|
scannedTables.createObjectTable[hash] = obj;
|
|
426
|
-
Object.entries(obj).forEach(([_key, style]) => {
|
|
427
|
-
if (typeof style === 'object' && style !== null) {
|
|
428
|
-
const records = (0, utils_1.getStyleRecords)(style);
|
|
429
|
-
if (!isProduction) {
|
|
430
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
431
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
432
|
-
}
|
|
433
|
-
}
|
|
434
|
-
});
|
|
435
417
|
}
|
|
436
418
|
}
|
|
437
419
|
},
|
|
@@ -496,63 +478,11 @@ async function loader(source) {
|
|
|
496
478
|
return;
|
|
497
479
|
const styleInfo = localCreateStyles[node.value];
|
|
498
480
|
if (styleInfo) {
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
.map((key) => {
|
|
505
|
-
const mapObj = hashMap[key];
|
|
506
|
-
if (typeof mapObj === 'string') {
|
|
507
|
-
return `classes.push("${mapObj}");`;
|
|
508
|
-
}
|
|
509
|
-
const mapStr = JSON.stringify(mapObj);
|
|
510
|
-
return `
|
|
511
|
-
var v${key} = ${mapStr};
|
|
512
|
-
if (props["${key}"] && v${key}[props["${key}"]]) {
|
|
513
|
-
classes.push(v${key}[props["${key}"]]);
|
|
514
|
-
} else if (v${key}["default"]) {
|
|
515
|
-
classes.push(v${key}["default"]);
|
|
516
|
-
}
|
|
517
|
-
`;
|
|
518
|
-
})
|
|
519
|
-
.join('\n');
|
|
520
|
-
const compoundChecks = compoundGroups
|
|
521
|
-
.map((group) => {
|
|
522
|
-
const keys = group.keys;
|
|
523
|
-
const mapObj = group.map;
|
|
524
|
-
const mapStr = JSON.stringify(mapObj);
|
|
525
|
-
const keyExpr = keys
|
|
526
|
-
.map((k) => `(props["${k}"] || "default")`)
|
|
527
|
-
.join(' + ":" + ');
|
|
528
|
-
return `
|
|
529
|
-
var c${keys.join('_')} = ${mapStr};
|
|
530
|
-
var k = ${keyExpr};
|
|
531
|
-
if (c${keys.join('_')}[k]) {
|
|
532
|
-
classes.push(c${keys.join('_')}[k]);
|
|
533
|
-
}
|
|
534
|
-
`;
|
|
535
|
-
})
|
|
536
|
-
.join('\n');
|
|
537
|
-
const runtimeFn = `(props) => {
|
|
538
|
-
var classes = [];
|
|
539
|
-
${independentChecks}
|
|
540
|
-
${compoundChecks}
|
|
541
|
-
return classes.join(" ");
|
|
542
|
-
}`;
|
|
543
|
-
replacements.push({
|
|
544
|
-
start: node.span.start - ast.span.start,
|
|
545
|
-
end: node.span.end - ast.span.start,
|
|
546
|
-
content: runtimeFn,
|
|
547
|
-
});
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
replacements.push({
|
|
551
|
-
start: node.span.start - ast.span.start,
|
|
552
|
-
end: node.span.end - ast.span.start,
|
|
553
|
-
content: JSON.stringify(styleInfo.hashMap),
|
|
554
|
-
});
|
|
555
|
-
}
|
|
481
|
+
replacements.push({
|
|
482
|
+
start: node.span.start - ast.span.start,
|
|
483
|
+
end: node.span.end - ast.span.start,
|
|
484
|
+
content: JSON.stringify(styleInfo.hashMap),
|
|
485
|
+
});
|
|
556
486
|
return;
|
|
557
487
|
}
|
|
558
488
|
const varName = node.value;
|
|
@@ -900,13 +830,7 @@ async function loader(source) {
|
|
|
900
830
|
if (isOptimizable &&
|
|
901
831
|
(args.length > 0 || Object.keys(baseStyle).length > 0)) {
|
|
902
832
|
if (conditionals.length === 0) {
|
|
903
|
-
if (!isProduction) {
|
|
904
|
-
(0, utils_1.extractOndemandStyles)(baseStyle, extractedSheets, scannedTables);
|
|
905
|
-
}
|
|
906
833
|
const records = (0, utils_1.getStyleRecords)(baseStyle);
|
|
907
|
-
if (!isProduction) {
|
|
908
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
909
|
-
}
|
|
910
834
|
const className = records.map((r) => r.hash).join(' ');
|
|
911
835
|
replacements.push({
|
|
912
836
|
start: node.span.start - ast.span.start,
|
|
@@ -1016,13 +940,7 @@ async function loader(source) {
|
|
|
1016
940
|
conditionals.forEach(splitConditional);
|
|
1017
941
|
const classParts = [];
|
|
1018
942
|
if (Object.keys(baseIndependent).length > 0) {
|
|
1019
|
-
if (!isProduction) {
|
|
1020
|
-
(0, utils_1.extractOndemandStyles)(baseIndependent, extractedSheets, scannedTables);
|
|
1021
|
-
}
|
|
1022
943
|
const records = (0, utils_1.getStyleRecords)(baseIndependent);
|
|
1023
|
-
if (!isProduction) {
|
|
1024
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1025
|
-
}
|
|
1026
944
|
const className = records.map((r) => r.hash).join(' ');
|
|
1027
945
|
if (className)
|
|
1028
946
|
classParts.push(JSON.stringify(className));
|
|
@@ -1032,11 +950,7 @@ async function loader(source) {
|
|
|
1032
950
|
const processBranch = (style) => {
|
|
1033
951
|
if (Object.keys(style).length === 0)
|
|
1034
952
|
return '""';
|
|
1035
|
-
if (!isProduction)
|
|
1036
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
1037
953
|
const records = (0, utils_1.getStyleRecords)(style);
|
|
1038
|
-
if (!isProduction)
|
|
1039
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1040
954
|
return JSON.stringify(records.map((r) => r.hash).join(' '));
|
|
1041
955
|
};
|
|
1042
956
|
const tClass = processBranch(c.truthy);
|
|
@@ -1075,11 +989,7 @@ async function loader(source) {
|
|
|
1075
989
|
}
|
|
1076
990
|
options.forEach((opt) => {
|
|
1077
991
|
if (opt.valueName && opt.truthy) {
|
|
1078
|
-
if (!isProduction)
|
|
1079
|
-
(0, utils_1.extractOndemandStyles)(opt.truthy, extractedSheets, scannedTables);
|
|
1080
992
|
const records = (0, utils_1.getStyleRecords)(opt.truthy);
|
|
1081
|
-
if (!isProduction)
|
|
1082
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1083
993
|
const className = records.map((r) => r.hash).join(' ');
|
|
1084
994
|
if (className) {
|
|
1085
995
|
lookupMap[opt.valueName] = className;
|
|
@@ -1152,11 +1062,7 @@ async function loader(source) {
|
|
|
1152
1062
|
const results = {};
|
|
1153
1063
|
const recurse = (dimIndex, currentStyle, keyParts) => {
|
|
1154
1064
|
if (dimIndex >= dimensions.length) {
|
|
1155
|
-
if (!isProduction)
|
|
1156
|
-
(0, utils_1.extractOndemandStyles)(currentStyle, extractedSheets, scannedTables);
|
|
1157
1065
|
const records = (0, utils_1.getStyleRecords)(currentStyle);
|
|
1158
|
-
if (!isProduction)
|
|
1159
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1160
1066
|
const className = records.map((r) => r.hash).join(' ');
|
|
1161
1067
|
const finalKey = keyParts.join('__');
|
|
1162
1068
|
if (className)
|
|
@@ -1175,11 +1081,7 @@ async function loader(source) {
|
|
|
1175
1081
|
recurse(0, baseConflict, []);
|
|
1176
1082
|
let baseConflictClass = '';
|
|
1177
1083
|
if (Object.keys(baseConflict).length > 0) {
|
|
1178
|
-
if (!isProduction)
|
|
1179
|
-
(0, utils_1.extractOndemandStyles)(baseConflict, extractedSheets, scannedTables);
|
|
1180
1084
|
const records = (0, utils_1.getStyleRecords)(baseConflict);
|
|
1181
|
-
if (!isProduction)
|
|
1182
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
1183
1085
|
baseConflictClass = records.map((r) => r.hash).join(' ');
|
|
1184
1086
|
}
|
|
1185
1087
|
const keyExprs = [];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.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": "^7.
|
|
25
|
+
"@plumeria/utils": "^7.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|