@plumeria/turbopack-loader 10.4.3 → 10.5.1

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 +26 -9
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1323,21 +1323,38 @@ async function loader(source) {
1323
1323
  if (process.env.NODE_ENV === 'production') {
1324
1324
  return callback(null, transformedSource);
1325
1325
  }
1326
- if (extractedSheets.length > 0 && process.env.NODE_ENV === 'development') {
1327
- const newCss = optInCSS + '\n';
1326
+ if (process.env.NODE_ENV === 'development') {
1327
+ const projectName = path.basename(this.rootContext);
1328
+ const relativeFromRoot = path
1329
+ .relative(this.rootContext, resourcePath)
1330
+ .replace(/\\/g, '/');
1331
+ const filePathKey = `${projectName}/${relativeFromRoot}`;
1332
+ const startMarker = `/* ---start:${filePathKey} */`;
1333
+ const endMarker = `/* ---end:${filePathKey} */`;
1328
1334
  let currentCss = '';
1329
1335
  try {
1330
1336
  currentCss = fs.readFileSync(VIRTUAL_FILE_PATH, 'utf-8');
1331
1337
  }
1332
1338
  catch (e) {
1333
1339
  }
1334
- if (!currentCss.includes(optInCSS)) {
1335
- if (currentCss) {
1336
- fs.writeFileSync(VIRTUAL_FILE_PATH, currentCss + newCss, 'utf-8');
1337
- }
1338
- else {
1339
- fs.writeFileSync(VIRTUAL_FILE_PATH, newCss, 'utf-8');
1340
- }
1340
+ let nextCss = currentCss;
1341
+ const cleanOptInCSS = optInCSS.trim();
1342
+ const newBlock = cleanOptInCSS
1343
+ ? `${startMarker}\n${cleanOptInCSS}\n${endMarker}`
1344
+ : '';
1345
+ const startIndex = currentCss.indexOf(startMarker);
1346
+ const endIndex = currentCss.indexOf(endMarker);
1347
+ if (startIndex !== -1 && endIndex !== -1 && endIndex > startIndex) {
1348
+ const before = currentCss.substring(0, startIndex);
1349
+ const after = currentCss.substring(endIndex + endMarker.length);
1350
+ nextCss = before + newBlock + after;
1351
+ }
1352
+ else if (newBlock) {
1353
+ nextCss = currentCss + (currentCss.trim() ? '\n\n' : '') + newBlock;
1354
+ }
1355
+ nextCss = nextCss.replace(/\n{3,}/g, '\n\n').trim() + '\n';
1356
+ if (currentCss !== nextCss) {
1357
+ fs.writeFileSync(VIRTUAL_FILE_PATH, nextCss, 'utf-8');
1341
1358
  }
1342
1359
  }
1343
1360
  return callback(null, transformedSource + postfix);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "10.4.3",
3
+ "version": "10.5.1",
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": "^10.4.3"
25
+ "@plumeria/utils": "^10.5.1"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@swc/core": "1.15.21",