@plumeria/turbopack-loader 6.0.2 → 6.1.1
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 +120 -44
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -40,9 +40,26 @@ async function loader(source) {
|
|
|
40
40
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
41
41
|
const resourcePath = this.resourcePath;
|
|
42
42
|
const importMap = {};
|
|
43
|
+
const plumeriaAliases = {};
|
|
43
44
|
(0, utils_1.traverse)(ast, {
|
|
44
45
|
ImportDeclaration({ node }) {
|
|
45
46
|
const sourcePath = node.source.value;
|
|
47
|
+
if (sourcePath === '@plumeria/core') {
|
|
48
|
+
node.specifiers.forEach((specifier) => {
|
|
49
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
50
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
51
|
+
}
|
|
52
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
53
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
54
|
+
}
|
|
55
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
56
|
+
const importedName = specifier.imported
|
|
57
|
+
? specifier.imported.value
|
|
58
|
+
: specifier.local.value;
|
|
59
|
+
plumeriaAliases[specifier.local.value] = importedName;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
}
|
|
46
63
|
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
|
|
47
64
|
if (actualPath) {
|
|
48
65
|
node.specifiers.forEach((specifier) => {
|
|
@@ -133,6 +150,9 @@ async function loader(source) {
|
|
|
133
150
|
const processedDecls = new Set();
|
|
134
151
|
const idSpans = new Set();
|
|
135
152
|
const excludedSpans = new Set();
|
|
153
|
+
if (scannedTables.extractedSheet) {
|
|
154
|
+
addSheet(scannedTables.extractedSheet);
|
|
155
|
+
}
|
|
136
156
|
const checkVariantAssignment = (decl) => {
|
|
137
157
|
if (decl.init &&
|
|
138
158
|
utils_1.t.isCallExpression(decl.init) &&
|
|
@@ -146,14 +166,31 @@ async function loader(source) {
|
|
|
146
166
|
}
|
|
147
167
|
};
|
|
148
168
|
const registerStyle = (node, declSpan, isExported) => {
|
|
169
|
+
let propName;
|
|
149
170
|
if (utils_1.t.isIdentifier(node.id) &&
|
|
150
171
|
node.init &&
|
|
151
172
|
utils_1.t.isCallExpression(node.init) &&
|
|
152
|
-
utils_1.t.isMemberExpression(node.init.callee) &&
|
|
153
|
-
utils_1.t.isIdentifier(node.init.callee.object, { name: 'css' }) &&
|
|
154
|
-
utils_1.t.isIdentifier(node.init.callee.property) &&
|
|
155
173
|
node.init.arguments.length >= 1) {
|
|
156
|
-
const
|
|
174
|
+
const callee = node.init.callee;
|
|
175
|
+
if (utils_1.t.isMemberExpression(callee) &&
|
|
176
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
177
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
178
|
+
const objectName = callee.object.value;
|
|
179
|
+
const propertyName = callee.property.value;
|
|
180
|
+
const alias = plumeriaAliases[objectName];
|
|
181
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
182
|
+
propName = propertyName;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
186
|
+
const calleeName = callee.value;
|
|
187
|
+
const originalName = plumeriaAliases[calleeName];
|
|
188
|
+
if (originalName) {
|
|
189
|
+
propName = originalName;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
if (propName) {
|
|
157
194
|
if (propName === 'create' &&
|
|
158
195
|
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
159
196
|
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable, mergedCreateTable, mergedVariantsTable);
|
|
@@ -274,10 +311,25 @@ async function loader(source) {
|
|
|
274
311
|
},
|
|
275
312
|
CallExpression({ node }) {
|
|
276
313
|
const callee = node.callee;
|
|
314
|
+
let propName;
|
|
277
315
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
278
|
-
utils_1.t.isIdentifier(callee.object
|
|
316
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
279
317
|
utils_1.t.isIdentifier(callee.property)) {
|
|
280
|
-
const
|
|
318
|
+
const objectName = callee.object.value;
|
|
319
|
+
const propertyName = callee.property.value;
|
|
320
|
+
const alias = plumeriaAliases[objectName];
|
|
321
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
322
|
+
propName = propertyName;
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
326
|
+
const calleeName = callee.value;
|
|
327
|
+
const originalName = plumeriaAliases[calleeName];
|
|
328
|
+
if (originalName) {
|
|
329
|
+
propName = originalName;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
if (propName) {
|
|
281
333
|
const args = node.arguments;
|
|
282
334
|
if (propName === 'keyframes' &&
|
|
283
335
|
args.length > 0 &&
|
|
@@ -338,9 +390,30 @@ async function loader(source) {
|
|
|
338
390
|
if (utils_1.t.isIdentifier(node.object) && utils_1.t.isIdentifier(node.property)) {
|
|
339
391
|
const varName = node.object.value;
|
|
340
392
|
const propName = node.property.value;
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
393
|
+
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
394
|
+
let hash = scannedTables.createHashTable[uniqueKey];
|
|
395
|
+
if (!hash) {
|
|
396
|
+
hash = mergedCreateTable[varName];
|
|
397
|
+
}
|
|
398
|
+
if (!hash) {
|
|
399
|
+
const styleInfo = localCreateStyles[varName];
|
|
400
|
+
if (styleInfo) {
|
|
401
|
+
const atomMap = styleInfo.hashMap[propName];
|
|
402
|
+
if (atomMap) {
|
|
403
|
+
replacements.push({
|
|
404
|
+
start: node.span.start - ast.span.start,
|
|
405
|
+
end: node.span.end - ast.span.start,
|
|
406
|
+
content: JSON.stringify(atomMap),
|
|
407
|
+
});
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
if (hash) {
|
|
413
|
+
let atomMap;
|
|
414
|
+
if (scannedTables.createAtomicMapTable[hash]) {
|
|
415
|
+
atomMap = scannedTables.createAtomicMapTable[hash][propName];
|
|
416
|
+
}
|
|
344
417
|
if (atomMap) {
|
|
345
418
|
replacements.push({
|
|
346
419
|
start: node.span.start - ast.span.start,
|
|
@@ -350,36 +423,30 @@ async function loader(source) {
|
|
|
350
423
|
return;
|
|
351
424
|
}
|
|
352
425
|
}
|
|
353
|
-
const hash = mergedCreateTable[varName];
|
|
354
|
-
if (hash) {
|
|
355
|
-
const obj = scannedTables.createObjectTable[hash];
|
|
356
|
-
if (obj && obj[propName]) {
|
|
357
|
-
const style = obj[propName];
|
|
358
|
-
if (typeof style === 'object' && style !== null) {
|
|
359
|
-
const records = (0, utils_1.getStyleRecords)(propName, style, 2);
|
|
360
|
-
if (!isProduction) {
|
|
361
|
-
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
362
|
-
records.forEach((r) => addSheet(r.sheet));
|
|
363
|
-
}
|
|
364
|
-
const atomMap = {};
|
|
365
|
-
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
366
|
-
if (Object.keys(atomMap).length > 0) {
|
|
367
|
-
replacements.push({
|
|
368
|
-
start: node.span.start - ast.span.start,
|
|
369
|
-
end: node.span.end - ast.span.start,
|
|
370
|
-
content: JSON.stringify(atomMap),
|
|
371
|
-
});
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
426
|
}
|
|
377
427
|
},
|
|
378
428
|
CallExpression({ node }) {
|
|
379
429
|
const callee = node.callee;
|
|
430
|
+
let isPropsCall = false;
|
|
380
431
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
381
|
-
utils_1.t.isIdentifier(callee.object
|
|
382
|
-
utils_1.t.isIdentifier(callee.property
|
|
432
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
433
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
434
|
+
const objectName = callee.object.value;
|
|
435
|
+
const propertyName = callee.property.value;
|
|
436
|
+
const alias = plumeriaAliases[objectName];
|
|
437
|
+
if ((alias === 'NAMESPACE' || objectName === 'css') &&
|
|
438
|
+
propertyName === 'props') {
|
|
439
|
+
isPropsCall = true;
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
443
|
+
const calleeName = callee.value;
|
|
444
|
+
const originalName = plumeriaAliases[calleeName];
|
|
445
|
+
if (originalName === 'props') {
|
|
446
|
+
isPropsCall = true;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
if (isPropsCall) {
|
|
383
450
|
const args = node.arguments;
|
|
384
451
|
const resolveStyleObject = (expr) => {
|
|
385
452
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
@@ -415,17 +482,21 @@ async function loader(source) {
|
|
|
415
482
|
}
|
|
416
483
|
else if (utils_1.t.isIdentifier(expr)) {
|
|
417
484
|
const varName = expr.value;
|
|
418
|
-
const
|
|
419
|
-
|
|
420
|
-
|
|
485
|
+
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
486
|
+
let hash = scannedTables.createHashTable[uniqueKey];
|
|
487
|
+
if (!hash) {
|
|
488
|
+
hash = mergedCreateTable[varName];
|
|
421
489
|
}
|
|
422
|
-
const hash = mergedCreateTable[varName];
|
|
423
490
|
if (hash) {
|
|
424
491
|
const obj = scannedTables.createObjectTable[hash];
|
|
425
492
|
if (obj && typeof obj === 'object') {
|
|
426
493
|
return obj;
|
|
427
494
|
}
|
|
428
495
|
}
|
|
496
|
+
const styleInfo = localCreateStyles[varName];
|
|
497
|
+
if (styleInfo && styleInfo.obj) {
|
|
498
|
+
return styleInfo.obj;
|
|
499
|
+
}
|
|
429
500
|
if (localCreateStyles[varName]) {
|
|
430
501
|
return localCreateStyles[varName].obj;
|
|
431
502
|
}
|
|
@@ -445,13 +516,18 @@ async function loader(source) {
|
|
|
445
516
|
if (utils_1.t.isCallExpression(expr) && utils_1.t.isIdentifier(expr.callee)) {
|
|
446
517
|
const varName = expr.callee.value;
|
|
447
518
|
let variantObj;
|
|
448
|
-
|
|
449
|
-
|
|
519
|
+
const uniqueKey = `${this.resourcePath}-${varName}`;
|
|
520
|
+
let hash = scannedTables.variantsHashTable[uniqueKey];
|
|
521
|
+
if (!hash) {
|
|
522
|
+
hash = mergedVariantsTable[varName];
|
|
523
|
+
}
|
|
524
|
+
if (hash && scannedTables.variantsObjectTable[hash]) {
|
|
525
|
+
variantObj = scannedTables.variantsObjectTable[hash];
|
|
450
526
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
variantObj =
|
|
527
|
+
if (!variantObj) {
|
|
528
|
+
if (localCreateStyles[varName] &&
|
|
529
|
+
localCreateStyles[varName].obj) {
|
|
530
|
+
variantObj = localCreateStyles[varName].obj;
|
|
455
531
|
}
|
|
456
532
|
}
|
|
457
533
|
if (variantObj) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.1.1",
|
|
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.
|
|
25
|
+
"@plumeria/utils": "^6.1.1"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|