shuding/yoga-wasm-web

CommonJS export

jacobp100 opened this issue · 2 comments

I'm trying to update ink to add gap support. The project hasn't been maintained for a long time, and adding ESM support doesn't seem feasible at this stage

Would it be possible to add a CJS build?

If anyone needed a workaround, you can do this in the mean time

import type Yoga from 'yoga-wasm-web';
import fs from 'fs';

const source = fs
	.readFileSync(require.resolve('yoga-wasm-web/asm'), 'utf-8')
	.replace(/export\s*\{(\w+)\s*as\s*default\}/, 'module.exports.default = $1');
const init = new Function('module', source);

const targetExports: any = {};
init({exports: targetExports});

export default targetExports.default() as any as ReturnType<typeof Yoga>;

export type {Node} from 'yoga-wasm-web';

@jacobp100 you can try @react-pdf/yoga, i released it as cjs wrapper around yoga-wasm-web/asm

Yep - that works!