@pagepocket/lib 0.7.1 → 0.8.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/README.md +7 -6
- package/dist/build-snapshot-from-bundle.d.ts +23 -0
- package/dist/build-snapshot-from-bundle.js +68 -0
- package/dist/builtin-blacklist.js +3 -6
- package/dist/bundle/from-network-store.d.ts +10 -0
- package/dist/bundle/from-network-store.js +26 -0
- package/dist/bundle/types.d.ts +32 -0
- package/dist/bundle/types.js +2 -0
- package/dist/capture/index.d.ts +14 -0
- package/dist/capture/index.js +86 -0
- package/dist/capture/memory-content-store.d.ts +4 -0
- package/dist/capture/memory-content-store.js +42 -0
- package/dist/capture/types.d.ts +61 -0
- package/dist/capture/types.js +2 -0
- package/dist/content-store.js +3 -8
- package/dist/content-type.d.ts +1 -1
- package/dist/content-type.js +2 -28
- package/dist/core/_impl/completion.d.ts +4 -0
- package/dist/core/_impl/completion.js +29 -0
- package/dist/core/_impl/content-store.d.ts +21 -0
- package/dist/core/_impl/content-store.js +91 -0
- package/dist/core/_impl/debug.d.ts +1 -0
- package/dist/core/_impl/debug.js +16 -0
- package/dist/core/_impl/inflight-tracker.d.ts +19 -0
- package/dist/core/_impl/inflight-tracker.js +48 -0
- package/dist/core/_impl/pagepocket.d.ts +27 -0
- package/dist/core/_impl/pagepocket.js +155 -0
- package/dist/core/capture/_impl/memory-content-store.d.ts +4 -0
- package/dist/core/capture/_impl/memory-content-store.js +42 -0
- package/dist/core/capture/_impl/types.d.ts +61 -0
- package/dist/core/capture/_impl/types.js +2 -0
- package/dist/core/capture/internal/memory-content-store.d.ts +4 -0
- package/dist/core/capture/internal/memory-content-store.js +42 -0
- package/dist/core/capture/internal/types.d.ts +61 -0
- package/dist/core/capture/internal/types.js +2 -0
- package/dist/core/capture/memory-content-store.d.ts +4 -0
- package/dist/core/capture/memory-content-store.js +38 -0
- package/dist/core/capture/types.d.ts +61 -0
- package/dist/core/capture/types.js +1 -0
- package/dist/core/completion.d.ts +4 -0
- package/dist/core/completion.js +23 -0
- package/dist/core/content-store.d.ts +21 -0
- package/dist/core/content-store.js +54 -0
- package/dist/core/debug.d.ts +1 -0
- package/dist/core/debug.js +12 -0
- package/dist/core/file-tree-merge.d.ts +2 -0
- package/dist/core/file-tree-merge.js +27 -0
- package/dist/core/file-tree.d.ts +36 -0
- package/dist/core/file-tree.js +1 -0
- package/dist/core/inflight-tracker.d.ts +19 -0
- package/dist/core/inflight-tracker.js +44 -0
- package/dist/core/internal/completion.d.ts +4 -0
- package/dist/core/internal/completion.js +29 -0
- package/dist/core/internal/content-store.d.ts +21 -0
- package/dist/core/internal/content-store.js +91 -0
- package/dist/core/internal/debug.d.ts +1 -0
- package/dist/core/internal/debug.js +16 -0
- package/dist/core/internal/inflight-tracker.d.ts +19 -0
- package/dist/core/internal/inflight-tracker.js +48 -0
- package/dist/core/internal/pagepocket.d.ts +27 -0
- package/dist/core/internal/pagepocket.js +155 -0
- package/dist/core/pagepocket.d.ts +38 -0
- package/dist/core/pagepocket.js +57 -0
- package/dist/core/plugin/_impl/context.d.ts +47 -0
- package/dist/core/plugin/_impl/context.js +142 -0
- package/dist/core/plugin/_impl/runner.d.ts +12 -0
- package/dist/core/plugin/_impl/runner.js +232 -0
- package/dist/core/plugin/_impl/types.d.ts +108 -0
- package/dist/core/plugin/_impl/types.js +2 -0
- package/dist/core/plugin/context.d.ts +47 -0
- package/dist/core/plugin/context.js +205 -0
- package/dist/core/plugin/internal/context.d.ts +47 -0
- package/dist/core/plugin/internal/context.js +142 -0
- package/dist/core/plugin/internal/runner.d.ts +12 -0
- package/dist/core/plugin/internal/runner.js +232 -0
- package/dist/core/plugin/internal/types.d.ts +108 -0
- package/dist/core/plugin/internal/types.js +2 -0
- package/dist/core/plugin/runner-utils.d.ts +9 -0
- package/dist/core/plugin/runner-utils.js +29 -0
- package/dist/core/plugin/runner.d.ts +12 -0
- package/dist/core/plugin/runner.js +118 -0
- package/dist/core/plugin/types.d.ts +117 -0
- package/dist/core/plugin/types.js +1 -0
- package/dist/core/runtime/types.d.ts +14 -0
- package/dist/core/runtime/types.js +2 -0
- package/dist/css-rewrite.js +1 -5
- package/dist/debug.d.ts +0 -1
- package/dist/debug.js +3 -5
- package/dist/files/types.d.ts +41 -0
- package/dist/files/types.js +2 -0
- package/dist/hack-html.js +20 -13
- package/dist/hackers/index.d.ts +1 -1
- package/dist/hackers/index.js +24 -27
- package/dist/hackers/preload-fetch.d.ts +1 -1
- package/dist/hackers/preload-fetch.js +1 -4
- package/dist/hackers/preload-xhr.d.ts +1 -1
- package/dist/hackers/preload-xhr.js +1 -4
- package/dist/hackers/replay-beacon.d.ts +1 -1
- package/dist/hackers/replay-beacon.js +1 -4
- package/dist/hackers/replay-block-text-fragment.d.ts +1 -1
- package/dist/hackers/replay-block-text-fragment.js +1 -4
- package/dist/hackers/replay-css-proxy.d.ts +1 -1
- package/dist/hackers/replay-css-proxy.js +9 -12
- package/dist/hackers/replay-dom-rewrite.d.ts +1 -1
- package/dist/hackers/replay-dom-rewrite.js +165 -154
- package/dist/hackers/replay-eventsource.d.ts +1 -1
- package/dist/hackers/replay-eventsource.js +1 -4
- package/dist/hackers/replay-fetch.d.ts +1 -1
- package/dist/hackers/replay-fetch.js +1 -4
- package/dist/hackers/replay-history-path.d.ts +1 -1
- package/dist/hackers/replay-history-path.js +1 -4
- package/dist/hackers/replay-svg-image.d.ts +1 -1
- package/dist/hackers/replay-svg-image.js +1 -4
- package/dist/hackers/replay-websocket.d.ts +1 -1
- package/dist/hackers/replay-websocket.js +1 -4
- package/dist/hackers/replay-xhr.d.ts +1 -1
- package/dist/hackers/replay-xhr.js +1 -4
- package/dist/hackers/types.js +1 -2
- package/dist/index.d.ts +29 -13
- package/dist/index.js +23 -44
- package/dist/kind-map.d.ts +68 -0
- package/dist/kind-map.js +58 -0
- package/dist/network-store.js +12 -1
- package/dist/pagepocket.d.ts +19 -4
- package/dist/pagepocket.js +36 -102
- package/dist/path-resolver.d.ts +1 -2
- package/dist/path-resolver.js +9 -16
- package/dist/plugin/builtins/build-snapshot-plugin.d.ts +5 -0
- package/dist/plugin/builtins/build-snapshot-plugin.js +84 -0
- package/dist/plugin/builtins/replace-elements-plugin.d.ts +8 -0
- package/dist/plugin/builtins/replace-elements-plugin.js +13 -0
- package/dist/plugin/builtins/to-directory-plugin.d.ts +7 -0
- package/dist/plugin/builtins/to-directory-plugin.js +20 -0
- package/dist/plugin/builtins/to-zip-plugin.d.ts +5 -0
- package/dist/plugin/builtins/to-zip-plugin.js +19 -0
- package/dist/plugin/context.d.ts +47 -0
- package/dist/plugin/context.js +142 -0
- package/dist/plugin/runner.d.ts +12 -0
- package/dist/plugin/runner.js +232 -0
- package/dist/plugin/types.d.ts +108 -0
- package/dist/plugin/types.js +2 -0
- package/dist/plugins/build-files-from-capture.d.ts +5 -0
- package/dist/plugins/build-files-from-capture.js +85 -0
- package/dist/plugins/build-warc.d.ts +5 -0
- package/dist/plugins/build-warc.js +225 -0
- package/dist/plugins/builtins/manifest.d.ts +2 -0
- package/dist/plugins/builtins/manifest.js +42 -0
- package/dist/plugins/builtins/snapshot-directory.d.ts +2 -0
- package/dist/plugins/builtins/snapshot-directory.js +24 -0
- package/dist/plugins/builtins/snapshot-zip.d.ts +2 -0
- package/dist/plugins/builtins/snapshot-zip.js +25 -0
- package/dist/plugins/capture-http-lighterceptor.d.ts +5 -0
- package/dist/plugins/capture-http-lighterceptor.js +85 -0
- package/dist/plugins/capture-http-puppeteer.d.ts +5 -0
- package/dist/plugins/capture-http-puppeteer.js +85 -0
- package/dist/plugins/host.d.ts +37 -0
- package/dist/plugins/host.js +105 -0
- package/dist/plugins/index.d.ts +6 -0
- package/dist/plugins/index.js +11 -0
- package/dist/plugins/ordering.d.ts +2 -0
- package/dist/plugins/ordering.js +19 -0
- package/dist/plugins/types.d.ts +51 -0
- package/dist/plugins/types.js +2 -0
- package/dist/preload.js +3 -7
- package/dist/replace-elements/actions.d.ts +5 -0
- package/dist/replace-elements/actions.js +86 -0
- package/dist/replace-elements/match.d.ts +5 -0
- package/dist/replace-elements/match.js +46 -0
- package/dist/replace-elements/normalize.d.ts +21 -0
- package/dist/replace-elements/normalize.js +50 -0
- package/dist/replace-elements.d.ts +1 -1
- package/dist/replace-elements.js +5 -185
- package/dist/replay/match-api.d.ts +10 -0
- package/dist/replay/match-api.js +162 -0
- package/dist/replay/templates/match-api-source.d.ts +1 -0
- package/dist/replay/templates/match-api-source.js +137 -0
- package/dist/replay/templates/replay-script-template.d.ts +5 -0
- package/dist/replay/templates/replay-script-template.js +337 -0
- package/dist/replay/templates/resource-proxy-script.d.ts +1 -0
- package/dist/replay/templates/resource-proxy-script.js +274 -0
- package/dist/replay-script.d.ts +3 -10
- package/dist/replay-script.js +11 -625
- package/dist/resource-filter.d.ts +1 -1
- package/dist/resource-filter.js +1 -5
- package/dist/resource-proxy/escape-percent.d.ts +1 -0
- package/dist/resource-proxy/escape-percent.js +12 -0
- package/dist/resource-proxy/multimap.d.ts +3 -0
- package/dist/resource-proxy/multimap.js +18 -0
- package/dist/resource-proxy/pathname-variants.d.ts +3 -0
- package/dist/resource-proxy/pathname-variants.js +54 -0
- package/dist/resource-proxy.d.ts +4 -2
- package/dist/resource-proxy.js +48 -117
- package/dist/resources.js +4 -42
- package/dist/rewrite-links/js-imports.d.ts +3 -0
- package/dist/rewrite-links/js-imports.js +56 -0
- package/dist/rewrite-links/link-rel.d.ts +2 -0
- package/dist/rewrite-links/link-rel.js +10 -0
- package/dist/rewrite-links/meta-refresh.d.ts +3 -0
- package/dist/rewrite-links/meta-refresh.js +22 -0
- package/dist/rewrite-links/skip.d.ts +1 -0
- package/dist/rewrite-links/skip.js +10 -0
- package/dist/rewrite-links/srcset.d.ts +3 -0
- package/dist/rewrite-links/srcset.js +63 -0
- package/dist/rewrite-links/url-resolve.d.ts +3 -0
- package/dist/rewrite-links/url-resolve.js +13 -0
- package/dist/rewrite-links.d.ts +3 -3
- package/dist/rewrite-links.js +31 -240
- package/dist/snapshot-builder/api.d.ts +3 -0
- package/dist/snapshot-builder/api.js +6 -0
- package/dist/snapshot-builder/build-snapshot.d.ts +3 -0
- package/dist/snapshot-builder/build-snapshot.js +138 -0
- package/dist/snapshot-builder/capture-index/index-capture.d.ts +13 -0
- package/dist/snapshot-builder/capture-index/index-capture.js +168 -0
- package/dist/snapshot-builder/capture-index/index.d.ts +2 -0
- package/dist/snapshot-builder/capture-index/index.js +1 -0
- package/dist/snapshot-builder/capture-index/types.d.ts +12 -0
- package/dist/snapshot-builder/capture-index/types.js +1 -0
- package/dist/snapshot-builder/capture-index.d.ts +12 -0
- package/dist/snapshot-builder/capture-index.js +173 -0
- package/dist/snapshot-builder/emit-document.d.ts +24 -0
- package/dist/snapshot-builder/emit-document.js +50 -0
- package/dist/snapshot-builder/grouping.d.ts +8 -0
- package/dist/snapshot-builder/grouping.js +87 -0
- package/dist/snapshot-builder/http.d.ts +6 -0
- package/dist/snapshot-builder/http.js +28 -0
- package/dist/snapshot-builder/index.d.ts +4 -0
- package/dist/snapshot-builder/index.js +2 -0
- package/dist/snapshot-builder/path-map.d.ts +3 -0
- package/dist/snapshot-builder/path-map.js +35 -0
- package/dist/snapshot-builder/resources-path.d.ts +23 -0
- package/dist/snapshot-builder/resources-path.js +47 -0
- package/dist/snapshot-builder/rewrite-resource.d.ts +18 -0
- package/dist/snapshot-builder/rewrite-resource.js +52 -0
- package/dist/snapshot-builder/types.d.ts +37 -0
- package/dist/snapshot-builder/types.js +2 -0
- package/dist/snapshot-builder.d.ts +12 -8
- package/dist/snapshot-builder.js +252 -27
- package/dist/types.d.ts +122 -78
- package/dist/types.js +4 -2
- package/dist/units/contracts-bridge.d.ts +76 -0
- package/dist/units/contracts-bridge.js +6 -0
- package/dist/units/index.d.ts +4 -0
- package/dist/units/index.js +2 -0
- package/dist/units/runner.d.ts +11 -0
- package/dist/units/runner.js +270 -0
- package/dist/units/types.d.ts +39 -0
- package/dist/units/types.js +1 -0
- package/dist/utils/streams.d.ts +2 -0
- package/dist/utils/streams.js +29 -0
- package/dist/utils.d.ts +35 -1
- package/dist/utils.js +107 -29
- package/dist/v3/contracts-bridge.d.ts +69 -0
- package/dist/v3/contracts-bridge.js +5 -0
- package/dist/v3/index.d.ts +4 -0
- package/dist/v3/index.js +2 -0
- package/dist/v3/runner.d.ts +20 -0
- package/dist/v3/runner.js +245 -0
- package/dist/v3/types.d.ts +39 -0
- package/dist/v3/types.js +1 -0
- package/dist/writers.js +3 -1
- package/package.json +11 -3
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
const emptyAsyncIterable = async function* () {
|
|
2
|
+
return;
|
|
3
|
+
};
|
|
4
|
+
class AsyncQueue {
|
|
5
|
+
constructor() {
|
|
6
|
+
this.values = [];
|
|
7
|
+
this.pending = [];
|
|
8
|
+
this.done = false;
|
|
9
|
+
}
|
|
10
|
+
push(value) {
|
|
11
|
+
if (this.done) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const resolve = this.pending.shift();
|
|
15
|
+
if (resolve) {
|
|
16
|
+
resolve({ value, done: false });
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
this.values.push(value);
|
|
20
|
+
}
|
|
21
|
+
close() {
|
|
22
|
+
if (this.done) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.done = true;
|
|
26
|
+
for (const resolve of this.pending) {
|
|
27
|
+
resolve({ value: undefined, done: true });
|
|
28
|
+
}
|
|
29
|
+
this.pending = [];
|
|
30
|
+
}
|
|
31
|
+
async *iterate() {
|
|
32
|
+
while (true) {
|
|
33
|
+
if (this.values.length > 0) {
|
|
34
|
+
const v = this.values.shift();
|
|
35
|
+
if (v === undefined) {
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
yield v;
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
if (this.done) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const next = await new Promise((resolve) => {
|
|
45
|
+
this.pending.push(resolve);
|
|
46
|
+
});
|
|
47
|
+
if (next.done) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
yield next.value;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
class DeferredTracker {
|
|
55
|
+
constructor() {
|
|
56
|
+
this.promises = [];
|
|
57
|
+
}
|
|
58
|
+
add(p) {
|
|
59
|
+
this.promises.push(p);
|
|
60
|
+
}
|
|
61
|
+
async awaitAll() {
|
|
62
|
+
const ps = this.promises;
|
|
63
|
+
this.promises = [];
|
|
64
|
+
await Promise.allSettled(ps);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
class ElementPatchRegistryImpl {
|
|
68
|
+
constructor() {
|
|
69
|
+
this.items = [];
|
|
70
|
+
}
|
|
71
|
+
contribute(_source, rules) {
|
|
72
|
+
this.items.push({ rules });
|
|
73
|
+
}
|
|
74
|
+
contributeLazy(_source, build) {
|
|
75
|
+
this.items.push({ build });
|
|
76
|
+
}
|
|
77
|
+
async compile() {
|
|
78
|
+
const out = [];
|
|
79
|
+
for (const item of this.items) {
|
|
80
|
+
if (item.rules) {
|
|
81
|
+
out.push(...item.rules);
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
if (item.build) {
|
|
85
|
+
const rules = await item.build();
|
|
86
|
+
out.push(...rules);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return out;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
class RuntimeImpl {
|
|
93
|
+
constructor(input) {
|
|
94
|
+
this.artifacts = new Map();
|
|
95
|
+
this.channels = new Map();
|
|
96
|
+
this.deferred = new DeferredTracker();
|
|
97
|
+
this.finished = false;
|
|
98
|
+
this.elements = new ElementPatchRegistryImpl();
|
|
99
|
+
this.entry = input.entry;
|
|
100
|
+
this.options = input.options;
|
|
101
|
+
this.pocketOptions = input.pocketOptions;
|
|
102
|
+
}
|
|
103
|
+
provide(t, value) {
|
|
104
|
+
this.artifacts.set(t.id, value);
|
|
105
|
+
}
|
|
106
|
+
get(t) {
|
|
107
|
+
return this.artifacts.get(t.id);
|
|
108
|
+
}
|
|
109
|
+
require(t) {
|
|
110
|
+
const v = this.get(t);
|
|
111
|
+
if (v === undefined) {
|
|
112
|
+
throw new Error(`Missing artifact: ${t.id}`);
|
|
113
|
+
}
|
|
114
|
+
return v;
|
|
115
|
+
}
|
|
116
|
+
publish(t, value) {
|
|
117
|
+
const state = this.channels.get(t.id);
|
|
118
|
+
if (!state || state.closed) {
|
|
119
|
+
// No subscribers or closed: drop.
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
state.hasPublisher = true;
|
|
123
|
+
for (const sub of state.subs) {
|
|
124
|
+
sub.push(value);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
subscribe(t) {
|
|
128
|
+
// subscribe MUST be safe.
|
|
129
|
+
// Important: subscribe must also be able to receive future publishes.
|
|
130
|
+
// If no publisher ever publishes, the iterator will just complete on close.
|
|
131
|
+
if (!this.channels.has(t.id)) {
|
|
132
|
+
this.channels.set(t.id, { hasPublisher: false, subs: new Set(), closed: false });
|
|
133
|
+
}
|
|
134
|
+
const state = this.channels.get(t.id);
|
|
135
|
+
if (!state || state.closed) {
|
|
136
|
+
return emptyAsyncIterable();
|
|
137
|
+
}
|
|
138
|
+
const q = new AsyncQueue();
|
|
139
|
+
const sub = {
|
|
140
|
+
push: (v) => q.push(v),
|
|
141
|
+
close: () => q.close()
|
|
142
|
+
};
|
|
143
|
+
state.subs.add(sub);
|
|
144
|
+
const owner = this;
|
|
145
|
+
return (async function* () {
|
|
146
|
+
try {
|
|
147
|
+
for await (const v of q.iterate()) {
|
|
148
|
+
yield v;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
finally {
|
|
152
|
+
// best-effort cleanup
|
|
153
|
+
const s = owner.channels.get(t.id);
|
|
154
|
+
s?.subs.delete(sub);
|
|
155
|
+
q.close();
|
|
156
|
+
}
|
|
157
|
+
})();
|
|
158
|
+
}
|
|
159
|
+
hasPublisher(t) {
|
|
160
|
+
return this.channels.get(t.id)?.hasPublisher === true;
|
|
161
|
+
}
|
|
162
|
+
finish(result) {
|
|
163
|
+
if (this.finished) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
this.finished = true;
|
|
167
|
+
this.result = result;
|
|
168
|
+
}
|
|
169
|
+
defer(promise) {
|
|
170
|
+
this.deferred.add(promise);
|
|
171
|
+
}
|
|
172
|
+
_isFinished() {
|
|
173
|
+
return this.finished;
|
|
174
|
+
}
|
|
175
|
+
_getResult() {
|
|
176
|
+
return this.result;
|
|
177
|
+
}
|
|
178
|
+
_ensureChannel(t) {
|
|
179
|
+
if (this.channels.has(t.id)) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.channels.set(t.id, { hasPublisher: false, subs: new Set(), closed: false });
|
|
183
|
+
}
|
|
184
|
+
async _closeAllChannels() {
|
|
185
|
+
for (const state of this.channels.values()) {
|
|
186
|
+
if (state.closed) {
|
|
187
|
+
continue;
|
|
188
|
+
}
|
|
189
|
+
state.closed = true;
|
|
190
|
+
for (const sub of state.subs) {
|
|
191
|
+
sub.close();
|
|
192
|
+
}
|
|
193
|
+
state.subs.clear();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async _awaitDeferred() {
|
|
197
|
+
await this.deferred.awaitAll();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
export const runCaptureV3 = async (input) => {
|
|
201
|
+
const rt = new RuntimeImpl({
|
|
202
|
+
entry: input.entry,
|
|
203
|
+
options: input.options,
|
|
204
|
+
pocketOptions: input.pocketOptions
|
|
205
|
+
});
|
|
206
|
+
for (const ch of input.declaredChannels ?? []) {
|
|
207
|
+
rt._ensureChannel(ch);
|
|
208
|
+
}
|
|
209
|
+
for (const unit of input.units) {
|
|
210
|
+
unit.attach(rt);
|
|
211
|
+
}
|
|
212
|
+
const pluginHost = {
|
|
213
|
+
entry: rt.entry,
|
|
214
|
+
options: rt.options,
|
|
215
|
+
subscribe: (t) => rt.subscribe(t),
|
|
216
|
+
hasPublisher: (t) => rt.hasPublisher(t),
|
|
217
|
+
elements: rt.elements,
|
|
218
|
+
defer: (p) => rt.defer(p)
|
|
219
|
+
};
|
|
220
|
+
for (const plugin of input.plugins ?? []) {
|
|
221
|
+
await plugin.setup(pluginHost);
|
|
222
|
+
}
|
|
223
|
+
try {
|
|
224
|
+
for (const unit of input.units) {
|
|
225
|
+
if (rt._isFinished()) {
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
const out = await unit.run();
|
|
229
|
+
if (out) {
|
|
230
|
+
rt.finish(out);
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
finally {
|
|
236
|
+
await rt._closeAllChannels();
|
|
237
|
+
await rt._awaitDeferred();
|
|
238
|
+
}
|
|
239
|
+
const result = rt._getResult();
|
|
240
|
+
if (!result) {
|
|
241
|
+
throw new Error("No terminal result. Ensure a terminal unit returns a CaptureResult or calls finish().");
|
|
242
|
+
}
|
|
243
|
+
return result;
|
|
244
|
+
};
|
|
245
|
+
export const runCapture = runCaptureV3;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { CompletionStrategy, ContentStore, PathResolver, ResourceFilter } from "../types.js";
|
|
2
|
+
export type EntryInfo = {
|
|
3
|
+
kind: "url";
|
|
4
|
+
url: string;
|
|
5
|
+
} | {
|
|
6
|
+
kind: "puppeteer-page";
|
|
7
|
+
page: unknown;
|
|
8
|
+
url?: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: "cdp-tab";
|
|
11
|
+
tabId: number;
|
|
12
|
+
url?: string;
|
|
13
|
+
} | {
|
|
14
|
+
kind: "html-string";
|
|
15
|
+
htmlString: string;
|
|
16
|
+
baseUrl: string;
|
|
17
|
+
url?: string;
|
|
18
|
+
} | {
|
|
19
|
+
kind: "document";
|
|
20
|
+
baseUrl: string;
|
|
21
|
+
url?: string;
|
|
22
|
+
};
|
|
23
|
+
export interface CaptureOptions {
|
|
24
|
+
completion?: CompletionStrategy | CompletionStrategy[];
|
|
25
|
+
timeoutMs?: number;
|
|
26
|
+
maxDurationMs?: number;
|
|
27
|
+
filter?: ResourceFilter;
|
|
28
|
+
blacklist?: RegExp[];
|
|
29
|
+
pathResolver?: PathResolver;
|
|
30
|
+
contentStore?: ContentStore;
|
|
31
|
+
rewriteEntry?: boolean;
|
|
32
|
+
rewriteCSS?: boolean;
|
|
33
|
+
limits?: {
|
|
34
|
+
maxTotalBytes?: number;
|
|
35
|
+
maxSingleResourceBytes?: number;
|
|
36
|
+
maxResources?: number;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export type PagePocketOptions = import("../types.js").PagePocketOptions;
|
package/dist/v3/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/writers.js
CHANGED
|
@@ -34,7 +34,9 @@ const trimTrailingSlash = (value) => {
|
|
|
34
34
|
};
|
|
35
35
|
const buildSuffix = (pattern, index) => {
|
|
36
36
|
const template = pattern ?? DEFAULT_SUFFIX_PATTERN;
|
|
37
|
-
return template.includes("{num}")
|
|
37
|
+
return template.includes("{num}")
|
|
38
|
+
? template.replace("{num}", String(index))
|
|
39
|
+
: `${template}${index}`;
|
|
38
40
|
};
|
|
39
41
|
const appendDirectorySuffix = (basePath, suffix) => {
|
|
40
42
|
return `${trimTrailingSlash(basePath)}${suffix}`;
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pagepocket/lib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "Library for rewriting HTML snapshots and inlining local resources.",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"default": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"files": [
|
|
8
15
|
"dist"
|
|
9
16
|
],
|
|
@@ -12,8 +19,9 @@
|
|
|
12
19
|
"license": "ISC",
|
|
13
20
|
"dependencies": {
|
|
14
21
|
"cheerio": "^1.0.0-rc.12",
|
|
15
|
-
"@pagepocket/
|
|
16
|
-
"@pagepocket/
|
|
22
|
+
"@pagepocket/contracts": "0.8.0",
|
|
23
|
+
"@pagepocket/shared": "0.8.0",
|
|
24
|
+
"@pagepocket/uni-fs": "0.8.0"
|
|
17
25
|
},
|
|
18
26
|
"devDependencies": {
|
|
19
27
|
"@playwright/test": "^1.50.1",
|