@exodus/stasis-core 1.0.0-rc.0 → 1.0.0-rc.1
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/package.json +1 -1
- package/src/brotli.js +1 -0
- package/src/bundle.js +26 -2
package/package.json
CHANGED
package/src/brotli.js
CHANGED
|
@@ -31,4 +31,5 @@ export function brotliDecompressStrict(bytes) {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
export const compressBundleText = (text, quality) => brotliCompressSync(text, brotliOptions(quality))
|
|
34
|
+
export const compressBundle = (bundle, quality) => brotliCompressSync(bundle.serializedBytes(), brotliOptions(quality))
|
|
34
35
|
export const parseBundleBytes = (bytes) => Bundle.parse(brotliDecompressStrict(bytes).toString('utf8'))
|
package/src/bundle.js
CHANGED
|
@@ -216,13 +216,37 @@ export class Bundle {
|
|
|
216
216
|
}
|
|
217
217
|
|
|
218
218
|
serialize() {
|
|
219
|
+
return JSON.stringify(this.#serialized(), undefined, 2)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
serializedBytes() {
|
|
223
|
+
const value = this.#serialized()
|
|
224
|
+
const dirs = Object.keys(value.modules)
|
|
225
|
+
if (dirs.length === 0) return Buffer.from(JSON.stringify(value, undefined, 2))
|
|
226
|
+
const { modules, ...rest } = value
|
|
227
|
+
const head = JSON.stringify(rest, undefined, 2)
|
|
228
|
+
assert(head.endsWith('\n}'))
|
|
229
|
+
const pieces = []
|
|
230
|
+
const add = (text) => pieces.push(Buffer.from(text))
|
|
231
|
+
add(head.slice(0, -2))
|
|
232
|
+
add(',\n "modules": {\n')
|
|
233
|
+
for (const [i, dir] of dirs.entries()) {
|
|
234
|
+
if (i > 0) add(',\n')
|
|
235
|
+
// `{\n "indent": {\n<member>\n }\n}`, the member nested as it is
|
|
236
|
+
add(JSON.stringify({ indent: { [dir]: modules[dir] } }, undefined, 2).slice(16, -6))
|
|
237
|
+
}
|
|
238
|
+
add('\n }\n}')
|
|
239
|
+
return Buffer.concat(pieces)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
#serialized() {
|
|
219
243
|
checkedFileKeys(this.modules, this.formats)
|
|
220
244
|
const { entries, sources, modules, formats, imports, executable } = serializedParts(this, 'bundle', { skipEmpty: true })
|
|
221
245
|
// File contents are written last, after every other key: sources, then modules.
|
|
222
|
-
return
|
|
246
|
+
return {
|
|
223
247
|
version: VERSION, config: this.config, repo: this.repo, package: this.package, entries, formats, imports, executable,
|
|
224
248
|
reason: mergeReason(this.reason, undefined), sources, modules,
|
|
225
|
-
}
|
|
249
|
+
}
|
|
226
250
|
}
|
|
227
251
|
|
|
228
252
|
withReason(consumer, files = [...this.sources.keys()]) {
|