@plumeria/vite-plugin 6.0.0 → 6.0.2

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.
Files changed (2) hide show
  1. package/dist/index.js +30 -25
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -68,12 +68,21 @@ 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 = {};
@@ -82,7 +91,6 @@ export function plumeria(options = {}) {
82
91
  const sourcePath = node.source.value;
83
92
  const actualPath = resolveImportPath(sourcePath, resourcePath);
84
93
  if (actualPath) {
85
- addDependency(actualPath);
86
94
  node.specifiers.forEach((specifier) => {
87
95
  if (specifier.type === 'ImportSpecifier') {
88
96
  const importedName = specifier.imported
@@ -166,6 +174,11 @@ export function plumeria(options = {}) {
166
174
  const localCreateStyles = {};
167
175
  const replacements = [];
168
176
  const extractedSheets = [];
177
+ const addSheet = (sheet) => {
178
+ if (!extractedSheets.includes(sheet)) {
179
+ extractedSheets.push(sheet);
180
+ }
181
+ };
169
182
  const processedDecls = new Set();
170
183
  const idSpans = new Set();
171
184
  const excludedSpans = new Set();
@@ -199,7 +212,7 @@ export function plumeria(options = {}) {
199
212
  const records = getStyleRecords(key, style, 2);
200
213
  extractOndemandStyles(style, extractedSheets, scannedTables);
201
214
  records.forEach((r) => {
202
- extractedSheets.push(r.sheet);
215
+ addSheet(r.sheet);
203
216
  });
204
217
  const atomMap = {};
205
218
  records.forEach((r) => (atomMap[r.key] = r.hash));
@@ -356,7 +369,7 @@ export function plumeria(options = {}) {
356
369
  if (typeof style === 'object' && style !== null) {
357
370
  const records = getStyleRecords(key, style, 2);
358
371
  extractOndemandStyles(style, extractedSheets, scannedTables);
359
- records.forEach((r) => extractedSheets.push(r.sheet));
372
+ records.forEach((r) => addSheet(r.sheet));
360
373
  }
361
374
  });
362
375
  }
@@ -388,7 +401,7 @@ export function plumeria(options = {}) {
388
401
  if (typeof style === 'object' && style !== null) {
389
402
  const records = getStyleRecords(propName, style, 2);
390
403
  extractOndemandStyles(style, extractedSheets, scannedTables);
391
- records.forEach((r) => extractedSheets.push(r.sheet));
404
+ records.forEach((r) => addSheet(r.sheet));
392
405
  const atomMap = {};
393
406
  records.forEach((r) => (atomMap[r.key] = r.hash));
394
407
  if (Object.keys(atomMap).length > 0) {
@@ -597,7 +610,7 @@ export function plumeria(options = {}) {
597
610
  extractOndemandStyles(baseStyle, extractedSheets, scannedTables);
598
611
  const hash = genBase36Hash(baseStyle, 1, 8);
599
612
  const records = getStyleRecords(hash, baseStyle, 2);
600
- records.forEach((r) => extractedSheets.push(r.sheet));
613
+ records.forEach((r) => addSheet(r.sheet));
601
614
  const className = records
602
615
  .map((r) => r.hash)
603
616
  .join(' ');
@@ -611,18 +624,10 @@ export function plumeria(options = {}) {
611
624
  const table = {};
612
625
  const combinations = 1 << conditionals.length;
613
626
  for (let i = 0; i < combinations; i++) {
614
- let currentClassNames = [];
627
+ let currentStyle = { ...baseStyle };
615
628
  const seenGroups = new Set();
616
629
  let impossible = false;
617
- if (Object.keys(baseStyle).length > 0) {
618
- extractOndemandStyles(baseStyle, extractedSheets, scannedTables);
619
- const hash = genBase36Hash(baseStyle, 1, 8);
620
- const records = getStyleRecords(hash, baseStyle, 2);
621
- records.forEach((r) => extractedSheets.push(r.sheet));
622
- currentClassNames.push(...records.map((r) => r.hash));
623
- }
624
630
  for (let j = 0; j < conditionals.length; j++) {
625
- let targetStyle = {};
626
631
  if ((i >> j) & 1) {
627
632
  if (conditionals[j].groupId !== undefined) {
628
633
  if (seenGroups.has(conditionals[j].groupId)) {
@@ -631,24 +636,24 @@ export function plumeria(options = {}) {
631
636
  }
632
637
  seenGroups.add(conditionals[j].groupId);
633
638
  }
634
- targetStyle = conditionals[j].truthy;
639
+ currentStyle = deepMerge(currentStyle, conditionals[j].truthy);
635
640
  }
636
641
  else {
637
- targetStyle = conditionals[j].falsy;
638
- }
639
- if (Object.keys(targetStyle).length > 0) {
640
- extractOndemandStyles(targetStyle, extractedSheets, scannedTables);
641
- const hash = genBase36Hash(targetStyle, 1, 8);
642
- const records = getStyleRecords(hash, targetStyle, 2);
643
- records.forEach((r) => extractedSheets.push(r.sheet));
644
- currentClassNames.push(...records.map((r) => r.hash));
642
+ currentStyle = deepMerge(currentStyle, conditionals[j].falsy);
645
643
  }
646
644
  }
647
645
  if (impossible) {
648
646
  table[i] = '';
649
647
  continue;
650
648
  }
651
- table[i] = currentClassNames.join(' ');
649
+ extractOndemandStyles(currentStyle, extractedSheets, scannedTables);
650
+ const hash = genBase36Hash(currentStyle, 1, 8);
651
+ const records = getStyleRecords(hash, currentStyle, 2);
652
+ records.forEach((r) => addSheet(r.sheet));
653
+ const className = records
654
+ .map((r) => r.hash)
655
+ .join(' ');
656
+ table[i] = className;
652
657
  }
653
658
  let indexExpr = '';
654
659
  if (conditionals.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/vite-plugin",
3
- "version": "6.0.0",
3
+ "version": "6.0.2",
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.0"
25
+ "@plumeria/utils": "^6.0.2"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.8",