(file: string, contents: string, npmDeps = {}, urls = {})
| 340 | } |
| 341 | |
| 342 | function parseFile(file: string, contents: string, npmDeps = {}, urls = {}) { |
| 343 | let deps = new Set<string>(); |
| 344 | for (let [, specifier] of contents.matchAll(/import (?:.|\n)*?['"](.+?)['"]/g)) { |
| 345 | specifier = specifier.replace( |
| 346 | STARTER_ALIAS_RE, |
| 347 | (m, s) => 'starters/' + STARTER_DIRS[s] + '/src/' |
| 348 | ); |
| 349 | |
| 350 | if (specifier.startsWith('url:')) { |
| 351 | urls[specifier] = resolveUrl(specifier.slice(4), file); |
| 352 | continue; |
| 353 | } |
| 354 | |
| 355 | if (!/^(\.|starters)/.test(specifier)) { |
| 356 | let dep = specifier.startsWith('@') |
| 357 | ? specifier.split('/').slice(0, 2).join('/') |
| 358 | : specifier.split('/')[0]; |
| 359 | npmDeps[dep] ??= '^' + getPackageVersion(dep); |
| 360 | continue; |
| 361 | } |
| 362 | |
| 363 | let resolved = specifier.startsWith('.') |
| 364 | ? path.resolve(path.dirname(file), specifier) |
| 365 | : path.resolve(baseDir, specifier); |
| 366 | if (path.extname(resolved) === '') { |
| 367 | if (fs.existsSync(resolved + '.tsx')) { |
| 368 | resolved += '.tsx'; |
| 369 | } else if (fs.existsSync(resolved + '.ts')) { |
| 370 | resolved += '.ts'; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | deps.add(resolved); |
| 375 | } |
| 376 | |
| 377 | return deps; |
| 378 | } |
| 379 | |
| 380 | export interface DownloadFiles { |
| 381 | files: { |
no test coverage detected