@bendyline/molen-pack 0.0.8 → 0.0.9

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/dist/index.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { n as PackRetryOptions, r as RangeReader, t as PackChangedError } from "./source-7Pr2tntF.mjs";
2
- import { _ as describePack, a as PackInput, b as sha256, c as ReadOptions, d as openPack, f as packFromFiles, g as createPack, h as PackOptions, i as PackEntryNotFoundError, l as isDirectoryPackUrl, m as PackFile, n as OpenPackOptions, o as PackIntegrityError, p as BuiltPack, r as Pack, s as PackProgress, t as OpenDirectoryPackOptions, u as openDirectoryPack, v as isTextPath, y as mediaTypeOf } from "./pack-BwwY7qpa.mjs";
2
+ import { _ as describePack, a as PackInput, b as sha256, c as ReadOptions, d as openPack, f as packFromFiles, g as createPack, h as PackOptions, i as PackEntryNotFoundError, l as isDirectoryPackUrl, m as PackFile, n as OpenPackOptions, o as PackIntegrityError, p as BuiltPack, r as Pack, s as PackProgress, t as OpenDirectoryPackOptions, u as openDirectoryPack, v as isTextPath, y as mediaTypeOf } from "./pack-BkaC_X0Y.mjs";
3
3
  import { PackIndex, PackIndexEntry, PackManifest } from "@bendyline/molen-schema";
4
4
 
5
5
  //#region src/set.d.ts
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { a as openPack, c as describePack, d as sha256, i as openDirectoryPack, l as isTextPath, n as PackIntegrityError, o as packFromFiles, r as isDirectoryPackUrl, s as createPack, t as PackEntryNotFoundError, u as mediaTypeOf } from "./pack-CymjXXOV.mjs";
1
+ import { a as openPack, c as describePack, d as sha256, i as openDirectoryPack, l as isTextPath, n as PackIntegrityError, o as packFromFiles, r as isDirectoryPackUrl, s as createPack, t as PackEntryNotFoundError, u as mediaTypeOf } from "./pack-C3g5LDPD.mjs";
2
2
  import { n as PackChangedError } from "./source-BMJGKBgK.mjs";
3
3
  //#region src/set.ts
4
4
  var Packs = class {
package/dist/node.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { h as PackOptions, m as PackFile, n as OpenPackOptions, r as Pack } from "./pack-BwwY7qpa.mjs";
1
+ import { h as PackOptions, m as PackFile, n as OpenPackOptions, r as Pack } from "./pack-BkaC_X0Y.mjs";
2
2
  import { PackIndex, PackIndexEntry, PackManifest, PackSourceConfig } from "@bendyline/molen-schema";
3
3
 
4
4
  //#region src/node.d.ts
package/dist/node.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { a as openPack, d as sha256, o as packFromFiles, s as createPack } from "./pack-CymjXXOV.mjs";
1
+ import { a as openPack, d as sha256, i as openDirectoryPack, o as packFromFiles, s as createPack } from "./pack-C3g5LDPD.mjs";
2
2
  import { PACK_MANIFEST_ENTRY, validate } from "@bendyline/molen-schema";
3
3
  import { mkdir, open, readFile, readdir, rm, stat, writeFile } from "node:fs/promises";
4
4
  import { dirname, join, relative, resolve, sep } from "node:path";
5
+ import { fileURLToPath, pathToFileURL } from "node:url";
5
6
  //#region src/node.ts
6
7
  /** Build settings file in a pack's source directory. */
7
8
  const PACK_SOURCE_FILE = "molen-pack.source.json";
@@ -101,7 +102,8 @@ function optionsOf(config) {
101
102
  ...config.notice !== void 0 ? { notice: config.notice } : {},
102
103
  ids: config.ids,
103
104
  provides: config.provides,
104
- solid: config.solid
105
+ solid: config.solid,
106
+ independent: config.independent
105
107
  };
106
108
  }
107
109
  /**
@@ -118,6 +120,17 @@ async function openDirPack(dir, options = {}) {
118
120
  /** Open a pack from a URL, a built pack file, or a pack source directory. */
