@absolutejs/absolute 0.19.0-beta.97 → 0.19.0-beta.98

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 CHANGED
@@ -202325,17 +202325,6 @@ var init_pageHandler = __esm(() => {
202325
202325
  });
202326
202326
 
202327
202327
  // src/dev/transformCache.ts
202328
- var exports_transformCache = {};
202329
- __export(exports_transformCache, {
202330
- setTransformed: () => setTransformed,
202331
- markAsDataFile: () => markAsDataFile,
202332
- isDataFile: () => isDataFile,
202333
- invalidateAll: () => invalidateAll,
202334
- invalidate: () => invalidate,
202335
- getTransformed: () => getTransformed,
202336
- getInvalidationVersion: () => getInvalidationVersion,
202337
- findNearestComponent: () => findNearestComponent
202338
- });
202339
202328
  var globalStore, cache, importers, getTransformed = (filePath) => cache.get(filePath)?.content, setTransformed = (filePath, content, mtime, imports) => {
202340
202329
  const resolvedImports = imports ?? [];
202341
202330
  cache.set(filePath, { content, imports: resolvedImports, mtime });
@@ -202354,31 +202343,9 @@ var globalStore, cache, importers, getTransformed = (filePath) => cache.get(file
202354
202343
  cache.delete(parent);
202355
202344
  }
202356
202345
  }
202357
- }, invalidateAll = () => {
202358
- cache.clear();
202359
- importers.clear();
202360
202346
  }, dataFiles, markAsDataFile = (filePath) => {
202361
202347
  dataFiles.add(filePath);
202362
- }, isDataFile = (filePath) => dataFiles.has(filePath), findNearestComponent = (filePath) => {
202363
- const visited = new Set;
202364
- const queue = [filePath];
202365
- while (queue.length > 0) {
202366
- const current = queue.shift();
202367
- if (visited.has(current))
202368
- continue;
202369
- visited.add(current);
202370
- const parents = importers.get(current);
202371
- if (!parents)
202372
- continue;
202373
- for (const parent of parents) {
202374
- if (parent.endsWith(".tsx") || parent.endsWith(".jsx")) {
202375
- return parent;
202376
- }
202377
- queue.push(parent);
202378
- }
202379
- }
202380
- return;
202381
- };
202348
+ }, isDataFile = (filePath) => dataFiles.has(filePath);
202382
202349
  var init_transformCache = __esm(() => {
202383
202350
  globalStore = globalThis;
202384
202351
  cache = globalStore.__transformCache ?? new Map;
@@ -202533,19 +202500,54 @@ ${stubs}
202533
202500
  });
202534
202501
  return result;
