@plumeria/unplugin 16.2.5 → 16.2.6

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/core.js CHANGED
@@ -151,6 +151,24 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
151
151
  }
152
152
  }
153
153
  const scannedTables = (0, utils_1.scanAll)();
154
+ if (scannedTables.componentPropsTable) {
155
+ const parentFiles = new Set();
156
+ for (const compKey of Object.keys(scannedTables.componentPropsTable)) {
157
+ if (!compKey.startsWith(`${id}-`))
158
+ continue;
159
+ const props = scannedTables.componentPropsTable[compKey];
160
+ for (const propName of Object.keys(props)) {
161
+ for (const entry of props[propName]) {
162
+ if (entry.filePath !== id) {
163
+ parentFiles.add(entry.filePath);
164
+ }
165
+ }
166
+ }
167
+ }
168
+ for (const parentFile of parentFiles) {
169
+ addDependency(parentFile);
170
+ }
171
+ }
154
172
  const extractedSheets = [];
155
173
  const addSheet = (sheet) => {
156
174
  if (!extractedSheets.includes(sheet)) {
@@ -885,7 +903,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
885
903
  const currentGroupId = ++groupIdCounter;
886
904
  const uniqueEntries = [];
887
905
  propPossibilities.forEach((entry) => {
888
- if (!uniqueEntries.some((x) => x.index === entry.index)) {
906
+ if (!uniqueEntries.some((x) => x.key === entry.key)) {
889
907
  uniqueEntries.push(entry);
890
908
  }
891
909
  });
@@ -893,12 +911,12 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
893
911
  conditionals.push({
894
912
  test: expr,
895
913
  testLHS,
896
- testString: `${testLHS} === ${entry.index}`,
914
+ testString: `${testLHS} === ${JSON.stringify(entry.key)}`,
897
915
  truthy: entry.styleObj,
898
916
  falsy: {},
899
917
  groupId: currentGroupId,
900
918
  groupName: undefined,
901
- valueName: String(entry.index),
919
+ valueName: entry.key,
902
920
  varName,
903
921
  });
904
922
  });
@@ -1504,6 +1522,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1504
1522
  const imported = localImports[parentTagName];
1505
1523
  if (imported) {
1506
1524
  compKey = `${imported.actualPath}-${imported.importedName}`;
1525
+ const resolved = (0, utils_1.resolveExport)(imported.actualPath, imported.importedName);
1526
+ if (resolved) {
1527
+ compKey = `${resolved.filePath}-${resolved.localName}`;
1528
+ }
1507
1529
  }
1508
1530
  else {
1509
1531
  compKey = `${resourcePath}-${parentTagName}`;
@@ -1513,28 +1535,28 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1513
1535
  node.value &&
1514
1536
  node.value.type === 'JSXExpressionContainer') {
1515
1537
  const expr = node.value.expression;
1538
+ const replaceWithKey = (subNode) => {
1539
+ const entry = list.find((x) => x.spanStart === subNode.span.start &&
1540
+ x.filePath === resourcePath);
1541
+ if (entry) {
1542
+ replacements.push({
1543
+ start: subNode.span.start - baseByteOffset,
1544
+ end: subNode.span.end - baseByteOffset,
1545
+ content: JSON.stringify(entry.key),
1546
+ });
1547
+ processStyleRecords(entry.styleObj);
1548
+ return true;
1549
+ }
1550
+ return false;
1551
+ };
1516
1552
  (0, utils_1.traverse)(expr, {
1517
1553
  MemberExpression({ node: subNode }) {
1518
- const entry = list.find((x) => x.spanStart === subNode.span.start &&
1519
- x.filePath === resourcePath);
1520
- if (entry) {
1521
- replacements.push({
1522
- start: subNode.span.start - baseByteOffset,
1523
- end: subNode.span.end - baseByteOffset,
1524
- content: String(entry.index),
1525
- });
1554
+ if (replaceWithKey(subNode)) {
1526
1555
  excludeSubtreeSpans(subNode);
1527
1556
  }
1528
1557
  },
1529
1558
  ArrayExpression({ node: subNode }) {
1530
- const entry = list.find((x) => x.spanStart === subNode.span.start &&
1531
- x.filePath === resourcePath);
1532
- if (entry) {
1533
- replacements.push({
1534
- start: subNode.span.start - baseByteOffset,
1535
- end: subNode.span.end - baseByteOffset,
1536
- content: String(entry.index),
1537
- });
1559
+ if (replaceWithKey(subNode)) {
1538
1560
  excludeSubtreeSpans(subNode);
1539
1561
  }
1540
1562
  },
@@ -1806,8 +1828,10 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
1806
1828
  devCssSheets.set(cssFilename, new Set());
1807
1829
  }
1808
1830
  const acc = devCssSheets.get(cssFilename);
1809
- acc.clear();
1810
- extractedSheets.forEach((sheet) => acc.add(sheet));
1831
+ extractedSheets.forEach((sheet) => {
1832
+ acc.delete(sheet);
1833
+ acc.add(sheet);
1834
+ });
1811
1835
  const accCSS = await (0, utils_1.optimizer)(Array.from(acc).join(''));
1812
1836
  cssLookup.set(cssFilename, accCSS);
1813
1837
  }
package/dist/core.mjs CHANGED
@@ -115,6 +115,24 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
115
115
  }
116
116
  }
117
117
  const scannedTables = scanAll();
118
+ if (scannedTables.componentPropsTable) {
119
+ const parentFiles = new Set();
120
+ for (const compKey of Object.keys(scannedTables.componentPropsTable)) {
121
+ if (!compKey.startsWith(`${id}-`))
122
+ continue;
123
+ const props = scannedTables.componentPropsTable[compKey];
124
+ for (const propName of Object.keys(props)) {
125
+ for (const entry of props[propName]) {
126
+ if (entry.filePath !== id) {
127
+ parentFiles.add(entry.filePath);
128
+ }
129
+ }
130
+ }
131
+ }
132
+ for (const parentFile of parentFiles) {
133
+ addDependency(parentFile);
134
+ }
135
+ }
118
136
  const extractedSheets = [];
119
137
  const addSheet = (sheet) => {
120
138
  if (!extractedSheets.includes(sheet)) {
@@ -849,7 +867,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
849
867
  const currentGroupId = ++groupIdCounter;
850
868
  const uniqueEntries = [];
851
869
  propPossibilities.forEach((entry) => {
852
- if (!uniqueEntries.some((x) => x.index === entry.index)) {
870
+ if (!uniqueEntries.some((x) => x.key === entry.key)) {
853
871
  uniqueEntries.push(entry);
854
872
  }
855
873
  });
@@ -857,12 +875,12 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
857
875
  conditionals.push({
858
876
  test: expr,
859
877
  testLHS,
860
- testString: `${testLHS} === ${entry.index}`,
878
+ testString: `${testLHS} === ${JSON.stringify(entry.key)}`,
861
879
  truthy: entry.styleObj,
862
880
  falsy: {},
863
881
  groupId: currentGroupId,
864
882
  groupName: undefined,
865
- valueName: String(entry.index),
883
+ valueName: entry.key,
866
884
  varName,
867
885
  });
868
886
  });
@@ -1468,6 +1486,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1468
1486
  const imported = localImports[parentTagName];
1469
1487
  if (imported) {
1470
1488
  compKey = `${imported.actualPath}-${imported.importedName}`;
1489
+ const resolved = resolveExport(imported.actualPath, imported.importedName);
1490
+ if (resolved) {
1491
+ compKey = `${resolved.filePath}-${resolved.localName}`;
1492
+ }
1471
1493
  }
1472
1494
  else {
1473
1495
  compKey = `${resourcePath}-${parentTagName}`;
@@ -1477,28 +1499,28 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1477
1499
  node.value &&
1478
1500
  node.value.type === 'JSXExpressionContainer') {
1479
1501
  const expr = node.value.expression;
1502
+ const replaceWithKey = (subNode) => {
1503
+ const entry = list.find((x) => x.spanStart === subNode.span.start &&
1504
+ x.filePath === resourcePath);
1505
+ if (entry) {
1506
+ replacements.push({
1507
+ start: subNode.span.start - baseByteOffset,
1508
+ end: subNode.span.end - baseByteOffset,
1509
+ content: JSON.stringify(entry.key),
1510
+ });
1511
+ processStyleRecords(entry.styleObj);
1512
+ return true;
1513
+ }
1514
+ return false;
1515
+ };
1480
1516
  traverse(expr, {
1481
1517
  MemberExpression({ node: subNode }) {
1482
- const entry = list.find((x) => x.spanStart === subNode.span.start &&
1483
- x.filePath === resourcePath);
1484
- if (entry) {
1485
- replacements.push({
1486
- start: subNode.span.start - baseByteOffset,
1487
- end: subNode.span.end - baseByteOffset,
1488
- content: String(entry.index),
1489
- });
1518
+ if (replaceWithKey(subNode)) {
1490
1519
  excludeSubtreeSpans(subNode);
1491
1520
  }
1492
1521
  },
1493
1522
  ArrayExpression({ node: subNode }) {
1494
- const entry = list.find((x) => x.spanStart === subNode.span.start &&
1495
- x.filePath === resourcePath);
1496
- if (entry) {
1497
- replacements.push({
1498
- start: subNode.span.start - baseByteOffset,
1499
- end: subNode.span.end - baseByteOffset,
1500
- content: String(entry.index),
1501
- });
1523
+ if (replaceWithKey(subNode)) {
1502
1524
  excludeSubtreeSpans(subNode);
1503
1525
  }
1504
1526
  },
@@ -1770,8 +1792,10 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
1770
1792
  devCssSheets.set(cssFilename, new Set());
1771
1793
  }
1772
1794
  const acc = devCssSheets.get(cssFilename);
1773
- acc.clear();
1774
- extractedSheets.forEach((sheet) => acc.add(sheet));
1795
+ extractedSheets.forEach((sheet) => {
1796
+ acc.delete(sheet);
1797
+ acc.add(sheet);
1798
+ });
1775
1799
  const accCSS = await optimizer(Array.from(acc).join(''));
1776
1800
  cssLookup.set(cssFilename, accCSS);
1777
1801
  }
package/dist/vite.js CHANGED
@@ -35,6 +35,7 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  const unplugin_1 = require("unplugin");
37
37
  const core_1 = require("./core");
38
+ const utils_1 = require("@plumeria/utils");
38
39
  const path = __importStar(require("path"));
39
40
  const disk_css_1 = require("./disk-css");
40
41
  function attachViteHooks(plugin, options) {
@@ -44,6 +45,22 @@ function attachViteHooks(plugin, options) {
44
45
  let isDev = false;
45
46
  let viteRoot = process.cwd();
46
47
  const virtualCssPath = useDiskEmit ? (0, disk_css_1.resolveVirtualCssPath)() : '';
48
+ let propsTableSnapshot = {};
49
+ const snapshotPropsTable = () => {
50
+ const snap = {};
51
+ const table = (0, utils_1.scanAll)().componentPropsTable || {};
52
+ for (const compKey of Object.keys(table)) {
53
+ snap[compKey] = {};
54
+ for (const propName of Object.keys(table[compKey])) {
55
+ snap[compKey][propName] = table[compKey][propName]
56
+ .map((e) => e.key)
57
+ .sort()
58
+ .join(',');
59
+ }
60
+ }
61
+ return snap;
62
+ };
63
+ const lastServedCss = new Map();
47
64
  const baseTransform = plugin.transform;
48
65
  plugin.transform = async function (code, id) {
49
66
  const result = await baseTransform.call(this, code, id);
@@ -77,7 +94,11 @@ function attachViteHooks(plugin, options) {
77
94
  const cssFilename = `${baseId}.zero.css`;
78
95
  const mod = devServer.moduleGraph.getModuleById(cssFilename);
79
96
  if (mod) {
80
- devServer.reloadModule(mod);
97
+ const cssContent = cssLookup.get(cssFilename) ?? '';
98
+ if (lastServedCss.get(cssFilename) !== cssContent) {
99
+ lastServedCss.set(cssFilename, cssContent);
100
+ devServer.reloadModule(mod);
101
+ }
81
102
  }
82
103
  }
83
104
  return result;
@@ -117,17 +138,37 @@ function attachViteHooks(plugin, options) {
117
138
  if (!devServer)
118
139
  return;
119
140
  const modules = [...ctx.modules];
120
- if (!ctx.file.includes('node_modules')) {
121
- const affectedProviders = targets
122
- .filter((t) => t.id !== ctx.file)
123
- .map((t) => devServer.moduleGraph.getModuleById(t.id))
124
- .filter((m) => !!m);
125
- affectedProviders.forEach((p) => {
126
- if (!modules.includes(p)) {
127
- modules.push(p);
128
- }
129
- });
141
+ if (ctx.file.includes('node_modules'))
142
+ return modules;
143
+ const addModule = (m) => {
144
+ if (m && !modules.includes(m)) {
145
+ modules.push(m);
146
+ }
147
+ };
148
+ const snapshot = snapshotPropsTable();
149
+ const prevSnapshot = propsTableSnapshot;
150
+ propsTableSnapshot = snapshot;
151
+ const compKeys = new Set([
152
+ ...Object.keys(prevSnapshot),
153
+ ...Object.keys(snapshot),
154
+ ]);
155
+ for (const compKey of compKeys) {
156
+ const prevProps = prevSnapshot[compKey] || {};
157
+ const nextProps = snapshot[compKey] || {};
158
+ const propNames = new Set([
159
+ ...Object.keys(prevProps),
160
+ ...Object.keys(nextProps),
161
+ ]);
162
+ const changed = [...propNames].some((p) => prevProps[p] !== nextProps[p]);
163
+ if (changed) {
164
+ const defFile = compKey.slice(0, compKey.lastIndexOf('-'));
165
+ devServer.moduleGraph.getModulesByFile(defFile)?.forEach(addModule);
166
+ }
130
167
  }
168
+ targets
169
+ .filter((t) => t.id !== ctx.file && t.dependencies.includes(ctx.file))
170
+ .map((t) => devServer.moduleGraph.getModuleById(t.id))
171
+ .forEach((m) => addModule(m));
131
172
  return modules;
132
173
  },
133
174
  };
package/dist/vite.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { createVitePlugin } from 'unplugin';
2
2
  import { unpluginFactory, EXTENSION_PATTERN } from './core.mjs';
3
+ import { scanAll } from '@plumeria/utils';
3
4
  import * as path from 'path';
4
5
  import { resolveVirtualCssPath, ensureVirtualCssFile, writeCssBlock, rewriteImportPath, } from './disk-css.mjs';
5
6
  function attachViteHooks(plugin, options) {
@@ -9,6 +10,22 @@ function attachViteHooks(plugin, options) {
9
10
  let isDev = false;
10
11
  let viteRoot = process.cwd();
11
12
  const virtualCssPath = useDiskEmit ? resolveVirtualCssPath() : '';
13
+ let propsTableSnapshot = {};
14
+ const snapshotPropsTable = () => {
15
+ const snap = {};
16
+ const table = scanAll().componentPropsTable || {};
17
+ for (const compKey of Object.keys(table)) {
18
+ snap[compKey] = {};
19
+ for (const propName of Object.keys(table[compKey])) {
20
+ snap[compKey][propName] = table[compKey][propName]
21
+ .map((e) => e.key)
22
+ .sort()
23
+ .join(',');
24
+ }
25
+ }
26
+ return snap;
27
+ };
28
+ const lastServedCss = new Map();
12
29
  const baseTransform = plugin.transform;
13
30
  plugin.transform = async function (code, id) {
14
31
  const result = await baseTransform.call(this, code, id);
@@ -42,7 +59,11 @@ function attachViteHooks(plugin, options) {
42
59
  const cssFilename = `${baseId}.zero.css`;
43
60
  const mod = devServer.moduleGraph.getModuleById(cssFilename);
44
61
  if (mod) {
45
- devServer.reloadModule(mod);
62
+ const cssContent = cssLookup.get(cssFilename) ?? '';
63
+ if (lastServedCss.get(cssFilename) !== cssContent) {
64
+ lastServedCss.set(cssFilename, cssContent);
65
+ devServer.reloadModule(mod);
66
+ }
46
67
  }
47
68
  }
48
69
  return result;
@@ -82,17 +103,37 @@ function attachViteHooks(plugin, options) {
82
103
  if (!devServer)
83
104
  return;
84
105
  const modules = [...ctx.modules];
85
- if (!ctx.file.includes('node_modules')) {
86
- const affectedProviders = targets
87
- .filter((t) => t.id !== ctx.file)
88
- .map((t) => devServer.moduleGraph.getModuleById(t.id))
89
- .filter((m) => !!m);
90
- affectedProviders.forEach((p) => {
91
- if (!modules.includes(p)) {
92
- modules.push(p);
93
- }
94
- });
106
+ if (ctx.file.includes('node_modules'))
107
+ return modules;
108
+ const addModule = (m) => {
109
+ if (m && !modules.includes(m)) {
110
+ modules.push(m);
111
+ }
112
+ };
113
+ const snapshot = snapshotPropsTable();
114
+ const prevSnapshot = propsTableSnapshot;
115
+ propsTableSnapshot = snapshot;
116
+ const compKeys = new Set([
117
+ ...Object.keys(prevSnapshot),
118
+ ...Object.keys(snapshot),
119
+ ]);
120
+ for (const compKey of compKeys) {
121
+ const prevProps = prevSnapshot[compKey] || {};
122
+ const nextProps = snapshot[compKey] || {};
123
+ const propNames = new Set([
124
+ ...Object.keys(prevProps),
125
+ ...Object.keys(nextProps),
126
+ ]);
127
+ const changed = [...propNames].some((p) => prevProps[p] !== nextProps[p]);
128
+ if (changed) {
129
+ const defFile = compKey.slice(0, compKey.lastIndexOf('-'));
130
+ devServer.moduleGraph.getModulesByFile(defFile)?.forEach(addModule);
131
+ }
95
132
  }
133
+ targets
134
+ .filter((t) => t.id !== ctx.file && t.dependencies.includes(ctx.file))
135
+ .map((t) => devServer.moduleGraph.getModuleById(t.id))
136
+ .forEach((m) => addModule(m));
96
137
  return modules;
97
138
  },
98
139
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "16.2.5",
3
+ "version": "16.2.6",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -89,7 +89,7 @@
89
89
  "dependencies": {
90
90
  "@rollup/pluginutils": "^5.4.0",
91
91
  "unplugin": "^3.0.0",
92
- "@plumeria/utils": "^16.2.5"
92
+ "@plumeria/utils": "^16.2.6"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@swc/core": "1.15.43",