|
1 | 1 | #!/usr/bin/env node |
2 | 2 | 'use strict'; |
3 | 3 |
|
4 | | -import { join } from 'node:path'; |
5 | | -import { writeFile } from 'node:fs/promises'; |
| 4 | +import { basename, dirname, join } from 'node:path'; |
| 5 | +import { readFile, writeFile } from 'node:fs/promises'; |
6 | 6 | import { |
7 | 7 | HeadObjectCommand, |
8 | 8 | ListObjectsV2Command, |
@@ -35,6 +35,14 @@ const CACHED_DIRECTORIES_OUT = join( |
35 | 35 | 'cachedDirectories.json' |
36 | 36 | ); |
37 | 37 |
|
| 38 | +const FILE_SYMLINKS = join( |
| 39 | + import.meta.dirname, |
| 40 | + '..', |
| 41 | + 'src', |
| 42 | + 'constants', |
| 43 | + 'fileSymlinks.json' |
| 44 | +); |
| 45 | + |
38 | 46 | if (!process.env.CF_ACCESS_KEY_ID) { |
39 | 47 | throw new TypeError('CF_ACCESS_KEY_ID missing'); |
40 | 48 | } |
@@ -118,6 +126,38 @@ const cachedDirectories = { |
118 | 126 | }, |
119 | 127 | }; |
120 | 128 |
|
| 129 | +// Some older versions of Node exist in `nodejs/release/` and have folders |
| 130 | +// with symlinks to them. For example, node-v0.1.100.tar.gz lives under |
| 131 | +// `nodejs/release/`, but there's also `nodejs/release/v0.1.100/node-v0.1.100.tar.gz` |
| 132 | +// which is just a symlink to it. |
| 133 | +// Let's add these to our cached directories. |
| 134 | +const fileSymlinks = JSON.parse(await readFile(FILE_SYMLINKS, 'utf8')); |
| 135 | + |
| 136 | +for (const file of Object.keys(fileSymlinks)) { |
| 137 | + // Stat the actual file so we can get it's size, last modified |
| 138 | + const actualFile = await headFile(client, fileSymlinks[file]); |
| 139 | + |
| 140 | + const directory = `${dirname(file)}/`; |
| 141 | + |
| 142 | + if (directory in cachedDirectories) { |
| 143 | + // Directory was already cached, let's just append the file to the result |
| 144 | + cachedDirectories[directory].files.push({ |
| 145 | + ...actualFile, |
| 146 | + name: basename(file), |
| 147 | + }); |
| 148 | + } else { |
| 149 | + // List the directory that the symlink is in so we can append the symlink to |
| 150 | + // what's actually there |
| 151 | + const contents = await listDirectory(client, directory); |
| 152 | + contents.files.push({ |
| 153 | + ...actualFile, |
| 154 | + name: basename(file), |
| 155 | + }); |
| 156 | + |
| 157 | + cachedDirectories[directory] = contents; |
| 158 | + } |
| 159 | +} |
| 160 | + |
121 | 161 | await writeFile(CACHED_DIRECTORIES_OUT, JSON.stringify(cachedDirectories)); |
122 | 162 |
|
123 | 163 | /** |
|
0 commit comments