| 15 | } |
| 16 | |
| 17 | export class Engine { |
| 18 | boot({ entry }: BootstrapOptions): void { |
| 19 | this.checkEntryExists(entry) |
| 20 | |
| 21 | const babelBinary = this.findBabelBinary() |
| 22 | const babelConfig = this.findBabelConfig() |
| 23 | |
| 24 | log(`waiting for compile exec: ${entry}`) |
| 25 | execa.commandSync(`${babelBinary} --config-file ${babelConfig} ${entry}`, { |
| 26 | stdio: 'inherit', |
| 27 | cwd: process.cwd(), |
| 28 | }) |
| 29 | } |
| 30 | |
| 31 | findBabelBinary(): string | undefined { |
| 32 | return findUp.sync( |
| 33 | (dir) => { |
| 34 | const file = path.join(dir, 'node_modules', '.bin', 'babel-node') |
| 35 | return findUp.sync.exists(file) ? file : dir |
| 36 | }, |
| 37 | { cwd: __dirname }, |
| 38 | ) |
| 39 | } |
| 40 | |
| 41 | findBabelConfig(): string | undefined { |
| 42 | return findUp.sync( |
| 43 | [ |
| 44 | 'babel.config.js', |
| 45 | 'babel.config.cjs', |
| 46 | 'babel.config.mjs', |
| 47 | 'babel.config.json', |
| 48 | '.babelrc', |
| 49 | '.babelrc.js', |
| 50 | '.babelrc.cjs', |
| 51 | '.babelrc.mjs', |
| 52 | ], |
| 53 | { |
| 54 | cwd: __dirname, |
| 55 | }, |
| 56 | ) |
| 57 | } |
| 58 | |
| 59 | checkEntryExists(entry: string): void { |
| 60 | if (!fs.existsSync(entry)) { |
| 61 | throw new Error(`entry file ${entry} not exists`) |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | export const createEngine = () => new Engine() |
nothing calls this directly
no outgoing calls
no test coverage detected