@plumeria/turbopack-loader 10.0.5 → 10.0.7
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 +144 -103
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -153,28 +153,40 @@ async function loader(source) {
|
|
|
153
153
|
mergedKeyframesTable[key] = scannedTables.keyframesHashTable[key];
|
|
154
154
|
}
|
|
155
155
|
for (const key of Object.keys(importMap)) {
|
|
156
|
-
|
|
156
|
+
const val = importMap[key];
|
|
157
|
+
if (typeof val === 'string') {
|
|
158
|
+
mergedKeyframesTable[key] = val;
|
|
159
|
+
}
|
|
157
160
|
}
|
|
158
161
|
const mergedViewTransitionTable = {};
|
|
159
162
|
for (const key of Object.keys(scannedTables.viewTransitionHashTable)) {
|
|
160
163
|
mergedViewTransitionTable[key] = scannedTables.viewTransitionHashTable[key];
|
|
161
164
|
}
|
|
162
165
|
for (const key of Object.keys(importMap)) {
|
|
163
|
-
|
|
166
|
+
const val = importMap[key];
|
|
167
|
+
if (typeof val === 'string') {
|
|
168
|
+
mergedViewTransitionTable[key] = val;
|
|
169
|
+
}
|
|
164
170
|
}
|
|
165
171
|
const mergedCreateTable = {};
|
|
166
172
|
for (const key of Object.keys(scannedTables.createHashTable)) {
|
|
167
173
|
mergedCreateTable[key] = scannedTables.createHashTable[key];
|
|
168
174
|
}
|
|
169
175
|
for (const key of Object.keys(importMap)) {
|
|
170
|
-
|
|
176
|
+
const val = importMap[key];
|
|
177
|
+
if (typeof val === 'string') {
|
|
178
|
+
mergedCreateTable[key] = val;
|
|
179
|
+
}
|
|
171
180
|
}
|
|
172
181
|
const mergedVariantsTable = {};
|
|
173
182
|
for (const key of Object.keys(scannedTables.variantsHashTable)) {
|
|
174
183
|
mergedVariantsTable[key] = scannedTables.variantsHashTable[key];
|
|
175
184
|
}
|
|
176
185
|
for (const key of Object.keys(importMap)) {
|
|
177
|
-
|
|
186
|
+
const val = importMap[key];
|
|
187
|
+
if (typeof val === 'string') {
|
|
188
|
+
mergedVariantsTable[key] = val;
|
|
189
|
+
}
|
|
178
190
|
}
|
|
179
191
|
const mergedCreateThemeHashTable = {};
|
|
180
192
|
for (const key of Object.keys(scannedTables.createThemeHashTable)) {
|
|
@@ -206,10 +218,9 @@ async function loader(source) {
|
|
|
206
218
|
const idSpans = new Set();
|
|
207
219
|
const excludedSpans = new Set();
|
|
208
220
|
const checkVariantAssignment = (decl) => {
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
const varName = decl.init.callee.value;
|
|
221
|
+
const init = decl.init;
|
|
222
|
+
if (init && utils_1.t.isCallExpression(init) && utils_1.t.isIdentifier(init.callee)) {
|
|
223
|
+
const varName = init.callee.value;
|
|
213
224
|
if ((localCreateStyles[varName] &&
|
|
214
225
|
localCreateStyles[varName].type === 'variant') ||
|
|
215
226
|
mergedVariantsTable[varName]) {
|
|
@@ -219,11 +230,12 @@ async function loader(source) {
|
|
|
219
230
|
};
|
|
220
231
|
const registerStyle = (node, declSpan, isExported) => {
|
|
221
232
|
let propName;
|
|
233
|
+
const init = node.init;
|
|
222
234
|
if (utils_1.t.isIdentifier(node.id) &&
|
|
223
|
-
|
|
224
|
-
utils_1.t.isCallExpression(
|
|
225
|
-
|
|
226
|
-
const callee =
|
|
235
|
+
init &&
|
|
236
|
+
utils_1.t.isCallExpression(init) &&
|
|
237
|
+
init.arguments.length >= 1) {
|
|
238
|
+
const callee = init.callee;
|
|
227
239
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
228
240
|
utils_1.t.isIdentifier(callee.object) &&
|
|
229
241
|
utils_1.t.isIdentifier(callee.property)) {
|
|
@@ -242,10 +254,10 @@ async function loader(source) {
|
|
|
242
254
|
}
|
|
243
255
|
}
|
|
244
256
|
}
|
|
245
|
-
if (propName) {
|
|
257
|
+
if (propName && init && utils_1.t.isCallExpression(init)) {
|
|
246
258
|
if (propName === 'create' &&
|
|
247
|
-
utils_1.t.isObjectExpression(
|
|
248
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
259
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
260
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
249
261
|
if (obj) {
|
|
250
262
|
const hashMap = {};
|
|
251
263
|
Object.entries(obj).forEach(([key, style]) => {
|
|
@@ -262,7 +274,7 @@ async function loader(source) {
|
|
|
262
274
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
263
275
|
hashMap[key] = atomMap;
|
|
264
276
|
});
|
|
265
|
-
const objExpr =
|
|
277
|
+
const objExpr = init.arguments[0].expression;
|
|
266
278
|
objExpr.properties.forEach((prop) => {
|
|
267
279
|
if (prop.type !== 'KeyValueProperty' ||
|
|
268
280
|
prop.key.type !== 'Identifier')
|
|
@@ -272,7 +284,20 @@ async function loader(source) {
|
|
|
272
284
|
if (!isArrow && !isFunc)
|
|
273
285
|
return;
|
|
274
286
|
const key = prop.key.value;
|
|
275
|
-
const
|
|
287
|
+
const func = prop.value;
|
|
288
|
+
if (func.type !== 'ArrowFunctionExpression' &&
|
|
289
|
+
func.type !== 'FunctionExpression')
|
|
290
|
+
return;
|
|
291
|
+
const params = func.params.map((p) => {
|
|
292
|
+
if (utils_1.t.isIdentifier(p))
|
|
293
|
+
return p.value;
|
|
294
|
+
if (typeof p === 'object' &&
|
|
295
|
+
p !== null &&
|
|
296
|
+
'pat' in p &&
|
|
297
|
+
utils_1.t.isIdentifier(p.pat))
|
|
298
|
+
return p.pat.value;
|
|
299
|
+
return 'arg';
|
|
300
|
+
});
|
|
276
301
|
const cssVarInfo = {};
|
|
277
302
|
const tempStaticTable = { ...mergedStaticTable };
|
|
278
303
|
const substitutedArgs = params.map((paramName) => {
|
|
@@ -283,7 +308,7 @@ async function loader(source) {
|
|
|
283
308
|
params.forEach((paramName, i) => {
|
|
284
309
|
tempStaticTable[paramName] = substitutedArgs[i];
|
|
285
310
|
});
|
|
286
|
-
let actualBody =
|
|
311
|
+
let actualBody = func.body;
|
|
287
312
|
if (actualBody?.type === 'ParenthesisExpression')
|
|
288
313
|
actualBody = actualBody.expression;
|
|
289
314
|
if (actualBody?.type === 'BlockStatement') {
|
|
@@ -316,29 +341,31 @@ async function loader(source) {
|
|
|
316
341
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
317
342
|
idSpans.add(node.id.span.start);
|
|
318
343
|
}
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
344
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
345
|
+
localCreateStyles[node.id.value] = {
|
|
346
|
+
name: node.id.value,
|
|
347
|
+
type: 'create',
|
|
348
|
+
obj,
|
|
349
|
+
hashMap,
|
|
350
|
+
isExported,
|
|
351
|
+
initSpan: {
|
|
352
|
+
start: init.span.start - baseByteOffset,
|
|
353
|
+
end: init.span.end - baseByteOffset,
|
|
354
|
+
},
|
|
355
|
+
declSpan: {
|
|
356
|
+
start: declSpan.start - baseByteOffset,
|
|
357
|
+
end: declSpan.end - baseByteOffset,
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
}
|
|
334
361
|
}
|
|
335
362
|
}
|
|
336
363
|
else if (propName === 'variants' &&
|
|
337
|
-
utils_1.t.isObjectExpression(
|
|
364
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
338
365
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
339
366
|
idSpans.add(node.id.span.start);
|
|
340
367
|
}
|
|
341
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
368
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable, (name) => {
|
|
342
369
|
if (localCreateStyles[name]) {
|
|
343
370
|
return localCreateStyles[name].obj;
|
|
344
371
|
}
|
|
@@ -351,47 +378,51 @@ async function loader(source) {
|
|
|
351
378
|
return undefined;
|
|
352
379
|
});
|
|
353
380
|
const { hashMap } = (0, utils_1.processVariants)(obj);
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
381
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
382
|
+
localCreateStyles[node.id.value] = {
|
|
383
|
+
name: node.id.value,
|
|
384
|
+
type: 'variant',
|
|
385
|
+
obj,
|
|
386
|
+
hashMap,
|
|
387
|
+
isExported,
|
|
388
|
+
initSpan: {
|
|
389
|
+
start: init.span.start - baseByteOffset,
|
|
390
|
+
end: init.span.end - baseByteOffset,
|
|
391
|
+
},
|
|
392
|
+
declSpan: {
|
|
393
|
+
start: declSpan.start - baseByteOffset,
|
|
394
|
+
end: declSpan.end - baseByteOffset,
|
|
395
|
+
},
|
|
396
|
+
};
|
|
397
|
+
}
|
|
369
398
|
}
|
|
370
399
|
else if (propName === 'createTheme' &&
|
|
371
|
-
utils_1.t.isObjectExpression(
|
|
400
|
+
utils_1.t.isObjectExpression(init.arguments[0].expression)) {
|
|
372
401
|
if (utils_1.t.isIdentifier(node.id)) {
|
|
373
402
|
idSpans.add(node.id.span.start);
|
|
374
403
|
}
|
|
375
|
-
const obj = (0, utils_1.objectExpressionToObject)(
|
|
404
|
+
const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
376
405
|
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
406
|
+
if (utils_1.t.isIdentifier(node.id)) {
|
|
407
|
+
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
408
|
+
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
409
|
+
scannedTables.createThemeObjectTable[hash] = obj;
|
|
410
|
+
localCreateStyles[node.id.value] = {
|
|
411
|
+
name: node.id.value,
|
|
412
|
+
type: 'constant',
|
|
413
|
+
obj,
|
|
414
|
+
hashMap: scannedTables.createAtomicMapTable[hash],
|
|
415
|
+
isExported,
|
|
416
|
+
initSpan: {
|
|
417
|
+
start: init.span.start - baseByteOffset,
|
|
418
|
+
end: init.span.end - baseByteOffset,
|
|
419
|
+
},
|
|
420
|
+
declSpan: {
|
|
421
|
+
start: declSpan.start - baseByteOffset,
|
|
422
|
+
end: declSpan.end - baseByteOffset,
|
|
423
|
+
},
|
|
424
|
+
};
|
|
425
|
+
}
|
|
395
426
|
}
|
|
396
427
|
}
|
|
397
428
|
};
|
|
@@ -402,7 +433,7 @@ async function loader(source) {
|
|
|
402
433
|
if (specifier.local) {
|
|
403
434
|
excludedSpans.add(specifier.local.span.start);
|
|
404
435
|
}
|
|
405
|
-
if (specifier.imported) {
|
|
436
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported) {
|
|
406
437
|
excludedSpans.add(specifier.imported.span.start);
|
|
407
438
|
}
|
|
408
439
|
});
|
|
@@ -447,17 +478,18 @@ async function loader(source) {
|
|
|
447
478
|
}
|
|
448
479
|
if (propName) {
|
|
449
480
|
const args = node.arguments;
|
|
450
|
-
if (propName === 'keyframes'
|
|
451
|
-
|
|
452
|
-
utils_1.t.isObjectExpression(
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
481
|
+
if (propName === 'keyframes') {
|
|
482
|
+
const expr = args[0].expression;
|
|
483
|
+
if (utils_1.t.isObjectExpression(expr)) {
|
|
484
|
+
const obj = (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
|
|
485
|
+
const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
|
|
486
|
+
scannedTables.keyframesObjectTable[hash] = obj;
|
|
487
|
+
replacements.push({
|
|
488
|
+
start: node.span.start - baseByteOffset,
|
|
489
|
+
end: node.span.end - baseByteOffset,
|
|
490
|
+
content: JSON.stringify(`kf-${hash}`),
|
|
491
|
+
});
|
|
492
|
+
}
|
|
461
493
|
}
|
|
462
494
|
else if (propName === 'viewTransition' &&
|
|
463
495
|
args.length > 0 &&
|
|
@@ -511,8 +543,7 @@ async function loader(source) {
|
|
|
511
543
|
}
|
|
512
544
|
else if (utils_1.t.isMemberExpression(expr) &&
|
|
513
545
|
utils_1.t.isIdentifier(expr.object) &&
|
|
514
|
-
(utils_1.t.isIdentifier(expr.property) ||
|
|
515
|
-
expr.property.type === 'Computed')) {
|
|
546
|
+
(utils_1.t.isIdentifier(expr.property) || expr.property.type === 'Computed')) {
|
|
516
547
|
if (expr.property.type === 'Computed')
|
|
517
548
|
return {};
|
|
518
549
|
const varName = expr.object.value;
|
|
@@ -647,8 +678,9 @@ async function loader(source) {
|
|
|
647
678
|
const currentGroupId = ++groupIdCounter;
|
|
648
679
|
const valSource = getSource(valExpr);
|
|
649
680
|
if (valExpr.type === 'StringLiteral') {
|
|
650
|
-
|
|
651
|
-
|
|
681
|
+
const groupVariantsAsObj = groupVariants;
|
|
682
|
+
if (groupVariantsAsObj[valExpr.value])
|
|
683
|
+
baseStyle = (0, utils_1.deepMerge)(baseStyle, groupVariantsAsObj[valExpr.value]);
|
|
652
684
|
continue;
|
|
653
685
|
}
|
|
654
686
|
Object.entries(groupVariants).forEach(([optionName, style]) => {
|
|
@@ -1066,20 +1098,24 @@ async function loader(source) {
|
|
|
1066
1098
|
const expr = node.value.expression;
|
|
1067
1099
|
let args = expr.type === 'ArrayExpression'
|
|
1068
1100
|
? expr.elements
|
|
1069
|
-
.filter(
|
|
1070
|
-
.map((el) => ({ expression: el.expression
|
|
1101
|
+
.filter((el) => el !== undefined)
|
|
1102
|
+
.map((el) => ({ expression: el.expression }))
|
|
1071
1103
|
: [{ expression: expr }];
|
|
1072
1104
|
const dynamicClassParts = [];
|
|
1073
1105
|
const dynamicStyleParts = [];
|
|
1074
1106
|
let attributes = [];
|
|
1075
1107
|
for (const [, attrs] of jsxOpeningElementMap) {
|
|
1076
|
-
const found = attrs
|
|
1108
|
+
const found = attrs
|
|
1109
|
+
.filter((a) => a.type === 'JSXAttribute')
|
|
1110
|
+
.find((a) => a.span.start === node.span.start);
|
|
1077
1111
|
if (found) {
|
|
1078
1112
|
attributes = attrs;
|
|
1079
1113
|
break;
|
|
1080
1114
|
}
|
|
1081
1115
|
}
|
|
1082
|
-
const classNameAttr = attributes.find((attr) => attr.
|
|
1116
|
+
const classNameAttr = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
1117
|
+
attr.name.type === 'Identifier' &&
|
|
1118
|
+
attr.name.value === 'className');
|
|
1083
1119
|
let existingClass = '';
|
|
1084
1120
|
if (classNameAttr?.value?.type === 'StringLiteral') {
|
|
1085
1121
|
existingClass = classNameAttr.value.value;
|
|
@@ -1089,23 +1125,27 @@ async function loader(source) {
|
|
|
1089
1125
|
content: '',
|
|
1090
1126
|
});
|
|
1091
1127
|
}
|
|
1092
|
-
const styleAttrExisting = attributes.find((attr) => attr.
|
|
1128
|
+
const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
|
|
1129
|
+
attr.name.type === 'Identifier' &&
|
|
1130
|
+
attr.name.value === 'style');
|
|
1093
1131
|
if (styleAttrExisting) {
|
|
1094
1132
|
replacements.push({
|
|
1095
1133
|
start: styleAttrExisting.span.start - baseByteOffset,
|
|
1096
1134
|
end: styleAttrExisting.span.end - baseByteOffset,
|
|
1097
1135
|
content: '',
|
|
1098
1136
|
});
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1137
|
+
if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
|
|
1138
|
+
const innerExpr = styleAttrExisting.value?.expression;
|
|
1139
|
+
if (innerExpr?.type === 'ObjectExpression') {
|
|
1140
|
+
const start = innerExpr.span.start - baseByteOffset;
|
|
1141
|
+
const end = innerExpr.span.end - baseByteOffset;
|
|
1142
|
+
const innerSource = sourceBuffer
|
|
1143
|
+
.subarray(start, end)
|
|
1144
|
+
.toString('utf-8');
|
|
1145
|
+
const stripped = innerSource.slice(1, -1).trim();
|
|
1146
|
+
if (stripped)
|
|
1147
|
+
dynamicStyleParts.push(stripped);
|
|
1148
|
+
}
|
|
1109
1149
|
}
|
|
1110
1150
|
}
|
|
1111
1151
|
args = args.filter((arg) => {
|
|
@@ -1133,8 +1173,9 @@ async function loader(source) {
|
|
|
1133
1173
|
const callArg = callArgs[i];
|
|
1134
1174
|
if (!callArg)
|
|
1135
1175
|
return;
|
|
1136
|
-
const
|
|
1137
|
-
const
|
|
1176
|
+
const argExpr = callArg.expression;
|
|
1177
|
+
const argStart = argExpr.span.start - baseByteOffset;
|
|
1178
|
+
const argEnd = argExpr.span.end - baseByteOffset;
|
|
1138
1179
|
const argSource = sourceBuffer
|
|
1139
1180
|
.subarray(argStart, argEnd)
|
|
1140
1181
|
.toString('utf-8');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "10.0.
|
|
3
|
+
"version": "10.0.7",
|
|
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": "^10.0.
|
|
25
|
+
"@plumeria/utils": "^10.0.7"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"@swc/core": "1.15.
|
|
28
|
+
"@swc/core": "1.15.21",
|
|
29
29
|
"zss-engine": "2.2.6"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|