119
121
  async function openPackAt(source, options = {}) {
120
122
  if (/^https?:\/\//.test(source)) return openPack(source, options);
123
+ if (source.endsWith(PACK_MANIFEST_ENTRY)) {
124
+ const base = pathToFileURL(resolve(source));
125
+ return openDirectoryPack(base, {
126
+ ...options,
127
+ fetch: async (input) => {
128
+ const url = new URL(String(input));
129
+ if (url.protocol !== "file:" || !url.href.startsWith(new URL(".", base).href)) throw new Error("Pack file outside its directory");
130
+ return new Response(await readFile(fileURLToPath(url)));
131
+ }
132
+ });
133
+ }
121
134
  return (await stat(source)).isDirectory() ? openDirPack(source, options) : openFilePack(source, options);
122
135
  }
123
136
  async function readIndex(path) {
@@ -213,7 +226,8 @@ async function extractPack(pack, outDir) {
213
226
  exclude: [],
214
227
  ids: manifest.ids,
215
228
  provides: manifest.provides,
216
- solid: Object.keys(manifest.blocks).length > 0
229
+ solid: Object.keys(manifest.blocks).length > 0,
230
+ independent: Object.entries(manifest.entries).filter(([, entry]) => entry.block === void 0).map(([path]) => path)
217
231
  };
218
232
  await writeFile(join(root, PACK_SOURCE_FILE), `${JSON.stringify(config, null, 2)}\n`);
219
233
  return written;
@@ -291,7 +305,7 @@ async function hostPacks(sourceIndexPath, options) {
291
305
  recursive: true,
292
306
  force: true
293
307
  });
294
- const pack = await openFilePack(join(dirname(source), ...entry.file.split("/")), { expect: { contentHash: entry.contentHash } });
308
+ const pack = await openPackAt(join(dirname(source), ...entry.file.split("/")), { expect: { contentHash: entry.contentHash } });
295
309
  try {
296
310
  manifestBytes = (await writeDirectoryPack(pack, dir)).manifestBytes;
297
311
  } finally {
@@ -20,6 +20,8 @@ interface PackOptions {
20
20
  provides?: Record<string, string | readonly string[]>;
21
21
  /** Group small text files into compressed solid blocks (default true). */
22
22
  solid?: boolean;
23
+ /** Files or directory prefixes (ending /) kept as independent ZIP members. */
24
+ independent?: readonly string[];
23
25
  /**
24
26
  * `auto` (default) deflates a member when that saves at least 10%. `store` writes every member
25
27
  * uncompressed: the manifest and contents are identical, only the archive is larger, so a pack
@@ -352,7 +352,7 @@ async function createPack(files, options) {
352
352
  const blocks = {};
353
353
  const blockMembers = [];
354
354
  const pending = /* @__PURE__ */ new Map();
355
- for (const file of sorted) if (options.solid !== false && isTextPath(file.path) && file.bytes.length < OWN_MEMBER_LIMIT) {
355
+ for (const file of sorted) if (options.solid !== false && !options.independent?.some((path) => file.path === path || path.endsWith("/") && file.path.startsWith(path)) && isTextPath(file.path) && file.bytes.length < OWN_MEMBER_LIMIT) {
356
356
  const group = groupOf(file.path);
357
357
  pending.set(group, [...pending.get(group) ?? [], file]);
358
358
  } else members.push({
@@ -475,6 +475,11 @@ var ByteCache = class {
475
475
  constructor(limit) {
476
476
  this.limit = limit;
477
477
  }
478
+ delete(key) {
479
+ this.entries.delete(key);
480
+ this.total -= this.sizes.get(key) ?? 0;
481
+ this.sizes.delete(key);
482
+ }
478
483
  get(key, load) {
479
484
  const hit = this.entries.get(key);
480
485
  if (hit !== void 0) {
@@ -632,6 +637,7 @@ var DirectoryPack = class extends BasePack {
632
637
  reader;
633
638
  controller;
634
639
  options;
640
+ flights = /* @__PURE__ */ new Map();
635
641
  cache;
636
642
  active = 0;
637
643
  waiting = [];
@@ -671,19 +677,49 @@ var DirectoryPack = class extends BasePack {
671
677
  }
672
678
  bytes(path, options) {
673
679
  if (this.controller.signal.aborted) return Promise.reject(this.controller.signal.reason);
680
+ if (options?.signal?.aborted) return Promise.reject(options.signal.reason);
674
681
  const entry = this.entry(path);
675
- return untilAborted(this.cache.get(path, async () => {
682
+ const load = this.cache.get(path, async () => {
676
683
  if (entry.size === 0) return new Uint8Array(0);
677
- const bytes = await this.slot(options?.priority !== "low", () => this.reader(this.url(path), entry).read(0, entry.size, this.controller.signal));
678
- this.bytesRead += bytes.length;
679
- this.requests++;
680
- this.options.onProgress?.({
681
- label: this.label,
682
- bytes: this.bytesRead,
683
- requests: this.requests
684
- });
685
- return bytes;
686
- }), options?.signal);
684
+ const flight = {
685
+ controller: new AbortController(),
686
+ users: 0,
687
+ settled: false
688
+ };
689
+ this.flights.set(path, flight);
690
+ const signal = AbortSignal.any([this.controller.signal, flight.controller.signal]);
691
+ try {
692
+ const bytes = await this.slot(options?.priority !== "low", async () => {
693
+ signal.throwIfAborted();
694
+ return this.reader(this.url(path), entry).read(0, entry.size, signal);
695
+ });
696
+ signal.throwIfAborted();
697
+ this.bytesRead += bytes.length;
698
+ this.requests++;
699
+ this.options.onProgress?.({
700
+ label: this.label,
701
+ bytes: this.bytesRead,
702
+ requests: this.requests
703
+ });
704
+ return bytes;
705
+ } finally {
706
+ flight.settled = true;
707
+ if (this.flights.get(path) === flight) this.flights.delete(path);
708
+ }
709
+ });
710
+ const flight = this.flights.get(path);
711
+ if (!flight) return untilAborted(load, options?.signal);
712
+ flight.users++;
713
+ return untilAborted(load, options?.signal).finally(() => {
714
+ flight.users--;
715
+ if (!flight.users && !flight.settled) {
716
+ flight.controller.abort(new DOMException("No remaining pack readers", "AbortError"));
717
+ if (this.flights.get(path) === flight) {
718
+ this.flights.delete(path);
719
+ this.cache.delete(path);
720
+ }
721
+ }
722
+ });
687
723
  }
688
724
  async readBytes(path, options) {
689
725
  const entry = this.entry(path);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bendyline/molen-pack",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "private": false,
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -45,8 +45,8 @@
45
45
  "dist"
46
46
  ],
47
47
  "dependencies": {
48
- "fflate": "0.8.3",
49
- "@bendyline/molen-schema": "0.0.7"
48
+ "@bendyline/molen-schema": "0.0.8",
49
+ "fflate": "0.8.3"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@biomejs/biome": "^2.5.0",