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