Skip to content

Instantly share code, notes, and snippets.

@brieb

brieb/babel-node Secret

Last active July 10, 2020 20:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brieb/e055e8df36769862bf2907893b3f9a81 to your computer and use it in GitHub Desktop.
Save brieb/e055e8df36769862bf2907893b3f9a81 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
node -r ./babel-node.register "$@"
const path = require('path');
require('@babel/register')({
extensions: ['.js', '.jsx', '.ts', '.tsx'],
// ... more config ...
});
#!/usr/bin/env bash
set -euo pipefail
./babel-node ./jest-ts-run.ts "$@"
import { run } from 'jest';
import path from 'path';
const argsIn = process.argv.slice(2);
const argsOut: string[] = [];
let configFile;
let i = 0;
while (i < argsIn.length) {
if (argsIn[i].startsWith('--config')) {
if (argsIn[i].startsWith('--config=')) {
configFile = argsIn[i].replace('--config=', '');
} else if (i + 1 < argsIn.length) {
configFile = argsIn[i + 1];
i++;
}
} else {
argsOut.push(argsIn[i]);
}
i++;
}
if (!configFile) {
throw new Error('Missing --config');
}
let config;
if (configFile.endsWith('.ts')) {
config = JSON.stringify(require(path.resolve(configFile)));
} else {
config = configFile;
}
argsOut.unshift('--config', config);
run(argsOut);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment