Consolidate JavaScript Flavors
Fixes https://github.com/facebook/yoga/issues/1417 This dramatically simplifies the matrix of Node vs web, ASM vs WASM, sync vs async compilation, or CommonJS vs ES Modules. We have one variant, using without, with ESModule top-level await to do async compilation. Web/node share the same binary, and we base64 encode the WASM into a wrapper JS file for compatibility with Node and bundlers. After this change we target: This has some downsides, like requiring an environment with top level await, but also has upsides, like a consistent, sync looking API compatible with older Yoga, and mitigating TypeScript issues with package exports and typings resolution. ## Test Plan 1. `yarn test` 2. `yarn lint` 3. `yarn tsc` 4. `yarn build` website-next 5. Locally test website 5. Examine package artifact created by GitHub
This commit is contained in:
@@ -5,8 +5,10 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {getMeasureCounter} from '../tools/MeasureCounter';
|
||||
import {Yoga, YGBENCHMARK} from '../tools/globals';
|
||||
import {getMeasureCounter} from '../tools/MeasureCounter.ts';
|
||||
import {YGBENCHMARK} from '../tools/globals.ts';
|
||||
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
const ITERATIONS = 2000;
|
||||
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('align_baseline_parent_using_child_in_column_as_reference', () => {
|
||||
const config = Yoga.Config.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('border_start', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('margin_start', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('padding_start', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('dirtied', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('errata_all_contains_example_errata', () => {
|
||||
const config = Yoga.Config.create();
|
||||
|
@@ -5,7 +5,7 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
test('flex_basis_auto', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,9 +5,9 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
import {getMeasureCounterMax} from './tools/MeasureCounter';
|
||||
import {getMeasureCounterMax} from './tools/MeasureCounter.ts';
|
||||
|
||||
test('measure_once_single_flexible_child', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -5,8 +5,8 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import {Yoga} from './tools/globals';
|
||||
import {getMeasureCounter} from './tools/MeasureCounter';
|
||||
import Yoga from 'yoga-layout';
|
||||
import {getMeasureCounter} from './tools/MeasureCounter.ts';
|
||||
|
||||
test('dont_measure_single_grow_shrink_child', () => {
|
||||
const root = Yoga.Node.create();
|
||||
|
@@ -10,9 +10,6 @@
|
||||
|
||||
import path from 'path';
|
||||
|
||||
import YogaAsmjs from 'yoga-layout/asmjs-sync';
|
||||
import YogaWasm from 'yoga-layout/wasm-sync';
|
||||
|
||||
const WARMUP_ITERATIONS = 3;
|
||||
const BENCHMARK_ITERATIONS = 10;
|
||||
|
||||
@@ -20,9 +17,7 @@ const testFiles = process.argv.slice(2);
|
||||
|
||||
const testResults = new Map<string, Map<string, number>>();
|
||||
|
||||
for (const type of ['asmjs', 'wasm']) {
|
||||
globalThis.Yoga = type === 'asmjs' ? YogaAsmjs : YogaWasm;
|
||||
|
||||
for (const type of ['wasm']) {
|
||||
for (const file of testFiles) {
|
||||
globalThis.YGBENCHMARK = (name: string, fn: () => void) => {
|
||||
let testEntry = testResults.get(name);
|
||||
@@ -42,10 +37,7 @@ for (const type of ['asmjs', 'wasm']) {
|
||||
};
|
||||
|
||||
const modulePath = path.resolve(file);
|
||||
|
||||
delete require.cache[require.resolve('../tools/globals')];
|
||||
delete require.cache[modulePath];
|
||||
require(modulePath);
|
||||
await import(modulePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAbsolutePositionTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignItemsTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignSelfTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAndroidNewsFeed.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGAspectRatioTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGBorderTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGDimensionTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGDisplayTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexDirectionTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGFlexWrapTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGGapTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGJustifyContentTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGMarginTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGMinMaxDimensionTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGPaddingTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGPercentageTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGRoundingTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -7,7 +7,7 @@
|
||||
|
||||
// @generated by gentest/gentest.rb from gentest/fixtures/YGSizeOverflowTest.html
|
||||
|
||||
import {Yoga} from "../tools/globals";
|
||||
import Yoga from 'yoga-layout';
|
||||
import {
|
||||
Align,
|
||||
Direction,
|
||||
|
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
import type {MeasureFunction} from 'yoga-layout';
|
||||
import {Yoga} from './globals';
|
||||
import Yoga from 'yoga-layout';
|
||||
|
||||
export type MeasureCounter = {
|
||||
inc: MeasureFunction;
|
||||
|
@@ -5,23 +5,15 @@
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
|
||||
import type {Yoga} from 'yoga-layout';
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var Yoga: Yoga | undefined;
|
||||
// eslint-disable-next-line no-var
|
||||
var YGBENCHMARK: (title: string, fn: () => void) => void;
|
||||
}
|
||||
|
||||
if (globalThis.Yoga === undefined) {
|
||||
throw new Error('Expected "Yoga" global to be set');
|
||||
}
|
||||
if (globalThis.YGBENCHMARK === undefined) {
|
||||
throw new Error('Expected "YGBENCHMARK" global to be set');
|
||||
}
|
||||
|
||||
const yoga = globalThis.Yoga;
|
||||
const benchmark = globalThis.YGBENCHMARK;
|
||||
|
||||
export {yoga as Yoga, benchmark as YGBENCHMARK};
|
||||
export {benchmark as YGBENCHMARK};
|
||||
|
Reference in New Issue
Block a user