@plumeria/turbopack-loader 13.2.2 → 14.0.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 +67 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -69,6 +69,25 @@ async function loader(source) {
|
|
|
69
69
|
const sourceBuffer = Buffer.from(source, 'utf-8');
|
|
70
70
|
const leadingBytes = Buffer.byteLength(source.slice(0, leadingLen), 'utf-8');
|
|
71
71
|
const baseByteOffset = ast.span.start - leadingBytes;
|
|
72
|
+
const throwCompilationError = (message, node) => {
|
|
73
|
+
let suffix = '';
|
|
74
|
+
if (node) {
|
|
75
|
+
const offset = node.span.start - baseByteOffset;
|
|
76
|
+
let line = 1;
|
|
77
|
+
let colStart = 0;
|
|
78
|
+
for (let i = 0; i < offset && i < sourceBuffer.length; i++) {
|
|
79
|
+
if (sourceBuffer[i] === 10) {
|
|
80
|
+
line++;
|
|
81
|
+
colStart = i + 1;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
const col = offset - colStart + 1;
|
|
85
|
+
suffix = ` (${path.basename(resourcePath)}:${line}:${col})`;
|
|
86
|
+
}
|
|
87
|
+
const err = new Error(`${message}${suffix}`);
|
|
88
|
+
err.stack = err.message;
|
|
89
|
+
throw err;
|
|
90
|
+
};
|
|
72
91
|
for (const node of ast.body) {
|
|
73
92
|
if (node.type === 'ImportDeclaration') {
|
|
74
93
|
const sourcePath = node.source.value;
|
|
@@ -257,7 +276,7 @@ async function loader(source) {
|
|
|
257
276
|
if ((localCreateStyles[varName] &&
|
|
258
277
|
localCreateStyles[varName].type === 'variant') ||
|
|
259
278
|
mergedVariantsTable[varName]) {
|
|
260
|
-
|
|
279
|
+
throwCompilationError(`Plumeria: Assigning the return value of css.variants() to a variable is not supported.\nPlease pass the variant function directly to styleName or css.use(). Found assignment to: ${utils_1.t.isIdentifier(decl.id) ? decl.id.value : 'unknown'}`, init);
|
|
261
280
|
}
|
|
262
281
|
}
|
|
263
282
|
};
|
|
@@ -410,7 +429,7 @@ async function loader(source) {
|
|
|
410
429
|
selector = selectorExpr.value;
|
|
411
430
|
}
|
|
412
431
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
413
|
-
|
|
432
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
414
433
|
}
|
|
415
434
|
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
416
435
|
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
@@ -591,7 +610,7 @@ async function loader(source) {
|
|
|
591
610
|
selector = selectorExpr.value;
|
|
592
611
|
}
|
|
593
612
|
if (selector.startsWith('@') && !(0, zss_engine_1.isAtRule)(selector)) {
|
|
594
|
-
|
|
613
|
+
throwCompilationError(`Plumeria: Unsupported at-rule: "${selector}". createTheme only supports nesting at-rules such as @media, @container, @supports, @layer, and @scope.`, selectorExpr);
|
|
595
614
|
}
|
|
596
615
|
const obj = (0, utils_1.objectExpressionToObject)(args[1].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
597
616
|
const hash = (0, zss_engine_1.genBase36Hash)({ _themeSelector: selector, ...obj }, 1, 8);
|
|
@@ -672,6 +691,24 @@ async function loader(source) {
|
|
|
672
691
|
let groupIdCounter = 0;
|
|
673
692
|
let baseStyle = {};
|
|
674
693
|
let isOptimizable = true;
|
|
694
|
+
const getRootIdentifier = (node) => {
|
|
695
|
+
if (utils_1.t.isIdentifier(node)) {
|
|
696
|
+
return node.value;
|
|
697
|
+
}
|
|
698
|
+
if (utils_1.t.isMemberExpression(node)) {
|
|
699
|
+
return getRootIdentifier(node.object);
|
|
700
|
+
}
|
|
701
|
+
if (utils_1.t.isCallExpression(node)) {
|
|
702
|
+
const callee = node.callee;
|
|
703
|
+
if (callee.type !== 'Super' && callee.type !== 'Import') {
|
|
704
|
+
return getRootIdentifier(callee);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
if (node.type === 'ParenthesisExpression') {
|
|
708
|
+
return getRootIdentifier(node.expression);
|
|
709
|
+
}
|
|
710
|
+
return null;
|
|
711
|
+
};
|
|
675
712
|
const collectConditions = (node, currentTestStrings = []) => {
|
|
676
713
|
const staticStyle = resolveStyleObject(node);
|
|
677
714
|
if (staticStyle) {
|
|
@@ -742,6 +779,21 @@ async function loader(source) {
|
|
|
742
779
|
variantObj = localCreateStyles[varName].obj;
|
|
743
780
|
if (variantObj) {
|
|
744
781
|
const callArgs = expr.arguments;
|
|
782
|
+
const hasSpread = callArgs.some((a) => {
|
|
783
|
+
if (a.spread)
|
|
784
|
+
return true;
|
|
785
|
+
if (a.expression.type === 'ObjectExpression') {
|
|
786
|
+
return a.expression.properties.some((p) => p.type === 'SpreadElement');
|
|
787
|
+
}
|
|
788
|
+
return false;
|
|
789
|
+
});
|
|
790
|
+
if (hasSpread) {
|
|
791
|
+
throwCompilationError(`Plumeria: Spread operator in ${getSource(expr)} is not supported. ` +
|
|
792
|
+
`Please pass specific variant options directly.`, expr);
|
|
793
|
+
}
|
|
794
|
+
if (callArgs.length !== 1) {
|
|
795
|
+
throwCompilationError(`Plumeria: Variant function "${varName}" expects exactly 1 argument, found ${callArgs.length}.`, expr);
|
|
796
|
+
}
|
|
745
797
|
if (callArgs.length === 1 && !callArgs[0].spread) {
|
|
746
798
|
const arg = callArgs[0].expression;
|
|
747
799
|
if (arg.type === 'ObjectExpression') {
|
|
@@ -848,6 +900,17 @@ async function loader(source) {
|
|
|
848
900
|
const handled = collectConditions(expr);
|
|
849
901
|
if (handled)
|
|
850
902
|
continue;
|
|
903
|
+
if (utils_1.t.isMemberExpression(expr) || utils_1.t.isIdentifier(expr)) {
|
|
904
|
+
const rootId = getRootIdentifier(expr);
|
|
905
|
+
const isPlumeriaStyle = rootId &&
|
|
906
|
+
((localCreateStyles[rootId] !== undefined &&
|
|
907
|
+
localCreateStyles[rootId].type !== 'constant') ||
|
|
908
|
+
mergedCreateTable[rootId] !== undefined ||
|
|
909
|
+
mergedVariantsTable[rootId] !== undefined);
|
|
910
|
+
if (!isPlumeriaStyle) {
|
|
911
|
+
throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
|
|
912
|
+
}
|
|
913
|
+
}
|
|
851
914
|
isOptimizable = false;
|
|
852
915
|
break;
|
|
853
916
|
}
|
|
@@ -1420,7 +1483,7 @@ async function loader(source) {
|
|
|
1420
1483
|
const propKey = callee.property.value;
|
|
1421
1484
|
const styleInfo = localCreateStyles[varName];
|
|
1422
1485
|
if (styleInfo?.functions?.[propKey]) {
|
|
1423
|
-
|
|
1486
|
+
throwCompilationError(`Plumeria: css.use(${getSource(expr)}) does not support dynamic function keys.`, expr);
|
|
1424
1487
|
}
|
|
1425
1488
|
}
|
|
1426
1489
|
const { classParts, isOptimizable, baseStyle } = buildClassParts(args);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "14.0.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": "^
|
|
25
|
+
"@plumeria/utils": "^14.0.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.41",
|