@plumeria/vite-plugin 6.0.1 → 6.1.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 +94 -15
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -68,21 +68,46 @@ export function plumeria(options = {}) {
|
|
|
68
68
|
dependencies.push(depPath);
|
|
69
69
|
this.addWatchFile(depPath);
|
|
70
70
|
};
|
|
71
|
-
const scannedTables = scanAll();
|
|
72
71
|
const ast = parseSync(source, {
|
|
73
72
|
syntax: 'typescript',
|
|
74
73
|
tsx: true,
|
|
75
74
|
target: 'es2022',
|
|
76
75
|
});
|
|
76
|
+
for (const node of ast.body) {
|
|
77
|
+
if (node.type === 'ImportDeclaration') {
|
|
78
|
+
const sourcePath = node.source.value;
|
|
79
|
+
const actualPath = resolveImportPath(sourcePath, id);
|
|
80
|
+
if (actualPath) {
|
|
81
|
+
addDependency(actualPath);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
const scannedTables = scanAll();
|
|
77
86
|
const localConsts = collectLocalConsts(ast);
|
|
78
87
|
const resourcePath = id;
|
|
79
88
|
const importMap = {};
|
|
89
|
+
const plumeriaAliases = {};
|
|
80
90
|
traverse(ast, {
|
|
81
91
|
ImportDeclaration({ node }) {
|
|
82
92
|
const sourcePath = node.source.value;
|
|
93
|
+
if (sourcePath === '@plumeria/core') {
|
|
94
|
+
node.specifiers.forEach((specifier) => {
|
|
95
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
96
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
97
|
+
}
|
|
98
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
99
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
100
|
+
}
|
|
101
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
102
|
+
const importedName = specifier.imported
|
|
103
|
+
? specifier.imported.value
|
|
104
|
+
: specifier.local.value;
|
|
105
|
+
plumeriaAliases[specifier.local.value] = importedName;
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
}
|
|
83
109
|
const actualPath = resolveImportPath(sourcePath, resourcePath);
|
|
84
110
|
if (actualPath) {
|
|
85
|
-
addDependency(actualPath);
|
|
86
111
|
node.specifiers.forEach((specifier) => {
|
|
87
112
|
if (specifier.type === 'ImportSpecifier') {
|
|
88
113
|
const importedName = specifier.imported
|
|
@@ -166,6 +191,11 @@ export function plumeria(options = {}) {
|
|
|
166
191
|
const localCreateStyles = {};
|
|
167
192
|
const replacements = [];
|
|
168
193
|
const extractedSheets = [];
|
|
194
|
+
const addSheet = (sheet) => {
|
|
195
|
+
if (!extractedSheets.includes(sheet)) {
|
|
196
|
+
extractedSheets.push(sheet);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
169
199
|
const processedDecls = new Set();
|
|
170
200
|
const idSpans = new Set();
|
|
171
201
|
const excludedSpans = new Set();
|
|
@@ -182,14 +212,31 @@ export function plumeria(options = {}) {
|
|
|
182
212
|
}
|
|
183
213
|
};
|
|
184
214
|
const registerStyle = (node, declSpan, isExported) => {
|
|
215
|
+
let propName;
|
|
185
216
|
if (t.isIdentifier(node.id) &&
|
|
186
217
|
node.init &&
|
|
187
218
|
t.isCallExpression(node.init) &&
|
|
188
|
-
t.isMemberExpression(node.init.callee) &&
|
|
189
|
-
t.isIdentifier(node.init.callee.object, { name: 'css' }) &&
|
|
190
|
-
t.isIdentifier(node.init.callee.property) &&
|
|
191
219
|
node.init.arguments.length >= 1) {
|
|
192
|
-
const
|
|
220
|
+
const callee = node.init.callee;
|
|
221
|
+
if (t.isMemberExpression(callee) &&
|
|
222
|
+
t.isIdentifier(callee.object) &&
|
|
223
|
+
t.isIdentifier(callee.property)) {
|
|
224
|
+
const objectName = callee.object.value;
|
|
225
|
+
const propertyName = callee.property.value;
|
|
226
|
+
const alias = plumeriaAliases[objectName];
|
|
227
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
228
|
+
propName = propertyName;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
else if (t.isIdentifier(callee)) {
|
|
232
|
+
const calleeName = callee.value;
|
|
233
|
+
const originalName = plumeriaAliases[calleeName];
|
|
234
|
+
if (originalName) {
|
|
235
|
+
propName = originalName;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
if (propName) {
|
|
193
240
|
if (propName === 'create' &&
|
|
194
241
|
t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
195
242
|
const obj = objectExpressionToObject(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable, mergedCreateTable, mergedVariantsTable);
|
|
@@ -199,7 +246,7 @@ export function plumeria(options = {}) {
|
|
|
199
246
|
const records = getStyleRecords(key, style, 2);
|
|
200
247
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
201
248
|
records.forEach((r) => {
|
|
202
|
-
|
|
249
|
+
addSheet(r.sheet);
|
|
203
250
|
});
|
|
204
251
|
const atomMap = {};
|
|
205
252
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
@@ -308,10 +355,25 @@ export function plumeria(options = {}) {
|
|
|
308
355
|
},
|
|
309
356
|
CallExpression({ node }) {
|
|
310
357
|
const callee = node.callee;
|
|
358
|
+
let propName;
|
|
311
359
|
if (t.isMemberExpression(callee) &&
|
|
312
|
-
t.isIdentifier(callee.object
|
|
360
|
+
t.isIdentifier(callee.object) &&
|
|
313
361
|
t.isIdentifier(callee.property)) {
|
|
314
|
-
const
|
|
362
|
+
const objectName = callee.object.value;
|
|
363
|
+
const propertyName = callee.property.value;
|
|
364
|
+
const alias = plumeriaAliases[objectName];
|
|
365
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
366
|
+
propName = propertyName;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
else if (t.isIdentifier(callee)) {
|
|
370
|
+
const calleeName = callee.value;
|
|
371
|
+
const originalName = plumeriaAliases[calleeName];
|
|
372
|
+
if (originalName) {
|
|
373
|
+
propName = originalName;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
if (propName) {
|
|
315
377
|
const args = node.arguments;
|
|
316
378
|
if (propName === 'keyframes' &&
|
|
317
379
|
args.length > 0 &&
|
|
@@ -356,7 +418,7 @@ export function plumeria(options = {}) {
|
|
|
356
418
|
if (typeof style === 'object' && style !== null) {
|
|
357
419
|
const records = getStyleRecords(key, style, 2);
|
|
358
420
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
359
|
-
records.forEach((r) =>
|
|
421
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
360
422
|
}
|
|
361
423
|
});
|
|
362
424
|
}
|
|
@@ -388,7 +450,7 @@ export function plumeria(options = {}) {
|
|
|
388
450
|
if (typeof style === 'object' && style !== null) {
|
|
389
451
|
const records = getStyleRecords(propName, style, 2);
|
|
390
452
|
extractOndemandStyles(style, extractedSheets, scannedTables);
|
|
391
|
-
records.forEach((r) =>
|
|
453
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
392
454
|
const atomMap = {};
|
|
393
455
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
394
456
|
if (Object.keys(atomMap).length > 0) {
|
|
@@ -405,9 +467,26 @@ export function plumeria(options = {}) {
|
|
|
405
467
|
},
|
|
406
468
|
CallExpression({ node }) {
|
|
407
469
|
const callee = node.callee;
|
|
470
|
+
let isPropsCall = false;
|
|
408
471
|
if (t.isMemberExpression(callee) &&
|
|
409
|
-
t.isIdentifier(callee.object
|
|
410
|
-
t.isIdentifier(callee.property
|
|
472
|
+
t.isIdentifier(callee.object) &&
|
|
473
|
+
t.isIdentifier(callee.property)) {
|
|
474
|
+
const objectName = callee.object.value;
|
|
475
|
+
const propertyName = callee.property.value;
|
|
476
|
+
const alias = plumeriaAliases[objectName];
|
|
477
|
+
if ((alias === 'NAMESPACE' || objectName === 'css') &&
|
|
478
|
+
propertyName === 'props') {
|
|
479
|
+
isPropsCall = true;
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
else if (t.isIdentifier(callee)) {
|
|
483
|
+
const calleeName = callee.value;
|
|
484
|
+
const originalName = plumeriaAliases[calleeName];
|
|
485
|
+
if (originalName === 'props') {
|
|
486
|
+
isPropsCall = true;
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (isPropsCall) {
|
|
411
490
|
const args = node.arguments;
|
|
412
491
|
const resolveStyleObject = (expr) => {
|
|
413
492
|
if (t.isObjectExpression(expr)) {
|
|
@@ -597,7 +676,7 @@ export function plumeria(options = {}) {
|
|
|
597
676
|
extractOndemandStyles(baseStyle, extractedSheets, scannedTables);
|
|
598
677
|
const hash = genBase36Hash(baseStyle, 1, 8);
|
|
599
678
|
const records = getStyleRecords(hash, baseStyle, 2);
|
|
600
|
-
records.forEach((r) =>
|
|
679
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
601
680
|
const className = records
|
|
602
681
|
.map((r) => r.hash)
|
|
603
682
|
.join(' ');
|
|
@@ -636,7 +715,7 @@ export function plumeria(options = {}) {
|
|
|
636
715
|
extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
|
|
637
716
|
const hash = genBase36Hash(currentStyle, 1, 8);
|
|
638
717
|
const records = getStyleRecords(hash, currentStyle, 2);
|
|
639
|
-
records.forEach((r) =>
|
|
718
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
640
719
|
const className = records
|
|
641
720
|
.map((r) => r.hash)
|
|
642
721
|
.join(' ');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/vite-plugin",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Plumeria Vite plugin",
|
|
6
6
|
"author": "Refirst 11",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dist/"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@plumeria/utils": "^6.0
|
|
25
|
+
"@plumeria/utils": "^6.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|