@absolutejs/absolute 0.19.0-beta.915 → 0.19.0-beta.916
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/angular/components/core/streamingSlotRegistrar.js +1 -1
- package/dist/angular/components/core/streamingSlotRegistry.js +2 -2
- package/dist/angular/index.js.map +1 -1
- package/dist/angular/server.js.map +1 -1
- package/dist/build.js +58 -5
- package/dist/build.js.map +5 -5
- package/dist/client/index.js.map +1 -1
- package/dist/index.js +58 -5
- package/dist/index.js.map +6 -6
- package/dist/islands/index.js.map +1 -1
- package/dist/react/index.js.map +1 -1
- package/dist/src/dev/angular/fastHmrCompiler.d.ts +1 -0
- package/dist/svelte/index.js.map +1 -1
- package/dist/vue/index.js.map +1 -1
- package/package.json +1 -1
package/dist/client/index.js.map
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"import { existsSync, readFileSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\n\n/**\n * Resolve Angular package paths from the compiled runtime node_modules first,\n * then the app's process.cwd()/node_modules, falling back to the bare specifier.\n * This prevents Bun's baked import.meta.dir from resolving Angular packages\n * from the absolutejs source tree instead of the consumer's project when\n * running from a published npm package.\n */\nexport const resolveAngularPackageDir = (specifier: string) => {\n\tconst fromCompiledRuntime = process.env.ABSOLUTE_BUILD_DIR\n\t\t? resolve(process.env.ABSOLUTE_BUILD_DIR, 'node_modules', specifier)\n\t\t: null;\n\tif (fromCompiledRuntime && existsSync(fromCompiledRuntime)) {\n\t\treturn fromCompiledRuntime;\n\t}\n\n\tconst fromProject = resolve(process.cwd(), 'node_modules', specifier);\n\n\tif (existsSync(fromProject)) {\n\t\treturn fromProject;\n\t}\n\n\treturn null;\n};\n\nconst resolvePackageEntry = (packageDir: string) => {\n\ttry {\n\t\tconst pkg = JSON.parse(\n\t\t\treadFileSync(join(packageDir, 'package.json'), 'utf-8')\n\t\t);\n\t\tconst rootExport = pkg.exports?.['.'];\n\t\tconst entry =\n\t\t\t(typeof rootExport === 'string'\n\t\t\t\t? rootExport\n\t\t\t\t: rootExport?.default) ??\n\t\t\tpkg.module ??\n\t\t\tpkg.main ??\n\t\t\t'index.js';\n\n\t\treturn join(packageDir, entry);\n\t} catch {\n\t\treturn packageDir;\n\t}\n};\n\nexport const resolveAngularPackage = (specifier: string) => {\n\tconst packageDir = resolveAngularPackageDir(specifier);\n\tif (packageDir) return resolvePackageEntry(packageDir);\n\n\treturn specifier;\n};\n\nconst toSafeVendorName = (specifier: string) =>\n\tspecifier.replace(/^@/, '').replace(/\\//g, '_');\n\n/** Prefer the linked Bun-target vendor file built by\n * `buildAngularServerVendor`. The file is at\n * `<ABSOLUTE_BUILD_DIR>/angular/vendor/server/<safe>.js`, which is what every\n * server bundle's `@angular/*` imports get rewritten to point at. Sharing\n * this path keeps SSR's class identity unified — the dual-package hazard\n * that produces NG0201 only appears when the runtime imports a *different*\n * copy from the bundles. Falls back to `resolveAngularPackage` (node_modules)\n * when no vendor file is available — e.g. running tests outside an\n * absolutejs build, or before the vendor pass completes. */\nexport const resolveAngularRuntimePath = (specifier: string) => {\n\tconst buildDirs = [\n\t\tprocess.env.ABSOLUTE_BUILD_DIR,\n\t\tresolve(process.cwd(), 'build')\n\t].filter((value): value is string => Boolean(value));\n\n\tfor (const buildDir of buildDirs) {\n\t\tconst vendorPath = join(\n\t\t\tbuildDir,\n\t\t\t'angular',\n\t\t\t'vendor',\n\t\t\t'server',\n\t\t\t`${toSafeVendorName(specifier)}.js`\n\t\t);\n\t\tif (existsSync(vendorPath)) return vendorPath;\n\t}\n\n\treturn resolveAngularPackage(specifier);\n};\n",
|
|
13
13
|
"/* Bundler-safe NODE_ENV reader.\n *\n * Bun (like esbuild and most modern bundlers) statically replaces\n * `process.env.NODE_ENV` with the build-time string. When absolutejs\n * itself is bundled (`bun run scripts/build.ts`), NODE_ENV is unset,\n * so every `process.env.NODE_ENV === 'production'` site collapses to\n * `false` and the production branch is dead-code-eliminated from\n * `dist/`. That breaks `bun start`, `bun compile`, and the standalone\n * compiled binary — they all run with NODE_ENV=production but see the\n * dev branches baked in.\n *\n * Computed-property access (`process.env[KEY]`) is NOT constant-folded\n * by Bun, so we read NODE_ENV through a string variable. Both branches\n * stay live in `dist/`, and the consumer's actual runtime NODE_ENV\n * decides which one fires.\n *\n * Verified empirically: Bun's bundler matches the literal AST shape\n * `MemberExpression { object: process.env, property: NODE_ENV }` for\n * its replacement. Computed-key access uses\n * `MemberExpression { computed: true, property: Identifier(KEY) }`,\n * which doesn't match the pattern. */\n\nconst ENV_VAR = 'NODE_ENV';\n\nexport const getNodeEnv = () => process.env[ENV_VAR];\n\nexport const isProductionRuntime = () => process.env[ENV_VAR] === 'production';\n\nexport const isDevelopmentRuntime = () =>\n\tprocess.env[ENV_VAR] === 'development';\n",
|
|
14
14
|
"import { resolveAngularRuntimePath } from './resolveAngularPackage';\nimport { isProductionRuntime } from '../utils/runtimeMode';\n\n// Patches Angular SSR's DominoAdapter to guard against null doc.head\n\nconst ensureHead = (doc: Document) => {\n\tif (!doc || doc.head || !doc.documentElement) {\n\t\treturn;\n\t}\n\n\tconst head = doc.createElement('head');\n\tdoc.documentElement.insertBefore(head, doc.documentElement.firstChild);\n};\n\n// Domino's Element does not implement layout APIs that browser components\n// (e.g. ngx-datatable, swiper, drag-drop) call eagerly during change detection.\n// Returning a zeroed DOMRect lets those components render in SSR without\n// crashing — the real values get computed once the page hydrates client-side.\nconst SSR_LAYOUT_RECT = Object.freeze({\n\tbottom: 0,\n\theight: 0,\n\tleft: 0,\n\tright: 0,\n\ttop: 0,\n\twidth: 0,\n\tx: 0,\n\ty: 0,\n\ttoJSON() {\n\t\treturn this;\n\t}\n});\nlet layoutPatchApplied = false;\nconst collectPrototypeChain = (instance: object | null) => {\n\tconst protos: object[] = [];\n\tlet current: object | null = instance\n\t\t? Object.getPrototypeOf(instance)\n\t\t: null;\n\twhile (current && current !== Object.prototype) {\n\t\tprotos.push(current);\n\t\tcurrent = Object.getPrototypeOf(current);\n\t}\n\n\treturn protos;\n};\n\nconst patchElementLayout = (doc: Document) => {\n\tif (layoutPatchApplied || !doc) {\n\t\treturn;\n\t}\n\tlet element: Element;\n\ttry {\n\t\telement = doc.createElement('div');\n\t} catch {\n\t\treturn;\n\t}\n\t// Walk the entire prototype chain so HTMLElement → Element → Node all get\n\t// the layout shims. Domino's base Element.prototype is several hops above\n\t// HTMLDivElement.prototype, and 3rd-party libs call methods anywhere along\n\t// the chain.\n\tconst protos = collectPrototypeChain(element);\n\tif (protos.length === 0) return;\n\n\tconst copyLayoutRect = (rect: typeof SSR_LAYOUT_RECT) => ({ ...rect });\n\tconst createLayoutRect = () => copyLayoutRect(SSR_LAYOUT_RECT);\n\tconst getClientRects = () => [];\n\tconst noop = () => undefined;\n\tconst numericProps = [\n\t\t'clientWidth',\n\t\t'clientHeight',\n\t\t'clientLeft',\n\t\t'clientTop',\n\t\t'offsetWidth',\n\t\t'offsetHeight',\n\t\t'offsetLeft',\n\t\t'offsetTop',\n\t\t'scrollWidth',\n\t\t'scrollHeight',\n\t\t'scrollLeft',\n\t\t'scrollTop'\n\t];\n\n\tfor (const proto of protos) {\n\t\tconst define = (name: string, value: unknown) => {\n\t\t\tconst descriptor = Object.getOwnPropertyDescriptor(proto, name);\n\t\t\tif (typeof descriptor?.value === 'function') return;\n\n\t\t\tObject.defineProperty(proto, name, {\n\t\t\t\tconfigurable: true,\n\t\t\t\tvalue,\n\t\t\t\twritable: true\n\t\t\t});\n\t\t};\n\n\t\tdefine('getBoundingClientRect', createLayoutRect);\n\t\tdefine('getClientRects', getClientRects);\n\t\tdefine('scrollTo', noop);\n\t\tdefine('scrollBy', noop);\n\t\tdefine('scrollIntoView', noop);\n\t\tdefine('focus', noop);\n\t\tdefine('blur', noop);\n\n\t\tfor (const prop of numericProps) {\n\t\t\tconst desc = Object.getOwnPropertyDescriptor(proto, prop);\n\t\t\tif (desc) continue;\n\t\t\tObject.defineProperty(proto, prop, {\n\t\t\t\tconfigurable: true,\n\t\t\t\tget: () => 0\n\t\t\t});\n\t\t}\n\t}\n\n\tlayoutPatchApplied = true;\n};\n\nexport const applyPatches = async () => {\n\t// §1.1 — bare specifier in dev shares Bun's module cache with bundled\n\t// server pages. Production stays on the resolved vendor path. Use\n\t// `isProductionRuntime()` instead of a direct `process.env.NODE_ENV`\n\t// read so Bun's bundler doesn't constant-fold this branch out of\n\t// dist/ at absolutejs build time.\n\tconst spec = isProductionRuntime()\n\t\t? resolveAngularRuntimePath('@angular/platform-server')\n\t\t: '@angular/platform-server';\n\tconst { ɵDominoAdapter } = await import(spec);\n\tif (!ɵDominoAdapter?.prototype) {\n\t\tconsole.warn(\n\t\t\t'[Angular Patch] ɵDominoAdapter not found, skipping patches'\n\t\t);\n\n\t\treturn false;\n\t}\n\n\t// Patch the layout shims onto Domino's Element prototypes immediately\n\t// (don't wait for the first createHtmlDocument call). Components that\n\t// hold an ElementRef from the very first change-detection pass call\n\t// these methods before the lazy patch path would have run.\n\ttry {\n\t\tconst adapter = new ɵDominoAdapter();\n\t\tconst seedDoc =\n\t\t\ttypeof adapter.createHtmlDocument === 'function'\n\t\t\t\t? adapter.createHtmlDocument()\n\t\t\t\t: typeof adapter.getDefaultDocument === 'function'\n\t\t\t\t\t? adapter.getDefaultDocument()\n\t\t\t\t\t: null;\n\t\tif (seedDoc) {\n\t\t\tpatchElementLayout(seedDoc);\n\t\t\tconst probe = seedDoc.createElement('div') as Element & {\n\t\t\t\tgetBoundingClientRect?: () => DOMRect;\n\t\t\t};\n\t\t\tif (typeof probe.getBoundingClientRect !== 'function') {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t'[Angular Patch] Layout shim did not stick on probe element prototype chain'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t} catch (error) {\n\t\tconsole.warn(\n\t\t\t'[Angular Patch] Could not eagerly patch Element prototypes:',\n\t\t\terror\n\t\t);\n\t}\n\n\tconst proto = ɵDominoAdapter.prototype;\n\n\tconst origGetBaseHref = proto.getBaseHref;\n\tproto.getBaseHref = function (doc: Document) {\n\t\tif (!doc || !doc.head || typeof doc.head.children === 'undefined') {\n\t\t\treturn '';\n\t\t}\n\n\t\treturn origGetBaseHref.call(this, doc);\n\t};\n\n\tconst origCreateHtmlDocument = proto.createHtmlDocument;\n\tproto.createHtmlDocument = function () {\n\t\tconst doc = origCreateHtmlDocument.call(this);\n\t\tensureHead(doc);\n\t\tpatchElementLayout(doc);\n\n\t\treturn doc;\n\t};\n\n\tconst origGetDefaultDocument = proto.getDefaultDocument;\n\tproto.getDefaultDocument = function () {\n\t\tconst doc = origGetDefaultDocument.call(this);\n\t\tensureHead(doc);\n\t\tpatchElementLayout(doc);\n\n\t\treturn doc;\n\t};\n\n\treturn true;\n};\n",
|
|
15
|
-
"import type { AngularDeps } from '../../types/angular';\nimport { resolveAngularRuntimePath } from './resolveAngularPackage';\nimport {\n\tisDevelopmentRuntime,\n\tisProductionRuntime\n} from '../utils/runtimeMode';\n\nconst initDominoAdapter = (platformServer: {\n\tɵDominoAdapter?: { makeCurrent?: () => void };\n}) => {\n\ttry {\n\t\tplatformServer.ɵDominoAdapter?.makeCurrent?.();\n\t} catch (err) {\n\t\tconsole.error('Failed to initialize DominoAdapter:', err);\n\t}\n};\n\nconst loadAngularDeps = async () => {\n\t// JIT compiler is only needed in development, where user pages are\n\t// runtime-compiled by `compileAngularFileJIT` and emit partial\n\t// declarations that need the compiler facade to link. In production\n\t// the linker has already processed every partial declaration into\n\t// final ɵdir/ɵcmp/ɵfac at vendor build time, so the compiler isn't\n\t// imported and isn't part of the prod vendor bundle.\n\tif (!isProductionRuntime()) {\n\t\t// Bare specifier in dev — Bun's module cache dedupes on\n\t\t// normalized specifier, so this is the same instance as the\n\t\t// `import \"@angular/compiler\"` baked into bundled server pages.\n\t\tawait import('@angular/compiler');\n\t}\n\n\t// angularPatch imports @angular/platform-server internally, so it\n\t// must also run after the compiler is available.\n\tconst { applyPatches } = await import('./angularPatch');\n\tawait applyPatches();\n\n\t// In dev (no Angular server vendor on disk — see §1.1), use bare\n\t// specifiers so Bun resolves them through node_modules and shares\n\t// the same module records with the bundled server pages, which\n\t// also have bare `@angular/*` imports in dev. Production keeps the\n\t// resolved-path import because the vendor bundle is what every\n\t// server-side import points at, and the resolved path is stable.\n\tconst useBareSpecifiers = !isProductionRuntime();\n\tconst [platformBrowser, platformServer, common, core] = await Promise.all([\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/platform-browser'\n\t\t\t\t: resolveAngularRuntimePath('@angular/platform-browser')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/platform-server'\n\t\t\t\t: resolveAngularRuntimePath('@angular/platform-server')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/common'\n\t\t\t\t: resolveAngularRuntimePath('@angular/common')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/core'\n\t\t\t\t: resolveAngularRuntimePath('@angular/core')\n\t\t)\n\t]);\n\n\tif (!isDevelopmentRuntime()) {\n\t\tcore.enableProdMode();\n\t}\n\n\tinitDominoAdapter(platformServer);\n\n\treturn {\n\t\tAPP_BASE_HREF: common.APP_BASE_HREF,\n\t\tbootstrapApplication: platformBrowser.bootstrapApplication,\n\t\tDomSanitizer: platformBrowser.DomSanitizer,\n\t\tENVIRONMENT_INITIALIZER: core.ENVIRONMENT_INITIALIZER,\n\t\tinject: core.inject,\n\t\tprovideClientHydration: platformBrowser.provideClientHydration,\n\t\tprovideServerRendering: platformServer.provideServerRendering,\n\t\tprovideZonelessChangeDetection: core.provideZonelessChangeDetection,\n\t\treflectComponentType: core.reflectComponentType,\n\t\trenderApplication: platformServer.renderApplication,\n\t\tREQUEST: core.REQUEST,\n\t\tREQUEST_CONTEXT: core.REQUEST_CONTEXT,\n\t\tRESPONSE_INIT: core.RESPONSE_INIT,\n\t\tSanitizer: core.Sanitizer,\n\t\tSecurityContext: core.SecurityContext,\n\t\twithHttpTransferCacheOptions:\n\t\t\tplatformBrowser.withHttpTransferCacheOptions\n\t};\n};\n\nlet angularDeps: Promise<AngularDeps> | null = null;\n\nexport const getAngularDeps = () => {\n\tif (!angularDeps) {\n\t\tangularDeps = loadAngularDeps();\n\t}\n\n\treturn angularDeps;\n};\n\n// TODO(test): the unit-style coverage in\n// `tests/integration/angular/single-core.test.ts` checks that\n// `resolveAngularRuntimePath` is consistent across calls and that two\n// dynamic imports from the resolved path return the same module record\n// — necessary but not sufficient. A stronger test would spawn a dev\n// server, trigger an HMR cycle, and assert the SSR process never sees\n// two `@angular/core` evaluations (e.g. via a marker incremented at\n// module init in a vendor stub). The fixture in\n// `tests/fixtures/compile-angular` is wired for compile-time checks\n// only, so end-to-end verification of the
|
|
15
|
+
"import type { AngularDeps } from '../../types/angular';\nimport { resolveAngularRuntimePath } from './resolveAngularPackage';\nimport {\n\tisDevelopmentRuntime,\n\tisProductionRuntime\n} from '../utils/runtimeMode';\n\nconst initDominoAdapter = (platformServer: {\n\tɵDominoAdapter?: { makeCurrent?: () => void };\n}) => {\n\ttry {\n\t\tplatformServer.ɵDominoAdapter?.makeCurrent?.();\n\t} catch (err) {\n\t\tconsole.error('Failed to initialize DominoAdapter:', err);\n\t}\n};\n\nconst loadAngularDeps = async () => {\n\t// JIT compiler is only needed in development, where user pages are\n\t// runtime-compiled by `compileAngularFileJIT` and emit partial\n\t// declarations that need the compiler facade to link. In production\n\t// the linker has already processed every partial declaration into\n\t// final ɵdir/ɵcmp/ɵfac at vendor build time, so the compiler isn't\n\t// imported and isn't part of the prod vendor bundle.\n\tif (!isProductionRuntime()) {\n\t\t// Bare specifier in dev — Bun's module cache dedupes on\n\t\t// normalized specifier, so this is the same instance as the\n\t\t// `import \"@angular/compiler\"` baked into bundled server pages.\n\t\tawait import('@angular/compiler');\n\t}\n\n\t// angularPatch imports @angular/platform-server internally, so it\n\t// must also run after the compiler is available.\n\tconst { applyPatches } = await import('./angularPatch');\n\tawait applyPatches();\n\n\t// In dev (no Angular server vendor on disk — see §1.1), use bare\n\t// specifiers so Bun resolves them through node_modules and shares\n\t// the same module records with the bundled server pages, which\n\t// also have bare `@angular/*` imports in dev. Production keeps the\n\t// resolved-path import because the vendor bundle is what every\n\t// server-side import points at, and the resolved path is stable.\n\tconst useBareSpecifiers = !isProductionRuntime();\n\tconst [platformBrowser, platformServer, common, core] = await Promise.all([\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/platform-browser'\n\t\t\t\t: resolveAngularRuntimePath('@angular/platform-browser')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/platform-server'\n\t\t\t\t: resolveAngularRuntimePath('@angular/platform-server')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/common'\n\t\t\t\t: resolveAngularRuntimePath('@angular/common')\n\t\t),\n\t\timport(\n\t\t\tuseBareSpecifiers\n\t\t\t\t? '@angular/core'\n\t\t\t\t: resolveAngularRuntimePath('@angular/core')\n\t\t)\n\t]);\n\n\tif (!isDevelopmentRuntime()) {\n\t\tcore.enableProdMode();\n\t}\n\n\tinitDominoAdapter(platformServer);\n\n\treturn {\n\t\tAPP_BASE_HREF: common.APP_BASE_HREF,\n\t\tbootstrapApplication: platformBrowser.bootstrapApplication,\n\t\tDomSanitizer: platformBrowser.DomSanitizer,\n\t\tENVIRONMENT_INITIALIZER: core.ENVIRONMENT_INITIALIZER,\n\t\tinject: core.inject,\n\t\tprovideClientHydration: platformBrowser.provideClientHydration,\n\t\tprovideServerRendering: platformServer.provideServerRendering,\n\t\tprovideZonelessChangeDetection: core.provideZonelessChangeDetection,\n\t\treflectComponentType: core.reflectComponentType,\n\t\trenderApplication: platformServer.renderApplication,\n\t\tREQUEST: core.REQUEST,\n\t\tREQUEST_CONTEXT: core.REQUEST_CONTEXT,\n\t\tRESPONSE_INIT: core.RESPONSE_INIT,\n\t\tSanitizer: core.Sanitizer,\n\t\tSecurityContext: core.SecurityContext,\n\t\twithHttpTransferCacheOptions:\n\t\t\tplatformBrowser.withHttpTransferCacheOptions\n\t};\n};\n\nlet angularDeps: Promise<AngularDeps> | null = null;\n\nexport const getAngularDeps = () => {\n\tif (!angularDeps) {\n\t\tangularDeps = loadAngularDeps();\n\t}\n\n\treturn angularDeps;\n};\n\n// TODO(test): the unit-style coverage in\n// `tests/integration/angular/single-core.test.ts` checks that\n// `resolveAngularRuntimePath` is consistent across calls and that two\n// dynamic imports from the resolved path return the same module record\n// — necessary but not sufficient. A stronger test would spawn a dev\n// server, trigger an HMR cycle, and assert the SSR process never sees\n// two `@angular/core` evaluations (e.g. via a marker incremented at\n// module init in a vendor stub). The fixture in\n// `tests/fixtures/compile-angular` is wired for compile-time checks\n// only, so end-to-end verification of the SSR core uniqueness fix\n// happens manually in `~/onspark/absolutejs/dealroom` (see\n// ABSOLUTEJS_ANGULAR_HMR.md §3.9).\n",
|
|
16
16
|
"const normalizeSlug = (str: string) =>\n\tstr\n\t\t.trim()\n\t\t.replace(/\\s+/g, '-')\n\t\t.replace(/[^A-Za-z0-9\\-_]+/g, '')\n\t\t.replace(/[-_]{2,}/g, '-');\n\nexport const toKebab = (str: string) =>\n\tnormalizeSlug(str)\n\t\t.replace(/([a-z0-9])([A-Z])/g, '$1-$2')\n\t\t.toLowerCase();\nexport const toPascal = (str: string) => {\n\tif (!str.includes('-') && !str.includes('_')) {\n\t\treturn str.charAt(0).toUpperCase() + str.slice(1);\n\t}\n\n\treturn normalizeSlug(str)\n\t\t.split(/[-_]/)\n\t\t.filter(Boolean)\n\t\t.map(\n\t\t\t(segment) =>\n\t\t\t\tsegment.charAt(0).toUpperCase() + segment.slice(1).toLowerCase()\n\t\t)\n\t\t.join('');\n};\nexport const toScreamingSnake = (str: string) =>\n\tstr.replace(/([a-z0-9])([A-Z])/g, '$1_$2').toUpperCase();\n",
|
|
17
17
|
"/**\n * Utility for registering client-side scripts that need to run after Angular SSR hydration.\n *\n * This is necessary because Angular's lifecycle hooks don't always run reliably on the client\n * after SSR hydration, especially for event listeners attached to DOM elements.\n *\n * Usage in Angular components:\n * ```typescript\n * import { registerClientScript } from '@absolutejs/absolute';\n *\n * // Register an event listener script\n * registerClientScript(() => {\n * const element = document.querySelector('.my-element');\n * if (element) {\n * element.addEventListener('click', () => {\n * console.log('Clicked!');\n * });\n * }\n * });\n * ```\n *\n * The script will be automatically injected into the HTML response and executed on the client.\n */\n\n// Request-scoped registry for client scripts\n// Each request gets its own set of scripts to inject\nconst scriptRegistry = new Map<string, Set<() => void>>();\n\n// Generate a unique request ID for tracking scripts per request\nlet requestCounter = 0;\nconst getRequestId = () => `req_${Date.now()}_${++requestCounter}`;\n\n// Allow SSR frameworks to inject a request context getter (e.g. AsyncLocalStorage)\nlet ssrContextGetter: (() => string | undefined) | null = null;\nexport const getSsrContextId = () =>\n\tssrContextGetter?.() ||\n\tObject.getOwnPropertyDescriptor(globalThis, '__absolutejs_requestId')\n\t\t?.value;\nexport const registerClientScript = (\n\tscript: () => void,\n\trequestId?: string\n) => {\n\t// Try to get requestId from explicit arg, then Async Context, then global fallback\n\tconst id = requestId || getSsrContextId() || getRequestId();\n\n\tif (!scriptRegistry.has(id)) {\n\t\tscriptRegistry.set(id, new Set());\n\t}\n\n\tscriptRegistry.get(id)?.add(script);\n\n\treturn id;\n};\nexport const setSsrContextGetter = (getter: () => string | undefined) => {\n\tssrContextGetter = getter;\n};\n\n// Make registerClientScript available globally during SSR for Angular components\n// Using type assertion for globalThis extension\nif (typeof globalThis !== 'undefined') {\n\tObject.assign(globalThis, { registerClientScript });\n}\n\n/**\n * Get all registered scripts for a request and clear them.\n * This is called by the page handler after rendering.\n *\n * @param requestId - The request ID to get scripts for\n * @returns Array of script functions, or empty array if none registered\n */\nexport const clearAllClientScripts = () => {\n\tscriptRegistry.clear();\n};\nexport const generateClientScriptCode = (scripts: (() => void)[]) => {\n\tif (scripts.length === 0) {\n\t\treturn '';\n\t}\n\n\t// Convert functions to strings and wrap in IIFE\n\tconst scriptCode = scripts\n\t\t.map((script, index) => {\n\t\t\t// Get the function body as a string\n\t\t\tconst funcString = script.toString();\n\n\t\t\t// Extract the body (everything between { and })\n\t\t\tconst bodyMatch = funcString.match(/\\{([\\s\\S]*)\\}/);\n\t\t\tif (!bodyMatch || !bodyMatch[1]) {\n\t\t\t\treturn '';\n\t\t\t}\n\n\t\t\tconst body = bodyMatch[1].trim();\n\n\t\t\t// Wrap in IIFE with MutationObserver for DOM readiness\n\t\t\treturn `\n\t(function() {\n\t\tvar executed = false;\n\t\tfunction executeScript_${index}() {\n\t\t\tif (executed) return;\n\t\t\texecuted = true;\n\t\t\t${body}\n\t\t}\n\n\t\tif (document.readyState === 'complete' || document.readyState === 'interactive') {\n\t\t\texecuteScript_${index}();\n\t\t} else {\n\t\t\tdocument.addEventListener('DOMContentLoaded', executeScript_${index});\n\t\t}\n\n\t\t// Watch for hydration-added elements\n\t\tvar observer = new MutationObserver(function() {\n\t\t\texecuteScript_${index}();\n\t\t\tif (executed) observer.disconnect();\n\t\t});\n\t\tif (!executed) {\n\t\t\tobserver.observe(document.body || document.documentElement, { childList: true, subtree: true });\n\t\t}\n\n\t\t// Single fallback timeout\n\t\tsetTimeout(function() {\n\t\t\texecuteScript_${index}();\n\t\t\tobserver.disconnect();\n\t\t}, 1000);\n\t})();`;\n\t\t})\n\t\t.join('\\n');\n\n\treturn `<script>\n(function() {\n${scriptCode}\n})();\n</script>`;\n};\nexport const getAndClearClientScripts = (requestId?: string) => {\n\tconst id = requestId || ssrContextGetter?.();\n\tif (!id) return [];\n\n\tconst scripts = scriptRegistry.get(id);\n\tif (!scripts) {\n\t\treturn [];\n\t}\n\n\tconst scriptArray = Array.from(scripts);\n\tscriptRegistry.delete(id);\n\n\treturn scriptArray;\n};\n",
|
|
18
18
|
"import type { HttpTransferCacheOptions } from '@angular/common/http';\n\nexport const ABSOLUTE_HTTP_TRANSFER_CACHE_SKIP_HEADER = 'x-skip-transfer-cache';\n\nexport type AbsoluteHttpTransferCacheOptions = Omit<\n\tHttpTransferCacheOptions,\n\t'filter'\n> & {\n\tfilter?: NonNullable<HttpTransferCacheOptions['filter']>;\n\tskipHeader?: string;\n};\n\nexport const buildAbsoluteHttpTransferCacheOptions = (\n\toptions: AbsoluteHttpTransferCacheOptions = {}\n) => {\n\tconst {\n\t\tfilter: userFilter,\n\t\tskipHeader = ABSOLUTE_HTTP_TRANSFER_CACHE_SKIP_HEADER,\n\t\t...angularOptions\n\t} = options;\n\n\treturn {\n\t\tincludePostRequests: false,\n\t\tincludeRequestsWithAuthHeaders: false,\n\t\t...angularOptions,\n\t\tfilter: (request) =>\n\t\t\t!request.headers.has(skipHeader) && (userFilter?.(request) ?? true)\n\t} satisfies HttpTransferCacheOptions;\n};\n",
|
package/dist/index.js
CHANGED
|
@@ -18689,6 +18689,8 @@ var fail = (reason, detail, location) => ({
|
|
|
18689
18689
|
return false;
|
|
18690
18690
|
if (!arraysEqual(a.memberDecoratorSig, b2.memberDecoratorSig))
|
|
18691
18691
|
return false;
|
|
18692
|
+
if (!arraysEqual(a.topLevelImports, b2.topLevelImports))
|
|
18693
|
+
return false;
|
|
18692
18694
|
return true;
|
|
18693
18695
|
}, recordFingerprint = (id, fp) => {
|
|
18694
18696
|
fingerprintCache.set(id, fp);
|
|
@@ -18831,7 +18833,7 @@ var fail = (reason, detail, location) => ({
|
|
|
18831
18833
|
}
|
|
18832
18834
|
}
|
|
18833
18835
|
return false;
|
|
18834
|
-
}, readDecoratorMeta = (args) => {
|
|
18836
|
+
}, readDecoratorMeta = (args, projectDefaults = {}) => {
|
|
18835
18837
|
const styleUrlsExpr = getProperty(args, "styleUrls");
|
|
18836
18838
|
const stylesExpr = getProperty(args, "styles");
|
|
18837
18839
|
const importsExpr = getProperty(args, "imports");
|
|
@@ -18858,7 +18860,7 @@ var fail = (reason, detail, location) => ({
|
|
|
18858
18860
|
hasProviders: getProperty(args, "providers") !== null,
|
|
18859
18861
|
hasViewProviders: getProperty(args, "viewProviders") !== null,
|
|
18860
18862
|
importsExpr: importsExpr && ts7.isArrayLiteralExpression(importsExpr) ? importsExpr : null,
|
|
18861
|
-
preserveWhitespaces: getBooleanProperty(args, "preserveWhitespaces") ?? false,
|
|
18863
|
+
preserveWhitespaces: getBooleanProperty(args, "preserveWhitespaces") ?? projectDefaults.preserveWhitespaces ?? false,
|
|
18862
18864
|
selector: getStringProperty(args, "selector"),
|
|
18863
18865
|
standalone: getBooleanProperty(args, "standalone") ?? true,
|
|
18864
18866
|
styleUrl: getStringProperty(args, "styleUrl"),
|
|
@@ -19751,6 +19753,32 @@ var fail = (reason, detail, location) => ({
|
|
|
19751
19753
|
}
|
|
19752
19754
|
}
|
|
19753
19755
|
return sig.sort();
|
|
19756
|
+
}, extractTopLevelImports = (sourceFile) => {
|
|
19757
|
+
const names = new Set;
|
|
19758
|
+
for (const stmt of sourceFile.statements) {
|
|
19759
|
+
if (!ts7.isImportDeclaration(stmt))
|
|
19760
|
+
continue;
|
|
19761
|
+
const clause = stmt.importClause;
|
|
19762
|
+
if (!clause)
|
|
19763
|
+
continue;
|
|
19764
|
+
if (clause.isTypeOnly)
|
|
19765
|
+
continue;
|
|
19766
|
+
if (clause.name)
|
|
19767
|
+
names.add(clause.name.text);
|
|
19768
|
+
const bindings = clause.namedBindings;
|
|
19769
|
+
if (!bindings)
|
|
19770
|
+
continue;
|
|
19771
|
+
if (ts7.isNamespaceImport(bindings)) {
|
|
19772
|
+
names.add(bindings.name.text);
|
|
19773
|
+
} else if (ts7.isNamedImports(bindings)) {
|
|
19774
|
+
for (const el of bindings.elements) {
|
|
19775
|
+
if (el.isTypeOnly)
|
|
19776
|
+
continue;
|
|
19777
|
+
names.add(el.name.text);
|
|
19778
|
+
}
|
|
19779
|
+
}
|
|
19780
|
+
}
|
|
19781
|
+
return [...names].sort();
|
|
19754
19782
|
}, extractFingerprint = (cls, className, decoratorMeta, inputs, outputs, sourceFile, componentDir) => {
|
|
19755
19783
|
const ctorParamTypes = [];
|
|
19756
19784
|
for (const member of cls.members) {
|
|
@@ -19766,6 +19794,7 @@ var fail = (reason, detail, location) => ({
|
|
|
19766
19794
|
const arrowFieldSig = extractArrowFieldSig(cls);
|
|
19767
19795
|
const memberDecoratorSig = extractMemberDecoratorSig(cls);
|
|
19768
19796
|
const providerImportSig = extractProviderImportSig(decoratorMeta.importsExpr, sourceFile, componentDir);
|
|
19797
|
+
const topLevelImports = extractTopLevelImports(sourceFile);
|
|
19769
19798
|
return {
|
|
19770
19799
|
arrowFieldSig,
|
|
19771
19800
|
className,
|
|
@@ -19777,7 +19806,8 @@ var fail = (reason, detail, location) => ({
|
|
|
19777
19806
|
outputs: outputNames,
|
|
19778
19807
|
providerImportSig,
|
|
19779
19808
|
selector: decoratorMeta.selector,
|
|
19780
|
-
standalone: decoratorMeta.standalone
|
|
19809
|
+
standalone: decoratorMeta.standalone,
|
|
19810
|
+
topLevelImports
|
|
19781
19811
|
};
|
|
19782
19812
|
}, buildFreshClassMethodsBlock = (classNode, className) => {
|
|
19783
19813
|
const memberSources = [];
|
|
@@ -19881,6 +19911,27 @@ ${transpiled}
|
|
|
19881
19911
|
${block}
|
|
19882
19912
|
}
|
|
19883
19913
|
`;
|
|
19914
|
+
}, projectOptionsCache, readProjectAngularCompilerOptions = (projectRoot) => {
|
|
19915
|
+
const cached = projectOptionsCache.get(projectRoot);
|
|
19916
|
+
if (cached !== undefined)
|
|
19917
|
+
return cached;
|
|
19918
|
+
const tsconfigPath = resolve34(projectRoot, "tsconfig.json");
|
|
19919
|
+
let opts = {};
|
|
19920
|
+
if (existsSync26(tsconfigPath)) {
|
|
19921
|
+
try {
|
|
19922
|
+
const text = readFileSync20(tsconfigPath, "utf8");
|
|
19923
|
+
const parsed = ts7.parseConfigFileTextToJson(tsconfigPath, text);
|
|
19924
|
+
if (!parsed.error && parsed.config) {
|
|
19925
|
+
const cfg = parsed.config;
|
|
19926
|
+
const raw = cfg.angularCompilerOptions?.preserveWhitespaces;
|
|
19927
|
+
if (typeof raw === "boolean") {
|
|
19928
|
+
opts = { preserveWhitespaces: raw };
|
|
19929
|
+
}
|
|
19930
|
+
}
|
|
19931
|
+
} catch {}
|
|
19932
|
+
}
|
|
19933
|
+
projectOptionsCache.set(projectRoot, opts);
|
|
19934
|
+
return opts;
|
|
19884
19935
|
}, tryFastHmr = async (params) => {
|
|
19885
19936
|
const { componentFilePath, className } = params;
|
|
19886
19937
|
const projectRoot = params.projectRoot ?? process.cwd();
|
|
@@ -19921,7 +19972,8 @@ ${block}
|
|
|
19921
19972
|
const decoratorArgs = getDecoratorArgsObject(decorator);
|
|
19922
19973
|
if (!decoratorArgs)
|
|
19923
19974
|
return fail("unsupported-decorator-args");
|
|
19924
|
-
const
|
|
19975
|
+
const projectDefaults = readProjectAngularCompilerOptions(projectRoot);
|
|
19976
|
+
const decoratorMeta = readDecoratorMeta(decoratorArgs, projectDefaults);
|
|
19925
19977
|
const advancedMetadata = extractAdvancedMetadata(classNode, decoratorArgs, compiler);
|
|
19926
19978
|
const componentDir = dirname19(componentFilePath);
|
|
19927
19979
|
let templateText;
|
|
@@ -20192,6 +20244,7 @@ var init_fastHmrCompiler = __esm(() => {
|
|
|
20192
20244
|
INPUT_OUTPUT_DECORATORS = new Set(["Input", "Output"]);
|
|
20193
20245
|
providerProbeCache = new Map;
|
|
20194
20246
|
TS_EXTENSIONS = [".ts", ".tsx", ".d.ts"];
|
|
20247
|
+
projectOptionsCache = new Map;
|
|
20195
20248
|
});
|
|
20196
20249
|
|
|
20197
20250
|
// src/dev/angular/hmrCompiler.ts
|
|
@@ -31430,5 +31483,5 @@ export {
|
|
|
31430
31483
|
ANGULAR_INIT_TIMEOUT_MS
|
|
31431
31484
|
};
|
|
31432
31485
|
|
|
31433
|
-
//# debugId=
|
|
31486
|
+
//# debugId=896D5FD28A1E79A364756E2164756E21
|
|
31434
31487
|
//# sourceMappingURL=index.js.map
|