@stream44.studio/encapsulate 0.4.0-rc.8 → 0.4.0-rc.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/package.json
CHANGED
|
@@ -307,50 +307,9 @@ export async function CapsuleSpineFactory({
|
|
|
307
307
|
return await resolve(uri, parentFilepath, spineFilesystemRoot)
|
|
308
308
|
},
|
|
309
309
|
importCapsule: (() => {
|
|
310
|
-
const callSequence: string[] = []
|
|
311
|
-
const MAX_SEQUENCE = 300
|
|
312
|
-
const REPEAT_THRESHOLD = 3
|
|
313
|
-
|
|
314
|
-
function detectRepeatingSequence(seq: string[]): string[] | null {
|
|
315
|
-
const len = seq.length
|
|
316
|
-
// Check subsequences of length 2..len/3
|
|
317
|
-
for (let subLen = 2; subLen <= Math.floor(len / REPEAT_THRESHOLD); subLen++) {
|
|
318
|
-
const tail = seq.slice(len - subLen)
|
|
319
|
-
let repeats = 1
|
|
320
|
-
for (let offset = subLen; offset <= len - subLen; offset += subLen) {
|
|
321
|
-
const chunk = seq.slice(len - subLen - offset, len - offset)
|
|
322
|
-
if (chunk.length === tail.length && chunk.every((v, i) => v === tail[i])) {
|
|
323
|
-
repeats++
|
|
324
|
-
} else {
|
|
325
|
-
break
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
if (repeats >= REPEAT_THRESHOLD) {
|
|
329
|
-
return tail
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
return null
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
let callCount = 0
|
|
336
|
-
|
|
337
310
|
return async (filepath: string) => {
|
|
338
311
|
const shortPath = filepath.replace(/^.*\/genesis\//, '')
|
|
339
312
|
|
|
340
|
-
callCount++
|
|
341
|
-
callSequence.push(shortPath)
|
|
342
|
-
if (callSequence.length > MAX_SEQUENCE) {
|
|
343
|
-
callSequence.splice(0, callSequence.length - MAX_SEQUENCE)
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
const repeating = detectRepeatingSequence(callSequence)
|
|
347
|
-
if (repeating) {
|
|
348
|
-
throw new Error(
|
|
349
|
-
`Circular capsule loading detected! The following sequence repeated ${REPEAT_THRESHOLD} times:\n` +
|
|
350
|
-
repeating.map((p, i) => ` ${i + 1}. ${p}`).join('\n')
|
|
351
|
-
)
|
|
352
|
-
}
|
|
353
|
-
|
|
354
313
|
timing?.record(`importCapsule: Called for ${shortPath}`)
|
|
355
314
|
const result = await registry.ensure(filepath, async () => {
|
|
356
315
|
timing?.recordMajor(`importCapsule: Starting import for ${shortPath}`)
|