@jimhoyd/urlcode-auth 0.1.0-alpha.6 → 0.4.0-alpha.3

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/README.md CHANGED
@@ -131,6 +131,12 @@ import, or a named export that is not a function fails **activation** —
131
131
  before this extension serves a single request — never the first request
132
132
  that happens to reach the hook.
133
133
 
134
+ Each activation re-reads the hook's **entry** module from disk, so editing a
135
+ hook file and re-activating (a dev reload) takes effect without restarting
136
+ the process. Only the entry module is refreshed: modules the hook itself
137
+ imports stay on Node's module cache for the life of the process, so a change
138
+ to a hook's own dependency still needs a restart.
139
+
134
140
  **`sandbox: true` is not implemented for these hooks and is refused
135
141
  explicitly at activation**, naming the hook: `hook <name>: sandbox: true is
136
142
  not yet supported for project-level hooks, see jimhoyd-com/urlcode-auth#35`.
@@ -20,6 +20,17 @@ var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExte
20
20
  // no way to actually isolate a hook call yet (tracked in
21
21
  // jimhoyd-com/urlcode#151). Accepting `sandbox: true` and running it trusted
22
22
  // anyway would misrepresent the isolation the project believes it configured.
23
+ //
24
+ // Each activation re-imports the hook's ENTRY module under a fresh
25
+ // cache-busting query, mirroring core's trusted route activation
26
+ // (src/trusted-functions.ts, `urlcode-trusted-epoch`): Node's ESM loader
27
+ // caches a resolved module forever by URL, so without this an edited hook
28
+ // file kept returning its previous decision for the life of the process
29
+ // (jimhoyd-com/urlcode#198). Only the entry module is refreshed — modules the
30
+ // hook itself imports stay on Node's module cache, the same already-documented
31
+ // core limitation the trusted route path has; a change to a hook's own
32
+ // dependency still needs a process restart.
33
+ import { randomUUID } from 'node:crypto';
23
34
  import { isAbsolute, relative, resolve } from 'node:path';
24
35
  import { realpath, stat } from 'node:fs/promises';
25
36
  import { pathToFileURL } from 'node:url';
@@ -82,6 +93,10 @@ export async function loadLifecycleHooks(config, root) {
82
93
  const hooks = {};
83
94
  if (!config)
84
95
  return hooks;
96
+ // One epoch per activation, not per hook: two hooks naming the same entry
97
+ // module still share a single instance within this activation, exactly as
98
+ // core's per-runtime-instance epoch does.
99
+ const epoch = randomUUID();
85
100
  for (const name of hookNames) {
86
101
  const ref = config[name];
87
102
  if (ref === undefined)
@@ -92,7 +107,7 @@ export async function loadLifecycleHooks(config, root) {
92
107
  const file = await projectFile(root, definition.source, name);
93
108
  let mod;
94
109
  try {
95
- mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href)));
110
+ mod = (await import(__rewriteRelativeImportExtension(pathToFileURL(file).href + '?urlcode-hook-epoch=' + epoch)));
96
111
  }
97
112
  catch {
98
113
  throw new Error(`hook ${name}: failed to load module "${definition.source}"`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jimhoyd/urlcode-auth",
3
- "version": "0.1.0-alpha.6",
3
+ "version": "0.4.0-alpha.3",
4
4
  "type": "module",
5
5
  "description": "Operator-installed authentication extension for URLCode: accounts, sessions, passkeys, OIDC, TOTP and trusted account pages",
6
6
  "license": "Apache-2.0",
@@ -52,8 +52,8 @@
52
52
  "otpauth": "9.5.2"
53
53
  },
54
54
  "peerDependencies": {
55
- "@jimhoyd/urlcode": ">=0.4.0-alpha.2 <0.5.0",
56
- "@jimhoyd/urlcode-ui": ">=0.1.0-alpha.1 <0.2.0"
55
+ "@jimhoyd/urlcode": ">=0.4.0-alpha.3 <0.5.0",
56
+ "@jimhoyd/urlcode-ui": ">=0.4.0-alpha.3 <0.5.0"
57
57
  },
58
58
  "bin": {
59
59
  "urlcode-auth": "./dist/cli.js"