@plumeria/turbopack-loader 18.4.2 → 18.5.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.
@@ -1,2 +1,2 @@
1
- export declare function acquireLock(lockDir: string, delayMs?: number, maxDelayMs?: number): Promise<void>;
1
+ export declare function acquireLock(lockDir: string, delayMs?: number, maxDelayMs?: number, timeoutMs?: number): Promise<void>;
2
2
  export declare function releaseLockSync(lockDir: string): void;
package/dist/file-lock.js CHANGED
@@ -37,7 +37,8 @@ exports.acquireLock = acquireLock;
37
37
  exports.releaseLockSync = releaseLockSync;
38
38
  const fs = __importStar(require("fs"));
39
39
  const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
40
- async function acquireLock(lockDir, delayMs = 2, maxDelayMs = 50) {
40
+ async function acquireLock(lockDir, delayMs = 2, maxDelayMs = 50, timeoutMs = 30_000) {
41
+ const started = Date.now();
41
42
  let delay = delayMs;
42
43
  while (true) {
43
44
  try {
@@ -46,7 +47,11 @@ async function acquireLock(lockDir, delayMs = 2, maxDelayMs = 50) {
46
47
  }
47
48
  catch (err) {
48
49
  if (err.code === 'EEXIST') {
49
- await sleep(delay);
50
+ const remaining = timeoutMs - (Date.now() - started);
51
+ if (remaining <= 0) {
52
+ throw new Error(`Plumeria: Timed out waiting for CSS lock "${lockDir}". If no build is running, remove the stale lock directory and retry.`, { cause: err });
53
+ }
54
+ await sleep(Math.min(delay, remaining));
50
55
  delay = Math.min(delay * 2, maxDelayMs);
51
56
  continue;
52
57
  }
package/dist/index.js CHANGED
@@ -77,7 +77,10 @@ async function generateProductionCss(virtualFilePath, options) {
77
77
  }
78
78
  const ensureProductionCss = (virtualFilePath, options) => {
79
79
  if (!productionCss) {
80
- productionCss = generateProductionCss(virtualFilePath, options);
80
+ productionCss = generateProductionCss(virtualFilePath, options).catch((error) => {
81
+ productionCss = null;
82
+ throw error;
83
+ });
81
84
  }
82
85
  return productionCss;
83
86
  };
@@ -213,6 +216,7 @@ async function loader(source) {
213
216
  utils_1.t.isFunctionExpression(node)) {
214
217
  const rootId = (0, utils_1.getRootIdentifier)(node);
215
218
  const isPlumeriaStyle = rootId &&
219
+ isVisibleReference(node) &&
216
220
  ((localCreateStyles[rootId] !== undefined &&
217
221
  localCreateStyles[rootId].type !== 'constant') ||
218
222
  mergedCreateTable[rootId] !== undefined ||
@@ -229,6 +233,10 @@ async function loader(source) {
229
233
  }
230
234
  }
231
235
  };
236
+ const scannedTables = (0, utils_1.scanAll)();
237
+ const ownFailure = (0, utils_1.resolveFileError)(resourcePath, '');
238
+ if (ownFailure)
239
+ throwCompilationError(`Plumeria: ${ownFailure.message}`);
232
240
  for (const node of ast.body) {
233
241
  if (node.type === 'ImportDeclaration') {
234
242
  const sourcePath = node.source.value;
@@ -242,7 +250,6 @@ async function loader(source) {
242
250
  }
243
251
  }
244
252
  }
245
- const scannedTables = (0, utils_1.scanAll)();
246
253
  if (scannedTables.componentPropsTable) {
247
254
  const parentFiles = new Set();
248
255
  for (const compKey of Object.keys(scannedTables.componentPropsTable)) {
@@ -510,14 +517,70 @@ async function loader(source) {
510
517
  }
511
518
  };
512
519
  const replacements = [];
520
+ const deferredSources = [];
521
+ const deferSource = (node, stripObject = false) => {
522
+ const token = `__plumeria_preserved_${deferredSources.length}__`;
523
+ deferredSources.push({
524
+ token,
525
+ start: node.span.start - baseByteOffset,
526
+ end: node.span.end - baseByteOffset,
527
+ stripObject,
528
+ });
529
+ return token;
530
+ };
513
531
  const dynamicFnCalls = [];
514
532
  const processedDecls = new Set();
533
+ const separatelyExported = new Set();
534
+ for (const statement of ast.body) {
535
+ if (statement.type !== 'ExportNamedDeclaration' || statement.source)
536
+ continue;
537
+ for (const specifier of statement.specifiers) {
538
+ if (specifier.type === 'ExportSpecifier' &&
539
+ utils_1.t.isIdentifier(specifier.orig)) {
540
+ separatelyExported.add(specifier.orig.value);
541
+ }
542
+ }
543
+ }
515
544
  const idSpans = new Set();
516
545
  const excludedSpans = new Set();
517
546
  const referenceIdents = (0, utils_1.collectReferenceIdentifiers)(ast);
547
+ const topLevelDeclarators = new Set();
548
+ for (const statement of ast.body) {
549
+ const declaration = unwrapExport(statement);
550
+ if (utils_1.t.isVariableDeclaration(declaration)) {
551
+ declaration.declarations.forEach((decl) => topLevelDeclarators.add(decl));
552
+ }
553
+ }
554
+ const unwrapStyleExpression = (node) => {
555
+ while (node &&
556
+ [
557
+ 'ParenthesisExpression',
558
+ 'TsAsExpression',
559
+ 'TsSatisfiesExpression',
560
+ 'TsNonNullExpression',
561
+ 'TsConstAssertion',
562
+ 'TsTypeAssertion',
563
+ ].includes(node.type))
564
+ node = node.expression;
565
+ return node;
566
+ };
567
+ const literalObjectArgument = (node, seen = new Set()) => {
568
+ node = unwrapStyleExpression(node);
569
+ if (utils_1.t.isObjectExpression(node))
570
+ return node;
571
+ if (!utils_1.t.isIdentifier(node) || seen.has(node.value))
572
+ return null;
573
+ seen.add(node.value);
574
+ const declaration = [...topLevelDeclarators].find((decl) => utils_1.t.isIdentifier(decl.id) &&
575
+ decl.id.value === node.value);
576
+ return declaration?.init
577
+ ? literalObjectArgument(declaration.init, seen)
578
+ : null;
579
+ };
580
+ const registeredStyleCalls = new Set();
518
581
  const registerStyle = (node, declSpan, isExported) => {
519
582
  let propName;
520
- const init = node.init;
583
+ const init = unwrapStyleExpression(node.init);
521
584
  if (utils_1.t.isIdentifier(node.id) &&
522
585
  init &&
523
586
  utils_1.t.isCallExpression(init) &&
@@ -542,6 +605,19 @@ async function loader(source) {
542
605
  }
543
606
  }
544
607
  if (propName && init && utils_1.t.isCallExpression(init)) {
608
+ if (['create', 'createTheme', 'createStatic'].includes(propName) &&
609
+ !topLevelDeclarators.has(node)) {
610
+ throwCompilationError(`Plumeria: css.${propName} must be assigned to a top-level variable so its styles can be resolved across files. Move this declaration outside the function or block.`, node);
611
+ }
612
+ if (['create', 'createTheme', 'createStatic'].includes(propName)) {
613
+ const argumentIndex = propName === 'createTheme' ? 1 : 0;
614
+ const argument = init.arguments[argumentIndex];
615
+ const object = argument && literalObjectArgument(argument.expression);
616
+ if (!object)
617
+ throwCompilationError(`Plumeria: css.${propName} needs a style object it can read at build time. Pass an object literal or a top-level constant containing one.`, init);
618
+ argument.expression = object;
619
+ registeredStyleCalls.add(init.span.start);
620
+ }
545
621
  if (propName === 'create' &&
546
622
  utils_1.t.isObjectExpression(init.arguments[0].expression)) {
547
623
  const obj = (0, utils_1.objectExpressionToObject)(init.arguments[0].expression, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
@@ -712,7 +788,9 @@ async function loader(source) {
712
788
  if (processedDecls.has(node))
713
789
  return;
714
790
  node.declarations.forEach((decl) => {
715
- registerStyle(decl, node.span, false);
791
+ registerStyle(decl, node.span, node.declarations.length > 1 ||
792
+ (utils_1.t.isIdentifier(decl.id) &&
793
+ separatelyExported.has(decl.id.value)));
716
794
  checkStyleAliasAssignment(decl);
717
795
  });
718
796
  },
@@ -737,6 +815,10 @@ async function loader(source) {
737
815
  }
738
816
  }
739
817
  if (propName) {
818
+ if (['create', 'createTheme', 'createStatic'].includes(propName) &&
819
+ !registeredStyleCalls.has(node.span.start)) {
820
+ throwCompilationError(`Plumeria: css.${propName} must be assigned to a named top-level variable. Destructuring, assignment statements, and default-exported calls cannot be compiled.`, node);
821
+ }
740
822
  const args = node.arguments;
741
823
  if (propName === 'keyframes' && args.length > 0) {
742
824
  const expr = args[0].expression;
@@ -802,12 +884,17 @@ async function loader(source) {
802
884
  const jsxOpeningElementMap = new Map();
803
885
  const componentParamNames = new Set();
804
886
  const addFirstParamName = (fn) => {
805
- const p = fn.params[0];
887
+ const first = fn.params[0];
888
+ const p = unwrapPatternDefault(first?.pat ?? first);
806
889
  if (utils_1.t.isIdentifier(p)) {
807
890
  componentParamNames.add(p.value);
808
891
  }
809
- else if (p?.pat && utils_1.t.isIdentifier(p.pat)) {
810
- componentParamNames.add(p.pat.value);
892
+ else if (p?.type === 'ObjectPattern') {
893
+ for (const item of p.properties) {
894
+ if (item.type === 'RestElement' && utils_1.t.isIdentifier(item.argument)) {
895
+ componentParamNames.add(item.argument.value);
896
+ }
897
+ }
811
898
  }
812
899
  };
813
900
  for (const node of ast.body) {
@@ -843,7 +930,21 @@ async function loader(source) {
843
930
  const end = node.span.end - baseByteOffset;
844
931
  return sourceBuffer.subarray(start, end).toString('utf-8');
845
932
  };
933
+ const isVisibleReference = (expr) => {
934
+ if (utils_1.t.isIdentifier(expr))
935
+ return referenceIdents.references.has(expr.span.start);
936
+ if (utils_1.t.isMemberExpression(expr))
937
+ return isVisibleReference(expr.object);
938
+ if (utils_1.t.isCallExpression(expr) &&
939
+ expr.callee.type !== 'Super' &&
940
+ expr.callee.type !== 'Import')
941
+ return isVisibleReference(expr.callee);
942
+ return true;
943
+ };
846
944
  const resolveStyleObject = (expr) => {
945
+ expr = (0, utils_1.unwrapExpression)(expr);
946
+ if (!isVisibleReference(expr))
947
+ return null;
847
948
  if (utils_1.t.isObjectExpression(expr)) {
848
949
  return (0, utils_1.objectExpressionToObject)(expr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
849
950
  }
@@ -909,6 +1010,8 @@ async function loader(source) {
909
1010
  const callee = expr.callee;
910
1011
  if (!utils_1.t.isIdentifier(callee.object) || !utils_1.t.isIdentifier(callee.property))
911
1012
  return null;
1013
+ if (!isVisibleReference(callee.object))
1014
+ return null;
912
1015
  const styleInfo = localCreateStyles[callee.object.value];
913
1016
  const func = styleInfo?.functions?.[callee.property.value] ??
914
1017
  createFunctionImportMap[callee.object.value]?.[callee.property.value];
@@ -919,7 +1022,12 @@ async function loader(source) {
919
1022
  return null;
920
1023
  const tempStaticTable = { ...mergedStaticTable };
921
1024
  const runtime = [];
922
- const resolveObjectArg = (argExpr) => (0, utils_1.objectExpressionToObject)(argExpr, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
1025
+ const resolveObjectArg = (argExpr) => (0, utils_1.objectExpressionToObject)({
1026
+ ...argExpr,
1027
+ properties: argExpr.properties.filter((prop) => prop.type === 'Identifier' ||
1028
+ (prop.type === 'KeyValueProperty' &&
1029
+ isStaticArgValue(prop.value))),
1030
+ }, mergedStaticTable, mergedKeyframesTable, mergedViewTransitionTable, mergedCreateThemeHashTable, scannedTables.createThemeObjectTable, mergedCreateTable, mergedCreateStaticHashTable, scannedTables.createStaticObjectTable, mergedVariantsTable);
923
1031
  if (func.named) {
924
1032
  const argExpr = callArgs[0]?.expression;
925
1033
  if (callArgs.length > 1 ||
@@ -1041,6 +1149,8 @@ async function loader(source) {
1041
1149
  utils_1.t.isStringLiteral(node.property.expression)) {
1042
1150
  return null;
1043
1151
  }
1152
+ if (!isVisibleReference(node.object))
1153
+ return null;
1044
1154
  const varName = node.object.value;
1045
1155
  const obj = resolveCreateObject(varName);
1046
1156
  return obj ? { varName, keyExpr: node.property.expression, obj } : null;
@@ -1134,8 +1244,14 @@ async function loader(source) {
1134
1244
  return buildDecision(node, prefix, off, { n: 0 }, scoped);
1135
1245
  };
1136
1246
  const collectConditions = (node, currentTestStrings = [], argOrder) => {
1247
+ node = (0, utils_1.unwrapExpression)(node);
1137
1248
  if (isNoOpStyle(node))
1138
1249
  return true;
1250
+ if (node.type === 'ArrayExpression') {
1251
+ return node.elements.every((element) => !element ||
1252
+ (!element.spread &&
1253
+ collectConditions(element.expression, currentTestStrings, argOrder)));
1254
+ }
1139
1255
  let branchStyle = resolveStyleObject(node);
1140
1256
  if (!branchStyle) {
1141
1257
  const dynamic = resolveDynamicCall(node);
@@ -1188,13 +1304,12 @@ async function loader(source) {
1188
1304
  return true;
1189
1305
  }
1190
1306
  }
1191
- collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
1192
- collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
1193
- return true;
1307
+ const consequentHandled = collectConditions(node.consequent, [...currentTestStrings, `(${testSource})`], argOrder);
1308
+ const alternateHandled = collectConditions(node.alternate, [...currentTestStrings, `!(${testSource})`], argOrder);
1309
+ return consequentHandled && alternateHandled;
1194
1310
  }
1195
1311
  else if (node.type === 'BinaryExpression' && node.operator === '&&') {
1196
- collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
1197
- return true;
1312
+ return collectConditions(node.right, [...currentTestStrings, `(${getSource(node.left)})`], argOrder);
1198
1313
  }
1199
1314
  else if (node.type === 'ParenthesisExpression') {
1200
1315
  return collectConditions(node.expression, currentTestStrings, argOrder);
@@ -1296,7 +1411,11 @@ async function loader(source) {
1296
1411
  hash = mergedVariantsTable[varName];
1297
1412
  if (hash && scannedTables.variantsObjectTable[hash])
1298
1413
  variantObj = scannedTables.variantsObjectTable[hash];
1299
- if (!variantObj && localCreateStyles[varName]?.obj)
1414
+ if (!isVisibleReference(expr))
1415
+ variantObj = undefined;
1416
+ if (isVisibleReference(expr) &&
1417
+ !variantObj &&
1418
+ localCreateStyles[varName]?.obj)
1300
1419
  variantObj = localCreateStyles[varName].obj;
1301
1420
  if (variantObj) {
1302
1421
  const callArgs = expr.arguments;
@@ -1407,7 +1526,11 @@ async function loader(source) {
1407
1526
  hash = mergedVariantsTable[varName];
1408
1527
  if (hash && scannedTables.variantsObjectTable[hash])
1409
1528
  variantObj = scannedTables.variantsObjectTable[hash];
1410
- if (!variantObj && localCreateStyles[varName]?.obj)
1529
+ if (!isVisibleReference(expr))
1530
+ variantObj = undefined;
1531
+ if (isVisibleReference(expr) &&
1532
+ !variantObj &&
1533
+ localCreateStyles[varName]?.obj)
1411
1534
  variantObj = localCreateStyles[varName].obj;
1412
1535
  if (variantObj) {
1413
1536
  Object.entries(variantObj).forEach(([groupName, groupVariants]) => {
@@ -1437,7 +1560,9 @@ async function loader(source) {
1437
1560
  utils_1.t.isIdentifier(expr.object) &&
1438
1561
  expr.property.type === 'Computed') {
1439
1562
  const varName = expr.object.value;
1440
- const styleObj = resolveCreateObject(varName);
1563
+ const styleObj = isVisibleReference(expr)
1564
+ ? resolveCreateObject(varName)
1565
+ : null;
1441
1566
  if (styleObj) {
1442
1567
  const dynExpr = expr.property.expression;
1443
1568
  const dynSource = getSource(dynExpr);
@@ -1766,6 +1891,8 @@ async function loader(source) {
1766
1891
  });
1767
1892
  },
1768
1893
  MemberExpression({ node }) {
1894
+ if (!isVisibleReference(node))
1895
+ return;
1769
1896
  if (utils_1.t.isIdentifier(node.object) &&
1770
1897
  (utils_1.t.isIdentifier(node.property) || node.property.type === 'Computed')) {
1771
1898
  const varName = node.object.value;
@@ -1957,45 +2084,54 @@ async function loader(source) {
1957
2084
  node.value &&
1958
2085
  node.value.type === 'JSXExpressionContainer') {
1959
2086
  const expr = node.value.expression;
1960
- const carrierFor = (subNode) => {
2087
+ const carrierFor = (subNode, calls) => {
1961
2088
  const vars = [];
1962
2089
  let unresolved = false;
1963
- (0, utils_1.traverse)(subNode, {
1964
- CallExpression({ node: call }) {
1965
- if (!isStyleFunctionCall(call))
1966
- return;
1967
- const resolved = resolveDynamicCall(call, true);
1968
- if (!resolved) {
1969
- unresolved = true;
1970
- return;
1971
- }
1972
- vars.push(...resolved.vars);
1973
- },
1974
- });
2090
+ for (const expression of calls ?? [subNode])
2091
+ (0, utils_1.traverse)(expression, {
2092
+ CallExpression({ node: call }) {
2093
+ if (!isStyleFunctionCall(call))
2094
+ return;
2095
+ const resolved = resolveDynamicCall(call, true);
2096
+ if (!resolved) {
2097
+ unresolved = true;
2098
+ return;
2099
+ }
2100
+ vars.push(...resolved.vars);
2101
+ },
2102
+ });
1975
2103
  if (unresolved)
1976
2104
  return null;
1977
2105
  return `{ ${foldDynamicVars(vars).join(', ')} }`;
1978
2106
  };
1979
2107
  const replaceWithKey = (subNode) => {
1980
- const entry = list.find((x) => x.spanStart === subNode.span.start &&
1981
- x.filePath === resourcePath);
1982
- if (entry) {
1983
- let content = JSON.stringify(entry.key);
2108
+ const entries = list.filter((entry) => entry.spanStart === subNode.span.start &&
2109
+ entry.filePath === resourcePath);
2110
+ if (!entries.length)
2111
+ return false;
2112
+ let content = '""';
2113
+ for (const entry of [...entries].reverse()) {
2114
+ let value = JSON.stringify(entry.key);
1984
2115
  if (entry.hasVars) {
1985
- const carrier = carrierFor(subNode);
2116
+ const carrier = carrierFor(subNode, entry.dynamicCalls);
1986
2117
  if (!carrier)
1987
2118
  return false;
1988
- content = `{ key: ${content}, vars: ${carrier} }`;
2119
+ value = `{ key: ${value}, vars: ${carrier} }`;
1989
2120
  }
1990
- replacements.push({
1991
- start: subNode.span.start - baseByteOffset,
1992
- end: subNode.span.end - baseByteOffset,
1993
- content,
1994
- });
2121
+ const condition = entry.conditions
2122
+ ?.map(({ test, truthy }) => `${truthy ? '' : '!'}(${getSource(test)})`)
2123
+ .join(' && ');
2124
+ content = condition
2125
+ ? `((${condition}) ? ${value} : ${content})`
2126
+ : value;
1995
2127
  processStyleRecords(entry.styleObj);
1996
- return true;
1997
2128
  }
1998
- return false;
2129
+ replacements.push({
2130
+ start: subNode.span.start - baseByteOffset,
2131
+ end: subNode.span.end - baseByteOffset,
2132
+ content,
2133
+ });
2134
+ return true;
1999
2135
  };
2000
2136
  (0, utils_1.traverse)(expr, {
2001
2137
  MemberExpression({ node: subNode }) {
@@ -2023,7 +2159,7 @@ async function loader(source) {
2023
2159
  const expr = node.value.expression;
2024
2160
  const args = expr.type === 'ArrayExpression'
2025
2161
  ? expr.elements
2026
- .filter((el) => el !== undefined)
2162
+ .filter((el) => el != null)
2027
2163
  .map((el) => ({ expression: el.expression }))
2028
2164
  : [{ expression: expr }];
2029
2165
  const dynamicClassParts = [];
@@ -2052,13 +2188,7 @@ async function loader(source) {
2052
2188
  existingClassExpr = JSON.stringify(classNameAttr.value.value);
2053
2189
  }
2054
2190
  else if (classNameAttr.value?.type === 'JSXExpressionContainer') {
2055
- const start = classNameAttr.value.expression.span.start -
2056
- baseByteOffset;
2057
- const end = classNameAttr.value.expression.span.end -
2058
- baseByteOffset;
2059
- existingClassExpr = `(${sourceBuffer
2060
- .subarray(start, end)
2061
- .toString('utf-8')})`;
2191
+ existingClassExpr = `(${deferSource(classNameAttr.value.expression)})`;
2062
2192
  }
2063
2193
  }
2064
2194
  const styleAttrExisting = attributes.find((attr) => attr.type === 'JSXAttribute' &&
@@ -2073,22 +2203,19 @@ async function loader(source) {
2073
2203
  });
2074
2204
  if (styleAttrExisting.value?.type === 'JSXExpressionContainer') {
2075
2205
  const innerExpr = styleAttrExisting.value?.expression;
2076
- const start = innerExpr.span.start - baseByteOffset;
2077
- const end = innerExpr.span.end - baseByteOffset;
2078
- const innerSource = sourceBuffer
2079
- .subarray(start, end)
2080
- .toString('utf-8');
2081
2206
  if (innerExpr.type === 'ObjectExpression') {
2082
- const stripped = innerSource.slice(1, -1).trim();
2083
- if (stripped)
2084
- existingStyleParts.push(stripped);
2207
+ if (innerExpr.properties.length > 0)
2208
+ existingStyleParts.push(deferSource(innerExpr, true));
2085
2209
  }
2086
2210
  else {
2087
- existingStyleExpr = `...(${innerSource})`;
2211
+ existingStyleExpr = `...(${deferSource(innerExpr)})`;
2088
2212
  }
2089
2213
  }
2090
2214
  }
2091
2215
  const { classParts, isOptimizable, baseStyle, dynamicVars, propVarSpreads, } = buildClassParts(args, dynamicClassParts, existingClassExpr, true);
2216
+ if (!isOptimizable) {
2217
+ throwCompilationError(`Plumeria: Dynamic or unresolvable style object "${getSource(expr)}" is not supported.`, expr);
2218
+ }
2092
2219
  const styleParts = [
2093
2220
  ...existingStyleParts,
2094
2221
  ...foldDynamicVars(dynamicVars),
@@ -2227,6 +2354,22 @@ async function loader(source) {
2227
2354
  `so it cannot be passed through another prop or read as a value.`, call);
2228
2355
  }
2229
2356
  });
2357
+ for (const deferred of deferredSources) {
2358
+ let cursor = deferred.start;
2359
+ const pieces = [];
2360
+ for (const replacement of [...replacements].sort((a, b) => a.start - b.start || b.end - a.end)) {
2361
+ if (replacement.start < cursor || replacement.end > deferred.end)
2362
+ continue;
2363
+ pieces.push(sourceBuffer.subarray(cursor, replacement.start).toString('utf-8'), replacement.content);
2364
+ cursor = replacement.end;
2365
+ }
2366
+ pieces.push(sourceBuffer.subarray(cursor, deferred.end).toString('utf-8'));
2367
+ let content = pieces.join('');
2368
+ if (deferred.stripObject)
2369
+ content = content.slice(1, -1).trim();
2370
+ for (const replacement of replacements)
2371
+ replacement.content = replacement.content.replaceAll(deferred.token, content);
2372
+ }
2230
2373
  const buffer = Buffer.from(source);
2231
2374
  let offset = 0;
2232
2375
  const parts = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/turbopack-loader",
3
- "version": "18.4.2",
3
+ "version": "18.5.0",
4
4
  "description": "Plumeria Turbopack-loader",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -29,8 +29,8 @@
29
29
  "zero-virtual.css"
30
30
  ],
31
31
  "dependencies": {
32
- "@plumeria/compiler": "^18.4.2",
33
- "@plumeria/utils": "^18.4.2"
32
+ "@plumeria/compiler": "^18.5.0",
33
+ "@plumeria/utils": "^18.5.0"
34
34
  },
35
35
  "devDependencies": {
36
36
  "@swc/core": "1.15.47",