| 41 | |
| 42 | // one bad export refuses a whole artifact, so retry each alone |
| 43 | export const writeValidators = ( |
| 44 | exportsByName: Record<string, StandaloneExport>, |
| 45 | opts: StandaloneOptions, |
| 46 | refusalsByName: Record<string, string[]>, |
| 47 | inline: boolean |
| 48 | ): StandaloneModules => { |
| 49 | const write = (names: string[], combines = true): StandaloneModules => { |
| 50 | const exports = Object.fromEntries( |
| 51 | names.map(name => [name, exportsByName[name]]) |
| 52 | ) |
| 53 | return (inline ? precompileStandalone : precompileStandaloneModules)( |
| 54 | exports, |
| 55 | combines ? opts : { ...opts, combines: false } |
| 56 | ) |
| 57 | } |
| 58 | let names = Object.keys(exportsByName) |
| 59 | let written: StandaloneModules |
| 60 | try { |
| 61 | written = write(names) |
| 62 | } catch { |
| 63 | names = names.filter(name => { |
| 64 | try { |
| 65 | write([name]) |
| 66 | return true |
| 67 | } catch (e) { |
| 68 | refusalsByName[name] = reasonsOf(e) |
| 69 | return false |
| 70 | } |
| 71 | }) |
| 72 | // e.g. every export under a configured locale |
| 73 | if (!names.length) return noValidators |
| 74 | written = write(names) |
| 75 | } |
| 76 | // a program choosing for its modules has chosen checkers |
| 77 | return combinesChecks(opts) && opts.combines === undefined ? |
| 78 | smallerOf(written, () => write(names, false), minifiedSizeOf) |
| 79 | : written |
| 80 | } |
| 81 | |
| 82 | // fixes the configuration as a failed definition does |
| 83 | export const writeParseErrorThrower = ( |