@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 +1 -1
- package/bin/vsr.ts +1 -1
- package/package.json +7 -2
- package/test/README.md +0 -91
- package/test/access.test.js +0 -760
- package/test/cloudflare-waituntil.test.js +0 -141
- package/test/db.test.js +0 -447
- package/test/dist-tag.test.js +0 -415
- package/test/e2e.test.js +0 -904
- package/test/hono-context.test.js +0 -250
- package/test/integrity-validation.test.js +0 -183
- package/test/json-response.test.js +0 -76
- package/test/manifest-slimming.test.js +0 -449
- package/test/packument-consistency.test.js +0 -351
- package/test/packument-version-range.test.js +0 -144
- package/test/performance.test.js +0 -162
- package/test/route-with-waituntil.test.js +0 -298
- package/test/run-tests.js +0 -151
- package/test/setup-cache-tests.js +0 -190
- package/test/setup.js +0 -64
- package/test/stale-while-revalidate.test.js +0 -273
- package/test/static-assets.test.js +0 -85
- package/test/upstream-routing.test.js +0 -86
- package/test/utils/test-helpers.js +0 -84
- package/test/waituntil-correct.test.js +0 -208
- package/test/waituntil-demo.test.js +0 -138
- package/test/waituntil-readme.md +0 -113
package/README.md
CHANGED
package/bin/vsr.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vltpkg/vsr",
|
|
3
|
-
"version": "0.2.
|
|
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
|
-
"
|
|
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
|
-
```
|