202535
202502
  }, NAMED_IMPORT_RE, rewriteDataImports = (code, projectRoot) => {
202503
+ const rewrites = [];
202536
202504
  let counter = 0;
202537
- return code.replace(NAMED_IMPORT_RE, (_match, names, q1, srcUrl2, q2) => {
202538
- const urlPath = srcUrl2.replace(/^\/\@src\//, "").split("?")[0];
202539
- if (!urlPath)
202540
- return _match;
202505
+ let m;
202506
+ NAMED_IMPORT_RE.lastIndex = 0;
202507
+ while ((m = NAMED_IMPORT_RE.exec(code)) !== null) {
202508
+ const [fullMatch, names, q1, srcUrl2, q2] = m;
202509
+ if (!names || !srcUrl2)
202510
+ continue;
202511
+ const urlPath = srcUrl2.replace(/^\/@src\//, "").split("?")[0];
202512
+ if (!urlPath || !urlPath.endsWith(".ts") || urlPath.endsWith(".d.ts"))
202513
+ continue;
202541
202514
  const absPath = resolve18(projectRoot, urlPath);
202542
- if (!isDataFile(absPath))
202543
- return _match;
202515
+ if (!isDataFile(absPath)) {
202516
+ if (!urlPath.endsWith(".tsx") && existsSync13(absPath)) {
202517
+ try {
202518
+ const src = readFileSync9(absPath, "utf-8");
202519
+ const exps = tsTranspiler2.scan(src).exports;
202520
+ if (isDataOnlyFile(exps, src, absPath))
202521
+ markAsDataFile(absPath);
202522
+ } catch {}
202523
+ }
202524
+ if (!isDataFile(absPath))
202525
+ continue;
202526
+ }
202544
202527
  const alias = `__hmr_${counter++}`;
202545
- const trimmedNames = names.trim();
202546
- return `import ${alias} from ${q1}${srcUrl2}${q2};
202547
- const { ${trimmedNames} } = ${alias}`;
202548
- });
202528
+ const importedNames = names.split(",").map((n) => n.trim().split(/\s+as\s+/)).filter(([n]) => n).map(([orig, asName]) => ({
202529
+ local: (asName ?? orig).trim(),
202530
+ orig: orig.trim()
202531
+ }));
202532
+ rewrites.push({
202533
+ alias,
202534
+ fullMatch,
202535
+ importLine: `import ${alias} from ${q1}${srcUrl2}${q2}`,
202536
+ names: importedNames
202537
+ });
202538
+ }
202539
+ if (rewrites.length === 0)
202540
+ return code;
202541
+ let result = code;
202542
+ for (const r of rewrites) {
202543
+ result = result.replace(r.fullMatch, r.importLine);
202544
+ }
202545
+ for (const r of rewrites) {
202546
+ for (const { orig, local } of r.names) {
202547
+ result = result.replace(new RegExp(`(?<![.\\w])${local}(?![\\w])`, "g"), `${r.alias}.${orig}`);
202548
+ }
202549
+ }
202550
+ return result;
202549
202551
  }, HOOK_NAMES, REFRESH_PREAMBLE, JSX_AUTO_RE, JSXS_AUTO_RE, JSX_PROD_RE, FRAGMENT_RE, addJsxImport = (code) => {
202550
202552
  const imports = [];
202551
202553
  const jsxDevMatch = JSX_AUTO_RE.exec(code);
@@ -202586,31 +202588,33 @@ const { ${trimmedNames} } = ${alias}`;
202586
202588
  let result = rewriteImports2(transpiled, filePath, projectRoot, rewriter);
202587
202589
  result = rewriteDataImports(result, projectRoot);
202588
202590
  return result;
202589
- }, isDataOnlyFile = (exports, transpiled) => {
202591
+ }, isDataOnlyFile = (exports, _source, filePath) => {
202590
202592
  if (exports.length === 0)
202591
202593
  return false;
202592
- if (exports.some((e) => /^[A-Z]/.test(e) && /^(use|[A-Z])/.test(e)))
202593
- return false;
202594
- if (/export\s+(function|class|async\s+function)\s/.test(transpiled))
202594
+ if (filePath) {
202595
+ const normalized = filePath.replace(/\\/g, "/");
202596
+ if (!normalized.includes("/data/"))
202597
+ return false;
202598
+ }
202599
+ if (exports.some((e) => /^[A-Z]/.test(e) || /^use[A-Z]/.test(e)))
202595
202600
  return false;
202596
202601
  return true;
202597
202602
  }, wrapDataExports = (transpiled, filePath, exports) => {
202598
202603
  const storeKey = filePath.replace(/\\/g, "/");
202599
202604
  let result = transpiled;
202600
- const preamble = `const __hmr = ((globalThis.__HMR_DATA__ ??= {})[${JSON.stringify(storeKey)}] ??= {});
202601
- `;
202602
202605
  for (const name of exports) {
202603
- result = result.replace(new RegExp(`export\\s+const\\s+${name}\\s*=`), `__hmr.${name} =`);
202604
- result = result.replace(new RegExp(`export\\s+var\\s+${name}\\s*=`), `__hmr.${name} =`);
202605
- result = result.replace(new RegExp(`export\\s+let\\s+${name}\\s*=`), `__hmr.${name} =`);
202606
+ result = result.replace(new RegExp(`export\\s+(const|let|var)\\s+${name}\\s*=`), `$1 ${name} =`);
202606
202607
  }
202607
- const defaultExport = `
202608
- export default __hmr;
202608
+ const preamble = `const __hmr = ((globalThis.__HMR_DATA__ ??= {})[${JSON.stringify(storeKey)}] ??= {});
202609
202609
  `;
202610
- const namedExports = exports.map((name) => `export const ${name} = __hmr.${name};`).join(`
202610
+ const storeWrites = exports.map((name) => `__hmr.${name} = ${name};`).join(`
202611
202611
  `);
202612
+ const namedExport = exports.length > 0 ? `export { ${exports.join(", ")} };
202613
+ ` : "";
202612
202614
  return preamble + result + `
202613
- ` + namedExports + defaultExport;
202615
+ ` + storeWrites + `
202616
+ ` + namedExport + `export default __hmr;
202617
+ `;
202614
202618
  }, transformPlainFile = (filePath, projectRoot, rewriter) => {
202615
202619
  const raw = readFileSync9(filePath, "utf-8");
202616
202620
  const ext = extname3(filePath);
@@ -202622,7 +202626,7 @@ export default __hmr;
202622
202626
  if (isTS) {
202623
202627
  transpiled = preserveTypeExports(raw, transpiled, valueExports);
202624
202628
  }
202625
- if (isTS && !isTSX && isDataOnlyFile(valueExports, transpiled)) {
202629
+ if (isTS && !isTSX && isDataOnlyFile(valueExports, transpiled, filePath)) {
202626
202630
  transpiled = wrapDataExports(transpiled, filePath, valueExports);
202627
202631
  markAsDataFile(filePath);
202628
202632
  }
@@ -203569,15 +203573,7 @@ var moduleServerPromise, getModuleServer = () => moduleServerPromise, parseError
203569
203573
  for (const file4 of reactFiles) {
203570
203574
  invalidateModule2(file4);
203571
203575
  }
203572
- const isComponentFile = primaryFile.endsWith(".tsx") || primaryFile.endsWith(".jsx");
203573
- let broadcastTarget = primaryFile;
203574
- if (!isComponentFile) {
203575
- const { findNearestComponent: findNearestComponent2 } = await Promise.resolve().then(() => (init_transformCache(), exports_transformCache));
203576
- const nearest = findNearestComponent2(resolve21(primaryFile));
203577
- if (nearest)
203578
- broadcastTarget = nearest;
203579
- }
203580
- const pageModuleUrl = await getReactModuleUrl(broadcastTarget);
203576
+ const pageModuleUrl = await getReactModuleUrl(primaryFile);
203581
203577
  if (pageModuleUrl) {
203582
203578
  const serverDuration = Date.now() - startTime;
203583
203579
  state.lastHmrPath = relative8(process.cwd(), primaryFile).replace(/\\/g, "/");
@@ -205365,5 +205361,5 @@ export {
205365
205361
  ANGULAR_INIT_TIMEOUT_MS
205366
205362
  };
205367
205363
 
205368
- //# debugId=961251AD68B6490564756E2164756E21
205364
+ //# debugId=78D70B808786BC8A64756E2164756E21
205369
205365
  //# sourceMappingURL=index.js.map