(name: string)
| 74 | } |
| 75 | |
| 76 | function parseModule(name: string): string[] { |
| 77 | if (isBuiltin(name)) { |
| 78 | if (cachedFileExports.has(name)) { |
| 79 | const cachedExports = cachedFileExports.get(name)! |
| 80 | return cachedExports |
| 81 | } |
| 82 | |
| 83 | const builtinModule = getBuiltinModule(name) |
| 84 | const builtinExports = Object.keys(builtinModule) |
| 85 | cachedFileExports.set(name, builtinExports) |
| 86 | return builtinExports |
| 87 | } |
| 88 | |
| 89 | const resolvedModuleUrl = format === 'module' |
| 90 | ? import.meta.resolve(name, pathToFileURL(filename).toString()) |
| 91 | : getModuleRequire().resolve(name) |
| 92 | |
| 93 | const resolvedModulePath = format === 'commonjs' |
| 94 | ? resolvedModuleUrl |
| 95 | : fileURLToPath(resolvedModuleUrl) |
| 96 | |
| 97 | if (cachedFileExports.has(resolvedModulePath)) { |
| 98 | return cachedFileExports.get(resolvedModulePath)! |
| 99 | } |
| 100 | |
| 101 | const fileContent = readFileSync(resolvedModulePath, 'utf-8') |
| 102 | const ext = extname(resolvedModulePath) |
| 103 | const code = transformCode(fileContent, resolvedModulePath) |
| 104 | if (code == null) { |
| 105 | cachedFileExports.set(resolvedModulePath, []) |
| 106 | return [] |
| 107 | } |
| 108 | |
| 109 | const resolvedModuleFormat = resolveModuleFormat(resolvedModulePath, code) |
| 110 | if (ext === '.json') { |
| 111 | return ['default'] |
| 112 | } |
| 113 | else { |
| 114 | // can't do wasm, for example |
| 115 | console.warn(`Cannot process '${resolvedModuleFormat}' imported from ${filename} because of unknown file extension: ${ext}.`) |
| 116 | } |
| 117 | if (resolvedModuleFormat) { |
| 118 | return collectModuleExports(resolvedModulePath, code, resolvedModuleFormat, exports) |
| 119 | } |
| 120 | return [] |
| 121 | } |
| 122 | |
| 123 | return Array.from(new Set(exports)) |
| 124 | } |
no test coverage detected