(file: string, contents: string, npmDeps = {}, urls = {})
| 316 | } |
| 317 | |
| 318 | function parseFile(file: string, contents: string, npmDeps = {}, urls = {}) { |
| 319 | let deps = new Set<string>(); |
| 320 | for (let [, specifier] of contents.matchAll(/import (?:.|\n)*?['"](.+?)['"]/g)) { |
| 321 | specifier = specifier.replace( |
| 322 | /(vanilla-starter|tailwind-starter)\//g, |
| 323 | (m, s) => 'starters/' + (s === 'vanilla-starter' ? 'docs' : 'tailwind') + '/src/' |
| 324 | ); |
| 325 | |
| 326 | if (specifier.startsWith('url:')) { |
| 327 | urls[specifier] = resolveUrl(specifier.slice(4), file); |
| 328 | continue; |
| 329 | } |
| 330 | |
| 331 | if (!/^(\.|starters)/.test(specifier)) { |
| 332 | let dep = specifier.startsWith('@') |
| 333 | ? specifier.split('/').slice(0, 2).join('/') |
| 334 | : specifier.split('/')[0]; |
| 335 | npmDeps[dep] ??= '^' + getPackageVersion(dep); |
| 336 | continue; |
| 337 | } |
| 338 | |
| 339 | let resolved = specifier.startsWith('.') |
| 340 | ? path.resolve(path.dirname(file), specifier) |
| 341 | : path.resolve('../../../' + specifier); |
| 342 | if (path.extname(resolved) === '') { |
| 343 | if (fs.existsSync(resolved + '.tsx')) { |
| 344 | resolved += '.tsx'; |
| 345 | } else if (fs.existsSync(resolved + '.ts')) { |
| 346 | resolved += '.ts'; |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | deps.add(resolved); |
| 351 | } |
| 352 | |
| 353 | return deps; |
| 354 | } |
| 355 | |
| 356 | export interface DownloadFiles { |
| 357 | files: { |
no test coverage detected