Load a script, directly bypassing the cache.
(
path: string | Link,
context: Record<string, unknown>
)
| 98 | |
| 99 | /** Load a script, directly bypassing the cache. */ |
| 100 | private async loadUncached( |
| 101 | path: string | Link, |
| 102 | context: Record<string, unknown> |
| 103 | ): Promise<Result<unknown, string>> { |
| 104 | const maybeSource = await this.resolveSource(path); |
| 105 | if (!maybeSource.successful) return maybeSource; |
| 106 | |
| 107 | // Transpile to vanilla javascript first... |
| 108 | const { code, language } = maybeSource.value; |
| 109 | let basic; |
| 110 | try { |
| 111 | basic = transpile(code, language); |
| 112 | } catch (error) { |
| 113 | return Result.failure(`Failed to import ${path.toString()} while transpiling from ${language}: ${error}`); |
| 114 | } |
| 115 | |
| 116 | // Then finally execute the script to 'load' it. |
| 117 | const finalContext = Object.assign({ h: h, Fragment: Fragment }, context); |
| 118 | try { |
| 119 | return Result.success(await asyncEvalInContext(basic, finalContext)); |
| 120 | } catch (error) { |
| 121 | return Result.failure(`Failed to execute script '${path.toString()}': ${error}`); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | /** Normalize a path or link to a textual path. */ |
| 126 | private pathkey(path: string | Link): string { |
no test coverage detected