@absolutejs/absolute 0.19.0-beta.854 → 0.19.0-beta.856

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
@@ -18287,40 +18287,38 @@ __export(exports_fastHmrCompiler, {
18287
18287
  recordFingerprint: () => recordFingerprint,
18288
18288
  invalidateFingerprintCache: () => invalidateFingerprintCache
18289
18289
  });
18290
- import { existsSync as existsSync26, readFileSync as readFileSync20 } from "fs";
18290
+ import { existsSync as existsSync26, readFileSync as readFileSync20, statSync as statSync4 } from "fs";
18291
18291
  import { dirname as dirname19, relative as relative13, resolve as resolve33 } from "path";
18292
18292
  import ts7 from "typescript";
18293
- var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache, fingerprintsEqual = (a, b2) => {
18293
+ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache, arraysEqual = (a, b2) => {
18294
+ if (a.length !== b2.length)
18295
+ return false;
18296
+ for (let i = 0;i < a.length; i++) {
18297
+ if (a[i] !== b2[i])
18298
+ return false;
18299
+ }
18300
+ return true;
18301
+ }, fingerprintsEqual = (a, b2) => {
18294
18302
  if (a.className !== b2.className)
18295
18303
  return false;
18296
18304
  if (a.selector !== b2.selector)
18297
18305
  return false;
18298
18306
  if (a.standalone !== b2.standalone)
18299
18307
  return false;
18300
- if (a.importsArity !== b2.importsArity)
18301
- return false;
18302
18308
  if (a.hasProviders !== b2.hasProviders)
18303
18309
  return false;
18304
18310
  if (a.hasViewProviders !== b2.hasViewProviders)
18305
18311
  return false;
18306
- if (a.ctorParamTypes.length !== b2.ctorParamTypes.length)
18312
+ if (!arraysEqual(a.ctorParamTypes, b2.ctorParamTypes))
18307
18313
  return false;
18308
- for (let i = 0;i < a.ctorParamTypes.length; i++) {
18309
- if (a.ctorParamTypes[i] !== b2.ctorParamTypes[i])
18310
- return false;
18311
- }
18312
- if (a.inputs.length !== b2.inputs.length)
18314
+ if (!arraysEqual(a.inputs, b2.inputs))
18313
18315
  return false;
18314
- for (let i = 0;i < a.inputs.length; i++) {
18315
- if (a.inputs[i] !== b2.inputs[i])
18316
- return false;
18317
- }
18318
- if (a.outputs.length !== b2.outputs.length)
18316
+ if (!arraysEqual(a.outputs, b2.outputs))
18317
+ return false;
18318
+ if (!arraysEqual(a.providerImportSig, b2.providerImportSig))
18319
+ return false;
18320
+ if (!arraysEqual(a.arrowFieldSig, b2.arrowFieldSig))
18319
18321
  return false;
18320
- for (let i = 0;i < a.outputs.length; i++) {
18321
- if (a.outputs[i] !== b2.outputs[i])
18322
- return false;
18323
- }
18324
18322
  return true;
18325
18323
  }, recordFingerprint = (id, fp) => {
18326
18324
  fingerprintCache.set(id, fp);
@@ -18568,7 +18566,137 @@ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache
18568
18566
  }
18569
18567
  }
18570
18568
  return { inputs, outputs };
18571
- }, extractFingerprint = (cls, className, decoratorMeta, inputs, outputs) => {
18569
+ }, djb2Hash = (s2) => {
18570
+ let h2 = 5381;
18571
+ for (let i = 0;i < s2.length; i++) {
18572
+ h2 = h2 * 33 ^ s2.charCodeAt(i);
18573
+ }
18574
+ return (h2 >>> 0).toString(36);
18575
+ }, extractArrowFieldSig = (cls) => {
18576
+ const entries = [];
18577
+ for (const member of cls.members) {
18578
+ if (!ts7.isPropertyDeclaration(member))
18579
+ continue;
18580
+ const init = member.initializer;
18581
+ if (!init)
18582
+ continue;
18583
+ if (!ts7.isArrowFunction(init) && !ts7.isFunctionExpression(init)) {
18584
+ continue;
18585
+ }
18586
+ const name = member.name.getText();
18587
+ const bodyHash = djb2Hash(init.getText());
18588
+ entries.push(`${name}:${bodyHash}`);
18589
+ }
18590
+ return entries.sort();
18591
+ }, providerProbeCache, fileHasModuleProviders = (filePath) => {
18592
+ let stat3;
18593
+ try {
18594
+ stat3 = statSync4(filePath);
18595
+ } catch {
18596
+ return true;
18597
+ }
18598
+ const cached = providerProbeCache.get(filePath);
18599
+ if (cached && cached.mtimeMs === stat3.mtimeMs)
18600
+ return cached.hasProviders;
18601
+ let source;
18602
+ try {
18603
+ source = readFileSync20(filePath, "utf8");
18604
+ } catch {
18605
+ return true;
18606
+ }
18607
+ const sf = ts7.createSourceFile(filePath, source, ts7.ScriptTarget.ES2022, true, ts7.ScriptKind.TS);
18608
+ let hasProviders = false;
18609
+ const visit = (node) => {
18610
+ if (hasProviders)
18611
+ return;
18612
+ if (ts7.isClassDeclaration(node)) {
18613
+ for (const decorator of ts7.getDecorators(node) ?? []) {
18614
+ const expr = decorator.expression;
18615
+ if (!ts7.isCallExpression(expr))
18616
+ continue;
18617
+ const arg = expr.arguments[0];
18618
+ if (!arg || !ts7.isObjectLiteralExpression(arg))
18619
+ continue;
18620
+ if (getProperty(arg, "providers") !== null) {
18621
+ hasProviders = true;
18622
+ return;
18623
+ }
18624
+ }
18625
+ }
18626
+ ts7.forEachChild(node, visit);
18627
+ };
18628
+ visit(sf);
18629
+ providerProbeCache.set(filePath, {
18630
+ hasProviders,
18631
+ mtimeMs: stat3.mtimeMs
18632
+ });
18633
+ return hasProviders;
18634
+ }, TS_EXTENSIONS, resolveImportSource = (identifierName, sourceFile, componentDir) => {
18635
+ for (const stmt of sourceFile.statements) {
18636
+ if (!ts7.isImportDeclaration(stmt))
18637
+ continue;
18638
+ const moduleSpec = stmt.moduleSpecifier;
18639
+ if (!ts7.isStringLiteral(moduleSpec))
18640
+ continue;
18641
+ const spec = moduleSpec.text;
18642
+ if (!spec.startsWith(".") && !spec.startsWith("/"))
18643
+ continue;
18644
+ const importClause = stmt.importClause;
18645
+ if (!importClause)
18646
+ continue;
18647
+ let matches = false;
18648
+ if (importClause.name && importClause.name.text === identifierName) {
18649
+ matches = true;
18650
+ }
18651
+ if (importClause.namedBindings) {
18652
+ const nb = importClause.namedBindings;
18653
+ if (ts7.isNamespaceImport(nb)) {
18654
+ if (nb.name.text === identifierName)
18655
+ matches = true;
18656
+ } else {
18657
+ for (const element of nb.elements) {
18658
+ if (element.name.text === identifierName) {
18659
+ matches = true;
18660
+ break;
18661
+ }
18662
+ }
18663
+ }
18664
+ }
18665
+ if (!matches)
18666
+ continue;
18667
+ const resolved = resolve33(componentDir, spec);
18668
+ for (const ext of TS_EXTENSIONS) {
18669
+ const candidate = resolved + ext;
18670
+ if (existsSync26(candidate))
18671
+ return candidate;
18672
+ }
18673
+ const indexCandidate = resolve33(resolved, "index.ts");
18674
+ if (existsSync26(indexCandidate))
18675
+ return indexCandidate;
18676
+ }
18677
+ return null;
18678
+ }, extractProviderImportSig = (importsExpr, sourceFile, componentDir) => {
18679
+ if (!importsExpr)
18680
+ return [];
18681
+ const sig = [];
18682
+ for (const entry of importsExpr.elements) {
18683
+ if (ts7.isIdentifier(entry)) {
18684
+ const importPath = resolveImportSource(entry.text, sourceFile, componentDir);
18685
+ if (importPath) {
18686
+ if (fileHasModuleProviders(importPath)) {
18687
+ sig.push(`P:${entry.text}`);
18688
+ }
18689
+ continue;
18690
+ }
18691
+ if (/Module$/.test(entry.text)) {
18692
+ sig.push(`P:${entry.text}`);
18693
+ }
18694
+ } else {
18695
+ sig.push(`P:${entry.getText()}`);
18696
+ }
18697
+ }
18698
+ return sig.sort();
18699
+ }, extractFingerprint = (cls, className, decoratorMeta, inputs, outputs, sourceFile, componentDir) => {
18572
18700
  const ctorParamTypes = [];
18573
18701
  for (const member of cls.members) {
18574
18702
  if (!ts7.isConstructorDeclaration(member))
@@ -18580,20 +18708,61 @@ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache
18580
18708
  }
18581
18709
  const inputNames = Object.keys(inputs).sort();
18582
18710
  const outputNames = Object.keys(outputs).sort();
18583
- const importsArity = decoratorMeta.importsExpr ? decoratorMeta.importsExpr.elements.length : 0;
18584
- const hasProviders = decoratorMeta.hasProviders;
18585
- const hasViewProviders = decoratorMeta.hasViewProviders;
18711
+ const arrowFieldSig = extractArrowFieldSig(cls);
18712
+ const providerImportSig = extractProviderImportSig(decoratorMeta.importsExpr, sourceFile, componentDir);
18586
18713
  return {
18714
+ arrowFieldSig,
18587
18715
  className,
18588
18716
  ctorParamTypes,
18589
- hasProviders,
18590
- hasViewProviders,
18591
- importsArity,
18717
+ hasProviders: decoratorMeta.hasProviders,
18718
+ hasViewProviders: decoratorMeta.hasViewProviders,
18592
18719
  inputs: inputNames,
18593
18720
  outputs: outputNames,
18721
+ providerImportSig,
18594
18722
  selector: decoratorMeta.selector,
18595
18723
  standalone: decoratorMeta.standalone
18596
18724
  };
18725
+ }, buildFreshClassMethodsBlock = (classNode, className) => {
18726
+ const methodSources = [];
18727
+ for (const member of classNode.members) {
18728
+ if (ts7.isMethodDeclaration(member) || ts7.isGetAccessorDeclaration(member) || ts7.isSetAccessorDeclaration(member)) {
18729
+ const modifiers = ts7.getModifiers(member) ?? [];
18730
+ const isStatic = modifiers.some((m) => m.kind === ts7.SyntaxKind.StaticKeyword);
18731
+ if (isStatic)
18732
+ continue;
18733
+ methodSources.push(member.getText());
18734
+ }
18735
+ }
18736
+ if (methodSources.length === 0)
18737
+ return null;
18738
+ const wrappedSource = `class _Fresh {
18739
+ ${methodSources.join(`
18740
+ `)}
18741
+ }`;
18742
+ let transpiled;
18743
+ try {
18744
+ transpiled = ts7.transpileModule(wrappedSource, {
18745
+ compilerOptions: {
18746
+ module: ts7.ModuleKind.ES2022,
18747
+ target: ts7.ScriptTarget.ES2022
18748
+ },
18749
+ reportDiagnostics: false
18750
+ }).outputText;
18751
+ } catch {
18752
+ return null;
18753
+ }
18754
+ return `// SURGICAL_HMR \u2014 patch prototype methods so existing instances
18755
+ // pick up new method bodies (\`compileComponentFromMetadata\` only
18756
+ // updates \`\u0275cmp\`, never the prototype).
18757
+ ${transpiled}
18758
+ {
18759
+ const __fresh_proto = _Fresh.prototype;
18760
+ for (const __name of Object.getOwnPropertyNames(__fresh_proto)) {
18761
+ if (__name === 'constructor') continue;
18762
+ const __desc = Object.getOwnPropertyDescriptor(__fresh_proto, __name);
18763
+ if (__desc) Object.defineProperty(${className}.prototype, __name, __desc);
18764
+ }
18765
+ }`;
18597
18766
  }, resolveAndReadResource = (componentDir, url) => {
18598
18767
  const abs = resolve33(componentDir, url);
18599
18768
  if (!existsSync26(abs))
@@ -18681,7 +18850,7 @@ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache
18681
18850
  const { inputs, outputs } = extractInputsAndOutputs(classNode);
18682
18851
  const projectRelPath = relative13(projectRoot, componentFilePath).replace(/\\/g, "/");
18683
18852
  const fingerprintId = encodeURIComponent(`${projectRelPath}@${className}`);
18684
- const currentFingerprint = extractFingerprint(classNode, className, decoratorMeta, inputs, outputs);
18853
+ const currentFingerprint = extractFingerprint(classNode, className, decoratorMeta, inputs, outputs, sourceFile, componentDir);
18685
18854
  const cachedFingerprint = fingerprintCache.get(fingerprintId);
18686
18855
  if (cachedFingerprint && !fingerprintsEqual(cachedFingerprint, currentFingerprint)) {
18687
18856
  return fail("structural-change", `fingerprint changed for ${className}; escalate to Tier 1`);
@@ -18783,7 +18952,7 @@ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache
18783
18952
  removeComments: false
18784
18953
  });
