@vltpkg/vsr 0.2.0 → 0.2.2

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
@@ -22,7 +22,7 @@
22
22
  You can quickly get started by installing/executing `vsr` with the following command:
23
23
 
24
24
  ```bash
25
- vlx -y @vltpkg/vsr
25
+ npx @vltpkg/vsr
26
26
  ```
27
27
 
28
28
  #### Production
package/bin/vsr.ts CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node --no-warnings --experimental-strip-types
1
+ #!/usr/bin/env node --loader ts-node/esm --no-warnings --experimental-strip-types
2
2
  import { fileURLToPath } from 'node:url'
3
3
  import path from 'node:path'
4
4
  import { execSync } from 'node:child_process'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vltpkg/vsr",
3
- "version": "0.2.0",
3
+ "version": "0.2.2",
4
4
  "license": "FSL-1.1-MIT",
5
5
  "author": "vlt technology inc. <support@vlt.sh> (http://vlt.sh)",
6
6
  "type": "module",
@@ -10,6 +10,9 @@
10
10
  "directory": "src/vsr"
11
11
  },
12
12
  "bin": "./bin/vsr.ts",
13
+ "engines": {
14
+ "node": ">=22.14.0"
15
+ },
13
16
  "scripts": {
14
17
  "db:push": "drizzle-kit push",
15
18
  "db:generate": "drizzle-kit generate",
@@ -75,6 +78,8 @@
75
78
  "path-scurry": "^2.0.0"
76
79
  },
77
80
  "peerDependencies": {
78
- "wrangler": "^4.20.3"
81
+ "ts-node": "^10.9.1",
82
+ "wrangler": "^4.20.3",
83
+ "node": ">=22.14.0"
79
84
  }
80
85
  }
package/test/README.md DELETED
@@ -1,91 +0,0 @@
1
- # Background Refresh Testing
2
-
3
- This directory contains tests for the background refresh functionality and the stale-while-revalidate caching pattern used in this registry.
4
-
5
- ## Understanding the Cache Refresh Pattern
6
-
7
- The registry implements a "stale-while-revalidate" caching pattern for faster responses:
8
-
9
- 1. When a request is received, we first check if the data is in our cache
10
- 2. If the data is in the cache, we return it immediately, even if it's stale (old)
11
- 3. If the data is stale, we queue a background task to refresh it from the upstream registry
12
- 4. The background task updates the cache with fresh data for future requests
13
- 5. This approach ensures users get a fast response (cached data) while keeping our cache up-to-date
14
-
15
- ## How `waitUntil` Works
16
-
17
- Cloudflare Workers provide a special API called `waitUntil` that enables background tasks to continue running after a response has been sent. Here's a simplified example:
18
-
19
- ```javascript
20
- export default {
21
- async fetch(request, env, ctx) {
22
- // Return a response immediately
23
- const response = new Response("Hello World");
24
-
25
- // Queue a background task that continues after response is sent
26
- ctx.waitUntil(
27
- (async () => {
28
- // This runs in the background after response is sent
29
- await doLongRunningTask();
30
- })()
31
- );
32
-
33
- return response;
34
- }
35
- };
36
- ```
37
-
38
- ## Test Files
39
-
40
- - `waituntil-demo.test.js`: Demonstrates the `waitUntil` API and caching pattern
41
- - `waituntil-correct.test.js`: Shows the correct way to test the `waitUntil` pattern
42
- - `hono-context.test.js`: Demonstrates how to mock the Hono context with proper `waitUntil` support
43
- - `route-with-waituntil.test.js`: Tests a route handler implementing the stale-while-revalidate pattern
44
-
45
- ## Testing the `waitUntil` Pattern
46
-
47
- Testing `waitUntil` behavior can be tricky because of how JavaScript executes Immediately Invoked Function Expressions (IIFEs). The common mistake is to use code like this:
48
-
49
- ```javascript
50
- // ❌ PROBLEM: This executes the function immediately!
51
- c.waitUntil((async () => {
52
- // Background work
53
- await refreshCache();
54
- })());
55
- ```
56
-
57
- Instead, our testing approach:
58
-
59
- 1. Correctly simulates the Cloudflare `waitUntil` API
60
- 2. Captures background tasks without executing them immediately
61
- 3. Allows precise control over when background tasks run
62
-
63
- See `waituntil-README.md` for detailed documentation on our testing approach.
64
-
65
- ## Implementation Details
66
-
67
- In the codebase, this pattern is used in:
68
- - `getPackagePackument`: to fetch package metadata
69
- - `getPackageManifest`: to fetch specific package versions
70
-
71
- ## Testing Challenges
72
-
73
- Testing asynchronous background tasks presents challenges:
74
- 1. Ensuring the correct execution order (main handler first, then background tasks)
75
- 2. Verifying the background task actually runs
76
- 3. Controlling when background tasks execute in tests
77
-
78
- Our test suite includes examples showing how to correctly test each of these aspects.
79
-
80
- ## Running Tests
81
-
82
- ```bash
83
- # Run all tests
84
- npm test
85
-
86
- # Run only the cache refresh tests
87
- npm run test:cache
88
-
89
- # Run only the improved waitUntil tests
90
- npm run test:improved
91
- ```