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