@yaks/esbuild 0.0.0-stage → 0.2.36

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.
Files changed (123) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +450 -2
  3. package/_dist/bundle.d.ts +6 -0
  4. package/_dist/bundle.d.ts.map +1 -0
  5. package/_dist/compile.d.ts +72 -0
  6. package/_dist/compile.d.ts.map +1 -0
  7. package/_dist/dependencies.d.ts +15 -0
  8. package/_dist/dependencies.d.ts.map +1 -0
  9. package/_dist/file.d.ts +185 -0
  10. package/_dist/file.d.ts.map +1 -0
  11. package/_dist/graph.d.ts +104 -0
  12. package/_dist/graph.d.ts.map +1 -0
  13. package/_dist/home.d.ts +15 -0
  14. package/_dist/home.d.ts.map +1 -0
  15. package/_dist/link.d.ts +192 -0
  16. package/_dist/link.d.ts.map +1 -0
  17. package/_dist/lock.d.ts +30 -0
  18. package/_dist/lock.d.ts.map +1 -0
  19. package/_dist/mod.d.ts +6 -0
  20. package/_dist/mod.d.ts.map +1 -0
  21. package/_dist/pack.d.ts +42 -0
  22. package/_dist/pack.d.ts.map +1 -0
  23. package/_dist/package.d.ts +11 -0
  24. package/_dist/package.d.ts.map +1 -0
  25. package/_dist/plan.d.ts +135 -0
  26. package/_dist/plan.d.ts.map +1 -0
  27. package/_dist/platform.d.ts +27 -0
  28. package/_dist/platform.d.ts.map +1 -0
  29. package/_dist/resolve.d.ts +42 -0
  30. package/_dist/resolve.d.ts.map +1 -0
  31. package/_dist/shelf.d.ts +11 -0
  32. package/_dist/shelf.d.ts.map +1 -0
  33. package/_dist/strip.d.ts +51 -0
  34. package/_dist/strip.d.ts.map +1 -0
  35. package/_dist/timing.d.ts +6 -0
  36. package/_dist/timing.d.ts.map +1 -0
  37. package/_dist/unpack.d.ts +14 -0
  38. package/_dist/unpack.d.ts.map +1 -0
  39. package/analysis.js +72 -0
  40. package/analysis.js.map +1 -0
  41. package/analysis.ts +82 -0
  42. package/bundle.js +320 -0
  43. package/bundle.js.map +1 -0
  44. package/bundle.ts +415 -0
  45. package/common.js +129 -0
  46. package/common.js.map +1 -0
  47. package/common.ts +138 -0
  48. package/compile.js +500 -0
  49. package/compile.js.map +1 -0
  50. package/compile.ts +622 -0
  51. package/container.js +142 -0
  52. package/container.js.map +1 -0
  53. package/container.ts +183 -0
  54. package/deno.json +1 -0
  55. package/dependencies.js +31 -0
  56. package/dependencies.js.map +1 -0
  57. package/dependencies.ts +40 -0
  58. package/file.js +303 -0
  59. package/file.js.map +1 -0
  60. package/file.ts +443 -0
  61. package/forward.ts +49 -0
  62. package/graph.js +297 -0
  63. package/graph.js.map +1 -0
  64. package/graph.ts +360 -0
  65. package/home.js +40 -0
  66. package/home.js.map +1 -0
  67. package/home.ts +52 -0
  68. package/link.js +455 -0
  69. package/link.js.map +1 -0
  70. package/link.ts +596 -0
  71. package/lock.js +129 -0
  72. package/lock.js.map +1 -0
  73. package/lock.ts +161 -0
  74. package/mod.js +14 -0
  75. package/mod.js.map +1 -0
  76. package/mod.ts +43 -0
  77. package/npm.js +362 -0
  78. package/npm.js.map +1 -0
  79. package/npm.ts +429 -0
  80. package/pack.js +188 -0
  81. package/pack.js.map +1 -0
  82. package/pack.ts +225 -0
  83. package/package.js +199 -0
  84. package/package.js.map +1 -0
  85. package/package.json +60 -4
  86. package/package.ts +255 -0
  87. package/plan.js +273 -0
  88. package/plan.js.map +1 -0
  89. package/plan.ts +395 -0
  90. package/platform.js +160 -0
  91. package/platform.js.map +1 -0
  92. package/platform.ts +238 -0
  93. package/resolve.js +86 -0
  94. package/resolve.js.map +1 -0
  95. package/resolve.ts +144 -0
  96. package/said.js +44 -0
  97. package/said.js.map +1 -0
  98. package/said.ts +61 -0
  99. package/serve.ts +37 -0
  100. package/sha256.js +7 -0
  101. package/sha256.js.map +1 -0
  102. package/sha256.ts +10 -0
  103. package/shared.js +646 -0
  104. package/shared.js.map +1 -0
  105. package/shared.ts +813 -0
  106. package/shelf.js +73 -0
  107. package/shelf.js.map +1 -0
  108. package/shelf.ts +110 -0
  109. package/strip.js +114 -0
  110. package/strip.js.map +1 -0
  111. package/strip.ts +117 -0
  112. package/tar.js +87 -0
  113. package/tar.js.map +1 -0
  114. package/tar.ts +99 -0
  115. package/timing.js +37 -0
  116. package/timing.js.map +1 -0
  117. package/timing.ts +71 -0
  118. package/unpack.js +40 -0
  119. package/unpack.js.map +1 -0
  120. package/unpack.ts +60 -0
  121. package/used.js +91 -0
  122. package/used.js.map +1 -0
  123. package/used.ts +116 -0
