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