This thing I said in a chat room one time:
webpack is so unknowable that everyone decided to give up on knowing their tools
| #!/bin/sh | |
| set -o errexit | |
| [ $# != 1 ] && { >&2 echo 'Argument: <pull request id>'; exit 1; } | |
| # Get origin remote | |
| origin=$(git remote get-url origin) | |
| # Find target ("owner/repo") of PR | |
| temp=${origin#*github.com?} | |
| [ $origin = $temp ] && { >&2 echo Unrecognized origin.; exit 1; } |
| #!/bin/bash | |
| if [ $# = 0 ]; then echo 'Arguments: <package>...'; exit 1; fi | |
| DIR="$PWD" | |
| for PKG in "$@"; do | |
| BASE="$(basename "$PKG")" | |
| while :; do | |
| if [ -e node_modules/"$PKG" ]; then | |
| DEST="$PWD"/node_modules/"$PKG" | |
| while :; do | |
| if [ -d "$BASE" ]; then |
| // ClientRequest -> Promise<IncomingMessage> with an extra .body field that is a Buffer of the entire response | |
| const response = request => | |
| new Promise((resolve, reject) => | |
| request | |
| .once('response', response => { | |
| const chunks = []; | |
| response.on('data', chunk => chunks.push(chunk)).once('end', () => { | |
| response.body = Buffer.concat(chunks); | |
| resolve(response); | |
| }); |
| // Async Local Context | |
| // Requires Node.js nightly features and fixes, planned (I believe) to be released in 8.2.0 | |
| // Call `createContext()` to create a new local context. | |
| // Call `getContext()` anywhere under that to retrieve the same local context. | |
| // Call `createContext()` when there is already an existing context to create a new child context which inherits from the parent. | |
| import { createHook, executionAsyncId } from 'async_hooks' |
I hereby claim:
To claim this, I am signing this object:
| import stream from 'stream' | |
| let Transform = stream.Transform | |
| export default function makeStream(transform, flush) { | |
| let stream = new Transform({ objectMode: true }) | |
| let push = stream.push.bind(stream) | |
| stream._transform = (file, enc, cb) => transform(file, push, cb) | |
| if (flush) { | |
| stream._flush = cb => flush(push, cb) |
| let rejectionTimeouts = new WeakMap() | |
| function displayError({ stack }) { | |
| process.stderr.write(stack + '\n') | |
| } | |
| process.on('unhandledRejection', (err, promise) => { | |
| rejectionTimeouts.set(promise, setTimeout(() => displayError(err), 200)) | |
| }) |
| export default function replaceAsync(str, re, func) { | |
| let replacements = [] | |
| str.replace(re, (...args) => { | |
| replacements.push(func(...args).then(res => [ args[args.length - 2], args[0].length, res ])) | |
| }) | |
| return Promise.all(replacements).then(replacements => { | |
| let out = '' | |
| let lastEnd = 0 | |
| for (let [ offset, length, replacement ] of replacements) { | |
| out += str.slice(lastEnd, offset) + replacement |