vitecache 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +48 -2
- package/dist/browser.d.ts +7 -0
- package/dist/browser.js +136 -0
- package/dist/browser.js.map +1 -0
- package/dist/dependencies.d.ts +9 -0
- package/dist/dependencies.js +118 -0
- package/dist/dependencies.js.map +1 -0
- package/dist/disk.d.ts +10 -0
- package/dist/disk.js +71 -0
- package/dist/disk.js.map +1 -0
- package/dist/entry.d.ts +11 -0
- package/dist/entry.js +81 -0
- package/dist/entry.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/dist/key.d.ts +3 -0
- package/dist/key.js +10 -0
- package/dist/key.js.map +1 -0
- package/dist/node.d.ts +7 -0
- package/dist/node.js +9 -0
- package/dist/node.js.map +1 -0
- package/dist/packages.d.ts +1 -0
- package/dist/packages.js +27 -0
- package/dist/packages.js.map +1 -0
- package/dist/storage.d.ts +5 -0
- package/dist/storage.js +97 -0
- package/dist/storage.js.map +1 -0
- package/dist/types.d.ts +54 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/vite/index.d.ts +8 -0
- package/dist/vite/index.js +210 -0
- package/dist/vite/index.js.map +1 -0
- package/dist/vite/manifest.d.ts +3 -0
- package/dist/vite/manifest.js +34 -0
- package/dist/vite/manifest.js.map +1 -0
- package/dist/vite/resolve.d.ts +8 -0
- package/dist/vite/resolve.js +81 -0
- package/dist/vite/resolve.js.map +1 -0
- package/package.json +70 -4
- package/skills/vitecache/SKILL.md +50 -0
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { realpath, stat } from 'node:fs/promises';
|
|
2
|
+
import { isAbsolute, relative, resolve, sep } from 'node:path';
|
|
3
|
+
import * as disk from '../disk.js';
|
|
4
|
+
export class OutsideRootError extends Error {
|
|
5
|
+
constructor() {
|
|
6
|
+
super('File dependencies must be inside the project root');
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
export function inside(root, path) {
|
|
10
|
+
const name = relative(root, path);
|
|
11
|
+
return name !== '..' && !name.startsWith(`..${sep}`) && !isAbsolute(name);
|
|
12
|
+
}
|
|
13
|
+
export async function confine(root, dependencies) {
|
|
14
|
+
const canonicalRoot = await realpath(root);
|
|
15
|
+
for (const dependency of Object.values(dependencies)) {
|
|
16
|
+
if (!('path' in dependency))
|
|
17
|
+
continue;
|
|
18
|
+
const path = resolve(root, dependency.path);
|
|
19
|
+
if (!inside(root, path))
|
|
20
|
+
throw new OutsideRootError();
|
|
21
|
+
try {
|
|
22
|
+
if (!inside(canonicalRoot, await realpath(path)))
|
|
23
|
+
throw new OutsideRootError();
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
if (!disk.missingDependency(error))
|
|
27
|
+
throw error;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async function exists(path) {
|
|
32
|
+
try {
|
|
33
|
+
return (await stat(path)).isFile();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
if (!disk.missingDependency(error))
|
|
37
|
+
throw error;
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export async function resolveDependencies(server, dependencies, origin) {
|
|
42
|
+
const entries = [];
|
|
43
|
+
const base = new URL(server.config.base, origin).pathname;
|
|
44
|
+
for (const [name, dependency] of Object.entries(dependencies)) {
|
|
45
|
+
if (!('url' in dependency)) {
|
|
46
|
+
entries.push([name, dependency]);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const url = new URL(dependency.url, origin);
|
|
50
|
+
if (url.origin !== origin)
|
|
51
|
+
throw new TypeError('File dependency URLs must have the Vite server origin');
|
|
52
|
+
if (!url.pathname.startsWith(base))
|
|
53
|
+
throw new TypeError('File dependency URL is outside the Vite base');
|
|
54
|
+
const pathname = decodeURIComponent(`/${url.pathname.slice(base.length)}`);
|
|
55
|
+
const publicFile = resolve(server.config.publicDir, `.${pathname}`);
|
|
56
|
+
const rootFile = resolve(server.config.root, `.${pathname}`);
|
|
57
|
+
let file;
|
|
58
|
+
if (server.config.publicDir && await exists(publicFile))
|
|
59
|
+
file = publicFile;
|
|
60
|
+
else if (pathname.startsWith('/@fs/'))
|
|
61
|
+
file = pathname.slice('/@fs'.length).replace(/^\/([A-Za-z]:\/)/, '$1');
|
|
62
|
+
else if (await exists(rootFile))
|
|
63
|
+
file = rootFile;
|
|
64
|
+
else {
|
|
65
|
+
const module = await server.pluginContainer.resolveId(pathname);
|
|
66
|
+
if (!module || !isAbsolute(module.id))
|
|
67
|
+
throw new TypeError(`Cannot resolve file dependency URL: ${dependency.url}`);
|
|
68
|
+
file = module.id.split('?')[0] ?? module.id;
|
|
69
|
+
}
|
|
70
|
+
if (!await exists(file))
|
|
71
|
+
throw new TypeError(`File dependency URL has no backing file: ${dependency.url}`);
|
|
72
|
+
const path = inside(server.config.root, file)
|
|
73
|
+
? relative(server.config.root, file)
|
|
74
|
+
: relative(await realpath(server.config.root), await realpath(file));
|
|
75
|
+
entries.push([name, { path: path.split(sep).join('/') }]);
|
|
76
|
+
}
|
|
77
|
+
const resolved = Object.fromEntries(entries);
|
|
78
|
+
await confine(server.config.root, resolved);
|
|
79
|
+
return resolved;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=resolve.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/vite/resolve.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAG/D,OAAO,KAAK,IAAI,MAAM,YAAY,CAAC;AAEnC,MAAM,OAAO,gBAAiB,SAAQ,KAAK;I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,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5D,CAAC;IACD,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IAC7C,MAAM,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAC5C,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import { realpath, stat } from 'node:fs/promises';\nimport { isAbsolute, relative, resolve, sep } from 'node:path';\nimport type { ViteDevServer } from 'vite';\nimport type { Dependencies, ResolvedDependencies, ResolvedDependency } from '../types.js';\nimport * as disk from '../disk.js';\n\nexport class OutsideRootError extends Error {\n constructor() {\n super('File dependencies must be inside the project root');\n }\n}\n\nexport function inside(root: string, path: string): boolean {\n const name = relative(root, path);\n return name !== '..' && !name.startsWith(`..${sep}`) && !isAbsolute(name);\n}\n\nexport async function confine(root: string, dependencies: ResolvedDependencies): Promise<void> {\n const canonicalRoot = await realpath(root);\n for (const dependency of Object.values(dependencies)) {\n if (!('path' in dependency)) continue;\n const path = resolve(root, dependency.path);\n if (!inside(root, path)) throw new OutsideRootError();\n try {\n if (!inside(canonicalRoot, await realpath(path))) throw new OutsideRootError();\n } catch (error) {\n if (!disk.missingDependency(error)) throw error;\n }\n }\n}\n\nasync function exists(path: string): Promise<boolean> {\n try {\n return (await stat(path)).isFile();\n } catch (error) {\n if (!disk.missingDependency(error)) throw error;\n return false;\n }\n}\n\nexport async function resolveDependencies(server: ViteDevServer, dependencies: Dependencies, origin: string): Promise<ResolvedDependencies> {\n const entries: [string, ResolvedDependency][] = [];\n const base = new URL(server.config.base, origin).pathname;\n for (const [name, dependency] of Object.entries(dependencies)) {\n if (!('url' in dependency)) {\n entries.push([name, dependency]);\n continue;\n }\n const url = new URL(dependency.url, origin);\n if (url.origin !== origin) throw new TypeError('File dependency URLs must have the Vite server origin');\n if (!url.pathname.startsWith(base)) throw new TypeError('File dependency URL is outside the Vite base');\n const pathname = decodeURIComponent(`/${url.pathname.slice(base.length)}`);\n const publicFile = resolve(server.config.publicDir, `.${pathname}`);\n const rootFile = resolve(server.config.root, `.${pathname}`);\n let file: string;\n if (server.config.publicDir && await exists(publicFile)) file = publicFile;\n else if (pathname.startsWith('/@fs/')) file = pathname.slice('/@fs'.length).replace(/^\\/([A-Za-z]:\\/)/, '$1');\n else if (await exists(rootFile)) file = rootFile;\n else {\n const module = await server.pluginContainer.resolveId(pathname);\n if (!module || !isAbsolute(module.id)) throw new TypeError(`Cannot resolve file dependency URL: ${dependency.url}`);\n file = module.id.split('?')[0] ?? module.id;\n }\n if (!await exists(file)) throw new TypeError(`File dependency URL has no backing file: ${dependency.url}`);\n const path = inside(server.config.root, file)\n ? relative(server.config.root, file)\n : relative(await realpath(server.config.root), await realpath(file));\n entries.push([name, { path: path.split(sep).join('/') }]);\n }\n const resolved = Object.fromEntries(entries);\n await confine(server.config.root, resolved);\n return resolved;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,72 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitecache",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Persistent binary caching for expensive computation in browsers and Node.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/drawcall-ai/vitecache.git",
|
|
10
|
+
"directory": "packages/vitecache"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/drawcall-ai/vitecache/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/drawcall-ai/vitecache#readme",
|
|
16
|
+
"keywords": [
|
|
17
|
+
"vite",
|
|
18
|
+
"cache",
|
|
19
|
+
"precompute",
|
|
20
|
+
"browser",
|
|
21
|
+
"node",
|
|
22
|
+
"typescript"
|
|
23
|
+
],
|
|
24
|
+
"sideEffects": false,
|
|
25
|
+
"main": "./dist/index.js",
|
|
26
|
+
"types": "./dist/index.d.ts",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"browser": "./dist/browser.js",
|
|
31
|
+
"node": "./dist/node.js",
|
|
32
|
+
"default": "./dist/browser.js"
|
|
33
|
+
},
|
|
34
|
+
"./vite": {
|
|
35
|
+
"types": "./dist/vite/index.d.ts",
|
|
36
|
+
"default": "./dist/vite/index.js"
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
"files": [
|
|
40
|
+
"dist",
|
|
41
|
+
"skills",
|
|
42
|
+
"README.md",
|
|
43
|
+
"LICENSE"
|
|
44
|
+
],
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
|
|
50
|
+
"prepack": "pnpm build && pnpm typecheck && pnpm test",
|
|
51
|
+
"test": "vitest run",
|
|
52
|
+
"typecheck": "tsc -p tsconfig.json --noEmit && tsc -p tsconfig.test.json --noEmit"
|
|
53
|
+
},
|
|
54
|
+
"dependencies": {
|
|
55
|
+
"@noble/hashes": "^2.0.1"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"vite": ">=6.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"vite": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
"devDependencies": {
|
|
66
|
+
"vite": "^8.0.0",
|
|
67
|
+
"vitest": "^4.0.17"
|
|
68
|
+
},
|
|
69
|
+
"engines": {
|
|
70
|
+
"node": ">=20.19.0"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: vitecache
|
|
3
|
+
description: Cache expensive computation with vitecache in browsers or Node, connect browser saves to a Vite development server, and reuse cached bytes in deployed apps.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# vitecache
|
|
7
|
+
|
|
8
|
+
Use vitecache when recomputing a result costs more than reading its encoded bytes. The application owns encoding and decoding. Declare every input that affects the computation as a named dependency. Use `{ value }` for JSON data and `{ package: "elkjs" }` for an installed library. Package dependencies track the named package’s installed version, so declare transitive packages separately when their versions matter. Bump the computation version for changes beyond what the declared dependencies capture.
|
|
9
|
+
|
|
10
|
+
Give dependencies stable names. Use `{ path: "src/simplify.ts" }` for a project-root-relative path or `{ url: modelUrl }` when you have an asset URL served by the same project origin. Paths resolve from the Node `root` or the Vite project root, never from the importing module, page URL, or cache directory. The Vite plugin resolves served URLs to source paths; Node accepts local file URLs. Keep the plugin in the production build configuration when using served URLs so deployed entries can recover the same source paths. Production mappings cover public files and emitted assets with one backing source. Use `{ path }` when an imported asset is inlined or deduplicated from several source files.
|
|
11
|
+
|
|
12
|
+
Reordering JSON object properties or dependency declarations does not change identity; array order matters. Changing a dependency name, JSON value, resolved path, or package name does. File contents and installed package versions invalidate the existing result when filesystem validation is available; installation paths do not affect identity.
|
|
13
|
+
|
|
14
|
+
Load once and compute on a miss. Reuse that entry when saving: loading captures file contents and package versions before computation, allowing saving to reject a result if those dependencies changed in the meantime. A new entry or a save without a preceding load cannot establish that relationship. Entries containing only value dependencies can save directly. If saving fails because dependencies changed, load again and recompute before retrying. Use a separate entry for each concurrent computation.
|
|
15
|
+
|
|
16
|
+
```ts
|
|
17
|
+
import { CacheEntry } from "vitecache"
|
|
18
|
+
import modelUrl from "./models/chair.glb?url"
|
|
19
|
+
|
|
20
|
+
const entry = new CacheEntry({
|
|
21
|
+
version: "simplify@2",
|
|
22
|
+
dependencies: {
|
|
23
|
+
settings: { value: { ratio: 0.5, preserveUVs: true } },
|
|
24
|
+
algorithm: { path: "src/simplify.ts" },
|
|
25
|
+
model: { url: modelUrl },
|
|
26
|
+
},
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
let bytes = await entry.load()
|
|
30
|
+
|
|
31
|
+
if (bytes === undefined) {
|
|
32
|
+
bytes = encodeMesh(await simplify())
|
|
33
|
+
await entry.save(bytes)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const mesh = decodeMesh(bytes)
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Use the Vite plugin when browser computation should produce reusable project files:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
import { defineConfig } from "vite"
|
|
43
|
+
import { vitecache } from "vitecache/vite"
|
|
44
|
+
|
|
45
|
+
export default defineConfig({ plugins: [vitecache()] })
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Generate caches during development or from Node before building when deployed users should download precomputed results. Include the generated public files in the build or deployment even when Git ignores them. The plugin writes files during development; it does not supply a production write server. Browsers without the plugin assume files and package versions unchanged, so regenerate affected caches before deployment. Calling `save()` there warns and skips persistence.
|
|
49
|
+
|
|
50
|
+
For custom locations, coordinate the filesystem destination with the URL used by browser callers. A filesystem path and a browser URL are different values. When deploying below a URL prefix, include that prefix in the browser cache path; the client does not infer Vite's base URL. Node jobs should select the same project root as the Vite app when launched from a different working directory.
|