@plumeria/webpack-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 -16
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -14,31 +14,55 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
14
14
|
fs_1.default.writeFileSync(VIRTUAL_FILE_PATH, '/** Placeholder file */', 'utf-8');
|
|
15
15
|
}
|
|
16
16
|
function loader(source) {
|
|
17
|
-
const loaderContext = this;
|
|
18
17
|
const callback = this.async();
|
|
19
18
|
const isProduction = process.env.NODE_ENV === 'production';
|
|
20
19
|
if (this.resourcePath.includes('node_modules') ||
|
|
21
20
|
!source.includes('@plumeria/core')) {
|
|
22
21
|
return callback(null, source);
|
|
23
22
|
}
|
|
23
|
+
const fileStyles = {};
|
|
24
24
|
this.clearDependencies();
|
|
25
25
|
this.addDependency(this.resourcePath);
|
|
26
|
-
const scannedTables = (0, utils_1.scanAll)();
|
|
27
|
-
const fileStyles = {};
|
|
28
26
|
const ast = (0, core_1.parseSync)(source, {
|
|
29
27
|
syntax: 'typescript',
|
|
30
28
|
tsx: true,
|
|
31
29
|
target: 'es2022',
|
|
32
30
|
});
|
|
31
|
+
for (const node of ast.body) {
|
|
32
|
+
if (node.type === 'ImportDeclaration') {
|
|
33
|
+
const sourcePath = node.source.value;
|
|
34
|
+
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, this.resourcePath);
|
|
35
|
+
if (actualPath) {
|
|
36
|
+
this.addDependency(actualPath);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
const scannedTables = (0, utils_1.scanAll)();
|
|
33
41
|
const localConsts = (0, utils_1.collectLocalConsts)(ast);
|
|
34
42
|
const resourcePath = this.resourcePath;
|
|
35
43
|
const importMap = {};
|
|
44
|
+
const plumeriaAliases = {};
|
|
36
45
|
(0, utils_1.traverse)(ast, {
|
|
37
46
|
ImportDeclaration({ node }) {
|
|
38
47
|
const sourcePath = node.source.value;
|
|
48
|
+
if (sourcePath === '@plumeria/core') {
|
|
49
|
+
node.specifiers.forEach((specifier) => {
|
|
50
|
+
if (specifier.type === 'ImportNamespaceSpecifier') {
|
|
51
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
52
|
+
}
|
|
53
|
+
else if (specifier.type === 'ImportDefaultSpecifier') {
|
|
54
|
+
plumeriaAliases[specifier.local.value] = 'NAMESPACE';
|
|
55
|
+
}
|
|
56
|
+
else if (specifier.type === 'ImportSpecifier') {
|
|
57
|
+
const importedName = specifier.imported
|
|
58
|
+
? specifier.imported.value
|
|
59
|
+
: specifier.local.value;
|
|
60
|
+
plumeriaAliases[specifier.local.value] = importedName;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
39
64
|
const actualPath = (0, utils_1.resolveImportPath)(sourcePath, resourcePath);
|
|
40
65
|
if (actualPath) {
|
|
41
|
-
loaderContext.addDependency(actualPath);
|
|
42
66
|
node.specifiers.forEach((specifier) => {
|
|
43
67
|
if (specifier.type === 'ImportSpecifier') {
|
|
44
68
|
const importedName = specifier.imported
|
|
@@ -119,6 +143,11 @@ function loader(source) {
|
|
|
119
143
|
const localCreateStyles = {};
|
|
120
144
|
const replacements = [];
|
|
121
145
|
const extractedSheets = [];
|
|
146
|
+
const addSheet = (sheet) => {
|
|
147
|
+
if (!extractedSheets.includes(sheet)) {
|
|
148
|
+
extractedSheets.push(sheet);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
122
151
|
const processedDecls = new Set();
|
|
123
152
|
const idSpans = new Set();
|
|
124
153
|
const excludedSpans = new Set();
|
|
@@ -135,14 +164,31 @@ function loader(source) {
|
|
|
135
164
|
}
|
|
136
165
|
};
|
|
137
166
|
const registerStyle = (node, declSpan, isExported) => {
|
|
167
|
+
let propName;
|
|
138
168
|
if (utils_1.t.isIdentifier(node.id) &&
|
|
139
169
|
node.init &&
|
|
140
170
|
utils_1.t.isCallExpression(node.init) &&
|
|
141
|
-
utils_1.t.isMemberExpression(node.init.callee) &&
|
|
142
|
-
utils_1.t.isIdentifier(node.init.callee.object, { name: 'css' }) &&
|
|
143
|
-
utils_1.t.isIdentifier(node.init.callee.property) &&
|
|
144
171
|
node.init.arguments.length >= 1) {
|
|
145
|
-
const
|
|
172
|
+
const callee = node.init.callee;
|
|
173
|
+
if (utils_1.t.isMemberExpression(callee) &&
|
|
174
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
175
|
+
utils_1.t.isIdentifier(callee.property)) {
|
|
176
|
+
const objectName = callee.object.value;
|
|
177
|
+
const propertyName = callee.property.value;
|
|
178
|
+
const alias = plumeriaAliases[objectName];
|
|
179
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
180
|
+
propName = propertyName;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
184
|
+
const calleeName = callee.value;
|
|
185
|
+
const originalName = plumeriaAliases[calleeName];
|
|
186
|
+
if (originalName) {
|
|
187
|
+
propName = originalName;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (propName) {
|
|
146
192
|
if (propName === 'create' &&
|
|
147
193
|
utils_1.t.isObjectExpression(node.init.arguments[0].expression)) {
|
|
148
194
|
const obj = (0, utils_1.objectExpressionToObject)(node.init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedThemeTable, mergedCreateTable, mergedVariantsTable);
|
|
@@ -153,7 +199,7 @@ function loader(source) {
|
|
|
153
199
|
if (!isProduction) {
|
|
154
200
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
155
201
|
records.forEach((r) => {
|
|
156
|
-
|
|
202
|
+
addSheet(r.sheet);
|
|
157
203
|
});
|
|
158
204
|
}
|
|
159
205
|
const atomMap = {};
|
|
@@ -263,10 +309,25 @@ function loader(source) {
|
|
|
263
309
|
},
|
|
264
310
|
CallExpression({ node }) {
|
|
265
311
|
const callee = node.callee;
|
|
312
|
+
let propName;
|
|
266
313
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
267
|
-
utils_1.t.isIdentifier(callee.object
|
|
314
|
+
utils_1.t.isIdentifier(callee.object) &&
|
|
268
315
|
utils_1.t.isIdentifier(callee.property)) {
|
|
269
|
-
const
|
|
316
|
+
const objectName = callee.object.value;
|
|
317
|
+
const propertyName = callee.property.value;
|
|
318
|
+
const alias = plumeriaAliases[objectName];
|
|
319
|
+
if (alias === 'NAMESPACE' || objectName === 'css') {
|
|
320
|
+
propName = propertyName;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (utils_1.t.isIdentifier(callee)) {
|
|
324
|
+
const calleeName = callee.value;
|
|
325
|
+
const originalName = plumeriaAliases[calleeName];
|
|
326
|
+
if (originalName) {
|
|
327
|
+
propName = originalName;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
if (propName) {
|
|
270
331
|
const args = node.arguments;
|
|
271
332
|
if (propName === 'keyframes' &&
|
|
272
333
|
args.length > 0 &&
|
|
@@ -314,7 +375,7 @@ function loader(source) {
|
|
|
314
375
|
const records = (0, utils_1.getStyleRecords)(key, style, 2);
|
|
315
376
|
if (!isProduction) {
|
|
316
377
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
317
|
-
records.forEach((r) =>
|
|
378
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
318
379
|
}
|
|
319
380
|
}
|
|
320
381
|
});
|
|
@@ -348,7 +409,7 @@ function loader(source) {
|
|
|
348
409
|
const records = (0, utils_1.getStyleRecords)(propName, style, 2);
|
|
349
410
|
if (!isProduction) {
|
|
350
411
|
(0, utils_1.extractOndemandStyles)(style, extractedSheets, scannedTables);
|
|
351
|
-
records.forEach((r) =>
|
|
412
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
352
413
|
}
|
|
353
414
|
const atomMap = {};
|
|
354
415
|
records.forEach((r) => (atomMap[r.key] = r.hash));
|
|
@@ -366,9 +427,26 @@ function loader(source) {
|
|
|
366
427
|
},
|
|
367
428
|
CallExpression({ node }) {
|
|
368
429
|
const callee = node.callee;
|
|
430
|
+
let isPropsCall = false;
|
|
369
431
|
if (utils_1.t.isMemberExpression(callee) &&
|
|
370
|
-
utils_1.t.isIdentifier(callee.object
|
|
371
|
-
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) {
|
|
372
450
|
const args = node.arguments;
|
|
373
451
|
const resolveStyleObject = (expr) => {
|
|
374
452
|
if (utils_1.t.isObjectExpression(expr)) {
|
|
@@ -561,7 +639,7 @@ function loader(source) {
|
|
|
561
639
|
const hash = (0, zss_engine_1.genBase36Hash)(baseStyle, 1, 8);
|
|
562
640
|
const records = (0, utils_1.getStyleRecords)(hash, baseStyle, 2);
|
|
563
641
|
if (!isProduction) {
|
|
564
|
-
records.forEach((r) =>
|
|
642
|
+
records.forEach((r) => addSheet(r.sheet));
|
|
565
643
|
}
|
|
566
644
|
const className = records.map((r) => r.hash).join(' ');
|
|
567
645
|
replacements.push({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/webpack-plugin",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.1.0",
|
|
4
4
|
"description": "Plumeria Webpack plugin",
|
|
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.0
|
|
25
|
+
"@plumeria/utils": "^6.1.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.8",
|