@@ -0,0 +1,30 @@
1
+ /** Package name to exact version. */ export type Pins = Record<string, string>;
2
+ /** The npm versions a package-lock.json pins; toolkit provenance is not an
3
+ * installer input, including legacy @yaks registry versions.
4
+ *
5
+ * ```ts
6
+ * import { assertEquals } from '@std/assert'
7
+ * assertEquals(pins(JSON.stringify({ lockfileVersion: 3, packages: {
8
+ * '': { dependencies: { three: '^0.180.0' } },
9
+ * 'node_modules/three': { version: '0.180.1' },
10
+ * 'node_modules/a/node_modules/b': { version: '2.0.0' },
11
+ * } })), { three: '0.180.1' })
12
+ * ```
13
+ */ export declare let pins: (text: string | null) => Pins;
14
+ /** What to install: every pinned version, and each declared range the pins
15
+ * do not satisfy.
16
+ *
17
+ * ```ts
18
+ * import { assertEquals } from '@std/assert'
19
+ * assertEquals(
20
+ * wanted({ three: '^0.180.0', hono: '^4' }, { three: '0.180.1', tslib: '2.8.1' }),
21
+ * { three: '0.180.1', tslib: '2.8.1', hono: '^4' },
22
+ * )
23
+ * assertEquals(wanted({ three: '^0.181.0' }, { three: '0.180.1' }), {
24
+ * three: '^0.181.0',
25
+ * })
26
+ * ```
27
+ */ export declare let wanted: (ranges: Record<string, string>, pinned: Pins) => Pins;
28
+ /** A package-lock.json holding these versions under these declared ranges,
29
+ * named as package.json names the app, if it does. */ export declare let lockfile: (name: string | undefined, ranges: Record<string, string>, versions: Pins) => string;
30
+ //# sourceMappingURL=lock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.d.ts","sources":["../lock.ts"],"names":[],"mappings":"AAcA,mCAAmC,GACnC,YAAY,OAAO,OAAO,MAAM,EAAE,MAAM;AAIxC;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,OAAQ,MAAM,MAAM,GAAG,IAAI,KAAG,KAkBxC;AAED;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,SAAU,QAAQ,OAAO,MAAM,EAAE,MAAM,GAAG,QAAQ,SAAO,KAgBnE;AAuCD;oDACoD,GACpD,OAAO,YAAI,WACT,MAAM,MAAM,GAAG,SAAS,EACxB,QAAQ,OAAO,MAAM,EAAE,MAAM,GAC7B,UAAU,SACT,MAAM,CAsBC"}
package/_dist/mod.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ export { modules, packageOf, type Reached, type Read, relative, resolved, script, sources, specifiers, started, startsIn, type Strip, twins, typed, type Walk } from "./graph.js";
2
+ export { type Answer, type App, type Ask, COMPILER, dependencies, loaded, mapped, type Plan, plan, toolkitOf, type Toolkits, toolkits, Unplanned } from "./plan.js";
3
+ export { homeOf, REGISTRY, type Tarball } from "./home.js";
4
+ export { lockfile, type Pins, pins, wanted } from "./lock.js";
5
+ export { type Catalog, seed } from "./platform.js";
6
+ //# sourceMappingURL=mod.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mod.d.ts","sources":["../mod.ts"],"names":[],"mappings":"AAQA,SACE,OAAO,EACP,SAAS,EACT,KAAK,OAAO,EACZ,KAAK,IAAI,EACT,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,OAAO,EACP,UAAU,EACV,OAAO,EACP,QAAQ,EACR,KAAK,KAAK,EACV,KAAK,EACL,KAAK,EACL,KAAK,IAAI,qBACQ;AACnB,SACE,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,GAAG,EACR,QAAQ,EACR,YAAY,EACZ,MAAM,EACN,MAAM,EACN,KAAK,IAAI,EACT,IAAI,EACJ,SAAS,EACT,KAAK,QAAQ,EACb,QAAQ,EACR,SAAS,oBACO;AAClB,SAAS,MAAM,EAAE,QAAQ,EAAE,KAAK,OAAO,oBAAmB;AAC1D,SAAS,QAAQ,EAAE,KAAK,IAAI,EAAE,IAAI,EAAE,MAAM,oBAAmB;AAC7D,SAAS,KAAK,OAAO,EAAE,IAAI,wBAAuB"}
@@ -0,0 +1,42 @@
1
+ /** What a host posts to have a page's modules packed: its roots, each a
2
+ * script's path from the app's root, and every module of the app by path,
3
+ * compiled. */ export type PackJob = {
4
+ pack: {
5
+ roots: string[];
6
+ modules: Record<string, string>;
7
+ packages?: Record<string, string>;
8
+ imports?: Record<string, string>;
9
+ };
10
+ };
11
+ /** A pack: the file each root became, each file's text, and what each
12
+ * imports statically, another of its files by `./<file>` or a bare
13
+ * specifier, which a page preloads. */ export type Packed = {
14
+ entries: Record<string, string>;
15
+ files: Record<string, string>;
16
+ links: Record<string, string[]>;
17
+ };
18
+ /** Modules a pack would not load as they load alone. */ export declare class Unpackable extends Error {
19
+ name: string;
20
+ }
21
+ /** The modules `roots` reach, packed: one file a root, and chunks the roots
22
+ * share. Throws {@link Unpackable} for modules that would not load packed
23
+ * as they load alone or that esbuild refuses, and for a root no module is;
24
+ * `Stopped` when esbuild's process ended under it.
25
+ *
26
+ * ```ts
27
+ * import { assertEquals } from '@std/assert'
28
+ * let { entries, files, links } = await packModules({
29
+ * roots: ['main.ts'],
30
+ * modules: {
31
+ * 'main.ts': "import { n } from './lib/n.ts'\n" +
32
+ * "import { h } from 'preact'\nexport let x = h(n)",
33
+ * 'lib/n.ts': 'export let n = new URL("./a.png", import.meta.url).href',
34
+ * },
35
+ * })
36
+ * let main = files[entries['main.ts']]
37
+ * assertEquals(/from\s*['"]preact['"]/.test(main), true)
38
+ * assertEquals(main.includes('"./lib/n.ts"'), true)
39
+ * assertEquals(links[entries['main.ts']], ['preact'])
40
+ * ```
41
+ */ export declare let packModules: ({}: PackJob['pack']) => Promise<Packed>;
42
+ //# sourceMappingURL=pack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack.d.ts","sources":["../pack.ts"],"names":[],"mappings":"AAwBA;;aAEa,GACb,YAAY;EACV;IACE,OAAO,MAAM;IACb,SAAS,OAAO,MAAM,EAAE,MAAM;IAC9B,WAAW,OAAO,MAAM,EAAE,MAAM;IAChC,UAAU,OAAO,MAAM,EAAE,MAAM;;;AAInC;;qCAEqC,GACrC,YAAY;EACV,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B,OAAO,OAAO,MAAM,EAAE,MAAM;;AAG9B,sDAAsD,GACtD,OAAO,cAAM,mBAAmB;EACrB,aAAmB;AAC9B;AA+GA;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,YAAI,cACT,IAAiD,QAAQ,OAAO,KAC/D,QAAQ,QA0CV"}
@@ -0,0 +1,11 @@
1
+ /** A compiled package: each export entry's specifier and the module it is,
2
+ * every module by its file name (`<name>.js`, kept and served as is), the
3
+ * bare specifiers its modules import, which a page's map resolves, and what
4
+ * each module imports statically (`links`): the package's other modules by
5
+ * file name (`./<name>.js`), and bare specifiers, which a page preloads. */ export type Compiled = {
6
+ entries: Record<string, string>;
7
+ modules: Record<string, string>;
8
+ imports: string[];
9
+ links: Record<string, string[]>;
10
+ };
11
+ //# sourceMappingURL=package.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"package.d.ts","sources":["../package.ts"],"names":[],"mappings":"AA2BA;;;;0EAI0E,GAC1E,YAAY;EACV,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B,SAAS,MAAM;EACf,OAAO,OAAO,MAAM,EAAE,MAAM"}
@@ -0,0 +1,135 @@
1
+ import type { Catalog } from "./platform.js";
2
+ import type { Timing } from "./timing.js";
3
+ import { type Read, type Strip } from "./graph.js";
4
+ import { dependencies, Unplanned } from "./dependencies.js";
5
+ export { dependencies, Unplanned };
6
+ /** An app's files, as the host holds them. */ export type App = {
7
+ /** Every file the app wrote, by its path from the app's root. */ paths: string[];
8
+ read: Read;
9
+ /** The server source, when the app has one. */ main?: string;
10
+ /** Compile just this server entry, including one with no imports. */ entryOnly?: boolean;
11
+ /** Its compatibility flags (`nodejs_compat` changes how it compiles). */ flags?: string[];
12
+ /** The folder its pages are served from, when not its root (a build's
13
+ * `dist`): only HTML inside it is a page whose scripts are compiled. */ served?: string;
14
+ /** How its TypeScript and JSX are read as JavaScript (`./strip`), asked
15
+ * only of an app that has some. */ strip: Strip;
16
+ };
17
+ /** What the compiler is handed: the text of every file a build reads, and
18
+ * which entries to build. */ export type Ask = {
19
+ files: Record<string, string>;
20
+ worker?: {
21
+ entry: string;
22
+ flags: string[];
23
+ /** What it imports that is not compiled in (a `.wasm`, a `.txt`): the
24
+ * host uploads each beside the compiled module, by its own path. */ carry: string[];
25
+ };
26
+ /** The page scripts to compile, and the module workers they start. */ pages: string[];
27
+ /** The pages one HTML page loads together, where it loads two or more:
28
+ * they share one pack of shared modules (./shared.ts `pack`). */ together?: string[][];
29
+ /** The package imports of each page script that package.json does not
30
+ * name and the import map of every page loading it resolves: the
31
+ * browser's to load, left as written. */ mapped?: Record<string, string[]>;
32
+ };
33
+ /** What the compiler answers. Any `errors` mean nothing it made may be used;
34
+ * each is a line an agent can act on. */ export type Answer = {
35
+ /** Compiler wall-clock milliseconds, when timing was requested. */ timing?: Timing;
36
+ /** The compiled worker: one ES module, uploaded under `main`. */ worker?: {
37
+ main: string;
38
+ code: string;
39
+ };
40
+ /** Each compiled page script, by the entry's own path. */ pages: Record<string, string>;
41
+ /** Runtime package resources, under a reserved package-relative namespace. */ assets: Record<string, string>;
42
+ /** Content-addressed browser modules and resources, shared across apps. */ shared?: Record<string, string>;
43
+ /** The registry tarball that fills each npm package home the compiled code
44
+ * names, by the SHA-256 that names the home (./home.ts). */ tarballs?: Record<string, string>;
45
+ /** package-lock.json as the build left it, when the app has a package.json. */ lock?: string;
46
+ /** What the lock holds, as `name@version`. */ installed: string[];
47
+ notes: string[];
48
+ errors: string[];
49
+ };
50
+ /** The plan: what to ask, what to say, and each entry's own source paths. */ export type Plan = {
51
+ ask: Ask;
52
+ notes: string[];
53
+ inputs: {
54
+ worker?: string[];
55
+ pages: Record<string, string[]>;
56
+ };
57
+ /** Every existing source read to decide this plan, including plain JS. */ reads: string[];
58
+ };
59
+ /** Each toolkit package of a catalog: its source digest, and the toolkit
60
+ * packages it depends on. A host keeps this beside the catalog, small enough
61
+ * to read wherever it asks whether a compile's toolkit is still current. */ export type Toolkits = Record<string, {
62
+ version: string;
63
+ uses: string[];
64
+ }>;
65
+ /** A catalog's {@link Toolkits}.
66
+ *
67
+ * ```ts
68
+ * import { assertEquals } from '@std/assert'
69
+ * assertEquals(
70
+ * toolkits({
71
+ * '@yaks/a': {
72
+ * files: {},
73
+ * dependencies: { '@yaks/b': 'platform', preact: '10.29.7' },
74
+ * version: 'sha256:a',
75
+ * },
76
+ * }),
77
+ * { '@yaks/a': { version: 'sha256:a', uses: ['@yaks/b'] } },
78
+ * )
79
+ * ```
80
+ */ export declare let toolkits: (catalog: Catalog) => Toolkits;
81
+ /** The compiler's own entry among the toolkit's digests, where a host keeps
82
+ * one: the source of this package, which makes what pages compile to, as a
83
+ * toolkit package's source makes what they import. */ export declare let COMPILER: string;
84
+ /** The source digest of each toolkit package a package.json reaches, through
85
+ * the toolkit's own dependencies, as a compile seeds them, and of the
86
+ * compiler: what that compile was made of. A package the toolkit does not
87
+ * have is left out.
88
+ *
89
+ * ```ts
90
+ * import { assertEquals } from '@std/assert'
91
+ * let kit = {
92
+ * '@yaks/a': { version: 'sha256:a', uses: ['@yaks/b'] },
93
+ * '@yaks/b': { version: 'sha256:b', uses: [] },
94
+ * '@yaks/c': { version: 'sha256:c', uses: [] },
95
+ * }
96
+ * let pkg = '{"dependencies": {"@yaks/a": "platform", "three": "1"}}'
97
+ * assertEquals(toolkitOf(pkg, kit), {
98
+ * '@yaks/a': 'sha256:a',
99
+ * '@yaks/b': 'sha256:b',
100
+ * })
101
+ * assertEquals(toolkitOf(null, kit), {})
102
+ * assertEquals(
103
+ * toolkitOf(null, { '@yaks/esbuild': { version: 'sha256:e', uses: [] } }),
104
+ * { '@yaks/esbuild': 'sha256:e' },
105
+ * )
106
+ * ```
107
+ */ export declare let toolkitOf: (pkg: string | null, kit: Toolkits) => Record<string, string>;
108
+ /** The module scripts an HTML file loads from the app's own files, by path.
109
+ *
110
+ * ```ts
111
+ * import { assertEquals } from '@std/assert'
112
+ * assertEquals(
113
+ * loaded('games/index.html', `<script type="module" src="./main.ts?v=2">` +
114
+ * `</script><script src="old.js"></script>` +
115
+ * `<script type=module src="https://esm.sh/x"></script>`),
116
+ * ['games/main.ts'],
117
+ * )
118
+ * ```
119
+ */ export declare let loaded: (page: string, html: string) => string[];
120
+ /** What an HTML file's import maps name: every key of their `imports`.
121
+ *
122
+ * ```ts
123
+ * import { assertEquals } from '@std/assert'
124
+ * assertEquals(
125
+ * mapped(`<script type=importmap>{"imports": {"three": "https://esm.sh/` +
126
+ * `three", "lit/": "https://esm.sh/lit/"}}</script>`),
127
+ * ['three', 'lit/'],
128
+ * )
129
+ * ```
130
+ */ export declare let mapped: (html: string) => string[];
131
+ /**
132
+ * What a deploy of this app compiles, or null when nothing needs compiling.
133
+ * Throws {@link Unplanned} when package.json cannot be read.
134
+ */ export declare let plan: (app: App) => Promise<Plan | null>;
135
+ //# sourceMappingURL=plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plan.d.ts","sources":["../plan.ts"],"names":[],"mappings":"AAgBA,cAAc,OAAO,wBAAuB;AAC5C,cAAc,MAAM,sBAAqB;AACzC,SAGE,KAAK,IAAI,EAIT,KAAK,KAAK,qBAEO;AACnB,SAAS,YAAY,EAAE,SAAS,4BAA2B;AAE3D,SAAS,YAAY,EAAE,SAAS,GAAE;AAElC,4CAA4C,GAC5C,YAAY;EACV,+DAA+D,GAC/D,OAAO,MAAM;EACb,MAAM;EACN,6CAA6C,GAC7C,OAAO,MAAM;EACb,mEAAmE,GACnE,YAAY,OAAO;EACnB,uEAAuE,GACvE,QAAQ,MAAM;EACd;wEACsE,GACtE,SAAS,MAAM;EACf;mCACiC,GACjC,OAAO;;AAGT;2BAC2B,GAC3B,YAAY;EACV,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B;IACE,OAAO,MAAM;IACb,OAAO,MAAM;IACb;sEACkE,GAClE,OAAO,MAAM;;EAEf,oEAAoE,GACpE,OAAO,MAAM;EACb;iEAC+D,GAC/D,WAAW,MAAM;EACjB;;yCAEuC,GACvC,SAAS,OAAO,MAAM,EAAE,MAAM;;AAGhC;uCACuC,GACvC,YAAY;EACV,iEAAiE,GACjE,SAAS;EACT,+DAA+D,GAC/D;IAAW,MAAM,MAAM;IAAE,MAAM,MAAM;;EACrC,wDAAwD,GACxD,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B,4EAA4E,GAC5E,QAAQ,OAAO,MAAM,EAAE,MAAM;EAC7B,yEAAyE,GACzE,SAAS,OAAO,MAAM,EAAE,MAAM;EAC9B;4DAC0D,GAC1D,WAAW,OAAO,MAAM,EAAE,MAAM;EAChC,6EAA6E,GAC7E,OAAO,MAAM;EACb,4CAA4C,GAC5C,WAAW,MAAM;EACjB,OAAO,MAAM;EACb,QAAQ,MAAM;;AAGhB,2EAA2E,GAC3E,YAAY;EACV,KAAK;EACL,OAAO,MAAM;EACb;IAAU,SAAS,MAAM;IAAI,OAAO,OAAO,MAAM,EAAE,MAAM;;EACzD,wEAAwE,GACxE,OAAO,MAAM;;AASf;;0EAE0E,GAC1E,YAAY,WAAW,OAAO,MAAM;EAAI,SAAS,MAAM;EAAE,MAAM,MAAM;;AAErE;;;;;;;;;;;;;;;CAeC,GACD,OAAO,YAAI,WAAY,SAAS,YAAU,SAQvC;AAEH;;oDAEoD,GACpD,OAAO,YAAI,UAAU,MAAM,CAAkB;AAE7C;;;;;;;;;;;;;;;;;;;;;;;CAuBC,GACD,OAAO,YAAI,YACT,KAAK,MAAM,GAAG,IAAI,EAClB,KAAK,aACJ,OAAO,MAAM,EAAE,MAAM,EAWvB;AAMD;;;;;;;;;;;CAWC,GACD,OAAO,YAAI,SAAU,MAAM,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,GAQiB;AAgBzE;;;;;;;;;;CAUC,GACD,OAAO,YAAI,SAAU,MAAM,MAAM,KAAG,MAAM,GACiB;AAO3D;;;CAGC,GACD,OAAO,YAAI,OAAc,KAAK,QAAM,QAAQ,OAAO,IAAI,EA+ItD"}
@@ -0,0 +1,27 @@
1
+ /** A compiler's toolkit package: paths relative to its package root, including
2
+ * package.json, normalized source imports, runtime dependencies and source SHA. */ export type Toolkit = {
3
+ files: Record<string, string>;
4
+ dependencies: Record<string, string>;
5
+ /** Runtime text files, relative to the package root. */ resources?: Record<string, string>;
6
+ renderer?: Renderer;
7
+ version: string;
8
+ };
9
+ /** The import aliases a renderer supplies to apps that select it. */ export type Renderer = {
10
+ dependency: string;
11
+ unless?: string;
12
+ aliases: Record<string, string>;
13
+ };
14
+ /** Supplied by the compiler's wrapper, never by an app. */ export type Catalog = Record<string, Toolkit>;
15
+ export type Seed = {
16
+ assets: Record<string, string>;
17
+ files: Record<string, string>;
18
+ /** npm roots, including toolkit externals whose transitives the installer
19
+ * would otherwise skip when it finds a preseeded toolkit package. */ dependencies: Record<string, string>;
20
+ /** Toolkit package to the exact source digest used by this compiler. */ platform: Record<string, string>;
21
+ /** What the app should know about how its asks were met. */ notes: string[];
22
+ aliases?: Readonly<Record<string, string>>;
23
+ jsxImportSource?: string;
24
+ };
25
+ /** Seed declared platform packages and their dependency closure without I/O.
26
+ * @yaks packages must use "platform"; none is fetched from a registry. */ export declare let seed: (files: Record<string, string>, catalog: Catalog) => Seed;
27
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sources":["../platform.ts"],"names":[],"mappings":"AASA;iFACiF,GACjF,YAAY;EACV,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B,cAAc,OAAO,MAAM,EAAE,MAAM;EACnC,sDAAsD,GACtD,YAAY,OAAO,MAAM,EAAE,MAAM;EACjC,WAAW;EACX,SAAS,MAAM;;AAGjB,mEAAmE,GACnE,YAAY;EACV,YAAY,MAAM;EAClB,SAAS,MAAM;EACf,SAAS,OAAO,MAAM,EAAE,MAAM;;AAGhC,yDAAyD,GACzD,YAAY,UAAU,OAAO,MAAM,EAAE;AAErC,YAAY;EACV,QAAQ,OAAO,MAAM,EAAE,MAAM;EAC7B,OAAO,OAAO,MAAM,EAAE,MAAM;EAC5B;qEACmE,GACnE,cAAc,OAAO,MAAM,EAAE,MAAM;EACnC,sEAAsE,GACtE,UAAU,OAAO,MAAM,EAAE,MAAM;EAC/B,0DAA0D,GAC1D,OAAO,MAAM;EACb,UAAU,SAAS,OAAO,MAAM,EAAE,MAAM;EACxC,kBAAkB,MAAM;;AAiH1B;wEACwE,GACxE,OAAO,YAAI,OAAQ,OAAO,OAAO,MAAM,EAAE,MAAM,GAAG,SAAS,YAAU,KAiFpE"}
@@ -0,0 +1,42 @@
1
+ export declare let WAIT: number;
2
+ export type Version = {
3
+ dependencies?: Record<string, string>;
4
+ dist?: {
5
+ tarball?: string;
6
+ };
7
+ };
8
+ export type Metadata = {
9
+ 'dist-tags': Record<string, string>;
10
+ versions: Record<string, Version>;
11
+ };
12
+ /** The version a range asks for, as npm reads it: a tag, an exact version or
13
+ * the newest the range allows. */ export declare let resolve: (range: string, meta: Metadata) => string | undefined;
14
+ /** A package's document at the registry. */ export declare let documentAt: (registry: string, name: string) => string;
15
+ /** `url`'s answer read by `read`, or a line saying the registry did not
16
+ * answer within `WAIT`. */ export declare let asked: <T>(get: typeof fetch, url: string, read: (response: Response) => Promise<T>, init?: RequestInit) => Promise<T>;
17
+ /** The registry's document for `name`, its abbreviated form. */ export declare let metadata: (ask: <T>(url: string, read: (response: Response) => Promise<T>, init?: RequestInit) => Promise<T>, url: string, name: string) => Promise<Metadata>;
18
+ /** The version of each package `want` names (name to range) and of each it
19
+ * needs, one of each name, as ./npm.ts `install` chooses them, asking the
20
+ * registry for documents and never a tarball. `warnings` names each package
21
+ * no version of satisfies its range, or that could not be read.
22
+ *
23
+ * ```ts
24
+ * import { assertEquals } from '@std/assert'
25
+ * let docs: Record<string, unknown> = {
26
+ * a: { 'dist-tags': { latest: '1.2.0' }, versions: {
27
+ * '1.1.0': {}, '1.2.0': { dependencies: { b: '^2.0.0' } },
28
+ * } },
29
+ * b: { 'dist-tags': { latest: '3.0.0' }, versions: { '2.1.0': {}, '3.0.0': {} } },
30
+ * }
31
+ * let get = (url: string | URL | Request) =>
32
+ * Promise.resolve(Response.json(docs[String(url).split('/').pop()!]))
33
+ * assertEquals(
34
+ * await resolved({ a: '^1.0.0' }, get as typeof fetch, 'https://r.test'),
35
+ * { pins: { a: '1.2.0', b: '2.1.0' }, warnings: [] },
36
+ * )
37
+ * ```
38
+ */ export declare let resolved: (want: Record<string, string>, get?: typeof fetch, registry?: string) => Promise<{
39
+ pins: Record<string, string>;
40
+ warnings: string[];
41
+ }>;
42
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sources":["../resolve.ts"],"names":[],"mappings":"AASA,OAAO,YAAI,aAAa;AAExB,YAAY;EACV,eAAe,OAAO,MAAM,EAAE,MAAM;EACpC;IAAS,UAAU,MAAM;;;AAE3B,YAAY;EACV,aAAa,OAAO,MAAM,EAAE,MAAM;EAClC,UAAU,OAAO,MAAM,EAAE;;AAG3B;gCACgC,GAChC,OAAO,YAAI,UAAW,OAAO,MAAM,EAAE,MAAM,aAAW,MAAM,GAAG,SAAS,CAML;AAEnE,0CAA0C,GAC1C,OAAO,YAAI,aAAc,UAAU,MAAM,EAAE,MAAM,MAAM,KAAG,MAAM,CAG5D;AAEJ;yBACyB,GACzB,OAAO,YAAI,QAAe,GACxB,YAAY,OACZ,KAAK,MAAM,EACX,OAAO,UAAU,aAAa,QAAQ,IACtC,OAAM,gBACL,QAAQ,GASV;AAED,8DAA8D,GAC9D,OAAO,YAAI,WACT,MAAM,GACJ,KAAK,MAAM,EACX,OAAO,UAAU,aAAa,QAAQ,IACtC,OAAO,gBACJ,QAAQ,IACb,KAAK,MAAM,EACX,MAAM,MAAM,KACX,QAAQ,UAeP;AAEJ;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,YAAI,WACT,MAAM,OAAO,MAAM,EAAE,MAAM,GAC3B,aAAY,OACZ,WAAU,MAAM,KACf;EAAU,MAAM,OAAO,MAAM,EAAE,MAAM;EAAG,UAAU,MAAM;GAsC1D"}
@@ -0,0 +1,11 @@
1
+ /** Bytes by key, kept beyond one container. A shelf out of reach is empty. */ export type Shelf = {
2
+ take(key: string): Promise<Uint8Array<ArrayBuffer> | null>;
3
+ /** Kept in the background: a compile never waits on it. */ put(key: string, bytes: Uint8Array<ArrayBuffer>): void;
4
+ };
5
+ /** The compiler's two shelves: `packages`, registry releases, which never
6
+ * change, kept across compiler releases; `builds`, what this compiler made,
7
+ * which another compiler might make differently. */ export type Shelves = {
8
+ packages: Shelf;
9
+ builds: Shelf;
10
+ };
11
+ //# sourceMappingURL=shelf.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shelf.d.ts","sources":["../shelf.ts"],"names":[],"mappings":"AAUA,4EAA4E,GAC5E,YAAY;EACV,KAAK,KAAK,MAAM,GAAG,QAAQ,WAAW,eAAe,IAAI;EACzD,yDAAyD,GACzD,IAAI,KAAK,MAAM,EAAE,OAAO,WAAW,eAAe,IAAI;;AAGxD;;kDAEkD,GAClD,YAAY;EAAY,UAAU;EAAO,QAAQ"}
@@ -0,0 +1,51 @@
1
+ import { type FileOptions } from "./file.js";
2
+ import type { Strip } from "./graph.js";
3
+ /** A module's imports of files no browser loads as written, as a bundle read
4
+ * them: JSON imported with no attributes takes `type: 'json'`, and a
5
+ * stylesheet imported for itself is left out, for the page to link.
6
+ *
7
+ * ```ts
8
+ * import { assertEquals } from '@std/assert'
9
+ * assertEquals(
10
+ * attributed("import d from './d.json'\nimport './a.css'\n" +
11
+ * "import e from './e.json' with { type: 'json' }\nimport 'x'"),
12
+ * "import d from './d.json' with { type: 'json' }\n\n" +
13
+ * "import e from './e.json' with { type: 'json' }\nimport 'x'",
14
+ * )
15
+ * ```
16
+ */ export declare let attributed: (code: string) => string;
17
+ /** A module as a browser runs it: every import kept as written (only
18
+ * `import type` and its kin go, and as `attributed` reads them), every line where
19
+ * it was, and no syntax the runtime runs rewritten. JSX is automatic from
20
+ * `jsxImportSource` where one is given. Throws a SyntaxError where the
21
+ * source does not parse.
22
+ *
23
+ * ```ts
24
+ * import { assertEquals } from '@std/assert'
25
+ * assertEquals(
26
+ * compiled('a.tsx', "import type { T } from 't'\nlet n: T = <b />", {
27
+ * jsxImportSource: 'preact',
28
+ * }),
29
+ * 'import {jsx as _jsx} from "preact/jsx-runtime";\n' +
30
+ * "let n = _jsx('b', {} )",
31
+ * )
32
+ * ```
33
+ */ export declare let compiled: (path: string, source: string, options?: FileOptions) => string;
34
+ /** A module's source as JavaScript, by what its path says it is, its JSX
35
+ * classic and its imports as written, for the walk, which reads only its
36
+ * imports.
37
+ *
38
+ * ```ts
39
+ * import { assertEquals, assertThrows } from '@std/assert'
40
+ * assertEquals(
41
+ * strip('a.tsx', "import type { T } from 't'\nimport u from 'u'\n" +
42
+ * 'let n: number = a?.b ?? 1\nlet b = <b />'),
43
+ * "\nimport u from 'u'\nlet n = a?.b ?? 1\n" +
44
+ * "let b = React.createElement('b', null )",
45
+ * )
46
+ * assertEquals(strip('a.js', 'let n: = 1'), 'let n: = 1')
47
+ * assertEquals(strip('a.ts', "import './a.css'"), "import './a.css'")
48
+ * assertThrows(() => strip('a.ts', 'let n: = 1'), SyntaxError)
49
+ * ```
50
+ */ export declare let strip: Strip;
51
+ //# sourceMappingURL=strip.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strip.d.ts","sources":["../strip.ts"],"names":[],"mappings":"AAQA,SAAS,KAAK,WAAW,oBAA2B;AACpD,cAAc,KAAK,qBAAoB;AAevC;;;;;;;;;;;;;CAaC,GACD,OAAO,YAAI,aAAc,MAAM,MAAM,KAAG,MAAM,CAiB7C;AAED;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,WACT,MAAM,MAAM,EACZ,QAAQ,MAAM,EACd,UAAS,gBACR,MAAM,CAA+C;AAqBxD;;;;;;;;;;;;;;;;CAgBC,GACD,OAAO,YAAI,OAAO,MAAgD"}
@@ -0,0 +1,6 @@
1
+ export type Phase = 'install' | 'registry' | 'shelf' | 'worker' | 'carried' | 'used' | 'groups' | 'cache' | 'pages' | 'total';
2
+ export type Timing = Record<Phase, number> & {
3
+ /** Shared-group cache lookups, counted rather than milliseconds. */ hits: number;
4
+ misses: number;
5
+ };
6
+ //# sourceMappingURL=timing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"timing.d.ts","sources":["../timing.ts"],"names":[],"mappings":"AAGA,YAAY,QACR,YACA,aACA,UACA,WACA,YACA,SACA,WACA,UACA,UACA;AACJ,YAAY,SAAS,OAAO,OAAO,MAAM;EACvC,kEAAkE,GAClE,MAAM,MAAM;EACZ,QAAQ,MAAM"}
@@ -0,0 +1,14 @@
1
+ /** What a tarball holds: its SHA-256, every file's path from the package's
2
+ * root, and the bytes of the one asked for, or null when it holds no such
3
+ * file. */ export type Unpacked = {
4
+ sha256: string;
5
+ paths: string[];
6
+ bytes: Uint8Array | null;
7
+ };
8
+ /**
9
+ * Read a gzipped npm tarball as it streams in, keeping only the file at
10
+ * `want`, a path from the package's root. The whole tarball is read, since
11
+ * its SHA-256 is what says it is the one a home names; a host checks that
12
+ * before it serves the bytes.
13
+ */ export declare let unpacked: (tgz: ReadableStream<Uint8Array<ArrayBuffer>>, want: string) => Promise<Unpacked>;
14
+ //# sourceMappingURL=unpack.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unpack.d.ts","sources":["../unpack.ts"],"names":[],"mappings":"AAQA;;SAES,GACT,YAAY;EACV,QAAQ,MAAM;EACd,OAAO,MAAM;EACb,OAAO,aAAa,IAAI;;AAG1B;;;;;CAKC,GACD,OAAO,YAAI,WACT,KAAK,eAAe,WAAW,eAC/B,MAAM,MAAM,KACX,QAAQ,UAiCV"}
package/analysis.js ADDED
@@ -0,0 +1,72 @@
1
+ // Bounded analysis results validated against every source read, including
2
+ // missing resolution targets. Source identity is deliberately not a cache key.
3
+ // A result kept on a shelf (./shelf.ts) outlives the container, and is
4
+ // validated the same way before it is used.
5
+ import { shelve, taken } from "./shelf.js";
6
+ export let analysisCache = (limit, digest)=>{
7
+ let entries = new Map();
8
+ let bytes = 0;
9
+ let remember = (key, entry)=>{
10
+ let size = JSON.stringify(entry.value).length * 2 + entry.reads.reduce((n, p)=>n + p.length * 2, 0);
11
+ if (size > limit) return;
12
+ bytes -= entries.get(key)?.bytes ?? 0;
13
+ entries.delete(key);
14
+ while(bytes + size > limit){
15
+ let oldest = entries.keys().next().value;
16
+ bytes -= entries.get(oldest).bytes;
17
+ entries.delete(oldest);
18
+ }
19
+ entries.set(key, {
20
+ ...entry,
21
+ bytes: size
22
+ });
23
+ bytes += size;
24
+ };
25
+ let cache = async (key, read, work, { shelf, looked } = {})=>{
26
+ let fingerprint = (paths)=>digest(paths.map((path)=>[
27
+ path,
28
+ read(path)
29
+ ]));
30
+ let valid = async (entry)=>Array.isArray(entry?.reads) && entry.fingerprint == await fingerprint(entry.reads);
31
+ let began = performance.now();
32
+ let held = entries.get(key);
33
+ let found = await valid(held) ? held : null;
34
+ if (found) {
35
+ entries.delete(key);
36
+ entries.set(key, held);
37
+ } else if (!held) {
38
+ // What memory held and its sources have since moved past, the shelf
39
+ // holds too: only a key memory never held is looked for there.
40
+ let kept = await taken(shelf, key);
41
+ if (await valid(kept)) remember(key, found = kept);
42
+ }
43
+ looked?.(!!found, performance.now() - began);
44
+ if (found) return found.value;
45
+ let reads = new Set();
46
+ let value = await work({
47
+ read: (path)=>{
48
+ reads.add(path);
49
+ return read(path);
50
+ }
51
+ });
52
+ // Failed work never replaces a successful entry.
53
+ let paths = [
54
+ ...reads
55
+ ].sort();
56
+ let entry = {
57
+ value,
58
+ reads: paths,
59
+ fingerprint: await fingerprint(paths)
60
+ };
61
+ remember(key, entry);
62
+ shelve(shelf, key, entry);
63
+ return value;
64
+ };
65
+ return Object.assign(cache, {
66
+ /** Forget what memory holds, as a container that restarts does. */ clear: ()=>{
67
+ entries.clear();
68
+ bytes = 0;
69
+ }
70
+ });
71
+ };
72
+ //# sourceMappingURL=analysis.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analysis.js","sources":["./analysis.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,+EAA+E;AAC/E,uEAAuE;AACvE,4CAA4C;AAC5C,SAAqB,MAAM,EAAE,KAAK,qBAAoB;AAWtD,OAAO,IAAI,gBAAgB,CACzB,OACA;EAEA,IAAI,UAAU,IAAI;EAClB,IAAI,QAAQ;EACZ,IAAI,WAAW,CAAC,KAAa;IAC3B,IAAI,OAAO,KAAK,SAAS,CAAC,MAAM,KAAK,EAAE,MAAM,GAAG,IAC9C,MAAM,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,IAAM,IAAI,EAAE,MAAM,GAAG,GAAG;IACjD,IAAI,OAAO,OAAO;IAClB,SAAS,QAAQ,GAAG,CAAC,MAAM,SAAS;IACpC,QAAQ,MAAM,CAAC;IACf,MAAO,QAAQ,OAAO,MAAO;MAC3B,IAAI,SAAS,QAAQ,IAAI,GAAG,IAAI,GAAG,KAAK;MACxC,SAAS,QAAQ,GAAG,CAAC,QAAS,KAAK;MACnC,QAAQ,MAAM,CAAC;IACjB;IACA,QAAQ,GAAG,CAAC,KAAK;MAAE,GAAG,KAAK;MAAE,OAAO;IAAK;IACzC,SAAS;EACX;EACA,IAAI,QAAQ,OACV,KACA,MACA,MACA,EAAE,KAAK,EAAE,MAAM,EAAU,GAAG,CAAC,CAAC;IAE9B,IAAI,cAAc,CAAC,QACjB,OAAO,MAAM,GAAG,CAAC,CAAC,OAAS;UAAC;UAAM,KAAK;SAAM;IAC/C,IAAI,QAAQ,OAAO,QACjB,MAAM,OAAO,CAAC,OAAO,UACrB,MAAM,WAAW,IAAI,MAAM,YAAY,MAAM,KAAK;IACpD,IAAI,QAAQ,YAAY,GAAG;IAC3B,IAAI,OAAO,QAAQ,GAAG,CAAC;IACvB,IAAI,QAAyB,MAAM,MAAM,QAAQ,OAAQ;IACzD,IAAI,OAAO;MACT,QAAQ,MAAM,CAAC;MACf,QAAQ,GAAG,CAAC,KAAK;IACnB,OAAO,IAAI,CAAC,MAAM;MAChB,oEAAoE;MACpE,+DAA+D;MAC/D,IAAI,OAAO,MAAM,MAAgB,OAAO;MACxC,IAAI,MAAM,MAAM,OAAO,SAAS,KAAK,QAAQ;IAC/C;IACA,SAAS,CAAC,CAAC,OAAO,YAAY,GAAG,KAAK;IACtC,IAAI,OAAO,OAAO,MAAM,KAAK;IAC7B,IAAI,QAAQ,IAAI;IAChB,IAAI,QAAQ,MAAM,KAAK;MACrB,MAAM,CAAC;QACL,MAAM,GAAG,CAAC;QACV,OAAO,KAAK;MACd;IACF;IACA,iDAAiD;IACjD,IAAI,QAAQ;SAAI;KAAM,CAAC,IAAI;IAC3B,IAAI,QAAQ;MAAE;MAAO,OAAO;MAAO,aAAa,MAAM,YAAY;IAAO;IACzE,SAAS,KAAK;IACd,OAAO,OAAO,KAAK;IACnB,OAAO;EACT;EACA,OAAO,OAAO,MAAM,CAAC,OAAO;IAC1B,iEAAiE,GACjE,OAAO;MACL,QAAQ,KAAK;MACb,QAAQ;IACV;EACF;AACF,EAAC"}
package/analysis.ts ADDED
@@ -0,0 +1,82 @@
1
+ // Bounded analysis results validated against every source read, including
2
+ // missing resolution targets. Source identity is deliberately not a cache key.
3
+ // A result kept on a shelf (./shelf.ts) outlives the container, and is
4
+ // validated the same way before it is used.
5
+ import { type Shelf, shelve, taken } from './shelf.js'
6
+
7
+ type Entry<T> = { value: T; reads: string[]; fingerprint: string }
8
+
9
+ /** Where a lookup goes beyond memory, and who hears whether it hit and how
10
+ * long finding out took, in ms. */
11
+ export type Lookup = {
12
+ shelf?: Shelf
13
+ looked?: (hit: boolean, ms: number) => void
14
+ }
15
+
16
+ export let analysisCache = <T>(
17
+ limit: number,
18
+ digest: (value: unknown) => Promise<string>,
19
+ ) => {
20
+ let entries = new Map<string, Entry<T> & { bytes: number }>()
21
+ let bytes = 0
22
+ let remember = (key: string, entry: Entry<T>) => {
23
+ let size = JSON.stringify(entry.value).length * 2 +
24
+ entry.reads.reduce((n, p) => n + p.length * 2, 0)
25
+ if (size > limit) return
26
+ bytes -= entries.get(key)?.bytes ?? 0
27
+ entries.delete(key)
28
+ while (bytes + size > limit) {
29
+ let oldest = entries.keys().next().value!
30
+ bytes -= entries.get(oldest)!.bytes
31
+ entries.delete(oldest)
32
+ }
33
+ entries.set(key, { ...entry, bytes: size })
34
+ bytes += size
35
+ }
36
+ let cache = async (
37
+ key: string,
38
+ read: (path: string) => string | null,
39
+ work: (source: { read: typeof read }) => Promise<T>,
40
+ { shelf, looked }: Lookup = {},
41
+ ): Promise<T> => {
42
+ let fingerprint = (paths: string[]) =>
43
+ digest(paths.map((path) => [path, read(path)]))
44
+ let valid = async (entry: Entry<T> | null | undefined) =>
45
+ Array.isArray(entry?.reads) &&
46
+ entry.fingerprint == await fingerprint(entry.reads)
47
+ let began = performance.now()
48
+ let held = entries.get(key)
49
+ let found: Entry<T> | null = await valid(held) ? held! : null
50
+ if (found) {
51
+ entries.delete(key)
52
+ entries.set(key, held!)
53
+ } else if (!held) {
54
+ // What memory held and its sources have since moved past, the shelf
55
+ // holds too: only a key memory never held is looked for there.
56
+ let kept = await taken<Entry<T>>(shelf, key)
57
+ if (await valid(kept)) remember(key, found = kept!)
58
+ }
59
+ looked?.(!!found, performance.now() - began)
60
+ if (found) return found.value
61
+ let reads = new Set<string>()
62
+ let value = await work({
63
+ read: (path) => {
64
+ reads.add(path)
65
+ return read(path)
66
+ },
67
+ })
68
+ // Failed work never replaces a successful entry.
69
+ let paths = [...reads].sort()
70
+ let entry = { value, reads: paths, fingerprint: await fingerprint(paths) }
71
+ remember(key, entry)
72
+ shelve(shelf, key, entry)
73
+ return value
74
+ }
75
+ return Object.assign(cache, {
76
+ /** Forget what memory holds, as a container that restarts does. */
77
+ clear: () => {
78
+ entries.clear()
79
+ bytes = 0
80
+ },
81
+ })
82
+ }