@plumeria/turbopack-loader 11.1.2 → 11.2.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 +52 -37
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -385,11 +385,17 @@ async function loader(source) {
|
|
|
385
385
|
const uniqueKey = `${resourcePath}-${node.id.value}`;
|
|
386
386
|
scannedTables.createThemeHashTable[uniqueKey] = hash;
|
|
387
387
|
scannedTables.createThemeObjectTable[hash] = obj;
|
|
388
|
+
mergedCreateThemeHashTable[node.id.value] = hash;
|
|
389
|
+
const themeHashMap = {};
|
|
390
|
+
for (const [key] of Object.entries(obj)) {
|
|
391
|
+
const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
|
|
392
|
+
themeHashMap[key] = `var(--${hash}-${cssVarName})`;
|
|
393
|
+
}
|
|
388
394
|
localCreateStyles[node.id.value] = {
|
|
389
395
|
name: node.id.value,
|
|
390
396
|
type: 'constant',
|
|
391
397
|
obj,
|
|
392
|
-
hashMap:
|
|
398
|
+
hashMap: themeHashMap,
|
|
393
399
|
isExported,
|
|
394
400
|
initSpan: {
|
|
395
401
|
start: init.span.start - baseByteOffset,
|
|
@@ -406,16 +412,42 @@ async function loader(source) {
|
|
|
406
412
|
};
|
|
407
413
|
(0, utils_1.traverse)(ast, {
|
|
408
414
|
ImportDeclaration({ node }) {
|
|
409
|
-
if (node.
|
|
410
|
-
node.
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
415
|
+
if (node.source.value === '@plumeria/core') {
|
|
416
|
+
if (node.typeOnly)
|
|
417
|
+
return;
|
|
418
|
+
const typeOnlySpecs = node.specifiers.filter((s) => s.type === 'ImportSpecifier' && s.isTypeOnly);
|
|
419
|
+
if (typeOnlySpecs.length > 0) {
|
|
420
|
+
const names = typeOnlySpecs
|
|
421
|
+
.map((s) => {
|
|
422
|
+
if (s.type !== 'ImportSpecifier')
|
|
423
|
+
return;
|
|
424
|
+
const imported = s.imported ? s.imported.value : s.local.value;
|
|
425
|
+
const local = s.local.value;
|
|
426
|
+
return imported === local ? imported : `${imported} as ${local}`;
|
|
427
|
+
})
|
|
428
|
+
.join(', ');
|
|
429
|
+
replacements.push({
|
|
430
|
+
start: node.span.start - baseByteOffset,
|
|
431
|
+
end: node.span.end - baseByteOffset,
|
|
432
|
+
content: `import type { ${names} } from '@plumeria/core'`,
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
replacements.push({
|
|
437
|
+
start: node.span.start - baseByteOffset,
|
|
438
|
+
end: node.span.end - baseByteOffset,
|
|
439
|
+
content: '',
|
|
440
|
+
});
|
|
441
|
+
}
|
|
418
442
|
}
|
|
443
|
+
node.specifiers.forEach((specifier) => {
|
|
444
|
+
if (specifier.local) {
|
|
445
|
+
excludedSpans.add(specifier.local.span.start);
|
|
446
|
+
}
|
|
447
|
+
if (specifier.type === 'ImportSpecifier' && specifier.imported) {
|
|
448
|
+
excludedSpans.add(specifier.imported.span.start);
|
|
449
|
+
}
|
|
450
|
+
});
|
|
419
451
|
},
|
|
420
452
|
ExportDeclaration({ node }) {
|
|
421
453
|
if (utils_1.t.isVariableDeclaration(node.declaration)) {
|
|
@@ -1311,6 +1343,7 @@ async function loader(source) {
|
|
|
1311
1343
|
});
|
|
1312
1344
|
parts.push(buffer.subarray(offset));
|
|
1313
1345
|
const transformedSource = Buffer.concat(parts).toString();
|
|
1346
|
+
const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
|
|
1314
1347
|
let relativeImportPath = path.relative(path.dirname(resourcePath), VIRTUAL_FILE_PATH);
|
|
1315
1348
|
relativeImportPath = relativeImportPath.replace(/\\/g, '/');
|
|
1316
1349
|
if (!relativeImportPath.startsWith('.')) {
|
|
@@ -1320,39 +1353,21 @@ async function loader(source) {
|
|
|
1320
1353
|
if (process.env.NODE_ENV === 'production') {
|
|
1321
1354
|
return callback(null, transformedSource);
|
|
1322
1355
|
}
|
|
1323
|
-
if (process.env.NODE_ENV === 'development') {
|
|
1324
|
-
const
|
|
1325
|
-
const projectName = path.basename(this.rootContext);
|
|
1326
|
-
const relativeFromRoot = path
|
|
1327
|
-
.relative(this.rootContext, resourcePath)
|
|
1328
|
-
.replace(/\\/g, '/');
|
|
1329
|
-
const filePathKey = `${projectName}/${relativeFromRoot}`;
|
|
1330
|
-
const startMarker = `/* ---start:${filePathKey} */`;
|
|
1331
|
-
const endMarker = `/* ---end:${filePathKey} */`;
|
|
1356
|
+
if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
|
|
1357
|
+
const newCss = optInCSS + '\n';
|
|
1332
1358
|
let currentCss = '';
|
|
1333
1359
|
try {
|
|
1334
1360
|
currentCss = fs.readFileSync(VIRTUAL_FILE_PATH, 'utf-8');
|
|
1335
1361
|
}
|
|
1336
1362
|
catch (e) {
|
|
1337
1363
|
}
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
|
|
1346
|
-
const before = currentCss.substring(0, startIndex);
|
|
1347
|
-
const after = currentCss.substring(endIndex + endMarker.length);
|
|
1348
|
-
nextCss = before + newBlock + after;
|
|
1349
|
-
}
|
|
1350
|
-
else if (newBlock) {
|
|
1351
|
-
nextCss = currentCss + (currentCss.trim() ? '\n\n' : '') + newBlock;
|
|
1352
|
-
}
|
|
1353
|
-
nextCss = nextCss.replace(/\n{3,}/g, '\n\n').trim() + '\n';
|
|
1354
|
-
if (currentCss !== nextCss) {
|
|
1355
|
-
fs.writeFileSync(VIRTUAL_FILE_PATH, nextCss, 'utf-8');
|
|
1364
|
+
if (!currentCss.includes(optInCSS)) {
|
|
1365
|
+
if (currentCss) {
|
|
1366
|
+
fs.writeFileSync(VIRTUAL_FILE_PATH, currentCss + newCss, 'utf-8');
|
|
1367
|
+
}
|
|
1368
|
+
else {
|
|
1369
|
+
fs.writeFileSync(VIRTUAL_FILE_PATH, newCss, 'utf-8');
|
|
1370
|
+
}
|
|
1356
1371
|
}
|
|
1357
1372
|
}
|
|
1358
1373
|
return callback(null, transformedSource + postfix);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@plumeria/turbopack-loader",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.2.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": "^11.
|
|
25
|
+
"@plumeria/utils": "^11.2.0"
|
|
26
26
|
},
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@swc/core": "1.15.21",
|