( item: RegistryItem, options: InstallOptions, )
| 67 | * parallel and writing it to its validated target path. |
| 68 | */ |
| 69 | export async function installItem( |
| 70 | item: RegistryItem, |
| 71 | options: InstallOptions, |
| 72 | ): Promise<InstallResult> { |
| 73 | const baseUrl = options.baseUrl ?? DEFAULT_REGISTRY_URL; |
| 74 | const destDir = resolve(options.destDir); |
| 75 | |
| 76 | // Validate all targets up-front so a malformed item fails before any write. |
| 77 | for (const file of item.files) { |
| 78 | assertSafeTarget(destDir, file.target); |
| 79 | } |
| 80 | |
| 81 | const written = await Promise.all( |
| 82 | item.files.map(async (file: FileTarget) => { |
| 83 | const destPath = resolve(destDir, file.target); |
| 84 | await fetchItemFile(item, file, destPath, baseUrl); |
| 85 | if (isInstalledRegistryBlockComposition(item, file)) { |
| 86 | const source = readFileSync(destPath, "utf-8"); |
| 87 | writeFileSync(destPath, addRegistryItemMarker(source, item), "utf-8"); |
| 88 | } |
| 89 | return destPath; |
| 90 | }), |
| 91 | ); |
| 92 | |
| 93 | return { written }; |
| 94 | } |
no test coverage detected