18785
18954
  const tsSourceText = printer.printNode(ts7.EmitHint.Unspecified, exportedDecl, sourceFile);
18786
- const moduleText = ts7.transpileModule(tsSourceText, {
18955
+ const transpiled = ts7.transpileModule(tsSourceText, {
18787
18956
  compilerOptions: {
18788
18957
  module: ts7.ModuleKind.ES2022,
18789
18958
  target: ts7.ScriptTarget.ES2022
@@ -18791,6 +18960,18 @@ var fail = (reason, detail) => ({ ok: false, reason, detail }), fingerprintCache
18791
18960
  fileName: componentFilePath,
18792
18961
  reportDiagnostics: false
18793
18962
  }).outputText;
18963
+ const methodsBlock = buildFreshClassMethodsBlock(classNode, className);
18964
+ let moduleText = transpiled;
18965
+ if (methodsBlock) {
18966
+ const fnOpening = `function ${className}_UpdateMetadata(${className}, \u0275\u0275namespaces) {`;
18967
+ const idx = moduleText.indexOf(fnOpening);
18968
+ if (idx >= 0) {
18969
+ const insertAt = idx + fnOpening.length;
18970
+ moduleText = moduleText.slice(0, insertAt) + `
18971
+ ` + methodsBlock + `
18972
+ ` + moduleText.slice(insertAt);
18973
+ }
18974
+ }
18794
18975
  fingerprintCache.set(fingerprintId, currentFingerprint);
18795
18976
  return { ok: true, moduleText, componentSource: sourceFile };
18796
18977
  } catch (err) {
@@ -18801,6 +18982,8 @@ var init_fastHmrCompiler = __esm(() => {
18801
18982
  init_hmrImportGenerator();
18802
18983
  init_typescript_translator();
18803
18984
  fingerprintCache = new Map;
18985
+ providerProbeCache = new Map;
18986
+ TS_EXTENSIONS = [".ts", ".tsx", ".d.ts"];
18804
18987
  });
18805
18988
 
18806
18989
  // src/dev/angular/hmrCompiler.ts
@@ -21025,7 +21208,7 @@ __export(exports_devBuild, {
21025
21208
  devBuild: () => devBuild
21026
21209
  });
21027
21210
  import { readdir as readdir5 } from "fs/promises";
21028
- import { statSync as statSync4 } from "fs";
21211
+ import { statSync as statSync5 } from "fs";
21029
21212
  import { resolve as resolve38 } from "path";
21030
21213
  var FRAMEWORK_DIR_KEYS, collectDepVendorSourceDirs = (config) => {
21031
21214
  const configuredDirs = [
@@ -21134,7 +21317,7 @@ var FRAMEWORK_DIR_KEYS, collectDepVendorSourceDirs = (config) => {
21134
21317
  state.fileChangeQueue.clear();
21135
21318
  }
21136
21319
  }, handleCachedReload = async () => {
21137
- const serverMtime = statSync4(resolve38(Bun.main)).mtimeMs;
21320
+ const serverMtime = statSync5(resolve38(Bun.main)).mtimeMs;
21138
21321
  const lastMtime = globalThis.__hmrServerMtime;
21139
21322
  globalThis.__hmrServerMtime = serverMtime;
21140
21323
  const cached = globalThis.__hmrDevResult;
@@ -21348,7 +21531,7 @@ var FRAMEWORK_DIR_KEYS, collectDepVendorSourceDirs = (config) => {
21348
21531
  manifest
21349
21532
  };
21350
21533
  globalThis.__hmrDevResult = result;
21351
- globalThis.__hmrServerMtime = statSync4(resolve38(Bun.main)).mtimeMs;
21534
+ globalThis.__hmrServerMtime = statSync5(resolve38(Bun.main)).mtimeMs;
21352
21535
  return result;
21353
21536
  };
21354
21537
  var init_devBuild = __esm(() => {
@@ -29950,5 +30133,5 @@ export {
29950
30133
  ANGULAR_INIT_TIMEOUT_MS
29951
30134
  };
29952
30135
 
29953
- //# debugId=1AAD42B006C96FC764756E2164756E21
30136
+ //# debugId=2BA92AA7B0159DCB64756E2164756E21
29954
30137
  //# sourceMappingURL=index.js.map